function validacionIntercambio(webId) 
{

  var caja = document.getElementById("intercambio"+webId);
  var actual =  caja.innerHTML;

  var peticion_http = null;
  // Obtener la instancia del objeto XMLHttpRequest
  if(window.XMLHttpRequest) {
    peticion_http = new XMLHttpRequest();
  }
  else if(window.ActiveXObject) {
    peticion_http = new ActiveXObject("Microsoft.XMLHTTP");
  }
 
  // Preparar la funcion de respuesta
  peticion_http.onreadystatechange = muestraContenido;
 
  // Realizar peticion HTTP
  peticion_http.open('GET', '/validacionIntercambio.php?id='+webId, true);
  peticion_http.send(null);
 
  function muestraContenido() 
  {
  
   /* if(peticion_http.readyState == 1)
    {
        //document.getElementById(webId).innerHTML="<img src='/imagenes/loading.gif' alt='cargando...' />";
		
    }
	*/
    if(peticion_http.readyState == 4) 
    {
      if(peticion_http.status == 200) 
     {


        if(peticion_http.responseText == 0)
        {

           
			caja.style.display="block";
			caja.innerHTML= "<b>Esta web aún no participa en el sistema NUEVO widget de intercambio de banners !</b>.<br>A que esperas para que tu web aparezca en cientos de webs.<br> Entra en la ficha de esta web y copia el código del widget de intercambio de banners";


        }
        else if(peticion_http.responseText != 1)
        {

            caja.innerHTML= "No se ha podido comprobar si esta web tiene el cajetín de intercambio de banners. El administrador lo revisará en breve.";
			caja.style.display="block";

        }
      }
    }
  }
}

function validacion(elementId,webId) 
{
  var actual = document.getElementById(elementId).innerHTML;
  var peticion_http = null;
  // Obtener la instancia del objeto XMLHttpRequest
  if(window.XMLHttpRequest) {
    peticion_http = new XMLHttpRequest();
  }
  else if(window.ActiveXObject) {
    peticion_http = new ActiveXObject("Microsoft.XMLHTTP");
  }
 
  // Preparar la funcion de respuesta
  peticion_http.onreadystatechange = muestraContenido;
 
  // Realizar peticion HTTP
  peticion_http.open('GET', '/validacion/'+webId, true);
  peticion_http.send(null);
 
  function muestraContenido() 
  {
  
    if(peticion_http.readyState == 1)
    {
        document.getElementById(elementId).innerHTML="<img src='/imagenes/loading.gif' alt='cargando...' />";
		
    }
    if(peticion_http.readyState == 4) 
    {
      if(peticion_http.status == 200) 
     {



        if(peticion_http.responseText == 1)
        {

            document.getElementById(elementId).innerHTML= "";


        }
        else if(peticion_http.responseText == 0)
        {

			document.getElementById(elementId).innerHTML= "Sin Validar !";
			document.getElementById("noValidadaError").style.display="block";
			document.getElementById("c"+webId).className +=" errorBlock";
			document.getElementById("visita"+webId).style.display="none";


        }
        else if(peticion_http.responseText == 2)
        {

			document.getElementById(elementId).innerHTML= "Invalidada";
			document.getElementById("noValidaError").style.display="block";
			document.getElementById("suberror"+webId).innerHTML = "Web invalidada.";
			document.getElementById("c"+webId).className +=" errorBlock";
			document.getElementById("visita"+webId).style.display="none";


        }
        else if(peticion_http.responseText == -1)
        {

            document.getElementById(elementId).innerHTML= "Web no registrada";


        }
        else
        {

			document.getElementById(elementId).innerHTML= "Error conexión";
			document.getElementById("problemasConexionError").style.display="block";

        }
      }
    }
  }
}







function controlVisitasPerfil(elementId,webId) 
{
  var actual = document.getElementById(elementId).innerHTML;
  var peticion_http = null;
  // Obtener la instancia del objeto XMLHttpRequest
  if(window.XMLHttpRequest) {
    peticion_http = new XMLHttpRequest();
  }
  else if(window.ActiveXObject) {
    peticion_http = new ActiveXObject("Microsoft.XMLHTTP");
  }
 
  // Preparar la funcion de respuesta
  peticion_http.onreadystatechange = muestraContenido;
 
  // Realizar peticion HTTP
  peticion_http.open('GET', '/controlVisitas/'+webId, true);
  peticion_http.send(null);
 
  function muestraContenido() 
  {
  
    if(peticion_http.readyState == 1)
    {
        document.getElementById(elementId).innerHTML="<img src='/imagenes/loading.gif' alt='cargando...' />";
		
    }
    if(peticion_http.readyState == 4) 
    {
      if(peticion_http.status == 200) 
     {

        if(peticion_http.responseText <0)
        {

            document.getElementById(elementId).innerHTML= "Error";

        }
        if(peticion_http.responseText ==0)
        {

            document.getElementById(elementId).innerHTML= actual;
        }
        if(peticion_http.responseText >0)
        {

           cuentaAtrasVisitas(peticion_http.responseText,elementId);
        }
		
      }
    }
  }
}


//DEFINICIONES GLOBALES DE CONFIGURACION
var speed=1000;





//FUNCION UTILIZADA EN EL CONTENIDO DE LA PAGINA DE VISITAS

function cuentaAtrasVisitas(count,elementId)
{
	

	
		if(count>0)
		{
			

			if(count>60)
					{
						if( count>=3600)
						{
							
							var horas = (count/3600) | 0;
							var minutos =  ((count%3600) / 60 ) | 0;
							var segundos = (count%3600) % 60 ;
						}
						else
						{
							
							var horas = 0;
							var minutos=(count/60) | 0; //esto es un casting a entero
							var segundos=count%60;
						}
						/*	alert("horas  "+horas);
														alert("minutos  "+minutos);
																					alert("segundos  "+segundos);

*/
						if(segundos<10)
						{
							segundos = "0"+segundos;
						}
						if(minutos<10)
						{
							minutos = "0"+minutos;
							
							
						}							
						
								document.getElementById(elementId).innerHTML ="5L: "+horas+":"+minutos+":"+segundos;
		

					}
					else
					{
					//document.getElementById("timer").innerHTML = "&nbsp;5links en "+count+"s";
					
							document.getElementById(elementId).innerHTML ="5links en: "+count+"s";
						
					}
					count--;
					window.setTimeout("cuentaAtrasVisitas("+count+",'"+elementId+"')",1000);			
			
			
			
			
			
			
			
			
			
		}
		else if (count <= 0)
		{
			window.location.reload(true);
		}
		
}




