// JavaScript Document

//var xmlHttpVerticalBanner;
//var xmlHttpHorizontalBanner;
var xmlHttpFeaturedAds1;
var xmlHttpFeaturedAds2;
var html_banner_id = "";

function getBanner(htmldetailid, bannertype, cityid) {
	switch (bannertype) {
		case "H":
			getHorizontalBanner(htmldetailid, cityid);
			break;
		case "V":
			getVerticalBanner(htmldetailid, cityid);
			break;
		case "F":
			getFeaturedAds(1);
			break;
	}
}

function getHorizontalBanner(td_id, cityid){
	var xmlHttpHorizontalBanner;
	//var param = "http://www.etitaniums.com/bannerdev2/generate.randombanner.ver.php?rnd=" + Math.random();
	var param = "http://www.wwacc.com/bannerdev/generate.randombanner.php?lid=6&mt=1&bt=H&sid="+cityid+"&rnd=" + Math.random(); 
	html_banner_id = td_id;

	xmlHttpHorizontalBanner = GetXmlHttpObject();
	//xmlHttpVerticalBanner.onreadystatechange=stateChanged_getVerticalBanner;
	xmlHttpHorizontalBanner.onreadystatechange=function()
	{
		if (xmlHttpHorizontalBanner.readyState==4 || xmlHttpHorizontalBanner.readyState=="complete") { 
			document.getElementById(td_id).innerHTML = xmlHttpHorizontalBanner.responseText;
		} 
	}
	xmlHttpHorizontalBanner.open("GET",param,true);
	xmlHttpHorizontalBanner.send(null);
}

function stateChanged_getHorizontalBanner(){ 
	if (xmlHttpVerticalBanner.readyState==4 || xmlHttpVerticalBanner.readyState=="complete"){ 
		document.getElementById(html_banner_id).innerHTML = xmlHttpVerticalBanner.responseText
	} 
}

function getVerticalBanner(td_id, cityid){
	var xmlHttpVerticalBanner;
	//var param = "http://www.etitaniums.com/bannerdev2/generate.randombanner.ver.php?rnd=" + Math.random();
	var param = "http://www.wwacc.com/bannerdev/generate.randombanner.php?lid=6&mt=1&bt=V&sid="+cityid+"&rnd=" + Math.random(); 
	html_banner_id = td_id;

	xmlHttpVerticalBanner = GetXmlHttpObject();
	//xmlHttpVerticalBanner.onreadystatechange=stateChanged_getVerticalBanner;
	xmlHttpVerticalBanner.onreadystatechange=function()
	{
		if (xmlHttpVerticalBanner.readyState==4 || xmlHttpVerticalBanner.readyState=="complete") { 
			document.getElementById(td_id).innerHTML = xmlHttpVerticalBanner.responseText;
		} 
	}
	xmlHttpVerticalBanner.open("GET",param,true);
	xmlHttpVerticalBanner.send(null);
}

function stateChanged_getVerticalBanner(){ 
	if (xmlHttpVerticalBanner.readyState==4 || xmlHttpVerticalBanner.readyState=="complete"){ 
		document.getElementById(html_banner_id).innerHTML = xmlHttpVerticalBanner.responseText
	} 
}

function getFeaturedAds(num){
	var param = "http://www.wwacc.com/bannerdev/generate.randombanner.fad.php";
	if (num==1){
		xmlHttpFeaturedAds1 = GetXMLHttpObject();
		xmlHttpFeaturedAds1.onreadystatechange=stateChanged_getFeaturedAds1;
		xmlHttpFeaturedAds1.open("GET",param,true);
		xmlHttpFeaturedAds1.send(null);
	}else{
		xmlHttpFeaturedAds2 = GetXMLHttpObject();
		xmlHttpFeaturedAds2.onreadystatechange=stateChanged_getFeaturedAds2;
		xmlHttpFeaturedAds2.open("GET",param,true);
		xmlHttpFeaturedAds2.send(null);
	}
}
function stateChanged_getFeaturedAds1(){ 
	if (xmlHttpFeaturedAds1.readyState==4 || xmlHttpFeaturedAds1.readyState=="complete"){ 
		document.getElementById("featuredads_1").innerHTML = xmlHttpFeaturedAds1.responseText
	} 
}
function stateChanged_getFeaturedAds2(){ 
	if (xmlHttpFeaturedAds2.readyState==4 || xmlHttpFeaturedAds2.readyState=="complete"){ 
		document.getElementById("featuredads_2").innerHTML = xmlHttpFeaturedAds2.responseText
	} 
}

function GetXmlHttpObject()
{ 
  var objXMLHttp=null
  if (window.XMLHttpRequest)
    {
     objXMLHttp=new XMLHttpRequest()
    }
  else if (window.ActiveXObject)
    {
     objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
  return objXMLHttp
} 
