function AcuMediaImageSrc(g_site_media_base) {
	var base = g_site_media_base;
	this.GetBase = function() {
		return base;
	}
	this.GetImageSrc = function(src, h, w) {
		if (!h) h == '';
		if (!w) w == '';
		return base + src + '-' + w + 'x' + h;
	}
}

function HandleAlertMessage(message, id, type) {
	var target = $('#' + id);
	if (target.length == 0) target = $('#error-message');
	if (target.length == 0) target = $('#user-message');
	if (target.length > 0) {
		target.html(message);
		target.attr('class', 'message');
		switch (type) {
			case "notice":
				target.addClass('message-notice');
				break;
			case "alert":
				target.addClass('message-alert');
				break;
			case "success":
				target.addClass('message-success');
				break;
		}
		//target.prepend('<a name="#user-message"/>');
		target.show();
		//window.location.hash = '#user-message';
	} else
		alert(message);
}

function FormatDate(fmt, d) {
	var dtDate = (d == null ? new Date() : d);
	switch (fmt) {
		case 1:
			return dtDate.getMonth() + 1 + "/" + dtDate.getDate() + "/" + dtDate.getYear();
		case 2:
			return GetMonth(dtDate.getMonth()) + " " + dtDate.getDate() + ", " + dtDate.getFullYear();
		case 3:
			return dtDate.getMonth() + 1 + "/" + dtDate.getDate() + "/" + dtDate.getFullYear();
		default:
			return dtDate.toString();
	}
}

function GetMonth(iIndex) {
	var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
	if (parseInt(iIndex) < months.length)
		return months[iIndex];
	else
		return "";
}

function trim(sValue) {
	return (sValue.replace(" ", ""));
}

function IsDate(sVal) {
	if (isNaN(sVal.replace(/[\/-]/g, "", 0))) return false;
	return true;
}

function checkRequiredFields(oForm, arFields, arTitles) {
	var sMessage = "Please fill in the following required fields:<br/>";
	for (var i = 0; i < arFields.length; i++) {
		if (oForm[arFields[i]].value == "") {
		    sMessage += "<br/>" + arTitles[i];
		}
	}
	if (sMessage != "Please fill in the following required fields:<br/>") {
		HandleAlertMessage(sMessage, 'error-message', 'alert');
		return false;
	} else return true;
}

//copied from CSScriptLib.js:

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

userAgent = window.navigator.userAgent;
browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/") + 1), 10);
mustInitImg = true;

function initImgID() {
	di = document.images;
	if (mustInitImg && di) {
		for (var i = 0; i < di.length; i++) {
			if (!di[i].id) di[i].id = di[i].name;
		}
		mustInitImg = false;
	}
}
function findElement(n, ly) {
	d = document;
	if (browserVers < 4) return d[n];
	if ((browserVers >= 6) && (d.getElementById)) { initImgID; return (d.getElementById(n)) };
	var cd = ly ? ly.document : d;
	var elem = cd[n];
	if (!elem) {
		for (var i = 0; i < cd.layers.length; i++) {
			elem = findElement(n, cd.layers[i]);
			if (elem) return elem;
		}
	}
	return elem;
}
function changeImages() {
	d = document;
	if (d.images) {
		var img;
		for (var i = 0; i < changeImages.arguments.length; i += 2) {
			img = null;
			if (d.layers) { img = findElement(changeImages.arguments[i], 0); }
			else { img = d.images[changeImages.arguments[i]]; }
			if (img) { img.src = changeImages.arguments[i + 1]; }
		}
	}
}

function openWindow(URL, windowTitle, windowWidth, windowHeight) {
	var wide = screen.width;
	var high = screen.height;
	var xCoordinate = ((wide / 2) - (windowWidth / 2));
	var yCoordinate = ((high / 2) - (windowHeight / 2));
	var w = window.open(URL, windowTitle, "width=" + windowWidth + ",height=" + windowHeight + ",left=" + xCoordinate + ",top=" + yCoordinate + ",resizable=no,status=no,menubar=no,scrollbars=auto,innerheight=" + windowHeight + ",innerwidth=" + windowWidth + ",screenx=" + xCoordinate + ",screeny=" + yCoordinate + ",toolbar=no");
	w.focus();
	w.opener = window;
}

function openContactWindow(URL, windowTitle) {
	var sWidth = 420;
	var sHeight = 555;
	var wide = screen.width;
	var high = screen.height;
	var xCoordinate = ((wide / 2) - (sWidth / 2));
	var yCoordinate = ((high / 2) - (sHeight / 2));
	var w = window.open(URL, windowTitle, "width=" + sWidth + ",height=" + sHeight + ",left=" + xCoordinate + ",top=" + yCoordinate + ",resizable=no,status=no,menubar=no,scrollbars=auto,innerheight=" + sHeight + ",innerwidth=" + sWidth + ",screenx=" + xCoordinate + ",screeny=" + yCoordinate + ",toolbar=no");
	w.focus();
	w.opener = window;
}
function openScrollingWindow(URL, windowTitle, windowWidth, windowHeight) {
	var wide = screen.width;
	var high = screen.height;
	var xCoordinate = ((wide / 2) - (windowWidth / 2));
	var yCoordinate = ((high / 2) - (windowHeight / 2));
	var w = window.open(URL, windowTitle, "width=" + windowWidth + ",height=" + windowHeight + ",left=" + xCoordinate + ",top=" + yCoordinate + ",resizable=yes,status=yes,menubar=no,scrollbars=yes,innerheight=" + windowHeight + ",innerwidth=" + windowWidth + ",screenx=" + xCoordinate + ",screeny=" + yCoordinate + ",toolbar=no");
	w.focus();
	w.opener = window;
	w.resizeTo(windowWidth, windowHeight);
}

/* MAY NEED TO REF FORMS[0] NOW THAT DUMMY FORM HAS BEEN REMOVED */
function browseStreams(sectionpath, kbactionid, kbcontentid, div_name, form_name) {
	var sStreamIDs = '';
	if (document.forms[1].streamid) {
		for (var i = 0; i < document.forms[1].streamid.length; i++) {
			sStreamIDs += "&selectedstreamid=" + document.forms[1].streamid[i].value;
		}
	}
	openScrollingWindow("?sectionpath=" + sectionpath + "&processor=asp&asp_processor=streams&action=loadstreamtree&div_name=" + div_name + "&kbactionid=" + kbactionid + "&kbcontentid=" + kbcontentid + sStreamIDs, "StreamManager", 736, 320);
}

function addStreams(div_name, form_name) {
	var streamid = '';
	opener.document.getElementById(div_name).innerHTML = '';
	for (var i = 0; i < document.forms[form_name].selectedstreamid.length; i++) {
		if (document.forms[form_name].selectedstreamid[i].checked) {
			streamid = document.forms[form_name].selectedstreamid[i].value;
			opener.document.getElementById(div_name).innerHTML = opener.document.getElementById(div_name).innerHTML + "<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td><input type=hidden name=streamid_" + streamid + " value=" + document.forms[form_name]["streamid_" + streamid].value + "><input type=hidden name=streamid value=" + streamid + ">" + document.forms[form_name]["streamid_" + streamid].value + "</td><td align=right><a href=# onClick=javascript:removeTopic('" + div_name + "','documentedit','" + streamid + "')>Remove</a></td></tr></table>";
		}
	}
}

function removeStream(div_name, form_name, streamid) {
	var curtopicid = '';
	var sRetVal = '';
	var sNameKey = '';
	if (document.forms[form_name].streamid) {

		for (var i = 0; i < document.forms[form_name].streamid.length; i++) {
			if (document.forms[form_name].streamid[i].value != streamid) {
				curstreamid = document.forms[form_name].streamid[i].value;
				sRetVal = sRetVal + "<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td><input type=hidden name=streamid_" + curstreamid + " value=" + document.forms[form_name]["streamid_" + curstreamid].value + "><input type=hidden name=streamid value=" + curstreamid + ">" + document.forms[form_name]["streamid_" + curstreamid].value + "</td><td align=right><a href=# onClick=javascript:removeStream('" + div_name + "','" + form_name + "','" + curstreamid + "')>Remove</a></td></tr></table>";
			}
		}
		document.getElementById(div_name).innerHTML = sRetVal;
	}
}

function browseTopics(sectionpath, kbactionid, kbcontentid, div_name, form_name) {
	var sTopicIDs = '';

	if (document.forms[form_name].topicid) {
		for (var i = 0; i < document.forms[form_name].topicid.length; i++) {
			sTopicIDs += "&selectedtopicid=" + document.forms[form_name].topicid[i].value;
		}
	}
	openScrollingWindow("?sectionpath=" + sectionpath + "&processor=asp&asp_processor=topics&action=loadtopictree&div_name=" + div_name + "&kbactionid=" + kbactionid + "&kbcontentid=" + kbcontentid + sTopicIDs, "TopicManager", 736, 320);
}

function addTopics(div_name, form_name) {
	var topicid = '';
	opener.document.getElementById(div_name).innerHTML = '';
	for (var i = 0; i < document.forms[form_name].selectedtopicid.length; i++) {
		if (document.forms[form_name].selectedtopicid[i].checked) {
			topicid = document.forms[form_name].selectedtopicid[i].value;
			opener.document.getElementById(div_name).innerHTML = opener.document.getElementById(div_name).innerHTML + "<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td><input type=hidden name=topicid_" + topicid + " value=" + document.forms[form_name]["topicid_" + topicid].value + "><input type=hidden name=topicid value=" + topicid + ">" + document.forms[form_name]["topicid_" + topicid].value + "</td><td align=right><a href=# onClick=javascript:removeTopic('" + div_name + "','documentedit','" + topicid + "')>Remove</a></td></tr></table>";
		}
	}
}

function removeTopic(div_name, form_name, topicid) {
	var curtopicid = '';
	var sRetVal = '';
	var sNameKey = '';
	if (document.forms[form_name].topicid) {

		for (var i = 0; i < document.forms[form_name].topicid.length; i++) {
			if (document.forms[form_name].topicid[i].value != topicid) {
				curtopicid = document.forms[form_name].topicid[i].value;
				sRetVal = sRetVal + "<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td><input type=hidden name=topicid_" + curtopicid + " value=" + document.forms[form_name]["topicid_" + curtopicid].value + "><input type=hidden name=topicid value=" + curtopicid + ">" + document.forms[form_name]["topicid_" + curtopicid].value + "</td><td align=right><a href=# onClick=javascript:removeTopic('" + div_name + "','" + form_name + "','" + curtopicid + "')>Remove</a></td></tr></table>";
			}
		}
		document.getElementById(div_name).innerHTML = sRetVal;
	}
}

var arImages = new Array();
var preloadFlag = false;
function preloadImages(arImages) {
	if (document.images && !preloadFlag) {
		var img;
		for (var i = 0; i < arImages.length; i++)
			img = newImage(arImages[i]);
		preloadFlag = true;
	}
}

function resizeImageWidth(form, imagename) {
	if (form.width.value != '') {
		if (form.source.value.indexOf('.jpg') != -1) {
			document.images[imagename].style.width = form.width.value;
			document.images[imagename].style.height = form.height.value;
			document.images[imagename].src = aspResizeImage(form.source.value, form.height.value, form.width.value);
		} else {
			document.images[imagename].style.width = form.width.value;
		}
	} else {
		if (form.source.value.indexOf('.jpg') != -1) {
			document.images[imagename].style.width = form.width.value;
			document.images[imagename].style.height = form.height.value;
			document.images[imagename].src = aspResizeImage(form.source.value, form.height.value, form.width.value);
		} else {
			if (document.images[imagename].style.width != '') {
				document.images[imagename].style.width = 'auto';
			}
		}
	}
}

function resizeImageHeight(form, imagename) {
	if (form.height.value != '') {
		if (form.source.value.indexOf('.jpg') != -1) {
			document.images[imagename].style.width = form.width.value;
			document.images[imagename].style.height = form.height.value;
			document.images[imagename].src = aspResizeImage(form.source.value, form.height.value, form.width.value);
		} else {
			document.images[imagename].style.height = form.height.value;
		}
	} else {
		if (form.source.value.indexOf('.jpg') != -1) {
			document.images[imagename].style.width = form.width.value;
			document.images[imagename].style.height = form.height.value;
			document.images[imagename].src = aspResizeImage(form.source.value, form.height.value, form.width.value);
		} else {
			if (document.images[imagename].style.height != '') {
				document.images[imagename].style.height = 'auto';
			}
		}
	}
}
//uses AcuMediaImageSrc above, which must be instantiated as early as possible in the page load. currently in core sitebase head tag
function aspResizeImage(sPath, iHeight, iWidth) {
	return acuMediaImageSrc.GetImageSrc(escape(sPath), iHeight, iWidth);
}

//copied from helppane.js:

function DoHelp(help_url) {
	var W;
	var H;
	var sWD;
	var sc = screen.width;
	var agent = navigator.userAgent.toLowerCase();
	var app = navigator.appName.toLowerCase();

	//If screen width is 800 or less and this is not a mac, set width to 180, otherwise set to 230
	W = (sc <= 800 && agent.indexOf("mac") == -1) ? 230 : 336;

	// If using AOL then height = available height - 22 from top, Otherwise height = available height 
	H = (agent.indexOf("windows") > 0 && agent.indexOf("aol") > 0) ? screen.availHeight - window.screenTop - 22 : screen.availHeight

	//sWD="toolbar=0,status=0,menubar=0,width="+W+",height="+H+",left="+(sc-W)+",top=0,resizable=1";
	sWD = "toolbar=0,status=0,scrollbars=1,location=0,menubar=0,left=" + (sc - W) + ",top=0,resizable=1";

	h_win = window.open(help_url, 'help', sWD);
	h_win.focus();
	h_win.resizeTo(W, H);

	//if not using a mac and not using netscape
	if (h_win && agent.indexOf("mac") < 0 && app.indexOf("netscape") < 0) h_win.opener = self//*IE5+PC
	//h_win.opener.focus();
	h_win.opener.resizeTo((sc - W), H);
	h_win.opener.moveTo(0, 0);

}

function populateFields(chkThis, frmThis, arFieldsFrom, arFieldsTo) {
	var i;

	if (chkThis.checked) {
		for (i = 0; i < arFieldsFrom.length; i++) {
			if (frmThis[arFieldsTo[i]])
				frmThis[arFieldsTo[i]].value = frmThis[arFieldsFrom[i]].value;
		}
	} else {
		for (i = 0; i < arFieldsFrom.length; i++) {
			if (frmThis[arFieldsTo[i]])
				frmThis[arFieldsTo[i]].value = '';
		}
	}
}
/***
* getOffsetLeft and getOffsetTop use element's parentOffset to calculate the
* absolute position. If the element is absolutely positioned, the "left" style is used
***/
function getOffsetLeft(p) {
	return p.offsetParent != null ? getInt(p.offsetLeft) + getOffsetLeft(p.offsetParent)
		: ((new RegExp("^(absolute)$", "i")).test(getStyleByObj(p, "position")) ? getInt(p.offsetLeft) : getInt(getStyleByObj(p, "left")));
}
function getOffsetTop(p) {
	return p.offsetParent != null ? getInt(p.offsetTop) + getOffsetTop(p.offsetParent)
		: ((new RegExp("^(absolute)$", "i")).test(getStyleByObj(p, "position")) ? getInt(p.offsetTop) : getInt(getStyleByObj(p, "top")));
}

function trim(inputString) {
	if (typeof inputString != "string") return inputString;
	return inputString.replace((new RegExp("\\s{2,}", "g")), " ");
}

function getEventTarget(e) {
	var obj = e.srcElement ? e.srcElement : e.target;
	return obj;
}

function isVisible(obj) {
	return $(obj).is(':visible');
}

function showIFrameHelper(obj, stoptrying) {
	var defaultZIndex = 100;
	if (!obj.parentNode && !stoptrying) {
		document.tempobj = obj;
		eval("document.iframehelper_" + obj.uniqueID + " = document.tempobj");
		window.setTimeout("showIFrameHelper(document.iframehelper_" + obj.uniqueID + ", true", 1);
	} else if (obj.parentNode) {
		if (gBrowserType() == 'IE' && gOS() == 'WIN' && gBrowserVersion() > 5) {
			var IFRAME_ID = 'iframehelper_' + obj.uniqueID;
			if (!getObject(IFRAME_ID)) {
				var newiframe = document.createElement('iframe');
				newiframe.setAttribute("id", IFRAME_ID);
				newiframe.style.position = "absolute";
				newiframe.style.visibility = "hidden";
				newiframe.style.border = 0;
				obj.parentNode.appendChild(newiframe);
			}
			//if (getStyleByObj(obj, "zIndex") == "") obj.style.zIndex = defaultZIndex;
			var iframe = getObject(IFRAME_ID);
			iframe.width = obj.offsetWidth;
			iframe.height = obj.offsetHeight;
			iframe.style.left = obj.offsetLeft;
			iframe.style.top = obj.offsetTop;
			iframe.style.zIndex = getStyleByObj(obj, "zIndex") - 1;
			iframe.frameBorder = 0;
			iframe.style.border = "none";
			iframe.style.visibility = "visible";
			obj.iframehelper = iframe;
			document.tempobj = obj;
			eval("document.iframehelper_" + obj.uniqueID + " = document.tempobj");
			eval("obj.iframehelperupdatefn = function(e){updateIFrameHelper(document.iframehelper_" + obj.uniqueID + ");}");
			addEvent(document, "mousemove", obj.iframehelperupdatefn);
		}
	}
}

function updateIFrameHelper(obj) {
	obj.iframehelper.width = obj.offsetWidth;
	obj.iframehelper.height = obj.offsetHeight;
	obj.iframehelper.style.left = obj.offsetLeft;
	obj.iframehelper.style.top = obj.offsetTop;
	obj.iframehelper.style.zIndex = getStyleByObj(obj, "zIndex") - 1;
}

function hideIFrameHelper(obj) {
	if (gBrowserType() == 'IE' && gOS() == 'WIN' && gBrowserVersion() > 5) {
		var IFRAME_ID = 'iframehelper_' + obj.uniqueID;
		if (getObject(IFRAME_ID)) {
			getObject(IFRAME_ID).style.visibility = "hidden";
			if (obj.iframehelperupdatefn) removeEvent(document, "mousemove", obj.iframehelperupdatefn);
		}
	}
}

function getObject(objid) {
	var obj = $(objid);
	if (obj.length > 0)
		return obj.get(0);
	else return null;
}
function setStyleById(i, p, v) {
	$('#' + i).css(p, v);
}

// getStyleById: given an element ID and style property
// return the current setting for that property, or null.
// args:
//  i - element id
//  p - property
function getStyleById(i, p) {
	return getStyleByObj(getObject(i), p);
}
// args:
//  o - object
//  p - property
function getStyleByObj(o, p) {
	return $(o).css(p);
}

function addEvent(obj, evtName, handler) {
	$(obj).unbind(evtName);
	$(obj).bind(evtName, handler);
}

function removeEvent(obj, evtName, handler) {
	$(obj).unbind(evtName);
}

function getEventX(e) {
	if (gBrowserType() == 'NS' && !gIsSafari)
		var x = e.pageX;
	else if (gOS() == "MAC")
		var x = event.clientX;
	else
		var x = event ? event.x : e.x;

	if (e) {
		var node = getEventTarget(e);
		if (node.ownerDocument) {
			var pframe = node.ownerDocument.parentWindow ? node.ownerDocument.parentWindow : node.ownerDocument.defaultView;
			while ((pframe) && (pframe.frameElement)) {
				x += getOffsetLeft(pframe.frameElement);
				pframe = pframe.parent;
			}
		}
	}
	return x;
}

function getEventY(e) {
	if (gBrowserType() == 'NS' && !gIsSafari)
		var y = e.pageY;
	else if (gOS() == "MAC")
		var y = event.clientY;
	else
		var y = event ? event.y : e.y;

	if (e) {
		var node = getEventTarget(e);
		if (node.ownerDocument) {
			var pframe = node.ownerDocument.parentWindow ? node.ownerDocument.parentWindow : node.ownerDocument.defaultView;
			if (pframe) {
				while (pframe.frameElement) {
					y += getOffsetTop(pframe.frameElement);
					pframe = pframe.parent;
				}
			}
		}
	}
	return y;
}

function getInt(i) {
	if (gIsSafari)
		return i.toString().replace((new RegExp("\\D+")), "").valueOf();
	else if ((new RegExp("\\d")).test(i))
		return parseInt(i);
	else
		return 0;
}

function numsort(a, b) { return (a - b); }

function arcopy(a1, a2) {
	for (var i = 0; i < a1.length; i++) {
		if ((a1[i]) && (typeof (a1[i]) == "object") && (a1[i].length)) {
			var newArray = new Array();
			arcopy(a1[i], newArray);
			a2[i] = newArray;
		} else {
			a2[i] = a1[i];
		}
	}
}

function getRegExpSafeString(str) {
	return str
		.replace((new RegExp("(\\\\)", "g")), "$1$1")
		.replace((new RegExp("\\*", "g")), "\\*")
		.replace((new RegExp("\\+", "g")), "\\+")
		.replace((new RegExp("\\[", "g")), "\\[")
		.replace((new RegExp("\\]", "g")), "\\]")
		.replace((new RegExp("\\(", "g")), "\\(")
		.replace((new RegExp("\\)", "g")), "\\)")
		.replace((new RegExp("\\{", "g")), "\\{")
		.replace((new RegExp("\\}", "g")), "\\}")
		.replace((new RegExp("\\?", "g")), "\\?")
		.replace((new RegExp("\\^", "g")), "\\^")
		.replace((new RegExp("\\$", "g")), "\\$")
		.replace((new RegExp("\\.", "g")), "\\.")
		.replace((new RegExp("\\!", "g")), "\\!")
		.replace((new RegExp("\\-", "g")), "\\-")
		.replace((new RegExp("\\|", "g")), "\\|")
		.replace((new RegExp("\\&", "g")), "\\&")
		.replace((new RegExp("\\/", "g")), "\\/");
}

function escapeQuotes(str) {
	return str.replace((new RegExp("(^|[^\\]([\\]{2})*)(?=')", "g")), "$1\\");
}

function unescapeQuotes(str) {
	return str.replace((new RegExp("((^|[^\\\\])([\\\\]{2})*)[\\\\](?=')", "g")), "$1");
}

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/

// -------------------------------------------------------------------
// hasOptions(obj)
//  Utility function to determine if a select object has an options array
// -------------------------------------------------------------------
function hasOptions(obj) {
	if (obj != null && obj.options != null) { return true; }
	return false;
}

// -------------------------------------------------------------------
// selectUnselectMatchingOptions(select_object,regex,select/unselect,true/false)
//  This is a general function used by the select functions below, to avoid code duplication
// -------------------------------------------------------------------
function selectUnselectMatchingOptions(obj, regex, which, only) {
	if (window.RegExp) {
		if (which == "select") {
			var selected1 = true;
			var selected2 = false;
		}
		else if (which == "unselect") {
			var selected1 = false;
			var selected2 = true;
		}
		else {
			return;
		}
		var re = new RegExp(regex);
		if (!hasOptions(obj)) { return; }
		for (var i = 0; i < obj.options.length; i++) {
			if (re.test(obj.options[i].text)) {
				obj.options[i].selected = selected1;
			}
			else {
				if (only == true) {
					obj.options[i].selected = selected2;
				}
			}
		}
	}
}

// -------------------------------------------------------------------
// selectMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression passed in. Currently-selected options will not be changed.
// -------------------------------------------------------------------
function selectMatchingOptions(obj, regex) {
	selectUnselectMatchingOptions(obj, regex, "select", false);
}
// -------------------------------------------------------------------
// selectOnlyMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression passed in. Selected options that don't match will be un-selected.
// -------------------------------------------------------------------
function selectOnlyMatchingOptions(obj, regex) {
	selectUnselectMatchingOptions(obj, regex, "select", true);
}
// -------------------------------------------------------------------
// unSelectMatchingOptions(select_object,regex)
//  This function Unselects all options that match the regular expression passed in. 
// -------------------------------------------------------------------
function unSelectMatchingOptions(obj, regex) {
	selectUnselectMatchingOptions(obj, regex, "unselect", false);
}

// -------------------------------------------------------------------
// 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);
	}
}

// -------------------------------------------------------------------
// selectAllOptions(select_object)
//  This function takes a select box and selects all options (in a multiple select object). This is used when passing values between
//  two select boxes. Select all options in the right box before submitting the form so the values will be sent to the server.
// -------------------------------------------------------------------
function selectAllOptions(obj) {
	if (!hasOptions(obj)) { return; }
	for (var i = 0; i < obj.options.length; i++) {
		obj.options[i].selected = true;
	}
}

// -------------------------------------------------------------------
// 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).
// -------------------------------------------------------------------
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;
}

// -------------------------------------------------------------------
// copySelectedOptions(select_object,select_object[,autosort(true/false)])
//  This function copies options between select boxes instead of moving items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copySelectedOptions(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);
			}
		}
	}
	if ((arguments.length < 3) || (arguments[2] == true)) {
		sortSelect(to);
	}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
}

// -------------------------------------------------------------------
// moveAllOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  Move all options from one select box to another.
// -------------------------------------------------------------------
function moveAllOptions(from, to) {
	selectAllOptions(from);
	if (arguments.length == 2) {
		moveSelectedOptions(from, to);
	}
	else if (arguments.length == 3) {
		moveSelectedOptions(from, to, arguments[2]);
	}
	else if (arguments.length == 4) {
		moveSelectedOptions(from, to, arguments[2], arguments[3]);
	}
}

// -------------------------------------------------------------------
// copyAllOptions(select_object,select_object[,autosort(true/false)])
//  Copy all options from one select box to another, instead of removing items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copyAllOptions(from, to) {
	selectAllOptions(from);
	if (arguments.length == 2) {
		copySelectedOptions(from, to);
	}
	else if (arguments.length == 3) {
		copySelectedOptions(from, to, arguments[2]);
	}
}

// -------------------------------------------------------------------
// swapOptions(select_object,option1,option2)
//  Swap positions of two options in a select list
// -------------------------------------------------------------------
function swapOptions(obj, i, j) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2 = new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
}

// -------------------------------------------------------------------
// moveOptionUp(select_object)
//  Move selected option in a select list up one
// -------------------------------------------------------------------
function moveOptionUp(obj) {
	if (!hasOptions(obj)) { return; }
	for (i = 0; i < obj.options.length; i++) {
		if (obj.options[i].selected) {
			if (i != 0 && !obj.options[i - 1].selected) {
				swapOptions(obj, i, i - 1);
				obj.options[i - 1].selected = true;
			}
		}
	}
}

// -------------------------------------------------------------------
// moveOptionDown(select_object)
//  Move selected option in a select list down one
// -------------------------------------------------------------------
function moveOptionDown(obj) {
	if (!hasOptions(obj)) { return; }
	for (i = obj.options.length - 1; i >= 0; i--) {
		if (obj.options[i].selected) {
			if (i != (obj.options.length - 1) && !obj.options[i + 1].selected) {
				swapOptions(obj, i, i + 1);
				obj.options[i + 1].selected = true;
			}
		}
	}
}

// -------------------------------------------------------------------
// removeSelectedOptions(select_object)
//  Remove all selected options from a list
// -------------------------------------------------------------------
function removeSelectedOptions(from) {
	if (!hasOptions(from)) { return; }
	if (from.type == "select-one") {
		from.options[from.selectedIndex] = null;
	}
	else {
		for (var i = (from.options.length - 1); i >= 0; i--) {
			var o = from.options[i];
			if (o.selected) {
				from.options[i] = null;
			}
		}
	}
	from.selectedIndex = -1;
}

// -------------------------------------------------------------------
// removeAllOptions(select_object)
//  Remove all options from a list
// -------------------------------------------------------------------
function removeAllOptions(from) {
	if (!hasOptions(from)) { return; }
	for (var i = (from.options.length - 1); i >= 0; i--) {
		from.options[i] = null;
	}
	from.selectedIndex = -1;
}

// -------------------------------------------------------------------
// addOption(select_object,display_text,value,selected)
//  Add an option to a list
// -------------------------------------------------------------------
function addOption(obj, text, value, selected) {
	if (obj != null && obj.options != null) {
		obj.options[obj.options.length] = new Option(text, value, false, selected);
	}
}

