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

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 _jsGeraSelect(tabName, fieldName, searchKey, searchValue, paramJs, paramCss, fieldValue, resultText, resultValue, idCont) {
	_jsPage("../inc/geraSelect.php?tabName="+tabName+"&fieldName="+fieldName+"&searchKey="+searchKey+"&searchValue="+searchValue+"&paramJs="+paramJs+"&paramCss="+paramCss+"&fieldValue="+fieldValue+"&resultText="+resultText+"&resultValue="+resultValue,idCont)
}

function popup(x,n,w,h,s) {
    var l = ((window.screen.width  - w) / 2);
    var t = ((window.screen.height - h) / 2);
   janelinha = window.open(x,n,'leftmargin=-15,topmargin=-15,marginheight=0,marginwidth=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+s+',resizable=no,top='+t+',left='+l+',screenX='+l+',screenY='+t+',copyhistory=no,height='+h+',width='+w+'');
}

var TimeToFade = 200.0;

function fade(eid){
  var element = document.getElementById(eid);
  if(element == null)
    return;
   
  if(element.FadeState == null){
    if(element.style.opacity == null 
        || element.style.opacity == '' 
        || element.style.opacity == '1'){
      element.FadeState = 2;
    }
    else{
      element.FadeState = -2;
    }
  }
    
  if(element.FadeState == 1 || element.FadeState == -1){
    element.FadeState = element.FadeState == 1 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  }
  else{
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    setTimeout("animateFade(" + new Date().getTime() 
        + ",'" + eid + "')", 33);
  }  
}
function animateFade(lastTick, eid){  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks){
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = ' 
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = element.FadeState == 1 ? 2 : -2;
    return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 
      'alpha(opacity = ' + (newOpVal*100) + ')';
  
  setTimeout("animateFade(" + curTick 
      + ",'" + eid + "')", 33);
}

function _jsPreviewThumb(imgSrc, divName, imgName) {
	document.getElementById(divName).style.display = '';	
	document.getElementById(imgName).src = imgSrc;	
}

/*
function readFileViaApplet(n) {
 document.f1.t1.value='Reading in progress...';
 document.ReadURL.readFile(theLocation);
 setTimeout("showFileContent()",100);
}

function showFileContent() {
 if (document.ReadURL.finished==0) {
  setTimeout("showFileContent()",100);
  return;
 }
 fileContent=document.ReadURL.fileContent;
 document.form1.textarea1.value=fileContent;
}
*/

function _jsPreviewFisico(Veiculo_Nome) {
	//alert(document.getElementById(Veiculo_Nome).value);
	if (document.getElementById(Veiculo_Nome).value) {
		document.getElementById("td"+Veiculo_Nome).style.display = '';
		document.getElementById("img"+Veiculo_Nome).src = 'file://'+document.getElementById(Veiculo_Nome).value;
	}
}

function _jsBoxResposta(css, msg){
	document.getElementById('boxMensagem').className = css;
	document.getElementById('retornoMensagem').innerHTML = msg;
	document.getElementById('boxMensagem').style.display = '';
	setTimeout('fade(\'boxMensagem\')', 2000);
}

function _jsCheckExcluir(Status) {
	var k;
	fieldName = "Check_Item[]";
	fieldId = "Check_Item";
	if(document.frmLista[fieldName].length){
		for(i=0;i<=(document.frmLista[fieldName].length-1);i++) {
			document.frmLista[fieldName][i].checked = Status;
			if(i!=0) k=i;
			else k="";
			if(Status == true) document.getElementById("listRes"+k).style.backgroundColor = "#D7D7D7";
			else  document.getElementById("listRes"+k).style.backgroundColor = "";
		}
	}
	else{
		document.getElementById(fieldId).checked = Status;
		if(Status == true) document.getElementById("listRes").style.backgroundColor = "#D7D7D7";
		else  document.getElementById("listRes").style.backgroundColor = "";
	}
}

function _jsSubmitLista(){
	var check = false;
	fieldName = "Check_Item[]";
	fieldId = "Check_Item";
	if(confirm('Deseja realmente excluir todos os itens cadastrados?')){
		if(document.frmLista[fieldName].length){
			for(i=0;i<=(document.frmLista[fieldName].length-1);i++) {
				if(document.frmLista[fieldName][i].checked == true){
					check = true;
				}
			}
		}
		else{
			if(document.getElementById(fieldId).checked == true){
				check = true;	
			}
		}
		if(check) document.frmLista.submit();
		else alert('Pelo menos 1 item deve ser selecionado.');
	}
}

function _jsChecaBox(id){
	if(document.getElementById("Check_Item"+id).checked == true){
		document.getElementById("Check_Item"+id).checked = false;	
		document.getElementById("listRes"+id).style.backgroundColor = "";
	}
	else{		
		document.getElementById("Check_Item"+id).checked = true;	
		document.getElementById("listRes"+id).style.backgroundColor = "#D7D7D7";
	}
}

function _jsClickBox(id){
	if(document.getElementById("Check_Item"+id).checked == true){		
		document.getElementById("listRes"+id).style.backgroundColor = "#D7D7D7";
	}
	else{
		document.getElementById("listRes"+id).style.backgroundColor = "";
	}
}



function _jsAdmCheckExcluir(Status) {
	fieldName = "Check_Item[]";
	fieldId = "Check_Item";
	if(document.frmLista[fieldName].length){
		for(i=0;i<=(document.frmLista[fieldName].length-1);i++) {
			document.frmLista[fieldName][i].checked = Status;
		}
	}
	else{
		document.getElementById(fieldId).checked = Status;
	}
}

function _jsAdmSubmitLista(){
	var check = false;
	fieldName = "Check_Item[]";
	fieldId = "Check_Item";
	if(document.frmLista[fieldName].length){
		for(i=0;i<=(document.frmLista[fieldName].length-1);i++) {
			if(document.frmLista[fieldName][i].checked == true){
				check = true;
			}
		}
	}
	else{
		if(document.getElementById(fieldId).checked == true){
			check = true;	
		}
	}

	if(check) document.frmLista.submit();
	else alert('Pelo menos 1 item deve ser selecionado.');
}



function abrefecha(divAbre,divFecha){
	document.getElementById(divAbre).style.display=''; 
	document.getElementById(divFecha).style.display='none';
}

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;
	}
}

function FormataValor(id,tammax,teclapres) {
   
    if(window.event) 
	{ // Internet Explorer
	 var tecla = teclapres.keyCode; 
	}
	else if(teclapres.which) 
	{ // Nestcape / firefox
	 var tecla = teclapres.which;
    }
	vr = document.getElementById(id).value;
	vr = vr.toString().replace( "/", "" );
	vr = vr.toString().replace( "/", "" );
	vr = vr.toString().replace( ",", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	tam = vr.length;
	
	if (tam < tammax && tecla != 8){ tam = vr.length + 1; }
		if (tecla == 8 ){ tam = tam - 1; }
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
		document.getElementById(id).value = vr; }
		if ( (tam > 2) && (tam <= 5) ){
		document.getElementById(id).value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
		if ( (tam >= 6) && (tam <= 8) ){
		document.getElementById(id).value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
		if ( (tam >= 9) && (tam <= 11) ){
		document.getElementById(id).value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
		if ( (tam >= 12) && (tam <= 14) ){
		document.getElementById(id).value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
		if ( (tam >= 15) && (tam <= 17) ){
		document.getElementById(id).value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );}
	}
}

function _jsPopup(Caminho){
	popup("http://"+Caminho,'','700','500','yes')
}

/* ========= EDITOR TABAJARA =========== */
function bbCodeB(textarea) {
	if(document.selection && document.selection.createRange().text != ""){
		document.selection.createRange().text = "[b]" + document.selection.createRange().text + "[/b]";
	}
	else if(typeof(textarea.selectionStart) != "undefined") {
		var antes, selecionado, depois;
		
		antes = textarea.value.substring(0, textarea.selectionStart);
		selecionado = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
		depois = textarea.value.substring(textarea.selectionEnd);
		
		textarea.value = antes + "[b]" + selecionado + "[/b]" + depois;
	}
	if(document.selection.createRange().text == "" || (!document.selection && textarea.selectionStart == "undefined")) {
		//textarea.value = textarea.value + "[b][/b]";
		return false;
	}
}

function bbCodeA(textarea) {
	var link = prompt("Coloque sua url:","http://");
	if(link != null){
		if(document.selection && document.selection.createRange().text != ""){
			document.selection.createRange().text = "[url=\""+ link +"\"]"+ document.selection.createRange().text + "[/url]";
		}
		else if(typeof(textarea.selectionStart) != "undefined") {
			var antes, selecionado, depois;
			
			antes = textarea.value.substring(0, textarea.selectionStart);
			selecionado = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
			depois = textarea.value.substring(textarea.selectionEnd);
			
			textarea.value = antes + "[url=\""+ link +"\"]"+ selecionado + "[/url]" + depois;
		}
		if(document.selection.createRange().text == "" || (!document.selection && textarea.selectionStart == "undefined")) {
			return false;
		}
	}
}
/* ===================================== */
function _jsClosePopup(){
	document.getElementById('BannerPopup').style.display = 'none';	
	document.getElementById('popBody').style.overflow = 'auto';	
	document.getElementById('popBody').scroll = 'yes';
}

function _jsLimiteVeiculos(Revenda_Id) {
	_jsPage("acoes.php?Acao=4&Revenda_Id="+Revenda_Id,"divMensagem");
}

function _jsPreco() {
	if (xmlHttp.readyState == 4 || !xmlHttp.readyState) {
		Tipo_Id = document.getElementById("Tipo_Id").value;
		Marca_Id = document.getElementById("Marca_Id").value;
		Modelo_Id = document.getElementById("Modelo_Id").value;
		Veiculo_AnoFabricacao = document.getElementById("Veiculo_AnoFabricacao").value;
		Veiculo_AnoModelo  = document.getElementById("Veiculo_AnoModelo").value;
		if (Tipo_Id && Marca_Id && Modelo_Id) _jsPage('../inc/dicaPreco.php?Tipo_Id='+Tipo_Id+'&Marca_Id='+Marca_Id+'&Modelo_Id='+Modelo_Id+'&Veiculo_AnoFabricacao='+Veiculo_AnoFabricacao+'&Veiculo_AnoModelo='+Veiculo_AnoModelo,'lblPreco');
	} else {
		setTimeout('_jsPreco()',100);
	}
}

function _jsDetalheVeic(caminho) {
	popup(caminho,'','780','580','no');
}


/* ============ index =============== */
function _jsChangeCidade(Cidade_Id){ _jsPage("/php/acoes.php?Acao=1&Cidade_Id="+Cidade_Id, "contRevendas");	}
function _jsRevenda(Revenda_Id) { location.href = "/resultadoBusca/?rev="+Revenda_Id; }
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=\"\">-</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.Tipo_Id.value == ""){
		alert("Você deve selecionar um tipo de veiculo");
		document.frmBusca.Tipo_Id.focus();
		return false;
	}
}

/* ======= busca avançada ======= */
function _jsChangeTipo02(Tipo_Id) {
	document.getElementById("buscaModelo").innerHTML = "<select disabled=\"disabled\" class=\"tipo\" name=\"mod\"><option value=\"\">-</option></select>";
	_jsPage("/php/acoes.php?Acao=36&Tipo_Id="+Tipo_Id,"tdMarca");
	_jsDetalhes02(Tipo_Id);
}

function _jsChangeMarca02(Marca_Id) {
	_jsPage("/php/acoes.php?Acao=37&Marca_Id="+Marca_Id,"tdModelo");
}
/* ============================== */

/* =========== resultadoBusca ============= */
function _jsMostraMais(id){
	if(document.getElementById(id).style.display == 'none'){
		document.getElementById(id).style.display = '';
	}
	else {
		document.getElementById(id).style.display = 'none';
	}
}
	
function _jsFav(Veiculo_Id) {
	_jsPage("/php/acoes.php?Acao=5&Veiculo_Id="+Veiculo_Id,"spanFav"+Veiculo_Id);
}

function _jsDesFav(Veiculo_Id) {
	_jsPage("/php/acoes.php?Acao=6&Veiculo_Id="+Veiculo_Id,"spanFav"+Veiculo_Id);
}

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

function _jsZoomIn(img){
	document.getElementById("imgZoom").src = img;
	document.getElementById("zoom").style.display = 'block';
}

function _jsZoomOut(){
	document.getElementById("zoom").style.display = 'none';
	document.getElementById("imgZoom").src = '';
}
	
function _jsFav01(Veiculo_Id) {
	_jsPage("/php/acoes.php?Acao=8&Veiculo_Id="+Veiculo_Id,"liFav");
}

function _jsDesFav01(Veiculo_Id) {
	_jsPage("/php/acoes.php?Acao=9&Veiculo_Id="+Veiculo_Id,"liFav");
}

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;
	}
	if (document.frmProposta.Proposta_Captcha.value == '') {
		alert('Você digitar o código verificador');
		document.frmProposta.Proposta_Captcha.focus();
		return false;
	}
} 

function _jsSubmitEsqueciSenha() {
	if (document.frmEsqueciSenha.Revenda_Email.value == '' || document.frmEsqueciSenha.Revenda_Email.value.indexOf("@") == -1 || document.frmEsqueciSenha.Revenda_Email.value.indexOf(".") == -1) {
		alert('Seu e-mail precisa ser preenchido');
		document.frmEsqueciSenha.Revenda_Email.focus();
		return false;
	}
} 





//===================================


function _jsAjaxAcessorios(tipo){
	if(document.getElementById("ajaxAcessorios").value != tipo){
		document.getElementById("ajaxAcessorios").value = tipo;
		if(tipo==1){
			document.getElementById("ajaxAcessorios1").style.backgroundPosition = "0px -799px";	
			document.getElementById("ajaxAcessorios2").style.backgroundPosition = "-105px -799px";	
		}
		else{
			document.getElementById("ajaxAcessorios1").style.backgroundPosition = "0px -826px";	
			document.getElementById("ajaxAcessorios2").style.backgroundPosition = "-105px -826px";	
		}
		_jsPage("/php/acoes.php?Acao=10&Tipo_Id="+tipo,"ulCont");
	}
}

function _jsAjaxVeiculos(tipo){
	if(document.getElementById("ajaxVeiculos").value != tipo){
		document.getElementById("ajaxVeiculos").value = tipo;
		if(tipo==1){
			document.getElementById("ajaxVeiculos1").style.backgroundPosition = "0px -799px";	
			document.getElementById("ajaxVeiculos2").style.backgroundPosition = "-105px -799px";	
		}
		else{
			document.getElementById("ajaxVeiculos1").style.backgroundPosition = "0px -826px";	
			document.getElementById("ajaxVeiculos2").style.backgroundPosition = "-105px -826px";	
		}
		_jsPage("/php/acoes.php?Acao=11&Tipo_Id="+tipo,"listaDestaques");
	}
}


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

function _jsRevLocalizacao(){
	if (document.getElementById("tabestoque").style.display == 'none') {
		document.getElementById("tabestoque").style.display = '';
		document.getElementById("tabmapa").style.display = 'none';
	}
	else{
		document.getElementById("tabestoque").style.display = 'none';
		document.getElementById("tabmapa").style.display = '';
	}
}

function _jsPropResposta(Proposta_Id){
	if(document.getElementById('Proposta_Responder['+Proposta_Id+']').style.display == 'none'){
		document.getElementById('Proposta_Responder['+Proposta_Id+']').style.display = '';
	}
	else{
		document.getElementById('Proposta_Responder['+Proposta_Id+']').style.display = 'none';
		document.getElementById('Proposta_Resposta['+Proposta_Id+']').value = '';
	}
}
function _jsSubmitResposta(Proposta_Id){
	if (document.getElementById('Proposta_Resposta['+Proposta_Id+']').value == '') {
		alert('Você deve preencher o campo de Resposta');	
	}
	else{
		document.getElementById('enviaProposta_Id').value = Proposta_Id;
		document.getElementById('enviaProposta_Resposta').value = document.getElementById('Proposta_Resposta['+Proposta_Id+']').value;
		//alert(document.getElementById('enviaProposta_Resposta').value);
		document.enviaResposta.submit();
	}
}

function _jsVizualizaProposta(Proposta_Id){
	tmp = document.getElementById('Proposta_MensagemTmp');
	msg = document.getElementById('Proposta_Mensagem['+Proposta_Id+']');
    if((tmp.value != '') && (tmp.value != Proposta_Id)){
		document.getElementById('Proposta_Mensagem['+tmp.value+']').innerHTML = "";
	}
	if(msg.innerHTML == ""){
		tmp.value = Proposta_Id;
		document.getElementById("env"+Proposta_Id).innerHTML = "<img title=\"Proposta lida\" alt=\"Proposta lida\" src=\"/img/iconEmailOpen.gif\"/>";
		_jsPage("/php/acoes.php?Acao=14&Proposta_Id="+Proposta_Id, "Proposta_Mensagem["+Proposta_Id+"]");
	}
	else{
		msg.innerHTML = "";
		tmp.value = "";
	}
}


function _jsAlteraRevenda() {
	/*if (navigator.appName == "Netscape") {*/
		document.frmAdmRevenda.Cidade_Id.value = document.getElementById("Cidade_Id02").value;
	/*}*/
	
	if (document.frmAdmRevenda.Revenda_Endereco.value == '') {
		alert('O endereço da revenda precisa ser preenchido');
		document.frmAdmRevenda.Revenda_Endereco.focus();
		return false;
	}

	if (document.frmAdmRevenda.Revenda_Numero.value == '') {
		alert('O numero da revenda precisa ser preenchido');
		document.frmAdmRevenda.Revenda_Numero.focus();
		return false;
	}

	if (document.frmAdmRevenda.Revenda_Bairro.value == '') {
		alert('O bairro da revenda precisa ser preenchido');
		document.frmAdmRevenda.Revenda_Bairro.focus();
		return false;
	}

	if (document.frmAdmRevenda.Revenda_CEP.value == '') {
		alert('O CEP da revenda precisa ser preenchido');
		document.frmAdmRevenda.Revenda_CEP.focus();
		return false;
	}

	if (document.frmAdmRevenda.Estado_Id.value == '') {
		alert('O estado da revenda precisa ser preenchido');
		document.frmAdmRevenda.Estado_Id.focus();
		return false;
	}
	
	if (document.frmAdmRevenda.Cidade_Id.value == '') {
		alert('A cidade da revenda precisa ser preenchida');
		//document.frmAdmRevenda.Cidade_Id.focus();
		return false;
	}
	
	if (document.frmAdmRevenda.Revenda_Telefone.value == '') {
		alert('O telefone da revenda precisa ser preenchido');
		document.frmAdmRevenda.Revenda_Telefone.focus();
		return false;
	}
}

function _jsAlteraEmpresa() {
	/*if (navigator.appName == "Netscape") {*/
		document.frmAdmEmpresa.Cidade_Id.value = document.getElementById("Cidade_Id02").value;
	/*}*/
	
	if (document.frmAdmEmpresa.Empresa_Endereco.value == '') {
		alert('O endereço da empresa precisa ser preenchido');
		document.frmAdmEmpresa.Empresa_Endereco.focus();
		return false;
	}

	if (document.frmAdmEmpresa.Estado_Id.value == '') {
		alert('O estado da empresa precisa ser preenchido');
		document.frmAdmEmpresa.Estado_Id.focus();
		return false;
	}
	
	if (document.frmAdmEmpresa.Cidade_Id.value == '') {
		alert('A cidade da empresa precisa ser preenchida');
		//document.frmAdmRevenda.Cidade_Id.focus();
		return false;
	}
	
	if (document.frmAdmEmpresa.Empresa_Telefone.value == '') {
		alert('O telefone da empresa precisa ser preenchido');
		document.frmAdmEmpresa.Empresa_Telefone.focus();
		return false;
	}
}

function _jsSubmitBuscaVeiculos() {
	if (navigator.appName == "Netscape") {
		document.frmBuscaVeiculos.admmar.value = document.getElementById("admmar").value;
		document.frmBuscaVeiculos.admmod.value = document.getElementById("admmod").value;
	}
}

function _jsVeiculoFinanciado(valor){
	var item = valor
	if (item.checked == true){ 
		document.getElementById('tabFinan').style.display = ''; 
	} 
	else { 
		document.getElementById('tabFinan').style.display = 'none'; 
	}
	document.getElementById('Veiculo_FEntrada').value = ''; 
	document.getElementById('Veiculo_FParcela').value = ''; 
	document.getElementById('Veiculo_FVlrParcela').value = '';  
}

function updateVeiculoDetalhe(sel, txtarea) {
	for (var i=0; i<sel.options.length; i++) {
		if (sel.options[i].selected){
			txtarea.value += sel.options[i].value + "\n";
		}
	}	
}

function _jsAbaPendentes(id){
	document.getElementById('veiPartPend').style.display = 'none';
	document.getElementById('veiPartProx').style.display = 'none';
	document.getElementById('acePartPend').style.display = 'none';
	document.getElementById('acePartProx').style.display = 'none';	
	document.getElementById(id).style.display = '';
}

 
function _jsValidaCPF(CPF){ 
	if((CPF == '00000000000') || (CPF == '11111111111') || (CPF == '22222222222') || (CPF == '33333333333') || (CPF == '44444444444') || 
	   (CPF == '55555555555') || (CPF == '66666666666') || (CPF == '77777777777') || (CPF == '88888888888') || (CPF == '99999999999')){
		return false;
	}
 	var i; 
	s = CPF  
	var c = s.substr(0,9); 
	var dv = s.substr(9,2); 
	var d1 = 0; 
	for (i = 0; i < 9; i++) { 
		d1 += c.charAt(i)*(10-i); 
	} 
	 
	if (d1 == 0) { 
		return false; 
	} 
	  
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(0) != d1) { 
 		return false;   
	} 
	  
	d1 *= 2; 	  
	for (i = 0; i < 9; i++)  {   
		d1 += c.charAt(i)*(11-i); 
	} 
	  
	d1 = 11 - (d1 % 11); 

	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1) { 
		return false; 
	} 
	  
	return true; 
}


function _jsSubmitCadastro(){
	if (document.frmCadastro.Usuario_Email.value == '' || document.frmCadastro.Usuario_Email.value.indexOf("@") == -1 || document.frmCadastro.Usuario_Email.value.indexOf(".") == -1) {
		alert('Você deve preencher o e-mail corretamente.');
		document.frmCadastro.Usuario_Email.focus();
		return false;
	}
	if (!_jsValidaCPF(document.frmCadastro.Usuario_CPF.value)) {
		alert('Você deve digitar o seu CPF corretamente, sem pontos, virgulas ou traços.\nEx: 12345678900');
		document.frmCadastro.Usuario_CPF.focus();
		return false;
	}
}

function _jsAnuncieCadastro(){
	//if (navigator.appName == "Netscape") {
	document.frmAnuncieCadastro.Cidade_Id.value = document.getElementById("Cidade_Id01").value;
	//}

	if(document.frmAnuncieCadastro.Usuario_Nome.value == ''){
		alert('Você deve preencher o campo Nome.');
		document.frmAnuncieCadastro.Usuario_Nome.focus();
		return false;
	}
	if((document.frmAnuncieCadastro.Usuario_Senha.value == '') || (document.frmAnuncieCadastro.Usuario_Senha.value.length < 6)){
		alert('Sua senha deve conter no mínimo 6 caracteres.');
		document.frmAnuncieCadastro.Usuario_Senha.focus();
		return false;
	}
	if(document.frmAnuncieCadastro.Usuario_DDD.value == ''){
		alert('Você deve preencher o campo DDD.');
		document.frmAnuncieCadastro.Usuario_DDD.focus();
		return false;
	}
	if(document.frmAnuncieCadastro.Usuario_Telefone.value == ''){
		alert('Você deve preencher o campo Telefone.');
		document.frmAnuncieCadastro.Usuario_Telefone.focus();
		return false;
	}
	if(document.frmAnuncieCadastro.Estado_Id.value == ''){
		alert('Você deve preencher o campo Estado.');
		document.frmAnuncieCadastro.Estado_Id.focus();
		return false;
	}
	if(document.frmAnuncieCadastro.Cidade_Id.value == ''){
		alert('Você deve preencher o campo Cidade.');
		//document.frmAnuncieCadastro.Cidade_Id.focus();
		return false;
	}
	if(document.frmAnuncieCadastro.Usuario_CEP.value == ''){
		alert('Você deve preencher o campo CEP.');
		document.frmAnuncieCadastro.Usuario_CEP.focus();
		return false;
	}
	if(document.frmAnuncieCadastro.Usuario_Endereco.value == ''){
		alert('Você deve preencher o campo Endereço.');
		document.frmAnuncieCadastro.Usuario_Endereco.focus();
		return false;
	}
	if(document.frmAnuncieCadastro.Usuario_Numero.value == ''){
		alert('Você deve preencher o campo Número.');
		document.frmAnuncieCadastro.Usuario_Numero.focus();
		return false;
	}
	if(document.frmAnuncieCadastro.Usuario_Bairro.value == ''){
		alert('Você deve preencher o campo Bairro.');
		document.frmAnuncieCadastro.Usuario_Bairro.focus();
		return false;
	}
}

function _jsDetalhes02(Tipo_Id) {
	if (!Tipo_Id) Tipo_Id = "";
	if (xmlHttp.readyState == 4) _jsPage('/php/acoes.php?Acao=38&Tipo_Id='+Tipo_Id,'tdDetalhes');
	else setTimeout('_jsDetalhes02('+Tipo_Id+')',100);
}

function _jsVeiculoVideo(vlr){
	if(vlr){
		document.getElementById('contImg').style.display = 'none';	
		document.getElementById('contVid').style.display = '';	
	}
	else{
		document.getElementById('contVid').style.display = 'none';	
		document.getElementById('contImg').style.display = '';			
	}
}

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

function _jsAbreBannerTopo(){
	if(document.getElementById("banImgTopo").height == '460'){
		document.getElementById("banDivTopo").style.height = '90px';
		document.getElementById("banImgTopo").height = '90';
	}
	else{
		document.getElementById("banDivTopo").style.height = '460px';
		document.getElementById("banImgTopo").height = '460';
	}
}

function addFav(){
    var url      = "http://www.compreauto.com.br";
    var title    = "Comprar carros usados é no Compreauto (carros usados)";
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all){window.external.AddFavorite(url, title);}
}
  
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2419963-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();