var xmlhttp

function loadXMLDoc(url,elementidtag)
{
saxloadset = 0
elementid = elementidtag
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  xmlhttp.onreadystatechange=state_Change
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    if (xmlhttp)
    {
    xmlhttp.onreadystatechange=state_Change
    xmlhttp.open("GET",url,true)
    xmlhttp.send()
    }
  }
}

function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
  {
  //alert(elementid)
	if (elementid != null)
	{
		document.getElementById(elementid).innerHTML=xmlhttp.responseText
		if (document.getElementById(elementid).innerHTML==oldsaxhtml) {
		saxrefreshtime+=400;
	}
  }
  } else if (xmlhttp.status==302) {
		document.getElementById(elementid).innerHTML=='<br />incorrect redirect.'+oldsaxhtml
  } else if (xmlhttp.status==403) {
		document.getElementById(elementid).innerHTML=='<br />You entered invalid characters!!'+oldsaxhtml
  } else {
  //alert("Problem retrieving data:" + xmlhttp.statusText)
  }
  } else if (elementid != null && document.getElementById(elementid) != null) 
  {
		if (xmlhttp.readyState==1 && saxloadset==0)
		 {
			saxloadset=1
			oldsaxhtml = document.getElementById(elementid).innerHTML
		 }
	}
}

function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()+";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
		if (ch == "+") {
			encoded += "_-_";
		} else if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};
