var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	]

};
BrowserDetect.init();

function abreEscondeObjeto(objetoId){
	var checkStatus = document.getElementById(objetoId).style.display;

	if(checkStatus == "none"){
		var setaStatus = "block";
	}else{
		var setaStatus = "none";
	}
	
	document.getElementById(objetoId).style.display = setaStatus;	
}

// ----- Menu -----

function exibe(x,acao){
	obj=document.getElementById(x);
	if (acao==1){
		if(BrowserDetect.browser == "Explorer" && BrowserDetect.version <= 6)
			combos_visiveis(true);
	
		obj.style.display="none";
	}
	else{
		if(BrowserDetect.browser == "Explorer" && BrowserDetect.version <= 6)
			combos_visiveis(false);

		obj.style.display="block";
	}
}

/* POPUP */
tela = {
	moveTo : function(x,y) { window.scroll(x,y); },
	moveBy : function(x,y) { this.moveTo(this.sx()+x,this.sy()+y) },
	sx : function() { return (is.ie) ? (document.body.scrollLeft) : (window.pageXOffset) },
	sy : function() { return (is.ie) ? (document.body.scrollTop) : (window.pageYOffset) },
	dw : function() { return (is.ie) ? (document.body.scrollWidth) : (document.width) },
	dh : function() { return (is.ie) ? (document.body.scrollHeight) : (document.height) },
	ww : function() { return (is.ie) ? (document.body.clientWidth) : (window.innerWidth) },
	wh : function() { return (is.ie) ? (document.body.clientHeight) : (window.innerHeight) },
	sw : function() { return (screen.width) },
	sh : function() { return (screen.height) }
};

function abreJanela(pagina,largura,altura,nome,mais) {
	calcleft = (tela.sw() / 2) - (largura / 2);
	calctop = (tela.sh() / 2) - (altura / 2);
	FTecno_pop = window.open(''+pagina+'',''+nome+'','width='+largura+',height='+altura+',left='+calcleft+',top='+calctop+',scrollbars=yes'+((mais)? ',' + mais : ''));
	FTecno_pop.focus();
}

function abreJanelaSemScroll(pagina,largura,altura,nome,mais) {
	calcleft = (tela.sw() / 2) - (largura / 2);
	calctop = (tela.sh() / 2) - (altura / 2);
	FTecno_pop = window.open(''+pagina+'',''+nome+'','width='+largura+',height='+altura+',left='+calcleft+',top='+calctop+',scrollbars=no'+((mais)?','+mais:''));
	FTecno_pop.focus();
}

function pops(pg,nome,fs,w,h,rolagem) {
	if(fs) { // fullscreen
		var w=screen.availWidth,h=screen.availHeight;
		var winObj = window.open(pg,nome,'width='+w+',height='+h+',directories=0,location=0,menubar=0,resizable=0,scrollbars='+rolagem+',status=0,toolbar=0,marginleft=0,margintop=0,left=0,top=0');
		with(winObj) { moveTo(0,0); resizeTo(w,h); focus(); }
	} else { // popup normal
		var winObj=window.open(pg,nome,'width='+w+',height='+h+',directories=0,location=0,menubar=0,resizable=0,scrollbars='+rolagem+',status=0,toolbar=0,marginleft=0,margintop=0,left='+(((screen.width-w)/2)+-10)+',top='+(((screen.height-h)/2)+-30));
		winObj.focus();
	}
}


function Formatar(src, mask) {
 if (src.value.length > mask.length) {
  src.value = src.value.substring(0,mask.length);
  return false;
 }
 var i = src.value.length;
 var saida = mask.substring(0,1);
 var texto = mask.substring(i)
 if (texto.substring(0,1) != saida) 
  src.value += texto.substring(0,1);
}

function SC_numero(e)
{ 
  navegador = /msie/i.test(navigator.userAgent); 
  if (navegador) 
   var tecla = event.keyCode; 
  else 
   var tecla = e.which; 
   
  if(tecla > 47 && tecla < 58) // numeros de 0 a 9 
    return true; 
  else 
    { 
      if (tecla != 8) // backspace 
        return false; 
      else 
        return true; 
    } 
} 

function FavoritosAdd(titulo, url)
{
	if (document.all)
		window.external.AddFavorite(url, titulo)
} 


function FormataValor(obj,tammax,teclapres) 
{
	 var tecla = teclapres.keyCode;
	 vr = obj.value;
	 vr = vr.replace( "/", "" );
	 vr = vr.replace( "/", "" );
	 vr = vr.replace( ",", "" );
	 vr = vr.replace( ",", "" );
	 vr = vr.replace( ".", "" );
	 vr = vr.replace( ".", "" );
	 vr = vr.replace( ".", "" );
	 vr = vr.replace( ".", "" );
	 //Replaces adicionais
	 //vr = vr.replace( "-", "" );
	 //vr = vr.replace( "+", "" );
	 //vr = vr.replace( "*", "" );
	 tam = vr.length;
	 
	 if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }
	 
	 if (tecla == 8 ){ tam = tam - 1 ; }
	  
	 if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
	  if ( tam <= 2 ){ 
	   obj.value = vr ; }
	  if ( (tam > 2) && (tam <= 5) ){
	   obj.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	  if ( (tam >= 6) && (tam <= 8) ){
	   obj.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	  if ( (tam >= 9) && (tam <= 11) ){
	   obj.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	  if ( (tam >= 12) && (tam <= 14) ){
	   obj.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	  if ( (tam >= 15) && (tam <= 17) ){
	   obj.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
 }
 
 }
 
 function aplicaFlash(swf, width, height, wmode, cache) {
 var noCache = "";
 if (cache == undefined || cache == '') {var noCache = "?" + new Date();}
 if (wmode != "opaque" && wmode != "transparent") {wmode = "transparent";}
 var monta_swf = "";
 
 monta_swf += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='"+ width +"' height='"+ height +"' title=''>";
 monta_swf += "<param name='movie' value='"+ swf + noCache +"'>";
 monta_swf += "<param name='quality' value='high'>";
 monta_swf += "<param name='menu' value='0'>";
 monta_swf += "<param name='wmode' value='"+ wmode +"'>";
 monta_swf += "<embed src='"+ swf + noCache +"' quality='high' wmode='"+ wmode +"' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+ width +"' height='"+ height +"'></embed>";
 monta_swf += "</object>";
 
 document.write(monta_swf);
}

 function aplicaFlash2(swf, width, height, wmode, cache) {
 var noCache = "";
 if (cache == undefined || cache == '') {var noCache = "?" + new Date();}
 if (wmode != "opaque" && wmode != "transparent") {wmode = "transparent";}
 var monta_swf = "";
 
 monta_swf += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='"+ width +"' height='"+ height +"' title=''>";
 monta_swf += "<param name='movie' value='"+ swf + noCache +"'>";
 monta_swf += "<param name='quality' value='high'>";
 monta_swf += "<param name='scale' value='noscale'>";
 monta_swf += "<param name='menu' value='0'>";
 monta_swf += "<param name='wmode' value='"+ wmode +"'>";
 monta_swf += "<embed src='"+ swf + noCache +"' quality='high' scale='noscale' wmode='"+ wmode +"' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+ width +"' height='"+ height +"'></embed>";
 monta_swf += "</object>";
 
 document.write(monta_swf);
}

             function aplicaFlashHome(swf, width, height, FlashVars, wmode, cache) {
                 var noCache = "";
                 if (cache == undefined || cache == '') {var noCache = "?" + new Date();}
                 if (wmode != "opaque" && wmode != "transparent") {wmode = "opaque";}
                 var monta_swf = "";
                 
                 monta_swf += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='"+ width +"' height='"+ height +"' title=''>";
                 monta_swf += "<param name='movie' value='"+ swf + noCache +"'>";
                 monta_swf += "<param name='quality' value='high'>";
                 monta_swf += "<param name='menu' value='0'>";
                 monta_swf += "<param name='wmode' value='"+ wmode +"'>";
                 monta_swf += '<param name="allowScriptAccess" value="always" />';
                 monta_swf += '<param name="FlashVars" value="' + FlashVars + '" />';                                 
                 monta_swf += "<embed src='"+ swf + noCache +"' quality='high' wmode='"+ wmode +"' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+ width +"' height='"+ height +"'></embed>";
                 monta_swf += "</object>";
                 
                 document.write(monta_swf); 
            }


           


function Redireciona(links) 
{ 
	setTimeout("document.location.href = '"+ links +"';", 1000); 
}

function combos_visiveis(y){
 var v_combo = document.getElementsByTagName("select");
 
 for (i = 0; i < v_combo.length; i++) {
	if(v_combo[i].name != 'ctl00$esmpLeftBar$LeftBar_MenuUnidades1$ddlUnidades')
	{
	   if (y == false){  //Se y = 1 todas as tags "select" do ducumento ficam ocultas
	   v_combo[i].style.visibility = "hidden";
	   }else{
	   v_combo[i].style.visibility = "";  
	   }
	}
 }  
}

// COOKIES VIA JAVA SCRIPT

//INICIO

function getCookie(key) {    
        var search = key + "="   
        var returnvalue = "";   
        if (document.cookie.length > 0) {   
            offset = document.cookie.indexOf(search)   
            if (offset != -1) {    
                offset += search.length   
                end = document.cookie.indexOf(";", offset);   
                if (end == -1)   
                    end = document.cookie.length;   
                returnvalue=unescape(document.cookie.substring(offset, end))   
            }   
        }   
        return returnvalue;   
    }   

function setCookie(key, value) {
	myDate = new Date('30/12/2010 12:00 AM');
	var the_cookie = key + "=" + value + ";path = /; expires=Fri, 27 Jul 2020 02:47:11 UTC;" ;   
        document.cookie = the_cookie;   
    }

//FIM


	function openBox(){
		if(document.all){
			document.getElementById('fade').style.height = document.body.clientHeight+"px";
		}else{
			document.getElementById('fade').style.height = (document.body.clientHeight+20)+"px";			
		}
		document.getElementById('fade').style.display='block';
		document.getElementById('light').style.display='block';
	}
	
	function closeBox(){
		document.getElementById('light').style.display='none';
		document.getElementById('fade').style.display='none';		
	}


            function montaSWF(url,width,height,FlashVars)
            {
                var ret = '';
                ret += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + width + '" height="' + height + '" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">';
                ret += '<param name="movie" value="' + url + '" />';
                ret += '<param name="quality" value="high" />';
                ret += '<param name="bgcolor" value="#FFFFFF" />';
                ret += '<param name="wmode" value="opaque" />';
                ret += '<param name="allowScriptAccess" value="always" />';
                ret += '<param name="FlashVars" value="' + FlashVars + '" />';
                ret += '<embed src="' + url + '" wmode="opaque" quality="high" bgcolor="#FFFFFF" width="' + width + '" height="' + height + '" align="middle" play="true" loop="false" FlashVars="' + FlashVars + '" quality="high" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer">';
                ret += '</embed>';
                ret += '</object>';
                document.write(ret);
            }
	
