function mostrar(div)
	{   
	var el = document.getElementById(div); //se define la variable "el" igual a nuestro div
	el.style.display = (el.style.display == 'none') ? 'block' : 'none'; //damos un atributo display:none que oculta el div
	}

function enterkeypress(e)
	{
	var key=(document.all) ? e.keyCode : e.which;
	if (key==13) { process();}
	}

function process()
	{
	var val=document.frmform.s.value;
	if (val !="Busca juegos aqui.")
		{
		if (val.length>2)
			{
	 		document.frmform.submit(); 	
	 		}
		} 
	}

function resettext(text)
	{
	if (text=="Busca juegos aqui.")
		{ document.getElementById('s').value=""; }
	}
	
function ValidateUrl(variableurl) { 
    var v = new RegExp(); 
    v.compile("^[A-Za-z]+://+$"); 
    if (!v.test(variableurl)) { 
          return false;
    } else  {   return true; }
} 


function validateEmail(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
 
var splitted = email.match("^(.+)@(.+)$");
if(splitted == null) return false;
if(splitted[1] != null )
{
var regexp_user=/^\"?[\w-_\.]*\"?$/;
if(splitted[1].match(regexp_user) == null) return false;
}
if(splitted[2] != null)
{
var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
if(splitted[2].match(regexp_domain) == null) 
{
var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
if(splitted[2].match(regexp_ip) == null) return false;
}// if
return true;
}
return false;
}	
	
function validar_registro(){    
var accs=1;
	if(!validateEmail(document.FormValidacion.email.value) & accs!=0){
		alert("Debe ingresar email correcto.");
		document.FormValidacion.email.focus();  
		accs=0;
		}  
 	if (document.FormValidacion.password.value<=5 & accs!=0){
		alert("Debes ingresar su contraseņa mayor a 5 caracteres.");
		document.FormValidacion.password.focus();  
		accs=0;
		}
 	if (document.FormValidacion.password.value!=document.FormValidacion.password2.value & accs!=0){
		alert("Debes ingresar contraseņas identicas.");
		document.FormValidacion.password2.focus();  
		accs=0;
		}
  	if (document.FormValidacion.nombre.value<=3 & accs!=0){
		alert("Debes ingresar su nick.");
		document.FormValidacion.nombre.focus();  
		accs=0;
		}
		
 	if (accs==1) { document.FormValidacion.submit(); }
	}	
	
function validar_mod3(){  
	var accs=1;
	if (document.formtres.password2.value<=5 & accs!=0){
		alert("Debes ingresar su contraseņa mayor a 5 caracteres.");
		document.formtres.password2.focus();  
		accs=0;
		}
 	if (accs==1) { document.formtres.submit(); }

	}
	
	
function validar_contacto(){  
	var accs=1;
	if (document.frmcontact.asunto.value=="" & accs!=0){
		alert("Debes ingresar asunto.");
		document.frmcontact.asunto.focus();  
		accs=0;
		}
	if (document.frmcontact.asuntotext.value=="" & accs!=0){
		alert("Debes ingresar texto del asunto.");
		document.frmcontact.asuntotext.focus();  
		accs=0;
		}
	if (document.frmcontact.nombre.value=="" & accs!=0){
		alert("Debes ingresar su nombre o de la empresa.");
		document.frmcontact.nombre.focus();  
		accs=0;
		}
	if (document.frmcontact.email.value=="" & accs!=0){
		alert("Debes ingresar su email.");
		document.frmcontact.email.focus();  
		accs=0;
		}		
	if (document.frmcontact.mensaje.value=="" & accs!=0){
		alert("Debes ingresar su mensaje.");
		document.frmcontact.mensaje.focus();  
		accs=0;
		}		
 	if (accs==1) { document.frmcontact.submit(); }

	}
	
function validar_intercambio(){    
var accs=1;
	if (document.formulario.link.value=="" & accs!=0){
		alert("Debes ingresar link.");
		document.formulario.link.focus();  
		accs=0;
		}
	if (document.formulario.anchor.value=="" & accs!=0){
		alert("Debes ingresar Nombre /anchor.");
		document.formulario.anchor.focus();  
		accs=0;
		}		
	if (!validateEmail(document.formulario.email.value)	 & accs!=0){
		alert("Debes ingresar su email");
		document.formulario.anchor.focus();  
		accs=0;
		}	
 
	
	if (accs==1) { document.formulario.submit();}
	}
	
	
function validar_recordar(){  
	var accs=1;
	if (document.frmrecordar.email.value=="" & accs!=0){
		alert("Debes ingresar su email.");
		document.frmrecordar.email.focus();  
		accs=0;
		}
	if (document.frmrecordar.validacion.value=="" & accs!=0){
		alert("Debes ingresar codigo.");
		document.frmrecordar.validacion.focus();  
		accs=0;
		}
 	if (accs==1) { document.frmrecordar.submit(); }
	}
	
	
function validar_comentario(){    
var accs=1;

  	if (document.frmcomt.comentario.value.length<=10 & accs!=0){
		alert("Debes ingresar su comentario mayor a 10 letras.");
		document.frmcomt.comentario.focus();  
		accs=0;
		}
  	if (document.frmcomt.codehide.value!=document.frmcomt.code.value & accs!=0){
		alert("Codigo incorrecto.");
		document.frmcomt.code.focus();  
		accs=0;
		}		
 	if (accs==1) { document.frmcomt.submit(); }
	}
	
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) { xmlhttp=false; }
    }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); } 

    return xmlhttp; 
}

function listado(top){
	document.getElementById("contenido").innerHTML="<div align=\"center\"><br><br><br><br><br><img src=\"/images/loadingAnimation.gif\"  /><br><br></div>";
    ajax=nuevoAjax();
 
    ajax.open("GET", "/ajax_listado.php?top="+top+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)
        	{ document.getElementById("contenido").innerHTML=ajax.responseText; } 
    	}
    ajax.send(null); 
	}
 
 
var ajaxjuego=nuevoAjax();
var juegocargado=0;
var milisec=0; 
var seconds=10;
function display(){ 

 if (milisec<=0){ 
    milisec=9; 
    seconds-=1; 
 } 
 if (seconds<=-1){ 
    milisec=0; 
    seconds+=1; 
 } 
 else 
    milisec-=1; 
	if (juegocargado==1)
		{
		document.getElementById("loadercargando").style.display="none";
		document.getElementById("loadercargado").style.display="block";
		}	
	
if (seconds==0) 
	{  
	if (ajaxjuego.readyState==4)
		{
		document.getElementById("juego").style.display="block";
		document.getElementById("publijuego").style.display="none";
		}
	}
if (seconds!=0) { setTimeout("display()",100) }
} 



function cargajuego(id)
{
	display();

    ajaxjuego.open("GET", "/ajax_juego.php?idcont="+id+"&num_ale="+Math.random(), true);
	
    ajaxjuego.onreadystatechange=function() 
    {    
		if (ajaxjuego.readyState==4) 
			{ 
			document.getElementById("juego").innerHTML=ajaxjuego.responseText;  
			juegocargado=1; 
			} 
    }
    ajaxjuego.send(null);       
}

 function votar(idcont)
{
    document.getElementById("divvoto").innerHTML='Cargando...';
	ajax=nuevoAjax();
	ajax.open("GET", "/ajax_votar.php?idcont="+idcont+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    {   
    	if (ajax.readyState==4) { document.getElementById("divvoto").innerHTML=ajax.responseText;  } 
    }
    ajax.send(null);       
}
 
 function zoommas() { 
var  c=40;
var   ancho; var   alto;
ancho = document.getElementById("juegobjc").width; 
alto = document.getElementById("juegobjc").height; 
if (ancho <=900) {
ancho = c + parseInt(ancho);
alto = c + parseInt(alto);
document.getElementById("juegobjc").width=ancho; 
document.getElementById("juegobjc").height=alto;
//document.getElementById("divjuego").style.width=ancho; 
//document.getElementById("divjuego").style.height=alto;
}
}

function zoommenos() { 
var  c=40;
var   ancho; var   alto;
ancho = document.getElementById("juegobjc").width; 
alto = document.getElementById("juegobjc").height; 
if (ancho >=500) {
ancho = parseInt(ancho) - c;
alto =  parseInt(alto) - c;
document.getElementById("juegobjc").width=ancho; 
document.getElementById("juegobjc").height=alto;
//document.getElementById("divjuego").style.width=ancho; 
//document.getElementById("divjuego").style.height=alto;
}
}

function pantallacompleta() { 
var  c=900; var   ancho; var   alto; var   ratio; var   altura;
ancho = document.getElementById("juegobjc").width; 
alto = document.getElementById("juegobjc").height; 	
ratio = parseInt(ancho) / c; 
altura = parseInt(alto) / ratio; 	
document.getElementById("juegobjc").width=c; 
document.getElementById("juegobjc").height=altura;
//document.getElementById("divjuego").style.width=c; 
//document.getElementById("divjuego").style.height=altura;
}


function pantallanormal() { 

var ancho = document.getElementById('ancho').value;
var alto  = document.getElementById('alto').value;
document.getElementById("juegobjc").width=ancho; 
document.getElementById("juegobjc").height=alto;
 
}




function favorito(idcont){
 
 document.getElementById("favoritoslista").style.display='block';
  document.getElementById("divfavorito"+idcont+"").style.display='none';
  ajax=nuevoAjax();
  ajax.open("GET", "/inc_favoritos.php?idcont="+idcont+"&num_ale="+Math.random(), true);
  ajax.onreadystatechange=function() 
   {  
   if (ajax.readyState==1) { document.getElementById("favoritoslista").innerHTML='<div align="center">Cargando Favoritos...</div>';  } 
   if (ajax.readyState==4) { document.getElementById("favoritoslista").innerHTML=ajax.responseText;  }  }
    ajax.send(null);    
  }
  
  
 function favorito_eliminar(idcont,idfavorito){
	if(document.getElementById("divfavorito"+idcont+""))
			{
   			document.getElementById("divfavorito"+idcont+"").style.display='block';
			}
  mostrar("favoritoslista");
  ajax=nuevoAjax();
  ajax.open("GET", "/inc_favoritos.php?idcont="+idcont+"&idfavorito="+idfavorito+"&num_ale="+Math.random(), true);
  ajax.onreadystatechange=function() 
   {  
   if (ajax.readyState==1) { document.getElementById("favoritoslista").innerHTML='<div align="center">Cargando Favoritos...</div>';  } 
   if (ajax.readyState==4) { document.getElementById("favoritoslista").innerHTML=ajax.responseText;  }  }
    ajax.send(null);    
  } 
