calArray = [];
function makeReqObj()
{
	if (window.XMLHttpRequest) return new XMLHttpRequest();
	else return new ActiveXObject("Microsoft.XMLHTTP");
}
function sendRequest(method, url, postdata, callback)
{
	var request = makeReqObj();
	request.open(method, url, true);
	if (method == "post") request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	request.onreadystatechange = function() { try { request.status; } catch (e) { return; } callback(request); };
	request.send(postdata);
	return request;
}

function deserialise(text)
{
	return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
		   text.replace(/"(\\.|[^"\\])*"/g, ''))) &&
		   eval('(' + text + ')');
}

// for debugging
function dump(obj)
{
	var s = "";
	for (var a in obj) s += a + ": " + obj[a] + ",";
	alert("{" + s + "}");
}

// Assigns event handlers and unhooks them on unload
var handle = function() {
	var events = [];
	window.onunload = function() {

		if(events.lengths > 0)
		{
			for (var i in events)
			{
				events[i][0][events[i][1]] = null;
			}
		}

		events = null;
	}
	return function(target, event, func) {
		target[event] = func;
		events[events.length] = [target, event];
	}
}();

function addonload(f) {
	var x = window.onload;
	if (x) window.onload = function() { x(); f(); }
	else handle(window, "onload", f);
}

function absLocate(obj)
{
	var left = 0, top = 0;
	do
	{
		left += obj.offsetLeft;
		top += obj.offsetTop;
	}
	while (obj = obj.offsetParent);
	return [left, top];
}
function getViewport()
{
	var x, y, w, h;
	if (self.pageYOffset)
	{ x = self.pageXOffset; y = self.pageYOffset; }
	else if (document.documentElement && document.documentElement.scrollTop)
	{ x = document.documentElement.scrollLeft; y = document.documentElement.scrollTop; }
	else if (document.body)
	{ x = document.body.scrollLeft; y = document.body.scrollTop; }
	if (self.innerHeight)
	{ w = self.innerWidth; h = self.innerHeight; }
	else if (document.documentElement && document.documentElement.clientHeight)
	{ w = document.documentElement.clientWidth; h = document.documentElement.clientHeight; }
	else if (document.body) // other Explorers
	{ w = document.body.clientWidth; h = document.body.clientHeight; }
	return [x, y, w, h];
}


function isAncestorOrSelfOf(x, y)
{
	while (y)
	{
		if (x == y) return true;
		y = y.parentNode;
	}
	return false;
}

function getPostString(elem, additional)
{
	var vals = additional || [];
	var types = ["input", "select", "textarea"];
	for (var typeIndex in types)
	{
		var type = types[typeIndex];
		var inputs = elem.getElementsByTagName(type);
		for (var i = 0; i < inputs.length; ++i)
		{
			var inp = inputs[i];
			if (inp.name && (type != "input" || inp.type != "checkbox" && inp.type != "radio" || inp.checked))
				vals.push(escape(inputs[i].name) + "=" + escape(inputs[i].value));
		}
	}
	return vals.join("&");
}

function showTempMessageAt(obj, message, pos, duration, d)
{
	if (duration == undefined) duration = 3000;

	var xy = absLocate(obj);
	var div = document.body.appendChild(document.createElement("div"));
	div.appendChild(document.createTextNode(message));
	div.className = "popup-msg";
	div.style.position = "absolute";

	if (pos == undefined || pos == "right")
	{
		div.style.left = (xy[0] + obj.offsetWidth + (d ? d[0] : 0)) + "px";
		div.style.top = xy[1] + (d ? d[1] : 0) + "px";
	}
	else if (pos == "under")
	{
		div.style.left = xy[0] + (d ? d[0] : 0) + "px";
		div.style.top = (xy[1] + obj.offsetHeight + (d ? d[1] : 0)) + "px";
	}

	var obj = {div: div, alive: true, kill: function() { if (obj.alive) { document.body.removeChild(obj.div); } obj.alive = false; }};
	if (duration != -1) window.setTimeout(obj.kill, duration);
	return obj;
}

function mousePos(e)
{
	if (e.pageX || e.pageY) return [e.pageX, e.pageY];
	return [e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft,
			e.clientY + document.body.scrollTop + document.documentElement.scrollTop];
}

function addClass(obj, className)
{
	obj.className += " " + className;
}

function delClass(obj, className)
{
	var klass = " " + obj.className + " ";
	klass = klass.replace(" " + className + " ", " ");
	obj.className = klass.substr(1, klass.length - 1);
}

function hasClass(obj, className)
{
	return obj.className.search(new RegExp("\\b"+className.replace("-", "\\-")+"\\b")) != -1;
}

function disableTextSelection()
{
	document.documentElement.ondrag = function () { return false; };
	document.documentElement.onselectstart = function () { return false; };
	addClass(document.body, "no-select");
}

function enableTextSelection()
{
	document.documentElement.ondrag = null;
	document.documentElement.onselectstart = null;
	delClass(document.body, "no-select");
}

function removedefaultonfocus(sender, msg)
{
	if (sender.value == msg) sender.value = "";
}
function adddefaultonblur(sender, msg)
{
	if (sender.value == "") sender.value = msg;
}

function changesearchtype(type)
{
	var lasttype = document.getElementById("_lastet").value;
	if (type == lasttype) return;
	if (location.search.match(/(\?|&)et=[123]/))
		location.search = location.search.replace(/(\?|&)et=[123]/, "$1et="+type);
	else if (location.search.match(/\?/))
		location.search = location.search + "&et="+type;
	else
		location.search = location.search + "?et="+type;
}

function preserveSearch(sender)
{
	var searchForm = document.getElementById("searchForm");
	if (!searchForm) return;

	var container = sender.firstChild;
	while (container.lastChild) container.removeChild(container.lastChild);

	sender.schStr.value = getPostString(searchForm);
}

function uncheckAll(id)
{
	var elem = typeof(id) == "string" ? document.getElementById(id) : id;
	var inputs = elem.getElementsByTagName("input");
	for (var i = 0; i < inputs.length; ++i)
		if (inputs[i].type == "checkbox") inputs[i].checked = false;
}

function sethash(hash)
{
	// Attempt to change the location hash without creating a new history entry, so using location.replace() (Opera creates one anyway -- oh well)
	// IE 6 and 7 seem to incorrectly process HTML entities here (&reg, even without a semicolon, gets translated)
	// Fortunately, IE doesn't create a history entry if I reassign location.hash, so it works out
	if (navigator.userAgent.indexOf("MSIE") != -1 && navigator.userAgent.indexOf("Opera") == -1)
		location.hash = hash;
	else
	{
		var x = location.href, y = x.indexOf("#");
		if (y != -1) x = x.substr(0, y);
		x = x + '#' + hash;
		location.replace(x);
	}
}

function clearKeywordSearchBox(that, deffieldins) { if (that.value == deffieldins) { that.value = ""; delClass(that, "kw-default"); } }
function reInstructKeywordSearchBox(that, deffieldins) { if (that.value == "") { that.value = deffieldins; addClass(that, "kw-default"); } }
function checkValueOfField(fieldid, deffieldins) { return (document.getElementById(fieldid).value != deffieldins); }

var addthis_config = { data_use_flash: false };