function vazio(campo){

    campo = jQuery(campo);
    id = campo.attr('id');

    if(campo.val().length == 0){

        campo.addClass('caixa_contato_erro');
        jQuery('#img_'+id).html('<img src="imagens/bot_erro.png" width="16" height="16" />');
        return false;
    }else{

        campo.removeClass('caixa_contato_erro');
        campo.addClass('caixa_contato');
        jQuery('#img_'+id).html('<img src="imagens/bot_acerto.png" width="16" height="16" />');
        return true;
    }

}

function nObrigatorio(campo){

    campo = jQuery(campo);
    id = campo.attr('id');

    if(campo.val().length != 0){
        jQuery('#img_'+id).html('<img src="imagens/bot_acerto.png" width="16" height="16" />');
    }else{
        jQuery('#img_'+id).html('');
    }
}

function is_checked(campo){

    campo = jQuery(campo);
    id = campo.attr('id');

    if(campo.attr('checked')){
        jQuery('#img_'+id).html('<img src="imagens/bot_acerto.png" width="16" height="16" />');
        jQuery('#tipo_ensino').removeClass('text_erro');
        jQuery('#sistemas').removeClass('text_erro');
        jQuery('#img_geral_ensino').html('');
        jQuery('#img_geral_sistema').html('');
    }else{
        jQuery('#img_'+id).html('');
    }
}

function possuiSistema(){

    if(jQuery('#nao').attr('checked')){
        jQuery('#nome_sistema').attr('disabled', true).removeClass('caixa_contato_error').removeClass('caixa_contato').addClass('disabled').val('');
        jQuery('#img_nome_sistema').html('');
        jQuery('#fornecedor').attr('disabled', true).removeClass('caixa_contato_error').removeClass('caixa_contato').addClass('disabled').val('');
        jQuery('#img_fornecedor').html('');
    }else if(jQuery('#sim').attr('checked')){
        jQuery('#nome_sistema').attr('disabled', false).removeClass('disabled').addClass('caixa_contato');
        jQuery('#fornecedor').attr('disabled', false).removeClass('disabled').addClass('caixa_contato');
    }
}

function checkMail(mail){
        mail = jQuery(mail);
        id = mail.attr('id');
        var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);

        if(typeof(mail) == "string"){
            if(er.test(mail)){return true;}
        }else if(typeof(mail) == "object"){
            if(er.test(mail.val())){
                mail.removeClass('caixa_contato_erro');
                mail.addClass('caixa_contato');
                jQuery('#img_'+id).html('<img src="imagens/bot_acerto.png" width="16" height="16" />');
                return true;
            }else{
                mail.addClass('caixa_contato_erro');
                jQuery('#img_'+id).html('<img src="imagens/bot_erro.png" width="16" height="16" />');
                return false;
            }
        }else{
            return false;
        }
}

function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

function escolaridade(){
    if(jQuery('#grau_instrucao').val() != 'Superior Completo' && jQuery('#grau_instrucao').val() != 'Superior Incompleto'){
        jQuery('#escolaridade input.if_superior').attr('disabled', true).addClass('disabled').val('');
        jQuery('#escolaridade input.if_superior').each(function(){
            id = jQuery(this).attr('name');
            jQuery('#img_'+id).html('');
        });
        return false;
    }else{
        jQuery('#escolaridade input.if_superior').attr('disabled', false).removeClass('disabled');
        return true;
    }
}

function exibirDialog(){
    
}

function somente_numero(n){
var digits="0123456789"
var campo = jQuery(n);
var campo_temp
    for (var i = 0; i < campo.val().length; i++){
        campo_temp = campo.val().substring(i,i+1)
        if (digits.indexOf(campo_temp) == -1){
            campo.val(campo.val().substring(0,i));
        }
    }
}