var IE = document.all?true:false;
var makeVars = new Array("type","id","className","innerHTML");
function get(val){return document.getElementById(val);}
function echo(val){document.write(val);}
function rndInt(lo,hi){return Math.floor(Math.random()*hi+1)+lo;}
function def(key,val){if(typeof(key)=='undefined')key=val;return key;}
function make(val){
	if(typeof(val)!='object')
		return document.createElement(def(val, 'div'))
	var tmp = document.createElement(def(val['type'], 'div'));
	for(var i=1;i<makeVars.length;i++)
		if(def(val[makeVars[i]], '')!='') eval("tmp."+makeVars[i]+" = '"+val[makeVars[i]]+"'");
	return tmp;
}
function setClass(id, name){
	if(IE) id.setAttribute('className', name);
	else id.setAttribute('class', name);
}
function alignBottom(div1, div2){
	if(div1.offsetHeight>div2.offsetHeight){
		div2.style.height = (div1.offsetHeight)+'px';
		div1.style.height = (div1.offsetHeight)+'px';
	}
	else{
		div1.style.height = (div2.offsetHeight)+'px';
		div2.style.height = (div2.offsetHeight)+'px';
	}
}

//auto page refresh//
//var RefreshID = 0;
//function startRefresh(seconds){RefreshID = setInterval("window.location.reload()",(seconds*1000));}
//function stopRefresh(){clearInterval(RefreshID);}
var RefreshID = 0;
function startRefresh(seconds){if (!location.href.match(/[0-9]{9,14}/) && !location.href.match(/\?/)){RefreshID=setInterval("window.location.href=window.location.href+'?build=refresh';",seconds*1000);}}
function stopRefresh(){clearInterval(RefreshID);}

//URL-related functions//
function getURLVar(urlVarName){var urlHalves = String(document.location).split('?');var urlVarValue = '';if(urlHalves[1]){var urlVars = urlHalves[1].split('&');for(i=0; i<=(urlVars.length); i++){if(urlVars[i]){var urlVarPair = urlVars[i].split('=');if (urlVarPair[0] && urlVarPair[0] == urlVarName)urlVarValue = urlVarPair[1];}}}return urlVarValue;}
function URLEncode(plaintext){var SAFECHARS="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.!~*'()";var HEX = "0123456789ABCDEF";var encoded = "";for (var i = 0; i < plaintext.length; i++ ) {var ch = plaintext.charAt(i);if (ch == " ") {encoded += "+";}else if (SAFECHARS.indexOf(ch) != -1) {encoded += ch;}else {var charCode = ch.charCodeAt(0);if (charCode > 255) {alert( "Unicode Character '"+ch+"' cannot be encoded using standard URL encoding.\n (URL encoding only supports 8-bit characters.)\n A space (+) will be substituted." );encoded += "+";} else {encoded += "%";encoded += HEX.charAt((charCode >> 4) & 0xF);encoded += HEX.charAt(charCode & 0xF);}}}return encoded;}
function URLDecode(encoded){var HEXCHARS = "0123456789ABCDEFabcdef";var plaintext = "";var i = 0;while (i < encoded.length) {var ch = encoded.charAt(i);if (ch == "+") {plaintext += " ";i++;} else if (ch == "%") {if (i < (encoded.length-2)&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 && HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {plaintext += unescape( encoded.substr(i,3) );i += 3;} else {alert( 'Bad escape combination near ...' + encoded.substr(i) );plaintext += "%[ERROR]";i++;}} else {plaintext += ch;i++;}}return plaintext;}

//AJAX queue handling//
var Qjax = new function(){
	this.locked = false;
	this.queue = new Array();
	this.add = function(div, url, params, type){
		type=def(type,"post");
		this.queue[this.queue.length] = Object({div:div, url:url, params:params, type:type});
		if(!this.locked)
			this.startLoop();
	};
	this.startLoop = function(){
		this.locked = true;
		this.request(this.queue[0]['div'], this.queue[0]['url'], this.queue[0]['params'], this.queue[0]['type']);
		this.queue = this.queue.slice(1);
	};
	this.loop = function(){
		if(this.queue.length==0)
			this.locked = false;
		else{
			this.request(this.queue[0]['div'], this.queue[0]['url'], this.queue[0]['params'], this.queue[0]['type']);
			this.queue = this.queue.slice(1);
		}
	}
	this.request = function(div, url, params, type){
		if(window.XMLHttpRequest)
			a=new XMLHttpRequest();
		else if(window.ActiveXObject)
			a=new ActiveXObject("Microsoft.XMLHTTP");
		a.open(type,url,true);
		a.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		a.setRequestHeader("Content-length", params.length);
		a.setRequestHeader("Connection", "close");
		a.onreadystatechange=function(){
			if(a.readyState==4){
				Qjax.sethtml(div,a.responseText);
				Qjax.loop();
			}
		};
		a.send(params);
	};
	this.sethtml =function(div,content){ 
		search = content; 
		while(script = search.match(/(<script[^>]+javascript[^>]+>\s*(<!--)?)/i)){ 
			search = search.substr(search.indexOf(RegExp.$1) + RegExp.$1.length); 
			if (!(endscript = search.match(/((-->)?\s*<\/script>)/))) break; 
			block = search.substr(0, search.indexOf(RegExp.$1)); 
			search = search.substring(block.length + RegExp.$1.length); 
			oScript = document.createElement('script'); 
			oScript.text = block; 
			document.getElementsByTagName("head").item(0).appendChild(oScript); 
		}
		document.getElementById(div).innerHTML=content; 
	};
};
//Comment related function//
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
}
else {	// grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
}	
if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}
get('flagComment').style.left = (tempX-250)+'px';
get('flagComment').style.top = (tempY-190)+'px';
return true;
}

//processes last-chance actions before user leaves a page//
var unload = new Array();
function processUnload(){
	for(var i=0;i<unload.length;i++)
		eval(unload[i]);
}
//processes last-chance actions before user leaves a page//
var postload = new Array();
function processLoad(){
	for(var i=0;i<postload.length;i++)
		eval(postload[i]);
}




