// JavaScript Document ********************************************
function objetoAjax()
{
	var xmlHttp;
	try 
	{
	// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		return xmlHttp;
	} 
	catch (e) 
	{
// Internet Explorer
		try 
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			return xmlHttp;
		} 
		catch (e) 
		{
			try 
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				return xmlHttp;
			} 
			catch (e) 
			{
				alert("Tu navegador no soporta AJAX!");
				return false;
			}
		}
	}
}
//*****************************************************************
		
//Detalles dependientes del combo *********************************
function muestraCatalogo(dir)
{
	divResultado = document.getElementById('catalogo');
	ajax=objetoAjax();	
	ajax.open("POST", "servicios/refacciones/galeria.php",true);
	ajax.onreadystatechange=function() 
	{
		if (ajax.readyState==4) {
			divResultado.innerHTML = ajax.responseText
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("dir=" + dir)
}

function Enviar(pagina,capa) 
{
	var
	ajax;
	ajax = objetoAjax();
	ajax.open("GET", pagina, true);
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.onreadystatechange = function()
	{
		if (ajax.readyState == 4)
		{
			document.getElementById(capa).innerHTML =ajax.responseText;
		}
	}
	ajax.send(null);
}

function Redireccion(pagina)
{
	pagina="http://www.nissan"+pagina+".com.mx";
	window.open(pagina); 
}
function RedireccionEspecial(pagina)
{
	pagina="http://www.nissan.com.mx/"+pagina+"/";
	window.open(pagina); 
}
//*****************************************************************
function colorIn(elemento){
			//elemento.style.color = "#003366";
			elemento.style.background = "#666666";		
	}

function colorOut(elemento){
			//elemento.style.color = "#003366";
			elemento.style.background = "#999999";	
	}

function salir()
{
	var exit = confirm("Esta usted seguro que desea abandonar la sala?");
	if(exit==true){Enviar("chat.php?logout=true","objetivo");}

}

function valores()
{
	if (document.getElementById("Nombre").value==""){alert("debe ingresar un nombre"); return false;}
	if (document.getElementById("Ciudad").value==""){alert("debe ingresar una ciudad"); return false;}
	if (document.getElementById("Telefono").value==""){alert("debe ingresar un telefono"); return false;}
	if (document.getElementById("email").value==""){alert("debe ingresar un email"); return false;}

//	if (document.getElementById("Estado").value==""){alert("debe ingresar un estado"); return false;}
	valores="Nombre=" + document.getElementById("Nombre").value;
	valores +="&Ciudad=" + document.getElementById("Ciudad").value;
	valores +="&Estado=" + document.getElementById("Estado").value;
	//valores +="&Email=" + document.getElementById("email").value;
	//valores +="&Unidad=" + document.getElementById("Unidad").value;
	if(document.getElementById("Direccion").value != "") valores +="&Email=" + document.getElementById("Direccion").value;
	if(document.getElementById("Colonia").value != "") valores +="&Email=" + document.getElementById("Colonia").value;
	if(document.getElementById("Telefono").value != "") valores +="&Email=" + document.getElementById("Telefono").value;
	//if(document.getElementById("Comentarios").text != "") valores +="&Observaciones=" + document.getElementById("Comentarios").text;
	window.open ("http://www.credinissan.com.mx", "mywindow","width=1000,height=1000, scrollbars=1");
}

function datos_nesesarios()
{
	var e=document.getElementsByTagName("input");

	for(i=0;i<e.length;i++)
	{
		if(e[i].getAttribute('type') == 'text')
			e[i].style.backgroundColor = "#ffffff";
	}
	for(i=0;i<e.length;i++)
	{
		if((e[i].getAttribute('type') == 'text') &&(e[i].value==""))
		{
			e[i].style.backgroundColor = "#ffff00";
			alert("Falto llenar uno o mas campos");
			return false;
		}
	}
	if(document.getElementById("unidad").value=="") {alert("Seleccione un tipo de auto"); return false;}
	validar_Email(document.getElementById("email").value);
	alert("Hemos recibido los datos. En breve recivira informacion de uno de nuestros asesores ");
	form1.submit();
}

function validar_Email(valor) {
	re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
    if(!re.exec(valor))    {
		alert("La dirección de email es incorrecta.");
		document.getElementById("email").style.backgroundColor = "#ffff00";
		return false();
    }
}

function ver_autos(valor)
{
	document.getElementById("objeto1").innerHTML="Cargando Gama.<br>Espere un momento";
	if(valor==0)
	{
		var total = document.getElementsByName("tipo_vehiculo").length
		for(i=0;i<total;i++)
		{
			if (document.getElementsByName("tipo_vehiculo")[i].checked) 
				valor=document.getElementsByName("tipo_vehiculo")[i].value
		}	
	}
	Enviar("cotiza_tu_auto2.php?auto="+valor,"objeto1")
}

function ver_tipo(tipo)
{
	document.getElementById("unidad").value=tipo;
	document.getElementById("objeto2").innerHTML="Cargando los diferentes modelos del: "+tipo+".<br>Espere un momento";
	Enviar("cotiza_tu_auto3.php?tipo="+tipo,"objeto2");
}
