/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

document.write('<script type="text/javascript" src="numeros.js"></script>');

function mascaraCEP(obj, event, corCampo, corLetra){

    enter = 13;
    space = 32;
    esc = 27;
    del = 83;
    backspace = 8;
    validos = '0123456789';
    aux = '';

    //testa os parâmetros de cor
    if(!corCampo) corCampo = '#FF0000';

    if(!corLetra) corLetra = '#FFFFFF';

    if(navigator.appName.indexOf('Netscape') != -1) tecla = event.which;
    else tecla = event.keyCode;

    if(tecla == enter)
        return false;
    else if(tecla == backspace)
        return true;
    else if(tecla == space)
        return false;
    else if(tecla == esc)
        return false;
    else if(tecla == del)
        return true;

    key = String.fromCharCode(tecla);

    if (validos.indexOf(key) == -1) {
        return false;
    }

    aux = obj.value;
    aux += key;

    if(aux.length == 5) obj.value = aux + '-';
    else if(aux.length <= 9) obj.value = aux;

    return false;
}

function validaTamanhoCep(obj, corCampo, corLetra){

    //testa os parâmetros de cor
    if(!corCampo) corCampo = '#FF0000';

    if(!corLetra) corLetra = '#FFFFFF';

    if(obj.value != '' && obj.value.length < 9){
        obj.style.backgroundColor = corCampo;
        obj.style.color = corLetra;
        obj.focus;
        alert('ATENÇÃO!\n\nO campo deve conter 9 caracteres com o formato 99999-999, verifique!');
    }
    if(obj.value == '00000-000' || obj.value == '11111-111' || obj.value == '22222-222' || obj.value == '33333-333' || obj.value == '44444-444' || obj.value == '55555-555' || obj.value == '66666-666' || obj.value == '77777-777' || obj.value == '88888-888' || obj.value == '99999-999'){
        obj.style.backgroundColor = corCampo;
        obj.style.color = corLetra;
        obj.focus;
        alert('ATENÇÃO!\n\nO campo está preenchido de forma incorreta. Este, deve conter um cep válido, verifique!');
        return;
    }
}