/*================================================================
| [TITLE]: Global
| [DESCRIPTION]:
|	Global object used to store global function and variables
| [DATE LAST MODIFIED]: 12/06/2004
| [LAST MODIFIED BY]: Trace Kopcych
================================================================*/
function GlobalObject(){
	this.Init();
}
//======================================================
//|[Global.Init()]
//|Initalization
//|
//======================================================
GlobalObject.prototype.Init = function(){
	//Properties
	this.IS_COOKIES_ENABLED			= true;
	this.SELECTED_ELEMENT			= null;
}
//======================================================
//|[Global.ModDisplayByID()]
//|	Sets the display value of an elements style attribute
//| to teh desired value.
//|
//======================================================
GlobalObject.prototype.ModDisplayByID = function(id, value){
	globalObject_ModDisplay(document.getElementById(id), value)
}
//======================================================
//|[Global.ModDisplay()]
//|	Sets the display value of an elements style attribute
//| to teh desired value.
//|
//======================================================
GlobalObject.prototype.ModDisplay = function(element, value){
	element.style.display = value;
}
//======================================================
//|[Global.ModImageSrc()]
//|Appends or removes value from image.src
//|
//======================================================
GlobalObject.prototype.ModImageSrc = function(image, append, value){
	var extension = image.src.substring(image.src.lastIndexOf('.'));
	var base = image.src.substring(0, image.src.lastIndexOf('.'));
	
	image.src = (append) ? base + '-' + value + extension :  base.substring(0, base.lastIndexOf('-')) + extension;
}
//======================================================
//|[Global.GetEventSource()]
//|Return the event source
//|
//======================================================
GlobalObject.prototype.GetEventSource = function(e){
	var targ;
	if (!e) e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	
	return(targ);
}
//======================================================
//|[Global.AddEventHandler()]
//|Appends an event handler to an object
//|
//======================================================
GlobalObject.prototype.AddEventHandler = function(source, eventName, fn, bubble){
	if(source.attachEvent)
		source.attachEvent(eventName, fn);
	else //'removing the 'on'
		source.addEventListener(eventName.substring(2), fn, bubble);
}
//======================================================
//|[Global.RemoveEventHandler()]
//|REmoves an event handler from an object
//|
//======================================================
GlobalObject.prototype.RemoveEventHandler = function(source, eventName, fn, bubble){
	if((source != null) && (fn != null))
	{
		//Mozilla
		if(source.removeEventListener)
			source.removeEventListener(eventName.substring(2), fn, bubble);
		else
			source.detachEvent(eventName, fn); //IE
	}
}
//======================================================
//|[Global.ChangeSelectedValue()]
//|Change the selected option of a select list
//|
//======================================================
GlobalObject.prototype.ChangeSelectedValue = function(select, value){
	for(var i=0; i<select.options.length; i++) {
		select.options[i].selected = (select.options[i].value == value) ? true : false;
	}
}
//======================================================
//|[Global.GetAppliedStyleValue()]
//|Returns the currently applied value for the specified style
//|
//======================================================
GlobalObject.prototype.GetAppliedStyleValue = function(element, attribute){
	//On style of element?
	if((element.style[attribute] != null) && (element.style[attribute] != ''))
		return(element.style[attribute]);
		
	//Check style sheet application
	if(element.currentStyle != null)
		return(element.currentStyle[attribute]);
	else
		return(document.defaultView.getComputedStyle(element, '').getPropertyValue(attribute));
}
//======================================================
//|[Global.GetLeftValue()]
//|Get the numerical value of left
//|
//======================================================
GlobalObject.prototype.GetLeftValue = function(element){
	var value = null;
	value = Global.GetAppliedStyleValue(element, 'left');
	if(value != null)
		return(value.match(/^[0-9]+/));
}
//======================================================
//|[Global.GetTopValue()]
//|Get the numerical value of top
//|
//======================================================
GlobalObject.prototype.GetTopValue = function(element){	
	var value = null;
	value = Global.GetAppliedStyleValue(element, 'top');
	if(value != null)
		return(value.match(/^[0-9]+/));
}
//======================================================
//|[Global.GetActiveXObject()]
//|Appends or removes value from image.src
//|
//======================================================
GlobalObject.prototype.GetActiveXObject = function(id){
	if(window.ActiveXObject)
		return(new ActiveXObject(id));
	
	return(new GeckoActiveXObject(id));		
}
//======================================================
//|[Global.ClickButton()]
//|Appends or removes value from image.src
//|
//======================================================
GlobalObject.prototype.ClickButton = function(e, buttonid){
	var bt = document.getElementById(buttonid);
	e = Global.GetEvent(e);
	if (e.keyCode == 13){
		bt.click();
		return false;
	}
}


/*================================================================
| [TITLE]: ToggleElement
| [DESCRIPTION]:
|	Javascript used for quick display change between click element
|	and block element
| [DATE LAST MODIFIED]: 12/06/2004
| [LAST MODIFIED BY]: Trace Kopcych
================================================================*/
function ToggleElement(toggle, panel){
	if(arguments.length > 0)
		this.Init(toggle, panel);
}

ToggleElement.prototype.Init = function(toggle, panel){
	this.ToggleSwitch = document.getElementById(toggle);
	this.Panel = document.getElementById(panel);
	this.IsOpen = true;
	
	
	//******************************
	//[Event handling hack!]
	var me = this;
	this.OnClick = function(){
		me.Toggle();
	}
	this.OnPageUnLoad = function(){
		
		//unhook
		Global.RemoveEventHandler(this.ToggleSwitch, 'onclick', me.OnClick, false);
		Global.RemoveEventHandler(window, 'onunload', me.OnPageUnLoad, false);
		
		//garbage
		delete me.OnPageUnload;
		
		me = null;
	}
	Global.AddEventHandler(this.ToggleSwitch, 'onclick', this.OnClick, false);
	Global.AddEventHandler(window, 'onunload', this.OnPageUnLoad, false);
	//******************************
	
	this.Toggle();
}

ToggleElement.prototype.Toggle = function(){
	this.Panel.style.display = (this.IsOpen) ? 'none' : 'block';	
	this.IsOpen = !this.IsOpen;
}




/*================================================================
| [TITLE]: Cookie
| [DESCRIPTION]:
|	Javascript used for client side functionality of a cookie
| [DATE LAST MODIFIED]: 12/06/2004
| [LAST MODIFIED BY]: Trace Kopcych
================================================================*/
function Cookie(name){
	if(arguments.length > 0)
		this.Init(name);
}
//======================================================
//|[Cookie.Save()]
//|Cookie set the expiration by day count
//|
//======================================================
Cookie.prototype.Init = function(name){
	//Properties
	this.Name = name;
	this.Value = null;
	this.Expires = null;
	this.Domain = null;
	this.Path = '/';
	this.Secure = null;
}
//======================================================
//|[Cookie.Save()]
//|Cookie set the expiration by day count
//|
//======================================================
Cookie.prototype.Save = function(){
	if((this.Name != null) && (this.Value != null)){
		var cookieString = escape(this.Name) + '=' + escape(this.Value) + '; ';
		cookieString = cookieString.substr(0, cookieString.length-2);
		cookieString += (this.Expires) ? '; expires=' + (new Date(this.Expires)).toGMTString() : '';
		cookieString += (this.Path) ? '; path=' + this.Path : '';
		cookieString += (this.Domain) ? '; domain=' + this.Domain : '';
		cookieString += (this.Secure) ? '; secure' : '';
		document.cookie = cookieString;
	}
}
//======================================================
//|[Cookie.Load()]
//|Cookie set the expiration by day count
//|
//======================================================
Cookie.prototype.Load = function(){
	if(this.Name){
		var regEx = new RegExp(this.Name + "=([^;]+)");
		var value = regEx.exec(document.cookie);
		this.Value = (value != null) ? unescape(value[1]) : null;
	}
}
//======================================================
//|[Cookie.SetDay()]
//|Cookie set the expiration by day count
//|
//======================================================
Cookie.prototype.SetDays = function(days){
	if(!isNaN(days)) this.Expires = ((new Date()).getTime() + days * 86400000); //24h * 60m * 60s * 1000ms = days in ms
}






/*================================================================
| [TITLE]: List
| [DESCRIPTION]:
|	List object that extends an Array
| [DATE LAST MODIFIED]: 12/06/2004
| [LAST MODIFIED BY]: Trace Kopcych
| [COMMENTS]
|	PEerhaps we should actually try inheriting from Array
================================================================*/
function List(){
	this.Init();
}
//======================================================
//|[List.Init()]
//|Initialization
//|
//======================================================
List.prototype.Init = function(){
	this.Items = new Array();
}
//======================================================
//|[List.Count()]
//|Return the Count of the List items
//|
//======================================================
List.prototype.Count = function(){
	return(this.Items.length);
}
//======================================================
//|[List.Push()]
//|Append an item to the list
//|
//======================================================
List.prototype.Push = function(value){
	this.Items.push(value);
}
//======================================================
//|[List.Pop()]
//|Remove the last item from the list
//|
//======================================================
List.prototype.Pop = function(){
	this.Items.pop();
}
//======================================================
//|[List.InsertAt()]
//|Insert an item at a specific index
//|
//======================================================
List.prototype.InsertAt = function(index, value){
	var left;
	var right;
	if(index > this.Count()){
		//insert null spacers
		for(var i=0; i<index; i++)
			this.Items.push(null);
		
		this.Items.Push(value);
	} else if(index > 0) {
		left = this.Items.slice(0, index);
		right = this.Items.slice(index+1, this.Count());
		this.Items = new Array();
		for(var i=0; i<left.length; i++)
			this.Items.push(left[i]);
		this.Items.push(value);
		for(var i=0; i<right.length; i++)
			this.Items.push(right[i]);		
	}
}
//======================================================
//|[List.RemoveAt()]
//|Remove an item at a specific index
//|
//======================================================
List.prototype.RemoveAt = function(index){
	var left;
	var right;
	if((index < this.Count()) && (index >= 0)){
		right = this.Items.slice(index+1, this.Count());
		left = this.Items.slice(0, index);
		alert('left :' + left);
		alert('right :' + right);
		this.Items = new Array();
		for(var i=0; i<left.length; i++)
			this.Items.push(left[i]);
		for(var i=0; i<right.length; i++)
			this.Items.push(right[i]);
	}
}
//======================================================
//|[List.Remove()]
//|Remove a specific item
//|
//======================================================
List.prototype.Remove = function(value){
	for(var i=0; i<this.Items.length; i++){
		if(this.Items[i] == value){
			this.RemoveAt(i)
			break;
		}
	}
}
//======================================================
//|[List.Get()]
//|Get an item at the specific index
//|
//======================================================
List.prototype.Get = function(index){
	return(this.Items[index]);
}
//======================================================
//|[List.Set()]
//|Set an item at the specific index
//|
//======================================================
List.prototype.Set = function(index, value){
	return(this.list_InsertAt(index, value));
}







/*================================================================
| [TITLE]: NameValuePair
| [DESCRIPTION]:
|	NameValuePair used to associate a string key with a value in a dictionary
| [DATE LAST MODIFIED]: 12/06/2004
| [LAST MODIFIED BY]: Trace Kopcych
================================================================*/
function NameValuePair(name, value){
	if(name){
		this.Name = name.toString();
		this.Value = value;
	}
}





/*================================================================
| [TITLE]: EventsCollection
| [DESCRIPTION]:
|	List object used to add and remove Listeners for an event
| [DATE LAST MODIFIED]: 12/10/2005
| [LAST MODIFIED BY]: Trace Kopcych
================================================================*/
function EventsCollection(){
	this.Init();
}
//======================================================
//|[EventsCollection.Init()]
//|Initialize
//|
//======================================================
EventsCollection.prototype.Init = function(){
	this.Events = new List();
}
//======================================================
//|[EventsCollection.Add()]
//|	Add a function [delegate] to the EventList
//|
//======================================================
EventsCollection.prototype.Add = function(handler, fn){
	obj = new EventsObject(handler, fn)
	Global.Debug.Write('Handler: ' + handler);
	Global.Debug.Write('Event Push: ' + fn);
	this.Events.Push(obj);
}
//======================================================
//|[EventsCollection.Remove()]
//|	Remove a function [delegate] to the EventList
//|
//======================================================
EventsCollection.prototype.Remove = function(handler, fn){
	obj = new EventsObject(handler, fn)
	this.Events.Remove(obj);
}
//======================================================
//|[EventsCollection.Fire()]
//|	Fire off the entire EventCollection
//|
//======================================================
EventsCollection.prototype.Fire = function(args){
	if(this.Events.Count() <= 0)
		Global.Debug.Write('No events to fire.');
	
	for(var i=0; i<this.Events.Count(); i++){
		Global.Debug.Write('Event is Firing: ' + this.Events.Get(i));
		args.Handler = this.Events.Get(i).Handler;
		if(this.Events.Get(i).Handle != null)
			this.Events.Get(i).Handle(args);
	}
}

function EventsObject(hndlr, hndl){
	this.Handler = hndlr;
	this.Handle = hndl;
}








/*================================================================
| [TITLE]: Debug
| [DESCRIPTION]:
|	List object that extends an Array
| [DATE LAST MODIFIED]: 12/06/2004
| [LAST MODIFIED BY]: Trace Kopcych
| [COMMENTS]
|	PEerhaps we should actually try inheriting from Array
================================================================*/
function Debug(){
	this.Init();
}
//======================================================
//|[Debug.Init()]
//|Initialization
//|
//======================================================
Debug.prototype.Init = function(){
	this.Verbose = false;
}
//======================================================
//|[Debug.Write()]
//|Write Debug information
//|
//======================================================
Debug.prototype.Write = function(value){
	if(this.Verbose)
		alert(value);
}
//======================================================
//|[Debug.ModImageSrc()]
//|Display properties of an object
//|
//======================================================
Debug.prototype.DumpProperties = function(obj, recurse, document) {
	if(document == null)
		document = window.open('about:blank', 'dump', 'height=400, width=400').document;
	
	var msg;
	document.write('<dl>');
	document.write('<dt>');
	document.write(obj);
	document.write('</dt>');
		        
	// Go through all the properties of the passed-in object 
	document.write('<dd>');
	for(var i in obj){
		msg = i + "&nbsp;|&nbsp;" + ((obj[i] != null) ? obj[i] : 'undefined');
		
		document.write("<li>");
		document.write(msg);
		document.write("</li>");
		
		if (recurse && (typeof obj[i] == 'object')){
			document.write("<ul>");
			this.DumpProperties(obj[i], true, document);
			document.write("</ul>");
		}
	}
	document.write('</dd>');
	document.write('</dl>');
}
//======================================================
//|[Debug.StartBenchMark()]
//|Start the begining of a benchmark test
//|
//======================================================
Debug.prototype.BenchMark = function() {
	if(this.BenchStartTime == null)
		this.BenchStartTime = new Date().getTime();
	else {
		var endTime = new Date().getTime();
		alert('Elapsed time: ' + ((endTime - this.BenchStartTime)/1000) + ' seconds.');
		delete this.BenchStartTime;
		delete endTime;
	}
}

/*================================================================
| [TITLE]: ImageSwap
| [DESCRIPTION]:
|	Quick swap image box
| [DATE LAST MODIFIED]: 08/02/2005
| [LAST MODIFIED BY]: Trace Kopcych
================================================================*/
function ImageSwap(id){
	if(arguments.length > 0)
		this.Init(id);
}
//======================================================
//|[ImageSwap.Init()]
//|Initializer
//|
//======================================================
ImageSwap.prototype.Init = function(id){
	this.Element	= document.getElementById(id);
	this.Images		= this.Element.getElementsByTagName('IMG');
	
	//******************************
	//[Event handling hack!]
	var me = this;
	this.OnImageClick = function(e){
		me.Swap(Global.GetEventSource(e));
	}
	//******************************
	
	for(var i=1, n=this.Images.length; i<n; i++){
		this.Images[i].style.cursor = 'hand';
		Global.AddEventHandler(this.Images[i], "onclick", this.OnImageClick, false);
	}
	
}
//======================================================
//|[ImageSwap.Swap()]
//|Switch images
//|
//======================================================
ImageSwap.prototype.Swap = function(img){
	var temp = img.src;
	img.src = this.Images[0].src;
	this.Images[0].src = temp;
}


//[Global Objects]
Global = new GlobalObject();
Global.Debug = new Debug();