﻿/*  UTILIDADES_UNIVERSAIS
*   JQUERY_MASKEDINPUT-1.2.2.MIN
*   VOLVO_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 VOLVO_DEFAULT *************
function overmodelos(obj) {
    obj.style.backgroundPosition = 'bottom';
    document.getElementById("DIV" + obj.id).style.display = 'inline';
}
function outmodelos(obj) {
    obj.style.backgroundPosition = 'top';
    document.getElementById("DIV" + obj.id).style.display = 'none';
}

function volta_info() {
    document.getElementById('volvo_informa').className = 'area-de-informacoes-veiculos-oculta';
}

function informacoes_volvo(obj) {
    if (obj.id == 's40') {
        document.getElementById('volvo_informa').className = 'area-de-informacoes-veiculos-info-s40';
    } else if (obj.id == 's60') {
        document.getElementById('volvo_informa').className = 'area-de-informacoes-veiculos-info-s60';
    } else if (obj.id == 's80') {
        document.getElementById('volvo_informa').className = 'area-de-informacoes-veiculos-info-s80';
    } else if (obj.id == 'v50') {
        document.getElementById('volvo_informa').className = 'area-de-informacoes-veiculos-info-v50';
    } else if (obj.id == 'xc60') {
        document.getElementById('volvo_informa').className = 'area-de-informacoes-veiculos-info-xc60';
    } else if (obj.id == 'xc70') {
        document.getElementById('volvo_informa').className = 'area-de-informacoes-veiculos-info-xc70';
    } else if (obj.id == 'xc90') {
        document.getElementById('volvo_informa').className = 'area-de-informacoes-veiculos-info-xc90';
    } else if (obj.id == 'c30') {
        document.getElementById('volvo_informa').className = 'area-de-informacoes-veiculos-info-c30';
    } else if (obj.id == 'c70') {
        document.getElementById('volvo_informa').className = 'area-de-informacoes-veiculos-info-c70';
    }
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

startList = function () {
    if (document.all && document.getElementById) {
        navRoot = document.getElementById("nav");
        for (i = 0; i < navRoot.childNodes.length; i++) {
            node = navRoot.childNodes[i];
            if (node.nodeName == "LI") {
                node.onmouseover = function () {
                    this.className += " over";
                }
                node.onmouseout = function () {
                    this.className = this.className.replace(" over", "");
                }
            }
        }
    }
}
window.onload = startList;

function AbrirPopupSemiNovos(chassi, empresa, produto, modelo) {
    var link;
    link = "PopupSeminovos.aspx?ChassiResumido=" + chassi + "&Empresa=" + empresa + "&Produto=" + produto + "&Modelo=" + modelo;
    window.open(link, "", "height = 650, width = 540, scrollbars = yes", true);
}

/* Informacoes tecnicas */

function abreItens(obj) {
    $("#area_com_rolagem table").hide()

    if (obj.value == 'none') {
        $("#area_com_rolagem table").show()
    } else {
        $("#" + obj.value).show()
    }
}

$(function () {
    if ($(".galeria").length > 0) {
        $(".menu-novos").css("top", $(".img-principal").height())
    }

    $(".menu-novos ul li")
    .mouseover(function () {
        $(this).find("a").css("background-position", "0px 0px")
        $(this).find("a").animate({ backgroundPosition: "(0px -23px)" }, { duration: 100 })
    })
	.mouseout(function () {
	    $(this).find("a").animate({ backgroundPosition: "(0px 0px)" }, { duration: 80, complete: function () {
	        $(this).css({ backgroundPosition: "0px 0px" })
	    }
	    })
	})

    var bandeiras = $(".bandeiras-lang")
    $(".bandeiras-lang").remove()
    $(".area_direita").append(bandeiras)

    //modelos
    $(".envolta a img").each(function () {
        $(this)[0].src = "http://www.caltabiano.com.br/volvo/imgs/" + $(this)[0].src.split('/')[$(this)[0].src.split('/').length - 3] + "/" + $(this)[0].src.split('/')[$(this)[0].src.split('/').length - 1]
    })

    $('.detalhaImgs ul li a').mouseover(function () {
        $('.envolta a img').hide()
        $('#DIV' + this.id).show()
    })

    $('.envolta a img').hover(function () {
        $(this).fadeIn('normal')
    }, function () {
        $(this).fadeOut(400)
        $('.envolta a img').hide()
    })
})
//************* FIM VOLVO_DEFAULT *************
