var xmlHttp = new Object();
var idCont;
var tmpidMenu;
var page;

function _jsPage() {
	if (_jsPage.arguments.length == 1) idCont = "tdCont";
	else idCont = _jsPage.arguments[1];
	page = _jsPage.arguments[0];

	if (window.XMLHttpRequest) xmlHttp=new XMLHttpRequest()
	else if (window.ActiveXObject) xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
	xmlHttp.onreadystatechange = _jsDone
	xmlHttp.open("GET", page, true)
	xmlHttp.send(null)
}

function _jsDone() { 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById(idCont).innerHTML = xmlHttp.responseText;
	}
	else {
		document.getElementById(idCont).innerHTML = "<img src=\"/img/imgCarregando.gif\">";
	}
}

function _jsValContato() {
	if (document.frm1.Contato_Nome.value == '') {
		alert('Voce deve preencher o seu nome completo');	
		document.frm1.Contato_Nome.focus();
		return false;
	}	
	if (document.frm1.Contato_Telefone.value == '') {
		alert('Voce deve preencher o número do seu telefone');	
		document.frm1.Contato_Telefone.focus();
		return false;
	}
	if (document.frm1.Contato_Email.value == '' || document.frm1.Contato_Email.value.indexOf("@") == -1 || document.frm1.Contato_Email.value.indexOf(".") == -1) {
		alert('Voce deve preencher o seu e-mail corretamente');	
		document.frm1.Contato_Email.focus();
		return false;
	}
	if (document.frm1.Contato_Cidade.value == '') {
		alert('Voce deve preencher o nome de sua cidade');	
		document.frm1.Contato_Cidade.focus();
		return false;
	}
	if (document.frm1.Contato_Mensagem.value == '') {
		alert('Voce deve preencher a Mensagem');	
		document.frm1.Contato_Mensagem.focus();
		return false;
	}
}

/* ============ index =============== */
function _jsChangeCidade(Cidade_Id){ _jsPage("/php/acoes.php?Acao=1&Cidade_Id="+Cidade_Id, "contRevendas");	}
function _jsChangeCidade02(Estado_Id){ _jsPage("/php/acoes.php?Acao=2&Estado_Id="+Estado_Id, "contCidade");	}
function _jsParticular(Cidade_Id){ location.href = "/resultadoBusca/?anu=2&cid="+Cidade_Id; }
function _jsChangeTipo(Tipo_Id, Marca_Id) {
	document.getElementById("buscaModelo").innerHTML = "<select disabled=\"disabled\" class=\"tipo\" name=\"mod\"><option value=\"\">Selecione o Modelo</option></select>";
	_jsPage("/php/acoes.php?Acao=3&Tipo_Id="+Tipo_Id+"&Marca_Id="+Marca_Id,"buscaMarca");
}

function _jsChangeMarca(Marca_Id, Modelo_Id) {
	_jsPage("/php/acoes.php?Acao=4&Marca_Id="+Marca_Id+"&Modelo_Id="+Modelo_Id,"buscaModelo");
}

function _jsBuscaPrincipal(){
	if(document.frmBusca.tip.value == ""){
		alert("Você deve selecionar um tipo de veiculo");
		document.frmBusca.tip.focus();
		return false;
	}
}

function _jsIndicar() {
	if (document.getElementById("tabindicar").style.display == 'none') {
		document.getElementById("tabindicar").style.display = '';
		document.getElementById("tabdetalhes").style.display = 'none';
		document.getElementById("tabpropostas").style.display = 'none';
	} else {
		document.getElementById("tabindicar").style.display = 'none';
		document.getElementById("tabdetalhes").style.display = '';
	}
}

function _jsPropostas() {
	if (document.getElementById("tabpropostas").style.display == 'none') {
		document.getElementById("tabpropostas").style.display = '';
		document.getElementById("tabdetalhes").style.display = 'none';
		document.getElementById("tabindicar").style.display = 'none';
	} else {
		document.getElementById("tabpropostas").style.display = 'none';
		document.getElementById("tabdetalhes").style.display = '';
	}
}


function _jsSubmitIndique() {
	if (document.frmIndique.Indique_Nome.value == '') {
		alert('Seu nome precisa ser preenchido');
		document.frmIndique.Indique_Nome.focus();
		return false;
	}
	if (document.frmIndique.Indique_Email.value == '' || document.frmIndique.Indique_Email.value.indexOf("@") == -1 || document.frmIndique.Indique_Email.value.indexOf(".") == -1) {
		alert('Seu e-mail precisa ser preenchido');
		document.frmIndique.Indique_Email.focus();
		return false;
	}
	if (document.frmIndique.Indique_AmigoNome.value == '') {
		alert('O nome do seu amigo precisa ser preenchido');
		document.frmIndique.Indique_AmigoNome.focus();
		return false;
	}
	if (document.frmIndique.Indique_AmigoEmail.value == '' || document.frmIndique.Indique_AmigoEmail.value.indexOf("@") == -1 || document.frmIndique.Indique_AmigoEmail.value.indexOf(".") == -1) {
		alert('O e-mail do seu amigo precisa ser preenchido');
		document.frmIndique.Indique_AmigoEmail.focus();
		return false;
	}
	if (document.frmIndique.Indique_Mensagem.value == '') {
		alert('Você deve digitar uma mensagem');
		document.frmIndique.Indique_Mensagem.focus();
		return false;
	}
}

function _jsSubmitProposta() {
	if (document.frmProposta.Proposta_Nome.value == '') {
		alert('Seu nome precisa ser preenchido');
		document.frmProposta.Proposta_Nome.focus();
		return false;
	}
	if (document.frmProposta.Proposta_Email.value == '' || document.frmProposta.Proposta_Email.value.indexOf("@") == -1 || document.frmProposta.Proposta_Email.value.indexOf(".") == -1) {
		alert('Seu e-mail precisa ser preenchido');
		document.frmProposta.Proposta_Email.focus();
		return false;
	}
	if (document.frmProposta.Proposta_Mensagem.value == '') {
		alert('Você deve digitar uma mensagem');
		document.frmProposta.Proposta_Mensagem.focus();
		return false;
	}
} 

function _jsBuscaImagem(img){
	_jsPage("/php/acoes.php?Acao=7&img="+img, "imgP");	
}

function _jsFechaBanner(){
	document.getElementById('bannerCortina').style.display = 'none';	
}

