var DomLoaded =
{
	onload: [],
	loaded: function()
	{
		if (arguments.callee.done) return;
		arguments.callee.done = true;
		for (i = 0;i < DomLoaded.onload.length;i++) DomLoaded.onload[i]();
	},
	load: function(fireThis)
	{
		this.onload.push(fireThis);
		if (document.addEventListener) 
			document.addEventListener("DOMContentLoaded", DomLoaded.loaded, null);
		if (/KHTML|WebKit/i.test(navigator.userAgent))
		{ 
			var _timer = setInterval(function()
			{
				if (/loaded|complete/.test(document.readyState))
				{
					clearInterval(_timer);
					delete _timer;
					DomLoaded.loaded();
				}
			}, 10);
		}
		/*@cc_on @*/
		/*@if (@_win32)
		var proto = "src='javascript:void(0)'";
		if (location.protocol == "https:") proto = "src=//0";
		document.write("<scr"+"ipt id=__ie_onload defer " + proto + "><\/scr"+"ipt>");
		var script = document.getElementById("__ie_onload");
		script.onreadystatechange = function() {
		    if (this.readyState == "complete") {
		        DomLoaded.loaded();
		    }
		};
		/*@end @*/
	   window.onload = DomLoaded.loaded;
	}
};

//Removes the selected listitems from a listbox
function removeListItems(source)
{
	var i = 0;
	while( i < source.options.length)
	{
		var theListItem = source.options[i];
		if(theListItem.selected)
		{
			source.remove(i);
			i = 0;
		}
		else 
		{
			i++;
		}
	}
}

//Selects all the items in a listbox.
function selectAllListItems(theListBox)
{
	var i = 0;
	while(i < theListBox.options.length)
	{
		var theListItem = theListBox.options[i];
		theListItem.selected = true;
		i++;
	}
}

function numberInputMask(txtb)
{
	var element = document.getElementById(txtb);
	if( isNaN(element.value) )
	{
		element.value = "";
	}
}

/* ********************************************************** 
 The code in this section is from: 
 http://www.mattkruse.com/javascript/selectbox/source.html  
Functions that have been modified are noted. 
 ********************************************************* */

// -------------------------------------------------------------------
// hasOptions(obj)
//  Utility function to determine if a select object has an options array
// From: http://www.mattkruse.com/javascript/selectbox/source.html
// -------------------------------------------------------------------
function hasOptions(obj) 
{
	if (obj!=null && obj.options!=null) 
	{ 
		return true; 
	}
	return false;
}

//Copies the selected listitems from one listbox to another.
//Modified code from http://www.mattkruse.com/javascript/selectbox/source.html
function addListItems(from, to)
{
	var options = new Object();
	if (hasOptions(to)) 
	{
		for (var i=0; i<to.options.length; i++) 
		{
			options[to.options[i].value] = to.options[i].text;
		}
	}
	if (!hasOptions(from)) 
	{ 
		return; 
	}
	for (var i=0; i<from.options.length; i++) 
	{
		var o = from.options[i];
		if (o.selected) 
		{
			if (options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text) 
			{
				if (!hasOptions(to)) 
				{ 
					var index = 0; 
				} 
				else 
				{ 
					var index=to.options.length; 
				}
				to.options[index] = new Option( o.text, o.value, false, false);
			}
		}
	}
	
	from.selectedIndex = -1;
	to.selectedIndex = -1;
}

// -------------------------------------------------------------------
// sortSelect(select_object)
//   Pass this function a SELECT object and the options will be sorted
//   by their text (display) values
// -------------------------------------------------------------------
function sortSelect(obj) 
{
	var o = new Array();
	if (!hasOptions(obj)) 
	{ 
		return; 
	}
	
	for (var i=0; i<obj.options.length; i++) 
	{
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
	}
	
	if (o.length==0) 
	{ 
		return; 
	}
	
	o = o.sort( 
		function(a,b) { 
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
			} 
		);

	for (var i=0; i<o.length; i++) 
	{
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	}
}

// -------------------------------------------------------------------
// sortSelect(select_object)
//   Pass this function a SELECT object and the options will be sorted
//   by their text (display) values
// -------------------------------------------------------------------
function sortSelect(obj) 
{
	var o = new Array();
	if (!hasOptions(obj)) 
	{ 
		return; 
	}
	
	for (var i=0; i<obj.options.length; i++) 
	{
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
	}
	
	if (o.length==0) 
	{ 
		return; 
	}
	
	o = o.sort( 
		function(a,b) 
		{ 
			if ((a.text+"") < (b.text+"")) 
			{ 
				return -1; 
			}
			if ((a.text+"") > (b.text+"")) 
			{ 
				return 1; 
			}
			return 0;
		} 
	);

	for (var i=0; i<o.length; i++) 
	{
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	}
}

// -------------------------------------------------------------------
// moveSelectedOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  This function moves options between select boxes. Works best with
//  multi-select boxes to create the common Windows control effect.
//  Passes all selected values from the first object to the second
//  object and re-sorts each box.
//  If a third argument of 'false' is passed, then the lists are not
//  sorted after the move.
//  If a fourth string argument is passed, this will function as a
//  Regular Expression to match against the TEXT or the options. If 
//  the text of an option matches the pattern, it will NOT be moved.
//  It will be treated as an unmoveable option.
//  You can also put this into the <SELECT> object as follows:
//    onDblClick="moveSelectedOptions(this,this.form.target)
//  This way, when the user double-clicks on a value in one box, it
//  will be transferred to the other (in browsers that support the 
//  onDblClick() event handler).
// From http://www.mattkruse.com/javascript/selectbox/source.html
// -------------------------------------------------------------------
function moveSelectedOptions(from,to) {
	// Unselect matching options, if required
	if (arguments.length>3) 
	{
		var regex = arguments[3];
		if (regex != "") 
		{
			unSelectMatchingOptions(from,regex);
		}
	}
	
	// Move them over
	if (!hasOptions(from)) 
	{ 
		return; 
	}
	
	for (var i=0; i<from.options.length; i++) 
	{
		var o = from.options[i];
		if (o.selected) 
		{
			if (!hasOptions(to)) 
			{ 
				var index = 0; } else { var index=to.options.length; 
			}
			to.options[index] = new Option( o.text, o.value, false, false);
		}
	}
	
	// Delete them from original
	for (var i=(from.options.length-1); i>=0; i--) 
	{
		var o = from.options[i];
		if (o.selected) 
		{
			from.options[i] = null;
		}
	}
	
	if ((arguments.length<3) || (arguments[2]==true)) 
	{
		sortSelect(from);
		sortSelect(to);
	}
	
	from.selectedIndex = -1;
	to.selectedIndex = -1;
}
/* ****************************************************************************************** */