function addEvent(elm, evType, fn, useCapture) {
// cross-browser event handling for IE5+, NS6 and Mozilla 
// By Scott Andrew
	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; 
	}
}


/**********************************************************************
The node can simply be document if you want to search the whole 
document or you can pass it a result from getElementById (for example).

The searchClass parameter is the name of the class you want to match.

The tag parameter allows you to restrict the search to a specific tag. 
You can simply use the wildcard (“*”) to search all tags.
**********************************************************************/
function getElementsByClass(node,searchClass,tag) {
 var classElements = new Array();
 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;
}

/**********************************************************************
pop up window
**********************************************************************/
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height, resizable, scrollbars) {
	if(popUpWin) {
		if(!popUpWin.closed) popUpWin.close();
	}
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,copyhistory=yes'
											+ ',width='+width
						  					+ ',height='+height
						  					+ ',resizable=' + ((resizable) ? 'yes' : 'no')
											+ ',scrollbars=' + ((scrollbars) ? 'yes' : 'no')
											);
  	popUpWin.focus();
}

/**********************************************************************
Set a cookie
**********************************************************************/
function setCookie(name, value, days) {
	if (!days) days = 365; // default to 365 days if empty
	
	var expdate = new Date();
	expdate.setTime(expdate.getTime() + days*24*60*60*1000);
	
	document.cookie = name + "=" + escape(value) + "; expires=" + expdate.toGMTString();
}

/**********************************************************************
Erase a cookie
**********************************************************************/
function eraseCookie(name) {
	setCookie(name,'',-1);
}

/*********************************************************************
returns a UNIX timestamp
**********************************************************************/
function convertToTimestamp(d,m,y)  {
    var humDate = new Date(Date.UTC(y, (m-1), d, 0,0,0));
    return (humDate.getTime()/1000.0);
  }
  
/*********************************************************************
Equivalient of PHP's in_array function
**********************************************************************/
function in_array(needle, haystack){
	for (var x = 0; x < haystack.length; x++ ) {
		if ( haystack[x] == needle ) return true;
	}
	return false;
}
	 