﻿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 trim(String) {
	return String.replace(/^\s+|\s+$/g,"");
}

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 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;
    }
}

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 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 sucesso(msg)
{
    document.getElementById('erro').className = "sucessoModal";
    document.getElementById('erro').innerHTML = msg;
}

function sucessoEnvio(msg)
{
    document.getElementById('erro').className = "sucesso";
    document.getElementById('erro').innerHTML = msg;
}

function errar(msg)
{
    document.getElementById('erro').className = "erroModal";
    document.getElementById('erro').innerHTML = msg;
}
