var showErrors = true;

function createXmlHttpRequestObject() {
  var xmlHttp;

  try{
    xmlHttp = new XMLHttpRequest();
  }catch(e){
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP");
    // try every id until one works
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++){
      try { 
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } catch (e) {} // ignore potential error
    }
  }
  if (!xmlHttp)
    displayError("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

// function that handles the HTTP response
function handleRequestStateChange() 
{
  if (xmlHttp.readyState == 4) {
    if (xmlHttp.status == 200) {
      try{
        // read the response from the server
        readResponse();
      }catch(e){
        // display error message
        displayError(e.toString());
      }
    }
    else{
      // display error message
      displayError(xmlHttp.statusText);
    }
  }
}

// function that displays an error message
function displayError($message)
{
  // ignore errors if showErrors is false
  if (showErrors){
    // turn error displaying Off
    showErrors = false;
    // display error message
 
    alert("Error encountered: \n" + $message);
    // retry validation after 10 seconds
    setTimeout("validate();", 10000);
  }
}

function encode(uri){
	if(encodeURIComponent){
		return encodeURIComponent(uri);
	}
	
	if(escape){
		return escape(uri);
	}
}