// ********* Ajax Program script tasks ********************

// ************ Global definitions ...
var vAjaxProc = location.pathname.substring(0, location.pathname.lastIndexOf("/")) + "/pollAjax.asp"
// alert(vAjaxProc)
var vData = "";
var http = getHTTPObject(); 	// We create the HTTP Object
var userAgent = navigator.userAgent.toLowerCase();
isMSIE = (document.all && userAgent.indexOf('msie')!=-1)? true: false;
var isWorking = false;
var ajaxTarget = "column_3";


function getHTTPObject() 
	{
  		var xmlhttp;

		/*@cc_on	
		@if (@_jscript_version >= 5)
		try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e) {
		      try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (E) { xmlhttp = false; }
		}
		@else
		xmlhttp = false;
		@end @*/

		if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
			try { xmlhttp = new XMLHttpRequest(); }
			catch (e) { xmlhttp = false; }
		}
		return xmlhttp;
	}


function xmlTimeout() {
	// Check if not done or if is working
	if (http.readyState != 4 ) {	
		http.abort();
		isWorking = false;
		var waitText = "<br><br><br><center><blockquote><b> A timeout was detected on your data request.<br><br><input type='button' onclick='window.location.reload()' value='Back'></b></blockquote></center>" ;
		var x = document.all?document.all[vTarget]:document.getElementById(ajaxTarget); 
		x.innerHTML = waitText;	
	}
}

function commonHttpInline() {
	if (document.getElementById(vDivName)){document.getElementById(vDivName).style.visibility='visible';}

	isWorking=true;
	var url = vAjaxProc;  

	// ************ Get down to business ... **************
    	http.open('post', url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.setRequestHeader('If-Modified-Since','Sat, 1 Jan 2000 00:00:00 GMT');
  	http.onreadystatechange = handleHttpResponseInline;
	http.send(vData);
}

function handleHttpResponseInline() {
	if (!isWorking) { return;}
	if (http.readyState == 4 ) {	
		// If defined, make the indicator turns off 
		if (document.getElementById('divSendAlert')){
			window.setTimeout("document.getElementById('divSendAlert').style.visibility='hidden'",1000);}

		isWorking = false;

		if (http.responseText.indexOf('invalid') == -1) {
			var results = http.responseText.split("%%||%%"); 	  		
			if (results[0] && results[0] != " ")
				{  
					x = document.all?document.all[ajaxTarget]:document.getElementById(ajaxTarget); 
					x.innerHTML = results[0] ;}
		}
	}
}


function goAjax (vTarget, vScript, vData) {
	if (isWorking || !http) { return; }	
	isWorking = true;
	if (!vScript) {vScript=vAjaxProc;} if (!vData) {vData="";} var vMethod = "GET";
	//  ****** Default to cgi-bin, but if with a [backslash] or [php], take the whole url
	var url = vScript + "?" + vData;  
	//  ****** Default to Earth, but use deer when going to focus area
	var waitText = "<img src='/images/Child_drawing.gif' width='74' height='81'><blockquote><b> Retrieving Information ...</blockquote>" ;
	x = document.getElementById(vTarget); 
	x.style.visibility='visible';
	x.innerHTML = waitText;
	ajaxTarget = vTarget;

	// ************ Get down to business ... **************
    	http.open(vMethod, url, true);
	  http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	  http.setRequestHeader('If-Modified-Since','Sat, 1 Jan 2000 00:00:00 GMT');
  	  http.onreadystatechange = handleHttpResponseInline;
	// **** Get timeout coding ****
	xmlTimer = window.setTimeout('xmlTimeout()', 120*1000);
	http.send(vData);
}



