function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else {
		elm['on' + evType] = fn;
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

//This function is for opening pop up windows. Added by Osman on Feb 23, 2008
function popUp(targetUrl,QryString,Resizable,width,height)
{
	lPos = (window.screen.width - width) / 2;
	tPos = (window.screen.height - height) / 2;
	popUpPage = window.open(targetUrl + "?" + QryString, "popUpPage","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable="+ Resizable +",width="+ width +",height=" + height + ",top=" + tPos + ",left=" + lPos);
	popUpPage.focus();
}

//Checks & Unchecks checkboxes filtered by names
function checkUncheckAll(theElement,filter) {
	var theForm = theElement.form, z = 0;
 	for(z=0; z<theForm.length;z++){
		var str = theForm[z].name;
     	if(theForm[z].type == 'checkbox' && str.indexOf(filter) >= 0){
  			theForm[z].checked = theElement.checked;
  		}
    }
}

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 toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

function insertAfter(parent, node, referenceNode) {
	parent.insertBefore(node, referenceNode.nextSibling);
}

/* RJV - 06.02.09 - Moved in from checkout code */
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
	{
		if(popUpWin)
			{
			if(!popUpWin.closed) popUpWin.close();
			}
	  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=auto,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	  return false;
	}

function popupCC(myform, windowname)
{
	if (! window.focus)return true;
	 		window.open('', windowname, 'height=800,width=800,scrollbars=yes');
		myform.target=windowname;
	return true;
}

function checkEmail(thisForm) {
	if (emailAddress_isFormatValid(thisForm.email.value) == false) {
		alert('Invalid Email address');
		return false;
		}
	else return true;
	}

function emailAddress_isFormatValid(emailAddress,allowMultiple,allowEmpty)
	{
	if (allowMultiple) // returns true with one or more white-space (space, tab, etc.), semi-colon(;) or comma(,) delimited email addresses
		if (allowEmpty && emailAddress.search(/[^\s;,]/)<0)
			return true;
		else
		return (emailAddress.search(/((^|[\s;,])[\s;,]*[\w-'\.]+@((([a-zA-Z0-9]+(-+[a-zA-Z0-9]+)*\.)+[a-zA-Z]{2,})|((((25[0-5])|(2[0-4]\d)|(([01]?\d)?\d))\.){3}((25[0-5])|(2[0-4]\d)|(([01]?\d)?\d)))))+[\s;,]*$/)==0);
	else // returns true with one and only one email address
		if (allowEmpty && emailAddress.search(/\S/)<0)
			return true;
		else
	   return (emailAddress.search(/^\s*[\w-'\.]+@((([a-zA-Z0-9]+(-+[a-zA-Z0-9]+)*\.)+[a-zA-Z]{2,})|((((25[0-5])|(2[0-4]\d)|(([01]?\d)?\d))\.){3}((25[0-5])|(2[0-4]\d)|(([01]?\d)?\d))))\s*$/)==0);
	}

Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
	
	function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}
};
