/* ------------------------------------------------------------------------------ */
	/*
	
		project:				Project_Title
		file: 					common.js
		creator:				Creator_Info
		creation date:	2007-01-07
		copyright:			(c) 2007 __Company_Name__. All rights reserved.
	
	*/
/* ------------------------------------------------------------------------------ */

/* ------------------------------------------------------------------------------ */
	/*
	
		File Layout
		
		1.0 addEvent
		2.0 getElementsByClass
		3.0 Toggle
		4.0 Cookies
		5.0 getElement
		6.0 Misc
		
	*/
/* ------------------------------------------------------------------------------ */

/* =1.0 addEvent
   --------------------------------------------------------------------*/
function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}
	
var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();
addEvent(window,'unload',EventCache.flush);

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

/* =1.0 addEvent End
   --------------------------------------------------------------------*/

/* =2.0 getElementsByClass
   --------------------------------------------------------------------*/

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;
}

/* =2.0 getElementsByClass End
   --------------------------------------------------------------------*/

/* =3.0 Toggle
   --------------------------------------------------------------------*/
function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

/* =3.0 Toggle End
   --------------------------------------------------------------------*/

/* =4.0 Cookies
   --------------------------------------------------------------------*/

		/* get cookies */
		function getCookie( name ) {
			var start = document.cookie.indexOf( name + "=" );
			var len = start + name.length + 1;
			if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
				return null;
			}
			if ( start == -1 ) return null;
			var end = document.cookie.indexOf( ";", len );
			if ( end == -1 ) end = document.cookie.length;
			return unescape( document.cookie.substring( len, end ) );
		}

		/* set cookies */
		function setCookie( name, value, expires, path, domain, secure ) {
			var today = new Date();
			today.setTime( today.getTime() );
			if ( expires ) {
				expires = expires * 1000 * 60 * 60 * 24;
			}
			var expires_date = new Date( today.getTime() + (expires) );
			document.cookie = name+"="+escape( value ) +
				( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
				( ( path ) ? ";path=" + path : "" ) +
				( ( domain ) ? ";domain=" + domain : "" ) +
				( ( secure ) ? ";secure" : "" );
		}

		/* delete cookie */
		function deleteCookie( name, path, domain ) {
			if ( getCookie( name ) ) document.cookie = name + "=" +
					( ( path ) ? ";path=" + path : "") +
					( ( domain ) ? ";domain=" + domain : "" ) +
					";expires=Thu, 01-Jan-1970 00:00:01 GMT";
		}

/* =4.0 Cookies End
   --------------------------------------------------------------------*/

/* =5.0 getElement
   --------------------------------------------------------------------*/

		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;
		}

/* =5.0 getElement End
   --------------------------------------------------------------------*/

/* =6.0 Misc
   --------------------------------------------------------------------*/

		/* insert an element after a particular node */
		function insertAfter(parent, node, referenceNode) {
			parent.insertBefore(node, referenceNode.nextSibling);
		}


		/* Array prototype, matches value in array: returns bool */
		Array.prototype.inArray = function (value) {
			var i;
			for (i=0; i < this.length; i++) {
				if (this[i] === value) {
					return true;
				}
			}
			return false;
		};

/* =6.0 Misc End
   --------------------------------------------------------------------*/

/* =popup config
   ------------------------------------------------------------------------ */
		var popupLinkConfig = new Array;

		// popupLinkConfig["classname"] = new Array ( "targetname", "width=550,height=350,scrollbars=yes,resizable=yes,status=yes,toolbar=yes,location=yes,menubar=yes");
		popupLinkConfig["helpPop"]    = new Array ( "help", "width=620,height=400,resizeable=yes,scrollbars=yes");
		popupLinkConfig["fullpop"] = new Array ( "_blank", "scrollbars=yes,resizable=yes,status=yes,toolbar=yes,location=yes,menubar=yes");




		function initPage() {
		  initPopupLinks();
		  // place here any other code you wish to run when the page loads.
		}

		function initPopupLinks()
		{
		  if (!document.getElementsByTagName) return true;
		  var pageLinks = document.getElementsByTagName("a");
		  for (var i = 0; i < pageLinks.length; i++) 
		  {
		    if (((pageLinks[i].className != null) && 
		         (pageLinks[i].className != "")) ||
		        ((pageLinks[i].parentNode.className != null) && 
		         (pageLinks[i].parentNode.className != "")))
		    {
		      var linkClass = " " + pageLinks[i].className + " ";
		      if ((linkClass == "  ") && (pageLinks[i].parentNode.className != ""))
		      {
		        linkClass = " " + pageLinks[i].parentNode.className + " ";
		      }
		      for (var theKey in popupLinkConfig) 
		      {
		        if (linkClass.indexOf(" " + theKey + " ") > -1)
		        {
		          if ((pageLinks[i].target == "") || (pageLinks[i].target == null))
		          {
		            pageLinks[i].target = (popupLinkConfig[theKey][0] != "") ? popupLinkConfig[theKey][0] : theKey;
		          }
		          pageLinks[i].settings = popupLinkConfig[theKey][1];
		          pageLinks[i].onclick = popUp;
		        }
		      }
		    }
		  }
		  return true;
		}

		function popUp()
		{
		  newWin = window.open(this.href, this.target, this.settings);
		  newWin.focus();
		  return false;
		}
		
/* =popup config end
   ------------------------------------------------------------------------ */
	