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 nuevoAjax()
{ 
    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 delete_text() {
	var web=document.getElementById("web");	
	if ( web.value=="Ingrese su sitio web")
		{	
		web.value="";	
		web.style.color="#000000";
		}
}

function check_web(input,web){
	web=web.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' '); //quito espacios
	if (web!="")
		{
		web= web.replace("http:///", "");
		web= web.replace("http://", "");
		web= web.replace("http:/", "");
		web= web.replace("http:", "");
		web= web.replace("http", "");
		web= web.replace("htp:///", "");
		web= web.replace("htp://", "");
		web= web.replace("htp:/", "");
		web= web.replace("htp:", "");
		web= web.replace("htp", "");
		web= web.replace("htttp:///", "");
		web= web.replace("htttp://", "");
		web= web.replace("htttp:/", "");
		web= web.replace("htttp:", "");
		web= web.replace("htttp", "");
		web= web.replace("hhttp:///", "");
		web= web.replace("hhtp://", "");
		web= web.replace("hhtp:/", "");
		web= web.replace("hhtp:", "");
		web= web.replace("hhtp", "");
		web = web.toLowerCase();
		document.getElementById(input).value="http://"+web;
		}
}
function check_thumb(web){
	if (web!="")
		{
		ajax1=nuevoAjax();
    	ajax1.open("GET", "/ajax_thumb.php?web="+web+"&num_ale="+Math.random(), true);
    	ajax1.onreadystatechange=function() 
    	{ 
    	    if (ajax1.readyState==4)
    	    { 
    	        document.getElementById("spanthumb").innerHTML=ajax1.responseText;
    	    } 
    	}
   	ajax1.send(null);    
	}
}
function delete_text_reciproco() {
	var web=document.getElementById("reciproco");	
	document.getElementById("reciproco_text").style.display="none";
	if ( web.value=="Ingrese la ubicación de nuestro enlace en su sitio web")
		{	
		web.value="";	
		web.style.color="#000000";
		}
}
function check_reciproco(reciproco){
	if (reciproco!="")
		{
		ajax2=nuevoAjax();
		document.getElementById("reciproco_text").style.display="block";
		document.getElementById("reciproco_text").innerHTML="Buscando reciproco. Puede demorar unos segundos.";
    	ajax2.open("GET", "/ajax_reciproco.php?reciproco="+reciproco+"&num_ale="+Math.random(), true);
    	ajax2.onreadystatechange=function() 
    	{ 
    	    if (ajax2.readyState==4)
    	    { 
    	        document.getElementById("reciproco_text").innerHTML=ajax2.responseText;
			 	document.getElementById("reciproco_text").style.display="block";
    	    } 
    	}
   	ajax2.send(null);    
	}
}
function check_feeds(feeds){
	if (feeds!="")
		{
		if (document.getElementById("feeds").value!="")
			{
	 		document.getElementById("feeds_text").style.display="none";
			ajax3=nuevoAjax();
    		ajax3.open("GET", "/ajax_feeds.php?feeds="+feeds+"&num_ale="+Math.random(), true);
    		ajax3.onreadystatechange=function() 
    		{ 
    		    if (ajax3.readyState==4)
    		    { 
    		        document.getElementById("divfeeds").innerHTML=ajax3.responseText;
				// 	document.getElementById("divfeeds").style.display="block";
    		    } 
    		}
   		ajax3.send(null);    
		}
	}
}
function check_exist(web){
	if (web!="")
		{
	 	document.getElementById("divexisteweb").style.display="none";
		ajax4=nuevoAjax();
    	ajax4.open("GET", "/ajax_exist.php?web="+web+"&num_ale="+Math.random(), true);
    	ajax4.onreadystatechange=function() 
    	{ 
    	    if (ajax4.readyState==4)
    	    { 
    	    var valorresult =ajax4.responseText;
			if (valorresult==1) {  	document.getElementById("divexisteweb").style.display="block"; 	document.getElementById("existeweb").value = ""; }
			if (valorresult==0) {  	document.getElementById("divexisteweb").style.display="none";  	document.getElementById("existeweb").value = ""; }
     	    } 
    	}
   	ajax4.send(null);    
	
	}
}

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 validateEmailinput(campo)
	{
	if(!validateEmail(campo))
		{
		alert("El email ingresado no es valido.");			
		document.frmagregar.email.focus(); 	
		}
	}
function keychecklength(texto)
	{
	 document.getElementById("spancaracteres").innerHTML='Caracteres: '+texto.length;
	}
function checklength()
	{
	var max = 300;
	var txt;
	txt=document.frmagregar.descripcion.value;
 	var n = txt.length;
	if (n>max) //i is the maxlength of textarea which we have set to 80
		{ 
		return false;
		}
	else { return true; }
	}
function checklengthtextarea(){

	if (checklength()==false)
		{
		alert("Su descripción no puede superar los 300 caracteres.");
		document.frmagregar.descripcion.focus();  	
		}  
	}	
function validar() {
var accs=1;
	delete_text();
	delete_text_reciproco();
	if(document.frmagregar.web.value==""  & accs!=0){
		alert("Debe ingresar  su sitio web o blog.");
		document.frmagregar.web.focus();  
		accs=0;
		}  
	if(document.frmagregar.web.value=="http://www.estuportal.com"  & accs!=0){
		alert("Debe ingresar  su sitio web o blog.");
		document.frmagregar.web.focus();  
		accs=0;
		}  
	if(document.frmagregar.existeweb.value==1  & accs!=0){
		alert("Su sitio ya existe en nuestro directorio.");
		document.frmagregar.web.focus();  
		accs=0;
		}  		
	if(document.frmagregar.titulo.value==""  & accs!=0){
		alert("Debe ingresar  titulo / anchor de su web.");
		document.frmagregar.titulo.focus();  
		accs=0;
		}  
	if(document.frmagregar.reciproco.value=="" & accs!=0){
		alert("Debe ingresar  la ubicación de su enlace reciproco.");
		document.frmagregar.reciproco.focus();  
		accs=0;
		} 
	if(document.frmagregar.web.value==document.frmagregar.feeds.value & accs!=0){
		alert("La Url de su web no puede ser igual a la Url de sus feeds.");
		accs=0;
		} 
	if(document.frmagregar.descripcion.value=="" & accs!=0){
		alert("Debe ingresar  la descripción.");
		document.frmagregar.descripcion.focus();  
		accs=0;
		} 
	if(!checklength & accs!=0){
		alert("Su descripción no puede superar los 300 caracteres.");
		document.frmagregar.descripcion.focus();  
		accs=0;
		}  		
	if(!validateEmail(document.frmagregar.email.value) & accs!=0){
		alert("Debe ingresar tu email.");
		document.frmagregar.email.focus();  
		accs=0;
		} 
	if(document.frmagregar.idcategoria.value=="" & accs!=0){
		alert("Debe ingresar la categoria de su web.");
		document.frmagregar.idcategoria.focus();  
		accs=0;
		} 
	if(document.frmagregar.idsubcategoria.value=="" & accs!=0){
		alert("Debe ingresar la subcategoria de su web.");
		document.frmagregar.idsubcategoria.focus();  
		accs=0;
		} 
 	if(document.frmagregar.code.value=="" & accs!=0){
		alert("Debe ingresar el codigo de seguridad.");
		document.frmagregar.code.focus();  
		accs=0;
		} 
 	if (accs==1) { document.frmagregar.submit(); }		
}
function cargasubcategoria(idcategoria)
{
    ajax=nuevoAjax();
    ajax.open("GET", "/ajax_subcategoria.php?idcategoria="+idcategoria+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    { 
        if (ajax.readyState==4)
        { 
            document.getElementById("dividsubcategoria").innerHTML=ajax.responseText;
        } 
    }
    ajax.send(null);        
}


  function popupmodificar() {
  var pagina = "/recordar/";
var opciones="toolbar=no, statusbar=yes, titlebar=no, location=no, directories=no, status=yes, menubar=no,menubar=0, scrollbars=yes, resizable=yes, width=670, height=400, left="+parseInt(((screen.width) / 2) - 335)+", top="+parseInt(((screen.height) / 2) - 200)+"";
 mywindows=window.open(pagina,"popup",opciones);

}
   function popupinfo (pagina) {
  
var opciones="toolbar=no, statusbar=no, titlebar=no, location=no, directories=no, status=no, menubar=no,menubar=0, scrollbars=yes, resizable=yes, width=670, height=400, left="+parseInt(((screen.width) / 2) - 335)+", top="+parseInt(((screen.height) / 2) - 200)+"";
 mywindows=window.open(pagina,"popup",opciones);

}
function recargarthumb(idweb,seid,email)
{	
	if (document.getElementById("web"))
		 { 	var web = document.getElementById("web").value; }
	else {  var web = document.getElementById("web"+idweb+"").value; }
      var  ajaxvar=nuevoAjax();
	document.getElementById("divthumb"+idweb+"").innerHTML='<img src="/images/img.jpg"  id="imgthumb'+idweb+'" width="108" height="80" hspace="2" border="0" align="left" style="border:1px solid #006699; padding:1px;" />';
	// alert ("/ajax_thumb_modificar.php?idweb="+idweb+"&seid="+seid+"&email="+email+"&num_ale="+Math.random());
    ajaxvar.open("GET", "/ajax_thumb_modificar.php?idweb="+idweb+"&web="+web+"&seid="+seid+"&email="+email+"&num_ale="+Math.random(), true);
    ajaxvar.onreadystatechange=function() 
    	{ 
        if (ajaxvar.readyState==4)  	
			{ 
		//	alert (ajaxvar.responseText);
			document.getElementById("divthumb"+idweb+"").innerHTML=ajaxvar.responseText; 
			document.getElementById('imgthumb'+idweb+'').src= '/thumbs/'+idweb+'.jpg?seed='+Math.random();
			
			} 
    	}
    ajaxvar.send(null); 
}
	function eliminar_tag_relacion(idtag, idwebtag,idweb, seid, email) {
if (confirm("Realmente desea eliminar relacion?"))
{
	var ajax=nuevoAjax();
    ajax.open("GET", "/ajax_tagcontenido_eliminar.php?idtag="+idtag+"&idwebtag="+idwebtag+"&idweb="+idweb+"&email="+email+"&seid="+seid+"&del=yes&num_ale="+Math.random(), true);
    document.getElementById("divtag"+idtag+"").innerHTML='Eliminando...';
	ajax.onreadystatechange=function() 
    	{  
	if (ajax.readyState==4) { document.getElementById("divtag"+idtag+"").innerHTML=ajax.responseText;  }  
		}
    ajax.send(null);
  	$("#divtag"+idtag+"").slideToggle("fast");
  	}
}	

function eliminarfeed(idfeeds,idweb,seid,email) {
if (confirm("Realmente desea eliminar entrada?"))
	{
	ajax=nuevoAjax();
    ajax.open("GET", "/ajax_feedeliminar.php?idfeeds="+idfeeds+"&idweb="+idweb+"&seid="+seid+"&email="+email+"&del=yes&num_ale="+Math.random(), true);
	ajax.onreadystatechange=function() 
    	{  
	if (ajax.readyState==4) { document.getElementById("divfeed"+idfeeds+"").innerHTML=ajax.responseText;  }  
		}
    ajax.send(null);
	$("#divfeed"+idfeeds+"").slideToggle("fast");
	}
}

function eliminarweb(idweb,seid,email) {
if (confirm("Realmente desea eliminar su web?"))
{
	ajax=nuevoAjax();
    ajax.open("GET", "/ajax_eliminar.php?idweb="+idweb+"&seid="+seid+"&email="+email+"&del=yes&num_ale="+Math.random(), true);
    document.getElementById("divw"+idweb+"").innerHTML='Eliminando...';
	ajax.onreadystatechange=function() 
    	{  
	if (ajax.readyState==4) { document.getElementById("divw"+idweb+"").innerHTML=ajax.responseText;  }  
		}
    ajax.send(null);
 	$("#divw"+idweb+"").slideToggle("fast");
  	}
}

 function votar(idweb)
{
    document.getElementById("divvotar").innerHTML='Cargando...';
	ajax=nuevoAjax();
	ajax.open("GET", "/ajax_votar.php?idweb="+idweb+"&num_ale="+Math.random(), true);
    ajax.onreadystatechange=function() 
    {   
    	if (ajax.readyState==4) { document.getElementById("divvotar").innerHTML=ajax.responseText;  } 
    }
    ajax.send(null);       
}
function precioenlace(){
 	var total = 0;
	if  (document.frmagregar.destacadopos1.checked==true) 
		{ total = total + parseInt(document.getElementById("spanprecio1").innerHTML); }
	if  (document.frmagregar.destacadopos2.checked==true) 
		{ total = total + parseInt(document.getElementById("spanprecio2").innerHTML); }		
	if  (document.frmagregar.destacadopos3.checked==true) 
		{ total = total + parseInt(document.getElementById("spanprecio3").innerHTML); }
	if  (document.frmagregar.destacadopos4.checked==true) 
		{ total = total + parseInt(document.getElementById("spanprecio4").innerHTML); }
 document.getElementById("totalpreciopromocion").innerHTML = total;
 document.getElementById("preciototal").value = total;
}
