/* All code (except where otherwise noted) is property of Eric Bigoness, all rights reserved. */
/* If you want to use code from this page, you must at least indicate its source. */

function URLEncode(inputString) {
	var encodedString=escape(inputString);
  encodedString=encodedString.replace("+", "%2B");
  encodedString=encodedString.replace("/", "%2F"); 
	return encodedString;
}

function GetXmlHttpObject() {
  var xmlHttp=null;
  try {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  } catch (e) {
    // Internet Explorer
    try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}

function ajaxRequest(reqUrl, elemID, finalCommands) {
	//if (typeof functionCall == 'undefined' ) functionCall = 0;
	
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		document.getElementById(elemID).innerHTML="error";
	  return;
  } 
	xmlHttp.open("GET", reqUrl, true);
	
	xmlHttp.onreadystatechange = function() { //Call a function when the state changes.
		if((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) {
			document.getElementById(elemID).innerHTML=xmlHttp.responseText;
			eval(finalCommands);
		} else if ((xmlHttp.readyState == 4) && (xmlHttp.status != 200)) {
			document.getElementById(elemID).innerHTML="error";
			eval(finalCommands);
		}
	}
	xmlHttp.send(null);
}

function ajaxPost(reqUrl, paramString, elemID, functionCall) {	
	if (typeof functionCall == 'undefined' ) functionCall = 0;
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		document.getElementById(elemID).innerHTML="error";
	  return;
  } 
	xmlHttp.open("POST", reqUrl, true);
	
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", paramString.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.onreadystatechange  = function() { //Call a function when the state changes.
		if((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) {
			document.getElementById(elemID).innerHTML=xmlHttp.responseText;
			functionCall;
		} else if ((xmlHttp.readyState == 4) && (xmlHttp.status != 200)) {
			document.getElementById(elemID).innerHTML="error";
			functionCall;
		}
	}
	xmlHttp.send(paramString);
}