configuraImagemLoading = function() {
    $('#divPreload').ajaxStart(function(){
        //$('#conteudoAdm').hide();
        $(this).show();
    });
    $('#divPreload').ajaxStop(function(){
        $(this).hide();
    //$('#conteudoAdm').show();
    });
}

cleanInputField = function (placeHolderValue, inputField) {
    if(inputField.value == placeHolderValue){
        inputField.value = "";
    }
}

fillInputField = function (placeHolderValue, inputField){
    if(inputField.value == ""){
        inputField.value = placeHolderValue;
    }
}

stylesFieldsForm = function(mask) {

    $(':input[type=text]').blur(function(){
        if ($(this).val().indexOf("'") > -1) {
            var string = $(this).val();
            while (string.indexOf("'") != -1) {
                string = string.replace("'", "");
            }
            $(this).val(string);
        }
    });

    $('.inputAdm, .textareaAdm, .inputContact, .textareaContact').focus(function(){
        $(this).css({
            backgroundColor:"#e9f7fd",
            border:"1px solid #00315a"
        });
    });

    $('.inputAdm, .textareaAdm, .inputContact, .textareaContact').blur(function(){
        $(this).css({
            backgroundColor:"#fff",
            border:"1px solid #aaa"
        });
    });

    $('.input').focus(function(){
        $(this).css({
            backgroundColor:"#e9f7fd",
            border:"1px solid #666"
        });
    });

    $('.input').blur(function(){
        $(this).css({
            backgroundColor:"#fff",
            border:"1px solid #666"
        });
    });

    $('#idData').blur(function() {
        validaData($('#idData').val())
    });
    
    if (mask == "true") {
        $("#idData").mask("99/99/9999", {
            placeholder: "_"
        });
        $("#idHora").mask("99:99", {
            placeholder: "_"
        });
        $("#idTelefone").mask("(99) 9999-9999", {
            placeholder: " "
        });
        $("#idCelular").mask("(99) 9999-9999", {
            placeholder: " "
        });
        $("#idDt1").mask("99/99/9999", {
            placeholder: " "
        });
        $("#idDt2").mask("99/99/9999", {
            placeholder: " "
        });
        $("#idValor").maskMoney({
            symbol: "",
            decimal: ",",
            thousands: "."
        });
        $("#idCpf").mask("999.999.999-99", {
            placeholder: "#"
        });

        //$("#idPeso").numeric(",");
        $("#idPeso").maskMoney({
            precision: 1,
            decimal:",",
            showSymbol: false,
            thousands: ''
        });
        $("#idAltura").maskMoney({
            precision: 2,
            decimal:",",
            showSymbol: false,
            thousands: ''
        });
        $("#idPesoD").maskMoney({
            precision: 1,
            decimal:",",
            showSymbol: false,
            thousands: ''
        });

    }

}

loadPage = function(idContainer, arquivo) {
    var agora = "";
    if (arquivo.indexOf("?")==-1) {
        agora = "?t="
    } else {
        agora = "&t=";
    }
    var Data = new Date();	
    $(idContainer).load(arquivo+agora+Data.getTime(), function() {
        scripts();
    });
}

loadPageParams = function(idContainer, arquivo, method, params) {
    var agora = "";
    if (arquivo.indexOf("?")==-1) {
        agora = "?t="
    } else {
        agora = "&t=";
    }
    var Data = new Date();
    $(idContainer).load(arquivo+agora+Data.getTime(), function() {
        scripts();
    });
}

alerta = function (msg,titulo,subtitulo,opt,focus) {
    new WindowAlert(msg,titulo,subtitulo,opt,focus);
}

confirma = function (msg,ondeIr,container,opt) {
    new WindowConfirm(msg,ondeIr,container,opt);
}

alertError = function (msg,opt) {
    new WindowError(msg,opt);
}

apagar = function(id, arq, texto, container, opt, param) {
    new WindowConfirm("Deseja Realmente <strong>APAGAR</strong> "+texto+" ? ",'../_lib/_actions/'+arq+'Actions.php?id='+id+'&m=DEL&'+param,container,opt);
}

apagarImg = function(arq, texto, container, opt, param) {
    new WindowConfirm("Deseja Realmente <strong>APAGAR</strong> "+texto+" ? ",'../_lib/_actions/'+arq+'Actions.php?m=DELIMG&'+param,container,opt);
}

finalizar = function(id, nome, container) {

    var eventHandler = new Event();
    WindowConfirm.prototype.windowClosed = function(){
        eventHandler.fireEvent(null, this, "windowClosed");
    };

    var wConfirm = new WindowConfirm("Deseja Realmente <strong>FINALIZAR</strong> o Vestibular,<BR>"+nome+"?");
    eventHandler.addListener(wConfirm, "windowClosed", function(){
        if(wConfirm.getAnswer() == true){
            askServiceCaller();
        }
    });
    wConfirm.init();

    var askServiceCaller = function(eventObject){
        loadPage(container,'../_lib/_actions/VestibularActions.php?id='+id+'&m=END');
    };

}

setPresenca = function(id, nome, container) {

    var eventHandler = new Event();
    WindowConfirm.prototype.windowClosed = function(){
        eventHandler.fireEvent(null, this, "windowClosed");
    };

    var wConfirm = new WindowConfirm("Deseja Realmente <strong>CONFIRMAR A PRESENÇA</strong> para o(a) candidato(a),<BR>"+nome+"?");
    eventHandler.addListener(wConfirm, "windowClosed", function(){
        if(wConfirm.getAnswer() == true){
            askServiceCaller();
        } else {
            $('#comp'+id).attr('checked', false);
        }
    });
    wConfirm.init();

    var askServiceCaller = function(eventObject){
        loadPage(container,'../_lib/_actions/AgendamentoActions.php?id='+id+'&m=SETCOMP');
    };

}

verificaCpf = function(value) {

    value = value.replace('.','');

    value = value.replace('.','');

    cpf = value.replace('-','');

    while(cpf.length < 11) cpf = "0"+ cpf;

    var expReg = /^0+$|^1+$|^2+$|^3+$|^4+$|^5+$|^6+$|^7+$|^8+$|^9+$/;

    var a = [];

    var b = new Number;

    var c = 11;

    for (i=0; i<11; i++){

        a[i] = cpf.charAt(i);

        if (i < 9) b += (a[i] * --c);

    }

    if ((x = b % 11) < 2) {
        a[9] = 0
    } else {
        a[9] = 11-x
    }

    b = 0;

    c = 11;

    for (y=0; y<10; y++) b += (a[y] * c--);

    if ((x = b % 11) < 2) {
        a[10] = 0;
    } else {
        a[10] = 11-x;
    }

    if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10]) || cpf.match(expReg)) return false;

    return true;

}

var ativo = "";
mostra = function(src, isIe) {
    if (ativo != src) {
        //if (ativo != "") {
        if (isIe == "false") {
            $('#'+ativo).slideToggle('slow', null);
        } else {
            $('#'+ativo).hide();
        }
        $('#tit_'+ativo).css({
            color: '#333',
            fontWeight: "normal",
            borderBottom: "1px solid #777",
            fonteight: 'bold'
        });
        //}
        if (isIe == "false") {
            $('#'+src).slideToggle('slow', null);
        } else {
            $('#'+src).show();
        }
        $('#tit_'+src).css({
            color: '#00478b',
            fontWeight: "bold",
            borderBottom: "1px solid #00478b"
        });

        ativo = src;
    }
}

carregaSubcategorias = function(val,container,cod) {
    $('#'+container).removeOption(/./);
    $('#'+container).ajaxAddOption('../_lib/_actions/SubcategoriaActions.php', {
        m: 'FILTRAR',
        id: val
    }, false,
    function() {
        if (cod != '') {
            $('#'+container).val(cod);
        }
    }
    );
}

filtraCursos = function (area) {
    $('#idCurso2').removeOption(/./);
    $('#idCurso2').ajaxAddOption('../_lib/_actions/CandidatoActions.php', {
        m: 'cursos',
        area: area
    }, false
    );
}

filtraRelatorio = function (area) {
    $('#idFiltros').hide();
    $('#idOrdenar').hide();
    $('#idArea').hide();
    $('#idTipoRel').removeOption(/./);
    $('#idTipoRel').ajaxAddOption('../_lib/_actions/RelatorioActions.php', {
        m: 'tipos',
        area: area
    }, false
    );
}

listaCidades = function (container, estado, cod) {
    
    $('#'+container).removeOption(/./);
    $('#'+container).ajaxAddOption('../_lib/_actions/CidadeActions.php',
    {
        m: 'LIST',
        cod: cod,
        estado: estado
    }, 
    false,
    function() {
        if (cod != '') {
            $('#'+container).val(cod);
        }
    }
    );

}


getPageSize = function() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = window.innerWidth + window.scrollMaxX;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;

    if (self.innerHeight) {	// all except Explorer
        if(document.documentElement.clientWidth){
            windowWidth = document.documentElement.clientWidth;
        } else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){
        pageWidth = xScroll;
    } else {
        pageWidth = windowWidth;
    }

    return [pageWidth,pageHeight];
}

agenda = function (dia, mes, ano, dSemana) {
    $('#idDia').val(dia);
    $('#idMes').val(mes);
    $('#idAno').val(ano);
    $('#idHora').removeOption(/./);
    $('#idHora').ajaxAddOption('../_lib/_actions/ConfiguracaoActions.php', {
        m: 'selHoras',
        semana: dSemana
    }, false);
}

mOutCalendar = function(src) {
    $(src).css({
        backgroundColor:'#aaf'
    });
}

mOverCalendar = function(src) {
    $(src).css({
        backgroundColor:'#ccf'
    });
}

gerarBoleto = function(params) {
    window.open('https://secure1.nexxera.com/cobranca/sacado/criarBoleto.do?'+params);
}

stringToNumber = function(str) {
    num = str.replace(',','.');
    return Number(num);
}

checkMail = function (mail){
    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.value)){
            return true;
        }
    }else{
        return false;
    }
}

validaData = function(data) {
     var noData = data.split('/');
     if (noData[0] > "31") {
        top.alerta('O dia preenchido não pode ser maior que 31!<BR><BR>','Atenção','','2','idData');
        return false;
     } else if (noData[1] > "12") {
        top.alerta('O mês preenchido não pode ser maior que 12!<BR><BR>','Atenção','','2','idData');
        return false;
     }
     return true;
}

trocaImgBanner = function(img) {
    $('#produtos').css({backgroundImage: 'url(_arquivos/_banners/img_'+img+'.jpg)'});
    abreConteudo('banner','titulos','img='+img);
}
