function buscar_cil(valor,criterio,destino){
	var div_id = document.getElementById("contenidos");
	div_id.innerHTML="<label id=respuesta></label>";
	//alert(valor+','+criterio+','+destino);
	cargaContenido_usu('respuesta',valor,criterio,destino);

}	

function buscar(forma){
	var criterio = '';
	var destino  = '';
	var valor = forma.valor_bus.value;
	var div_id = document.getElementById("contenidos");
	div_id.innerHTML="<label id=respuesta></label>";
	
	if (!forma.criterio[0].checked && !forma.criterio[1].checked && !forma.criterio[2].checked){
		ShowAlert("¡¡ Selecciona un criterio de búsqueda !!");
		return false;
	}else if (valor == '' || valor == null || valor == ' '){
		ShowAlert("¡¡ Escribe el valor a buscar !!");
		return false;
	}else if (forma.criterio[0].checked){// si es 0 eligió buscar por número de registro
		criterio = 0;
		destino  = 'tarjeta'; 
		cargaContenido_usu('respuesta',valor,criterio,destino);
	}else if (forma.criterio[1].checked){// si es 1 eligió buscar por id de contrato
		criterio = 1;
		destino  = 'tarjeta'; 
		cargaContenido_usu('respuesta',valor,criterio,destino);
	}else if (forma.criterio[2].checked){// si es 2 eligió buscar por nombre del producto
		criterio = 2;
		destino  = 'busqueda'; 
		cargaContenido_usu('respuesta',valor,criterio,destino);
	}
	
	
	
	//window.open(destino+'.php?opcion='+criterio+'&valor='+valor,'mywindow','width=710,height=440')
	//forma.action="busqueda.php";
    //forma.submit();
    return true;
	
}

function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	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)
		{
			if (!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();
		}
	}
	return xmlhttp; 
}


function cargaContenido_usu(idDestino,valor,criterio,destino)
{//alert(idDestino+','+valor+','+criterio+','+destino);
	// Obtengo el elemento que debo cargar
	var selectDestino=document.getElementById(idDestino);
	// 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", "contrato_existente.php?valor="+valor+"&criterio="+criterio+"&destino="+destino, true);
	ajax.onreadystatechange=function() 
	{ //alert("destino"+idSelectDestino+", opcion"+opcionSeleccionada);
		if (ajax.readyState==1)
		{
			// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Buscando..."
			//selectDestino.length=0;
			//var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Buscando...";
			//selectDestino.appendChild(nuevaOpcion); selectDestino.disabled=true;	
		}
		if (ajax.readyState==4)
		{
			//selectDestino.parentNode.innerHTML=ajax.responseText;
			var ExecuteNow = ajax.responseText; 
			eval(ExecuteNow); 
		}
	}
	ajax.send(null)
}