﻿/* UTILIDADES_UNIVERSAIS
*  JQUERY_MASKEDINPUT-1.2.2.MIN
*  PORTAL_DEFAULT
*/

//************* INICIO UTILIDADES_UNIVERSAIS *************
// MASCARAS
function mascaras() {
$(".data").mask("99/99/9999")
$(".fone").mask("(99)9999-9999")
$(".cep").mask("99999-999")
$(".hora").mask("99:99")
}

$(function () {
mascaras()
})

function FormatacaoCpfCnpj(e) {
var tecla = (window.event) ? event.keyCode : e.which;
if ((tecla >= 45 && tecla < 58) || (tecla == 44 || tecla == 46))
return true;
else {
if (tecla != 8)
return false;
else
return true;
}
}


// FLASH
function ReescreveFlash(swf, width, height, flashvars, id) {
var escreveFlash = new String();
if (navigator.appName.indexOf("Microsoft") != -1) {
escreveFlash += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
escreveFlash += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=version=8,0,0,0" ';
escreveFlash += 'width="' + width + '" height="' + height + '" name="' + id + '"id = ' + id + '">';
escreveFlash += '<param name="movie" value="' + swf + '"/>';
if (flashvars != null) { escreveFlash += '<param name="flashvars" value="' + flashvars + '"/>' };
escreveFlash += '<param name="menu" value="false"/>';
escreveFlash += '<param name="salign" value="LT"/>';
escreveFlash += '<param name="scale" value="noscale"/>';
escreveFlash += '<param name="wmode" value="transparent"/>';
escreveFlash += '<param name="allowScriptAccess" value="sameDomain"/>';
escreveFlash += '</object>';
} else {
escreveFlash += '<embed src="' + swf + '" ';
escreveFlash += 'width="' + width + '" ';
escreveFlash += 'height="' + height + '" ';
escreveFlash += 'id="' + id + '" ';
escreveFlash += 'name="' + id + '" ';
escreveFlash += 'menu="false" ';
escreveFlash += 'scale="noscale" ';
escreveFlash += 'salign="LT" ';
escreveFlash += 'wmode="transparent" ';
escreveFlash += 'allowScriptAccess="sameDomain" ';
if (flashvars != null) { escreveFlash += 'flashvars="' + flashvars + '" ' };
escreveFlash += 'type="application/x-shockwave-flash" ';
escreveFlash += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
escreveFlash += '</embed>';
}
return escreveFlash;
}

function Flash(swf, width, height, flashvars, id) {
var escreveFlash = new String();
if (navigator.appName.indexOf("Microsoft") != -1) {
escreveFlash += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
escreveFlash += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=version=8,0,0,0" ';
escreveFlash += 'width="' + width + '" height="' + height + '" name="' + id + '"id = ' + id + '">';
escreveFlash += '<param name="movie" value="' + swf + '"/>';
if (flashvars != null) { escreveFlash += '<param name="flashvars" value="' + flashvars + '"/>' };
escreveFlash += '<param name="menu" value="false"/>';
escreveFlash += '<param name="salign" value="LT"/>';
escreveFlash += '<param name="scale" value="noscale"/>';
escreveFlash += '<param name="wmode" value="transparent"/>';
escreveFlash += '<param name="allowScriptAccess" value="sameDomain"/>';
escreveFlash += '</object>';
} else {
escreveFlash += '<embed src="' + swf + '" ';
escreveFlash += 'width="' + width + '" ';
escreveFlash += 'height="' + height + '" ';
escreveFlash += 'id="' + id + '" ';
escreveFlash += 'name="' + id + '" ';
escreveFlash += 'menu="false" ';
escreveFlash += 'scale="noscale" ';
escreveFlash += 'salign="LT" ';
escreveFlash += 'wmode="transparent" ';
escreveFlash += 'allowScriptAccess="sameDomain" ';
if (flashvars != null) { escreveFlash += 'flashvars="' + flashvars + '" ' };
escreveFlash += 'type="application/x-shockwave-flash" ';
escreveFlash += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
escreveFlash += '</embed>';
}
document.write(escreveFlash);
}


//MENSAGENS PARA USUARIO
function exibeerro(msg) {
mensagem(msg);
document.getElementById('erro').className = "errocampo campoerro erroMenor";
document.getElementById('erro').focus();
}

function errar(msg) {
mensagem(msg);
document.getElementById('erro').className = "errocampo campoerro erroMenor";
document.getElementById('erro').focus();
}

function sucesso(msg) {
//document.getElementById("imgConversaoGA").src = "http://www.googleadservices.com/pagead/conversion/1035864199/?label=_yeaCIXyxAEQh5H47QM&amp;guid=ON&amp;script=0";

mensagem(msg);
document.getElementById('erro').className = "sucesso";
document.getElementById('erro').focus();
}

function mensagem(msg) {
    document.getElementById('erro').innerHTML = msg;
}

function ocultar() {
document.getElementById('erro').innerHTML = "";
document.getElementById('erro').className = "invisivel";
}


//FUNCOES DIVERSAS
function trim(String) {
return String.replace(/^\s+|\s+$/g, "");
}

function SomenteNumero(e) {
var tecla = (window.event) ? event.keyCode : e.which;
if ((tecla > 47 && tecla < 58))
return true;
else {
if (tecla != 8)
return false;
else
return true;
}
}

function FormataValor(el, portugues) {
if (portugues) {
var val = el.value
var answer_match = "$1,$2"                         // Delimitador casas decimal , (virgula)
var aux;
val = val.replace(/\D/g, "")                       // Remove tudo o que não é dígito
val = val.replace(/(\d)(\d{2})$/, answer_match)    // Coloca a separação de decimal
answer_match = "$1.$2"                             // Delimitador milhares
aux = val.match(/(\,\d+)$/)                        // Salva o valor decimal na variavel auxiliar
if (aux) {                                          // Verifica se existe decimais, senão não existirá milhar
aux = aux[0]
var compare = val.replace(aux, "")              // Pega apenas o valor a ser comparado
while (compare.match(/(\d+)(\d{3})/)) {
compare = compare.replace(/(\d+)(\d{3})/, answer_match)    // Coloca o delimitador a cada milhar
}
val = compare + aux
}
// Change this val
el.value = val
} else {
var val = el.value
var answer_match = "$1.$2"                         // Delimitador casas decimal , (virgula)
var aux;
val = val.replace(/\D/g, "")                       // Remove tudo o que não é dígito
val = val.replace(/(\d)(\d{2})$/, answer_match)    // Coloca a separação de decimal
answer_match = "$1,$2"                             // Delimitador milhares
aux = val.match(/(\.\d+)$/)                        // Salva o valor decimal na variavel auxiliar
if (aux) {                                          // Verifica se existe decimais, senão não existirá milhar
aux = aux[0]
var compare = val.replace(aux, "")              // Pega apenas o valor a ser comparado
while (compare.match(/(\d+)(\d{3})/)) {
compare = compare.replace(/(\d+)(\d{3})/, answer_match)    // Coloca o delimitador a cada milhar
}
val = compare + aux
}
// Change this val
el.value = val
}
}

function SomenteNumeroComPontuacao(e) {
var tecla = (window.event) ? event.keyCode : e.which;
if ((tecla > 47 && tecla < 58) || (tecla == 44 || tecla == 46))
return true;
else {
if (tecla != 8)
return false;
else
return true;
}
}

function txtBoxFormat(objeto, sMask, evtKeyPress) {
var i, nCount, sValue, fldLen, mskLen, bolMask, sCod, nTecla;

if (document.all) { // Internet Explorer
nTecla = evtKeyPress.keyCode;
} else if (document.layers) { // Nestcape
nTecla = evtKeyPress.which;
} else {
nTecla = evtKeyPress.which;
if (nTecla == 8) {
return true;
}
}

sValue = objeto.value;

// Limpa todos os caracteres de formatação que
// já estiverem no campo.
sValue = sValue.toString().replace("-", "");
sValue = sValue.toString().replace("-", "");
sValue = sValue.toString().replace(".", "");
sValue = sValue.toString().replace(".", "");
sValue = sValue.toString().replace("/", "");
sValue = sValue.toString().replace("/", "");
sValue = sValue.toString().replace(":", "");
sValue = sValue.toString().replace(":", "");
sValue = sValue.toString().replace("(", "");
sValue = sValue.toString().replace("(", "");
sValue = sValue.toString().replace(")", "");
sValue = sValue.toString().replace(")", "");
sValue = sValue.toString().replace(" ", "");
sValue = sValue.toString().replace(" ", "");
fldLen = sValue.length;
mskLen = sMask.length;

i = 0;
nCount = 0;
sCod = "";
mskLen = fldLen;

while (i <= mskLen) {
bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

if (bolMask) {
sCod += sMask.charAt(i);
mskLen++;
}
else {
sCod += sValue.charAt(nCount);
nCount++;
}

i++;
}

objeto.value = sCod;

if (nTecla != 8) { // backspace
if (sMask.charAt(i - 1) == "9") { // apenas números...
return ((nTecla >= 47) && (nTecla <= 58));
}
else { // qualquer caracter...
return true;
}
}
else {
return true;
}
}
//************* FIM UTILIDADES_UNIVERSAIS *************


//************* INICIO JQUERY_MASKEDINPUT-1.2.2.MIN *************
/*
Masked Input plugin for jQuery
Copyright (c) 2007-2009 Josh Bush (digitalbush.com)
Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) 
Version: 1.2.2 (03/09/2009 22:39:06)
*/
(function (a) { var c = (a.browser.msie ? "paste" : "input") + ".mask"; var b = (window.orientation != undefined); a.mask = { definitions: { "9": "[0-9]", a: "[A-Za-z]", "*": "[A-Za-z0-9]"} }; a.fn.extend({ caret: function (e, f) { if (this.length == 0) { return } if (typeof e == "number") { f = (typeof f == "number") ? f : e; return this.each(function () { if (this.setSelectionRange) { this.focus(); this.setSelectionRange(e, f) } else { if (this.createTextRange) { var g = this.createTextRange(); g.collapse(true); g.moveEnd("character", f); g.moveStart("character", e); g.select() } } }) } else { if (this[0].setSelectionRange) { e = this[0].selectionStart; f = this[0].selectionEnd } else { if (document.selection && document.selection.createRange) { var d = document.selection.createRange(); e = 0 - d.duplicate().moveStart("character", -100000); f = e + d.text.length } } return { begin: e, end: f} } }, unmask: function () { return this.trigger("unmask") }, mask: function (j, d) { if (!j && this.length > 0) { var f = a(this[0]); var g = f.data("tests"); return a.map(f.data("buffer"), function (l, m) { return g[m] ? l : null }).join("") } d = a.extend({ placeholder: "_", completed: null }, d); var k = a.mask.definitions; var g = []; var e = j.length; var i = null; var h = j.length; a.each(j.split(""), function (m, l) { if (l == "?") { h--; e = m } else { if (k[l]) { g.push(new RegExp(k[l])); if (i == null) { i = g.length - 1 } } else { g.push(null) } } }); return this.each(function () { var r = a(this); var m = a.map(j.split(""), function (x, y) { if (x != "?") { return k[x] ? d.placeholder : x } }); var n = false; var q = r.val(); r.data("buffer", m).data("tests", g); function v(x) { while (++x <= h && !g[x]) { } return x } function t(x) { while (!g[x] && --x >= 0) { } for (var y = x; y < h; y++) { if (g[y]) { m[y] = d.placeholder; var z = v(y); if (z < h && g[y].test(m[z])) { m[y] = m[z] } else { break } } } s(); r.caret(Math.max(i, x)) } function u(y) { for (var A = y, z = d.placeholder; A < h; A++) { if (g[A]) { var B = v(A); var x = m[A]; m[A] = z; if (B < h && g[B].test(x)) { z = x } else { break } } } } function l(y) { var x = a(this).caret(); var z = y.keyCode; n = (z < 16 || (z > 16 && z < 32) || (z > 32 && z < 41)); if ((x.begin - x.end) != 0 && (!n || z == 8 || z == 46)) { w(x.begin, x.end) } if (z == 8 || z == 46 || (b && z == 127)) { t(x.begin + (z == 46 ? 0 : -1)); return false } else { if (z == 27) { r.val(q); r.caret(0, p()); return false } } } function o(B) { if (n) { n = false; return (B.keyCode == 8) ? false : null } B = B || window.event; var C = B.charCode || B.keyCode || B.which; var z = a(this).caret(); if (B.ctrlKey || B.altKey || B.metaKey) { return true } else { if ((C >= 32 && C <= 125) || C > 186) { var x = v(z.begin - 1); if (x < h) { var A = String.fromCharCode(C); if (g[x].test(A)) { u(x); m[x] = A; s(); var y = v(x); a(this).caret(y); if (d.completed && y == h) { d.completed.call(r) } } } } } return false } function w(x, y) { for (var z = x; z < y && z < h; z++) { if (g[z]) { m[z] = d.placeholder } } } function s() { return r.val(m.join("")).val() } function p(y) { var z = r.val(); var C = -1; for (var B = 0, x = 0; B < h; B++) { if (g[B]) { m[B] = d.placeholder; while (x++ < z.length) { var A = z.charAt(x - 1); if (g[B].test(A)) { m[B] = A; C = B; break } } if (x > z.length) { break } } else { if (m[B] == z[x] && B != e) { x++; C = B } } } if (!y && C + 1 < e) { r.val(""); w(0, h) } else { if (y || C + 1 >= e) { s(); if (!y) { r.val(r.val().substring(0, C + 1)) } } } return (e ? B : i) } if (!r.attr("readonly")) { r.one("unmask", function () { r.unbind(".mask").removeData("buffer").removeData("tests") }).bind("focus.mask", function () { q = r.val(); var x = p(); s(); setTimeout(function () { if (x == j.length) { r.caret(0, x) } else { r.caret(x) } }, 0) }).bind("blur.mask", function () { p(); if (r.val() != q) { r.change() } }).bind("keydown.mask", l).bind("keypress.mask", o).bind(c, function () { setTimeout(function () { r.caret(p(true)) }, 0) }) } p() }) } }) })(jQuery);
//************* FIM JQUERY_MASKEDINPUT-1.2.2.MIN *************

//************* INICIO PORTAL_DEFAULT *************
function pesquisaavancada(obj) {
    var objeto = obj.id + "avancada";
    document.getElementById(objeto).style.display = 'inline';
}

function verCarro(el) {
    document.getElementById('imgMaior').src = el.href;
    return false;
}

function dataMaiorQueAtual(data) {
    dataAtual = new Date();
    diaAtual = dataAtual.getDate();
    mesAtual = dataAtual.getMonth() + 1;
    anoAtual = dataAtual.getFullYear();

    dia = data.split("/")[0].toString();
    mes = data.split("/")[1].toString();
    ano = data.split("/")[2].toString();

    if ((anoAtual > ano) || (anoAtual == ano && mesAtual > mes) || (anoAtual == ano && mesAtual == mes && diaAtual > dia)) {
        return false;
    } else {
        return true;
    }
}

function AtualizaBanner() {
    var existe = document.getElementById("divBanner");
    if (existe)
        document.getElementById("divBanner").innerHTML = ReescreveFlash('../banner/banner-home.swf', '693', '220', '', 'BannerCaltabiano');

    var existeSeminovos = document.getElementById("divBannerSeminovos");
    if (existeSeminovos)
        document.getElementById("divBannerSeminovos").innerHTML = ReescreveFlash('../banner/banner-seminovos.swf', '693', '220', '', 'BannerCaltabiano');
}

$(function () {

    // AJAX - OVER PARA DETERMINADOS OBJETOS
    $('.tabela tr').mouseover(function () {
        $(this).find('td').addClass('tabela-over');
    })
    $('.tabela tr').mouseout(function () {
        $(this).find('td').removeClass('tabela-over');
    })
    $('.veiculo-seminovos').mouseover(function () {
        $(this).css('background-color', 'red');
    })

    $('.textboxBusca').focus(function () {
        $(this).addClass('textboxBusca-over');
    })

    $('.textboxBusca').blur(function () {
        $(this).removeClass('textboxBusca-over');
    })


    // BRILHO
    $('.brilho').hover(function () {
        $(this).fadeTo("fast", 0.2, function () {
            $(this).fadeTo("fast", 1)
        })
    });
})

// AJAX - Vendas Diplomáticas

function fechavendas() {
    document.getElementById('DIVum').style.display = 'none';
    document.getElementById('DIVdois').style.display = 'none';
    document.getElementById('DIVtres').style.display = 'none';
    document.getElementById('DIVquatro').style.display = 'none';
    document.getElementById('DIVcinco').style.display = 'none';
    document.getElementById('um').className = ''
    document.getElementById('dois').className = ''
    document.getElementById('tres').className = ''
    document.getElementById('quatro').className = ''
    document.getElementById('cinco').className = ''
}

function verifica_venda_diplomatica_interno(obj) {
    fechavendas();
    obj.className = "linkativado";
    var usual = "DIV" + obj.id;
    document.getElementById(usual).style.display = 'inline';
}

// GOOGLE MAPS

function MapaGoogle(DivMapa, hdnLoja, hdnTo, hdnTelefone) {
    mapa = new GMap2(document.getElementById(DivMapa), { size: new GSize(600, 300) });
    mapa.addControl(new GLargeMapControl());
    mapa.setCenter(new GLatLng(-23.547779, -46.639366), 12);
    mapa.addControl(new GMapTypeControl());

    geocoder = new GClientGeocoder();
    mapa = showAddress(document.getElementById(hdnLoja).value,
    document.getElementById(hdnTo).value, document.getElementById(hdnTelefone).value, mapa);
}

function MostraImagemPesquisa(nomeImagem, imagem) {
    eval("document.getElementById('ctl00_ContentPlaceHolder1_ListaSeminovos1_rptResultado_" + nomeImagem + "').src = 'http://www.caltabiano.com.br/imgveiculos/" + imagem + "';");
}

function MostraDestalhesVeiculo(ChassiResumido, CodEmpresa, CodProduto, CodModelo) {
    $('#ctl00_ContentPlaceHolder1_ListaSeminovos1_hdnChassiResumido')[0].value = ChassiResumido;
    $('#ctl00_ContentPlaceHolder1_ListaSeminovos1_hdnCodEmpresa')[0].value = CodEmpresa;
    $('#ctl00_ContentPlaceHolder1_ListaSeminovos1_hdnCodProduto')[0].value = CodProduto;
    $('#ctl00_ContentPlaceHolder1_ListaSeminovos1_hdnCodModelo')[0].value = CodModelo;
}

function NumeroPagina(num) {
    window.location = "#topo";
    $('#ctl00_ContentPlaceHolder1_ListaSeminovos1_hdnPagina')[0].value = num;
}

function NumeroBloco(num) {
    window.location = "#topo";
    $('#ctl00_ContentPlaceHolder1_ListaSeminovos1_hdnBloco')[0].value = num;
}
//************* FIM PORTAL_DEFAULT *************

