﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />
var font_size = 12;
var cfPesquisou = false;
function Imprimir(elemento) {
    window.open("print.aspx?el=" + elemento, "CarroLivre", "width=700, height=600, menubar=yes, scrollbars=yes,toolbar=yes,location=no");
}
function EnviarEmail() {
    window.open("sendMail.aspx", "CarroLivre", "width=700, height=600, menubar=no, scrollbars = no, location=no");
}
function EscondeControles() {
    $("#dvControelsPag").hide();
}
function MostraControles() {
    $("#dvControelsPag").show();
}
function Aumentar(elemento) {
    document.getElementById(elemento).setAttribute("style", "font-Size:" + (font_size += 1) + "px");
}
function Diminuir(elemento) {
    document.getElementById(elemento).setAttribute("style", "font-Size:" + (font_size -= 1) + "px");
}
function LimparExemplo(campo, valor) {
    if (campo.value == valor) {
        campo.value = "";
    }
}
function isEmailAddress(theElement) {
    var s = theElement.val();
    var filter = /^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
    if (s.length == 0) return true;
    if (filter.test(s))
        return true;
    else
        theElement.focus();
    return true;
}
function Pesquisar(cb) {
    if ($("#ddlMarcasApelido").val() == "0") {
        alert("Selecione pelo menos a marca.");
        return false;
    } else {
    if (cfPesquisou == false) {
        var dti = $("#ctl00_colunaEsquerda_ddlAnoInicio").val();
        var dtf = $("#ctl00_colunaEsquerda_ddlAnoFinal").val();

        if (dtf == "0") {
            dtf = 2099;
        }

        if (dti == "") dti = 0;
        if (dtf == "") dtf = 0;


        if (dti > 0) {
            if (parseFloat(dti) > parseFloat(dtf)) {
                alert("O Ano inicial deve ser maior que o ano final.");
                return false;
            }
        }
        cb.value = 'Aguarde...'
        cfPesquisou = true;
    } else {
        return false;
    }
        return true;
    }
}

function PesquisarAv() {
    if ($("#ddlMarca").val() == "0") {
        alert("Selecione pelo menos a marca.");
        return false;
    } else {
        var dti = $("#ctl00_Conteudo_cboAnoI").val();
        var dtf = $("#ctl00_Conteudo_cboAnoF").val();
        if (dti == "") dti = 0;
        if (dtf == "") dtf = 0;


        if (dti > 0) {
            if (parseFloat(dti) > parseFloat(dtf)) {
                alert("O Ano inicial deve ser menor que o ano final.");
                return false;
            }
        }
        return true;
    }
}
function centrar(arquivo, janela, largura, altura) {
    posx = (screen.width / 2) - (largura / 2);
    posy = (screen.height / 2) - (altura / 2);

    features = "',width=" + largura + ", height=" + altura + ", top=" + posy + ", left=" + posx + ", scrollbars,resizable,status,toolbar,menubar'";
    window.open(arquivo, janela, features);
}
function LimparPesquisaRapida() {
    $("#ddlMarcasApelido").val("0");
    $("#ddlModelosApelido").val("0");
    $("#ctl00_colunaEsquerda_txtMarca").val("Palavra Chave");
    $("#ctl00_colunaEsquerda_ddlUF").val("");
    $("#ctl00_colunaEsquerda_ddlAnoInicio").val("");
    $("#ctl00_colunaEsquerda_ddlAnoFinal").val("");
    $("#ctl00_colunaEsquerda_ddlOrdenarPor").val("");
    $("#ctl00_colunaEsquerda__ckPesquisa").get(0).checked = false;
}
function handleError() {
    return true;
}

function NumFormat(Campo, Evento, AceitaNegativo) {

    if ((Evento.keyCode >= 96 && Evento.keyCode <= 105) || (Evento.keyCode >= 48 && Evento.keyCode <= 57)
	|| Evento.keyCode == 188 || Evento.keyCode == 190
	|| Evento.keyCode == 8 || Evento.keyCode == 46 || (Evento.keyCode == 189 && AceitaNegativo)) {
        campoTmp = Campo.value;
        reg = /[^0-9]/g;

        if (campoTmp.indexOf("-") == 0)
            negativo = "-";
        else
            negativo = "";

        campoTmp = campoTmp.replace(reg, "");
        result = "";
        i = 4;
        len = campoTmp.length;
        if (len > 2) {
            parteDecimal = campoTmp.substr(len - 2, 2)
            campoTmp = campoTmp.substr(0, len - 2)
            len = campoTmp.length;
            while (i <= campoTmp.length) {
                result = '.' + campoTmp.substr(len - 3, 3) + result;
                i += 3;
                len -= 3;
            }
            result = campoTmp.substr(0, len) + result;
            Campo.value = negativo + result + ',' + parteDecimal;
        }
        else
            Campo.value = negativo + Campo.value.replace(reg, "");
    }
    else
        if ((Evento.keyCode < 35 || Evento.keyCode > 40) && Evento.keyCode != 9 && Evento.keyCode != 16) {
        if (AceitaNegativo)
            reg = /[^0-9,-\.]/g;
        else
            reg = /[^0-9,\.]/g;

        Campo.value = Campo.value.replace(reg, "");
    }
}


window.onerror = handleError;

