var xmlhttp=false;
/*@cc_on @*/
// 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;
  }
 }

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

function AJAXFetch(URL)
{
	//alert(URL);
	xmlhttp.open("GET", URL,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			return xmlhttp.responseText;
		}
	}
	xmlhttp.send(null)
}

function getAJAXProducts(URL, Div)
{
	document.getElementById(Div).innerHTML = "";	
	xmlhttp.open("GET", URL, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
		    PutInDiv(xmlhttp.responseText, Div, URL);
		}
	}
	xmlhttp.send(null)
}

function PutInDiv(theText, Div, URL) 
{
    URL = URL.toString().replace("/Admin/", "");
    theText = theText.toString().replace("<form name=\"form1\" method=\"post\" action=\"" + URL + "\" id=\"form1\">", "");
    theText = theText.toString().replace("</form>", "");
	document.getElementById(Div).innerHTML = theText;
}
function PutInDiv(theText, Div, URL) {
    URL = URL.toString().replace("/Admin/", "");
    theText = theText.toString().replace("<form name=\"form1\" method=\"post\" action=\"" + URL + "\" id=\"form1\">", "");
    theText = theText.toString().replace("</form>", "");
    document.getElementById(Div).innerHTML = theText;
}

function PutInDiv(theText, Div) {
    document.getElementById(Div).innerHTML = theText;
}

function AJAXSend(URL)
{
	xmlhttp.open("GET", URL,true);	
	xmlhttp.send(null)
}

function AJAXClick(theImageName, theImage, CMD, GUID)
{
	var NewImage = '/graphics/AJAX/1' + theImage
	MM_swapImage(theImageName,'',NewImage,1);	
	var URL = "/Admin/Auto/AJAX/AjaxRemote.aspx?GUID=" + GUID + "&CMD=" + CMD;			
	AJAXSend(URL);
}	


function DespatchClick(theImageName, theImage, CMD, GUID, OrderID)
{
	var NewImage = '/graphics/AJAX/1' + theImage
	MM_swapImage(theImageName,'',NewImage,1);	
	var URL = "/Admin/Auto/AJAX/AjaxRemote.aspx?GUID=" + GUID + "&CMD=" + CMD + "&OID=" + OrderID;			
	AJAXSend(URL);
}


function AJAXFetchIntoDiv(URL, Div, Cache) {
    PutInDiv("<img src='/graphics/admin/big-flower.gif' alt='Loading' />", Div);
    if (!Cache) {
        var rand_no = Math.random();
        URL = URL + "&Rand=" + rand_no;
    }

    xmlhttp.open("GET", URL, true);
    xmlhttp.onreadystatechange = function() {
       
        if (xmlhttp.readyState == 4) {
            PutInDiv(xmlhttp.responseText, Div);
        }
    }
 
    xmlhttp.send(null)
}

function AJAXAddToDiv(URL, Div, Cache) {

    if (!Cache) {
        var rand_no = Math.random();
        URL = URL + "&Rand=" + rand_no;
    }
    xmlhttp.open("GET", URL, true);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            var result = xmlhttp.responseText;
            AddOnlyToDiv(result, Div);
        }
    }
    xmlhttp.send(null)
}

function AJAXAddToText(URL, Div, Cache) {

    if (!Cache) {
        var rand_no = Math.random();
        URL = URL + "&Rand=" + rand_no;
    }
    xmlhttp.open("GET", URL, true);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            var result = xmlhttp.responseText;
            AddOnlyToText(result, Div);
        }
    }
    xmlhttp.send(null)
}

function AddOnlyToDiv(theText, Div) {
    document.getElementById(Div).innerHTML += theText;
    document.getElementById(Div).value += theText;
}


function AddOnlyToText(theText, Div) {    
    document.getElementById(Div).value += theText;
}
