adTime=61;  // seconds ad reminder is shown
chanceAd=1; // ad will be shown 1 in X times (put 1 for everytime)

var ns=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);
var calunit=ns? "" : "px"
adCount=0;

function initAd(){
    if(!ns && !ie && !w3) return;
    for (i=1;i<=2;i++){
    	if (i==1){
	    	frameSelecionado = "document.all.sponsorAdDiv.style";
			if(ie)		adDiv1=eval(frameSelecionado);
			else if(ns)	adDiv1=eval('document.layers["sponsorAdDiv"]');
			else if(w3)	adDiv1=eval('document.getElementById("sponsorAdDiv").style');
			randAd=Math.ceil(Math.random()*chanceAd);
		        if (ie||w3){
		        adDiv1.visibility="visible";
		        }else{
		        adDiv1.visibility ="show";
		        }
			if(randAd==1) showAd(1);
	    	
    	}else{
	    	frameSelecionado = "document.all.sponsorAdDiv2.style";
			if(ie)		adDiv2=eval(frameSelecionado);
			else if(ns)	adDiv2=eval('document.layers["sponsorAdDiv2"]');
			else if(w3)	adDiv2=eval('document.getElementById("sponsorAdDiv2").style');
			randAd=Math.ceil(Math.random()*chanceAd);
		        if (ie||w3){
		        adDiv2.visibility="visible";
		        }else{
		        adDiv2.visibility ="show";
		        }
			if(randAd==1) showAd(2);
    	}
    }
}
function showAd(i){
if(adCount<adTime*10){adCount+=1;
	if (ie){documentWidth  =truebody().offsetWidth/2+truebody().scrollLeft-20;
	documentHeight =truebody().offsetHeight/2+truebody().scrollTop-20;}
	else if (ns){documentWidth=window.innerWidth/2+window.pageXOffset-20;
	documentHeight=window.innerHeight/2+window.pageYOffset-20;}
	else if (w3){documentWidth=self.innerWidth/2+window.pageXOffset-20;
	documentHeight=self.innerHeight/2+window.pageYOffset-20;}
	if (i==1){
		adDiv1.left=documentWidth-80+calunit;
		adDiv1.top =documentHeight-80+calunit;
	}else{
		adDiv2.left=documentWidth-350+calunit;
		adDiv2.top =documentHeight-80+calunit;
	}
	setTimeout("showAd("+i+")",100);}else closeAd(i);
}
function closeAd(i){
    if (ie||w3){
    	eval('adDiv'+i+'.display="none"');
    }else{
    	eval('adDiv'+i+'.visibility="hide"');
    }
}
function abrePromocao(){
    closeAd(1);
    closeAd(2);
    initDivFloat('sponsorAdDiv3');
}

function truebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function initDivFloat(id){
    if(!ns && !ie && !w3) return;
	if(ie){
		adDivBackground=eval("document.all.divBackground.style");
		adid=eval("document.all.sponsorAdDiv3.style");
	}
	if(ns){
		adDivBackground=eval('document.layers["divBackground"]');
		adid=eval('document.layers["sponsorAdDiv3"]');
	}
	if(w3){
		adDivBackground=eval('document.getElementById("divBackground").style');
		adid=eval('document.getElementById("sponsorAdDiv3").style');
	}
    if (ie||w3){
    	adDivBackground.display="block";
        adDivBackground.visibility="visible";
    	adid.display="block";
        adid.visibility="visible";
    }else{
        adDivBackground.visibility ="show";
        adid.visibility ="show";
    }
	var winHeight = NaN;
	var winWidth = NaN;
	d = document;
	if (typeof window.innerWidth != 'undefined') {
		winWidth = window.innerWidth;
		winHeight = window.innerHeight;
	} else if (d.documentElement &&	typeof d.documentElement.clientWidth != 'undefined' &&	d.documentElement.clientWidth != 0) {
		winWidth = d.documentElement.clientWidth;
		winHeight = d.documentElement.clientHeight;
	} else if (d.body && typeof d.body.clientWidth != 'undefined') {
		winWidth = d.body.clientWidth;
		winHeight = d.body.clientHeight;
	}    
    document.getElementById("divBackground").style.height = document.getElementById("container").offsetHeight+5+'px';

    var d = document.getElementById(id);
	larguraAtual =  getWidth(d);	
	altura = getHeight(d);
	positionX = (winWidth - larguraAtual)/2;
	positionY = (winHeight-altura)/2;
	
	document.getElementById(id).style.left = positionX +'px' ;
	document.getElementById(id).style.top = positionY +'px' ;  
}
function getWidth(d) {
    if( document.all ) {
        return eval( "document.all." + d.id + ".offsetWidth" );
    } else {
        return parseInt( getStyle(d,"width") );
    }
}
function getHeight(d) {
    if( document.all ) {
        return eval( "document.all." + d.id + ".offsetHeight" );
    } else {
        return parseInt( getStyle(d,"height") );
    }
}
function getStyle(el, style) {
    if(!document.getElementById) return;
    if( window.getComputedStyle ) {
        value = document.defaultView.getComputedStyle(el, "").getPropertyValue(style);
    } else if(document.defaultView) {
        value = document.defaultView.getComputedStyle(el, "").getPropertyValue(style);
    } else if(el.currentStyle) {
        value = el.currentStyle[style];
    }
    return value;
}


function closeFloatDiv(){
	if (ie||w3){
		document.getElementById('sponsorAdDiv3').style.display="none";
		adDivBackground.display="none";
	}else{
		document.getElementById('sponsorAdDiv3').style.display ="hide";
		adDivBackground.visibility ="hide";
	}
}

onload=initAd;
