//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();
arrSky1 = new Array();
arrSky2 = new Array();
arrSky3 = new Array();

arrDest[0] = "/swf/full-lapa.swf|/imoveis/home.aspx?idImovel=83|83";
arrDest[1] = "/swf/full-escape.swf|/imoveis/home.aspx?idImovel=84|84";
//arrDest[1] = "/swf/full-moema.swf|/imoveis/home.aspx?idImovel=82|82";

arrSky1[0] = "/swf/lapa-1024.swf|/imoveis/home.aspx?idImovel=83|83";
arrSky1[1] = "/swf/moema-1024.swf|/imoveis/home.aspx?idImovel=84|84";

arrSky2[0] = "/swf/armarios-1024.swf|/index.aspx|0";
arrSky2[1] = "/swf/prontosparamorar-1024.swf|/imoveis/index.aspx|0";
arrSky2[2] = "/swf/magnum-1024.swf|/imoveis/home.aspx?idImovel=6|6";
arrSky2[3] = "/swf/lerichemond-1024.swf|/imoveis/home.aspx?idImovel=76|76";
arrSky2[4] = "/swf/millesime-1024.swf|/imoveis/home.aspx?idImovel=2|2";
arrSky2[5] = "/swf/gardenville-1024.swf|/imoveis/home.aspx?idImovel=5|5";
arrSky2[6] = "/swf/granja-1024.swf|/imoveis/home.aspx?idImovel=81|81";
arrSky2[7] = "/swf/mooca-1024.swf|/imoveis/home.aspx?idImovel=79|79";
arrSky2[8] = "/swf/moema-1024.swf|/imoveis/home.aspx?idImovel=82|82";			

arrSky3[0] = "/swf/armarios-1024.swf|/index.aspx|0";
arrSky3[1] = "/swf/prontosparamorar-1024.swf|/imoveis/index.aspx|0";
arrSky3[2] = "/swf/magnum-1024.swf|/imoveis/home.aspx?idImovel=6|6";
arrSky3[3] = "/swf/lerichemond-1024.swf|/imoveis/home.aspx?idImovel=76|76";
arrSky3[4] = "/swf/millesime-1024.swf|/imoveis/home.aspx?idImovel=2|2";
arrSky3[5] = "/swf/gardenville-1024.swf|/imoveis/home.aspx?idImovel=5|5";
arrSky3[6] = "/swf/granja-1024.swf|/imoveis/home.aspx?idImovel=81|81";
arrSky3[7] = "/swf/mooca-1024.swf|/imoveis/home.aspx?idImovel=79|79";
arrSky3[8] = "/swf/moema-1024.swf|/imoveis/home.aspx?idImovel=82|82";			

//alert(arrDest.length);
//alert(arrSky1.length);
//alert(arrSky2.length);

if ((pagina_origem != "http://localhost/index.aspx") && (pagina_origem != "http://localhost/") && 
	(pagina_origem != "http://tecnisa/index.aspx") && (pagina_origem != "http://tecnisa/") && 
	(pagina_origem != "http://www.tecnisa.com.br/index.aspx") && (pagina_origem != "http://www.tecnisa.com.br/") && 
	(pagina_origem != "http://qa.tecnisa.com.br/index.aspx") && (pagina_origem != "http://qa.tecnisa.com.br/")
   )
{
	randomizeBanners(arrDest.length,arrSky1.length);
	//dest = bannerURL(arrDest[0]);
	//sky1 = bannerURL(arrSky1[8]);
	//sky2 = bannerURL(arrSky2[6]);
	//sky3 = bannerURL(arrSky3[7]);

}
else
{
	randomizeBanners(arrDest.length,arrSky1.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)
{
	if (_d>1)
	{
		x = arrSky2[6].split("|");
		ImSky2 = x[2];
		ImDest = ImSky2;
	
		while (ImSky2==ImDest)
		{
			pos_dest = random(0,(_d-1));
			y = arrDest[pos_dest].split("|");
			ImDest = y[2];
			//alert(ImDest);
		}
		
		ImSky1 = ImDest;
		while (ImSky1 == ImDest)
		{
			pos_sky1 = random(0,(_s1-1));
			z = arrSky1[pos_sky1].split("|");
			ImSky1 = z[2];
			//alert(ImSky1);
		}
		
	}
	dest = bannerURL(arrDest[pos_dest]);
	sky1 = bannerURL(arrSky1[pos_sky1]);
	sky2 = bannerURL(arrSky2[6]);
	sky3 = bannerURL(arrSky3[7]);
}
function bannerURL(str)
{
	aux = str.split("|");
	url = aux[0]+"?clickTAG="+aux[1];
	return url;
}