// JavaScript Document
//************************************************************************
// HTTP REQUEST **********************************************************
//************************************************************************
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var AjaxA = getHTTPObject();

//************************************************************************
//************************************************************************

// POP-UPS ----------------------------------------------
/* SEM SCROLLBARS */
function page_less(url, largura, altura) {
  var url;
  
  var esquerda = (screen.width - largura)/2;
  var topo = (screen.height - altura)/2;
  window.open(url,'win','height=' + altura + ', width=' + largura + ', top=' + topo + ', left=' + esquerda);
}

/* COM SCROLLBARS */
function PopUpScroll(url, largura, altura) {
  var url;
  
  var esquerda = (screen.width - largura)/2;
  var topo = (screen.height - altura)/2;
  telapopup2 = window.open(url,'win','height=' + altura + ', width=' + largura + ', top=' + topo + ', left=' + esquerda +', scrollbars=1, resizable=1'); 
  if(!telapopup2) alert('Atenção, o seu navegador está bloqueando as janelas popups, é necessário que você habilite a visualização de Popups.');
}
//*********************************************************************************

//VALIDAÇÃO DO FORMULÁRIO
// VALIDAR - INDICAR------------------------------------
function validar_indicar(){

if(document.form1.nome.value == ""){
		alert("Informe o seu nome!");
		document.form1.nome.focus();
		return false;
	};
	
	strEmail = document.form1.email.value;
	if(strEmail == ""){
		alert("Informe seu e-mail!");
		document.form1.email.focus();
		return false;
	};
	
	if(strEmail.indexOf("@",0) == -1 || strEmail.indexOf(".",0) == -1){ 
		alert("Informe um email válido !"); 
		document.form1.email.select();
		return false; 
	};
	
	if(document.form1.nome_para.value == ""){
		alert("Informe o do para quem você deseja fazer a indicação!");
		document.form1.nome_para.focus();
		return false;
	};
	
	strEmail2 = document.form1.email_para.value;
	if(strEmail2 == ""){
		var nomepara = document.form1.nome_para.value;
		alert("IInforme o e-mail de "+nomepara+"!");
		document.form1.email_para.focus();
		return false;
	};
	
	if(strEmail2.indexOf("@",0) == -1 || strEmail2.indexOf(".",0) == -1){ 
		alert("Informe um email válido !"); 
		document.form1.email_para.select();
		return false; 
	};
	
	if(document.form1.mensagem.value == ""){
		alert("Informe sua mensagem!");
		document.form1.mensagem.focus();
		return false;
	};
	
}

//PROPOSTA  - MOTOS USADAS
function validar_contato(){
	
	if(document.form1.nome.value==""){
		alert("Informe seu nome!");
		document.form1.nome.focus();
		return false; 
	}
	
	strEmail = document.form1.email.value;
	if(strEmail == ""){
		alert("Informe seu e-mail!");
		document.form1.email.focus();
		return false;
	};
	
	if(strEmail.indexOf("@",0) == -1 || strEmail.indexOf(".",0) == -1){ 
		alert("Informe um email válido !"); 
		document.form1.email.select();
		return false; 
	};
	
	if(document.form1.telefone.value==""){
		alert("Informe seu telefone para contato!");
		document.form1.telefone.focus();
		return false; 
	}
	
	if(document.form1.cidade.value==""){
		alert("Informe sua cidade!");
		document.form1.cidade.focus();
		return false; 
	}
	
	if(document.form1.assunto.value==""){
		alert("Informe o assunto do contato!");
		document.form1.assunto.focus();
		return false; 
	}	
	
	if(document.form1.mensagem.value==""){
		alert("Informe sua mesagem!");
		document.form1.mensagem.focus();
		return false; 
	}
}

//PROPOSTA  - MOTOS USADAS
function validar_proposta_usada(){
	
	if(document.form1.nome.value==""){
		alert("Informe seu nome!");
		document.form1.nome.focus();
		return false; 
	}
	
	strEmail = document.form1.email.value;
	if(strEmail == ""){
		alert("Informe seu e-mail!");
		document.form1.email.focus();
		return false;
	};
	
	if(strEmail.indexOf("@",0) == -1 || strEmail.indexOf(".",0) == -1){ 
		alert("Informe um email válido !"); 
		document.form1.email.select();
		return false; 
	};
	
	if(document.form1.telefone.value==""){
		alert("Informe seu telefone para contato!");
		document.form1.telefone.focus();
		return false; 
	}
	
	if(document.form1.cidade.value==""){
		alert("Informe sua cidade!");
		document.form1.cidade.focus();
		return false; 
	}
	
	if(document.form1.mensagem.value==""){
		alert("Informe sua mesagem!");
		document.form1.mensagem.focus();
		return false; 
	}
}

//PROPOSTA  - MOTOS NOVAS
function validar_proposta_nova(){
	
	if(document.form1.nome.value==""){
		alert("Informe seu nome!");
		document.form1.nome.focus();
		return false; 
	}
	
	strEmail = document.form1.email.value;
	if(strEmail == ""){
		alert("Informe seu e-mail!");
		document.form1.email.focus();
		return false;
	};
	
	if(strEmail.indexOf("@",0) == -1 || strEmail.indexOf(".",0) == -1){ 
		alert("Informe um email válido !"); 
		document.form1.email.select();
		return false; 
	};
	
	if(document.form1.telefone.value=="" && document.form1.celular.value==""){
		alert("Informe seu telefone ou celular para contato!");
		document.form1.telefone.focus();
		return false; 
	}
	
	if(document.form1.cidade.value==""){
		alert("Informe sua cidade!");
		document.form1.cidade.focus();
		return false; 
	}
}


//SELEÇÃO DAS MOTOS 0 KM

function ver_moto_nova(moto){
	
	if(moto!="0"){
		var moto_ex = moto.split(",");
		document.getElementById('novas_nome').innerHTML=moto_ex[0];
		document.getElementById('foto_moto_novas').src="imagens/motos/"+moto_ex[2];
	}
}

function validar_novas(){
	if(document.getElementById('lista_motos').value=="0"){
		alert("Selecione uma moto!");
		return false;
	}
}

function selecionar_cor(nome, ano, cor, foto){
	var pasta_motos = "imagens/motos/"
	document.getElementById('foto_grande').src=pasta_motos+ano+"/"+foto;
	document.getElementById('foto_grande').alt=nome+" "+ano+" - "+cor;
}

function controle_aba(n_aba,id,tipo){
	var ativado = "div_aba_hover";
	var desativado = "div_aba";
	
	document.getElementById("texto").innerHTML = '<div  align="center"><img src="imagens/loading.gif" width="32" height="32" /></div>'
	if(n_aba==1){
		document.getElementById('aba_1').className = ativado;
		document.getElementById('aba_2').className = desativado;
		document.getElementById('aba_3').className = desativado;
				
	}else if(n_aba==2){
		document.getElementById('aba_1').className = desativado;
		document.getElementById('aba_2').className = ativado;
		document.getElementById('aba_3').className = desativado;
		
	}else if(n_aba==3){
		document.getElementById('aba_1').className = desativado;
		document.getElementById('aba_2').className = desativado;
		document.getElementById('aba_3').className = ativado;
	}
	
	AjaxA.open("GET", "dados_motos.php?id="+id+'&tipo='+tipo, true);
	AjaxA.onreadystatechange=function(){
		if(AjaxA.readyState==4){
			document.getElementById("texto").innerHTML = '';
			document.getElementById("texto").innerHTML = AjaxA.responseText;
		}
	}
	AjaxA.send(null)
}


function controle_aba(n_aba,id,tipo,nova){
	var ativado = "div_aba_hover";
	var desativado = "div_aba";
	
	document.getElementById("texto").innerHTML = '<div  align="center"><img src="imagens/loading.gif" width="32" height="32" /></div>'
	
	if(n_aba==1){
		document.getElementById('aba_1').className = ativado;
		document.getElementById('aba_2').className = desativado;
		if(nova==1){
			document.getElementById('aba_3').className = desativado;
		}
				
	}else if(n_aba==2){
		document.getElementById('aba_1').className = desativado;
		document.getElementById('aba_2').className = ativado;
		if(nova==1){
			document.getElementById('aba_3').className = desativado;
		}
		
	}else if(n_aba==3){
		document.getElementById('aba_1').className = desativado;
		document.getElementById('aba_2').className = desativado;
		if(nova==1){
			document.getElementById('aba_3').className = ativado;
		}
	}
	
	AjaxA.open("GET", "dados_motos.php?id="+id+'&tipo='+tipo, true);
	AjaxA.onreadystatechange=function(){
		if(AjaxA.readyState==4){
			document.getElementById("texto").innerHTML = '';
			document.getElementById("texto").innerHTML = AjaxA.responseText;
		}
	}
	AjaxA.send(null)
}
//======================

//VER MAPA

function ver_mapa(loja){

		AjaxA.open("GET", "gerar_mapa.php?loja="+loja, true);
		AjaxA.onreadystatechange=function(){
			if(AjaxA.readyState==4){
				document.getElementById("mapa_google").innerHTML = '';
				document.getElementById("mapa_google").innerHTML = AjaxA.responseText;
			}
		}
	AjaxA.send(null)
}

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

//VER NOTICIAS, FINANCIAMENTO

function outros_dados(id,pg,arq){
		
		document.getElementById("outros_dados").innerHTML = '<div align="center" style="padding:10px;"><img src="imagens/loading.gif" width="32" height="32" /></div>';
		
		AjaxA.open("GET", arq+"?id="+id+"&pagina="+pg, true);
		AjaxA.onreadystatechange=function(){
			if(AjaxA.readyState==4){
				document.getElementById("outros_dados").innerHTML = '';
				document.getElementById("outros_dados").innerHTML = AjaxA.responseText;
			}
		}
	AjaxA.send(null);
}

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

//VER MAPA

function galeria_fotos(id,pg){

		AjaxA.open("GET", "lista_fotos.php?id="+id+"&pagina="+pg, true);
		AjaxA.onreadystatechange=function(){
			if(AjaxA.readyState==4){
				document.getElementById("fotos_mini").innerHTML = '';
				document.getElementById("fotos_mini").innerHTML = AjaxA.responseText;
			}
		}
	AjaxA.send(null)
	setTimeout(function(){document.getElementById('foto_grande').src = document.getElementById('primeira_foto').value;},1000);
}

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

