//=================================================================
// JAVASCRIPT IMPLEMENTATION FOR AJAX BANNERS (GDRipoll)
// ACCIPITER VERSION
//=================================================================
var      BANNER_timeout;
function BANNER_ocultarflyAd(nombre,mensaje){
	if(this.debug)	alert("onclick");
	if(document.getElementById(nombre+"_diviframe")) document.getElementById(nombre+"_diviframe").style.display="none"
	if(document.getElementById(nombre+"_iframe")) document.getElementById(nombre+"_iframe").style.display="none"
	if(typeof mensaje=="undefined"){
		mensaje="ocultarflyAd";
	}
	window.status=mensaje;
	return true;
}
function BANNER_mostrarflyAd(nombre){
	window.status="";
	if(window.wmp_isonlinestore&&window.wmp_isonlinestore()){
		return;
	}	
	if(document.getElementById(nombre+"_diviframe")){	
		if(this.debug)	alert("BANNERS :: fix FlyAd DivIframe positioning h:"+window.screen.height+" w:"+window.screen.width);
		document.getElementById(nombre+"_diviframe").style.position="absolute";
		document.getElementById(nombre+"_diviframe").style.zIndex=10000;
		document.getElementById(nombre+"_diviframe").style.left="0px";
		document.getElementById(nombre+"_diviframe").style.top="0px";					
		document.getElementById(nombre+"_diviframe").style.height=window.screen.height+"px";
		document.getElementById(nombre+"_diviframe").style.width=window.screen.width+"px";										
		document.getElementById(nombre+"_diviframe").onclick=function () { return BANNER_ocultarflyAd(nombre);};
		if(document.getElementById(nombre+"_iframe")){
			if(this.debug)	alert("BANNERS :: fix FlyAd Iframe");						
			document.getElementById(nombre+"_iframe").style.position="absolute";
			document.getElementById(nombre+"_iframe").style.zIndex=10000;
			document.getElementById(nombre+"_iframe").style.left="0px";
			document.getElementById(nombre+"_iframe").style.top="0px";					
			document.getElementById(nombre+"_iframe").style.height=window.screen.height+"px";
			document.getElementById(nombre+"_iframe").style.width=window.screen.width+"px";												
			if(window.frames[nombre+"_iframe"]){
				if(window.frames[nombre+"_iframe"].document){
					if(window.frames[nombre+"_iframe"].document.body){
						if(this.debug)	alert("BANNERS :: fix FlyAd IframeBody");
						window.frames[nombre+"_iframe"].document.body.style.backgroundColor="transparent";
						window.frames[nombre+"_iframe"].document.body.onclick=document.getElementById(nombre+"_diviframe").onclick;
					}
				}
			}
			document.getElementById(nombre+"_iframe").style.display="block";
		}
		document.getElementById(nombre+"_diviframe").style.display="block";
		if(BANNER_timeout){
			window.clearTimeout(BANNER_timeout);
		}
		BANNER_timeout=setTimeout("BANNER_ocultarflyAd('"+nombre+"');",120000); //20000
	}	
}
BANNERS =
{
	debug			: false,
	aBanners	: Array(),

	add	:	function(nombre,noCargarDefault)
	{
		var armado=Array(	nombre,
											document.getElementById(nombre+"_iframe"),
											document.getElementById(nombre+"_div"),
											window.frames[nombre+"_iframe"]
											);
		this.aBanners.push(armado);
		if(this.debug)	alert(":: BANNERS >> add "+this.aBanners.join("|"));
		//if(!noCargarDefault)
		//	this.getOneBanner(nombre);
		if(typeof(IRENDER)!="undefined"){
			this.getOneBanner(nombre);
		}
	},

	setearBanner	:	function(nombre,contenido)
	{	
		if(this.debug)	alert("BANNERS :: setear "+nombre);
		if(nombre){
			if(nombre.toLowerCase()=="bannerflyad"){
				if(contenido){
					if(contenido.search(/<object/i)!=-1){
						if(this.debug)	alert(contenido);
						if(this.debug)	alert("BANNERS :: fix FlyAd");
						BANNER_mostrarflyAd(nombre,contenido);				
					}else{
						BANNER_ocultarflyAd(nombre,"flyAd NoObject");
					}				
				}else{
					BANNER_ocultarflyAd(nombre,"flyAd NoObject");
				}
				return;
			}
		}
		if(document.getElementById(nombre+"_div"))
			document.getElementById(nombre+"_div").innerHTML=contenido;
	},

	getOneBanner	:	function(nombre)
	{
		if(this.debug)	alert(":: BANNERS >> add "+nombre);
		if(this.debug)	alert("/scripts/app/framework.php?APP=banners_ajax|"+nombre+"|"+nombre+"|principal&API=banner");
		//for(var a in this.aBanners) if(this.aBanners[a][0]==nombre) this.aBanners[a][1].src="/scripts/app/framework.php?APP=banners_ajax|"+nombre+"|"+nombre+"|principal&API=banner";
		//07042009//for(var a in this.aBanners) if(this.aBanners[a][0]==nombre) this.aBanners[a][3].document.location.replace("/scripts/app/framework.php?APP=banners_ajax|"+nombre+"|"+nombre+"|principal&API=banner");
		for(var a in this.aBanners) if(this.aBanners[a][0]==nombre) this.aBanners[a][3].document.location.replace(this.getUrlRefreshBanner(nombre));
	},

	reload	:	function()
	{
		//for(var a in this.aBanners) this.aBanners[a][1].src="/scripts/app/framework.php?APP=banners_ajax|"+this.aBanners[a][0]+"|"+this.aBanners[a][0]+"|principal&API=banner";
		//07042009//for(var a in this.aBanners) this.aBanners[a][3].document.location.replace("/scripts/app/framework.php?APP=banners_ajax|"+this.aBanners[a][0]+"|"+this.aBanners[a][0]+"|principal&API=banner");
		for(var a in this.aBanners) this.aBanners[a][3].document.location.replace(this.getUrlRefreshBanner(this.aBanners[a][0]));
	},
	reloadEx	:	function(sParams,sPosition)
	{
		for(var a in this.aBanners){
			if(sPosition==undefined||this.aBanners[a][0]==sPosition){
				this.aBanners[a][3].document.location.replace(this.getUrlRefreshBanner(this.aBanners[a][0],sParams));
			}
		}
	},	
	getUrlRefreshBanner : function(nombre,sParams){
		if(sParams==undefined){
			sParams="";
		}else{
			sParams=sParams.replace("{@name}",nombre);
		}
		var def="/scripts/app/framework.php?APP=banners_ajax|"+nombre+"|"+nombre+"|principal&API=banner&";
		if(top.getUrlRefreshBannerSeoEnabled!=undefined){
			return top.getUrlRefreshBannerSeoEnabled(nombre,def)+"&"+sParams;
		}else{
			return def+sParams;
		}
	}

}

//alert("JSforBanners v.0.15");
