var ManiPagina=function(){}
//var oXmlHttp = null;
var iInterval = 10000;
var iLastCommentId = -1;
var httpSendAdmin;
ManiPagina.prototype.RefrescoPagina=function (){
	window.location.reload();
}
ManiPagina.prototype.OpenWindow=function ( url, width, height, opt , name ) {
	window.open( url, (name || "OutsideWindow"), "width="+(width || 714)+",height="+(height || 536)+","+(opt ||  "scrollbars=yes,menubar=yes,toolbar=yes,location=yes,status=yes,resizable=yes")).focus();
}

ManiPagina.prototype.IrAlgunLado=function(dato){
	window.location=dato;
}
ManiPagina.prototype.IrAlgunLadoConcat=function(dato){
	window.location+=dato;
}
ManiPagina.prototype.wind_open_Gen=function(page,anch,alto){
	var width = anch;
   	var height = alto;
   	var left = parseInt((screen.availWidth/2) - (width/2));
  	var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + anch+ ",height=" +alto + ",status=0,resizable=0,left=" + left + ",top=" + top + 
        ",screenX=" + left + ",screenY=" + top;
   	var winnueva = window.open(page, "winnueva", windowFeatures);
	winnueva.focus();
}

ManiPagina.prototype.EnviarAmigo=function(ruta){
	
	 if (httpSendAdmin.readyState == 4 || httpSendAdmin.readyState == 0) {
		httpSendAdmin.open("POST", ruta+"/php_files/clases/SendFirend/genFormEnviar.php", true);
		httpSendAdmin.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	  	httpSendAdmin.onreadystatechange = this.MUestroFormEnviar;
	  	httpSendAdmin.send(null);
	}
}
ManiPagina.prototype.PaginaGen=function(ruta,OrderBY,QueryCuento,QueryDato,pagina){
	var rutas=$F('rutaSitio');
	var actuaMenu = new Ajax.Updater('paginador',
	   rutas + 'php_files/clases/Articulos/GenPaginador.php', {
	     parameters: { pagina: pagina, OrderBY: OrderBY, QueryCuento: QueryCuento, QueryDato: QueryDato, rutas:rutas}
	});
}

ManiPagina.prototype.MUestroFormEnviar=function(){
	if (httpSendAdmin.readyState == 4) {
		results = "EnviarAmigo{#}"+httpSendAdmin.responseText;
		pagi.MOstrarAlgunResDifeHash(results);
	}
}
ManiPagina.prototype.ValidoEnviarEmFiren=function(){
	var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	var res = /^[\w-]+{\/}$/;
	 var sNewUrl = location.href;
	var NombreAmigo=$('NombreAmigo');
	var EmaiLAmigo=$('EmaiLAmigo');
	var comentario=$('comentario');
	if(!NombreAmigo.value){
		alert("Please inser the name firend"); NombreAmigo.focus(); return;
	}else if(!EmaiLAmigo.value){
		alert("You must enter a valid email"); email.focus(); return;
	}else if(!EmaiLAmigo.value.match(re)){
		alert("You must enter a valid email"); email.focus(); return;
	}else{
		var datos=sNewUrl+"##"+NombreAmigo.value+"##"+EmaiLAmigo.value+"##"+comentario.value;
		x_EnviarEmailAmigo(datos,this.MOstrarAlgunResDifeHash);
	}
}
ManiPagina.prototype.MOstrarAlgunResDifeHash=function(dato){
	
	var resDato=dato.split("{#}");
	//alert(resDato[0]);
	if(resDato[0]!="4"){
		var divAEscrib=resDato[0];
		var ValorDiv=resDato[1];
		var Elemento = $(divAEscrib);
		Elemento.innerHTML=ValorDiv;
		//alert(divAEscrib);
		var ele=new Effect.Highlight(divAEscrib,{duration: 0.5});
		
	
	}else if(resDato[0]=="4"){
		pagi.RefrescoPagina();
	}
	
}
ManiPagina.prototype.DeiableEnamble=function(form,elmento,elemDisable){
	var e = form.elements;
	for(i=0;i<e.length;i++)
	{		
		if(e[i].name == elmento)
		{
			if(e[i].checked){	
					$(elemDisable).disabled = false;
				}else{
					$(elemDisable).disabled = true;
				
			}
		}
	}
}

ManiPagina.prototype.DevolverValorChqueado=function(form,Elemento){
	var a = form.elements;
	for(i=0;i<a.length;i++)
	{		
		if(a[i].name == Elemento)
		{
			if(a[i].checked){				
				return a[i].value;				
			}
		}
	}
}
ManiPagina.prototype.getURLForPage=function(parametros) {
    var sNewUrl = location.href;
    if (location.search.length > 0) {
        sNewUrl = sNewUrl.substring(0, sNewUrl.indexOf("?"))
    }
    sNewUrl += "?" + parametros;
    this.IrAlgunLado(sNewUrl);
}

ManiPagina.prototype.inplaceEditText=function(el, url){
	var el= new Ajax.InPlaceEditor(el, url);
}

ManiPagina.prototype.CreoEtiquetaA=function(valorEti, valora, dondeImprime){
	var Ele=$(dondeImprime);
	var a=document.createElement("a");
    a.setAttribute("href",valora);
    a.innerHTML=valorEti;
   Ele.removeChild(Ele.lastChild);
   Ele.appendChild(a);   
}

ManiPagina.prototype.getHTTPObject=function() {
   var xmlhttp; 
   if (!xmlhttp) {
        xmlhttp = zXmlHttp.createRequest();
    } else if (xmlhttp.readyState != 0) {
        xmlhttp.abort();
    }    
    return xmlhttp;
}
ManiPagina.prototype.GetUrlParam=function( paramName )
{
	var oRegex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' ) ;
	var oMatch = oRegex.exec( window.top.location.search ) ;
	
	if ( oMatch && oMatch.length > 1 )
		return decodeURIComponent( oMatch[1] ) ;
	else
		return '' ;
}

function ActuaResourceLink(id,linkActu){
	var link = "?learn="+document.getElementById('learn').value+"&idFiltro="+id+"&linkActu="+linkActu;
	document.location=link;
}

function VolverAlgunLado(dato){
	if(dato==1){
		document.getElementById('div_form1').innerHTML ="This Category Name already exist";
	}else{ 
		window.location=dato;
		
	}
}


function BorrarFavorito(IDForo){
	if(confirm("Sure that want delete this room from your favorites rooms?")){
		
		//var sajax_request_type = "POST";
		x_BorraFavorito(IDForo,pagi.RefrescoPagina());
	}
}

function SeleccionarTodo(){
	var control=0;
	var e = document.lista.elements;
	var allbox=document.getElementById('allbox');
	if(document.getElementById('allbox').checked){
		for(var i=0;i<e.length;i++){
	
			if((e[i].name!="allbox")&& (e[i].type=='checkbox')){
				e[i].checked=true;
			
			}	
		}
	}else{
		for(var i=0;i<e.length;i++){
	
			if((e[i].name!="allbox")&& (e[i].type=='checkbox')){
				e[i].checked=false;
			
			}	
		}
	}
}




ManiPagina.prototype.procesarLog=function(ruta){
	var html="<div align=\"center\" ><img src=\""+ruta+"files/cssFiles/ajax-loader.gif\"  /><br /><b>Procesando Informacion...</b></div>";
	return html;
}

function SubMIAprovar(grupo){
	document.FormActu.action="?group="+grupo+"&pendingMEmebers=true&actua=true";
	document.FormActu.submit();
}

ManiPagina.prototype.MOstrarAlgunRes=function(dato){
	
	var resDato=dato.split("#");
	//alert(resDato[0]);
	if(resDato[0]!="4"){
		var divAEscrib=resDato[0];
		var ValorDiv=resDato[1];
		var Elemento = $(divAEscrib);
		
		Elemento.update(ValorDiv);
		//alert(divAEscrib);
		var ele=new Effect.Highlight(divAEscrib,{duration: 0.5});
		//Elmemento.removeClassName('Loadign');
	
	}else if(resDato[0]=="4"){
		pagi.RefrescoPagina();
	}
	
}

function CehcloNuevoEmails(ruta){
	var rutas=ruta;	
	 if (!oXmlHttp) {
      var  oXmlHttp = zXmlHttp.createRequest();
    } else if (oXmlHttp.readyState != 0) {
        oXmlHttp.abort();
    }    
    
    oXmlHttp.open("get", ""+rutas+"php_files/clases/MailClass/ChecoMeailNUevo.php", true);
    oXmlHttp.onreadystatechange = function () {               
        
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {

                var aData = oXmlHttp.responseText;
               
               if (aData != iLastCommentId) {                   
                    
                    iLastCommentId = aData;
                    
                   if (iLastCommentId != -1) {                        
                        showNotification(aData);
                    }                   
                }              
               var tiempoEmail=setTimeout("CehcloNuevoEmails('"+rutas+"')", iInterval);             
            }                         
        }
    };    

    oXmlHttp.send(null);       
	
}
function showNotification(dato){
	
	var idDivEmail=$('emails');
	var idNumeroEmails=$('NumeorNEmail');
	idNumeroEmails.innerHTML=dato;
	//var efe =new Effect.Highlight(idDivEmail,{duration: 0.5});
}


pagi = new ManiPagina();
