var LOADING='<div align="center" style="padding:6px;"><img src="/images/loading.gif" border="0" align="middle" /></div>';

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 CreateBookmarkLink() {
titulo="Tatuajes21.com";
url="http://www.imagens21.com/";
if (window.sidebar) { // Mozilla Firefox 
window.sidebar.addPanel(titulo, url,"");
} else if( window.external ) { // IE 
window.external.AddFavorite( url, titulo); }
else if(window.opera && window.print) { // Opera
/**alert("Para agregar a tu pagina a sus favoritos presione control + D") }**/
window.external.AddFavorite( url, titulo); }
}
	
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,idcategoria){
	document.getElementById("list").innerHTML="<div align=\"center\"><br><br><br><br><br><img src=\"/images/loading.gif\" width=\"16\" height=\"16\" /><br><br></div>";
    ajax=nuevoAjax();
 
    ajax.open("GET", "/ajax_listado.php?top="+top+"&idcategoria="+idcategoria+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    	{ 
        if (ajax.readyState==4)
        	{ document.getElementById("list").innerHTML=ajax.responseText; } 
    	}
    ajax.send(null); 
	document.getElementById("paginador").style.display="none";
	}
 
 
 


 

 function votar(idimagen)
{
    document.getElementById("divvoto").innerHTML='Cargando...';
	ajax=nuevoAjax();
	ajax.open("GET", "/ajax_votar.php?idimagen="+idimagen+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    {   
    	if (ajax.readyState==4) { document.getElementById("divvoto").innerHTML=ajax.responseText;  } 
    }
    ajax.send(null);       
}

 


function favorito(idimagen){
 
 document.getElementById("favoritoslista").style.display='block';
  document.getElementById("divfavorito"+idimagen+"").style.display='none';
  ajax=nuevoAjax();
  ajax.open("GET", "/inc_favoritos.php?idimagen="+idimagen+"&num_ale="+Math.random(), true);
  ajax.onreadystatechange=function() 
   {  
   if (ajax.readyState==1) { document.getElementById("favoritoslista").innerHTML='<div align="center" style="font-size:11px;">Cargando Favoritos...</div>';  } 
   if (ajax.readyState==4) { document.getElementById("favoritoslista").innerHTML=ajax.responseText;  }  }
    ajax.send(null);    
  }
  
  
 function favorito_eliminar(idimagen,idfavorito){
	if(document.getElementById("divfavorito"+idimagen+""))
			{
   			document.getElementById("divfavorito"+idimagen+"").style.display='block';
			}
  mostrar("favoritoslista");
  ajax=nuevoAjax();
  ajax.open("GET", "/inc_favoritos.php?idimagen="+idimagen+"&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);    
  } 
  
   function cambiarpass(email,id){
 
  ajax=nuevoAjax();
  ajax.open("GET", "/ajax_contrasena.php?email="+email+"&id="+id+"&nueva=yes&num_ale="+Math.random(), true);
  ajax.onreadystatechange=function() 
   {  
    if (ajax.readyState==4) { document.getElementById("nuevacontrasena").innerHTML=ajax.responseText;  }  }
    ajax.send(null);    
  } 
 

function nombreenvia(datos){
 	document.getElementById("spanuser").innerHTML=datos;
	}
  
function mensajeimagen(datos){
 	document.getElementById("divtexto").innerHTML=datos.replace(/\n/g, '<br />');
 
	}
	
function validacion(){    
var accs=1;


	if (document.formulario.nombre_envia.value=="" & accs!=0){
		alert("Debes ingresar tu nombre.");
		document.formulario.nombre_envia.focus();  
		accs=0;
		}	
	if (document.formulario.email_envia.value=="" & accs!=0){
		alert("Debes ingresar tu email.");
		document.formulario.email_envia.focus();  
		accs=0;
		}	
	if(!validateEmail(document.formulario.email_envia.value) & accs!=0){
		alert("Debes ingresar Email correcto.");
		document.formulario.email_envia.focus();  
		accs=0;
		}  
 
	var registros = document.getElementById("cantidadregistros").value;
	var nombre 	= "";
	var email 	= "";
	for (i=1;i<registros;i++)
	 	{ 
		if (document.getElementById("nombre_recibe"+i).value!="" || document.getElementById("email_recibe"+i).value!="")	
			{
			nombre = document.getElementById("nombre_recibe"+i).value;
			email = document.getElementById("email_recibe"+i).value;

			if(!document.getElementById("nombre_recibe"+i).value & accs!=0)
				{
				alert("Debes ingresar nombre del destinatario.");	
				document.getElementById("nombre_recibe"+i).focus();  
				accs=0;
				}
			if(!validateEmail(email) & accs!=0)
				{
				alert("Debes ingresar Email correcto.");	
				document.getElementById("email_recibe"+i).focus();  
				accs=0;
				}
			}
		}

if (document.formulario.code.value=="" & accs!=0){
		alert("Debes ingresar el codigo de seguridad.");
		document.formulario.code.focus();  
		accs=0;
		}
 

	if (accs==1) { document.formulario.submit(); }
	}	
	
function nuevoregistro() {
	var registros = document.getElementById("cantidadregistros").value;
	var li = document.createElement('li');
if (registros<=5)
	{
	ajax=nuevoAjax();
 	ajax.open("GET", "/ajax_tabla.php?i="+registros+"&num_ale="+Math.random(), true);
  	ajax.onreadystatechange=function() 
   		{  
    	if (ajax.readyState==4) { li.innerHTML=ajax.responseText;  }  }
    ajax.send(null);    
  	 
	
	registros ++;	
	document.getElementById("cantidadregistros").value=registros;
	var ul = document.getElementById('listadoregistros');
	ul.appendChild(li);
	}
	else
	{
	document.getElementById("nuevoregistro").style.display="none";
	}
 
 
}
 
function eliminarmensaje()
	{
	var valor=document.getElementById("id").value;
 
	if (valor=="Ingrese su código") 
		{  
		alert ('asdasd');
		document.getElementById("id").value="";  }
 	}