function addEvent(obj, type, func, useCapture) {
	if (obj.addEventListener) {
		obj.addEventListener(type, func, useCapture);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent('on'+type, func);
		return r;
	} else {
		obj['on'+type] = func;
	}
}

function stopPropagation(event) {
	if (window.event) {
		window.event.cancelBubble = true;
	} else if (event) {
		event.stopPropagation();
	}
}

function preventDefault(event) {
	if (window.event) {
		window.event.returnValue = false;
	} else if (event) {
		event.preventDefault();
	}
}

function hashToQueryString(hash) {
	if (hash == null) {
		return "";
	}
	var queryArray = [];
	for (var prop in hash) {
		if (hash[prop] == '#')
			queryArray.push(prop);
		else
			queryArray.push(prop + "=" + escape(hash[prop]));
	}
	return queryArray.join("&");
}

function queryStringToHash(qString) {
	//note: IE won't let you overwrite the parameters passed to functions
	var queryString = qString;
	if (queryString.charAt(0) == '#')
		queryString = queryString.substring(1,queryString.length);
	if (queryString.match(/^\s*$/))
		return {};
	var hash = {};
	var pairs = queryString.split('&');
	for (var i = 0; i < pairs.length; i++) {
		var pair = pairs[i].split('=');
		var key = pair[0];
		var value = '#';
		if (pair.length > 1)
			value = unescape(pair[1]);
		hash[key] = value;
	}
	return hash;
}

/**
ajaxSend - convenience function for sending AJAX HTTP requests
	(required parameters are method, url, hash, and callback)
	
	Requires import of Sarissa library (scripts/sarissa.js)

Parameters:
method = GET or POST (determines how contents of 'hash' are sent)
url - the URL of the page from which the response will be received
	(asynchronously)
hash - a typical JS property list mapped to key/value
	pairs in a GET/POST query string (may be null) 
callback - a function to call with the resulting XML document object
	if the response is received successfully

isAsync - 'true' if request is to be sent asynchronously; 'false'
	otherwise (defaults to 'true')
returnType - 'XML' or 'Text' (case insensitive) to determine whether
	responseXML or responseText is returned (defaults to 'text')
*/
function sendAJAXRequest(method, url, hash, callback,
				  isAsync, returnType) {
	var type = 'text';
	if (typeof returnType != 'undefined') {
		type = returnType.toLowerCase();
		if (type != 'text' && type != 'xml') {
			return;
		}
	}
	var async = true;
	if (typeof isAsync != 'undefined') {
		async = isAsync;
	}
	var xmlHttp = new XMLHttpRequest();
	var queryString = hashToQueryString(hash);
	if (method == 'POST') {
		xmlHttp.open('POST', url, async);
		xmlHttp.setRequestHeader('Content-Type', 
		 'application/x-www-form-urlencoded');
	}
	else if (method == 'GET') {
		var getURL = url;
		if (queryString != "") {
			getURL += "?" + queryString;
		}
		xmlHttp.open('GET', getURL, async);
	}
	else {
		return;
	}
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
			if (type == 'text') {
				callback(xmlHttp.responseText, xmlHttp.status);
			}
			else {
				callback(xmlHttp.responseXML, xmlHttp.status);
			}
		}
	}
	//alert(url + "?" + queryString)
	var postQuery = (method == 'POST') ? queryString : null;
	xmlHttp.send(postQuery);
}

function sendTextRequest(method,url,hash,callback,async) {
	sendAJAXRequest(method,url,hash,callback,async,'text');
}

function sendXMLRequest(method,url,hash,callback,async) {
	sendAJAXRequest(method,url,hash,callback,async,'xml');
}

// updated by Tim Eichner (5/18/06) with test condition
function show(element_id, display_type) {
	if (document.getElementById(element_id))
		document.getElementById(element_id).style.display = display_type;
}

// updated by Tim Eichner (5/18/06) with test condition
function hide(element_id) {
	if (document.getElementById(element_id))
		document.getElementById(element_id).style.display = "none";
}

function change_content(element_id, changed_content) {
	document.getElementById(element_id).innerHTML = changed_content;
}

function popup(filename, width, height) {
	var center_left = (screen.width/2) - width/2;
	var center_top = (screen.height/2) - height/2;
	var filename_array = filename.split(".");
	z = window.open(filename, filename_array[0], 'width=' + width + ',height=' + height + ',left=' + center_left + ',top=' + center_top + ',scrollbars=yes,resizable=yes');
	z.focus();
}

function rand() {
	var randomNumber = Math.floor(Math.random() * 9999999);
	return randomNumber;
}