   /* 
    * Copyright 2005 Dave Feil. All rights reserved.
	*/
	/*
	* Global Javascript functions
	* this file should be included on every jsp page in the <head> tag
    */
	//These should match what is in JAVA
	var THEFORM = "theform";
	var SOURCEPAGEHF = "sourcepageHF";
	//target page is determined by setting the form action in PHP (no servlet or single entry point)
	//var TARGETPAGEHF = "targetpageHF";
	var PAGEACTIONHF = "pageactionHF";
	var SORTCOLUMNHF = "sortColumnValueHF";
	var SORTCOLUMNACTION = "sortColumnAction";
	
	var MAXTA = 500;

	/*___________________________________________________________________________
	* General Dreamweaver Functions
    */
	function MM_reloadPage(init) {  //reloads the window if Nav4 resized
	  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
	    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
	  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
	}
	MM_reloadPage(true);
	function MM_findObj(n, d) { //v4.01
  		var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
	


	function stringTrim(s) {
		if (s == null) {
			return s;
		}
		while (s.substring(0,1) == ' ') {
			s = s.substring(1,s.length);
		}
		while (s.substring(s.length-1,s.length) == ' ') {
			s = s.substring(0,s.length-1);
		}
		return s;
	}

	
   /* 
    * Copyright 2005 Dave Feil. All rights reserved.
	*/	
   /*
	* return true if event is the enter key being pressed
	* param event object
	*/	
	var IE = (document.all) ? true : false;
	function isEnterEvent(event) { 
		var code = 0;
		if (IE) {
			code = event.keyCode;
		} else {
			code = event.which;
		}	
		if (code==13 || code==3) {
			return true;
		}
		return false;
	}
	
   /*
	* param aLocation String
	*/
	function openWindow(newURL, windowName, windowWidth, windowHeight,opts) {
		var defaultOpts = "status=1,resizable=1,location=1,directories=1,menubar=1,toolbar=1,titlebar=1,scrollbars=1";
		if (opts != null) {
			defaultOpts = opts;
		}
		if (windowWidth == null || windowHeight == null) {
			return window.open(newURL, windowName,defaultOpts);		
		} else {
			var leftLoc=(screen.width-windowWidth)/2;
			var topLoc=(screen.height-windowHeight)/2;
			return window.open(newURL, windowName, "width="+windowWidth+",height="+windowHeight+",left="+leftLoc+",top="+topLoc+","+defaultOpts);
		}
	}
	function openFeedbackWindow(newURL,windowName) {
		var opts = "status=0,resizable=0,location=0,directories=0,menubar=0,toolbar=0,titlebar=1";
		var actualURL = newURL;
		if (actualURL == null || actualURL == "") {
			actualURL = "about:blank";
		}
		openWindow(actualURL,windowName,400,200,opts);
	}
	/*
	* Navigate to aURL.  Instead of submitting a form this method might be more appropriate.  
	* Push button that navigates to another handler without any actions for example.
	*
	* param aURL String - URL to navigate to.
	*/
	function gotoURL(aURL) {
		location = aURL;
		//NOTE Avoid using replace method of navigation because of Safari
		//location.replace(aURL);
	}
	/*
	* scroll to an anchor 
	*
	* param anchorName String 
	*/
	function goToAnchor(anchorName) {
		document.location.hash=anchorName;
	}
   /*
	* browser sniffer
	*/
	function isMac() {
	    var agt=navigator.userAgent.toLowerCase();
		return (agt.indexOf("mac")!=-1);
	}
	function isMacSafari() {
	    var agt=navigator.userAgent.toLowerCase();
		return (isMac() && (agt.indexOf('safari')!=-1));
	}
	function isMacIE() {
		var appVer = navigator.appVersion.toLowerCase();
		return (isMac() && (appVer.indexOf('msie')!=-1));
	}
   /* 
    * Copyright 2005 Dave Feil. All rights reserved.
	*/
   /*___________________________________________________________________________
	* Layer Functions
    */
	/*
	* Find any object on the HTML page
	* 
	* param objectName
	*/
	function findAnyObject(objectName) {
		return MM_findObj(objectName);	
	}
   /*
	* hide or show a layer
	* 
	* param layerObject layer object
	* param isShow boolean
	*/
	function hideShowLayer(layerObject, isShow) {
		var workingObject = layerObject;
		if (workingObject.style) { 
			workingObject=workingObject.style; 
		}
		if (isShow) {
			workingObject.visibility = 'visible'; 
		} else {
			workingObject.visibility = 'hidden'; 
		}
	}
	function hideLayer(layerObject) {
		hideShowLayer(layerObject, false);
	}
	function showLayer(layerObject) {
		hideShowLayer(layerObject, true);
	}
	/*
	* hide or show a layer using the display property
	* 
	* param layerObject layer object
	* param isShow boolean
	*/
	function displayLayer(layerObject, isShow) {
		var workingObject = layerObject;
		if (workingObject.style) { 
			workingObject=workingObject.style; 
		}
		if (isShow) {
			workingObject.display = ''; 
		} else {
			workingObject.display = 'none'; 
		}
	}
	
   /* 
    * Copyright 2005 Dave Feil. All rights reserved.
	*/
   /*___________________________________________________________________________
	* Form and Form Items
    */
		
   /*
	* return the form object reference
	*/
	function getForm(formName) {
		if (formName != null) {
			return findAnyObject(formName);
		} else {
			return eval("document."+THEFORM);	
		}
	}
   /*
	* return the form item object reference with given name
	* 
	* param formItemName String name of the object to get
	*/
	function getFormItem(formItemName) {
		return findAnyObject(formItemName);
	}
   /*
	* return the "value" property of the form item object reference with given name
	* 
	* param formItemName String name of the object to get
	*/
	function getFormItemValue(formItemName) {
		var formitem = getFormItem(formItemName);
		return (formitem == null) ? null : formitem.value;
	}	
   /*
	* return the value of the selected radio button.  null if none selected
	* 
	* param radioButtonsName String name of the radio button set
	*/
	function getSelectedRadioNamed(radioButtonsName) {
		return getSelectedRadioValue(getFormItem(radioButtonsName));
	}
   /*
	* return the value of the selected radio button.  null if none selected
	* 
	* param formItem RadioButton form object
	*/	
	function getSelectedRadioValue(formItem) {
		if (formItem == null || formItem.length == 0) {
				return "";
		}
		for (var i = 0; i < formItem.length; i++) {
			var currentItem = formItem[i];
			if (currentItem.checked) {
				return currentItem.value;
			}
		}
		return null;
	}
	/*
	* Set the value of a hidden field
	* 
	* param fieldName String - name of the hidden field form object
	* param newValue String - value to set 	
	*/	
	function setHiddenFieldValue(fieldName, newValue) {
		var hiddenField = getFormItem(fieldName);
		hiddenField.value = newValue;
	}
	
   /*
	* Submit the form after setting the action to pageAction.  Submits the form to the target page handler.
	* 
	* param pageAction String - name of the action defined by Java Page Handler for this page
	* param targetWindow String - name of the window the form should show it's results
	*/
	function submitForm(pageAction, targetWindow, formName) {
		setHiddenFieldValue(PAGEACTIONHF, pageAction);
		var theForm = getForm(formName);
		if (targetWindow != null && targetWindow != "") {
			theForm.target = targetWindow;
		} else {
			theForm.target = "_self";
		}
		theForm.submit();
		return false;
	}
	/*
	* Download a PDF into a new window or for mac in same window (Which will popup the preview app to show the pdf)
	* 
	* param pageHandlerClass String - Name of the JAVA page handler class to handle this request.
	* param pageAction String - name of the action defined by Java Page Handler for this page
	*/
	function downloadPDF(pageAction, seperateWindowIndicatorHF) {
		//if (isMacSafari() || isMacIE()) {
		if (isMac()  && !isMacSafari()) {
			submitForm(pageAction);	
		} else {
			//let server know if request will be returning on a seperate window  (for user messages)
			if (seperateWindowIndicatorHF != null) {
				setHiddenFieldValue(seperateWindowIndicatorHF, 'true');
			}
			submitForm(pageAction,"PDFWINDOW");
		}
	}
	/* 
	 * return true if the string has a value
	 * 
	 * param valueString
	 */ 
	function stringHasValue(valueString) {
		if (valueString == null || stringTrim(valueString) == "") {
			return false;
		}
		return true;
	}
	/* 
	 * return the form item object reference with given name 
	 * 
	 * param formItemName String name of the object to get 
	 */ 
	function itemHasValue(formItemObject) {
		if (formItemObject == null || !stringHasValue(formItemObject.value)) {
			return false;
		}
		return true;
	}
	/* 
	 * return true if the form item is checked
	 * 
	 * param formItemObject
	 */ 
	function itemIsChecked(formItemObject) {
		if (formItemObject == null || formItemObject.checked == null) {
				return false;
		} else {
				return formItemObject.checked;
		}
	}
   /*
	* Select All radio buttons with the given prefix and ending in the id in listIds.
	* Check box name is made up of prefix + id where id is each id in the array.
	* globalAllSelected stores the state of what was last selected
	* 
	* param prefix String - prefix of the check box name
	* param listIds Id Array - ids of each row.  (ending part of the name of the check box)
	*/	
	var globalAllSelected = false;
	function selectAllCheckbox(prefix, listIds) {
		var form = getForm();
		globalAllSelected = !globalAllSelected;
		for (var i = 0; i < listIds.length; i++) {
			var checkbox = getFormItem(prefix + listIds[i]);
			if (checkbox != null) {
				checkbox.checked = globalAllSelected;
			}
		}
	}
	/*
	* select a specific optionValue on the given dropDown object.
	* 
	* param dropDownName String - name of the select drop down object
	* param optionValue any - the value that is compared to each option in the drop down.
	*/	 	
	function selectOptionOnDropDown(dropDownName, optionValue) {
		var dropDown = getFormItem(dropDownName);
		if (dropDown != null) {
			var ddOptions = dropDown.options;
			for (var i = 0; i < ddOptions.length; i++) {
				var anOption = ddOptions[i];
				if (anOption.value == optionValue) {
					anOption.selected = true;
					return;
				}
			}
		}
	}
		/*
	* select a specific optionValue on the given dropDown object.
	* 
	* param dropDownName String - name of the select drop down object
	* param optionValue any - the value that is compared to each option in the drop down.
	*/	
	function selectIndexOnDropDown(dropDownName, index) {
		var dropDown = getFormItem(dropDownName);
		if (dropDown != null) {
			var ddOptions = dropDown.options;
			var anOption = ddOptions[index];
			anOption.selected = true;
		}
	}
	
	/*
	* select an item that is similar to optionValue on the given dropDown object.
	* 
	* param dropDownName String - name of the select drop down object
	* param optionValue any - the value that is compared to each option in the drop down.
	*/	 	
	function selectLikeNameOnDropDown(dropDownName, optionValue) {
		var dropDown = getFormItem(dropDownName);
		if (dropDown != null) {
			var ddOptions = dropDown.options;
			for (var i = 0; i < ddOptions.length; i++) {
				var anOption = ddOptions[i];
				if (anOption.text.toLowerCase().indexOf(optionValue.toLowerCase()) != -1) {
					anOption.selected = true;
					return;
				}
			}
		}
	}
	/*
	* select a matching value in a drop down based on a value in an entry field.
	* 
	* param dropDownName String - name of the select drop down object
	* param entryFieldName String - name of the entry field search field
	*/	
	function dropDownSearchChanged(dropDownName, entryFieldName) {
		var searchFieldEF = getFormItem(entryFieldName);
		selectLikeNameOnDropDown(dropDownName, searchFieldEF.value);
	}
   /*
	* move selected items from one multiselect to another.  
	* 
	* param sourceMultiName String - name of the source multi select 
	* param destinationMultiName String - name of the destination
	* param hiddenFieldName String - name of the hidden field that will hold the id's of items in destination
	*/	
	function moveChooserItems(sourceMultiName, destinationMultiName, isMoveRight, hiddenFieldName) {
		var sourceMS = getFormItem(sourceMultiName);
		var destMS = getFormItem(destinationMultiName);
		var sourceOptions = sourceMS.options;
		var destOptions = destMS.options;
		var newSource = new Array();
		var newDest = new Array();
		var debug = "";
		for (var i = 0; i < destOptions.length; i++) {
			var destOption = destOptions[i];
			newDest[newDest.length] = new Option(destOption.text,destOption.value);
		}
		for (var i = 0; i < sourceOptions.length; i++) {
			var sourceOption = sourceOptions[i];
			var newSourceOption =  new Option(sourceOption.text, sourceOption.value);
			if (sourceOption.selected) {
				newSourceOption.selected = true;
				newDest[newDest.length] = newSourceOption;
			} else {
				newSource[newSource.length] = newSourceOption;
			}
		}
		//store destination id's in the hidden field if it exists.
		var hiddenFieldValue = "";
		if (isMoveRight) {
			for (var i = 0; i < newDest.length; i++) {
				var newOption = newDest[i];
				if (i > 0) {
					hiddenFieldValue += ",";
				}
				hiddenFieldValue += newOption.value;
			}
		} else {
			for (var i = 0; i < newSource.length; i++) {
				var newOption = newSource[i];
				if (i > 0) {
					hiddenFieldValue += ",";
				}
				hiddenFieldValue += newOption.value;
			}
		}
		var hiddenField = getFormItem(hiddenFieldName);
		hiddenField.value = hiddenFieldValue;
		//alert(hiddenFieldValue);
		sourceMS.length = 0;
		destMS.length = 0;
		for (var i = 0; i < newSource.length; i++) {
			var newOption = newSource[i];
			sourceMS.options[i] = newOption;
		}
		for (var i = 0; i < newDest.length; i++) {
			var newOption = newDest[i];
			destMS.options[i] = newOption;
		}
		
	}

   /*
	* Set focus to the form object with given name
	* 
	* param formObjectName String - name of the form object 
	*/	
	function focusOn(formObjectName) {
		var formItem = getFormItem(formObjectName);
		if (formItem != null) {
			formItem.focus();
			formItem.select();
		}
	}
   /*
	* control the length of text in a text area form object.  
	* if it gets too long an alert can be shown
	* 
	* param taName String - name of the text area form object
	* param maxChars int - number of chars allowed or null
	* param countEFName String - name of the object to set with the count
	*/
	function taChanged(taName,maxChars,countEFName) {
		var ta = getFormItem(taName);
		if (ta == null) {
			return;
		}
		var count = ta.value.length;
		if (maxChars != null && maxChars > 0) {
			if (count > maxChars) {
				alert("Max characters limit reached");
				ta.value = ta.value.substring(0,maxChars);
				count--;
			}
		}
		if (countEFName != null) {
			var countEF = getFormItem(countEFName);
			if (countEF != null) {
				countEF.value = count;
			}
		}
	}
	function enableFormItem(formObjectName, isEnable) {
		var formItem = getFormItem(formObjectName);
		if (formItem != null) {
			if (isEnable == null) {
				formItem.disabled = false;
			} else {
				formItem.disabled = !isEnable;
			}
		}
	}
	function disableFormItem(formObjectName) {
		enableFormItem(formObjectName, false);
	}
	function enableFormItems(formObjectNameArray) {
		for (var i = 0; i < formObjectNameArray.length; i++) {
			enableFormItem(formObjectNameArray[i]);
		}
	}
	function disableFormItems(formObjectNameArray) {
		for (var i = 0; i < formObjectNameArray.length; i++) {
			disableFormItem(formObjectNameArray[i]);
		}
	}
   /* 
    * Copyright 2005 Dave Feil. All rights reserved.
	*/
   /*___________________________________________________________________________
	* Image Rollover Functions
    */
	function RolloverImage(imageSrc, overImageSrc) {
		this.image = new Image();
		this.image.src = imageSrc;
		this.overImage = new Image();
		this.overImage.src = overImageSrc;

		//methods
		this.rollOverAction = RolloverImage_rollOverAction;
		this.rollOutAction = RolloverImage_rollOutAction;
	}
	function RolloverImage_rollOverAction(imageObj) {
		imageObj.src = this.overImage.src;
	}
	function RolloverImage_rollOutAction(imageObj) {
		imageObj.src = this.image.src;
	}
	/* 
    * Copyright 2005 Dave Feil. All rights reserved.
	*/
   /*___________________________________________________________________________
	* URL handling object and functions
    */
	function JDURL(theUrl) {
		this.url = theUrl;
		
		//methods
		this.appendParam = JDURL_appendParam;
		this.getUrl = JDURL_getUrl;
	}
	function JDURL_getUrl() {
		return this.url;
	}
	function JDURL_appendParam(newName, newValue) {
		var delim = "?";
		var working = this.url;
		if (working == null || newName == null || newValue == null) {
			return;
		}
		if (working.indexOf("?") != -1) {
			delim = "&";
		}
		this.url = working + delim + newName + "=" + escape(newValue);
	}
	/*___________________________________________________________________________
	* Date chooser popup
    */
	function chooseDate(fieldName) {
		return NewCal(fieldName,'mmddyyyy');
	}
	function chooseDateTime(fieldName) {
		return NewCal(fieldName,'mmddyyyy',true, 12);
	}
	
