function Comprobar(idtipovehiculo,tipo)	
{

	formu = obtenerObjeto("Formu");

// COMPROBAMOS QUE LOS CAMPOS SON CORRECTOS
				
	if (formu.pPreciodesde.value != "" && !validateNumber(formu.pPreciodesde.value.replace(".","")))
	{
		alert("El Precio Desde introducido no es correcto.");
		formu.pPreciodesde.focus();
		return; 
	}
	
	if (formu.pPreciohasta.value != "" && !validateNumber(formu.pPreciohasta.value.replace(".","")))
	{
		alert("El Precio Hasta introducido no es correcto.");
		formu.pPreciohasta.focus();
		return; 
	}				
			

// COMPROBAMOS LOS CAMPOS QUE SE VALIDAN			
			
	formu.target=window.name;
	if (tipo==2)
		formu.action="javascript:obtenerListadoVehiculos('" + idtipovehiculo + "')";
	else
		formu.action="/secciones/buscador/buscador.asp";
	try { formu.onsubmit(); }
	catch(e) {}
	formu.submit();
}

var ajaxSeries = new sack();
var ajaxDatosVehiculo = new sack();
var ajaxListado = new sack();

var iPaso = 0;

function whenLoading1(){
	var e = document.getElementById('ficha'); 
	e.innerHTML = "<table width='100%' height='545' border='0' cellspacing'0' cellpadding='0'><tr><td width='100%' align='center' valign='middle'><img src='/images/loading.gif'><br><br></td></tr></table>";
}

function whenLoading2(){
	var e = document.getElementById('listadovehiculos'); 
	e.innerHTML = "<table width='100%' border='0' cellspacing'0' cellpadding='0'><tr><td width='100%' align='center'><img src='/images/loading.gif'><br><br></td></tr></table>";
}

function whenLoaded(){
	var e = document.getElementById('ficha'); 
	e.innerHTML = "<p>Data Sent...</p>";
}

function whenInteractive(){
	var e = document.getElementById('ficha'); 
	e.innerHTML = "<p>getting data...</p>";
}

function whenCompleted(idMarca,idSerie){
//	var e = document.getElementById('sackdata'); 
//	if (ajax.responseStatus){
//		var string = "<p>Status Code: " + ajax.responseStatus[0] + "</p><p>Status Message: " + ajax.responseStatus[1] + "</p><p>URLString Sent: " + ajax.URLString + "</p>";
//	} else {
//		var string = "<p>URLString Sent: " + ajax.URLString + "</p>";
//	}
//	e.innerHTML = string;	
	
	if (window.document.Formu.pMarca.value!="0" && iPaso==0)
		obtenerListadoSeries(window.document.Formu.pMarca.value, document.getElementById('pSerie').value);		
	
	ComprobarLoadVehiculo();
	
	iPaso = 1;
}

function obtenerDatosCoche(idVehiculo)
{
	var form = document.getElementById('form');
	ajaxDatosVehiculo.setVar("pIdVehiculo", idVehiculo); // recomended method of setting data to be parsed.
	ajaxDatosVehiculo.requestFile = "/secciones/vehiculos/datosVehiculo.asp";
	//ajax.method = form.method.value;
	ajaxDatosVehiculo.element = 'ficha';
	ajaxDatosVehiculo.onLoading = whenLoading1;
	ajaxDatosVehiculo.onLoaded = whenLoaded; 
	ajaxDatosVehiculo.onInteractive = whenInteractive;
	//ajax.onCompletion = whenCompleted;
	ajaxDatosVehiculo.runAJAX("");
}

function obtenerListadoVehiculos(idTipoVehiculo)
{
	var form = document.getElementById('form');
	ajaxListado.setVar("tipovehiculo", idTipoVehiculo); // recomended method of setting data to be parsed.
	ajaxListado.setVar("pMarca", window.document.Formu.pMarca.value); // recomended method of setting data to be parsed.
	ajaxListado.setVar("pSerie", document.getElementById('pSerie').value); // recomended method of setting data to be parsed.
	ajaxListado.setVar("pAnyoMatricula", window.document.Formu.pAnyoMatricula.value); // recomended method of setting data to be parsed.
	ajaxListado.setVar("pPreciodesde", window.document.Formu.pPreciodesde.value); // recomended method of setting data to be parsed.
	ajaxListado.setVar("pPreciohasta", window.document.Formu.pPreciohasta.value); // recomended method of setting data to be parsed.
	ajaxListado.setVar("pMatricula", window.document.Formu.pMatricula.value); // recomended method of setting data to be parsed.
	ajaxListado.requestFile = "/secciones/vehiculos/listadoVehiculos.asp";
	//ajaxListado.method = form.method.value;
	ajaxListado.element = 'listadovehiculos';	
	ajaxListado.onLoading = whenLoading2;
	ajaxListado.onLoaded = whenLoaded; 
	ajaxListado.onInteractive = whenInteractive;
	ajaxListado.onCompletion = whenCompleted;
	ajaxListado.runAJAX("");				
}

function obtenerListadoSeries(idMarca, idSerie)
{
	var form = document.getElementById('form');
	ajaxSeries.setVar("pIdMarca", idMarca); // recomended method of setting data to be parsed.
	ajaxSeries.setVar("pIdSerie", idSerie); // recomended method of setting data to be parsed.
	ajaxSeries.requestFile = "/secciones/vehiculos/listadoSeries.asp";
	//ajax.method = form.method.value;
	ajaxSeries.element = 'selectseries';	
	//ajax.onLoading = whenLoading;
	//ajax.onLoaded = whenLoaded; 
	//ajax.onInteractive = whenInteractive;
	//ajax.onCompletion = whenCompleted;
	ajaxSeries.runAJAX("");		
}

function ComprobarLoadVehiculo()
{
	if (window.document.Formu.pIdVehiculo.value!="")
	{
		MM_showHideLayers('overlay','','show','ficha','','show');
		obtenerDatosCoche(window.document.Formu.pIdVehiculo.value);
		window.document.Formu.pIdVehiculo.value="";
	}
}