String.prototype.trim = function(){ return this.replace(/^s+|s+$/g,'') }
/* Crea la capa de ajax {{{ */
function createRequestObject() {
        try {
                objetus = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
                try {
                        objetus= new ActiveXObject("Microsoft.XMLHTTP");
                } catch (E) {
                        objetus= false;
                }
        }
        if (!objetus && typeof XMLHttpRequest!='undefined') {
                objetus = new XMLHttpRequest();
        }
        return objetus
} /* }}} */
var http = createRequestObject();
var aaa = null;
var waiting = '';
var lastmsg='';
var channel='general';
/* Envío de variables por medio de GET {{{ */
function sndReq(url,argumentos,elid) {
    aaa = elid;
    http.open('get', url+argumentos,true);
    http.onreadystatechange = handleResponse;
    http.send(null);
} /* }}} */
/* Manejador de respuestas de GET {{{ */
function handleResponse() {
    var moreID = document.getElementById(aaa);
    if (http.readyState == 1 && waiting != '') {
        moreID.style.display = "block";
        moreID.innerHTML = waiting;
    }
    if(http.readyState == 4) {
        response = http.responseText;
        moreID.innerHTML = response;
    }
} /* }}} */
function is_busy() {
   if(http.readyState == 3 || http.readyState == 1 || http.readyState == 2) { return true; }
   else { return false; }
}
function shoutIt(mensaje) {
   if(is_busy()) { alert('Estoy algo ocupado, intenta en unos segundos ;)'); return false; }
   var tmp = mensaje.trim();
   if(tmp.length < 2) { alert('Escriba algo!'); return false; }
   if(tmp == lastmsg) { alert('Usted ya escribio eso...'); return false; }
   lastmsg = mensaje;
   q = "?s=shout&c="+channel+"&m="+encodeURIComponent(mensaje);
   //waiting='<p align="center"><img src="/media/waitffffff.gif" alt="espere..." /><br />cargando...</p>';
   sndReq("http://www.ymipollo.com/gadgets/gadget.shout.php",q,"shoutbox");
   document.sh.shoutx.value = '';
   //waiting = '';
}
function shoutRefresh(ch) {
   if(is_busy()) { return false ; }
   if(ch == '' && channel=='general') { ch=channel; }
   else { channel=ch; }
   //waiting='<p align="center"><img src="/media/waitffffff.gif" alt="espere..." /><br />cargando...</p>';
   sndReq("http://www.ymipollo.com/gadgets/gadget.shout.php","?s=shoutrefresh&c="+ch,"shoutbox");
   //waiting = '';
}
function stopRefresh() {
   clearInterval(timerChat);
   //creamos cookie
   var ExpireDate = new Date ();
   ExpireDate.setTime(ExpireDate.getTime() + (7 * 24 * 3600 * 1000));
   document.cookie = "pollochat=" + escape('no') + "; expires=" + ExpireDate.toGMTString();
   //redireccionamos
   location.href ='http://www.ymipollo.com/';
}
function startShout() {
   location.href ='http://www.ymipollo.com/?chat';
}
function readInbox() {
   if(is_busy()) { return false; }
   sndReq("http://www.ymipollo.com/gadgets/gadget.inbox.php","?s=x","mailbox");
}
function delMsg(msg) {
   if(is_busy()) { alert('Espere un momento...'); return false; }
   sndReq("http://www.ymipollo.com/gadgets/gadget.buzon.php","?s=del&del="+msg,'msgid'+msg);
   document.getElementById('msgid'+msg).innerHTML = '';
   return false;
}

function _(url,nombre,ancho,alto) {
   ancho = ancho ? ancho : 600; alto = alto ? alto : 480; nombre = nombre ? nombre : 'aux';
   aux = window.open(url,nombre,"width="+ancho+",height="+alto+",toolbar=no,directories=no,location=no,copyhistory=no,scrollbars=yes,resizable=yes");
   aux.focus();
   return false;
}
function loquesehabla(accion) {
   if(is_busy()) { return false; }
   waiting='<p align="center"><img src="/media/waitffffff.gif" alt="espere..." /><br />cargando...</p>';
   sndReq("http://www.ymipollo.com/gadgets/gadget.ajax.php","?s="+accion,accion);
   waiting='';
   return false;
}
function ttoggle(i) {
   var tmp = document.getElementById(i).style.display;
   if(tmp == 'none') document.getElementById(i).style.display = 'block';
   else document.getElementById(i).style.display = 'none';
}
