function troca(im) {
        document.logo.src="imgs/" + im;
}
function link(url) {
   location.href = escape(url);
}

function SetCookie (name, value)    {
   var argv = SetCookie.arguments;
   var argc = SetCookie.arguments.length;
   var expires = (argc > 2) ? argv[2] : null;
   var path = "/";
   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 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 "";
   }


function load(valor,url) {
	
	SetCookie("form_id", valor);
	show(url);

}


function show(url) {
	var popupfomr=null;
	url=escape(url);
	popupform=window.open(url,'new','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,menubar=no')
	if(popupfomr!=null)
		{popupform.location.href=url
	}
}



function Help() {

	var msg = "Autenticação\r Para ter acesso a esta opção é necessário\r seu Usuário e Senha da Intranet, caso ainda\r não tenha um solicite-o agora mesmo na\r área de Recursos Humanos";
	alert(msg);

}	
		

function PreTest() {
		
	//if ((document.aut.user.value) && (document.aut.pass.value)) { document.aut.submit(); }
	if (document.aut.user.value) { document.aut.submit(); }
		else { alert ("Para prosseguir você precisa preencher os campos Usuário e Senha"); }
		
}		

function CheckPass() {

	if (document.aut.pass.value == document.aut.pass2.value) { 

		document.aut.submit() ;

	} else {

		alert("Redigite a senha");

	}
}

function colore(celula)
{

   data = celula + "|";
   celula = document.getElementById(celula);
   if((celula.style.backgroundColor=="#cccccc") || (celula.style.backgroundColor=="rgb(204,204,204)")) {
       celula.style.backgroundColor="#FFFFFF";
       num_inicio = document.formulario.datas.value.indexOf(data);
       num_fim = num_inicio + 11;
       document.formulario.datas.value = document.formulario.datas.value.slice(0,num_inicio) + document.formulario.datas.value.slice(num_fim);
       document.formulario.numc.value = (document.formulario.numc.value - 1);
       
   } else {

       celula.style.backgroundColor="#CCCCCC";
       document.formulario.datas.value += data;
       document.formulario.numc.value = (1 + eval(document.formulario.numc.value));
   }
}


function valorPorExtenso(c)
	{
	if(c == "" || c < 0 || c >=10000000)
		{
		return(-1);
		}
	else
		{
		if(c == 0)
			{
			return(" ZERO ");
			}
		else
			{
			aUnid = new Array();
			aDezena = new Array();
			aCentena = new Array();
			aGrupo = new Array();
			aTexto = new Array();

			aUnid[1] = "UM ";
			aUnid[2] = "DOIS ";
			aUnid[3] = "TRÊS ";
			aUnid[4] = "QUATRO ";
			aUnid[5] = "CINCO ";
			aUnid[6] = "SEIS ";
			aUnid[7] = "SETE ";
			aUnid[8] = "OITO ";
			aUnid[9] = "NOVE ";
			aUnid[10] = "DEZ ";
			aUnid[11] = "ONZE ";
			aUnid[12] = "DOZE ";
			aUnid[13] = "TREZE ";
			aUnid[14] = "QUATORZE ";
			aUnid[15] = "QUINZE ";
			aUnid[16] = "DEZESSEIS ";
			aUnid[17] = "DEZESETE ";
			aUnid[18] = "DEZOITO ";
			aUnid[19] = "DEZENOVE ";

			aDezena[1] = "DEZ ";
			aDezena[2] = "VINTE ";
			aDezena[3] = "TRINTA ";
			aDezena[4] = "QUARENTA ";
			aDezena[5] = "CINQÜENTA ";
			aDezena[6] = "SESSENTA ";
			aDezena[7] = "SETENTA ";
			aDezena[8] = "OITENTA ";
			aDezena[9] = "NOVENTA ";

			aCentena[1] = "CENTO ";
			aCentena[2] = "DUZENTOS ";
			aCentena[3] = "TREZENTOS ";
			aCentena[4] = "QUATROCENTOS ";
			aCentena[5] = "QUINHENTOS ";
			aCentena[6] = "SEISCENTOS ";
			aCentena[7] = "SETECENTOS ";
			aCentena[8] = "OITOCENTOS ";
			aCentena[9] = "NOVECENTOS ";

			if(c.indexOf(".") != -1)
				{
				aGrupo[4] = c.substring(c.indexOf(".")+1,c.length);
				aGrupo[4] = aGrupo[4].substring(0,2);
				ct = c.substring(0,c.indexOf("."));
				}
			else
				{
				if(c.indexOf(",") != -1)
					{
					aGrupo[4] = c.substring(c.indexOf(",")+1,c.length);
					aGrupo[4] = aGrupo[4].substring(0,2);
					ct = c.substring(0,c.indexOf(","));
					}
				else
					{
					aGrupo[4] = "00";
					ct = c;
					}
				tt = "";
				for(f=0;f<(10-ct.length);f++)
					{
					tt += "0";
					}
				tt += ct;
				}
			aGrupo[1] = tt.substring(1,4);
			aGrupo[2] = tt.substring(4,7);
			aGrupo[3] = tt.substring(7,10);
			aGrupo[4] = "0"+aGrupo[4];

			for(f=1;f<5;f++)
				{
				cParte = aGrupo[f];
				if(parseFloat(cParte) < 10)
					{
					nTamanho = 1;
					}
				else
					{
					if(parseFloat(cParte) < 100)
 						{
						nTamanho = 2;
						}
					else
						{
						if(parseFloat(cParte) < 1000)
							{
							nTamanho = 3;
							}
						else
							{
							nTamanho = 0;
							}
						}
					}
				aTexto[f] = "";
				if(nTamanho == 3)
					{
					if(cParte.substring(1,3) != "00")
						{
						aTexto[f] += aCentena[cParte.substring(0,1)] + "E ";
						nTamanho = 2;
						}
					else
						{
						if(cParte.substring(0,1) == "1")
							{
							aTexto[f] += "CEM ";
							}
						else
							{
							aTexto[f] += aCentena[cParte.substring(0,1)];
							}
						}
					}
				if(nTamanho == 2)
					{
					if(parseFloat(cParte.substring(1,3)) < 10)
						{
						aTexto[f] += aUnid[cParte.substring(2,3)];
						}
					else
						{
						if(parseFloat(cParte.substring(1,3)) < 20)
							{
							aTexto[f] += aUnid[cParte.substring(1,3)];
							}
						else
							{
							aTexto[f] += aDezena[cParte.substring(1,2)];
							if(cParte.substring(2,3) != "0")
								{
								aTexto[f] += "E ";
								nTamanho = 1;
								}
							}
						}
					}
				if(nTamanho == 1)
					{
					aTexto[f] += aUnid[cParte.substring(2,3)];
					}
				}
			if(parseFloat(aGrupo[1] + aGrupo[2] + aGrupo[3]) == 0 && parseFloat(aGrupo[4]) != 0)
				{
				cFinal = aTexto[4];
				if(parseFloat(aGrupo[4]) == 1)
					{
					cFinal +=  "CENTAVO";
					}
				else
					{
					cFinal +=  "CENTAVOS";
					}
				}
			else
				{
				if(parseFloat(aGrupo[1]) != 0)
					{
					cFinal = aTexto[1];
					if(parseFloat(aGrupo[1]) > 1)
						{
						cFinal += "MILHÕES ";
						}
					else
						{
						cFinal += "MILHÃO ";
						}
					if(parseFloat(aGrupo[2] + aGrupo[3]) == 0)
						{
						cFinal += "DE ";
						}
					else
						{
						cFinal += "E ";
						}
					}
				else
					{
					cFinal = "";
					}
				if(parseFloat(aGrupo[2]) != 0)
					{
					cFinal += aTexto[2] + "MIL ";
					if(parseFloat(aGrupo[3]) != 0)
						{
						cFinal += "E ";
						}
					}
				if(parseFloat(aGrupo[3]) != 0)
					{
					cFinal += aTexto[3];
					}
				if(parseFloat(aGrupo[1] + aGrupo[2] + aGrupo[3]) == 1)
					{
					cFinal += "REAL";
					}
				else
					{
					cFinal += "REAIS";
					}
				if(parseFloat(aGrupo[4]) != 0)
					{
					cFinal += " E "+aTexto[4];
					if(parseFloat(aGrupo[4])==1)
						{
						cFinal += "CENTAVO";
						}
					else
						{
						cFinal += "CENTAVOS";
						}
					}
				}
			return(cFinal);
			}
		}
	}

function FormataMoeda(campo) {
	vr = campo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( ",", "" );
	tam = vr.length ;

	campo.value='';
	if (tam > 2) campo.value += vr.substr(0 ,(tam - 2)) + '.';
	if (tam) campo.value += vr.substr( (tam -2), 2 );
	if (tam  == 1) campo.value = vr + '.00' ;
	if (tam  == 2) campo.value = vr + '.00' ;

}
function FormataMoedaReal(campo) {
	vr = campo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( ",", "" );
	tam = vr.length ;

	campo.value='';
	if (tam > 5)  campo.value = vr.substr( 0, (tam -5) ) + '.';
	if ((tam > 2) && (tam < 6)) campo.value += vr.substr(0 ,(tam - 2)) + '.';
	if (tam > 5)  campo.value += vr.substr((tam - 5) ,3) + '.';
	if (tam) campo.value += vr.substr( (tam -2), 2 );
	if (tam  == 1) campo.value = vr + '.00' ;
	if (tam  == 2) campo.value = vr + '.00' ;

}
function FormataTempo(campo,tipo) {
	
	vr = campo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( ":", "" );
	tam = vr.length;
	if (tipo) {
		if (vr.length == 4) {
			campo.value = vr.substr( 0, 2 ) + ':' + vr.substr( 2, 2 );
		}
	} else {
		if (vr.length == 6) {
			campo.value = vr.substr( 0, 2 ) + ':' + vr.substr( 2, 2 ) + ':' + vr.substr( 4, 2 );
		}
	}
	if (tipo) {
		if ( campo.value.length > 5 ) campo.value = campo.value.substr(0,5);
		if ( campo.value.length == 5 ) Valida_tempo_curto(campo.value);
	} else {
		if ( campo.value.length > 8 ) campo.value = campo.value.substr(0,7);
		if ( campo.value.length == 8) Valida_tempo(campo.value);
	}
}


function Valida_tempo(hora){
	h = hora.substr(0, 2);
	m = hora.substr(3, 2);
	s = hora.substr(7, 2);

	if ( (h > 99) || (m > 59) || (s > 59) ){
		alert("Tempo inválido.");
		return false;
	}
	return true;
}

function Valida_tempo_curto(min){
	m = min.substr(0, 2);
	s = min.substr(3, 2);
	if ( (m > 59) || (s > 59)  ){
		alert("Tempo inválido.");
		return false;
	}
	return true;
}


/******************************************/
function FormataHora(campo, prox, teclapress) {
if (FormataHora.arguments.length == 1){
	prox = 0;
	tecla = 41;
}
if (FormataHora.arguments.length == 2){
	prox = FormataHora.arguments[1];
	tecla = 41;
}
if (FormataHora.arguments.length == 3){
	prox = FormataHora.arguments[1];
	tecla = FormataHora.arguments[2].keyCode;
}
	vr = campo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( ":", "" );
	tam = vr.length;
//alert(tecla);
/* Se for passado prox e tecla diferente de DEL, BACKSPACE, ENTER e DIRECIONAIS */
	if ( (tecla > 40) && (tecla != 46) ){
		if ( tam == 4 ){
			campo.value = vr.substr( 0, tam - 2  ) + ':' + vr.substr( tam - 2, tam );
		}
		if ( campo.value.length > 5 ) campo.value = campo.value.substr(0,4);
		if ( campo.value.length == 5){
			if ( ValidaHora(campo.value) ){
				if (prox)
					prox.select();
			}else{
				alert("Hora inválida!");
				campo.select();
			}
		}
	}
}


function ValidaHora(hora){
	h = hora.substr(0, 2);
	m = hora.substr(3, 2);
//alert(h + " : " + m);
	if ( (h > 23) || (m > 59) ){
//		alert("Hora inválida.");
		return false;
	}
	return true;
}


function FormataData(campo, prox, teclapress) {
if (FormataData.arguments.length == 1){
	prox = 0;
	tecla = 41;
}
if (FormataData.arguments.length == 2){
	prox = Formata_Data.arguments[1];
	tecla = 41;
}
if (FormataData.arguments.length == 3){
	prox = FormataData.arguments[1];
	tecla = FormataData.arguments[2].keyCode;
}
	vr = campo.value;
if( (vr.charAt(3) != "/") && (vr.charAt(4) != "/") ){
	vr = vr.replace( /[a-z]/, "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length;
/* Se for passado prox e tecla diferente de DEL, BACKSPACE e DIRECIONAIS */
	if ( (tecla > 40) && (tecla != 46) ){
		if ( tam  == 4 )
			campo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 8 ){
			campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
		}
		if ( campo.value.length > 10 ) campo.value = campo.value.substr(0,9);
		if ( campo.value.length == 10){
//alert(prox.name);
			if ( ValidaData(campo.value) ){
				if (prox)
					prox.select();
			}else{
				alert("Data inválida!");
				campo.select();
			}
		}
	}
}// if( vr.charAt() ...
}

function FormataDataMesAno(campo, prox, teclapress) {
	if (FormataDataMesAno.arguments.length == 1){
		prox = 0;
		tecla = 41;
	}
	if (FormataDataMesAno.arguments.length == 2){
		prox = Formata_DataMesAno.arguments[1];
		tecla = 41;
	}
	if (FormataDataMesAno.arguments.length == 3){
		prox = FormataDataMesAno.arguments[1];
		tecla = FormataDataMesAno.arguments[2].keyCode;
	}
		vr = campo.value;
	if( (vr.charAt(3) != "/")){
		vr = vr.replace( /[a-z]/, "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( "/", "" );
		vr = vr.replace( "/", "" );
		tam = vr.length;
	/* Se for passado prox e tecla diferente de DEL, BACKSPACE e DIRECIONAIS */
		if ( (tecla > 40) && (tecla != 46) ){
			if ( tam  == 4 )
				campo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
			if ( tam >= 5 && tam <= 6 ){
				campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 4 );
			}
			if ( campo.value.length > 7 ) campo.value = campo.value.substr(0,7);
		}
	}
}

function ValidaData(data){
	status = 0;
	ano = data.substr(6, 4);
	mes = data.substr(3, 2);
	dia = data.substr(0, 2);
//alert(data + " " + dia + " " + mes + " " + ano);

	if ( (dia > 0) && (dia <= 31) ){	//testa dia dentro do limite
		if ( (mes > 0) && (mes <= 12) ){//testa mes dentro do limite
			if ( ((mes == 1) || (mes == 3) || (mes == 5) || (mes == 7) || (mes == 8) || (mes == 10) || (mes == 12)) && (dia > 31) ){
				status = 1;
			}
			if ( ((mes == 4) || (mes == 6) || (mes == 9) || (mes == 11)) && (dia > 30) ){
				status = 2;
			}

			if (ano % 4){	//ano  Não bissexto
				if ( (mes == 2) && (dia > 28) ){
					status = 3;
				}
			}else{	//ano bissexto
				if ( (mes == 2) && (dia >29) ){
					status = 4;
				}
			}
		}else{
			status = 5;
		}
	}else{
		status = 6;
	}
	if (status > 0){
//		alert("Data inválida.");
		return false;
	}
	return true;
}
/**********************************************/


function CountDown(textName,fieldName,max,formName) {
	if (textName.value.length > eval(max)) {
		textName.value = textName.value.substring(0,eval(max));
	}
	eval(fieldName).value = (eval(max) - textName.value.length) ;

}

function PopUp(url,largura,altura,nome,topo,esquerda,bar,scroll,res) {
	if (!(esquerda)) esquerda = 40;
	if (!(topo)) topo = 10;
	if (!(altura)) altura = 250;
	if (!(largura)) largura = 330;
	if (!(bar)) scroll = 1;
	if (!(nome)) nome = "Pesquisa";
	if (!(res)) res = 0;

	window.open( url, nome, "left=" + esquerda + ",top=" + topo + ",width=" + largura + ",height=" + altura + ",resizable=" + res + ",scrollbars=" + scroll + ",toolbar=0,status=0,location=0,directories=0,menubar=0"); 
}


function PopUpPesquisa(url,nome,altura,largura,topo,esquerda) {
	if (!(esquerda)) esquerda = 400;
	if (!(topo)) topo = 180;
	if (!(altura)) altura = 250;
	if (!(largura)) largura = 330;
	if (!(nome)) nome = "Pesquisa";

	window.open( url, nome, "left=" + esquerda + ",top=" + topo + ",width=" + largura + ",height=" + altura + ",resizable=1,scrollbars=1,toolbar=0,status=0,location=0,directories=0,menubar=0"); 
}

function PopUpUser(t,u) {
        window.open("pesquisausuario.php?user="+t+"&data="+u,"Mostra","scrollbars=no,width=250,height=250");
}


function MM_findObj(n, d) { //v4.0
	var p,i,x;
	if(!d)
		d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length)
	{
      	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
        if(!(x=d[n])&&d.all)
		x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++)
		x=d.forms[i][n];
 	for(i=0;!x&&d.layers&&i<d.layers.length;i++)
		x=MM_findObj(n,d.layers[i].document);
    	if(!x && document.getElementById)
		x=document.getElementById(n);
	return x;
}

function MM_ShowLayer(obj) {
        document.getElementById(obj).style.visibility='visible';
        document.getElementById(obj).style.height='';
}

function MM_HideLayer(obj) {
        document.getElementById(obj).style.visibility='hidden';
        document.getElementById(obj).style.height='1px';
}

function MM_showHideLayers() { //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3)
	if ((obj=MM_findObj(args[i]))!=null)
	{
		v=args[i+2];
	    	if (obj.style)
		{
			obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v;
		}
	        obj.visibility=v;
	}
}

function RPC_Menu(layer){
	var nets = navigator.appName == "Netscape";
	var ns4 = (nets && parseInt(navigator.appVersion) == 4);
	var rpclayer = MM_findObj(layer+'_layer');

	if (!ns4)
	{
		if (rpclayer.style['visibility']=='visible' || rpclayer.style['visibility']=='show')
		{
			MM_showHideLayers(layer+'_layer','','hide');
			rpclayer.style['height'] = '1px';
		}
		else
		{
			MM_showHideLayers(layer+'_layer','','show');
			rpclayer.style['height'] = '';
		}
	}
}

			

function RPC_TrocaImagem (nome, img_um, img_dois)
{
	rpcimagem = MM_findObj(nome);

	if (rpcimagem.src.indexOf (img_um) != -1)
	{
		nova_imagem = img_dois;
	}
	else
	{
		nova_imagem = img_um;
	}

	MM_swapImage (nome, '', nova_imagem, 1);
}

function MM_swapImage() { //v3.0
     var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
     if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function ShowPic(url,titulo,greetingtxt)
{
	var myDiv = document.getElementById('divPic');
	myDiv.style.visibility = 'visible';
	var img = "";
	if (url) img = '<BR><img src = \''+url+'\' height=\'200\'>';

	myDiv.innerHTML = titulo+img+'<table width=\'210\' class=\'divMagnifytd\' border=0><tr><td>'+greetingtxt+'</td></tr></table>';
	
}

function MovePic(e)
{
	var myDiv = document.getElementById('divPic');
	
	/* coloque  as  seguintes linhas na sua página:
	document.onmousemove = MovePic;
	var x=0;
	var y=0;
	*/
	
	
	if (myDiv)
	{
		var divWidth = myDiv.offsetWidth;
		z =  document.body.scrollTop;
		if (z > 200) z = (110 + (z/8));
		if (z > 200) z = (110 + (z/8));

		if (window.navigator.userAgent.indexOf("MSIE") > 0) { 
			x = window.event.clientX + document.body.scrollLeft+20;

			y = window.event.clientY + document.body.scrollTop-220;
			
		} else {
			x = e.pageX + document.body.scrollLeft+20;
		
			y = e.pageY - 200 + z;
		}
		if (x > 680) x = 550;

		if (myDiv)
		{
			myDiv.style.top = y  + 'px';
			myDiv.style.left = x+'px';
		}
	}
}

function HidePic()
{				
	var myDiv = document.getElementById('divPic');
	myDiv.style.visibility = 'hidden';				
	myDiv.innerHTML = '';
}




