//===========================================================================//
//Contains ajaxpack.js,dhtmltooltip.js,mouseovertabs.js
//===========================================================================//
//Basic Ajax Routine- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Modified by T.Suriyathep for Gamebrew.com
//Last updated: 12.21.07

//ACCESSIBLE VARIABLES (for use within your callback functions):
//1) ajaxpack.ajaxobj //points to the current ajax object
//3) ajaxpack.basedomain //The root domain executing this ajax script, taking into account the possible "www" prefix.

//ACCESSIBLE FUNCTIONS:
//1) ajaxpack.get(url, div_id)
//2) ajaxpack.post(url, parameters, div_id)

function createAjaxObj() {
  var httprequest=false;
  if(window.XMLHttpRequest) { // if Mozilla, Safari etc
    httprequest=new XMLHttpRequest();
    if(httprequest.overrideMimeType) httprequest.overrideMimeType('text/xml');
  }
  else if(window.ActiveXObject) { // if IE
    try {httprequest=new ActiveXObject("Msxml2.XMLHTTP");} 
    catch(e) {
      try {httprequest=new ActiveXObject("Microsoft.XMLHTTP");}
      catch (e){}
    }
  }
  return httprequest;
}

var ajaxpack=new Object();
ajaxpack.basedomain="http://"+window.location.hostname;
ajaxpack.ajaxobj=createAjaxObj();

ajaxpack.loadDiv=function(containerid) {
  if(this.ajaxobj.readyState==4 && (this.ajaxobj.status==200||window.location.href.indexOf("http")==-1)) {
    if(this.ajaxobj.responseText.length>0) document.getElementById(containerid).innerHTML=this.ajaxobj.responseText;
  }
}

ajaxpack.get=function(url,containerid) {
  ajaxpack.ajaxobj=createAjaxObj(); //recreate ajax object to defeat cache problem in IE
  if(this.ajaxobj) {
    var bustcacheparameter=(url.indexOf("?")!=-1)?"&"+new Date().getTime():"?"+new Date().getTime()
    this.ajaxobj.onreadystatechange=function() {ajaxpack.loadDiv(containerid);}
    this.ajaxobj.open('GET',url+bustcacheparameter,true);
    this.ajaxobj.send(null);
  }
}

ajaxpack.post=function(url,parameters,containerid) {
  ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
  if(this.ajaxobj) {
    this.ajaxobj.onreadystatechange=function() {ajaxpack.loadDiv(containerid);}
    this.ajaxobj.open('POST',url,true);
    this.ajaxobj.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    this.ajaxobj.setRequestHeader("Content-length",parameters.length);
    this.ajaxobj.setRequestHeader("Connection","close");
    this.ajaxobj.send(parameters);
  }
}
//===========================================================================//
/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX=14 //Customize x offset of tooltip
var offsetfromcursorY=14 //Customize y offset of tooltip

var offsetdivfrompointerX=14 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="images/dhtmltooltip.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip
//===========================================================================//
//Mouseover Tabs Menu: By http://www.dynamicdrive.com
//http://www.dynamicdrive.com/dynamicindex1/mouseovertabs.js
//Modified:
//  * No disappear delay
//  * Delay on hover before switching to new tab (switchdelay)

var mouseovertabsmenu={
  
  switchtimer:null,
  switchdelay:250,
  tabsmenutree:{},
  
  initializetabs:function(tabsmenuid, submenuid, tabcontentsLength) {
    var tabmenu=document.getElementById(tabsmenuid);
    var tablinks=tabmenu.getElementsByTagName("a");
    var submenu=document.getElementById(submenuid);
    var selected=null,tablinks_count=0;
    for(var i=0;i<tablinks.length;i++) {
      tablinks[i]._parentid=tabsmenuid;
      var relattr=tablinks[i].getAttribute("rel");
      if(/^gotsubmenu/i.test(relattr) && tablinks_count<tabcontentsLength) { //if "rel" attribute starts with="gotsubmenu" and a tab content exists for this tab based on its order
      	 tablinks[i]._pos=tablinks_count; //remember position of this tab relative to its active peers
      	 if(relattr.indexOf("[selected]")!=-1) selected=tablinks_count;
      	 this.addEvent(tablinks[i],function() {
           var cursubmenuobj=this;
        	 mouseovertabsmenu.clearswitchtimer();
           mouseovertabsmenu.switchtimer=setTimeout(function(){
          	 var tabsmenutree=mouseovertabsmenu.tabsmenutree[cursubmenuobj._parentid];
          	 mouseovertabsmenu.clearswitchtimer();
          	 mouseovertabsmenu.showsubmenu(cursubmenuobj);
             },mouseovertabsmenu.switchdelay);
     	     }, "mouseover");
      	 tablinks_count++;
      	 this.tabsmenutree[tabsmenuid].tabs.push(tablinks[i]); //add this tab to tab collection
      }
      else { //else for regular tab links (with no "rel" attribute)
      	 this.addEvent(tablinks[i], function(){mouseovertabsmenu.hidesubmenu(this._parentid)},"mouseover");
      }
    }
    
    this.addEvent(submenu,function(e){mouseovertabsmenu.clearswitchtimer()},"mouseover");
    
    //return position of selected tab (relative to its peers), or null
    var urlselected=this.urlparamselect(tabsmenuid);
    return typeof urlselected=="number"?urlselected:document.getElementById(urlselected)?document.getElementById(urlselected)._pos:selected;
  },
  
  showsubmenu:function(linkobj) {
  	 var tabsmenutree=this.tabsmenutree[linkobj._parentid];
  	 this.hidesubmenu(linkobj._parentid);
  	 var selected=parseInt(linkobj._pos);
  	 tabsmenutree.submenu_divs[selected].style.display="block";
  	 this.css(tabsmenutree.tabs[selected],"selected","add");
  	 tabsmenutree.submenu._prevselected=selected;
  },
  
  hidesubmenu:function(tabsmenuid) {
  	 var tabsmenutree=this.tabsmenutree[tabsmenuid];
  	 var prevselectedindex=tabsmenutree.submenu._prevselected;
  	 if(typeof prevselectedindex!="undefined") {
  		 tabsmenutree.submenu_divs[prevselectedindex].style.display="none";
  		 this.css(tabsmenutree.tabs[prevselectedindex], "selected", "remove");
  	 }
  },
  
  clearswitchtimer:function() {
  	 if(mouseovertabsmenu.switchtimer)	clearTimeout(mouseovertabsmenu.switchtimer);
  },
  
  css:function(el,targetclass,action) {
    var needle=new RegExp("(^|\\s+)"+targetclass+"($|\\s+)", "ig");
    if(action=="check")	return needle.test(el.className);
    else if(action=="remove") el.className=el.className.replace(needle,"");
    else if(action=="add" && !needle.test(el.className)) el.className+=" "+targetclass;
  },
  
  urlparamselect:function(tabsmenuid) {
  	 var result=window.location.search.match(new RegExp(tabsmenuid+"=(\\w+)", "i")); //check for "?tabsmenuid=id_or_pos_of_selected_tab" in URL
  	 var selectedtabstr=RegExp.$1;
  	 return /^\d+$/.test(selectedtabstr)? parseInt(selectedtabstr) : selectedtabstr; //return position or ID of selected tab (or null if niether found)
  },
    
  addEvent:function(target,functionref,tasktype) {
  	 if(target.addEventListener) target.addEventListener(tasktype, functionref, false);
  	 else if(target.attachEvent) target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)});
  },
  
  init:function(tabsmenuid,submenuid) {
  	 this.tabsmenutree[tabsmenuid]={}; 
  	 this.tabsmenutree[tabsmenuid].tabs=[]; //array referencing the active tab links in this menu (ones with a "rel=gotsubmenu" attr)
  	 this.tabsmenutree[tabsmenuid].submenu=null; //reference submenu DIV for this menu
  	 this.tabsmenutree[tabsmenuid].submenu_divs=[]; //array referencing the submenu contents (external DIVs with class="tabsmenucontent")
  	 var submenu=document.getElementById(submenuid);
  	 if(submenu==null) return;
  	 this.tabsmenutree[tabsmenuid].submenu=submenu; //remember this DIV as menu's submenu container
    var tabsmenutree=this.tabsmenutree[tabsmenuid];
    var innerdivs=tabsmenutree.submenu.getElementsByTagName("div");
    for(var i=0;i<innerdivs.length;i++) {
  			if(/tabsubmenu_content/i.test(innerdivs[i].className)) tabsmenutree.submenu_divs.push(innerdivs[i]);
    }
    var selected=this.initializetabs(tabsmenuid, submenuid, tabsmenutree.submenu_divs.length);
    if(selected!=null&&selected<tabsmenutree.submenu_divs.length) {
  			innerdivs[selected].style.display="block";
  			this.css(tabsmenutree.tabs[selected],"selected","add");
  			tabsmenutree.submenu._prevselected=selected;
  	 }
  }

}
//===========================================================================//
function addBookmark(str){
  if(str=='') str=window.location.href;
  if(document.all) window.external.AddFavorite(window.location.href,str);
  else alert('Press CTRL and D to add a bookmark to:\n"'+window.location.href+'".');
} 

function setHomepage(str){
  if(document.all) {
    document.body.style.behavior='url(#default#homepage)';
    document.body.setHomePage(window.location.href);
  }
  else alert('To set this as your homepage drag and drop the icon to the home button.');
} 

function reportAbuse(CHATID) {
  yn=confirm('Are you absolutely sure this statement contains\nabusive language and you want to report it?');
  if(yn==true) window.location.href='/report-abuse.php?id='+CHATID;
}

function searchOn(FRM,BTN) {window.document.forms[FRM].elements[BTN].style.backgroundColor="#DE0608";}
function searchOff(FRM,BTN) {window.document.forms[FRM].elements[BTN].style.backgroundColor="#A90000";}
function imageSwap(IMG,SRC) {window.document.images[IMG].src=SRC;}

function buttonOn(FRM,BTN) {
  window.document.forms[FRM].elements[BTN].style.color = "#0B00E0";
  window.document.forms[FRM].elements[BTN].style.backgroundImage = "url(theme/but_over.gif)";
  window.document.forms[FRM].elements[BTN].style.borderColor = "#9B96FA";
}

function buttonOff(FRM,BTN) {
  window.document.forms[FRM].elements[BTN].style.color = "#E000E0";
  window.document.forms[FRM].elements[BTN].style.backgroundImage = "url(theme/but.gif)";
  window.document.forms[FRM].elements[BTN].style.borderColor = "#FA96FA";
}

function buttonDisable(FRM,BTN) {
  if(window.document.forms[FRM].elements[BTN].disabled==true) return;
  window.document.forms[FRM].elements[BTN].disabled=true;
  window.document.forms[FRM].elements[BTN].style.color = "#808080";
  window.document.forms[FRM].elements[BTN].style.backgroundImage = "url(theme/but_disable.gif)";
  window.document.forms[FRM].elements[BTN].style.borderColor = "#808080";
  window.document.forms[FRM].elements[BTN].style.cursor="pointer";
}

function buttonEnable(FRM,BTN) {
  if(window.document.forms[FRM].elements[BTN].disabled==false) return;
  window.document.forms[FRM].elements[BTN].disabled=false;
  buttonOff(FRM,BTN);
}

//Call in first 10 seconds with setTimeout()
function callAjaxAlert1() {
  ajaxpack.get("/process/alert.php","ajax_alert");
  setInterval("callAjaxAlert2()",1000*60*3); //Then call every 3 mins after
}

function callAjaxAlert2() {ajaxpack.get("/process/alert.php","ajax_alert");}

//Get Flash movie object by ID, or any other ID?
function getId(nm) {return document.getElementById(nm);}

function getSwf(nm) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE)?window[nm]:document[nm];
}
//===========================================================================//
