//CODIGO PARA VERIFICAR A HORA: onblur="saindo(this,event)" onkeypress="return teclaH(this,event)"
//CODIGOPARA VERIFICARA DATA: onblur="DataIncompleta(this)" onkeypress="return validaTecla(this,event)"


if( document.captureEvents ) {
    //non IE
    if( Event.KEYUP ) {
        //NS 4, NS 6+, Mozilla 0.9+
        document.captureEvents( Event.KEYUP );
    }
}
document.onkeyup = alertkey;
function alertkey(e) {
    if( !e ) {
        if( window.event ) {
            e = window.event;
        } else {
            return;
        }
    }
    if( typeof( e.which ) == 'number' ) {
        e = e.which;
    } else if( typeof( e.keyCode ) == 'number'  ) {
        e = e.keyCode;
    } else if( typeof( e.charCode ) == 'number'  ) {
        e = e.charCode;
    } else {
        return;
    }
	return ( e );
}
//##############Filtra os campos obrigatorios e submet o formulario############
//Como usar:  <input type="button" name="Botao2" value="Enviar" onClick="checaCampos(this)">
function checaCampos(obj,envia,campo){
	//alert(obj);
	var form = obj.form;
	msg = '';
	msg2 = '';
	campoAtual = '';
	situacao = 'preenchido';
	tipoCampo = campo
		
	for (var i = 0 ; i < form.length ; i++){
		
		if (tipoCampo == 'id') {
			campo = form.elements[i].id;
		} else {
			campo = form.elements[i].name;	
		}
		
		valorTrim = trim(form.elements[i].value);
		form.elements[i].value = valorTrim;
		
		if (form.elements[i].className == 'obrigatorio'){
			if ((form.elements[i].type == 'text') || (form.elements[i].type == 'textarea') || (form.elements[i].type == 'select-one') || (form.elements[i].type == 'hidden') || (form.elements[i].type == 'password')){
				if (valorTrim == '' && form.elements[i].disabled != true){
					//msg = msg + msg2 + 'O campo "'+campo+'" é obrigatório e encontra-se vazio.\n';msg2=''
					msg = msg + msg2 + campo+'\n';msg2=''
					//form.elements[i].style.backgroundColor='#ff0000';
					form.elements[i].style.borderStyle = 'dotted';
					form.elements[i].style.borderColor = '#FF0000';
				} else {
					//form.elements[i].style.backgroundColor='#ffffff';
					form.elements[i].style.borderStyle = '';
					form.elements[i].style.borderColor = '';
				}
			}
			else{
				if(form.elements[i].type == 'radio'){ //Verifica se é do tipo radio
					if (campoAtual == campo){//Verifica se é o mesmo radio que esta sendo testado
						if (situacao == 'vazio'){//Caso ainda não tenha encontrado um campo preenchido 
							if (form.elements[i].checked){//Testa se preencheu
								msg2 = '';
								situacao = 'preenchido';
							}
							else
								situacao = 'vazio';
						}
					}
					else{
						msg = msg + msg2; msg2 = '';
						campoAtual = campo;
						if (form.elements[i].checked)//Testa se preencheu
							situacao = 'preenchido';
						else{
							//msg2 = 'O campo "'+campo+'" é obrigatório e encontra-se vazio.\n';
							msg2 = campo+'\n';
							situacao = 'vazio';
						}
					}
				}
			}
			if (form.elements[i].type == 'checkbox') {
				if (!form.elements[i].checked) {
					//msg = msg + msg2 + 'O campo "'+campo+'" é obrigatório e encontra-se vazio.\n';msg2=''	
					msg = msg + msg2 + campo+'\n';msg2=''	
				}
			}
		}
		
	}
	if (msg2 != '') {
		msg = msg + msg2;
		msg2='';
	}
	if (msg != ''){
		//alert('Foram encontrados os seguintes problemas:\n\n' + msg + msg2);
		alert('Os campos listados abaixo são de preenchimento obrigatório:\n\n' + msg + msg2);
		return false;
	}
	else{
		if (envia) {
			form.submit();
		} else {
			return true;	
		}
	}
}
//##############FIM Filtra os campos obrigatorios e submet o formulario############

//##############CALCULA CPF############
//onBlur="checacpf('cpf_pessoa')"  ##em caso de usar ID (ajax)
//onBlur="checacpf(this,'name')"  ##em caso de usar o post normal. com os nomes dos campos no atributo name
function checacpf(obj,name) {
	if (name == "name") {
		cpf = obj.value;
	} else {
		obj = document.getElementById(obj);
		cpf = obj.value;
	}
	if (cpf != ''){	
		if (calculacpf(cpf)){
			return true;
			//CPF OK
		}
		else {
			errors="1";
			if (errors){
				alert('CPF inválido, por favor digite-o novamente.');
				obj.focus();
				return false;
				//setTimeout(function(){obj.focus();},10)
			}	
			//document.retorno = (errors == '');
		}
	} return true;
}
function calculacpf(cpf){
	if (cpf == '')
		return true;
	else{
		if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
			return false;
		soma = 0;
		for (i=0; i < 9; i ++)
			soma += parseInt(cpf.charAt(i)) * (10 - i);
		resto = 11 - (soma % 11);
		if (resto == 10 || resto == 11)
			resto = 0;
		if (resto != parseInt(cpf.charAt(9)))
			return false;
		soma = 0;
		for (i = 0; i < 10; i ++)
			soma += parseInt(cpf.charAt(i)) * (11 - i);
		resto = 11 - (soma % 11);
		if (resto == 10 || resto == 11)
			resto = 0;
		if (resto != parseInt(cpf.charAt(10)))
			return false;
		//alert('CPF correto.');
		return true;
	}
}
//##############FIM CALCULA CPF############

//#################CONVERTE DATA PARA MOSTRAR DA TELA#######################
function converteData(data,formato){
	if (formato == 'BR') {
		data = data.substring(8,10)+'/'+data.substring(5,7)+'/'+data.substring(0,4);
		return data;
	}
	if (formato == 'US') {
		data = data.substring(6,10)+'-'+data.substring(3,5)+'-'+data.substring(0,2);
		return data;
	}
}
//#####################FIM CONVERTE DATA PARA MOSTRAR DA TELA##################################


//#################Mascara para numero#######################
//Como usar: <input type="text" onkeypress="JavaScript: return numero(event)">
function filtroNumero(event,decimal,negativo){
	tecla = alertkey(event);
	if(document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = event.which;
	if((tecla == 8) || (tecla == 9) || (tecla == 0)){
		return true;
	} else if(tecla > 47 && tecla < 58 ) // numeros de 0 a 9
		return true;
	else if (tecla == 44) {
		if (decimal) {
			return true;	
		}
	} else if (tecla == 45) {
		if (negativo) {
			return true;	
		}
	}
		return false;
}

function numero(event,decimal,negativo){
	return filtroNumero(event,decimal,negativo);
}
//#####################Fim mascara de numeros##################################

//###################################Mascara para data###################################
//Como usar: <input type="text" name="Data" onBlur="DataIncompleta(this)" onkeypress="return validaTecla(this,event)">
function validaTecla(campo,event){
	FormataData(campo,event);
	
	tecla = alertkey(event);
	if((tecla == 8) || (tecla == 9) || (tecla == 0)){
		return true;
	}
	else if (campo.value.length + 1 == 1){
		if(tecla > 47 && tecla < 52) // numeros de 0, 1, 2 e 3    
			return true;
	}
	else if (campo.value.length + 1 == 2){
		if (campo.value.substr(0,1) == 0){
			if(tecla > 48 && tecla < 58 ) // numeros de 1 a 9
				return true;
		}
		else if (campo.value.substr(0,1) == 3){
			if(tecla == 48 || tecla == 49) // numeros de 0 e 1
				return true;
		}
		else if(tecla > 47 && tecla < 58 ) // numeros de 0 a 9
			return true;
	}
	else if (campo.value.length + 1 == 4){
		if(tecla == 48 || tecla == 49) // numeros de 0 e 1
			return true;
	}
	else if (campo.value.length + 1 == 5){
		if (campo.value.substr(3,1) == 0){
			if(campo.value.substr(0,2) == 31){//49=1 51=3 53=5 55=7 56=8
				if((tecla == 49) ||(tecla == 51) ||(tecla == 53) ||(tecla == 55) ||(tecla == 56)) // numeros de 1 a 9
					return true;
			}
			else if(campo.value.substr(0,2) == 30){
				if((tecla == 49) ||(tecla > 50 && tecla < 58)) // numeros de 1 a 9
					return true;
			}
			else if(campo.value.substr(0,2) < 30){
				if(tecla > 48 && tecla < 58) // numeros de 1 a 9
					return true;
			}
		}
		else{
			if(campo.value.substr(0,2) == 31){//49=1 51=3 53=5 55=7 56=8
				if((tecla == 48) ||(tecla == 50)) // numeros de 1 a 9
					return true;
			}
			else if(campo.value.substr(0,2) < 31){
				if(tecla == 48 || tecla == 49 || tecla == 50) // numeros de 0, 1 e 2
					return true;
			}
		}
	}
	else if (campo.value.length + 1 == 7){
		if(tecla == 49 || tecla == 50) // numeros de 1 e 2
			return true;
	}
	else if (campo.value.length + 1 == 8){
		if (campo.value.substr(6,1) == 1){
			if(tecla == 57 ) // numero 9
				return true;
		}
		else{
			if (campo.value.substr(6,1) == 2){
				if(tecla == 48 ) // numero 0
					return true;
			}
		}
	}
	else if (campo.value.length + 1 == 9){
		if(tecla > 47 && tecla < 58 ) // numeros de 0 a 9
			return true;
	}
	else if (campo.value.length + 1 == 10){
		if(tecla > 47 && tecla < 58 ) // numeros de 0 a 9
			return true;
	}
	if (tecla == 46) // backspace
		return true;
	else
		return false;
}

function DataIncompleta(campo1){
	//vr = campo.value
	obj = document.getElementById(campo1);
	campo = obj;
	tam = campo.value.length;
	if ( tam == 0 ){
	} else if ( tam == 10 ){
		tipodata(campo);
	/*} else if ( tam == 8 ){
		AutoCompleta(campo);*/
	} else {
		alert('Data Incompleta. Favor digitar a data no formato DD/MM/AAAA');
		//alert('teste')
		setTimeout("obj.focus()",10);
		//obj.focus()
	}
}
function AutoCompleta(campo){
	vr = campo.value;
	xy = vr.substring(6,8);
	if ( xy > 20 ){
		vr = vr.substr( 0, tam - 2  ) + '19' + xy;
	    campo.value = vr
		tipodata(campo);
	}
	else if ( xy < 21 ){
		vr = vr.substr( 0, tam - 2  ) + '20' + vr.substr( tam - 2, tam );
		campo.value = vr
		tipodata(campo);
	}
	tamA = vr.length
	if ( tamA == 10 ){
		tipodata(campo);
	}
}
function VerificaTexto( str, chars ){
	var ret = true;
	for (i = 0; i < str.length; i++){
		for (j = 0; j < chars.length; j++) {
			if (str.substr(i, 1) == chars.substr(j, 1)) ret = false;
		}
	}
	return ret;
} 
function Saltacampo (campo){
	if ( tam == 10 ){
		tipodata(campo)
	}
}
function tipodata(campo){
	vr = campo.value
	if((vr.substring(6,10) < 1900) || (vr.substring(6,10) > 2099)){
		alert('Ano incorreto! O ano deve ser entre 1900 e 2099.')
		campo.focus()	
		return		
	}
	if((vr.substring(3,5) == 01) || (vr.substring(3,5) == 03) || (vr.substring(3,5) == 05) || (vr.substring(3,5) == 07) || (vr.substring(3,5) == 08) || (vr.substring(3,5) == 10) || (vr.substring(3,5) == 12)){
		TestaData31(campo)	
	}
	else if((vr.substring(3,5) == 04) || (vr.substring(3,5) == 06) || (vr.substring(3,5) == 09) || (vr.substring(3,5) == 11)){
		TestaData30(campo)
	}
	else if((vr.substring(3,5) == 02)){
		TestaData29(campo)
	}
	else if((vr.substring(3,5) == 00) || (vr.substring(3,5) > 12)){
		alert('Mês invalido.')
		campo.focus()	
	}
}
function TestaData31(campo){
	if((vr.substring(0,2) > 31) || (vr.substring(0,2) == 00)){
		DataIncompleta(campo)	
		return
	}
	if(vr.substring(3,5) > 12){
		alert('O mê está incorreto.')
		return
	}
//	DataIncompleta(campo)
}
function TestaData30(campo){
	if((vr.substring(0,2) > 30) || (vr.substring(0,2) == 00)){
		alert('A data está incorreta. O mês deve ter no maximo 30 dias.')
		campo.focus()
	}
	if(vr.substring(3,5) > 12){
		alert('O mê está incorreto.')
		campo.focus()
		return
	}
//	DataIncompleta(campo)
}
function TestaData29(campo){
		if(vr.substring(6,10) % 4 == 0){
			TestaDataBis(campo)
		}
		else{
			TestaDataCom(campo)
		}
}
function TestaDataCom(campo){
	if((vr.substring(0,2) > 28) || (vr.substring(0,2) == 00)){
		alert('A data está incorreta. O mês deve ter no maximo 28 dias.')
		campo.focus()
		return
	}
	if(vr.substring(3,5) > 12){
		alert('O mê está incorreto.')
		campo.focus()
		return
	}
//	DataIncompleta(campo)
}
function TestaDataBis(campo){
	if((vr.substring(0,2) > 29) || (vr.substring(0,2) == 00)){
		alert('A data está incorreta. O mês deve ter no maximo 29 dias.')
		campo.focus()
		return
	}
	if(vr.substring(3,5) > 12){
		alert('O mê está incorreto.')
		campo.focus()
		return
	}
//	DataIncompleta(campo)
}
function FormataData(campo,event) {
	tecla = alertkey(event);
//alert(tecla)
	vr = campo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );	
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			campo.value = vr.substr( 0, 2  ) + '/' + vr.substr( 2, 10 );
		if ( tam >= 5 && tam <= 10 )
			campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
	}
	tam = vr.length;
	//if ( tam > 8 ){
	Saltacampo(campo);
	//}
}
//################################Fim da macara para data##############################
//####################################Mascara de hora##################################
//Como usar: <input type="text" name="Hora" onBlur="saindo(this,event)" onkeypress="return teclaH(this,event)">
function ProximoCampo(obj){
	var form = obj.form;
	for (var i = 0 ; i < form.length ; i++){
		if (form[i].name == obj.name){
			//alert(i);
			break;
		}
	}
	if (obj.value.length == 5){
		n = i+1;
	if (form.elements.length > n)
		form.elements[n].focus();
	}
}
function saindo(campo,event){
	verificaHora(campo,event);
}

function verificaHora(campo,event){
	alertkey(event)
	if(document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = event.which;
	if ((tecla != 8) && (tecla != 9) && (tecla != 0)){
		if ((campo.value.length != 0) && (campo.value.length  != 5)){
			campo.value = "";
			alert('Hora incompleta. Favor digitá-la corretamente!')
			//alert(campo.name);
			campo.focus();
			//document.form1.teste.focus()	
		}
	}
	if (parseInt(campo.value.substr(0,2)) > 23 || parseInt(campo.value.substr(3,2)) > 59) {
		//campo.value = "";
		//alert('Hora inválida. Favor digitá-la corretamente!')
		//campo.focus();
	}
}
function teclaH(campo,event){
	FormataHora(campo,event);
	tecla = alertkey(event);
	
	if(document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = event.which;
	if((tecla == 8) || (tecla == 9) || (tecla == 0) || (tecla == 46)){
		return true;
	}
	else if (campo.value.length + 1 == 1){
		if(tecla > 47 && tecla < 51) // numeros de 0, 1 e 2
			campo.value = campo.value + String.fromCharCode(tecla);
	}
	else if (campo.value.length + 1 == 2){
		if (campo.value.substr(0,1) == 0){
			if(tecla > 47 && tecla < 58) // numeros de 0 a 9
				campo.value = campo.value + String.fromCharCode(tecla);
		}
		else if (campo.value.substr(0,1) == 2){
			if(tecla > 47 && tecla < 52) // numeros de 0 a 3
				campo.value = campo.value + String.fromCharCode(tecla);
		}
		else if(tecla > 47 && tecla < 58 ) // numeros de 0 a 9
			campo.value = campo.value + String.fromCharCode(tecla);
	}
	else if (campo.value.length + 1 == 4){
		if(tecla > 47 && tecla < 54) // numeros de 0 a 5
			campo.value = campo.value + String.fromCharCode(tecla);
	}
	else if (campo.value.length + 1 == 5){
		if(tecla > 47 && tecla < 58 ) // numeros de 0 a 9
			campo.value = campo.value + String.fromCharCode(tecla);
	}
	if (tecla == 46) // backspace
		return true;
	else
		return false;
}

function tipoHora(campo,event){
//alert(vr.substring(0,2))
	if((vr.substring(2,4) > 60) || (vr.substring(2,4) < 00)){
		alert('Minutos incorretos.')
		campo.focus()
	}
	else if((vr.substring(0,2) > 24) || (vr.substring(0,2) < 00)){
		alert('Hora incorreta.')
		campo.focus()
	}
}
function FormataHora(campo,event) {
	
	tecla = alertkey(event);
	if(document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = event.which;

	
	vr = campo.value;
	vr = vr.replace( ":", "" );
	vr = vr.replace( ":", "" );
	vr = vr.replace( ":", "" );
	tam = vr.length + 1;
	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			campo.value = vr.substr( 0, 2  ) + ':' + vr.substr( 2, 5 );
		if ( tam > 4 && tam <= 5 )
			campo.value = vr.substr( 0, 2 ) + ':' + vr.substr( 2, 2 )
	}
	tam = vr.length
	if ( tam == 4 ){
		tipoHora(campo)
	}
	if ((tecla != 8) && (tecla != 9) && (tecla != 0)){
		//ProximoCampo(campo);
	}
}
//################################Fim da mascara de hora###################################

//################################funcao para determinar qual o navegador do usuario###################################

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}
//################################Fim da funcao para determinar qual o navegador do usuario###################################


//######FUNCAO PARA LIMITAR O NUMERO DE CARACTERES EM UM TEXTAREA
//
function limitaTextArea(id, tipo, tamanho){
	var texto = document.getElementById(id).value;
	numeroDeCaracteres=texto.length


	if (tipo == 1) {
		if (numeroDeCaracteres >= tamanho){
			document.getElementById(id).value = texto.substring(0,tamanho-1)
			alert('Não é permitido mais de '+tamanho+' Caracteres')
		}
	} else {
		if (numeroDeCaracteres > tamanho){
			document.getElementById(id).value = texto.substring(0,tamanho)
			alert('Não é permitido mais de '+tamanho+' Caracteres')
		}
	}
}

//################################################################
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}


//################################################################
function formataNumero(valor,decimais,entrada, retorno){
	if (valor=='') {return parseFloat(0.00)};
	if (entrada == "float") {
		valor = parseFloat(valor).toFixed(decimais);
	} else if (entrada == "string") {
		valor = valor.replace(",",".");
		valor = parseFloat(valor).toFixed(decimais);
	} else {
		return 0;
	}

	if (retorno == "string") {
		valor = String(valor);
		valor = valor.replace(".",",");
	}
//	if (isNaN(valor)) { return 0};
	return valor;

}

//################################################################

//Esta função serve como máscara para valores monetários.
//ex.: onKeyDown='formataValor("valor", 13, event)
//Obs.: "valor" é o nome do campo, 13 o tamanho máximo permitido de carac. do campo e event é a tecla pressionada
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( ".", "" );
 
 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 abilitaCampoGenerico(campo1,campo2,valor,neg,idTr) {
	campo1 = document.getElementById(campo1);
	campo2 = document.getElementById(campo2);
//	alert(idTr);
	if (!neg) {
		if (campo1.value == valor) {
			campo2.disabled = "";
			if (idTr != undefined) {
				document.getElementById(idTr).style.display = "";
			}
		} else {
			campo2.disabled = "disabled";
			campo2.value = "";
			if (idTr != undefined) {
				document.getElementById(idTr).style.display = "none";
			}
		}
	} else {
		if (campo1.value == valor) {
			campo2.disabled = "disabled";
			campo2.value = "";
			if (idTr != undefined) {
				document.getElementById(idTr).style.display = "none";
			}
		} else {
			campo2.disabled = "";
			if (idTr != undefined) {
				document.getElementById(idTr).style.display = "";
			}
		}
	}
	//alert('teste');
}

//########################################################

//funcao para formatar cep

//modo de usar <input name="cep" type="text" id="cep" onkeypress="return MM_formtCep(event,this,'#####-###');" size="10" maxlength="9">
function formataCep(e,src,mask) {
	if(window.event) {
		_TXT = e.keyCode;
	}
	else if(e.which) {
		_TXT = e.which;
	}
	if(_TXT > 47 && _TXT < 58) {
		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);
		}
		return true;
	} else {
		if (_TXT != 8) {
			return false;
		}
		else {
			return true;
		}
	}
}

function FormataDigitosData(Data){
	posicaoBarra = Data.indexOf('/');
	Dia = '0'+Data.substr(0,posicaoBarra)
	Dia = Dia.substr(Dia.length-2,2)
	posicaoBarra2 = Data.lastIndexOf('/');
	Mes = '0'+Data.substring(posicaoBarra+1,posicaoBarra2)
	Mes = Mes.substr(Mes.length-2,2)
	Ano = Data.substr(posicaoBarra2+1,4)
	//formata ano
	if ( Ano.length <= 2 ){
		if ( Ano > 20 )
			Ano = '19' + Ano;
		else if ( Ano < 21 )
			Ano = '20' + Ano;
	}
	Data = Dia+'/'+Mes+'/'+Ano
	return Data;
}
function comparaData(DataInicial,DataFinal){
	var ret = true;
	
	DataInicial = FormataDigitosData(DataInicial);
	DataFinal = FormataDigitosData(DataFinal);

	
	DataFAno = DataFinal.substr(6,4)
	DataFMes = DataFinal.substr(3,2)
	DataFDia = DataFinal.substr(0,2)
	DataIAno = DataInicial.substr(6,4)
	DataIMes = DataInicial.substr(3,2)
	DataIDia = DataInicial.substr(0,2)
	NumeroDataF = DataFAno += DataFMes += DataFDia
	NumeroDataI = DataIAno += DataIMes += DataIDia
	if ((DataInicial == '') || (DataFinal == '')){
		var ret = false;
	}
	else if(NumeroDataF < NumeroDataI){
		var ret = false;
	}
	else{
	}
	return ret;
}
