function reWriteElement(isDisabled,strOnChangeHREF,canToggleElement,parentElementId,newElementId,newElementName,newElementClass,newElementWidth,tabIndex,toolTip,arr)
	{
	//sniff non-DOM browsers and ignore
	if(document.getElementById)
		{
		var parentEl = document.getElementById(parentElementId)
		if(parentEl.hasChildNodes())
			{
			for(i=0;i<parentEl.childNodes.length;i++)
				{
				if(parentEl.childNodes.item(i).name==newElementName)
					{
					parentEl.removeChild(parentEl.childNodes.item(i))
					break;
					}
				}
			}
		var newSelect = document.createElement('SELECT');
		    newSelect.setAttribute('id',newElementId);
			    //newSelect.setAttribute('tabindex',tabIndex); doesn't work in MSIE
		    newSelect.tabIndex=tabIndex; //if this doesn't work consistently, the perhaps creating an attribute object and setting it using setAttributeNode() should be implemented.
		    newSelect.title=toolTip;
		    newSelect.className=newElementClass;
		    newSelect.name=newElementName;
		    newSelect.disabled=isDisabled;
		    	    //newSelect.style.width=newElementWidth;
			    //newSelect.setAttribute('title',toolTip);
			    //newSelect.setAttribute('name',newElementName);
			    //newSelect.setAttribute('style','width:200px;');
			    //newSelect.setAttribute('class','required');

		if(strOnChangeHREF.length>0)
			{
			if(newSelect.addEventListener) //for mozilla
				{
				newSelect.addEventListener("change",function(event){loadOnChangeHREF(event,strOnChangeHREF)},false);
				}
			else if(newSelect.attachEvent) //msie
				{
				newSelect.attachEvent("onchange",function(event){loadOnChangeHREF(event,strOnChangeHREF)});
				}
			}

		if(canToggleElement)
			{
			if(newSelect.addEventListener) //for mozilla
				{
				newSelect.addEventListener("change",checkMakeNewToggleField,false);
				}
			else if(newSelect.attachEvent) //msie
				{
				newSelect.attachEvent("onchange",checkMakeNewToggleField);
				}
			}
							
		parentEl.appendChild(newSelect)
		var selectedI = 0;

		for(i=0;i<arr.length;i++)
			{
			arr[i] = arr[i].split('|')
			var newOption = document.createElement('OPTION');
			    newOption.value = arr[i][0];
			    newOption.text = arr[i][1];
			    newOption.selected=arr[i][2]; //buggy in msie
			if(arr[i][2]=='true')
				{//so workaround for msie
				selectedI=i;
				}
				//var newOption = new Option(arr[i][1],arr[i][0],true,arr[i][2]);
			newSelect.options[i] = newOption;
			}
		newSelect.selectedIndex=selectedI; //for MSIE.  mozzila doesn't need this line.
		}
	}




function checkMakeNewToggleField(event)
	{
	var srcEl;
	if(event.target)
		{
		srcEl = event.target;
		}
	else if(event.srcElement)
		{
		srcEl = event.srcElement;
		}

	if(srcEl.selectedIndex==1)
		{
		var newTextBox = srcEl.name+'MakeNew';
		srcEl.form.elements.namedItem(newTextBox).style.display='';
		}
	}




function loadOnChangeHREF(event,strURL)
	{
	var srcEl;
	if(event.target)
		{
		srcEl = event.target;
		}
	else if(event.srcElement)
		{
		srcEl = event.srcElement;
		}
	location.href=strURL+srcEl[srcEl.selectedIndex].value;
	}




function echoInOption(thisEl,targetElId,targetElName)
	{
	var targetEl = document.getElementById(targetElId).options[1];
	targetEl.value=thisEl.value;

	if(targetEl.innerText)
		{
		targetEl.innerText=thisEl.value;
		} else {
		targetEl.text=thisEl.value;
		}
	}




function checkFormRequiredFields(theForm,alertString)
	{
	if(document.getElementById)
		{
		var i;
		var el;

		var formIsValid;
		formIsValid = true;
		for(i=0;i<theForm.elements.length;i++)
			{
			el = theForm.elements.item(i);
			if((el.className=='required') || (el.className.indexOf("required")>0))
				{
				if(el.type!='select-one')
					{
					if(el.value.length==0)
						{
						formIsValid = false;
						alert(alertString);
						break;
						}
					} else {
					if(el[el.selectedIndex].value=='')
						{
						formIsValid = false;
						alert(alertString);
						break;
						}
					}
				}
			}
		return formIsValid;
		}
	}




function validateInputIsNumeric(thisEl,alertString)
	{
	var strValue;
	if(isNaN(thisEl.value))
		{
		strValue = thisEl.value;
		alert(alertString);
		thisEl.value = strValue.substr(0,(strValue.length-1));
		}
	}




function toggleDivsByClassName(divName)
	{
	elemnts=document.getElementsByTagName('div');

	for(i=0;i<elemnts.length;i++)

	if(elemnts[i].className==divName)
		{
		if(elemnts[i].style.display=='block' || elemnts[i].style.display=='')
			{
			elemnts[i].style.display='none';//inline';
			} else {
			elemnts[i].style.display='block';//inline';
			}					
		}
	}





function toggleInnerText(thisEl,label1,label2)
	{
	if(document.getElementById)
		{
		if(thisEl.childNodes[0].nodeValue==label1+' ')
			{
			thisEl.childNodes[0].nodeValue=label2+' ';
			} else {
			thisEl.childNodes[0].nodeValue=label1+' ';
			}
		}
	}




function validateInputIsFileName(thisEl,expectedExtension,alertString)
	{
	var isValidFileName = true;
	var strValue = thisEl.value;

	if(strValue.length<=5)
		{
		isValidFileName = false;
		}
	if(isValidFileName && (expectedExtension!=''))
		{
		if(strValue.substr(strValue.length-4,4).toLowerCase()!=expectedExtension)
			{
			isValidFileName = false;
			}
		}
	if(!isValidFileName)
		{
		alert(alertString);
		}
	return isValidFileName;
	}




// -------------------------------------------------------------------
// Courtesy of http://www.mattkruse.com/
// Original Author: Matt Kruse
// Thanks Matt, for creating such nice functions.
// 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;
		}
	}




// -------------------------------------------------------------------
// Courtesy of http://www.mattkruse.com/
// Original Author: Matt Kruse
// Thanks Matt, for creating such nice functions.
// moveSelectedOptions(FROMselect_object,TOselect_object[,autosort(true/false)[,regex]])
//  This function moves options between select boxes.
//  Passes all selected values from the first object to the second
//  object and re-sorts each box if third argument is not "false".
//  If a fourth string argument is passed, this will function as a
//  Regular Expression to match against the TEXT of the options. If 
//  the text of an option matches the pattern, it will NOT be moved.
//  It will be treated as an unmoveable option.
//  In browsers that support onDblClick, this function can be called
//  from a select object by:
//    ondblclick="moveSelectedOptions(this,this.form.target)
// -------------------------------------------------------------------
function moveSelectedOptions(from,to)
	{
	// Unselect matching options, if required
	if(arguments.length>3)
		{
		var regex = arguments[3];
		if(regex != "")
			{
			//unSelectMatchingOptions(from,regex); NOT IMPLEMENTED
			}
		}
	// 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;
	}




// -------------------------------------------------------------------
// Courtesy of http://www.mattkruse.com/
// Original Author: Matt Kruse
// Thanks Matt, for creating such nice functions.
// 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;
		} else {
		return false;
		}
	}




// -------------------------------------------------------------------
// Courtesy of http://www.mattkruse.com/
// Original Author: Matt Kruse
// Thanks Matt, for creating such nice functions.
// sortSelect(select_object)
//   Pass this function to 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);
		}
	}




// -------------------------------------------------------------------
// Courtesy of http://www.mattkruse.com/
// Original Author: Matt Kruse
// Thanks Matt, for creating such nice functions.
// 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;
				}
			}
		}
	}




// -------------------------------------------------------------------
// Courtesy of http://www.mattkruse.com/
// Original Author: Matt Kruse
// Thanks Matt, for creating such nice functions.
// 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;
				}
			}
		}
	}




// -------------------------------------------------------------------
// Courtesy of http://www.mattkruse.com/
// Original Author: Matt Kruse
// Thanks Matt, for creating such nice functions.
// 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;
	}


var arrPopUpWindows = new Array();
function doPopUp(windowname,windowURL,windowWidth,windowHeight,windowLeft,windowTop,directories,menubar,resizable,status,toolbar,scrollbars)
//
//windowname a string (this becomes the actual windowOBJECT. and the NAME of the object)
//windowURL a URL
//windowWidth a number
//windowHeight a number
//windowLeft a number (or "center" to center on screen)
//windowTop a number (or "center" to center on screen)
//directories yes/no
//menubar yes/no
//resizable yes/no
//status yes/no
//toolbar yes/no
//scrollbars yes/no
//
	{
	var objWindow;
	var listSettings;

	//?:
	//first condition returns true or false
	//second operand is expression IF TRUE
	//third operand is expression IF FALSE

	if(windowWidth=='maximum')
		{
		w = (screen.availWidth) ? (screen.availWidth) : (screen.width) ? (screen.width) : 740;
		} else {
		w = windowWidth;
		}

	if(windowHeight=='maximum')
		{
		h = (screen.availHeight) ? (screen.availHeight) : (screen.height) ? (screen.height) : 580;
		} else {
		h = windowHeight;
		}

	if(windowLeft=='center')
		{
		l = (screen.width) ? (screen.width-w)/2 : 0;
		} else {
		l = windowLeft;
		}

	if(windowTop=='center')
		{
		t = (screen.height) ? (screen.height-h)/2 : 0;
		} else {
		t = windowTop;
		}

	listSettings = 'directories='+directories+',menubar='+menubar+',resizable='+resizable+',status='+status+',toolbar='+toolbar+',height='+h+',width='+w+',top='+t+',left='+l+',scrollbars='+scrollbars;

	if(typeof(arrPopUpWindows[windowname]) != 'object')
		{
		//the window doesn't exist //create it and return it
		objWindow = window.open(windowURL,windowname,listSettings)
		arrPopUpWindows[windowname] = objWindow;
		} else {
		if(!arrPopUpWindows[windowname].closed)
			{
			//the window existed and is not closed (therefore must be open) //resize it, move it, and update its URL
			objWindow = arrPopUpWindows[windowname];
			objWindow.moveTo(l,t)
			objWindow.resizeTo(w,h)
			objWindow.location.href = windowURL;
			} else {
			//the window existed but is closed //re create it
			objWindow = window.open(windowURL,windowname,listSettings)
			arrPopUpWindows[windowname] = objWindow;
			}
		}
	objWindow.focus()
	return objWindow;
	}

