var ajaxdebug = false;
/**
Browser Compatability function.
Returns the correct XMLHttpRequest depending on the current browser.
*/
function GetXmlHttp() {	
	var xmlhttp = false;
	if (window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
    }
	else if (window.ActiveXObject)// code for IE
	{
		try 
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlhttp=false;
			}
		}
	}
	return xmlhttp;
}


function XMLnewDocument(rootTagName, namespaceURL) {
  if (!rootTagName) rootTagName = "";
  if (!namespaceURL) namespaceURL = "";
  if (document.implementation && document.implementation.createDocument) {
    // This is the W3C standard way to do it
    return document.implementation.createDocument(namespaceURL, rootTagName, null);
  }
  else { // This is the IE way to do it
    // Create an empty document as an ActiveX object
    // If there is no root element, this is all we have to do
    var doc = new ActiveXObject("MSXML2.DOMDocument");
    // If there is a root tag, initialize the document
    if (rootTagName) {
      // Look for a namespace prefix
      var prefix = "";
      var tagname = rootTagName;
      var p = rootTagName.indexOf(':');
      if (p != -1) {
        prefix = rootTagName.substring(0, p);
        tagname = rootTagName.substring(p+1);
      }
      // If we have a namespace, we must have a namespace prefix
      // If we don't have a namespace, we discard any prefix
      if (namespaceURL) {
        if (!prefix) prefix = "a0"; // What Firefox uses
      }
      else prefix = "";
      // Create the root element (with optional namespace) as a
      // string of text
      var text = "<" + (prefix?(prefix+":"):"") +  tagname +
          (namespaceURL
           ?(" xmlns:" + prefix + '="' + namespaceURL +'"')
           :"") +
          "/>";
      // And parse that text into the empty document
      doc.loadXML(text);
    }
    return doc;
  }
};

function PassAjaxResponseToFunction(url, urldata, callbackFunction, callbackParams, method, async, output)
{		
  var xmlhttp = new GetXmlHttp();
  //now we got the XmlHttpRequest object, send the request.
  if (xmlhttp)
  {
    xmlhttp.onreadystatechange = function () 
                                {
	                                if (xmlhttp && xmlhttp.readyState==4)
	                                {//we got something back..
		                                if (xmlhttp.status==200)
		                                {
			                                var response = ( output == 'xml' ) ? xmlhttp.responseXML : xmlhttp.responseText;
											if ( output == 'xml' && response == null ) response = xmlhttp.responseText;
			                                var functionToCall = callbackFunction+'(response,'+callbackParams+')';
			                                if(ajaxdebug && false ){
				                                alert(response);
				                                alert (functionToCall);
			                                }
			                                eval(functionToCall);
		                                } else if(ajaxdebug){
			                                document.write(xmlhttp.responseText);
		                                }
	                                }
                                }
    xmlhttp.open(method,url,async);
	if ( method == 'POST' ) xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xmlhttp.send(urldata);
  }
}