// .-==================================================================
// .	FusionBB Version 2.2
// .
// .	Created August 20, 2003 by InteractivePHP
// .
// .	All scripts and files used by this program
// .	are copyright InteractivePHP, Inc
// .	For discussion, bug reports and updates
// .	visit http://www.FusionBB.com
// .
// .	You may not redistribute this program in any form, without
// .	express written permisson from InteractivePHP.
// .
// .	WARNING: If you modify any scripts within FusionBB
// .	you will be unable to obtain official support.
// .	Modify at your own risk!
// .
// .	FusionBB Copyright 2003-2007, InteractivePHP, Inc
// .-==================================================================
// .	$Date: 2008/05/15 17:26:41 $	$Author: couch $
// .	$RCSfile: fusionbb_main.js,v $	$Revision: 1.5 $
// .-==================================================================
// .	File Description:
// .		Main Javascript used by FusionBB
// .-==================================================================

function breakFrame(){
	if (top.location != location) {
		top.location.href = document.location.href ;
	}
}

function loadShoutBox(url) {
	if (document.getElementById('shoutbox')) {
		document.getElementById('shoutbox').src=url;
	}
}

function setCookie(name, value) {
	var date = new Date();
	var expire = date.getTime();
	expire += 1000 * cookieexpire;
	date.setTime(expire);
	document.cookie = cookieprefix + name + "=" + escape(value) + "; expires=" + date.toGMTString() + "; path=" + cookiepath + "; domain=" + cookiedomain;
}

function toggleDisplay(id) {
	var cat = document.getElementById("cat-" + id);
	cname = 'cat-'+id;
	var name = 'img-' + id;
	if (cat.style.display != "") {
		cat.style.display="";
		document.images[name].src = collapse.src;
		setCookie(cname, 1);
	}
	else {
		cat.style.display = "none";
		document.images[name].src = expand.src;
		setCookie(cname, 0);
	}
}

function toggleSection(id) {
	var cat = document.getElementById("section-" + id);
	cname = 'section-'+id;
	var name = 'img-' + id;
	if (cat.style.display != "") {
		cat.style.display="";
		document.images[name].src = collapse.src;
	}
	else {
		cat.style.display = "none";
		document.images[name].src = expand.src;
	}
}


function QuickReply(id) {
	var cat = document.getElementById("section-1");
	var name = 'img-1';
	obj = document.post;
	obj.pid.value = document.getElementById('pid-' + id).innerHTML;

	if (cat.style.display != "") {
		cat.style.display="";
		document.images[name].src = collapse.src;
	}
}

function unread_pt(text,sess,fullurl) {
	if (confirm(text)) { // Take them to the Private Topic Page
		window.location=""+fullurl+"/listpt.php?"+sess;
	}
}


var lastid = '';
var gotclick = 0;
function toggleClick() {
	if (gotclick == 1) {
		gotclick = 0;
	}
	else {
		gotclick = 1;
	}
}
function hideCheck() {
	if (lastid != '' && lastid != null && gotclick == 1) {
		document.getElementById(lastid).style.visibility = "hidden";
		lastid = '';
		gotclick = 0;
	}
}
function showCheck(id) {
	if (lastid != id && gotclick == 1) {
		document.getElementById(lastid).style.visibility = "hidden";
		lastid = id;
		document.getElementById(id).style.visibility = "visible";
	}
}
function showMenu(id) {
	if (lastid != id) {
		if (lastid != '' && lastid != null) {
			document.getElementById(lastid).style.visibility = "hidden";
		}
		lastid = id;
		gotclick = 1;
		document.getElementById(id).style.visibility = "visible";
	}
	else {
		lastid = '';
		gotclick = 0;
		document.getElementById(id).style.visibility = "hidden";
	}
}
function showHide(id) {
	var obj = document.getElementById(id);
	if (obj) {
		if (obj.style.display == "") {
			obj.style.display = "none";
			setCookie('sbar', 'none');
		}
		else {
			obj.style.display = "";
			setCookie('sbar', ';');
		}
	}
}
document.onmousedown = hideCheck;











/* ===========================================================
   Below is the begining of how we need to do javascript. It's
   more object based and contained within it's own class. This
   keeps it from getting into conflicts with other javascsript
   the end user may add to their forums. (less support tickets
   are a good thing) :D
   =========================================================== */
FBB = {
	eventList: [], eventNum: 0, xmlHttp: false, eventUse: true, reqVars: [], reqVarsNum: 0, reqPending: false, statusOpen: true, navStore: '',
	logInOut: function() {
		if (FBB.statusOpen) {
			FBB.ajaxRequest('GET','./ajax/login.php');// need to import $conf['full_url'] here
		} else {
			return false;
		}
	},
	ajaxOpen: function() {
		if (window.XMLHttpRequest) { // mozilla, safari, konqueror... and ie 7?
			FBB.xmlHttp = new XMLHttpRequest();
		} else if (window.ActiveXObject) { // ie
			var axTypes = ['MSXML2.XMLHTTP','Microsoft.XMLHTTP','MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0'];
			for (i=0; i<axTypes.length; i++) {
				try {
					FBB.xmlHttp = new ActiveXObject(axTypes[i]);
					break;
				} catch (e) {
					// do nothing
				}
			}
		}
	},
	ajaxAddVar: function(type, name, val) {
		FBB.reqVars[FBB.reqVarsNum] = [name, val];
		FBB.reqVarsNum++;
	},
	ajaxRequest: function(type, url) {
		if (!FBB.reqPending) {
			FBB.reqPending = true;
			var post_data = null;
			if (type == 'GET') {
				var qString = '?ajax/1';
				for(i=0; i<FBB.reqVars.length; i++) {
					qString += '/'+FBB.reqVars[i][0]+'/'+escape(FBB.reqVars[i][1]);
				}
				url += qString;
			} else {
				var qString = 'ajax=1';
				for(i=0; i<FBB.reqVars.length; i++) {
					qString += '&'+FBB.reqVars[i][0]+'='+escape(FBB.reqVars[i][1]);
				}
			}
			FBB.xmlHttp.open(type, url, true);
			if (type == 'POST') {
				post_data = qString;
				FBB.xmlHttp.setRequestHeader('Method', 'POST ' + url + ' HTTP/1.1');
				FBB.xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				FBB.xmlHttp.setRequestHeader('Content-Length', qString.length);
				FBB.xmlHttp.setRequestHeader('Connection', 'close');
			}
			FBB.xmlHttp.onreadystatechange = FBB.ajaxProcess;
			FBB.navStore = document.getElementById('navsubs').innerHTML;
			document.getElementById('navsubs').innerHTML = document.getElementById('OneMoment').innerHTML;
			FBB.xmlHttp.send(post_data);
			FBB.reqVars = [];
			FBB.reqVarsNum = 0;
		}
	},
	ajaxClearResponse: function() {
		document.getElementById('AjaxContent').innerHTML = '';
		// add in busy graphic removal here
		FBB.reqPending = false;
	},
	ajaxParseResponse: function() {
		var node = document.getElementById('AjaxResponse');
		if (node) {
			if (node.childNodes.length) {
				for (i=0; i<node.childNodes.length; i++) {
					subnode = node.childNodes[i].className.split(' ');
					var innercontent = node.childNodes[i].innerHTML;
					node.childNodes[i].innerHTML = '';
					if (subnode.length == 2) {
						if (subnode[0] == 'inner') {
							document.getElementById(subnode[1]).innerHTML = innercontent;
						} else if (subnode[0] == 'value') {
							document.getElementById(subnode[1]).value = innercontent;
						} else if (subnode[0] == 'action') {
							eval(innercontent);
						}
					}
				}
			}
		}
		document.getElementById('navsubs').innerHTML = FBB.navStore;
		FBB.ajaxClearResponse();
	},
	ajaxProcess: function() {
		if (FBB.xmlHttp.readyState == 4) {
			//alert('got status:'+FBB.xmlHttp.status);// debug
			if (FBB.xmlHttp.status == 200) {
				document.getElementById('AjaxContent').innerHTML = FBB.xmlHttp.responseText;
				setTimeout('FBB.ajaxParseResponse()',200);// this gives the dom time to recognize the ajax supplied html code
			} else if (FBB.xmlHttp.status == 403) {
				// do something to let them know
				// they failed to login via http auth
				FBB.ajaxClearResponse();
			} else {
				FBB.ajaxClearResponse();
			}
		}
	},
	init: function() {
		var loginoutLink = document.getElementById('loginout');
		if (loginoutLink.innerHTML && FBB.eventUse) {
			FBB.ajaxOpen();
			if (FBB.xmlHttp) {
				loginoutLink.href = 'javascript:FBB.logInOut()';
			}
		}
	},
	addEvent: function(node, type, func, capt) {
		if (document.getElementById && FBB.eventUse) {
			if (node.addEventListener) {
				node.addEventListener(type, func, capt);
				return true;
			} else if (node.attachEvent) {
				var val = node.attachEvent('on' + type, func);
				FBB.eventList[FBB.eventNum] = [node, type, func, capt];
				FBB.eventNum++;
				return val;
			} else {
				FBB.eventUse = false;
			}
		}
	},
	remEvents: function() {
		for(i=0; i<FBB.eventNum; i++){
			if(FBB.eventList[i][0].removeEventListener){
				FBB.eventList[i][0].removeEventListener(FBB.eventList[i][1], FBB.eventList[i][2], FBB.eventList[i][3]);
			}
			FBB.eventList[i][1] = 'on' + FBB.eventList[i][1];
			if(FBB.eventList[i][0].detachEvent){
				FBB.eventList[i][0].detachEvent(FBB.eventList[i][1], FBB.eventList[i][2]);
			}
			FBB.eventList[i][0][FBB.eventList[i][1]] = null;
		}
	}
}
// Got to hold off a bit while I bring everything else in.
//FBB.addEvent(window, 'load',  FBB.init, false);
//FBB.addEvent(window, 'unload', FBB.remEvents, false);

var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

// open hidden layer
function mopen(id){	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose(){
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime(){
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime(){
	if(closetimer)	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 
