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 mostrarjquery(div)
	{
	 document.getElementById('alertheader1').style.display='none';	
	 document.getElementById(div).style.display='block';
	 $("#"+div).delay(1400); 
	 $("#"+div).fadeOut(1400); 
	}

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="+parse_url(web,'host')+"&num_ale="+Math.random(), true);
    	ajax1.onreadystatechange=function() 
    	{ 
    	    if (ajax1.readyState==4)
    	    { 
    	        document.getElementById("spanthumb").innerHTML=ajax1.responseText;
    	    } 
    	}
   	ajax1.send(null);    
	}
}

  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 popup_modificar_general () {
var opciones="toolbar=no, statusbar=no, titlebar=no, location=no, directories=no, status=no, menubar=no,menubar=0, scrollbars=no, resizable=yes, width=670, height=440, left="+parseInt(((screen.width) / 2) - 335)+", top="+parseInt(((screen.height) / 2) - 220)+"";
var pagina= "/popup_email.php";
mywindows=window.open(pagina,"popup",opciones);
}

 

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. Este proceso puede demorar unos minutos...";
		reciproco= reciproco.replace("http://", "");
    	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_exist(web){
	if (web!="")
		{
	 	document.getElementById("divexisteweb").style.display="none";
		ajax4=nuevoAjax();
    	ajax4.open("GET", "/ajax_exist.php?web="+parse_url(web,'host')+"&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.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 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="+parse_url(web,'host')+"&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 eliminarweb(idweb,seid,email,seid_email) {
if (confirm("Realmente desea eliminar su sitio del directorio?"))
{
	ajax=nuevoAjax();
    ajax.open("GET", "/ajax_eliminar.php?idweb="+idweb+"&seid="+seid+"&email="+email+"&seid_email="+seid_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;
}

function parse_url (str, component) {
    // Parse a URL and return its components  
    // 
    // version: 1103.1210
    // discuss at: http://phpjs.org/functions/parse_url    // +      original by: Steven Levithan (http://blog.stevenlevithan.com)
    // + reimplemented by: Brett Zamir (http://brett-zamir.me)
    // + input by: Lorenzo Pisani
    // + input by: Tony
    // + improved by: Brett Zamir (http://brett-zamir.me)    // %          note: Based on http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
    // %          note: blog post at http://blog.stevenlevithan.com/archives/parseuri
    // %          note: demo at http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
    // %          note: Does not replace invalid characters with '_' as in PHP, nor does it return false with
    // %          note: a seriously malformed URL.    // %          note: Besides function name, is essentially the same as parseUri as well as our allowing
    // %          note: an extra slash after the scheme/protocol (to allow file:/// as in PHP)
    // *     example 1: parse_url('http://username:password@hostname/path?arg=value#anchor');
    // *     returns 1: {scheme: 'http', host: 'hostname', user: 'username', pass: 'password', path: '/path', query: 'arg=value', fragment: 'anchor'}
    var key = ['source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port',                         'relative', 'path', 'directory', 'file', 'query', 'fragment'],
        ini = (this.php_js && this.php_js.ini) || {},
        mode = (ini['phpjs.parse_url.mode'] && 
            ini['phpjs.parse_url.mode'].local_value) || 'php',
        parser = {            php: /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
            strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
            loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-scheme to catch file:/// (should restrict this)
        };
     var m = parser[mode].exec(str),
        uri = {},
        i = 14;
    while (i--) {
        if (m[i]) {          uri[key[i]] = m[i];  
        }
    }
 
    if (component) {        return uri[component.replace('PHP_URL_', '').toLowerCase()];
    }
    if (mode !== 'php') {
        var name = (ini['phpjs.parse_url.queryKey'] && 
                ini['phpjs.parse_url.queryKey'].local_value) || 'queryKey';        parser = /(?:^|&)([^&=]*)=?([^&]*)/g;
        uri[name] = {};
        uri[key[12]].replace(parser, function ($0, $1, $2) {
            if ($1) {uri[name][$1] = $2;}
        });    }
    delete uri.source;
    return uri;
}
