// JavaScript Document
// 5I6P3ZV1Itw

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];}
}
function kits_qt_rec(num, obj)
{
	if (obj.checked)document.getElementById('quant['+num+']').value=document.getElementById('rec['+num+']').value;	
	else document.getElementById('quant['+num+']').value=0;
}
function pesquisar()
{
	var km= document.getElementById('km').options[document.getElementById('km').selectedIndex].value;
	var modelo= document.getElementById('modelo').options[document.getElementById('modelo').selectedIndex].value;
	var motor= document.getElementById('motor').options[document.getElementById('motor').selectedIndex].value;
	var combustivel= document.getElementById('combustivel').options[document.getElementById('combustivel').selectedIndex].value;
	var ar= document.getElementById('ar').options[document.getElementById('ar').selectedIndex].value;
	var direcao= document.getElementById('direcao').options[document.getElementById('direcao').selectedIndex].value;
	
	location.href='index.php?op=kits&km='+km+'&modelo='+modelo+'&motor='+motor+'&combustivel='+combustivel+'&ar='+ar+'&direcao='+direcao;
}
function alerta()
{
	showPopWin('confirmacao.php', 194, 75, null);
}
function esq(num)
{
	var left = document.getElementById("cat"+num).offsetParent.offsetLeft;
	return left;
}
function cima(num)
{
	var top= document.getElementById("cat"+num).offsetParent.offsetTop;
	return top;
}
function mostrar(num, vis) 
{
	var esqe= esq(num);
	var cim= cima(num)+184;
	var div = document.getElementById("subcat"+num);
	if (vis == "ver")
	{
		div.style.top=  cim+"px";
		if ((num==8) || (num==9) || (num==12))
		{
			esqe= parseFloat(esqe) - ((parseFloat(div.offsetWidth)/2) -50);
		}
		if (num == 15)
		{
			esqe= parseFloat(esqe) - (parseFloat(div.offsetWidth)/2);
		}
		if (num == 13)
		{
			esqe= parseFloat(esqe) -(parseFloat(document.getElementById("cat"+num).offsetWidth)+7);
		}
		if ((num==9) || (num==10) || (num==15) || (num==12))
		{
			document.getElementById('flash').style.visibility="hidden";
		}
		div.style.left= esqe-1+"px";
		div.style.visibility="visible";
		//alert(div.offsetHeight);
		if(document.getElementById("pagina"))
		document.getElementById("pagina").style.visibility="hidden";
	}
	else 
	{
		div.style.top= "0px";
		div.style.left= "0px";
		div.style.visibility="hidden";
		if ((num==9) || (num==10) || (num==15) || (num==12))
		{
			document.getElementById('flash').style.visibility="visible";
		}
		if(document.getElementById("pagina"))
		document.getElementById("pagina").style.visibility="visible";
	}
}
function conta(vis) 
{
	var left = document.getElementById("sua_conta");
	left= parseFloat(left.offsetParent.offsetLeft)+(parseFloat(left.offsetWidth)/2);
	var div = document.getElementById("suaconta");
	div.style.top=  145+"px";
	div.style.left= left+"px";
	if (vis == "ver")
	{
		div.style.visibility="visible";
	}
	else 
	{
		div.style.visibility="hidden";
	}
}
var Cep = {
	get:function(cep){
		var ajax = null;
		var ie = false;
		var indice;
		if (window.XMLHttpRequest){ 
			ajax = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			ajax = new ActiveXObject("Microsoft.XMLHTTP");
			ie = true;
		}
		ajax.onreadystatechange = function() {
			switch(ajax.readyState){
			case 4:
				if (ajax.responseXML.firstChild.childNodes[1].childNodes.length == 12) {
					document.getElementById('bt_env').disabled='';
					document.getElementById('endereco').value = ajax.responseXML.firstChild.childNodes[1].childNodes[4].firstChild.data + ' '+ajax.responseXML.firstChild.childNodes[1].childNodes[5].firstChild.data;
					document.getElementById('bairro').value = ajax.responseXML.firstChild.childNodes[1].childNodes[3].firstChild.data;
					document.getElementById('cidade').value = ajax.responseXML.firstChild.childNodes[1].childNodes[2].firstChild.data;
					var est = document.getElementById('uf');
					var res=ajax.responseXML.firstChild.childNodes[1].childNodes[1].firstChild.data;
					for(var p=0; p < est.options.length; p++)
					if (est.options[p].value==res)
					{
						est.selectedIndex= p;
						break;
					}
				} else
				{
					alert('Endereço não encontrado! \n Por favor informe um CEP válido!');
					document.getElementById('cep').focus();
					//document.getElementById('bt_env').disabled='disabled';
				}
				delete ajax;
				break;
			}
		};
		if (cep != null && cep.length != 0) {
			ajax.open('GET', 'cep.php?cep='+cep, true);                  
			ajax.send(null);
		}
	}
}
function erro()
{
	alert('Este e-mail já consta em nosso cadastro!');
	document.forms['cadcli'].email.focus();
}
function vall()
{
	var bt= document.getElementById('bt_env').disabled;
	if (bt != '')
	{
		alert('Por favor informe um CEP válido!');
		return false;
	}
	if (bt == 'disabled')
	{
		//alert();
		form_validate(document.forms['cadcli']);
		return true;
	}
}
function formata(formato, keypress, objeto, event)
{
	campo = eval(objeto);
	if (formato=='CEP')
	{
		caracteres = '01234567890';
		separacoes = 1;
		separacao1 = '-';
		conjuntos = 2;
		conjunto1 = 5;
		conjunto2 = 3;
		if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
		(conjunto1 + conjunto2 + 1))
			{
			if (campo.value.length == conjunto1) 
			   campo.value = campo.value + separacao1;
			}
		else 
			event.returnValue = false;
	}
	if (formato=='insc_est')
	{
		caracteres = '01234567890';
		separacoes = 1;
		separacao1 = '/';
		conjuntos = 2;
		conjunto1 = 3;
		conjunto2 = 7;
		if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
		(conjunto1 + conjunto2 + 1))
			{
			if (campo.value.length == conjunto1) 
			   campo.value = campo.value + separacao1;
			}
		else 
			event.returnValue = false;
	}
}
function formataNumeric(formato, keypress, objeto)
{
	campo = eval(objeto);
	if (formato=='Numeric')
		{
		caracteres = '01234567890';
		separacoes = 1;
		separacao1 = '';
		conjuntos = 2;
		conjunto1 = 5;
		conjunto2 = 4;
		if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
		(conjunto1 + conjunto2 + 1))
			{
			if (campo.value.length == conjunto1) 
			   campo.value = campo.value + separacao1;
			}
		else 
			event.returnValue = false;
		}
}
function dis()
{
	document.getElementById('fec').href="#";
	document.getElementById('Atualizar').focus();
}
function vall_cesta(num, defaulte)
{
	var obj = document.getElementById('quant['+num+']').value;
	var ver_numero = "01234567890";
	var retorno='';
	for (i = 0;  i < obj.length;  ++i)
	{
		ch = obj.charAt(i);
		if (ver_numero.indexOf(ch) != (-1))
		{
			retorno = retorno + ch;
		}
	}
	if ((retorno.length == 0) ||(retorno ==0))
	{
		// retorno=defaulte;
	}
	document.getElementById('quant['+num+']').value=retorno;
}
function Forma_entrega()
{
	var ent= document.getElementById('result').value;
	var divi=  document.getElementById('otto').style.visibility;
	if (divi == 'hidden')
	{
		location.href="index.php?op=fecpedido&entrega="+ent;
	}
	else
	{
		location.href="index.php?op=fecpedido&entrega="+ent+"&outro="+document.getElementById('qual').value;
	}
}
function ativar(arg)
{
	var divi=  document.getElementById('otto');
	if (arg == 0)
	{
		divi.style.visibility='hidden';
	}
	else
	{
		divi.style.visibility='visible';
	}
}
function enviar()
{
	var pesq=document.getElementById('pesquisa_lat').value;
	var onde= document.getElementById('onde_pesq_sel').value;
	if (document.getElementById('ft').checked)
	{
		pesq+="&foto=1";
	}
	window.location.href='index.php?op=home&pesquisa='+pesq+'&onde='+onde;
}
function enquete(jan)
{
	resultado=window.open('',jan,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=no,width=160,height=110");
	document.enqueteform.submit();
	window.history.go(0);
}
