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();}
	}

 mywindows=""; 
  function enviar (idcont) {
  var opciones="toolbar=no, statusbar=no, titlebar=no, location=no, directories=no, status=no, menubar=no,menubar=0, scrollbars=no, resizable=yes, width=500, height=400, left="+parseInt(((screen.width) / 2) - 250)+", top="+parseInt(((screen.height) / 2) - 200)+"";
  mywindows=window.open("/pop_enviar.php?idcont="+idcont+"","popup",opciones);

}

function process()
	{
	var val=document.frmform.s.value;
	if (val !="Busca poemas aqui.")
		{
		if (val.length>2)
			{
	 		document.frmform.submit(); 	
	 		}
		} 
	}

function resettext(text)
	{
	if (text=="Busca poemas 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.usuario.value<=3 & accs!=0){
		alert("Debes ingresar su nick.");
		document.FormValidacion.usuario.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.postals21.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(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 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" style="font-size:11px;">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);    
  } 
  
   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 footer_div()
 	{
 
	}

function nombreenvia(datos){
 	document.getElementById("spanuser").innerHTML=datos;
	}
  
function mensajepostal(datos){
 	document.getElementById("divtexto").innerHTML=datos.replace(/\n/g, '<br />');
	footer_div();
	}
	
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";
	}
 
	footer_div();
}
function mostrarfondos()
	{
	document.getElementById("fondos_hide").style.display="block";	 
  	ajaxfondo=nuevoAjax();
	document.getElementById("fondos_hide").innerHTML=LOADING;
  	ajaxfondo.open("GET", "/ajax_fondos.php", true);
  	ajaxfondo.onreadystatechange=function() 
  	 {  
   	 if (ajaxfondo.readyState==4) { document.getElementById("fondos_hide").innerHTML=ajaxfondo.responseText;  }  
	 }
  	ajaxfondo.send(null);  
	footer_div();	
	}
function cambiarfondo(valor)
	{
	document.getElementById("div_fondo").style.background="url('/imagenes_fondo/"+valor+"')";
	document.getElementById("postalenvio").style.background="url('/imagenes_fondo/"+valor+"')";
	document.getElementById("fondo").value=valor;
	document.getElementById("fondos_hide").style.display="none";
	footer_div();	
	}
function mostrarcolores()
	{
	document.getElementById("colores_hide").style.display="block";	 
  	ajaxcolores=nuevoAjax();
	document.getElementById("colores_hide").innerHTML=LOADING;
  	ajaxcolores.open("GET", "/ajax_colores.php", true);
  	ajaxcolores.onreadystatechange=function() 
  	 {  
   	 if (ajaxcolores.readyState==4) { document.getElementById("colores_hide").innerHTML=ajaxcolores.responseText;  }  
	 }
  	ajaxcolores.send(null);  
	footer_div();	
	}
function cambiarcolor(valor)
	{
 	document.getElementById("postalmensaje").style.color=valor;
 	document.getElementById("div_color").style.backgroundColor=valor;
 	document.getElementById("div_color").style.color=valor;	
 	document.getElementById("h3text").style.color=valor;	
 	document.getElementById("color").value=valor;
	document.getElementById("colores_hide").style.display="none";
	footer_div();	
	}
function mostrarsellos()
	{
	document.getElementById("sellos_hide").style.display="block";	 
  	ajaxsellos=nuevoAjax();
	document.getElementById("sellos_hide").innerHTML=LOADING;
  	ajaxsellos.open("GET", "/ajax_sellos.php", true);
  	ajaxsellos.onreadystatechange=function() 
  	 {  
   	 if (ajaxsellos.readyState==4) { document.getElementById("sellos_hide").innerHTML=ajaxsellos.responseText;  }  
	 }
  	ajaxsellos.send(null);  
	footer_div();	
	}
function cambiarsello(valor)
	{
 	document.getElementById("sello").value=valor;
 	document.getElementById("imgsello").src= '/imagenes_sello/'+valor+'?seed='+Math.random();
 	document.getElementById("imagen_sello").src= '/imagenes_sello/'+valor+'?seed='+Math.random();
	document.getElementById("sellos_hide").style.display="none";
	footer_div();	
	}
function mostrardestinatarios()
	{
	var registros = document.getElementById("cantidadregistros").value;
	var listado = "";
	var nombre = "";
	for (i=1;i<registros;i++)
	 	{ 
		nombre = document.getElementById("nombre_recibe"+i).value;
		if (nombre!="")
			{
				if (i!=1) listado = listado +", ";
			listado = listado + nombre;	
			}
		}
	listado = "Esta postal es para: "+listado;
	document.getElementById("divdestinatarios").innerHTML=listado;
	footer_div();	
	}
function eliminarmensaje()
	{
	var valor=document.getElementById("id").value;
 
	if (valor=="Ingrese su código") 
		{  
		alert ('asdasd');
		document.getElementById("id").value="";  }
		footer_div();	
	}
