// JavaScript Document

function GetXmlHttpObject(handler)
{
    var objXMLHttp=null
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest()
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp
}

function stateChanged()
{
	//alert(vReturn)
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
		//Grab the returned string and stick it in an array
		
		//loop through the array and assign the 
            document.getElementById(vReturn).innerHTML= xmlHttp.responseText;
    }
    else {
           // alert(xmlHttp.readyState + " " + vReturn);
    }
}


function GetAds(vType,vPos,vCtry,vReg,vSect,Adcount)
{
	var vPosition
	
	if (vPos == 0)
	{vPosition = "Skyscraper"}
	else
	{vPosition = "BottomAd"}
	
		//alert("/ajax/GetAd.asp?AdType="+ vType +"&Country=" + vCtry +"&Region=" + vReg +"&Sector=" + vSect +"&Position=" + vPos +"&Adcount=" + Adcount)
		xmlreqGET("/ajax/GetAd.asp?AdType="+ vType +"&Country=" + vCtry +"&Region=" + vReg +"&Sector=" + vSect +"&Position=" + vPos +"&Adcount=" + Adcount,vPosition)
}

// Will populate data based on input
function htmlData(vType,vID,vCurrent)
{
	var vPage
	
	if (vType == "advice"){
	xmlreqGET("/ajax/UDAdvisor.asp?ID="+ vID, "advice");
	}
	
	if (vType == "region"){
		//alert("http://MOB/ajax/Getregion.asp?ID="+ vID + "&current=" + vCurrent,"Region")
		xmlreqGET("/ajax/Getregion.asp?ID="+ vID + "&current=" + vCurrent,"Region");
		xmlreqGET("/ajax/Gettown.asp?Country="+ vID + "&current=" + vCurrent,"Town");
		}
		
	if (vType == "town"){
		//alert("http://MOB/ajax/Gettown.asp?ID="+ vID + "&current=" + vCurrent,"Town")
		xmlreqGET("/ajax/Gettown.asp?ID="+ vID + "&current=" + vCurrent,"Town")
		}
		
	if (vType == "subsector"){
		//alert("http://MOB/ajax/GetSubSector.asp?ID="+ vID + "&current=" + vCurrent,"SubSector")
		xmlreqGET("/ajax/GetSubSector.asp?ID="+ vID + "&current=" + vCurrent,"SubSector")
		}
		
	if (vType == "email"){
		//alert("http://MOB/ajax/CheckPW.asp?Email="+ vID)
		xmlreqGET("/ajax/CheckPW.asp?type=1&Email="+ vID,"EmailError")
		xmlreqGET("/ajax/CheckPW.asp?type=2&Email="+ vID,"SubCover")
		}
	if (vType == "ad"){
		//in this case the ID is the location and vCurrent = type of ad
		
		//alert("/ajax/GetAd.asp?AdType="+ vCurrent +"&AdLoc=" + vID,"LHBanner")
		xmlreqGET("/ajax/GetAd.asp?AdType="+ vCurrent +"&AdLoc=" + vID,"LHBanner")
		}
		
	if (vType == "Lowerad"){
		//in this case the ID is the location and vCurrent = type of ad
		
		//alert("/ajax/GetLowerAd.asp?AdType="+ vCurrent +"&AdLoc=" + vID,"BottomAd")
		xmlreqGET("/ajax/GetLowerAd.asp?AdType="+ vCurrent +"&AdLoc=" + vID,"BottomAd")
		}
		
	if (vType == "adregion"){
		//alert("http://MOB/ajax/Getregion.asp?ID="+ vID + "&current=" + vCurrent,"Region")
		xmlreqGET("/ajax/AdRegion.asp?ID="+ vID + "&current=" + vCurrent,"Region");
		xmlreqGET("/ajax/AdTown.asp?Country="+ vID + "&current=" + vCurrent,"Town");
		}
		
	if (vType == "adtown"){
		//alert("http://MOB/ajax/Gettown.asp?ID="+ vID + "&current=" + vCurrent,"Town")
		xmlreqGET("/ajax/AdTown.asp?ID="+ vID + "&current=" + vCurrent,"Town")
		}
		
	if (vType == "adsubsector"){
		//alert("http://MOB/ajax/GetSubSector.asp?ID="+ vID + "&current=" + vCurrent,"SubSector")
		xmlreqGET("/ajax/AdSubSector.asp?ID="+ vID + "&current=" + vCurrent,"SubSector")
		}
		
}


var xmlreqs = new Array(); 

function CXMLReq(freed) 
	{ 
	this.freed = freed; this.xmlhttp = false; if (window.XMLHttpRequest) { this.xmlhttp = new XMLHttpRequest(); 
	} else if (window.ActiveXObject) 
	{ this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } 
	} 

function xmlreqGET(url,vWhere) 
{
	var pos = -1; 
	var vWhere
	for (var i=0; i<xmlreqs.length; i++) { 
	if (xmlreqs[i].freed == 1) 	{ pos = i; break; } } if (pos == -1) { pos = xmlreqs.length; xmlreqs[pos] = new CXMLReq(1); } 
	if (xmlreqs[pos].xmlhttp) { 
			xmlreqs[pos].freed = 0; xmlreqs[pos].xmlhttp.open("GET",url,true); 
			xmlreqs[pos].xmlhttp.onreadystatechange = function() { if (typeof(xmlhttpChange) != 'undefined') { 
			xmlhttpChange(pos,vWhere); } 
			} 
			if (window.XMLHttpRequest) 
			{ 
			xmlreqs[pos].xmlhttp.send(null); } else if (window.ActiveXObject) { xmlreqs[pos].xmlhttp.send(); } 
			} 
} 
			
function xmlreqPOST(url,data) 
{
	var pos = -1; 
	var vWhere
	for (var i=0; i<xmlreqs.length; i++) { 
	if (xmlreqs[i].freed == 1) { pos = i; break; } } 
	if (pos == -1) { pos = xmlreqs.length; xmlreqs[pos] = new CXMLReq(1); } 
	if (xmlreqs[pos].xmlhttp) { 
	xmlreqs[pos].freed = 0; xmlreqs[pos].xmlhttp.open("POST",url,true); 
	xmlreqs[pos].xmlhttp.onreadystatechange = function() { if (typeof(xmlhttpChange) != 'undefined') { xmlhttpChange(pos,vWhere); } } 
	xmlreqs[pos].xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	xmlreqs[pos].xmlhttp.send(data); } 
} 
	
function xmlhttpChange(pos,vWhere) 
{
	if (typeof(xmlreqs[pos]) != 'undefined' && xmlreqs[pos].freed == 0 && xmlreqs[pos].xmlhttp.readyState == 4) 
	{ if (xmlreqs[pos].xmlhttp.status == 200 || xmlreqs[pos].xmlhttp.status == 304) 
	{ document.getElementById(vWhere).innerHTML=xmlreqs[pos].xmlhttp.responseText; } 
	//{ handle_response(xmlreqs[pos].xmlhttp.responseXML); } 
	else 
	{// handle_error(); 
	} 
	xmlreqs[pos].freed = 1; } 
}
