/*
*----------------------------phpMyBitTorrent V 2.0-beta4-----------------------*
*--- The Ultimate BitTorrent Tracker and BMS (Bittorrent Management System) ---*
*--------------   Created By Antonio Anzivino (aka DJ Echelon)   --------------*
*-------------               http://www.p2pmania.it               -------------*
*------------ Based on the Bit Torrent Protocol made by Bram Cohen ------------*
*-------------              http://www.bittorrent.com             -------------*
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
*--   This program is free software; you can redistribute it and/or modify   --*
*--   it under the terms of the GNU General Public License as published by   --*
*--   the Free Software Foundation; either version 2 of the License, or      --*
*--   (at your option) any later version.                                    --*
*--                                                                          --*
*--   This program is distributed in the hope that it will be useful,        --*
*--   but WITHOUT ANY WARRANTY; without even the implied warranty of         --*
*--   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          --*
*--   GNU General Public License for more details.                           --*
*--                                                                          --*
*--   You should have received a copy of the GNU General Public License      --*
*--   along with this program; if not, write to the Free Software            --*
*-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA --*
*--                                                                          --*
*------------------------------------------------------------------------------*
*------              ©2005 phpMyBitTorrent Development Team              ------*
*-----------               http://phpmybittorrent.com               -----------*
*------------------------------------------------------------------------------*
*-----------------   Sunday, September 14, 2008 9:05 PM   ---------------------*
*/
/// Space for AJAX mods \\\
function advanced() {
        var obj;
        var obj2;
        obj = document.getElementById("users_simple");
        obj.className = 'hide';

        obj2 = document.getElementById("users_advanced");
        obj2.className = 'show';
}

function simple() {
        var obj;
        var obj2;
        obj2 = document.getElementById("users_advanced");
        obj2.className = 'hide';

        obj = document.getElementById("users_simple");
        obj.className = 'show';
}
function descriptor(val) {
        var obj;
        obj = document.getElementById("descriptor");
        if (!obj) return;
        obj.firstChild.nodeValue = val;
}
function ajax_createRequestObject(){
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
} else{
ro = new XMLHttpRequest();
}
return ro;
}
var ajax_http = ajax_createRequestObject();
var ajax_destObj;
function SetSize(obj, x_size) {
       if (obj.offsetWidth > x_size) {
       obj.style.width = x_size;
   };
};
var c=0;
function shoutthis_ajax()
{ 
c=0;
this.ts = window.setInterval('shoutload()', 30000);
this.ta = window.setInterval('getactive()', 35100);
this.tpm = window.setInterval('sendPmId()', 35500);
this.idletime = window.setInterval("stopall()",30000);
}
 showsmiles = "show";
 inprivate = 'no';
function sndReq(argumentString, destStr){
		showprivateonly = '';

		if(inprivate == 'no'){
	showprivateonly = argumentString;
	}else{
		showprivateonly = argumentString+'&shotuser='+inprivate;
	}
//alert(showprivateonly);

	if(argumentString == "op=activeusers"){
	//alert("user");
	refreshoff = true;
	}
	if(argumentString == "op=view_shout"){
		refreshoff = false;
	}
	
	if(argumentString == "op=more_smiles")
	{
	if(showsmiles == "show")
	{
		 showsmiles = "hide";
		 ajax_destObj = document.getElementById(destStr);
ajax_http.open('get', './ajax.php?'+showprivateonly);
ajax_http.onreadystatechange = ajax_handleResponse;
ajax_http.send(null);

	}
	else if(showsmiles == "hide")
	{
		 showsmiles = "show";
		 ajax_destObj = document.getElementById(destStr);
ajax_http.open('get', './ajax.php?op=take_edit_shout_cancel');
ajax_http.onreadystatechange = ajax_handleResponse;
ajax_http.send(null);

	}
	}
	else
	{
ajax_destObj = document.getElementById(destStr);
ajax_http.open('get', './ajax.php?'+showprivateonly);
ajax_http.onreadystatechange = ajax_handleResponse;
ajax_http.send(null);
	}
}
function toggleprivate(nome, pmshout) {
		//alert(inprivate);

	//alert(document.getElementById(nome).attributes["onclick"].value)
if(document.getElementById(nome).value=="Shout!")
{
//document.getElementById(nome).style.display = '';
 inprivate = pmshout;
document.getElementById(nome).value= _btshoutnowprivate;
document.getElementById(nome).attributes["onclick"].value="sndprivateshoutReq(text.value, 'shout_out', '"+pmshout+"')";
document.getElementById("shoutthisch").attributes["onclick"].value="toggleprivate('shout_send'); sndReq('op=view_shout', 'shout_out');";
document.getElementById("shout_text_area").attributes["onkeypress"].value="if (event.keyCode == 13) {sndprivateshoutReq(this.value, 'shout_out', '"+pmshout+"');}";
} else {
//document.getElementById(nome).style.display = 'auto';
 inprivate = 'no';
document.getElementById(nome).value="Shout!";
document.getElementById(nome).attributes["onclick"].value="sendshoutout(text.value, 'shout_out')";
document.getElementById("shoutthisch").attributes["onclick"].value="sndReq('op=view_shout', 'shout_out');";
document.getElementById("shout_text_area").attributes["onkeypress"].value="if (event.keyCode == 13) {sendshoutout(this.value, 'shout_out');}";

}
}
function getactive(){
	//alert(inprivate);
ajax_destObj = document.getElementById('shoutbox_activity');
ajax_http.open('get', './ajax.php?op=getactive');
ajax_http.onreadystatechange = ajax_handleResponse;
ajax_http.send(null);
}
function stopall()
{
	c=c+1;

if(c >= 30){
	 var div = document.getElementById('shoutidle');
	 if(div != null)div.innerHTML ='<font style="font-size:9pt; color:#FF0000;">ShoutBox Notice!</font> You are currently idle in the shoutbox. Click <a href="?" onclick="return shoutthis_ajax();">here</a> to un-idle yourself.';
window.clearTimeout(this.ts);
window.clearTimeout(this.ta);
window.clearTimeout(this.tpm);
window.clearTimeout(this.idletime);
}	else
	{
		return null;
	}

}
function shoutload(){
		showprivateonly = '';
	//alert(inprivate);
	if(inprivate == 'no'){
	showprivateonly = '';
	}else{
		showprivateonly = '&shotuser='+inprivate;
	}

ajax_destObj = document.getElementById('shout_out');
if(ajax_destObj == null){return}
ajax_http.open('get', './ajax.php?op=view_shout'+showprivateonly);
ajax_http.onreadystatechange = ajax_handleResponse;
ajax_http.send(null);
}
function sndprivateshoutReq(argumentString, destStr, sendto){
	//alert(argumentString);
	//validate(theform)
ajax_destObj = document.getElementById(destStr);
ajax_http.open('get', './ajax.php?op=take_shout&sendto='+sendto+'&text='+argumentString);
ajax_http.onreadystatechange = ajax_handleResponse;
ajax_http.send(null);
	//shoutload();
}
function makeurlsafe(text){
	argumentString = text.replace(/&/,"/amp2/");
	return argumentString;
}
function sndshoutReq(argumentString, destStr){
	//alert(makeurlsafe(argumentString));
	//validate(theform)
ajax_destObj = document.getElementById(destStr);
ajax_http.open('get', './ajax.php?op=take_shout&text='+makeurlsafe(argumentString));
ajax_http.onreadystatechange = ajax_handleResponse;
ajax_http.send(null);
	//shoutload();
}
function sendshoutout(text, destStr){
	c=0;
	//alert(destStr);
	sndshoutReq(text, destStr);
	//shoutload();
}
function ajax_handleResponse(){
if(ajax_http.readyState == 4){
var response = ajax_http.responseText;
if(ajax_destObj != null)ajax_destObj.innerHTML = response;
//alert(response);
//ajax_destObj.innerHTML = response;
} else if(ajax_http.readyState == 1 ){
// Uncomment the next line if you want
// to display a Loading text. This will
// cause the page to blink if lots of
// data is being transferred. I vote off.
// However, if your server is slow and
// you want to tell your users something
// is being processed, turn it on.
//ajax_destObj.innerHTML = '<img src="/images/please_wait.gif" title="Loading" border="0" alt="Loading" />';
}
}
//// END AJAX MODS \\\\
function SetSize(obj, x_size) {
       if (obj.offsetWidth > x_size) {
       obj.style.width = x_size;
   };
};
function sendPmId()
{
    if(document.getElementById("nopm_notif"))
    {
        try
          {
          // Firefox, Opera 8.0+, Safari
          pmIdsend=new XMLHttpRequest();
          }
        catch (e)
          {
          // Internet Explorer
          try
            {
            pmIdsend=new ActiveXObject("Msxml2.XMLHTTP");
            }
          catch (e)
            {
            try
              {
              pmIdsend=new ActiveXObject("Microsoft.XMLHTTP");
              }
            catch (e)
              {
              alert("Your browser does not support AJAX!");
              return false;
              }
            }
          }
          
          
          pmIdsend.onreadystatechange = pmResponse;
          pmIdsend.open("GET","./pm_ajax.php");
          pmIdsend.send(null);
          
          
          return false;
    }  
}

function pmResponse()
{
if(pmIdsend.readyState == 4)
          {
            if(pmIdsend.status == 200){// ok
                try { // precte odpoved
                    var response = pmIdsend.responseText;
                    //alert(response);
                    if(response.length == 0) throw "Invalid server response.";
                    /*if(response.indexOf("login_error") >= 0) {
                        zobrazChybuPrihlaseni();
                        return;
                    }*/
                    response = pmIdsend.responseXML.documentElement;
                    stav = response.getElementsByTagName("status"); // vsechny elementy kontakt
                    // nepodarilo se ulozit
                    if(stav[0].firstChild.data != "OK"){
                        alert("Message was not saved!\n");
                        //document.getElementById('tarea_text').focus();
                    }
                    //else  zjistiPocetZpravAjax(); //odeslanoOK = true;
                      else{ 
                          pm = response.getElementsByTagName("pm");
                          if(pm[0].firstChild.data != "false"){
                             // alert(pm[0].firstChild.data+"\n");
                            pmNotif = document.getElementById("nopm_notif");
                            pmNotif.id = "pm_notif";  
                            
                            while(pmNotif.hasChildNodes()) pmNotif.removeChild(pmNotif.firstChild);
                            
                            a = document.createElement("a");
                            atr = document.createAttribute("href");
                            atr.value = "pm.php?op=inbox";
                            a.setAttributeNode(atr);
                            txt = document.createTextNode(pm[0].firstChild.data);
                            a.appendChild(txt);
                            blink = document.createElement("blink");
                            blink.appendChild(a);
                            pmNotif.appendChild(blink);
                            
                            conftext = response.getElementsByTagName("confirm");
                            conftext = conftext[0].firstChild.data;
                            var answer = confirm (conftext);
                            if (answer) window.location="pm.php?op=inbox";
                          }
                          
                        
                      }                
                }
                catch(e) {
                    alert("Error when processing:\n " + e.toString());
                }
            }
          }
}
var newwindow;
function popshout(url)
{
 newwindow=window.open(url,'popshout','height=400,width=900');
}
function popusers(url)
{
 newwindow=window.open(url,'popusers','height=70,width=400');
 if (window.focus) {newwindow.focus()}
}