///linea 229 dominio
function scon(sacar)
{
var sacar=sacar;
document.getElementById(sacar).selectedIndex='0';
document.getElementById(sacar).value=0;

//alert('menos'+sacar);

if(sacar=='pesosb')
document.getElementById('pesosb').style.display='none';
if(sacar=='dolarb')
document.getElementById('dolarb').style.display='none';



}

function moneda(moneda)
{
var moneda=moneda;
if(moneda=='0')
{
document.getElementById('pesosb').style.display='none';
document.getElementById('dolarb').style.display='none';
document.getElementById('pesosb').selectedIndex='0';
document.getElementById('dolarb').selectedIndex='0';
document.getElementById('pesosb').value=0;
document.getElementById('dolarb').value=0;
}
if(moneda=='1'){document.getElementById('pesosb').style.display='inline';document.getElementById('dolarb').style.display='none';document.getElementById('dolarb').value=0;}
if(moneda=='2'){document.getElementById('dolarb').style.display='inline';document.getElementById('pesosb').style.display='none';document.getElementById('pesosb').value=0;}
}

// Declaro los selects que componen el documento HTML. Su atributo ID debe figurar aqui.
var buscaSelects=new Array();
buscaSelects[0]="busca1";
buscaSelects[1]="busca2";
buscaSelects[2]="busca3";


function buscarEnArray(array, dato)
{
	// Retorna el indice de la posicion donde se encuentra el elemento en el array o null si no se encuentra
	var x=0;
	while(array[x])
	{
		if(array[x]==dato) return x;
		x++;
	}
	return null;
}




function OC(userb,t)
{
var userb=userb;
var t=t;
var otrascondiciones='';

//alert('user='+userb);
//alert('oc='+otrascondiciones);

var cwebb=document.getElementById('cwebb').value; if(cwebb!='') var otrascondiciones=otrascondiciones+cwebb;

var vehiculob=document.getElementById('busca1').value; if(vehiculob>0) var otrascondiciones=otrascondiciones+' and vehiculo='+vehiculob;
var marcab=document.getElementById('busca2').value; if(marcab>0) var otrascondiciones=otrascondiciones+' and marca='+marcab;
var modelob=document.getElementById('busca3').value; if(modelob>0) var otrascondiciones=otrascondiciones+' and modelo='+modelob;

//var ciudadb=document.getElementById('ciudadb').value; if(ciudadb>0) var otrascondiciones=otrascondiciones+' and ciudad='+ciudadb;
//var regionb=document.getElementById('regionb').value; if(regionb>0) var otrascondiciones=otrascondiciones+' and region='+regionb;



var tipob=document.getElementById('tipob').value; if(tipob>0) var otrascondiciones=otrascondiciones+' and tipo_aviso='+tipob;
var anob=document.getElementById('anob').value; if(anob>0) var otrascondiciones=otrascondiciones+' and ano='+anob;
var npuertasb=document.getElementById('npuertasb').value; if(npuertasb>0) var otrascondiciones=otrascondiciones+' and npuertas='+npuertasb;
var combustibleb=document.getElementById('combustibleb').value; if(combustibleb>0) var otrascondiciones=otrascondiciones+' and combustible='+combustibleb;
var ncilb=document.getElementById('ncilb').value; if(ncilb>0) var otrascondiciones=otrascondiciones+' and ncil='+ncilb;
var motorb=document.getElementById('motorb').value; if(motorb>0) var otrascondiciones=otrascondiciones+' and motor='+motorb;
var transmisionb=document.getElementById('transmisionb').value; if(transmisionb>0) var otrascondiciones=otrascondiciones+' and transmision='+transmisionb;
var direccionb=document.getElementById('direccionb').value; if(direccionb>0) var otrascondiciones=otrascondiciones+' and direccion='+direccionb;
var monedab=document.getElementById('monedab').value; if(monedab>0) var otrascondiciones=otrascondiciones+' and moneda='+monedab;
var pesosb=document.getElementById('pesosb').value; if(pesosb>0) var otrascondiciones=otrascondiciones+' and precio='+pesosb;
var dolarb=document.getElementById('dolarb').value; if(dolarb>0) var otrascondiciones=otrascondiciones+' and precio='+dolarb;

cargalistado('0',''+t,'user='+userb+' '+otrascondiciones);

//alert('user='+userb+' '+otrascondiciones);

}




function buscaContenido(idSelectOrigen,userb,t,otrascondiciones)
{

var userb=userb;
var t=t;
var otrascondiciones=otrascondiciones;
var idSelectOrigen=idSelectOrigen;

	var posicionSelectDestino=buscarEnArray(buscaSelects, idSelectOrigen)+1;
	// Obtengo el select que el usuario modifico
	var selectOrigen=document.getElementById(idSelectOrigen);
	// Obtengo la opcion que el usuario selecciono
	var opcionSeleccionada=selectOrigen.options[selectOrigen.selectedIndex].value;

var cwebb=document.getElementById('cwebb').value; if(cwebb!='') var otrascondiciones=otrascondiciones+cwebb;


//alert('cond:'+otrascondiciones);

var vehiculob=document.getElementById('busca1').value; if(vehiculob>0) var otrascondiciones=otrascondiciones+' and vehiculo='+vehiculob;
if(vehiculob>0)
{
var marcab=document.getElementById('busca2').value; 
if(posicionSelectDestino!='1')
if(marcab>0) var otrascondiciones=otrascondiciones+' and marca='+marcab;
}

if(marcab>0)
{
var modelob=document.getElementById('busca3').value; 
if(posicionSelectDestino!='1')
if(posicionSelectDestino!='2')
if(modelob>0) var otrascondiciones=otrascondiciones+' and modelo='+modelob;
}

//alert('cond:'+otrascondiciones);

//var ciudadb=document.getElementById('ciudadb').value; if(ciudadb>0) var otrascondiciones=otrascondiciones+' and ciudad='+ciudadb;
//var regionb=document.getElementById('regionb').value; if(regionb>0) var otrascondiciones=otrascondiciones+' and region='+regionb;



var tipob=document.getElementById('tipob').value; if(tipob>0) var otrascondiciones=otrascondiciones+' and tipo_aviso='+tipob;
var anob=document.getElementById('anob').value; if(anob>0) var otrascondiciones=otrascondiciones+' and ano='+anob;
var npuertasb=document.getElementById('npuertasb').value; if(npuertasb>0) var otrascondiciones=otrascondiciones+' and npuertas='+npuertasb;
var combustibleb=document.getElementById('combustibleb').value; if(combustibleb>0) var otrascondiciones=otrascondiciones+' and combustible='+combustibleb;
var ncilb=document.getElementById('ncilb').value; if(ncilb>0) var otrascondiciones=otrascondiciones+' and ncil='+ncilb;
var motorb=document.getElementById('motorb').value; if(motorb>0) var otrascondiciones=otrascondiciones+' and motor='+motorb;
var transmisionb=document.getElementById('transmisionb').value; if(transmisionb>0) var otrascondiciones=otrascondiciones+' and transmision='+transmisionb;
var direccionb=document.getElementById('direccionb').value; if(direccionb>0) var otrascondiciones=otrascondiciones+' and direccion='+direccionb;
var monedab=document.getElementById('monedab').value; if(monedab>0) var otrascondiciones=otrascondiciones+' and moneda='+monedab;
var pesosb=document.getElementById('pesosb').value; if(pesosb>0) var otrascondiciones=otrascondiciones+' and precio='+pesosb;
var dolarb=document.getElementById('dolarb').value; if(dolarb>0) var otrascondiciones=otrascondiciones+' and precio='+dolarb;

	// Obtengo la posicion que ocupa el select que debe ser cargado en el array declarado mas arriba
	// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo los selects siguientes en estado "Selecciona opcion..."

  

//alert('cond:'+otrascondiciones);

 
 
//alert('hola'+posicionSelectDestino);

//alert('holaopcion'+opcionSeleccionada);

if(posicionSelectDestino=='1')
{
//alert('holaposicion'+posicionSelectDestino);


document.getElementById('busca3').style.display='none';
//document.getElementById('otrascondiciones0').style.display='none';

document.getElementById('otrascondiciones2').style.display='none';
document.getElementById('otrascondiciones3').style.display='none';

//document.getElementById('otrascondiciones1').style.display='block';

if(opcionSeleccionada>0)
{
//alert('holaopcion'+opcionSeleccionada);
document.getElementById('otrascondiciones1').style.display='none';
cargalistado('0',''+t,'user='+userb+' and vehiculo='+opcionSeleccionada+' '+otrascondiciones);
}
if(opcionSeleccionada==0)
{
cargalistado('0',''+t,'user='+userb+' '+otrascondiciones);
document.getElementById('busca2').style.display='none';
document.getElementById('otrascondiciones1').style.display='block';
}
}


if(posicionSelectDestino=='2')
{
if(opcionSeleccionada>0)
cargalistado('0',''+t,'user='+userb+' and marca='+opcionSeleccionada+' '+otrascondiciones);

if(opcionSeleccionada==0)
{
var selectOrigenvehiculo=document.getElementById('busca1');
var opcionSeleccionadavehiculo=selectOrigenvehiculo.options[selectOrigenvehiculo.selectedIndex].value;
cargalistado('0',''+t,'user='+userb+' and vehiculo='+opcionSeleccionadavehiculo+' '+otrascondiciones);
}


if(opcionSeleccionada==0)
document.getElementById('busca3').style.display='none';
document.getElementById('otrascondiciones1').style.display='none';
}

if(posicionSelectDestino=='3')
{

if(opcionSeleccionada==0)
{
var selectOrigenmarca=document.getElementById('busca2');
var opcionSeleccionadamarca=selectOrigenmarca.options[selectOrigenmarca.selectedIndex].value;
cargalistado('0',''+t,'user='+userb+' and marca='+opcionSeleccionadamarca+' '+otrascondiciones);
}


if(opcionSeleccionada>0)
cargalistado('0',''+t,'user='+userb+' and modelo='+opcionSeleccionada+' '+otrascondiciones);
document.getElementById('otrascondiciones2').style.display='none';
document.getElementById('otrascondiciones3').style.display='block';
}

		//alert('hola1');

	if(opcionSeleccionada==0)
	{
		var x=posicionSelectDestino, selectActual=null;
		// Busco todos los selects siguientes al que inicio el evento onChange y les cambio el estado y deshabilito
		while(buscaSelects[x])
		{
			selectActual=document.getElementById(buscaSelects[x]);
			selectActual.length=0;
			
			var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Selecciona Opci&oacute;n...";
			selectActual.appendChild(nuevaOpcion);	selectActual.disabled=true;
			x++;
		}
	}
	// Compruebo que el select modificado no sea el ultimo de la cadena//
	else 
	if(idSelectOrigen!=buscaSelects[buscaSelects.length-1])
	{
		// Obtengo el elemento del select que debo cargar
		var idSelectDestino=buscaSelects[posicionSelectDestino];
		var selectDestino=document.getElementById(idSelectDestino);
		
		//alert('hola2');


		
		// Creo el nuevo objeto AJAX y envio al servidor el ID del select a cargar y la opcion seleccionada del select origen 
		var ajax=nuevoAjax();
		ajax.open("GET", "buscador_proceso.php?select="+idSelectDestino+"&opcion="+opcionSeleccionada+"&userb="+userb+"&t="+t+"&otrascondiciones="+otrascondiciones, true);
		ajax.onreadystatechange=function() 
		{ 


		    if (ajax.readyState==1)
			{
			

if(posicionSelectDestino=='1')var caya=document.getElementById('dmb');
if(posicionSelectDestino=='2')var caya=document.getElementById('ddb');
				
				caya.length=0;
				var no=document.createElement("div"); 
				no.value=0; 
				no.innerHTML="<img src='b/al.gif'> Por favor espere....";
				caya.appendChild(no); 

			}


			if (ajax.readyState==4)
			{
				selectDestino.parentNode.innerHTML=ajax.responseText;
			} 
		}
		ajax.send(null);
	}

//cargalistado('0','0','0');
}
