// 
// This code was written and/or modified by Jason Wall.  Feel free to use, and if you can, include a link back to www.walljm.com
// Jason@walljm.com // www.walljm.com
//


/// <summary>
///  The loadXMLDoc() function creates an xmlhttprequest object, calls a specified url 
///   and then calls a specified function to handle the response.
/// </summary>
///
/// <param name="url" required="true">The URL load.</param>
/// <param name="callback" required="true">The Callback function the object will call with the returned document's xml doc.</param>
/// <param name="vars" required="false">An int, string, object or array that is passed through to the callback function.</param>
/// <param name="method" required="false">GET or POST.  Defaults to GET.</param>
/// <param name="post" required="false">If method is POST, then this would be the POST data.</param>
function loadXMLDoc(url, callback, vars, method, post) {
	method = (method == null) ? "GET" : method;
  var xmlhttp=false;
  /*@cc_on @*/
  /*@if (@_jscript_version >= 5)
  // JScript gives us Conditional compilation, we can cope with old IE versions.
  // and security blocked creation of the objects.
   try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
   } catch (e) {
    try {
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
     xmlhttp = false;
    }
   }
  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  xmlhttp.open(method, url,true);
  xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
		/*@cc_on @*/
       /*@if (@_jscript_version >= 5)
    	if (xmlhttp.responseXML.childNodes.length == 0 && xmlhttp.responseText != '') {
    		try {
    			var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
    			xmlDoc.async = false;
    			var loaded = xmlDoc.loadXML(xmlhttp.responseText);
				callback(xmlDoc, vars);
				return false;
    		} catch (e) {
    			try {
    				var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    				var loaded = xmlDoc.load(xmlhttp.responseText);
 					callback(xmlDoc, vars);
 					return false;
    			} catch (E) {
    			
    			}
    		}	   
    	}
    	@end @*/
    	callback(xmlhttp.responseXML, vars);
    }
  }
	if (method == "POST") 
	{
  	xmlhttp.send(post);
	} else {
		xmlhttp.send(null)
	}
		
}
/// <summary>
///  The loadXMLDocSync() function uses the xmlhttprequest object to get an xml doc syncronously.
/// </summary>
///
/// <param name="url" required="true">The url of the document to retrieve</a>
function loadXMLDocSync(url) {
  var xmlhttp=false;
  /*@cc_on @*/
  /*@if (@_jscript_version >= 5)
  // JScript gives us Conditional compilation, we can cope with old IE versions.
  // and security blocked creation of the objects.
   try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
   } catch (e) {
    try {
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
     xmlhttp = false;
    }
   }
  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  
  xmlhttp.open("GET", url,false);
  xmlhttp.send(null);
  /*@cc_on @*/
  /*@if (@_jscript_version >= 5)
	if (xmlhttp.responseXML.childNodes.length == 0 && xmlhttp.responseText != '') {
		try {
			var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
			xmlDoc.async = false;
			var loaded = xmlDoc.loadXML(xmlhttp.responseText);
			return xmlDoc;
		} catch (e) {
			try {
				var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
				var loaded = xmlDoc.load(xmlhttp.responseText);
				return xmlDoc;
			} catch (E) {
			
			}
		}	   
	}
	@end @*/
	return xmlhttp.responseXML;
}




