String.prototype.comma_list_search=function(searched_string){
	var value_list = this.split(",");
	var found = false;
	
	for (var i = 0; i < value_list.length; i++) {
		if (value_list[i].trim() == searched_string) {
			found = true;
			break;
		}
	}
	
	return found;
}

String.prototype.trim=function(){
    return this.replace(/^\s*|\s*$/g,'');
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


function addLoadListener(fn)
{
	if (typeof window.addEventListener != 'undefined')
	{
		window.addEventListener('load', fn, false);
	}
	else if (typeof document.addEventListener != 'undefined')
	{
		document.addEventListener('load', fn, false);
	}
	else if (typeof window.attachEvent != 'undefined')
	{
		window.attachEvent('onload', fn);
	}
	else
	{
		var oldfn = window.onload;
		if (typeof window.onload != 'function')
		{
			window.onload = fn;
		}
		else
		{
			window.onload = function()
			{
				oldfn();
				fn();
			};
		}
	}
}


function attachEventListener(target, eventType, functionRef, capture)
{
	if (typeof target.addEventListener != "undefined")
	{
		target.addEventListener(eventType, functionRef, capture);
	}
	else if (typeof target.attachEvent != "undefined")
	{
		target.attachEvent("on" + eventType, functionRef);
	}
	else
	{
		eventType = "on" + eventType;

		if (typeof target[eventType] == "function")
		{
			var oldListener = target[eventType];

			target[eventType] = function()
			{
				oldListener();
				return functionRef();
			}
		}
		else
		{
			target[eventType] = functionRef;
		}
  	}

	return true;
}

window.onload = function() {
	// check to see that the browser supports the getElementsByTagName method
	// if not, exit the loop
	if (!document.getElementsByTagName) {
		return false;
//		// Manual labour
//		var popuplinks = getElementsByClass("popup");
//		// loop through each of these links (anchor tags)
//		for (var i=0; i < popuplinks.length; i++) {
//			// if the popuplink is an anchor indeed
//			if (popuplinks[i].getElement() == "a") {
//				// add an onclick event on the fly to pass the href attribute
//				// of the link to our second function, openPopUp
//				popuplinks[i].onclick = function() {
//				openPopUp(this.getAttribute("href"));
//				return false;
//				}
//			}
//		}
	}
	
	// create an array of objects of each link in the document
	var popuplinks = document.getElementsByTagName("a");
	// loop through each of these links (anchor tags)
	for (var i=0; i < popuplinks.length; i++) {
		// if the link has a class of "popup"...
		if (popuplinks[i].getAttribute("class") == "popup" || popuplinks[i].className == "popup") {
			// add an onclick event on the fly to pass the href attribute
			// of the link to our second function, openPopUp
			popuplinks[i].onclick = function() {
			openPopUp(this.getAttribute("href"));
			return false;
			}
		}
	}
	return false;
}

function openPopUp(linkURL) {
	window.open(linkURL,'popup','width=640,height=480,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no');
}
