<!-- ATUALIZADO EM 09:35 23/2/2005 -->
function ConverteValorCalculo(String1) {
	if (String1 != '') {
		String1 = String1.replace( ".", "" );
		String1 = String1.replace( ".", "" );
		String1 = String1.replace( ".", "" );
		String1 = String1.replace( ".", "" );
		String1 = String1.replace( ".", "" );
		String1 = String1.replace( ",", "." ); } 
	else
		String1 = 0;
	return (String1);
	}
	
//Formata um numero apos ter feito a conta para exibicao com duas casa decimais
function FormataValorExibir(String1) {
	tammax = 20;
	valorSemFormato = ConverteValorCalculo(String1);
	tamanho = valorSemFormato.length;
	
	if (tamanho <= 4)
		{ 
		if (valorSemFormato == '0.00')
			res = "0,00";
		else
			res = valorSemFormato.substr(0,1) + "," + valorSemFormato.substr(2,2);
		}
		
	if (tamanho == 5)
	 	res = valorSemFormato.substr(0,2) + "," + valorSemFormato.substr(3,2);
	if (tamanho == 6)
	 	res = valorSemFormato.substr(0,3) + "," + valorSemFormato.substr(4,2);
	if (tamanho == 7)
	 	res = valorSemFormato.substr(0,1) + "." + valorSemFormato.substr(1,3) + "," + valorSemFormato.substr(5,2);		
	if (tamanho == 8)
	 	res = valorSemFormato.substr(0,2) + "." + valorSemFormato.substr(2,3) + "," + valorSemFormato.substr(6,2);
	if (tamanho == 9)
	 	res = valorSemFormato.substr(0,3) + "." + valorSemFormato.substr(3,3) + "," + valorSemFormato.substr(7,2);
	if (tamanho == 10)
	 	res = valorSemFormato.substr(0,1) + "." + valorSemFormato.substr(1,3) + "." + valorSemFormato.substr(4,3) + "," + valorSemFormato.substr(8,2);
	if (tamanho == 11)
	 	res = valorSemFormato.substr(0,2) + "." + valorSemFormato.substr(2,3) + "." + valorSemFormato.substr(5,3) + "," + valorSemFormato.substr(9,2);
	if (tamanho == 12)
	 	res = valorSemFormato.substr(0,3) + "." + valorSemFormato.substr(3,3) + "." + valorSemFormato.substr(6,3) + "," + valorSemFormato.substr(10,2);
	if (tamanho == 13)
	 	res = valorSemFormato.substr(0,1) + "." + valorSemFormato.substr(1,3) + "." + valorSemFormato.substr(4,3) + "." + valorSemFormato.substr(7,3) + "," + valorSemFormato.substr(11,2);
	if (tamanho == 14)
	 	res = valorSemFormato.substr(0,2) + "." + valorSemFormato.substr(2,3) + "." + valorSemFormato.substr(5,3) + "." + valorSemFormato.substr(8,3) + "," + valorSemFormato.substr(12,2);
	if (tamanho == 15)
	 	res = valorSemFormato.substr(0,3) + "." + valorSemFormato.substr(3,3) + "." + valorSemFormato.substr(6,3) + "." + valorSemFormato.substr(9,3) + "," + valorSemFormato.substr(13,2);
	if (tamanho == 16)
	 	res = valorSemFormato.substr(0,1) + "." + valorSemFormato.substr(1,3) + "." + valorSemFormato.substr(4,3) + "." + valorSemFormato.substr(7,3) + "." + valorSemFormato.substr(10,3) + "," + valorSemFormato.substr(14,2);
	if (tamanho == 17)
	 	res = valorSemFormato.substr(0,2) + "." + valorSemFormato.substr(2,3) + "." + valorSemFormato.substr(5,3) + "." + valorSemFormato.substr(8,3) + "." + valorSemFormato.substr(11,3) + "," + valorSemFormato.substr(15,2);
	if (tamanho == 18)
	 	res = valorSemFormato.substr(0,3) + "." + valorSemFormato.substr(3,3) + "." + valorSemFormato.substr(6,3) + "." + valorSemFormato.substr(9,3) + "." + valorSemFormato.substr(12,3) + "," + valorSemFormato.substr(16,2);
	if (tamanho == 19)
	 	res = valorSemFormato.substr(0,1) + "." + valorSemFormato.substr(1,3) + "." + valorSemFormato.substr(4,3) + "." + valorSemFormato.substr(10,3) + "." + valorSemFormato.substr(13,3) + "." + valorSemFormato.substr(13,3) + "," + valorSemFormato.substr(17,2);
	if (tamanho == 20)
	 	res = valorSemFormato.substr(0,2) + "." + valorSemFormato.substr(2,3) + "." + valorSemFormato.substr(5,3) + "." + valorSemFormato.substr(11,3) + "." + valorSemFormato.substr(14,3) + "." + valorSemFormato.substr(14,3) + "," + valorSemFormato.substr(18,2);

	return (res);
	}

//onKeyPress="return BloqueiaCaracteresEspeciais(this, event);"
function BloqueiaCaracteresEspeciais(campo, event)  {
	//var AspasSimples=39;
	//var AspasDupla=34;
	//var BackSpace=8; 
  	var key; 
  	var tecla;
  	if(navigator.appName.indexOf("Netscape")!= -1) 
  		tecla= event.which; 
  	else 
  		tecla= event.keyCode; 
  	key = String.fromCharCode( tecla); 
  	//alert( 'key: ' + tecla + ' -> campo: ' + campo.value); 
	//13=Espaco 39=AspasSimples 34=AspasDupla 8=BackSpace
  	if ( tecla == 13 || tecla == 39 || tecla == 34 || tecla == 8 ) 
  		return false;
	else
		return true;
  	}
	
// Verifica se campo preenchido
function CampoBranco(campo) {
	if(campo.value == "") return true;
	else return false;
	}
	
//Anima Barra de Status
function animastatus() {
	if (chars > -1) str = wtexto[chars]; 
	else str = wtexto[0];
	if (chars-- < -40) chars = 31;
	status = str;
	clearTimeout(tempo);
	tempo = setTimeout("animastatus()", 150);
	}
//Descomente a linha abaixo no aqruivo para executar
//animastatus();

function fncCarregando(Opc) {
	var Carregando = "<div id=\"Layer1\" style=\"position:relative; width:100%; height:100%; z-index:1; top: 0px; left: 0px;\">  <table width=\"100%\" height=\"100%\"  border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">  <tr> <td align=\"center\" valign=\"middle\">Aguarde Carregando...</td>  </tr>  </table>  </div> ";
	}

//type = image ou color default=color
function fnc_BtnCenterOver(src,clrOver,type) {
	//type=color
	if (type == '' || type == undefined || type == 'color') {
		if (!src.contains(event.fromElement)) {
			src.style.cursor = 'hand';
			src.style.color = clrOver;
			}
		}
	//type=image
	else if (type == 'image') {
		if (!src.contains(event.fromElement)) {
			src.style.cursor = 'hand';
			src.style.backgroundImage='url('+clrOver+')';
			}
		}
	//
	}
	
function fnc_BtnCenterOut(src,clrOut,type) {
	if (type == '' || type == undefined || type == 'color') {
		if (!src.contains(event.toElement)) {
			src.style.cursor = 'default';
			src.style.color = clrOut;
			}
		}
	//type=image
	else if (type == 'image') {
		src.style.cursor = 'hand';
		src.style.backgroundImage='url('+clrOut+')';
		}
	//
	}
	
function fnc_BtnCenterFocus(Obj,clrFocus,type) {
	if (type == '' || type == undefined || type == 'color')
		document.getElementById(Obj).style.color=clrFocus;
	else if (type == 'image')
		document.getElementById(Obj).style.backgroundImage='url('+clrFocus+')';
	}
	
function fnc_BtnCenterBlur(Obj,clrFocus,type) {	
	if (type == '' || type == undefined || type == 'color')
		document.getElementById(Obj).style.color=clrFocus;
	else if (type == 'image')
		document.getElementById(Obj).style.backgroundImage='url('+clrFocus+')';
	}

function ChkVar(str01) {
	if (str01 != undefined && str01 != '')
		return true;
	else 
		return false;
	}

//ADICIONA PAGINA FAVORITOS
function fnc_AdicFav(nome,url) {
	if ( (ChkVar(url) == false) || (ChkVar(nome) == false) ) {
		var url 	= 'http://www.inforen.com.br';
		var nome 	= 'Inforen - A informática na ponta dos dedos';
		}
	if (document.all)
		window.external.AddFavorite(url,nome);
	else
   		window.alert("O browser que você está usando não permite o uso deste comando.");
	}
	
/*** 
* Descrição.: formata um campo do formulário de 
* acordo com a máscara informada... 
* Parâmetros: - objForm (o Objeto Form) 
* - strField (string contendo o nome 
* do textbox) 
* - sMask (mascara que define o 
* formato que o dado será apresentado, 
* usando o algarismo "9" para 
* definir números e o símbolo "!" para 
* qualquer caracter... 
* - evtKeyPress (evento) 
* Uso.......: <input type=\"textbox\" 
* name="xxx"..... 
* onkeypress="return txtBoxFormat(document.rcfDownload, 'str_cep', '99999-999', event);"> 
* Observação: As máscaras podem ser representadas como os exemplos abaixo: 
* CEP -> 99.999-999 
* CPF -> 999.999.999-99 
* CNPJ -> 99.999.999/9999-99 
* Data -> 99/99/9999 
* Tel Resid -> (99) 999-9999 
* Tel Cel -> (99) 9999-9999 
* Processo -> 99.999999999/999-99 
* C/C -> 999999-! 
* E por aí vai... 
***/
/*
EXEMPLOS
CEP 		<input type="text" name="str_cep" maxlength="10" size="10" onkeypress="return txtBoxFormat(document.Form, 'str_cep', '99.999-999', event);">
CPF 		<input type="text" name="str_cpf" maxlength="14" size="14" onkeypress="return txtBoxFormat(document.Form, 'str_cpf', '999.999.999-99', event);">
CNPJ 		<input type="text" name="str_cnpj" maxlength="18" size="18" onkeypress="return txtBoxFormat(document.Form, 'str_cnpj', '99.999.999/9999-99', event);">
Data 		<input type="text" name="str_data" maxlength="10" size="10" onkeypress="return txtBoxFormat(document.Form, 'str_data', '99/99/9999', event);">
Tel Res 	<input type="text" name="str_tel2" maxlength="13" size="13" onkeypress="return txtBoxFormat(document.Form, 'str_tel2', '(99) 999-9999', event);">
Tel Cel 	<input type="text" name="str_tel" maxlength="14" size="14" onkeypress="return txtBoxFormat(document.Form, 'str_tel', '(99) 9999-9999', event);">
Processo	<input type="text" name="str_proc" maxlength="20" size="20" onkeypress="return txtBoxFormat(document.Form, 'str_proc', '99.999999999/9999-99', event);">
Conta		<input type="text" name="str_cc" maxlength="6" size="10"onkeypress="return txtBoxFormat(document.Form, 'str_cc', '9999-!', event);">
Codigo		<input type="text" name="str_cod" maxlength="10" size="10" onkeypress="return txtBoxFormat(document.Form, 'str_cod', '99999-9999', event);">
*/
function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

	if(document.all) { // Internet Explorer
		nTecla = evtKeyPress.keyCode; }
	else if(document.layers) { // Nestcape
		nTecla = evtKeyPress.which;
		}

	sValue = objForm[strField].value;

	// Limpa todos os caracteres de formatação que
	// já estiverem no campo.
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( " ", "" );
	sValue = sValue.toString().replace( " ", "" );
	fldLen = sValue.length;
	mskLen = sMask.length;

	i = 0;
	nCount = 0;
	sCod = "";
	mskLen = fldLen;

	while (i <= mskLen) {
		bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
		bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

		if (bolMask) {
			sCod += sMask.charAt(i);
			mskLen++;
			}
		else {
			sCod += sValue.charAt(nCount);
			nCount++;
			}
		i++;
		}

	objForm[strField].value = sCod;

	if (nTecla != 8) { // backspace
		if (sMask.charAt(i-1) == "9") { // apenas números...
			return ((nTecla > 47) && (nTecla < 58));
			} // números de 0 a 9
		else { // qualquer caracter...
			return true;
			}
		}
	else {
		return true;
		}
	}
//Fim da Função Máscaras Gerais

//COMPLETA CAMPO COM ZEROS A ESQUERDA - INICIO
function CompletaComZero(objForm, strField, Mask, evtKeyPress, tamReal) {
	//CAPTURA TEXTO DO CAMPO
	var strText = objForm[strField].value;
	
	//VERIFICA SE O CAMPO FOI PREENCHIDO
	if ( strText != '') {
		//RETIRA CARACTERES ESPECIAS DAS STRING
		strText = strText.toString().replace( "-", "" );
		strText = strText.toString().replace( "-", "" );
		strText = strText.toString().replace( ".", "" );
		strText = strText.toString().replace( ".", "" );
		strText = strText.toString().replace( "/", "" );
		strText = strText.toString().replace( "/", "" );
		strText = strText.toString().replace( "(", "" );
		strText = strText.toString().replace( "(", "" );
		strText = strText.toString().replace( ")", "" );
		strText = strText.toString().replace( ")", "" );
		strText = strText.toString().replace( " ", "" );
		strText = strText.toString().replace( " ", "" );
		
		var intTamStr = strText.length;
		/*verifica se o tamanho da string eh menor ou igual ao tamanho que eh pedido na funcão*/
		if (intTamStr <= tamReal) {//executa a adaptação do texto
			//preenchimento do campo com zero
			for (i=0; i<parseInt(tamReal) - intTamStr; i++){
				strText = "0" + strText;
				}
			objForm[strField].value = strText;
			return txtBoxFormat(objForm, strField, Mask, evtKeyPress);
			}
		}
	}
//COMPLETA CAMPO COM ZEROS A ESQUERDA - FIM

/*
['Label','Form','Name','Tp','QtdOpc','MsgErro','MsgErroTxt']
ITENS DO ARRAY
Label 		=> DESCRIÇÃO DO CAMPO
Form 		=> NOME DO FORMULARIO
Name		=> NOME REAL DO CAMPO
Tp			=> TIPO DO CAMPO - Text | Radio | Check | TextArea | File | Select
QtdOpc		=> QUANTIDADE DE OPÇÕES: CASO O CAMPO SEJA Radio OU Check PASSA A QUANTIDADE DE CAMPO COM MESMO NAME PARA AVALIAR
MsgErro		=> MENSAGEM DE ERRO: CASO CAMPO VENHA COM VALOR 0 NÃO EXIBI MENSAGEM DE ERRO PERSONALIZADA E SIM A PADRÃO QUE JÁ ESTA DENTRO DO SCRIPT CASO VENHA 1 O EXIBI A MENSAGEM DE ERRO PERSONALIZADA QUE ESTA NA VARIAVEL MsgErroTxt
MsgErroTxt	=> MENSAGEM DE ERRO TEXTO: CASO O VALOR CAMPO MsgErro VENHA COM VALOR 1 EXIBI MENSAGEM DE ERRO PERSONALIZADA

RETURN´S DE ERROS INTERNOS
0001	=> Array vazia ou passada de forma incorreta, tente novamente.
0002	=> Variavél MsgErro não tem valor ou valor passado errado, no tipo de campo Text. Valores corretos 0 para exibição de mensagem de erro padrão e 1 para mensagem de erro personalizada.
0003	=> Variavél MsgErro não tem valor ou valor passado errado, no tipo de campo File. Valores corretos 0 para exibição de mensagem de erro padrão e 1 para mensagem de erro personalizada.
0004	=> Opcões para variavel Tp Tipo de Campo invalida.
0005	=> Validação para Tp Tipo de Campo RadioButton para esta validação é necessario um valor numerico e diferente de ZERO para a variavel QtdOpc.
0006	=> Tipo de campo não corresponde ao objeto passado
*/
function ValidaCampo(ObjCampo) {
	if (ObjCampo.length <= 0) {
		alert('ERRO CÓDIGO: 0001.');
		return false;
		}	
	for(i=0;i<ObjCampo.length;i++) {
		//VARIAVEL strCampo = document.NomeDoForm.NomeDoCampo		
		eval( "strCampo = document." + ObjCmp[i][1] + "." + ObjCmp[i][2] );
		
		//Campo Tipo Text
		if (ObjCmp[i][3] == 'Text') {
			if(CampoBranco( strCampo ) == true) {
				if (ObjCmp[i][5] == 0)
					alert("Preencha o campo \""+ObjCmp[i][0]+"\".");
				else if (ObjCmp[i][5] == 1)
					alert(ObjCmp[i][6]);
				else {
					alert('ERRO CÓDIGO: 0002.');
					return false;
					}
				eval("document." + ObjCmp[i][1] + "." + ObjCmp[i][2] + ".focus()");
				return false;
				}
			}
		//Campo Tipo Radio
		else if (ObjCmp[i][3] == 'Radio') {
			if ( (ObjCmp[i][4] == 0) || (ObjCmp[i][4] == null) ) {
				alert('ERRO CÓDIGO: 0005.');
				return false;
				}
			var y = null;
			for(countX=0; countX < ObjCmp[i][4]; countX++) {
				if ( strCampo[countX].type != "radio") {
					alert('.ERRO CÓDIGO: 0006.');
					return false;
					}		
				if ( strCampo[countX].checked == true )
					y = 1;
				}
			if ( y == null) {
				if (ObjCmp[i][5] == 0)
					alert("Selecione o campo \""+ObjCmp[i][0]+"\".");
				else if (ObjCmp[i][5] == 1)
					alert(ObjCmp[i][6]);
				else {
					alert('ERRO CÓDIGO: 0002.');
					return false;
					}
				return false;
				}			
			}
		//Campo Tipo Check
		else if (ObjCmp[i][3] == 'Check') {
			if ( (ObjCmp[i][4] == 0) || (ObjCmp[i][4] == null) ) {
				alert('ERRO CÓDIGO: 0005.');
				return false;
				}
			var y = null;
			for(countX=0; countX < ObjCmp[i][4]; countX++) {
				if ( strCampo[countX].type != "checkbox") {
					alert('ERRO CÓDIGO: 0006.');
					return false;
					}		
				if ( strCampo[countX].checked == true )
					y = 1;
				}
			if ( y == null) {
				if (ObjCmp[i][5] == 0)
					alert("Selecione o campo \""+ObjCmp[i][0]+"\".");
				else if (ObjCmp[i][5] == 1)
					alert(ObjCmp[i][6]);
				else {
					alert('ERRO CÓDIGO: 0002.');
					return false;
					}
				return false;
				}			
			}
		//Campo Tipo TextArea
		else if (ObjCmp[i][3] == 'TextArea') {
			if ( strCampo.type != "textarea") {
				alert('ERRO CÓDIGO: 0006.');
				return false;
				}
			if(CampoBranco( strCampo ) == true) {
				if (ObjCmp[i][5] == 0)
					alert("Preencha o campo \""+ObjCmp[i][0]+"\".");
				else if (ObjCmp[i][5] == 1)
					alert(ObjCmp[i][6]);
				else {
					alert('ERRO CÓDIGO: 0002.');
					return false;
					}
				eval("document." + ObjCmp[i][1] + "." + ObjCmp[i][2] + ".focus()");
				return false;
				}					
			}
		//Campo Tipo File
		else if (ObjCmp[i][3] == 'File') {
			if(CampoBranco( strCampo ) == true) {
				if (ObjCmp[i][5] == 0)
					alert("Selecione ou Preencha o campo \""+ObjCmp[i][0]+"\" com o arquivo que deseja enviar.");
				else if (ObjCmp[i][5] == 1)
					alert(ObjCmp[i][6]);
				else {				
					alert('ERRO CÓDIGO: 0003.');
					return false;
					}
				eval("document." + ObjCmp[i][1] + "." + ObjCmp[i][2] + ".focus()");
				return false;
				}
			}
		//Campo Tipo Select
		else if (ObjCmp[i][3] == 'Select') {			
			//document.NomeDoForm.NomeDoCampo.options[document.NomeDoForm.NomeDoCampo.selectedIndex]
			if(CampoBranco( strCampo.options[ strCampo.selectedIndex ] ) == true) {
				if (ObjCmp[i][5] == 0)
					alert("Selecione o campo \""+ObjCmp[i][0]+"\".");
				else if (ObjCmp[i][5] == 1)
					alert(ObjCmp[i][6]);
				else {
					alert('ERRO CÓDIGO: 0003.');
					return false;
					}
				eval("document." + ObjCmp[i][1] + "." + ObjCmp[i][2] + ".focus()");
				return false;
				}
			}
		else {				
			alert('ERRO CÓDIGO: 0004.');
			return false;
			}
		}
	return true;
	}
//FIM VALIDAGERAL

function URLencode(sStr) {
    return escape(sStr).replace(/\+/g, '%2C').replace(/\"/g,'%22').replace(/\'/g, '%27');
  }
	
function SetValue(strObj, Value) {
	eval("Obj = " + strObj);
	
	if (!Obj)
		alert('Objeto não existe:\n'+Obj);
	else
		Obj.value = Value;
	}
	
function FullscreenLoad(url) {
	if (window.screen) {
		var hori	=screen.availWidth;
		var verti	=screen.availHeight;
		window.open(url,'WindowConsultaFullscreen', 'width='+hori+',height='+verti+',fullscreen=1, scrollbars=1,left='+(0)+',top='+(0));
		}
	}
	
function winModelessDialog(sURL ,sName ,sXPos ,sYPos ,sHeight ,sWidth ,sCenter ,sHide ,sEdge ,sHelp ,sResizable ,sScroll ,sStatus ,sUnadorned ,sTool ,sLocation ,sMenu) {
	
	var sFeatures = '';
	
	if (document.all && window.print) {//if ie5
		if(!sXPos)
			sFeatures += 'dialogLeft:'+sXPos+';';

		if(!sYPos)
			sFeatures += 'dialogTop:'+sYPos+';';

		if(!sWidth)
			sFeatures += 'dialogWidth:'+sWidth+';'; 
      
		if(!sCenter)
			sFeatures += 'center:'+sCenter+';';
      
		if(!sHide)
			sFeatures += 'dialogHide:'+sHide+';';
      
		if(!sEdge)
			sFeatures += 'edge:'+sEdge+';';
      
		if(!sHelp)
			sFeatures += 'help:'+sHelp+';';
      
		if(!sResizable)
			sFeatures += 'resizable:'+sResizable+';';
      
		if(!sScroll)
			sFeatures += 'scroll:'+sScroll+';';
      
		if(!sStatus)
			sFeatures += 'status:'+sStatus+';';
      
		if(!sUnadorned)
			sFeatures += 'unadorned:'+sUnadorned+';';

		eval('Win = window.showModelessDialog('+sURL+',"'+sName+'","'+sFeatures+'")');
		}
	else {
		if(!sTool)
			sFeatures += 'toolbar='+sTool+',';
		
		if(!sLocation)
			sFeatures += 'location='+sLocation+',';
		
		if(!sStatus)
			sFeatures += 'status='+sStatus+',';
		
		if(!sMenu)
			sFeatures += 'menubar='+sMenu+',';
			
		if(!sScroll)
			sFeatures += 'scrollbars='+sScroll+',';
			
		if(!sResizable)
			sFeatures += 'resizable='+sResizable+',';
		
		if(!sWidth)
			sFeatures += 'width='+sXPos+',';
			
		if(!sHeight)
			sFeatures += 'height='+sHeight+',';
			
		eval('Win = window.open("'+sURL+'","'+sName+'","'+sFeatures+'")');
		}
	
	if(Win) {
		Win;
		}
	
	return;
	}
	
function closeNoConfirm() {
	win = top;
	win.opener = top;
	win.close ();
	}
