if(self != top) top.location = self.location;

function chooseStyle (newstyle){
	var expdate = new Date();
	expdate.setTime(expdate.getTime() + (1000*3600*24*183));  // seis meses
	SetCookie("estilo",newstyle,expdate)
//	self.location= (window.location.href.lastIndexOf ("#") == -1)? self.location : window.location.href.substring(0,window.location.href.lastIndexOf("#"));
	history.go(0);
	}


if(document.cookie.indexOf('estilo=1')>=0)
	{
	document.write('<link rel="stylesheet" type="text/css" href="script/blue.css">\n');
	document.write('<SCRIPT language=JavaScript src="script/array_purple.js" type=text/javascript></'+'SCRIPT>\n');
	}
else if (document.cookie.indexOf('estilo=2')>=0)
	{
	document.write('<link rel="stylesheet" type="text/css" href="script/green.css">\n');
	document.write('<SCRIPT language=JavaScript src="script/array_green.js" type=text/javascript></'+'SCRIPT>\n');
	}
else if (document.cookie.indexOf('estilo=3')>=0)
	{
	document.write('<link rel="stylesheet" type="text/css" href="script/salmon.css">\n');
	document.write('<SCRIPT language=JavaScript src="script/array_salmon.js" type=text/javascript></'+'SCRIPT>\n');
	}
else if (document.cookie.indexOf('estilo=4')>=0)
	{
	document.write('<link rel="stylesheet" type="text/css" href="script/gray.css">\n');
	document.write('<SCRIPT language=JavaScript src="script/array_gray.js" type=text/javascript></'+'SCRIPT>\n');
	}
else if (document.cookie.indexOf('estilo=5')>=0)
	{
	document.write('<link rel="stylesheet" type="text/css" href="script/black.css">\n');
	document.write('<SCRIPT language=JavaScript src="script/array_black.js" type=text/javascript></'+'SCRIPT>\n');
	}
else
	{
	var endbarra = window.location.href.lastIndexOf ("/");
	var inicio3 = window.location.href.substring(endbarra+1,endbarra+4);
	if (inicio3=="wt_" || inicio3=="tip") {
		document.write('<link rel="stylesheet" type="text/css" href="script/green.css">\n');
		document.write('<SCRIPT language=JavaScript src="script/array_green.js" type=text/javascript></'+'SCRIPT>\n');
		}
	else
		{
		document.write('<link rel="stylesheet" type="text/css" href="script/blue.css">\n');
		document.write('<SCRIPT language=JavaScript src="script/array_purple.js" type=text/javascript></'+'SCRIPT>\n');
		}
	}


function getCookieVal (offset) { 
var endstr = document.cookie.indexOf (";", offset); 
if (endstr == -1) 
endstr = document.cookie.length; 
return unescape(document.cookie.substring(offset, endstr)); 
} 
function GetCookie (name) { 
var arg = name + "="; 
var alen = arg.length; 
var clen = document.cookie.length; 
var i = 0; 
while (i < clen) { 
var j = i + alen; 
if (document.cookie.substring(i, j) == arg) 
return getCookieVal (j); 
i = document.cookie.indexOf(" ", i) + 1; 
if (i == 0) break; 
} 
return null; 
} 
function SetCookie (name, value) { 
var argv = SetCookie.arguments; 
var argc = SetCookie.arguments.length; 
var expires = (argc > 2) ? argv[2] : null; 
var path = (argc > 3) ? argv[3] : null; 
var domain = (argc > 4) ? argv[4] : null; 
var secure = (argc > 5) ? argv[5] : false; 
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) + 
((domain == null) ? "" : ("; domain=" + domain)) + 
((secure == true) ? "; secure" : ""); 
} 
function DeleteCookie (name) { 
var exp = new Date(); 
exp.setTime (exp.getTime() - 1); // This cookie is history 
var cval = GetCookie (name); 
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString(); 
} 
function DelCookie () {
DeleteCookie("estilo");
alert("Color configuration set to the default.\nGreen for the guides & blue for the tutorials.");
//self.location= (window.location.href.lastIndexOf ("#") == -1)? self.location : window.location.href.substring(0,window.location.href.lastIndexOf("#"));
history.go(0);
}

netscape = (document.layers) ? 1:0;
goodIE = (document.all) ? 1:0;
gecko = document.getElementById ? 1:0;

//if (goodIE) alert("IE");
//if (gecko) alert("gecko");
//if (netscape) alert("netscape");

if (goodIE)
  {
  var IW= 0;
  var IH= 0;
  var PX= 0;
  var PY= 0;
  var botW= 1600;
  var botH= 31;
  }

else if (netscape || gecko)
  {
  var IW= 0;
  var IH= 0;
  var PX= 0;
  var PY= 0;
  var botW= 1600;
  var botH= 31;
  //alert ("oi"); // OKAY !!
  }


function warming()
  {
  if (goodIE)
      {

      if (typeof(bf) != "undefined") 
      bf.style.display='block';
      Xpos = (document.body.clientWidth/2);
      Ypos = (document.body.clientHeight/2);
      }


  else if (gecko)
      {

      if (typeof(bfn) != "undefined") 
      bfn.style.display='block';
      Xpos = (window.innerWidth/2);
      Ypos = (window.innerHeight/2);
	  //alert("warming"); //OKAY !!
      }

  }


function positioning()
  {
  if(goodIE)
    {
    IH= document.body.clientHeight;
    IW= document.body.clientWidth;
    PX= document.body.scrollLeft;
    PY= document.body.scrollTop;
    if (typeof(bf) != "undefined") {
    bf.style.top=0;
//  bf.style.top= (IH+PY-botH);
    bf.style.left=(IW+PX-botW); }
    }


  else if(gecko)
    {
    IH= window.innerHeight;
    IW= window.innerWidth;
    PX= window.pageXOffset;
    PY= window.pageYOffset;
    if (typeof(document.getElementById("bfn")) != "undefined") {
		document.getElementById("bfn").style.top=0;
		//bf.style.top=0;
		document.getElementById("bfn").style.left=(IW+PX-botW-15);  // esse 14 muda com o skin do Gecko !!
		//bf.style.left=(IW+PX-botW);
		//alert("positioning");  // OKAY !!
		}
    }

/*
if (Zflag.NS) {
	layerstart = "document.";
	layerstyle = "";  }
if (Zflag.gecko){
	layerstart = "document.getElementById('";
	layerstyle = "').style"; }
if (Zflag.IE){
	layerstart = "document.all.";
	layerstyle = ".style"; }
*/

  }


function framing()
  {
  if (goodIE && navigator.appVersion.indexOf("Mac") == -1)
    {
    oldIW= IW;
    oldIH= IH;
    oldPX= PX;
    oldPY= PY;
    if ((document.body.clientHeight != oldIH) ||
        (document.body.clientWidth != oldIW) ||
        (document.body.scrollLeft != oldPX) ||
        (document.body.scrollTop != oldPY))
      positioning();
    fra = setTimeout("framing()", 200);
    }

  else if (gecko)
    {
    oldIW= IW;
    oldIH= IH;
    oldPX= PX;
    oldPY= PY;
    if ((window.innerHeight != oldIH) ||
        (window.innerWidth != oldIW) ||
        (window.pageXOffset != oldPX) ||
        (window.pageYOffset != oldPY))
      positioning();
    fra = setTimeout("framing()", 200);
	//alert ("framing");   fica chamando infinitamente.... CUIDADO !!!
    }
  
  }


function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 )
         return a.getAttribute("title");
  }
  return null;
}


function diving()
  {
    // testa a existência de um stylesheet para evitar colocar o frame torto.
    if (getActiveStyleSheet() != null) {

    if (goodIE)
      {
      if (window.document.bgColor == "#99ccff") arq="art/frame_blue.gif";
      if (window.document.bgColor == "#b4c85a") arq="art/frame_green.gif";
      if (window.document.bgColor == "#e9967a") arq="art/frame_salmon.gif";
      if (window.document.bgColor == "#dcdcdc") arq="art/frame_main.gif";
      if (window.document.bgColor == "#000000") arq="art/frame_black.gif";
      //alert(window.document.bgColor);
      document.write('<DIV ID="bf" align="right"><img src="' + arq + '" height=26' +
		   ' width=1600 alt="" border="0"></DIV>'
                    );
      }

    else if (gecko)
      {
	  // alert ("diving");  OKAY !!
	  if (window.document.bgColor == "#99ccff") arq="art/frame_blue.gif";
      if (window.document.bgColor == "#b4c85a") arq="art/frame_green.gif";
      if (window.document.bgColor == "#e9967a") arq="art/frame_salmon.gif";
      if (window.document.bgColor == "#dcdcdc") arq="art/frame_main.gif";
      if (window.document.bgColor == "#000000") arq="art/frame_black.gif";
	  //alert(arq);  //OKAY !!
      document.write('<DIV ID="bfn" align="right"><img src="' + arq + '" height=26' +
		   ' width=1600 alt="" border="0"></DIV>'
                    );
      //alert(window.document.bgColor);  //OKAY !!
      }

    }
  }



function upper_bar()
  {
   warming();
   positioning();
   framing();
  }


window.onload=upper_bar;
