// JavaScript Document

var http_request = false;

function postForm(theURL, theParameters, theSpan) {
      http_request = false;
	  if (theParameters.indexOf("ajaxDiv=") == -1){
		  if (theParameters.length > 0){theParameters += "&"}
	  theParameters += "ajaxDiv=" + theSpan
	  }
	  
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = function() {
		  document.body.style.cursor = 'wait';
		  if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById(theSpan).innerHTML = result;  
			//alert("Success");
         } else {
			document.getElementById(theSpan).innerHTML = http_request.responseText;    
            alert("There was an error");
         }
		 document.body.style.cursor = 'default';
      } 
	  
		  };
      http_request.open('POST', theURL, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", theParameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(theParameters);
   }


function ajaxSetup(theURL, theParameters, theSpan, theCount) {
      http_request = false;
	  
	var arrayURL = new Array();
	arrayURL = theURL.split(",");
	thisURL = arrayURL[theCount-1];
	
	var arrayParameters = new Array();
	arrayParameters = theParameters.split(",");
	thisParameters = arrayParameters[theCount-1];
	
	var arraySpan = new Array();
	arraySpan = theSpan.split(",");
	thisSpan = arraySpan[theCount-1];
	

	  if (thisParameters.indexOf("ajaxDiv=") == -1){
		  if (thisParameters.length > 0){thisParameters += "&"}
	  thisParameters += "ajaxDiv=" + thisSpan
	  }
	  
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = function() {
		  document.body.style.cursor = 'wait';
		  if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById(thisSpan).innerHTML = result;  
			//alert("Success");
         } else {
			document.getElementById(thisSpan).innerHTML = http_request.responseText;    
            alert("There was an error");
         }
		 // recursion
		 document.body.style.cursor = 'default';
		 if(theCount > 1){
		 ajaxSetup(theURL, theParameters, theSpan, theCount - 1);
		 }
      } 
	  
		  };
      http_request.open('POST', thisURL, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", thisParameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(thisParameters);
   }
   

function getParams(theForm)
{
var elem = document.getElementById(theForm).elements;
var theParams = "";
for(var i = 0; i < elem.length; i++) //start loop
{
	if(elem[i].type == "text" || elem[i].type == "textarea" || elem[i].type == "hidden"){
		theParams += elem[i].name + "=" + elem[i].value + "&"
	}
	  
	else if(elem[i].type == "checkbox"){
		if (elem[i].checked == true){
			theParams += elem[i].name + "=" + elem[i].value  + "&"
		}
	}
	  
	else if(elem[i].type == "select-one"){
		theParams += elem[i].name + "=" + elem[i].options[elem[i].selectedIndex].value  + "&"
	}
	  
	else if(elem[i].type == "radio"){
		if (elem[i].checked == true){
			theParams += elem[i].name + "=" + elem[i].value  + "&"
		}
	}
}
;
theParams = theParams.substring(0, theParams.length - 1); 
//alert(theParams);
return theParams;

} 


function gotoPAGE(theURL){
window.location = theURL;
}
;
