var limit
function objetoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}


function getNBanners(level,bsection,bcountry,bstate){
	ajax2=objetoAjax();
	ajax2.open("POST", level+"countbanners",true);
	ajax2.onreadystatechange=function() {
		if (ajax2.readyState==4) {
			limit=ajax2.responseText;
		
		}
	}
	
	ajax2.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	ajax2.send("section="+bsection+"&country="+bcountry+"&state="+bstate);
}

		
function load_banner(level,nstart,bsection,bcountry,bstate){
	
	var divResult2 = document.getElementById('content2');
	delay = 10000
	ini=nstart
	ajax=objetoAjax();
	ajax.open("POST", level+"banners",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divResult2.innerHTML = ajax.responseText;
			j=0;
		       while(j < 4 ){
		         ini++;
		         if(ini == limit){
		            j++; 
		            break;
		           }
		         else
		            j++;
		       }
		      if(ini == limit){
		          ini = 0;
		      }
		       
		     setTimeout(function(){load_banner(level,ini,bsection,bcountry,bstate)},delay) 
           
		
											
		}
	}
	
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	ajax.send("start="+nstart+"&section="+bsection+"&country="+bcountry+"&state="+bstate);
}





