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') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

function AJAXFetch(URL)
{
	xmlhttp.open("GET", URL,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			return xmlhttp.responseText;
		}
	}
	xmlhttp.send(null)
}

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function URLDecode (encodedString) {
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  return output;
}



function getAJAXProducts(URL, Div)
{
	document.getElementById(Div).innerHTML = "<div style='background: #ffffff; text-align:center;'><img src='/graphics/admin/big-flower.gif' /></div>";	
	xmlhttp.open("GET", URL, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			PutInDiv2(xmlhttp.responseText, Div);
		}
	}
	xmlhttp.send(null)
}		

function RunAndPost(CMD, GUID)
{
	var URL = "/Admin/Auto/AJAX/AjaxRemote.aspx?GUID=" + GUID + "&CMD=" + CMD;			
	document.getElementById(Div).innerHTML = "";	
	xmlhttp.open("GET", URL, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {	
		    Go();
		}
	}
	xmlhttp.send(null)
}	

		
function PutInDiv2(theText, Div)
{						
    document.getElementById(Div).innerHTML = "";	
	var t = document.createElement('div');
    t.innerHTML = theText;
    document.getElementById(Div).appendChild(t);
}
			
function PutInDiv(theText, Div)
{	
	document.getElementById(Div).innerHTML = theText;					
}
		
function AJAXFetchIntoDiv(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) {
			PutInDiv( xmlhttp.responseText, Div);
		}
	}
	xmlhttp.send(null)
}		

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);
	SendURL(GUID, CMD);
}	

function AJAXCommand(theImageName, theImage, Command, Argument, GUID)
{
	var NewImage = '/graphics/AJAX/1' + theImage
	MM_swapImage(theImageName,'',NewImage,1);
	SendCommand(GUID, Command, Argument);
}	

function SendURL(GUID, CMD)
{
	var URL = "/Admin/AJAX/AjaxRemote.aspx?GUID=" + GUID + "&CMD=" + CMD;			
	AJAXSend(URL);
}

function SendCommand(GUID, Command, Argument)
{
	var URL = "/Admin/AJAX/AjaxCommand.aspx?GUID=" + GUID + "&Command=" + Command + "&Argument=" + Argument;			
	AJAXSend(URL);
}
