// JavaScript Document
var xmlHttpDelegacion
var xmlHttpMarca
var xmlHttpModelo
var xmlHttpColor
var xmlHttpListado

var delegacion	= ''
var marca		= ''
var modelo		= ''
var color		= ''

var precio1 = 0
var precio2 = 0

var oferta1 = 0
var oferta2 = 0
var oferta3 = 0
var oferta4 = 0
var oferta5 = 0
var strListado = ''

function Inicio()
{
	creaDelegacion();
	creaMarca('');
	creaListado('', '', '','', 1, 0)
}
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXX  FUNCIONES GENERALES	
function limpiavalores()
{
	document.getElementById("div_marca").innerHTML=""
	document.getElementById("div_modelo").innerHTML=""
	document.getElementById("div_color").innerHTML=""
	document.getElementById("div_listado").innerHTML=""
}

function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
} 

function verficha(id){
	var vehiculo = id
	
	document.getElementById("div_listado").innerHTML=""
	var tipo = document.getElementById("tipo").value
	//alert(tipo)
	xmlHttpListado = GetXmlHttpObject()
	if (xmlHttpListado==null)
	{
		alert ("El navegador no soporta HTTP Request")
		return
	} 
	var url="/autocasion/ajax/listado.asp"
	
	url=url+"?vehiculo="+vehiculo
	url=url+"&lista=1"
	url=url+"&sid="+Math.random()
	//window.location = '#'+url
	xmlHttpListado.onreadystatechange = CambiaEstadoListado
	xmlHttpListado.open("GET",url,true)
	xmlHttpListado.send(null)
}

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXX  FUNCIONES DELEGACION
function recargaDelegacion()
{
	document.getElementById("div_marca").innerHTML=""
	document.getElementById("div_modelo").innerHTML=""
	document.getElementById("div_color").innerHTML=""
	document.getElementById("div_listado").innerHTML=""	
	creaDelegacion()
	
}
function creaDelegacion()
{
	var tipo = document.getElementById("tipo").value
	xmlHttpDelegacion = GetXmlHttpObject()
	if (xmlHttpDelegacion==null)
	{
		alert ("El navegador no soporta HTTP Request")
		return
	} 
	var url="/autocasion/ajax/delegacion.asp"
	url=url+"?tipo="+tipo
	url=url+"&sid="+Math.random()
	xmlHttpDelegacion.onreadystatechange = CambiaEstadoDelegacion
	xmlHttpDelegacion.open("GET",url,true)
	xmlHttpDelegacion.send(null)
}
function CambiaEstadoDelegacion() 
{ 

	var divMenu = document.getElementById('div_delegacion');
	if (xmlHttpDelegacion.readyState==4 || xmlHttpDelegacion.readyState=="complete")
	{ 
		divMenu.innerHTML = xmlHttpDelegacion.responseText;
	} 
}

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXX  FUNCIONES MARCA
function recargaMarca()
{

	var delegacion = document.getElementById('delegacion').options[document.getElementById('delegacion').selectedIndex].value
	
	document.getElementById("div_marca").innerHTML=""
	document.getElementById("div_modelo").innerHTML=""
	document.getElementById("div_color").innerHTML=""
	document.getElementById("div_listado").innerHTML=""
	creaMarca(marca)
	creaListado(delegacion, '', '','', 1, 0)
}
function creaMarca(delegacion)
{
	document.getElementById("div_marca").innerHTML=""
	var tipo = document.getElementById("tipo").value
	xmlHttpMarca = GetXmlHttpObject()
	if (xmlHttpMarca==null)
	{
		alert ("El navegador no soporta HTTP Request")
		return
	} 
	var url="/autocasion/ajax/marca.asp"
	url=url+"?tipo="+tipo
	url=url+"&delegacion="+delegacion
	url=url+"&sid="+Math.random()
	xmlHttpMarca.onreadystatechange = CambiaEstadoMarca
	xmlHttpMarca.open("GET",url,true)
	xmlHttpMarca.send(null)
}
function CambiaEstadoMarca() 
{ 

	var divMenu = document.getElementById('div_marca');
	if (xmlHttpMarca.readyState==4 || xmlHttpMarca.readyState=="complete")
	{ 
		divMenu.innerHTML = xmlHttpMarca.responseText;
	} 
}

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXX  FUNCIONES MODELO
function recargaModelo()
{

	var delegacion = document.getElementById('delegacion').options[document.getElementById('delegacion').selectedIndex].value
	var marca = document.getElementById('marca').options[document.getElementById('marca').selectedIndex].value
	
	document.getElementById("div_modelo").innerHTML=""
	document.getElementById("div_color").innerHTML=""
	document.getElementById("div_listado").innerHTML=""
	creaModelo(delegacion, marca)
	creaListado(delegacion, marca, '','', 1, 0)

}
function creaModelo(delegacion, marca)
{
	document.getElementById("div_modelo").innerHTML=""
	var tipo = document.getElementById("tipo").value
	xmlHttpModelo = GetXmlHttpObject()
	if (xmlHttpModelo==null)
	{
		alert ("El navegador no soporta HTTP Request")
		return
	} 
	var url="/autocasion/ajax/modelo.asp"
	url=url+"?tipo="+tipo
	url=url+"&delegacion="+delegacion
	url=url+"&marca="+marca
	url=url+"&sid="+Math.random()
	xmlHttpModelo.onreadystatechange = CambiaEstadoModelo
	xmlHttpModelo.open("GET",url,true)
	xmlHttpModelo.send(null)
}
function CambiaEstadoModelo() 
{ 

	var divMenu = document.getElementById('div_modelo');
	if (xmlHttpModelo.readyState==4 || xmlHttpModelo.readyState=="complete")
	{ 
		divMenu.innerHTML = xmlHttpModelo.responseText;
	} 
} 

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXX  FUNCIONES COLOR
function recargaColor()
{
	var delegacion = document.getElementById('delegacion').options[document.getElementById('delegacion').selectedIndex].value
	var marca = document.getElementById('marca').options[document.getElementById('marca').selectedIndex].value
	var modelo = document.getElementById('modelo').options[document.getElementById('modelo').selectedIndex].value

	
	document.getElementById("div_color").innerHTML=""
	document.getElementById("div_listado").innerHTML=""
	creaColor(modelo)
	creaListado(delegacion, marca, modelo,'', 1, 0)


}
function creaColor(modelo)
{
	document.getElementById("div_color").innerHTML=""
	var tipo = document.getElementById("tipo").value
	xmlHttpColor = GetXmlHttpObject()
	if (xmlHttpColor==null)
	{
		alert ("El navegador no soporta HTTP Request")
		return
	} 
	var url="/autocasion/ajax/color.asp"
	url=url+"?tipo="+tipo
	url=url+"&delegacion="+delegacion
	url=url+"&marca="+marca
	url=url+"&modelo="+modelo
	url=url+"&sid="+Math.random()
	xmlHttpColor.onreadystatechange = CambiaEstadoColor
	xmlHttpColor.open("GET",url,true)
	xmlHttpColor.send(null)	 
}
function CambiaEstadoColor() 
{ 
	var divMenu = document.getElementById('div_color');
	if (xmlHttpColor.readyState==4 || xmlHttpColor.readyState=="complete")
	{ 
		divMenu.innerHTML = xmlHttpColor.responseText;
	} 
}

function recargaColor2()
{
	var delegacion = document.getElementById('delegacion').options[document.getElementById('delegacion').selectedIndex].value
	var marca = document.getElementById('marca').options[document.getElementById('marca').selectedIndex].value
	var modelo = document.getElementById('modelo').options[document.getElementById('modelo').selectedIndex].value
	var color = document.getElementById('color').options[document.getElementById('color').selectedIndex].value

	
	document.getElementById("div_listado").innerHTML=""
	creaListado(delegacion, marca, modelo,color, 1, 0)
}
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXX  FUNCIONES LISTADO
function recargaListado()
{
	//alert("l")
	var delegacion = document.getElementById('delegacion').options[document.getElementById('delegacion').selectedIndex].value
	var marca = document.getElementById('marca').options[document.getElementById('marca').selectedIndex].value
	var modelo = document.getElementById('modelo').options[document.getElementById('modelo').selectedIndex].value
	var color = document.getElementById('color').options[document.getElementById('color').selectedIndex].value

	document.getElementById("div_listado").innerHTML=""
	
}
function creaListado(delegacion, marca, modelo, color, lista, bloque)
{
	document.getElementById("div_listado").innerHTML=""
	var tipo = document.getElementById("tipo").value
	//alert(tipo)
	xmlHttpListado = GetXmlHttpObject()
	if (xmlHttpListado==null)
	{
		alert ("El navegador no soporta HTTP Request")
		return
	} 
	var url="/autocasion/ajax/listado.asp"
	url=url+"?tipo="+tipo
	url=url+"&delegacion="+delegacion
	url=url+"&marca="+marca
	url=url+"&modelo="+modelo
	url=url+"&color="+color
	url=url+"&lista="+lista
	url=url+"&bloque="+bloque
	url=url+"&sid="+Math.random()
	strListado = url
	//window.location = '#'+url
	//alert(url)
	xmlHttpListado.onreadystatechange = CambiaEstadoListado
	xmlHttpListado.open("GET",url,true)
	xmlHttpListado.send(null)
}
function verListado()
{
	document.getElementById("div_listado").innerHTML=""
	var tipo = document.getElementById("tipo").value
	//alert(tipo)
	xmlHttpListado = GetXmlHttpObject()
	if (xmlHttpListado==null)
	{
		alert ("El navegador no soporta HTTP Request")
		return
	} 

	url = strListado
	//window.location = '#'+url
	//alert(url)
	xmlHttpListado.onreadystatechange = CambiaEstadoListado
	xmlHttpListado.open("GET",url,true)
	xmlHttpListado.send(null)	
}
function creaOferta(oferta, bloque)
{
	document.getElementById("div_listado").innerHTML=""
	var tipo = document.getElementById("tipo").value
	//alert(tipo)
	xmlHttpListado = GetXmlHttpObject()
	if (xmlHttpListado==null)
	{
		alert ("El navegador no soporta HTTP Request")
		return
	} 
	var url="/autocasion/ajax/ofertas.asp"
	url=url+"?tipo="+tipo
	url=url+"&oferta="+oferta
	url=url+"&bloque="+bloque
	url=url+"&sid="+Math.random()
	//window.location = '#'+url
	//alert(url)
	xmlHttpListado.onreadystatechange = CambiaEstadoListado
	xmlHttpListado.open("GET",url,true)
	xmlHttpListado.send(null)
}

function CambiaEstadoListado() 
{ 

	var divMenu = document.getElementById('div_listado');
	if (xmlHttpListado.readyState==4 || xmlHttpListado.readyState=="complete")
	{ 
		divMenu.innerHTML = xmlHttpListado.responseText;
	} 
} 

function cargalistadoPrecios()
{
	document.getElementById("div_marca").innerHTML=""
	document.getElementById("div_modelo").innerHTML=""
	document.getElementById("div_color").innerHTML=""
	document.getElementById("div_listado").innerHTML=""	
	var precio1 = document.getElementById('preciodesde2').options[document.getElementById('preciodesde2').selectedIndex].value
	var precio2 = document.getElementById('preciohasta2').options[document.getElementById('preciohasta2').selectedIndex].value
}
