/**
*
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
*
*
**/
function trim(str, chars) {return ltrim(rtrim(str, chars), chars);}
function ltrim(str, chars) {  chars = chars || "\\s"; return str.replace(new RegExp("^[" + chars + "]+", "g"), "");}
function rtrim(str, chars) { chars = chars || "\\s";  return str.replace(new RegExp("[" + chars + "]+$", "g"), "");}

var documentHeight=  jQuery(document.body).height; 
var documentWidth =  jQuery(document.body).width; 
function get_xmlhttp(){try{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}catch(E){xmlhttp=false;}}if(!xmlhttp&&typeof XMLHttpRequest!='undefined'){xmlhttp=new XMLHttpRequest();}return xmlhttp}

function ajax(xmlhttp,metodo,url,datos,async,callback){
  theDate = new Date();
  datos + "&theTimeID=" +theDate.getTime();
  if(metodo=='GET') url  =  url  + '?' + datos;
  xmlhttp.open(metodo,url ,async);
  xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4)callback(xmlhttp);};	
  if(metodo=='GET')
    xmlhttp.send(null); 
  else {
    xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xmlhttp.send(datos);
  }
}

function showcapa(capa){jQuery('#'+capa).show();}
function hidecapa(capa){jQuery('#'+capa).hide();}

function viewcapa(capa){  if  (jQuery('#'+capa).css('display')=='none') showcapa(capa); else hidecapa(capa);}
function viewcapaif(capa,condition){  if (condition) showcapa(capa); else hidecapa(capa);}
function loadtext(capa,text){jQuery('#'+capa).html(text); }
function loadhtml(elemento,texto){document.getElementById(elemento).innerHTML=texto;}
function isvisible(capa){  return  (jQuery('#'+capa).css('display')!='none');}
function slidecapa(x) { if (jQuery('#'+x).css('display')=='none') jQuery('#'+x).slideDown('slow'); else jQuery('#'+x).slideUp('slow'); }

function addLoadEvent(func) { 
  var oldonload = window.onload; 
  if (typeof window.onload != 'function') { 
    window.onload = func; 
   } else { 
    window.onload = function() { 
      oldonload(); 
      func(); 
    } 
  } 
} 
	 
//addLoadEvent(nameOfSomeFunctionToRunOnPageLoad); 
//addLoadEvent(function() { /* more code to run on page load */ }); 

/**
* Adds a function to the window onunload event
*/
function addUnloadEvent(func) {
  var oldOnunload = window.onunload;
  if (typeof window.onunload != 'function') {
    window.onunload = func;
  }
  else {
    window.onunload = function() {
      oldOnunload();
      func();
    }
  }
}

function getUserInfo(){
  loadtext('layerlogin',ajaxindicator);
  xmlhttp=get_xmlhttp();
  ajax(xmlhttp,"GET","_includes_/cms_ajax.php","op=userinfo",true,UserInfo);
}
function UserInfo(xmlhttp){
  if(xmlhttp.status==404) loadtext('layerlogin','404 not found!');
                    else loadtext('layerlogin',xmlhttp.responseText);
  xmlhttp.onreadystatechange = function(){};
}

function getUsersOnline(){
  xmlhttp=get_xmlhttp();
  ajax(xmlhttp,"GET","_includes_/cms_ajax.php","op=usersonline",true,UsersOnline);
}
function UsersOnline(xmlhttp){
  if(xmlhttp.status==404) loadtext('layerusers','404 not found!');
                     else loadtext('layerusers',xmlhttp.responseText);
  xmlhttp.onreadystatechange = function(){};
}

function getTimeOnline(){
  xmlhttp=get_xmlhttp();
  ajax(xmlhttp,"GET","_includes_/cms_ajax.php","op=timeonline",true,TimeOnline);
}
function TimeOnline(xmlhttp){
  if(xmlhttp.status==404) loadtext('layerreloj','404 not found!');
                     else loadtext('layerreloj',xmlhttp.responseText);
  xmlhttp.onreadystatechange = function(){};
}

function getReloj(){xmlhttp=get_xmlhttp();ajax(xmlhttp,"GET","_includes_/cms_ajax.php","op=reloj",true,Reloj);}
function Reloj(xmlhttp){
  if(xmlhttp.status==404)
    loadtext('layerreloj','404 not found!');
  else
  {
    rcvText=xmlhttp.responseText;
    if(rcvText!='\n')
    {
      loadtext('layerreloj',eval(rcvText));
      evalScript();
    }
  }
  xmlhttp.onreadystatechange = function(){};
}

function evalScript(){  
  script = jQuery('#layerreloj');  
  eval(script.innerHTML);
}