/* 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. */

var ajaxErr = false;

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) {
	xmlHttp = GetXmlHttpObject()
	if ((xmlHttp == null) || ajaxErr) {
		ajaxErr = true;
		document.getElementById(elemID).innerHTML="Sorry, there was an error.";
	  return;
  } 
	xmlHttp.open("GET", reqUrl, true);
	
	ajaxErr = true; // will be set to false upon success
	xmlHttp.onreadystatechange = function() { //Call a function when the state changes.
		if((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) {
			document.getElementById(elemID).innerHTML=xmlHttp.responseText;
			ajaxErr = false;
		}
	}
	xmlHttp.send(null);
}

function ajaxPost(reqUrl, paramString, elemID) {	
	xmlHttp=GetXmlHttpObject()
	if ((xmlHttp==null) || ajaxErr) {
		ajaxErr = true;
		document.getElementById(elemID).innerHTML="Sorry, there was an error.";
	  return;
  } 
	xmlHttp.open("POST", reqUrl, true);
	
	ajaxErr = true; // will be set to false upon success
	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;
			ajaxErr = false;
		}
	}
	xmlHttp.send(paramString);
}