function nuevoAjax()
{ 
	var xmlhttp=false; 
	try 
	{ 
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// Creacion del objet AJAX para IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) 
		{ 
			xmlhttp=false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); } 
	return xmlhttp; 
}

function cargaModelos(marca)
{
	var aleatorio=Math.random();
	ajax=nuevoAjax();
	ajax.open("GET","carga_modelos.php?marca="+marca+"&aleatorio="+aleatorio, true);
	ajax.onreadystatechange = function() 
	{ 
		if (ajax.readyState==1)
		{ 
			document.getElementById('div_modelo').innerHTML = "<select id='modelo' name='modelo' class='span-45 left tab'><option value='0'>Cargando Modelos...</option></select>";
			document.getElementById('modelo').disabled = 'disabled';
			document.getElementById('marca').disabled = 'disabled';
			document.getElementById('estado').disabled = 'disabled';
			document.getElementById('ciudad').disabled = 'disabled';
			document.getElementById('clasificacion').innerHTML = 'Autos y Camionetas';
			muestraBanner(marca);
		} 
		if (ajax.readyState==4)
		{ 
			if(ajax.status==200)
            {
				document.getElementById('div_modelo').innerHTML = ajax.responseText;
				document.getElementById('marca').disabled = false;
				document.getElementById('estado').disabled = false;
				document.getElementById('ciudad').disabled = false;
			}
		} 
	}
	ajax.send(null);
}

function seleccionaMarca(idmarca, clasificacion)
{
	var select		= document.getElementById("marca")
	var band		= 0;
	for(var i=0; i<select.options.length; i++)
	{
 		if(select.options[i].value==idmarca)
 		{
 			select.options[i].selected=true;
 			band	= 1;
 		}
 		if(band == 0)
 			select.options[0].selected=true;
	}
	document.getElementById('clasificacion').innerHTML = clasificacion;
	muestraBanner(idmarca);
}

function muestraBanner(idmarca)
{
	//BANNER MONDO CAR--------------------------------------------------
	if(idmarca == '48')
		document.getElementById('banner_mondo').style.display = 'block';
	else
		document.getElementById('banner_mondo').style.display = 'none';
	//------------------------------------------------------------------
}

function cargaCiudades(estado)
{
	var aleatorio=Math.random();
	ajax=nuevoAjax();
	ajax.open("GET","carga_ciudades.php?estado="+estado+"&aleatorio="+aleatorio, true);
	ajax.onreadystatechange = function() 
	{ 
		if (ajax.readyState==1)
		{ 
			document.getElementById('div_ciudad').innerHTML = "<select id='ciudad' name='ciudad' class='span-4 left tab'><option value='0'>Cargando Ciudades...</option></select>";
			document.getElementById('ciudad').disabled = 'disabled';
			document.getElementById('modelo').disabled = 'disabled';
			document.getElementById('marca').disabled = 'disabled';
			document.getElementById('estado').disabled = 'disabled';
		} 
		if (ajax.readyState==4)
		{ 
			if(ajax.status==200)
            {
				document.getElementById('div_ciudad').innerHTML = ajax.responseText;
				document.getElementById('marca').disabled = false;
				document.getElementById('estado').disabled = false;
				document.getElementById('modelo').disabled = false;
				cargaAgencias(estado, '0');
			}
		} 
	}
	ajax.send(null);
}

function cargaAgencias(estado, ciudad)
{	
	var aleatorio=Math.random();
	ajax=nuevoAjax();
	ajax.open("GET","carga_agencias.php?estado="+estado+"&ciudad="+ciudad+"&aleatorio="+aleatorio, true);
	
	ajax.onreadystatechange = function() 
	{ 
		if (ajax.readyState==1)
		{ 
			document.getElementById('div_propietario').innerHTML = "<select id='propietario' name='propietario' class='span-4 left tab'><option value='0'>Cargando Agencias...</option></select>";
			document.getElementById('propietario').disabled = 'disabled';
			
			document.getElementById('ciudad').disabled = 'disabled';
			document.getElementById('modelo').disabled = 'disabled';
			document.getElementById('marca').disabled = 'disabled';
			document.getElementById('estado').disabled = 'disabled';
			
		} 
		if (ajax.readyState==4)
		{ 
			if(ajax.status==200)
            {
				document.getElementById('div_propietario').innerHTML = ajax.responseText;
				document.getElementById('marca').disabled = false;
				document.getElementById('estado').disabled = false;
				document.getElementById('modelo').disabled = false;
				document.getElementById('ciudad').disabled = false;
			}
		} 
	}
	ajax.send(null);
}

function cargaAnioFin(anio_ini, anio_fin)
{
	var anios 				= new Array();
	var i 					= 0;
	var select				= "<select id='ANIO_FIN' name='ANIO_FIN' class='tab span-4 left'><option value='0'>Hasta</option>"
	var cont_anio			= anio_fin;
	
	if(anio_ini != '0')
	{
		while(cont_anio >= anio_ini)
		{
			select					= select+"<option value='"+cont_anio+"'>"+cont_anio+"</option>";
			if(cont_anio <= 1990)
				cont_anio			= cont_anio - 10;
			else
				cont_anio			= cont_anio - 1;
		}
		select						= select+"</select>";
		document.getElementById('div_anio_fin').innerHTML = select;
	}
	else
		document.getElementById('div_anio_fin').innerHTML = "<select id='ANIO_FIN' name='ANIO_FIN' class='tab span-4 left'><option value='0'>Hasta</option></select>"
	
}

function cargaPrecioFin(precio_ini)
{
	var precios					= new Array(5000, 10000, 15000, 20000, 25000, 30000, 35000, 50000, 75000, 100000, 125000, 150000, 200000, 250000, 300000, 500000);
	var valores					= new Array("$ 5,000", "$ 10,000", "$ 15,000", "$ 20,000", "$ 25,000", "$ 30,000", "$ 35,000", "$ 50,000", "$ 75,000", "$ 100,000", "$ 125,000", "$ 150,000", "$ 200,000", "$ 250,000", "$ 300,000", "$ 500,000");
	var num_precios				= 16;
	var select					= "<select id='PRECIO_FIN' name='PRECIO_FIN' class='span-4 left tab'><option value='0'>Hasta</option>"
	
	if(precio_ini != '0')
	{
		for( var i = 0; i < num_precios; i = i + 1 )
		{
			if(precio_ini <= precios[i])
			{
				select		= select+"<option value='"+precios[i]+"'>"+valores[i]+"</option>";
			}
		}
		select						= select+"</select>";
		document.getElementById('div_precio_fin').innerHTML = select;
	}
	else
		document.getElementById('div_precio_fin').innerHTML = "<select id='PRECIO_FIN' name='PRECIO_FIN' class='span-4 left tab'><option value='0'>Hasta</option></select>"
}
