function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function mudacor(prmThis,prmName)	{
		prmThis.className = prmName;
}

var win = null;
function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',noresizable,status=yes'
	win = window.open(mypage,myname,settings)
}

function Redimensiona(w, h) {
	window.resizeTo(w, h);
	window.focus();
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

// Recupera informações de um cookie
function getCookieVal(inicio) {
	var fim = document.cookie.indexOf(";", inicio);
	if (fim == -1) fim = document.cookie.length;
	return unescape(document.cookie.substring(inicio, fim));
}

function getCookie(label) {
	var arg = label + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i,j) == arg) return getCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function setCookie(label, valor, expires) {
	document.cookie = label + "=" + escape(valor) + 
		((expires) ? "; expires=" + expires.toGMTString() : "");
}

function delCookie(label) {
	if (getCookie(label)) {
		document.cookie = label + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

/* 
	Mascara para Campos.
	"#" - Numeros
	"A" - Letras UpperCase
	"a" - Letras LowerCase
	"Z" - Letras
	"*" - Qualquer Caracter
	"/", ".", "-", " ", ":" - Caracteres Fixos
*/
function Mascara(objeto, evt, mask) {
		
	var LetrasU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var LetrasL = 'abcdefghijklmnopqrstuvwxyz';
	var Letras 	= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
	var Numeros = '0123456789';
	var Fixos 	= '().-:/ '; 
	var Charset = " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_/`abcdefghijklmnopqrstuvwxyz{|}~";
	
	evt = (evt) ? evt : (window.event) ? window.event : "";
	var value = objeto.value;
	if (evt) {
		var ntecla = (evt.which) ? evt.which : evt.keyCode;
		tecla = Charset.substr(ntecla - 32, 1);
		if (ntecla < 32) return true;

		var tamanho = value.length;
		if (tamanho >= mask.length) return false;

		var pos = mask.substr(tamanho,1); 
		while (Fixos.indexOf(pos) != -1) {
			value += pos;
			tamanho = value.length;
			if (tamanho >= mask.length) return false;
			pos = mask.substr(tamanho,1);
		}

		switch (pos) {
				case '#' : if (Numeros.indexOf(tecla) == -1) return false; break;
				case 'A' : if (LetrasU.indexOf(tecla) == -1) return false; break;
				case 'a' : if (LetrasL.indexOf(tecla) == -1) return false; break;
				case 'Z' : if (Letras.indexOf(tecla) == -1) return false; break;
				case '*' : objeto.value = value; return true; break;
				default : return false; break;
		}
	}
	objeto.value = value; 
	return true;
}

// Deixa a string apenas com os numeros, eliminando o restante.
function trimToDigits(string) {
	s = "";
	var Numeros = /\d/;
	for (i = 0; i <= string.length; i++) 
		if (Numeros.test(string.substr(i,1))) s += string.substr(i,1);
	return s;	
}

function VEmail( strEmail ) {
     var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
     return (filter.test(strEmail));
}

function VAno(ano) {
	ano = trimToDigits(ano);
	return ((parseInt(ano) < 1900) || (ano.length != 4) || (parseInt(ano) > 2050)) ? false : true; 
}

function VMes(mes) {
	mes = trimToDigits(mes);
	return ((mes.length != 2) || (parseInt(mes) < 1) || (parseInt(mes) > 12)) ? false : true; 
}

function VMesAno(data) {
	data = trimToDigits(data);
	if (data.length < 6) return false;
	mes = data.substr(0,2);
	ano = data.substr(2,4);
	return (!VAno(ano) || !VMes(mes)) ? false : true;
}
//Verifica se a data é valida
function VData(data) {
	data = trimToDigits(data);
	if (data.length < 8) return false;
	dia = data.substr(0,2);
	mes = data.substr(2,2);
	ano = data.substr(4,4);
	
	if(ano >= 0 && ano < 1900) return false; 
	if(ano > 2100 || ano < 0 || mes > 12 || mes < 1) return false; 
	numero = ((parseInt(ano) - 1884) / 4) 
	dias = (numero == Math.floor(numero)) ? "312931303130313130313031" : "312831303130313130313031"; 
	diamax = parseInt(dias.substring((mes - 1) * 2, ((mes - 1) * 2) + 2)); 
	if(dia < 1 || dia > diamax) return false; 	
	
	return true;
}

// Verifica a autenticidade do CPF
function VCPF(cpf) {
	cpf = trimToDigits(cpf);
	if (cpf.length < 11) return false;
	valor = true;
	if (cpf == "00000000000" || cpf == "11111111111" || 
			cpf == "22222222222" || cpf == "33333333333" || 
			cpf == "44444444444" || cpf == "55555555555" || 
			cpf == "66666666666" || cpf == "77777777777" || 
			cpf == "88888888888" || cpf == "99999999999") return false;

	var a = [];
	var b = new Number;
	var c = 11;
	for (i = 0; i < 11; i++) {
		a[i] = cpf.charAt(i);
		b = (i < 9) ? b + (a[i] *  --c) : b;
	}
	
	a[9] = ((x = b % 11) < 2) ? 0 : 11 - x;

	b = 0;
	c = 11;
	for (y = 0; y < 10; y++) b += (a[y] *  c--); 
	a[10] = ((x = b % 11) < 2) ? 0 : 11 - x;

	return (cpf.charAt(9) == a[9]) && (cpf.charAt(10) == a[10]);
}	

function VCNPJ(cnpj) {
	cnpj = trimToDigits(cnpj);
	if (cnpj.length < 14) return false;
	m2 = 2;		
	soma1 = 0;
	soma2 = 0;
	for ( i = 11; i >= 0; i--) {
		val = eval(cnpj.charAt(i));
		m1 = m2;
		if (m2 < 9) { m2++ }
	 	else { m2 = 2 }
		soma1 = soma1 + (val * m1)
		soma2 = soma2 + (val * m2)
  }
	soma1 = soma1 % 11
	if (soma1 < 2) { d1 = 0 }
  else { d1 = 11 - soma1}
	soma2 = (soma2 + (2 * d1)) % 11
	if (soma2 < 2) { d2 = 0 }
  else { d2 = 11 - soma2}
	return (cnpj.charAt(12) == d1) && (cnpj.charAt(13) == d2);
}

function MaskAno(objeto, evt) { 
	return Mascara(objeto, evt, '####');
}

function MaskMesAno(objeto, evt) { 
	return Mascara(objeto, evt, '##/####');
}

function MaskCEP(objeto, evt) { 
	return Mascara(objeto, evt, '##.###-###');
}

function MaskTelefone(objeto, evt) { 
	return Mascara(objeto, evt, '(##) ####-####');
}

function MaskCPF(objeto, evt) { 
	return Mascara(objeto, evt, '###.###.###-##');
}

function MaskCNPJ(objeto, evt) { 
	return Mascara(objeto, evt, '##.###.###/####-##');
}

function MaskData(objeto, evt) { 
	return Mascara(objeto, evt, '##/##/####');
}

function MaskHora(objeto, evt) { 
	return Mascara(objeto, evt, '##:##');
}

function MaskHora2(objeto, evt) { 
	return Mascara(objeto, evt, '##:##:##');
}

var tipo = 0;

function FaleConosco() {
	tipo = 1;
	document.form1.action = "mail.asp";
	document.form1.method = "post";
}

function Newsletter() {
	tipo = 2;
	document.form1.action = "newsletter-action.asp";
	document.form1.method = "post";
}

function Busca() {
	tipo = 3;
	document.form1.action = "";
	document.form1.method = "get";
}

function AcessoRestrito() {
	tipo = 4;
	document.form1.action = "/acessorestrito/login.asp";
	document.form1.method = "post";
}

function AlterarSenha() {
	tipo = 5;
	document.form1.action = "/acessorestrito/alterar-action.asp";
	document.form1.method = "post";
}

function AcessoRestritoPP() {
	tipo = 6;
	document.form1.action = "/acessorestrito/login.asp";
	document.form1.method = "post";
}

function AlterarVeiculo() {
	tipo = 7;
	document.form1.action = "/acessorestrito/alterar-veiculo-action.asp";
	document.form1.method = "post";
}

function InserirVeiculo() {
	tipo = 8;
	document.form1.action = "/acessorestrito/veiculos-inserir-action.asp";
	document.form1.method = "post";
}

function BuscaVeic() {
	tipo = 9;
	document.form1.action = "/veiculos/busca.asp";
	document.form1.method = "post";
}

function BuscaVeic2() {
	tipo = 9;
	document.form1.action = "/veiculos/busca.asp";
	document.form1.method = "post";
}

function IndiqueAmigo() {
	tipo = 10;
	document.form1.action = "/veiculos/indique-mail.asp";
	document.form1.method = "post";
}

function BuscaVeic3() {
	tipo = 11;
	document.form1.action = "/veiculos/busca.asp";
	document.form1.method = "post";
}

function VFaleConosco() {
	if (!document.form1.nome.value) { alert("Por favor, informe seu nome."); document.form1.nome.focus(); return false; };
  if (!VEmail( document.form1.email.value)) { alert("O seu e-mail não é válido!\nVerifique-o novamente."); document.form1.email.focus(); return false; };
  if (!document.form1.cidade.value) { alert("Por favor, informe a cidade."); document.form1.cidade.focus(); return false; };
  if (!document.form1.mensagem.value) { alert("Você deve escrever a mensagem."); document.form1.mensagem.focus(); return false; };
  return true;
}

function VNewsletter() {
	if (!document.form1.newsnome.value) { alert("Por favor, informe seu nome."); document.form1.newsnome.focus(); return false; };
  if (!VEmail(document.form1.newsemail.value)) { alert("O seu e-mail não é válido!\nVerifique-o novamente."); document.form1.newsemail.focus(); return false; };
  return true;
}

function VBusca() {
	if (!(document.form1.busca.value.length > 1)) { alert("Informe um número maior de caracteres para busca."); document.form1.busca.focus(); return false; };
	return true;
}

function VBuscaVeic() {
	if ((document.form1.categoria.value == "-") && (!document.form1.veiculo.value) && (document.form1.motorizacao.value == "-") && (document.form1.valormedio.value == "-") && (document.form1.ano.value == "-")) { alert("Por favor, informe pelo menos um critério de busca."); document.form1.veiculo.focus(); return false; }	
	return true;
}

function VBuscaVeic3() {
	var chk = false;
	for (var i = 0; i <= document.form1.chkacessorio.length - 1; i++) {
		if (document.form1.chkacessorio[i].checked) {
			chk = true;
		}
	}

	if ((document.form1.categoria.value == "-") && (!document.form1.veiculo.value) && (document.form1.motorizacao.value == "-") && (document.form1.combustivel.value == "-") && (document.form1.valormedio.value == "-") && (document.form1.ano.value == "-") && (document.form1.marcas.value == "-") && (!chk)) { alert("Por favor, informe pelo menus um critério de busca."); document.form1.veiculo.focus(); return false; }	
	return true;
}

function VAcessoRestrito() {
  if (document.form1.login.value == "") { alert("Por favor, informe seu Login."); document.form1.login.focus(); return false; };
  if (document.form1.senha.value == "") { alert("Por favor, informe a Senha."); document.form1.senha.focus(); return false; };
  return true;
}

function VAlterarSenha() {
  if (document.form1.senha.value == "") { alert("Por favor, informe a Senha."); document.form1.senha.focus(); return false; };
  if (document.form1.senhac.value == "") { alert("Por favor, confirme a sua nova Senha."); document.form1.senhac.focus(); return false; };
  if (document.form1.telefone.value == "") { alert("Por favor, informe seu telefone."); document.form1.telefone.focus(); return false; };
  if (document.form1.endereco.value == "") { alert("Por favor, informe seu endereço."); document.form1.endereco.focus(); return false; };
  if (document.form1.senha.value != document.form1.senhac.value) { alert("As Senhas digitadas não coincidem."); document.form1.senha.focus(); return false; };
  return true;
}

function VAcessoRestritoPP() {
  if (document.form1.login.value == "") { alert("Por favor, informe seu Login."); document.form1.login.focus(); return false; };
  if (document.form1.senha.value == "") { alert("Por favor, informe a Senha."); document.form1.senha.focus(); return false; };
  return true;
}

function VAlterarVeiculo() {
  if (document.form1.categoria.value == "-") { alert("Por favor, informe o tipo."); document.form1.categoria.focus(); return false; };
  if (document.form1.combustivel.value == "-") { alert("Por favor, informe o combustível."); document.form1.combustivel.focus(); return false; };
  if (document.form1.marca.value == "-") { alert("Por favor, informe a marca."); document.form1.marca.focus(); return false; };
  if (document.form1.veiculo.value == "") { alert("Por favor, informe o nome do veículo."); document.form1.veiculo.focus(); return false; };
  if (document.form1.ano.value == "") { alert("Por favor, informe o ano/modelo do veículo."); document.form1.ano.focus(); return false; };
  if (document.form1.valor.value == "") { alert("Por favor, informe o valor do veículo."); document.form1.valor.focus(); return false; };
  if (document.form1.cor.value == "") { alert("Por favor, informe a cor do veículo."); document.form1.cor.focus(); return false; };
  if (document.form1.referencia.value == "") { alert("Por favor, informe a referência do veículo."); document.form1.referencia.focus(); return false; };
  return true;
}

function VInserirVeiculo() {
  if (document.form1.categoria.value == "-") { alert("Por favor, informe o tipo."); document.form1.categoria.focus(); return false; };
  if (document.form1.marca.value == "-") { alert("Por favor, informe a marca."); document.form1.marca.focus(); return false; };
  if (document.form1.veiculo.value == "") { alert("Por favor, informe o nome do veículo."); document.form1.veiculo.focus(); return false; };
  if (document.form1.ano.value == "") { alert("Por favor, informe o ano/modelo do veículo."); document.form1.ano.focus(); return false; };
  if (document.form1.valor.value == "") { alert("Por favor, informe o valor do veículo."); document.form1.valor.focus(); return false; };
  if (document.form1.cor.value == "") { alert("Por favor, informe a cor do veículo."); document.form1.cor.focus(); return false; };
  if (document.form1.referencia.value == "") { alert("Por favor, informe a referência do veículo."); document.form1.referencia.focus(); return false; };
  return true;
}

function VIndiqueAmigo() {
	if (!document.form1.nome.value) { alert("Por favor, informe seu nome."); document.form1.nome.focus(); return false; };
	if (!document.form1.nomeamigo.value) { alert("Por favor, informe o nome do seu amigo."); document.form1.nomeamigo.focus(); return false; };
  if (!VEmail( document.form1.email.value)) { alert("O seu e-mail não é válido!\nVerifique-o novamente."); document.form1.email.focus(); return false; };
  if (!VEmail( document.form1.emailamigo.value)) { alert("O e-mail do seu amigo não é válido!\nVerifique-o novamente."); document.form1.emailamigo.focus(); return false; };
  if (!document.form1.comentario.value) { alert("Você deve escrever a mensagem."); document.form1.comentario.focus(); return false; };
  return true;
}

function EnviaFormulario() {
	switch(tipo) {
		case 1: return VFaleConosco(); break;
		case 2: return VNewsletter(); break;
		case 3:	if (VBusca()) { document.location.href="/veiculos/busca.asp?busca=" + document.form1.busca.value; } break;
		case 4: return VAcessoRestrito();
		case 5: return VAlterarSenha();
		case 6: return VAcessoRestritoPP();
		case 7: return VAlterarVeiculo();
		case 8: return VInserirVeiculo();
		case 9:	return VBuscaVeic();
		case 10: return VIndiqueAmigo(); break;
		case 11: return VBuscaVeic3();
	}
	return false;
}

function ExibeFlash(w,h,wmode,movie) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+w+'" height="'+h+'">');
	document.write('<param name="wmode" value="'+wmode+'"/>');
	document.write('<param name="quality" value="high"/>');
	document.write('<param name="movie" value="'+movie+'"/>');
	document.write('<embed src="'+movie+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="'+wmode+'" width="'+w+'" height="'+h+'"></embed>');
	document.write('</object>');
}
function ExibeVeiculo(cod) {
	self.location.href = "exibir.asp?cod="+cod ;
}
function ExibeVeiculo2(cod) {
	var janela = window.open ('exibir.asp?cod='+cod,'','width=800,height=600,scrollbars=yes');
}
function ExibeVeiculoRevenda(cod) {
	self.location.href = "/veiculos/exibir.asp?cod="+cod ;
}
function ExibeVeiculoBusca(cod) {
	self.location.href = "/veiculos/exibir.asp?cod="+cod ;
}
function ExibeRevenda(cod) {
	self.location.href = "exibir.asp?cod="+cod ;
}
function FecharPopUp() {
	document.getElementById("popup").style.visibility = "hidden";
	document.getElementById("categoria").style.visibility = "visible";
	document.getElementById("cidade").style.visibility = "visible";
	document.getElementById("veiculo").style.visibility = "visible";
	document.getElementById("valormedio").style.visibility = "visible";
	document.getElementById("motorizacao").style.visibility = "visible";
	document.getElementById("ano").style.visibility = "visible";
}
function ExibePopUp(w,h,wmode,movie) {
	document.getElementById("categoria").style.visibility = "hidden";
	document.getElementById("cidade").style.visibility = "hidden";
	document.getElementById("veiculo").style.visibility = "hidden";
	document.getElementById("valormedio").style.visibility = "hidden";
	document.getElementById("motorizacao").style.visibility = "hidden";
	document.getElementById("ano").style.visibility = "hidden";
	marginLeft = parseInt(-w / 2);
	document.write('<div id="popupDHTML" style="width:'+w+'px; height:'+h+'px; left:50%; margin-left:'+marginLeft+'px;">');
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+w+'" height="'+h+'">');
	document.write('<param name="wmode" value="'+wmode+'"/>');
	document.write('<param name="quality" value="high"/>');
	document.write('<param name="movie" value="'+movie+'"/>');
	document.write('<embed src="'+movie+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="'+wmode+'" width="'+w+'" height="'+h+'"></embed>');
	document.write('</object>');
	document.write('</div>');
}

function ajaxInit() {
	var req;
	
	try {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	} catch(e) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(ex) {
			try {
				req = new XMLHttpRequest();
			} catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				req = null;
			}
		}
	}
	return req;
};

function LoadAjax(metodo, url, send, destino) {
	var ajax = ajaxInit();	
	if(ajax) {  
		if(metodo == "post") {  
				ajax.open("POST", url, true);  
				ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
		} else {  
				ajax.open("GET", url + "?" + send, false);  
		}  
				
		ajax.onreadystatechange = function() { 
																if (ajax.readyState == 1) {
																	//document.getElementById(destino).innerHTML = 'Carregando...';
																}
																if (ajax.readyState == 4) {
																	if (ajax.status == 200) {
																		document.getElementById(destino).innerHTML = unescape(ajax.responseText.replace(/\+/g," "));
																	};
																}
															}  
			
		if(metodo == "post") {  
			ajax.send(send);  
		} else {  
			ajax.send(null);  
		}  
	}  
}

function AlterarFoto(codigo, origem) {
	var codAnt = document.getElementById('imgGrande').value;

	var ajax = ajaxInit();	
	ajax.open("GET", "fotoGrande.asp?cod=" + codigo, false);  
	ajax.send(null);  
	returnAjax = unescape(ajax.responseText.replace(/\+/g," ")).split(';');
	
	div1 = document.getElementById('fotoGrandeAjax');
	div1.innerHTML='';

	img1 = document.createElement('img');
	img1.setAttribute('border', '0');
	img1.setAttribute('id', 'img1');
	img1.src = '../includes/corte-auto.asp?imagem='+returnAjax[0]+'&height=210&width=280';

	hnd1 = document.createElement('input');
	hnd1.setAttribute('name', 'imgGrande');
	hnd1.setAttribute('id', 'imgGrande');
	hnd1.setAttribute('type', 'hidden');
	hnd1.setAttribute('value', codigo);

	if (returnAjax[1] == 'true') {
		href = document.createElement('a');
		href.setAttribute('href', "javascript: NewWindow('exibir-foto.asp?cod="+codigo+"','foto','"+returnAjax[2]+"','"+returnAjax[3]+"','false');");
		
		/*lightbox*/
		
		/*href.setAttribute('href', '../includes/corte-auto2.asp?imagem=imgsite/veiculos/'+returnAjax[3]);
        
		href.setAttribute('rel', '"lightbox[roadtrip]";');*/
		
		/*fim lightbox*/
		
		href.setAttribute('style', 'padding:0; border:none;');

		img1.setAttribute('onMouseOut', "MM_displayStatusMsg(' ');return document.MM_returnValue");
		img1.setAttribute('onMouseOver', "MM_displayStatusMsg('Ampliar');return document.MM_returnValue");
		img1.setAttribute('title', "Clique aqui para ampliar");
		img1.setAttribute('alt', "Clique aqui para ampliar");
		
		href.appendChild(img1);
		div1.appendChild(href);
	} else {
		div1.appendChild(img1);
	}
	div1.appendChild(hnd1);

	var ajax = ajaxInit();	
	ajax.open("GET", "fotoPequena.asp?cod=" + codAnt + '&origem=' + origem, false);  
	ajax.send(null);  
	document.getElementById('fotoPequenaAjax'+origem).innerHTML = unescape(ajax.responseText.replace(/\+/g," ")).split(';');
}