
function keyDown(e) {
	key_code = e.which;
}

function mascara(Campo, Mascara, evtKeyPress){
	var i, j, Valor, TamanhoCampo, TamanhoMascara, MascaraOk, Codigo, Tecla;

	Tecla = KeyCode(evtKeyPress);
	//	alert(Tecla);
	//            TAB          F5
	if (Tecla==8 || Tecla==9 || Tecla==116) return true;

	Valor = Campo.value;
	Valor = Valor.toString().replace( ':', '' );
	Valor = Valor.toString().replace( '-', '' );
	Valor = Valor.toString().replace( '-', '' );
	Valor = Valor.toString().replace( '.', '' );
	Valor = Valor.toString().replace( '.', '' );
	Valor = Valor.toString().replace( '/', '' );
	Valor = Valor.toString().replace( '/', '' );
	Valor = Valor.toString().replace( '(', '' );
	Valor = Valor.toString().replace( '(', '' );
	Valor = Valor.toString().replace( ')', '' );
	Valor = Valor.toString().replace( ')', '' );
	Valor = Valor.toString().replace( ' ', '' );
	Valor = Valor.toString().replace( ' ', '' );
	TamanhoCampo = Valor.length;
	TamanhoMascara = Mascara.length;

	i = 0; j = 0; Codigo = '';
	TamanhoMascara = TamanhoCampo;

	while ( i <= TamanhoMascara ){

		MascaraOk = ((Mascara.charAt(i) == '-') ||
		(Mascara.charAt(i) == '.') ||
		(Mascara.charAt(i) == '/') ||
		(Mascara.charAt(i) == '(') ||
		(Mascara.charAt(i) == ')') ||
		(Mascara.charAt(i) == ':') ||
		(Mascara.charAt(i) == ' ')
		);

		if (MascaraOk){
			Codigo += Mascara.charAt(i);
			TamanhoMascara++;
		}
		else {
			Codigo += Valor.charAt(j);
			j++;
		}
		i++;
	}

	Campo.value = Codigo;

	if (Tecla != 8 && Tecla != 9){
		if (Mascara.charAt(i-1) == "9" && Mascara.length > Valor.length){
			return (((Tecla > 47) && (Tecla < 58)) || ((Tecla > 95) && (Tecla < 106)));
		}else{
			return true;
		}
	}else{
		return true;
	}
}

function KeyCode(e)
{
	if(document.all){
		return e.keyCode;
	}
	else if(navigator.appName == 'Netscape'){
		return e.which;
	}
}

function numerico(event){
	Tecla = KeyCode(event);
	if ((Tecla > 47) && (Tecla < 58))
	return true;
	else
	return false;
}

function FormataValor(campo,teclapres) {
	var tecla = teclapres.keyCode;
	var tammax = campo.maxLength - 1;
	vr = campo.value;
	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 ){
		campo.value = vr.substr( 0, tam - 2 ) + '.' + vr.substr( tam - 2, tam ) ; }
		if ( tam <= 2 ){
			campo.value = vr ; }
			if ( (tam > 2) && (tam <= 5) ){
				if ( (tam >= 6) && (tam <= 8) ){
					campo.value = vr.substr( 0, tam - 5 ) + '' + vr.substr( tam - 5, 3 ) + '.' + vr.substr( tam - 2, tam ) ; }
					if ( (tam >= 9) && (tam <= 11) ){
						campo.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) ){
							campo.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) ){
								campo.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 validaSenha(SENHA, CONFIRMACAO) {

	if(SENHA==CONFIRMACAO){
		
		if(SENHA=='')
			return false;
			
		return true;
		
	} else {
		
		return false;
		
	}
}

	function submitPedido(frm, act){
	
		frm.action = act;
		frm.submit();
	
	}
	
	function submitLogin(dest){
		
		var erro, msg;
		var form = document.frm_login;
		
		erro = false;
		msg = '';
		
		if(form.email_cliente.value == ''){
			msg += "\nInforme seu login de acesso.";
			erro = true;
		}
		if(form.senha_cliente.value == ''){
			msg += "\nInforme sua senha de acesso.";
			erro = true;
		}
		msg += "\n";
		
		if(erro){
			
			alert(msg);
			return false;
			
		} else {
			
			if(dest == '')
				form.action = "?t=login";
			else
				form.action = dest;
				
			form.submit();
			
		}
		
	}
