// Ajax components for standard ASPUpload script. Created by Simon 12/11/2007


function ProgressBar(uploadID){
	//alert("Show progress");
	showOverlay(); //Show overlay
	var ProgressURL; //Set location of progressURl
	ProgressURL = 'aspupload/progress.asp?UploadID=<%=UploadID%>';
	
	//Change style of Progress window at runtime. .To make sure it stays hidden in all browsers. GRR @ Firefox!
	var isUnderIE7 = getIEVersionNumber() < 7;
	if(isUnderIE7){
		//$('#progressWindow').css("display","block");
		//$('#progressWindow').css("top","300px");	
		$('#IE6Window').css("display","block");
	} else {
		$('#progressWindow').css("display","block");
		$('#progressWindow').css("border","1px black solid");
		$('#progressWindow').css("z-index","2000");
		$('#progressWindow').css("background","#FFFFFF");
		$('#progressWindow').css("position","fixed");
		$('#progressWindow').css("height","200px");
		$('#progressWindow').css("width","400px");
	}

	//Calculate left and top CSS settings to make progress windows appear in center of the screen
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	  }
	 // myWidth - myHeight
	
	
	vLeft	= (myWidth)?(myWidth-400)/2:100 + 'px';
	vTop	= 200 + 'px'; //(screen.height)?(screen.height-200)/2:100 + 'px';			  		
	$('#progressWindow').css("top",vTop);
	$('#progressWindow').css("left",vLeft);

	//Set up timer to calculate progress (Currently set to 2 seconds)
	$.timer(2000, function (timer) {
			$.ajax({
				url: 'aspupload/progress.asp?UploadID=' + uploadID,
				type: 'GET',
				dataType: 'html',
				timeout: 1990,
				error: function(){
					//alert('Upload Progress Error!');
				},
				success: function(data){
					// do something with xml
					var isUnderIE7 = getIEVersionNumber() < 7;
					if(isUnderIE7){
						document.getElementById('IE6Window').innerHTML = data;
					} else {
						document.getElementById('progressWindow').innerHTML = data;
					}
					//alert(data);
				}
			});
			//timer.stop();
	});
	
	return true;
}

function Cancel(){
	//Return to main news screen and display a cancellation message
	window.location = 'quote.asp?result=error&resulttext=' + encodeURIComponent('The upload was not completed because of user interaction.');
}


function getIEVersionNumber() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");
    
    if (MSIEOffset == -1) {
        return 999;
    } else {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
} 


function showOverlay() {
	
	var isOverIE6 = getIEVersionNumber() > 6;

	if (isOverIE6) {
		var arrayPageSize = getPageSize();
		$('#overlay2').css("visibility",'visible');
		$('#overlay2').css("height",arrayPageSize[1]);
	
		//document.getElementById('overlay2').style.visibility = 'visible';
		//new Effect.Appear('overlay2', { duration: 0.2, from: 0.0, to: 0.6 });
		$("#overlay2").fadeIn(2000);
	}
	$("#progressWindow").fadeIn(1000);

}


/* Misc functions that are required --------------------------------- */ 

/*
 *
 *	jQuery Timer plugin v0.1
 *		Matt Schmidt [http://www.mattptr.net]
 *
 *	Licensed under the BSD License:
 *		http://mattptr.net/license/license.txt
 *
 */
 
 jQuery.timer = function (interval, callback)
 {
 /**
  *
  * timer() provides a cleaner way to handle intervals  
  *
  *	@usage
  * $.timer(interval, callback);
  *
  *
  * @example
  * $.timer(1000, function (timer) {
  * 	alert("hello");
  * 	timer.stop();
  * });
  * @desc Show an alert box after 1 second and stop
  * 
  * @example
  * var second = false;
  *	$.timer(1000, function (timer) {
  *		if (!second) {
  *			alert('First time!');
  *			second = true;
  *			timer.reset(3000);
  *		}
  *		else {
  *			alert('Second time');
  *			timer.stop();
  *		}
  *	});
  * @desc Show an alert box after 1 second and show another after 3 seconds
  *
  * 
  */

	var interval = interval || 100;

	if (!callback)
		return false;
	
	_timer = function (interval, callback) {
		this.stop = function () {
			clearInterval(self.id);
		};
		
		this.internalCallback = function () {
			callback(self);
		};
		
		this.reset = function (val) {
			if (self.id)
				clearInterval(self.id);
			
			var val = val || 100;
			this.id = setInterval(this.internalCallback, val);
		};
		
		this.interval = interval;
		this.id = setInterval(this.internalCallback, this.interval);
		
		var self = this;
	};
	
	return new _timer(interval, callback);
 };
 
 
 
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}




 
 
 
 