﻿function ajax(url, qs, load, method, container, bigload) {
	if (bigload != false)
	{
		try {
			document.getElementById(container).innerHTML = "<div style=\"text-align: center;\"><img src=\"images/loading.gif\" class=\"bigload\" /></div>";
			load = null;
		}
		catch (Error) { }
	}
	try {
		document.getElementById(load).style.visibility = "visible";
	}
	catch (Error) { }
	
	var xmlHttp;
    
    try {  // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();  
    }
    catch (e) {  // Internet Explorer
        try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                alert("Your browser does not support AJAX.  You should consider upgrading your browser since this and many other sites use AJAX often.");
            }
        }
    }
    xmlHttp.onreadystatechange = function()
    {
        if (xmlHttp.readyState==4) {
			try {
				document.getElementById(load).style.visibility = "hidden";
			}
			catch(Error) {}
			
			if (xmlHttp.status.toString().substring(1) == "4" || xmlHttp.status.toString().substring(1) == "5")
			{
				alert("There was a problem processing your request.  (Error code " + xmlHttp.status + ")  Please try again later.");
			}
			else
			{	
				if (xmlHttp.responseText.replace("loginidentifier", "") != xmlHttp.responseText) {
					window.location.href = baseurl + "login.aspx?s=l&err=5";
				}
				else if (xmlHttp.responseText.replace("ajaxerridentifier", "") != xmlHttp.responseText) {
					var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body

					var dsocleft=document.all? iebody.scrollLeft : pageXOffset
					var dsoctop=document.all? iebody.scrollTop : pageYOffset
					
					document.getElementById("bigshadow").style.display = "block";
					document.getElementById("ajaxerrcontainer").innerHTML = xmlHttp.responseText;
					document.getElementById("bigshadow").style.top = dsoctop;
					document.getElementById("ajaxerrcontainer").style.top = document.body.clientHeight / 2 - 75 + dsoctop;
					document.getElementById("ajaxerrcontainer").style.left = document.body.clientWidth / 2 - 225 + dsocleft;
				}
				else {
					if (container != null) {
						document.getElementById(container).innerHTML = xmlHttp.responseText;
					}
				}
			}
			xmlHttp = null;
        }
    }
	if (method == "POST") {
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.send(qs);
    }
    else {
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
    }
}
function hideAjaxError() {
	document.getElementById("bigshadow").style.display = "none";
	document.getElementById("ajaxerrcontainer").innerHTML = "";
}
function AjaxCustom(URL, QueryString, Method, EndFunction, EndParams)
{
	var xmlHttp;
    
    try {  // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();  
    }
    catch (e) {  // Internet Explorer
        try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                alert("Your browser does not support AJAX.  You should consider upgrading your browser since this and many other sites use AJAX often.");
            }
        }
    }
    xmlHttp.onreadystatechange = function()
    {
        if (xmlHttp.readyState==4) {
			if (xmlHttp.status.toString().substring(1) == "4" || xmlHttp.status.toString().substring(1) == "5")
				alert("There was a problem processing your request.  (Error code " + xmlHttp.status + " " + xmlHttp.statusText + ")  Please try again later.");
			else
			{
				if (xmlHttp.responseText.search("loginidentifier") != -1) {
					window.location.href = baseurl + "login.aspx?s=l&err=5";
				}
				else if (xmlHttp.responseText.search("ajaxerridentifier") != -1) {
					var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body

					var dsocleft=document.all? iebody.scrollLeft : pageXOffset
					var dsoctop=document.all? iebody.scrollTop : pageYOffset
					
					document.getElementById("bigshadow").style.display = "block";
					document.getElementById("ajaxerrcontainer").innerHTML = xmlHttp.responseText;
					document.getElementById("bigshadow").style.top = dsoctop;
					document.getElementById("ajaxerrcontainer").style.top = document.body.clientHeight / 2 - 75 + dsoctop;
					document.getElementById("ajaxerrcontainer").style.left = document.body.clientWidth / 2 - 225 + dsocleft;
				}
				else
				{
					EndFunction(xmlHttp, EndParams);
				}
			}
		}
	}
	if (Method == "POST") {
		xmlHttp.open("POST", URL, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.send(QueryString);
    }
    else {
		xmlHttp.open("GET", URL, true);
		xmlHttp.send(null);
    }
}