// JavaScript Document

var xmlHttp;
var tipo;

function createXMLHttpRequest() 
{
	var req;
	if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
	req = new XMLHttpRequest();
	}
	return req;
}

function comparar(flag)
{  
	var sexo=sexo_2=para="";
		
	if(document.getElementById("SH").checked){sexo="H"}
	else{sexo="M";}
	
	if(document.getElementById("BM").checked){sexo_2="M"}
	else{sexo_2="H";}
	
	if(document.getElementById("RE").checked){para="R"}
	else if(document.getElementById("SE").checked){para="A"}
	else{para="C";}
    
	xmlHttp= createXMLHttpRequest();	
	xmlHttp.open("GET","http://www.solterosenlared.es/xml/xml_comparador.php?soy="+sexo+"&busco="+sexo_2+"&para="+para+"&flag="+flag,true);	
	xmlHttp.onreadystatechange = function()
	{
    	Insertar_Contenido(xmlHttp);
	}
	xmlHttp.send(null);	
}

function Insertar_Contenido(a)
{
	if(a.readyState == 4)
	{
		if(a.status == 200)
		{	 
		   var texto=a.responseText;
		   limpiarGeneral("poner");
		   document.getElementById("tabla_botones").style.visibility="visible";
		   document.getElementById("tabla_botones_2").style.visibility="visible";
		   var element=document.getElementById("poner").innerHTML = texto;
		}
	    else 
	    {
		 	alert("Error");	
        }
	}
}

function limpiar()
{
	xmlHttp= createXMLHttpRequest();	
	xmlHttp.open("GET","http://www.solterosenlared.es/xml/xml_banner.php",true);	
	xmlHttp.onreadystatechange = function()
	{
    	Insertar_banner(xmlHttp);
	}
	xmlHttp.send(null);	
}

function Insertar_banner(a)
{
	if(a.readyState == 4)
	{
		if(a.status == 200)
		{	 
		  	  
		   var texto=a.responseText;
		   limpiarGeneral("poner");
		   document.getElementById("tabla_botones").style.visibility="hidden";	
		   document.getElementById("tabla_botones_2").style.visibility="hidden";	
		   var element=document.getElementById("poner").innerHTML = texto;
		}
	    else 
	    {
		 	alert("Error");	
        }
	}
}

function limpiarGeneral(id_tag)
{
   limpiarTextNodo(document.getElementById(id_tag));
}

function limpiarTextNodo(nodo)
{
	while(nodo.hasChildNodes())
      nodo.removeChild(nodo.firstChild);
}

function armarNumero(numero)
{
	 var new_numero="";
	 for(i=0; i<numero.length; i++)
	 {
        if(numero.charAt(i)!= ',')
		{ 
		  new_numero=new_numero+numero.charAt(i);
		}
   }
   return new_numero;
}

function ver_check_seleccionado()
{
	var checkboxes = document.getElementsByName("checkbox");	
	var cont = 0;     
    for (var x=0; x < checkboxes.length; x++) 
	{
    	if (checkboxes[x].checked) {cont++;}
    }
	return cont;
}

function check_quitar(id)
{	
  document.getElementById(id).checked=false;
}

function contar_check(id)
{
	if(chk_select = ver_check_seleccionado()==5)
	{
	   alert("Solo puedes comparar 4 sitios");
	   check_quitar(id);
	}	
}

function comparar_sitio()
{
	var checkboxes = document.getElementsByName("checkbox");
	var id="", cont=0;
	
	for (var x=0; x < checkboxes.length; x++) 
	{
    	if (checkboxes[x].checked) 
		{
			if(cont != 0){id = id + ",";}
			id  = id + checkboxes[x].value ;
			cont++;
		}
    }
	if(cont != 0){
		document.location.href="http://www.solterosenlared.es/comparador.php?flag="+id; 
		//document.location.href="comparador.php?flag="+id; 
	}
	else{ alert("Escoja un sitio para comparar");}
}

function mostrar_informacion(id)
{  
	xmlHttp= createXMLHttpRequest();	
	xmlHttp.open("GET","http://www.solterosenlared.es/xml/xml_informacion.php?id="+id,true);	
	xmlHttp.open("GET","xml/xml_informacion.php?id="+id,true);	
	xmlHttp.onreadystatechange = function()
	{
    	Insertar_Informacion(xmlHttp);
	}
	xmlHttp.send(null);	
}

function Insertar_Informacion(a)
{
	if(a.readyState == 4)
	{
		if(a.status == 200)
		{	 
		  	  
		   var texto=a.responseText;
		   limpiarGeneral("informacion");		
		   var element=document.getElementById("informacion").innerHTML = texto;
		}
	    else 
	    {
		 	alert("Error");	
        }
	}
}

function verEmpresa(id,flag)
{

	if(id != "")
	{		
		if(flag==2)
		{
			xmlHttp= createXMLHttpRequest();	
			xmlHttp.open("GET","http://www.solterosenlared.es/xml/xml_info_modificar.php?id="+id,true);
			xmlHttp.onreadystatechange = function()
			{
				Insertar_Informacion_Empresa(xmlHttp);
			}
			xmlHttp.send(null);	
			
		}
		if(flag==1)
		{
		    document.forms["frm_registro"].action="registrar_empresa_actualizacion.php?id="+id;
            document.forms["frm_registro"].submit();		  	 
		}
		
		
	}
}

function Insertar_Informacion_Empresa(a)
{
	if(a.readyState == 4)
	{
		if(a.status == 200)
		{	 
		  	  
		   var texto=a.responseText;
		   limpiarGeneral("tabla_empresa");		
		   var element=document.getElementById("tabla_empresa").innerHTML = texto;
		}
	    else 
	    {
		 	alert("Error");	
        }
	}
}
