//alert(document.location);
var pagina_origem = document.location;

function windowOpener(url,width,height,name,scrolls) 
{ 
	
	 browserName = navigator.appName; 
	
          browserVer = navigator.appVersion.substring(0,1);
          if (scrolls==true) { 
                  scrollsOption="yes";
          } else { 
                  scrollsOption="no";
          } 
          var l = ( (window.screen.width - width) / 2 );
		    var t = ( (window.screen.height - height) / 2 );
		    if (browserName != "Netscape" || browserVer != 2) {
              controlWindow=window.open( 
              url,name,"toolbar=no,height="+height+",width="+width+",location=no,directories=no,status=no,menubar=no,top="+t+",left="+l+",screenX="+l+",screenY="+t+",scrollbars="+scrollsOption+",resizable=no" 
              );
          } 
    }

/*
function addBookmark(anchor){
   if(window.external)
   {
       window.external.AddFavorite(anchor.getAttribute('href'), anchor.getAttribute('title'));
       return false;
   }
   return true;
}
*/

function GetCookie(cookieName){
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return null;
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length;
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

function SetCookie(cookieName,cookieValue,nDays){
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName + "=" +escape(cookieValue) + ";expires="+expire.toGMTString();
} 


function checkBrowser(){
	var b=navigator.appName;
	var v=navigator.appVersion;
	var u=navigator.userAgent.toLowerCase();
	if(u==null)return;
	this.ie = (u.indexOf("msie") != -1 && u.indexOf("opera") == -1 && u.indexOf("webtv") == -1);
}
is = new checkBrowser();


//Função de Show Hide layers Universal
ns4 = (document.layers)? true:false 
dom = (document.getElementById) ? true : false; 
ie = (document.all)? true:false 
ie4 = ie && !dom
   
function show(id) {  
	if (ns4) document.layers[id].visibility = "show"  
	else if (ie4) document.all[id].style.visibility = "visible"  
	else if (dom) document.getElementById(id).style.visibility = 'visible' 
} 
 
function hide(id) {  
	if (ns4) document.layers[id].visibility = "hide"  
	else if (ie4) document.all[id].style.visibility = "hidden"  
	else if (dom) document.getElementById(id).style.visibility = 'hidden' 
} 

function flashMe(id,src,width,height,wmode,flashvars){
	document.write('<OBJECT name="'+id+'" id="'+id+'" codeBase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" height="'+height+'" width="'+width+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" VIEWASTEXT>');
	document.write('<PARAM NAME="Movie" VALUE="'+src+'">');
	document.write('<PARAM NAME="WMode" VALUE="'+wmode+'">');
	document.write('<PARAM NAME="FlashVars" VALUE="'+flashvars+'">');
	document.write('<PARAM NAME="swLiveConnect" VALUE="true">');
	document.write('<EMBED name="'+id+'" id="'+id+'" src="'+src+'" flashvars="'+flashvars+'" quality="high" bgcolor="#FFFFFF" WIDTH="'+width+'" HEIGHT="'+height+'" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" wmode="'+wmode+'" swLiveConnect="true"></EMBED>');
	document.write('</OBJECT>');
}

arrDest = new Array();
arrDest2 = new Array();
arrSky1 = new Array();
arrSky2 = new Array();
arrSky3 = new Array();
arrSky4 = new Array();
arrSky5 = new Array();
arrSky6 = new Array();
arrSky7 = new Array();
arrSky8 = new Array();


//alert(arrDest.length);
//alert(arrSky1.length);
//alert(arrSky2.length);

if ((pagina_origem != "http://localhost/index.aspx") && (pagina_origem != "http://localhost/") && 
	(pagina_origem != "http://site.md.internal/index.aspx") && (pagina_origem != "http://site.md.internal/") && 
	(pagina_origem != "http://www.com.br/index.aspx") && (pagina_origem != "http://www.com.br/") && 
	(pagina_origem != "http://qa.com.br/index.aspx") && (pagina_origem != "http://qa.com.br/"))
{
	//alert("oi 2");
	randomizeBanners1(arrDest2.length,arrSky4.length,arrSky5.length,arrSky6.length,arrSky7.length,arrSky8.length);	
}
else
{
	//alert("oi");
	randomizeBanners(arrDest.length,arrSky1.length,arrSky2.length,arrSky3.length);
}

	//dest = bannerURL(arrDest[0]);
	//sky1 = bannerURL(arrSky1[8]);
	//sky2 = bannerURL(arrSky2[6]);
	//sky3 = bannerURL(arrSky3[7]);

function random(r1,r2)
{
	return Math.round(Math.random()*(r2-r1))+ (r2>r1?r1:r2);
}
function randomizeBanners(_d,_s1,_s2,_s3)
{
	if (_d>1)
	{
		x = arrSky2[0].split("|");
		ImSky2 = x[2];
		ImDest = ImSky2;
	
		while (ImSky2==ImDest)
		{
			pos_dest = random(0,(_d-1));
			y = arrDest[pos_dest].split("|");
			ImDest = y[2];
		}
		
		ImSky1 = ImDest;
		while (ImSky1 == ImDest)
		{
			pos_sky1 = random(0,(_s1-1));
			z = arrSky1[pos_sky1].split("|");
			ImSky1 = z[2];
		}

		ImSky2 = ImSky1;
		while ((ImSky2 == ImSky1) || (ImSky2 == ImDest))
		{
			pos_sky2 = random(0,(_s2-1));
			z = arrSky2[pos_sky2].split("|");
			ImSky2 = z[2];
		}

		ImSky3 = ImSky2;
		while ((ImSky3 == ImSky2) || (ImSky3 == ImSky1))
		{
			pos_sky3 = random(0,(_s3-1));
			z = arrSky3[pos_sky3].split("|");
			ImSky3 = z[2];
		}

	}
	dest = bannerURL(arrDest[pos_dest]);
	sky1 = bannerURL(arrSky1[pos_sky1]);
	sky2 = bannerURL(arrSky2[pos_sky2]);
	sky3 = bannerURL(arrSky3[pos_sky3]);
}

function randomizeBanners1(_d,_s4,_s5,_s6,_s7,_s8)
{
	if (_s4 > 1)
	{
		pos_dest2 = random(0,(_d-1));
		
		x = arrSky8[0].split("|");
		ImSky8 = x[2];
		ImSky4 = ImSky8;
	
		while (ImSky8==ImSky4)
		{
			pos_sky4 = random(0,(_s4-1));
			y = arrSky4[pos_sky4].split("|");
			ImSky4 = y[2];
		}

		ImSky5 = ImSky4;
		while (ImSky5 == ImSky4)
		{
			pos_sky5 = random(0,(_s5-1));
			z = arrSky5[pos_sky5].split("|");
			ImSky5 = z[2];
		}

  	    ImSky6 = ImSky5;
		while ((ImSky6 == ImSky5) || (ImSky6 == ImSky4))
		{
			pos_sky6 = random(0,(_s6-1));
			z = arrSky6[pos_sky6].split("|");
			ImSky6 = z[2];
		}

		ImSky7 = ImSky6;
		while ((ImSky7 == ImSky6) || (ImSky7 == ImSky5) || (ImSky7 == ImSky4))
		{
			pos_sky7 = random(0,(_s7-1));
			z = arrSky7[pos_sky7].split("|");
			ImSky7 = z[2];
		}

		ImSky8 = ImSky7;
		while ((ImSky8 == ImSky7) || (ImSky8 == ImSky7) || (ImSky8 == ImSky6) || (ImSky8 == ImSky5) || (ImSky8 == ImSky4))
		{
			pos_sky8 = random(0,(_s8-1));
			z = arrSky8[pos_sky8].split("|");
			ImSky8 = z[2];
		}

	}
	dest = bannerURL(arrDest2[pos_dest2]);
	sky4 = bannerURL(arrSky4[pos_sky4]);
	sky5 = bannerURL(arrSky5[pos_sky5]);
	sky6 = bannerURL(arrSky6[pos_sky6]);
	sky7 = bannerURL(arrSky7[pos_sky7]);
	sky8 = bannerURL(arrSky8[pos_sky8]);
}

function bannerURL(str)
{
	aux = str.split("|");
	url = aux[0]+"?clickTAG="+aux[1];
	return url;
}