	_scrollTop=0;
	_scrollLeft=0;
	var _Ajax=Ajax_Object();
	var _Ajax1=Ajax_Object();	
	


/************JORGE ESTUDIAMOS EL FORMULARIO Y MANDAMOS DATOS**************/
function prepara_datos(datos_pasados,tlf_casa,casa_provincia){

		parametros_tipo1='1#';
	
		for (i=0; i < datos_pasados.elements.length; i++) {
			parametros_tipo1=parametros_tipo1+datos_pasados.elements[i].value+'#';
		}
		parametros_tipo1=parametros_tipo1+tlf_casa+"#"+escape(casa_provincia);

	add_item_lista(parametros_tipo1);
}
/*************************************************************************/


	//-------------------------------------------------------------------------------------------------------------------
	//									ini: Funciones para las listas.
	//-------------------------------------------------------------------------------------------------------------------


	function _envia_mail()
	{
//		_capa_concept=document.getElementById('ajaxListas');
//		_capa_concept.innerHTML='&nbsp;&nbsp;<span id=\'fichas_txt_neg\' style=\'text-align:center; color:#FF0000; font-size=16px;\'><b>Enviando mail</b></span>';
		if (_Ajax.readyState==4) //control de estados del proceso
		{
			if(_Ajax.status==200) //si se da un status 200 (TERMINADO CON EXITO)
			{
				//alert(_Ajax.responseText);
				if(_Ajax.responseText=='')
					alert('No se ha podido enviar el mail');
				else if(_Ajax.responseText!='')
				{
					//_capa_concept.innerHTML=_Ajax.responseText;
					alert('mail enviado');
				}
			}
		}
	}	
	

	function envia_mail()
	{
		// Variables
		parametros='operacion=6';
		_values_send='id='+document.getElementById('id_favor_operador').value+'&'+parametros;
		//alert(_values_send);
		
		_URL_=fichero_gestion;
		_Ajax.open('POST',_URL_,true);
		_Ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		_Ajax.send('&'+_values_send); //enviar variables
		_Ajax.onreadystatechange=_envia_mail;			
	}		



	function _ver_lista()
	{
		_capa_concept=document.getElementById('ajaxListas');
		_capa_concept.innerHTML='<img align="middle"  src="http://www.ruralgest.net/operadoresV2_pruebas/modulos/favoritos/images/opcion_2.gif" width="181" height="44" />';

		
		if (_Ajax.readyState==4) //control de estados del proceso
		{
			if(_Ajax.status==200) //si se da un status 200 (TERMINADO CON EXITO)
			{
				if(_Ajax.responseText=='')
					alert('No se ha podido crear su lista de casas.');
				else if(_Ajax.responseText!='')
				{
					respuestaAjax=_Ajax.responseText.split("|*");
					_capa_concept.innerHTML=respuestaAjax[0];								

					//Mostramos u ocultamos los favoritos.
					if(respuestaAjax[2]==1)
					{
						document.getElementById("capa_favoritos").style.left=respuestaAjax[3];
						document.getElementById("capa_favoritos").style.top=respuestaAjax[4];						
						document.getElementById("capa_favoritos").style.visibility="visible";
						document.body.scrollTop=_scrollTop;
						document.body.scrollLeft=_scrollLeft;
					}
					else
						document.getElementById("capa_favoritos").style.visibility="hidden";		
					//document.getElementById('ajaxNombreLista').innerHTML=respuestaAjax[1];
				}
			}
		}
	}	

	function ver_lista()
	{
		if(_Ajax.status!=200)
			return 0;

			
		document.getElementById("capa_favoritos").style.visibility="visible";				
		var id_lista_sel=document.getElementById('id_lista_sel').value;
		//Para q se qde seleccionada el primer elemento de los favoritos al cargar
		if(id_lista_sel=="") 
			id_lista_sel=document.getElementById('id_lista_sel').value=0;

		var pos_x=document.getElementById("capa_favoritos").style.left;
		var pos_y=document.getElementById("capa_favoritos").style.top;
		parametros='operacion=1&id_lista_sel='+id_lista_sel+"&pos_x="+pos_x+"&pos_y="+pos_y;


		_values_send='id='+document.getElementById('id_favor_operador').value+'&'+parametros;
		//alert(_values_send);
		
		_URL_=fichero_gestion;
		_Ajax.open('POST',_URL_,true);
		_Ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		_Ajax.send('&'+_values_send); //enviar variables
		_Ajax.onreadystatechange=_ver_lista;			
	}		




	function _ocultar_lista()
	{
		
		if (_Ajax.readyState==4) //control de estados del proceso
		{
			if(_Ajax.status==200) //si se da un status 200 (TERMINADO CON EXITO)
			{
				if(_Ajax.responseText=='')
					alert('No se ha podido ocultar las listas.');
				else if(_Ajax.responseText!='')
				{
//					document.getElementById("capa_favoritos").style.visibility="hidden";		
				}
			}
		}
	}	

	function ocultar_lista()
	{
		if(_Ajax.status!=200)
			return 0;
		
		parametros='operacion=7';
		_values_send='id='+document.getElementById('id_favor_operador').value+'&'+parametros;
		document.getElementById("capa_favoritos").style.visibility="hidden";		
		
		_URL_=fichero_gestion;
		_Ajax.open('POST',_URL_,true);
		_Ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		_Ajax.send('&'+_values_send); //enviar variables
		_Ajax.onreadystatechange=_ocultar_lista;			
	}		


	function _mostrar_prim_vez()
	{
		try
		{
			_capa_concept=document.getElementById('ajaxListas');
			_capa_concept.innerHTML='<img align="middle"  src="http://www.ruralgest.net/operadoresV2_pruebas/modulos/favoritos/images/opcion_2.gif" width="181" height="44" />';
			if (_Ajax.readyState==4) //control de estados del proceso
			{
				if(_Ajax.status==200) //si se da un status 200 (TERMINADO CON EXITO) 
				{
					if(_Ajax.responseText=='')
						alert('No se ha podido ocultar las listas.');
					else if(_Ajax.responseText!='')
					{
						var respuesta_ajax=_Ajax.responseText.split("|*");
						if(respuesta_ajax[0]==1)
						{
							document.getElementById("id_lista_sel").value=respuesta_ajax[1];
							ver_lista();
						}
						else if(respuesta_ajax[0]==0)
						{
							ocultar_lista();
						}
	
	//					else
	//						alert("no se ha devuelto ninguna informacion. Error al mostrar la primera vez");
					}
				}
			}
		} // Tray
		catch(e)
		{
			//alert('Fallo => _mostrar_prim_vez()');
		}
	}	

	function mostrar_prim_vez()
	{
		parametros='operacion=8';
		_values_send='id='+document.getElementById('id_favor_operador').value+'&'+parametros;

		_URL_=fichero_gestion;
		_Ajax.open('POST',_URL_,true);
		_Ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		_Ajax.send('&'+_values_send); //enviar variables
		_Ajax.onreadystatechange=_mostrar_prim_vez;		 	
	}	

	function _add_lista()
	{
		try
		{
		
			_capa_concept=document.getElementById('ajaxListas');
			_capa_concept.innerHTML='<img align="middle"  src="http://www.ruralgest.net/operadoresV2_pruebas/modulos/favoritos/images/opcion_2.gif" width="181" height="44" />';
			if (_Ajax.readyState==4) //control de estados del proceso
			{
				if(_Ajax.status==200) //si se da un status 200 (TERMINADO CON EXITO)
				{
					if(_Ajax.responseText=='')
						alert('No se ha podido crear su lista de casas.');
					else if(_Ajax.responseText!='')
					{
						//_capa_concept.innerHTML=_Ajax.responseText;
						respuestaAjax=_Ajax.responseText.split("|*");
						document.getElementById('id_lista_sel').value=respuestaAjax[0];					
					//	document.getElementById('ajaxNombreLista').innerHTML=respuestaAjax[1];
						ver_lista();
					}
				}
			}
		}
		catch (e)
		{	
			alert("no se pudo generar la nueva lista");
		}
	}	

	function add_lista()
	{
		if(_Ajax.status!=200)
			return 0;
		
		var nombre_lista = prompt('Introduce un nombre para la lista de casas','');		
		if(nombre_lista==null) return 0;
		// Variables
		//alert(nombre_lista);
		parametros='operacion=2&nombre_lista='+escape(nombre_lista);
		_values_send='id='+document.getElementById('id_favor_operador').value+'&'+'id='+document.getElementById('id_favor_operador').value+'&'+parametros;
		_URL_=fichero_gestion;
		_Ajax.open('POST',_URL_,true);
		_Ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		_Ajax.send('&'+_values_send); //enviar variables
		_Ajax.onreadystatechange=_add_lista;		
		
		
		
	}	
	
	
	
	
	function _del_lista()
	{
		_capa_concept=document.getElementById('ajaxListas');
		_capa_concept.innerHTML='<img align="middle"  src="http://www.ruralgest.net/operadoresV2_pruebas/modulos/favoritos/images/opcion_2.gif" width="181" height="44" />';
		if (_Ajax.readyState==4) //control de estados del proceso
		{
			if(_Ajax.status==200) //si se da un status 200 (TERMINADO CON EXITO)
			{
				if(_Ajax.responseText=='')
					alert('No se ha podido crear su lista de casas.');
				else if(_Ajax.responseText!='')
				{
					document.getElementById('id_lista_sel').value=_Ajax.responseText;
					//_capa_concept.innerHTML=_Ajax.responseText;
					ver_lista();
				}
			}
		}
	}	

	function del_lista()
	{
		if(_Ajax.status!=200)
			return 0;
		
		parametros='operacion=3&id_lista='+document.getElementById('id_lista_sel').value;
		_values_send='id='+document.getElementById('id_favor_operador').value+'&'+parametros;
		//alert(_values_send);
		
		_URL_=fichero_gestion;
		_Ajax.open('POST',_URL_,true);
		_Ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		_Ajax.send('&'+_values_send); //enviar variables
		_Ajax.onreadystatechange=_del_lista;			
	}	
		
	//-------------------------------------------------------------------------------------------------------------------
	//									fin: Funciones para las listas.
	//-------------------------------------------------------------------------------------------------------------------



	//-------------------------------------------------------------------------------------------------------------------
	//									ini: Funciones para los itmes de las listas.
	//-------------------------------------------------------------------------------------------------------------------


	function ver_item_lista(cual)
	{
		if(_Ajax.status!=200)
			return 0;
		
		// Variables
		document.getElementById('id_lista_sel').value=cual;
		parametros='operacion=1&id_lista_sel='+document.getElementById('id_lista_sel').value;		
		_values_send='id='+document.getElementById('id_favor_operador').value+'&'+parametros;
		//alert(_values_send);
		
		_URL_=fichero_gestion;
		_Ajax.open('POST',_URL_,true);
		_Ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		_Ajax.send('&'+_values_send); //enviar variables
		_Ajax.onreadystatechange=_ver_lista;			
	}	




	function _add_item_lista()
	{
		_capa_concept=document.getElementById('ajaxListas');
		_capa_concept.innerHTML='<img align="middle"  src="http://www.ruralgest.net/operadoresV2_pruebas/modulos/favoritos/images/opcion_2.gif" width="181" height="44" />';
		if (_Ajax.readyState==4) //control de estados del proceso
		{
			if(_Ajax.status==200) //si se da un status 200 (TERMINADO CON EXITO)
			{
				if(_Ajax.responseText=='')
					alert('No se ha podido crear su casa.');
				else if(_Ajax.responseText!='')
				{
					_capa_concept.innerHTML=_Ajax.responseText;
					ver_lista();
							
				}
			}
		}
	}	



	function add_item_lista(parametros)
	{
		if(_Ajax.status!=200)
			return 0;
		
		_scrollTop=	document.body.scrollTop;
		_scrollLeft=document.body.scrollLeft;
		if(document.getElementById('id_lista_sel').value=='')
		{
			//alert('Para aņadir un nuevo elemento debe haber una lista seleccionada');
			//return 0;
			document.getElementById('id_lista_sel').value=0;
		}
		_values_send='id='+document.getElementById('id_favor_operador').value+'&'+'operacion=4&id_lista_sel='+document.getElementById('id_lista_sel').value+'&nombre_item_lista='+escape(parametros);
		
		_URL_=fichero_gestion;
		_Ajax.open('POST',_URL_,true);
		_Ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		_Ajax.send('&'+_values_send); //enviar variables
		_Ajax.onreadystatechange=_add_item_lista;	
		
		document.body.scrollTop=_scrollTop;
		document.body.scrollLeft=0;		
	}	
	

	
	function _del_lista_item()
	{
		_capa_concept=document.getElementById('ajaxListas');
		_capa_concept.innerHTML='<img align="middle"  src="http://www.ruralgest.net/operadoresV2_pruebas/modulos/favoritos/images/opcion_2.gif" width="181" height="44" />';
		if (_Ajax.readyState==4) //control de estados del proceso
		{
			if(_Ajax.status==200) //si se da un status 200 (TERMINADO CON EXITO)
			{
				if(_Ajax.responseText=='')
					alert('No se ha podido borrar el elemento. Intentelo de nuevo.');
				else if(_Ajax.responseText!='')
				{
					_capa_concept.innerHTML=_Ajax.responseText;
					ver_lista();
				}
			}
		}
	}	

	function del_lista_item(id_item,pos_item)
	{
		if(_Ajax.status!=200)
			return 0;
		
		// Variables
		parametros='operacion=5&id_lista_sel='+document.getElementById('id_lista_sel').value+'&id_item_lista='+id_item+'&pos_item='+pos_item;		
		_values_send='id='+document.getElementById('id_favor_operador').value+'&'+parametros;
		
		_URL_=fichero_gestion;
		_Ajax.open('POST',_URL_,true);
		_Ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		_Ajax.send('&'+_values_send); //enviar variables
		_Ajax.onreadystatechange=_del_lista_item;			
	}		
	//-------------------------------------------------------------------------------------------------------------------
	//									fin: Funciones para los itmes de las listas.
	//-------------------------------------------------------------------------------------------------------------------





	function _guardar_posicion()
	{
		try
		{
			if (_Ajax1.readyState==4) //control de estados del proceso
			{
				if(_Ajax1.status==200) //si se da un status 200 (TERMINADO CON EXITO)
				{
					if(_Ajax1.responseText=='')
						alert('No se ha podido ocultar las listas.');
					else if(_Ajax1.responseText!='')
					{
						var nada="nada";
						//document.getElementById("capa_favoritos").style.visibility="hidden";		
					}
				}
			}
		} 
		catch (e)
		{	
			//alert('BUENOOOOO!!');
		}
	}	

	function guardar_posicion()
	{
		if(_Ajax.status!=200)
			return 0;
		
		if(document.getElementById("capa_favoritos").style.visibility=="hidden")
			return 0;

		__pos_x=document.getElementById("capa_favoritos").style.left;
		__pos_y=document.getElementById("capa_favoritos").style.top;		
		parametros='operacion=9&pos_x='+__pos_x+'&pos_y='+__pos_y;
		_values_send='id='+document.getElementById('id_favor_operador').value+'&'+parametros;
		//alert(_values_send);
		
		_URL_=fichero_gestion;
		_Ajax1.open('POST',_URL_,true);
		_Ajax1.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		_Ajax1.send('&'+_values_send); //enviar variables
		_Ajax1.onreadystatechange=_guardar_posicion;	
	}		




	
	function clavar(obj, posic)
	{
alert("este mensaje no deberia aparecer. funcion clavar");		
		dObj =document.getElementById(obj);
alert(dObj);		
		dObj.style.top = document.documentElement.scrollTop+10+"px";
	}	
	
	
	function borrar_lista(cual)
	{
		alert("esto no vale para nada. borrar");
		alert(cual.name);
	}	
	
	window.onscroll=function()
	{
		if (bloqueo_far==0)
		{
			var pos_y=document.getElementById("capa_favoritos");	
			pos_y.style.top=eval(document.body.scrollTop)+30;
		}
	
	}


