//
// Open a "standard" lookup window, centered on the screen and set the focus to it.
//
function openPopupWindow(url,id) {
	var winWidth=760;
	var winHeight=550;
	openPopupWindowSized(url, id, winWidth, winHeight);
}

//
// Open a "standard" popup window, centered on the screen and set the focus to it.
//
function openPopupWindowSized(url, id, winWidth, winHeight) {

	// This only centers the popup in the screen, would like to have it center on
	// application at some point.
	var x=screen.width/2-winWidth/2;
	var y=screen.height/2-winHeight/2;

	var winAttrib='scrollbars=yes,toolbar=no,location=no,status=no,resizable=yes,'+
					  'width='+winWidth+',height='+winHeight+',left='+x+',top='+y;
	var newWindow = window.open(url,id,winAttrib);
	if (newWindow) newWindow.focus();
	return newWindow;
}

/*************************************************************
   Function name:  closePopupAndRefreshParent
         Purpose:  refresh the parent page then close the current page
          Inputs:  none
         Outputs:  nothing
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function closePopupAndRefreshParent() {
	window.opener.location=window.opener.location; window.close();
}



function confirmCsRemoval() {
	return confirmThis("Click OK to remove this item, or Cancel to return to the page.");
}

function confirmDatagridItemDelete() {
	return confirmThis("Click OK to delete this item.");
}

function confirmThis(pMessage) {
	return confirm(pMessage);
}

function ShowImage(pImage) {
	newImage=new Image;
	newImage.src=pImage.src;
	openPopupWindowSized(pImage.src, '_new', newImage.width+40, newImage.height+42);
}

/* Shows an object by adding it */
function showIt2(objID) 
{
	//inline, block, and none are the valid display args
	getObjectByID(objID).style.display= "inline";
}

/* Hides an object by removing it*/
function hideIt2(objID) 
{
	//inline, block, and none are the valid display args
	getObjectByID(objID).style.display="NONE";
}



//
// Retrieve the "value" of the given field in a browser-independent fashion.
//
function setValue(pField, pValue) {
//alert('setValue: ' + pField.toString() + " = " + pValue);

	if (pField.type == 'select-one') {
//		lValue = pField.options[pField.selectedIndex].value;
		for (i=0; i<pField.options.length; i++)
			if (pField.options[i].value == pValue) {
				pField.selectedIndex = i;
				break;
			}
	} else if (pField.type == "checkbox") {
		if (pValue == true || pValue == "Y")
			pField.checked = true;
		else pField.checked = false;
	} else if (pField.tagName == "DIV") {
		pField.innerText = pValue;
	} else {
		pField.value = pValue;
	}
}



//pField must be an object - use getObjectByID('fieldName')
function getValue(pField) {
	lValue = '';
	if (pField==null || pField=="null") {
		return '';
	}
	else if (pField.type == "button") {
		lValue = '';
	}
	else if (pField.type == "checkbox") {
		lValue = pField.checked ? true : false;//"Y" : "";
	}
	else if (pField.type == "file") {
		lValue = '';
	}
	else if (pField.type == "hidden") {
		lValue = pField.value;
	}
	else if (pField.type == "image") {
		lValue = pField.value;
	}
	else if (pField.type == "password") {
		lValue = pField.value;
	}
	else if (pField.type == "radio") {
		lValue = pField.checked ?  true : false;//"Y" : "";
	}
	else if (pField.type == "reset") {
		lValue = '';
	}
	if (pField.type == 'select-multiple') {
		lValue = '';
	}
	if (pField.type == 'select-one') {
		lValue = pField.options[pField.selectedIndex].value;
	}
	else if (pField.type == "text") {
		lValue = pField.value;
	}
	else if (pField.type == "textarea") {
		lValue = pField.value;
	}

	if (lValue == null || lValue == 'null')
		lValue = '';
		
	//alert(pField + " : " + pField.type + " : " + lValue);
	return lValue;
}


//
// Build a URL with embedded fieldname=value pairs.
//
function buildUrl(pUrl, pFormName, pFieldNames, pIncludeEmpty) {
	if (pIncludeEmpty == null || pIncludeEmpty != true)
		pIncludeEmpty = false;
	var lLength = pFieldNames.length;
	var lArgs = "";
	for (i=0; i<lLength; i++) {
		var lField = document.forms[pFormName].elements[pFieldNames[i]];
		var lValue = getValue(lField);
		if (!pIncludeEmpty)
			lArgs += ((lValue.length > 0) ? (((lArgs.length > 0) ? '&' : '') + (pFieldNames[i]+'='+escape(lValue))) : '');
		else
			lArgs += ( ((lArgs.length > 0) ? '&' : '') + (pFieldNames[i]+'='+escape(lValue)) );
	}
	var lNewUrl = pUrl.replace(/replace=me/,lArgs);
//alert(lNewUrl);
	return lNewUrl;
}



//
// Build a 'callback' script which "backfills" the given fields with values.
//
function buildCallback( pFormName, pFieldNames, pResultNames) {

	var lLength = pFieldNames.length;
	var lCallback = "";
	for (i=0; i<lLength; i++) {
		var lField = document.forms[pFormName].elements[pFieldNames[i]];
		lCallback += ((lField != null) ?
			("opener.setValue(opener.document.forms['"+pFormName+"'].elements['"+pFieldNames[i]+"'],"+pResultNames[i]+"); ") : "");
	}
//alert(lCallback);
	return lCallback;
}


//
// Converts the data in the given field to upper case.
//
function upperCase (pField) {
	pField.value = pField.value.toUpperCase();
}


// Trim whitespace from beginning & end of string.
function trimString(lVal) {	
	while (lVal.length > 0 && (lVal.charAt(0) == ' ' || lVal.charAt(0) == '\t'))
		lVal = lVal.substr(1);
	while (lVal.length > 0 && (lVal.charAt(lVal.length-1) == ' ' || lVal.charAt(lVal.length-1) == '\t'))
		lVal = lVal.substr(0, lVal.length-1);		
	return lVal;
}

/*************************************************************
   Function name:  trim
         Purpose:  trim a field of whitespace
          Inputs:  string
         Outputs:  none
         Returns:  trimmed string
         Creator:  Aaron K. Murray
*************************************************************/
function trim(pTrimThis){
	if(pTrimThis.length < 1){
		return"";
	}
	pTrimThis = trimRight(pTrimThis);
	pTrimThis = trimLeft(pTrimThis);
	if(pTrimThis==""){
		return "";
	} else {
		return pTrimThis;
	}
} 

/*************************************************************
   Function name:  trimRight
         Purpose:  right trim a field of whitespace
          Inputs:  string
         Outputs:  none
         Returns:  trimmed string
         Creator:  Aaron K. Murray
*************************************************************/
function trimRight(pTrimThis){
	var w_space = String.fromCharCode(32);
	var v_length = pTrimThis.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;
	
	while(iTemp > -1){
		if(pTrimThis.charAt(iTemp) == w_space){
	
		} else {
			strTemp = pTrimThis.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	} 
	return strTemp;
} 

/*************************************************************
   Function name:  trimLeft
         Purpose:  left trim a field of whitespace
          Inputs:  string
         Outputs:  none
         Returns:  trimmed string
         Creator:  Aaron K. Murray
*************************************************************/
function trimLeft(pTrimThis){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = pTrimThis.length;
	var strTemp = "";
	
	var iTemp = 0;
	
	while(iTemp < v_length){
		if(pTrimThis.charAt(iTemp) == w_space) {

		} else {
			strTemp = pTrimThis.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} 
	return strTemp;
} 


//functions to limit the type of characters allowed in textfields


/*************************************************************
   Function name:  onlyAllowNumbers
         Purpose:  only allow number keys to be pressed
          Inputs:  showAlertYN
         Outputs:  none
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function onlyAllowNumbers(showAlertYN) {
 	var charCode = event.keyCode;
	if ((charCode < 48) || (charCode > 57)) {
	 if (showAlertYN == "Y" || showAlertYN == "y") { alert('Only enter numbers'); }
	 event.cancelBubble = true
	 event.returnValue = false;
	}
}

/*************************************************************
   Function name:  onlyAllowTime
         Purpose:  only allow number keys and colon ':' to be pressed
          Inputs:  showAlertYN
         Outputs:  alert popup (optional)
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function onlyAllowTime(showAlertYN) {
	var charCode = event.keyCode;
	if ( ((charCode < 48) || (charCode > 57)) && (charCode != 58) ) {
	 if (showAlertYN == "Y" || showAlertYN == "y")
		 alert('Only enter numbers or a colon (:)');

	 event.cancelBubble = true
	 event.returnValue = false;
	}
}

/*************************************************************
   Function name:  onlyAllowDate
         Purpose:  only allow number/slash keys to be pressed
          Inputs:  showAlertYN
         Outputs:  none
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function onlyAllowDate(showAlertYN) {
 	var charCode = event.keyCode;
	if (((charCode < 47) && (charCode != 13)) || (charCode > 57)) {
	 if (showAlertYN == "Y" || showAlertYN == "y") { alert('Only enter numbers or slashes (/)'); }
	 event.cancelBubble = true
	 event.returnValue = false;
	}
}

/*************************************************************
   Function name:  onlyAllowZip
         Purpose:  only allow number/dash keys to be pressed
          Inputs:  showAlertYN
         Outputs:  none
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function onlyAllowZip(showAlertYN) {
	var charCode = event.keyCode;
	if (charCode !=45) {
		if (((charCode < 47) && (charCode != 13)) || (charCode > 57)) {
		 if (showAlertYN == "Y" || showAlertYN == "y")
		 {
			 alert('Only enter numbers or dashes (-)');
		 }
		 event.cancelBubble = true
		 event.returnValue = false;
		}
	}
}

/*************************************************************
   Function name:  onlyAllowPhone
         Purpose:  only allow (phone) number keys to be pressed
          Inputs:  showAlertYN
         Outputs:  none
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function onlyAllowPhone(showAlertYN) {
	var charCode = event.keyCode;
	if (charCode !=45) { //45 is a -
		if (charCode !=40) { //40 is a (
			if (charCode !=41) { //41 is a )
				if (charCode !=32) { //32 is a space
					if ((charCode < 48) || (charCode > 57)) {
						if (showAlertYN == "Y" || showAlertYN == "y") {
							alert('Only enter numbers, dashes, or parentheses');
						}
			 			event.cancelBubble = true
			 			event.returnValue = false;
					}
				}
			}
		}
	}
}

/*************************************************************
   Function name:  onlyAllowName
         Purpose:  only allow letters/dash/apostrophe keys to be pressed
          Inputs:  showAlertYN
         Outputs:  none
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function onlyAllowName(showAlertYN) {
	var charCode = event.keyCode;
	if (charCode !=45) { //45 is a -
		if (charCode !=39) { //39 is a '
			if ( (charCode < 65) || (charCode > 122) || ((charCode > 90) && (charCode < 97)) ) { //less than A, or greater than z, or between Z and a
				if (showAlertYN == "Y" || showAlertYN == "y") {
					alert('Only enter numbers, dashes, or apostrophes');
				}
			 	event.cancelBubble = true
			 	event.returnValue = false;
			}
		}
	}
}

/*************************************************************
   Function name:  onlyAllowLetters
         Purpose:  only allow letter keys to be pressed
          Inputs:  showAlertYN
         Outputs:  none
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function onlyAllowLetters(showAlertYN) {
	var charCode = event.keyCode;
	if ( (charCode < 65) || (charCode > 122) || ((charCode > 90) && (charCode < 97)) ) { //less than A, or greater than z, or between Z and a
		if (showAlertYN == "Y" || showAlertYN == "y") {
			alert('Only enter letters');
		}
		event.cancelBubble = true
	 	event.returnValue = false;
	}
}


/*************************************************************
   Function name:  goTo
         Purpose:  change the browser location - go to a page
          Inputs:  link
         Outputs:  none
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function goTo(link){
	location.href=link;
}


/*************************************************************
   Function name:  textCounter
         Purpose:  trim a field if over the char limit
          Inputs:  field, maxlimit
         Outputs:  none
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function textCounter(field, maxlimit) {
	if (field.value.length > maxlimit) {
		// if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	} 
}

/*************************************************************
   Function name:  getCharsLeft
         Purpose:  return number of chars left in a textarea
          Inputs:  field, maxLen
         Outputs:  nothing
         Returns:  number of chars left in a textarea
         Creator:  Aaron K. Murray
*************************************************************/
function getCharsLeft(field, maxLen) {
	return (maxLen - field.value.length);
}

/*************************************************************
   Function name:  getObjectByID
         Purpose:  return html object based on the ID
          Inputs:  id
         Outputs:  nothing
         Returns:  html object 
         Creator:  Aaron K. Murray
*************************************************************/
function getObjectByID(id) {
	try {
		var objs;
		if (document.getElementById) { 
			objs = document.getElementById(id); 
		} else if (document.all) { 
			objs = document.all[id]; 
		} else if (document.layers) { 
			objs = document.all[id]; 
		} 
		return objs;
	} catch (err) {
		return null;
		//ignore this 	
	}
}
function GetObjectByID(id) {
	return getObjectByID(id);
}

/*************************************************************
   Function name:  addSelectOption
         Purpose:  add a select option to an existing dropdown
          Inputs:  id
         Outputs:  new select object into the passed object
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function addSelectOption( pText, pValue, pSelectObject) {
	pSelectObject.options[pSelectObject.options.length]= new Option(pText,pValue);
}


/*************************************************************
   Function name:  getIndexOfSelectItem
         Purpose:  get a numeric index for the corresponding option value
          Inputs:  pDropdown, pOptionValue
         Outputs:  nothing
         Returns:  first index # of the option with a matching value
         Creator:  Aaron K. Murray
*************************************************************/
function getIndexOfSelectItem(pDropdown, pOptionValue) {
	var i;
	for(i=0;i<pDropdown.options.length;i++){
    	if(pDropdown.options[i].value==pOptionValue){ //values match
			return i;
		}
	}
	return 0; //default value
}

/*************************************************************
   Function name:  ClearDropDownList
         Purpose:  clears all elements of a dropdownlist
          Inputs:  listName
         Outputs:  nothing
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function ClearDropDownList(listName) {
    var theList = document.getElementById(listName);
	for (var count = theList.options.length-1; count >-1; count--) { theList.options[count] = null; }	//Clears the list contents.
}

function GetDropdownTextForObjectByID(id) {
	var selectObject = getObjectByID(id)
	return selectObject.options[selectObject.selectedIndex].text;
}



//Returns the node text value 
function getInnerText(pNode)
{
	if (pNode == null) {
		return "";
	} else  {
		return (pNode.textContent || pNode.innerText || pNode.text) ;
	}
}


/*************************************************************
   Function name:  disableField
         Purpose:  disable a form field
          Inputs:  object - field
         Outputs:  none
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function disableField(pField){
	if (getObjectByID(pField) == null) { //then pField is already an object
		pField.disabled = true;
	} else {
		getObjectByID(pField).disabled = true;
	}
} 

/*************************************************************
   Function name:  enableField
         Purpose:  enable a form field
          Inputs:  object - field
         Outputs:  none
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function enableField(pField){
	if (getObjectByID(pField) == null) { //then pField is already an object
		pField.disabled = false;
	} else {
		getObjectByID(pField).disabled = false;
	}
} 

/*************************************************************
   Function name:  enableAllFields
         Purpose:  enable all form fields
          Inputs:  nothing
         Outputs:  none
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function enableAllFields() {
	var i;
	var f;
	// types: text|textarea|password|checkbox|radio|submit|reset|file|hidden|image|button|undefined
	//alert("enabling fields");
	for (f=0; f<document.forms.length; f++) {
		var formElements = document.forms[f].elements;
		for (i=0; i<formElements.length; i++) {
			//alert("form " + f + " : element " + i + " has type " + formElements[i].type + " and name " + formElements[i].name + " and id " + formElements[i].id);
			if (formElements[i].type == "text" || formElements[i].type == "textarea" || formElements[i].type == "select-one" || formElements[i].type == "checkbox" || formElements[i].type == "radio" || formElements[i].type == "file" || formElements[i].type == "password") {
				enableField(formElements[i].id);
			} 
		}
	}
}

/*************************************************************
   Function name:  disableAllFields
         Purpose:  disable all form fields
          Inputs:  nothing
         Outputs:  none
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function disableAllFields() {
	var i;
	var f;
	// types: text|textarea|password|checkbox|radio|submit|reset|file|hidden|image|button|undefined
	
	for (f=0; f<document.forms.length; f++) {
		var formElements = document.forms[f].elements;
		for (i=0; i<formElements.length; i++) {
			if (formElements[i].type == "text" || formElements[i].type == "textarea" || formElements[i].type == "select-one" || formElements[i].type == "checkbox" || formElements[i].type == "radio" || formElements[i].type == "file" || formElements[i].type == "password") {
				disableField(formElements[i].id);
			} 
		}
	}
}

/*************************************************************
   Function name:  clearFieldValue
         Purpose:  clear a form field value
          Inputs:  string - field name
         Outputs:  none
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function clearFieldValue(pField) {
	if (getObjectByID(pField) == null) { //then pField is already an object
		setValue(pField, ""); 
	} else {
		setValue(getObjectByID(pField), ""); 
	}
}

/*************************************************************
   Function name:  hide
         Purpose:  hide an object
          Inputs:  string - object id (or the actual object)
         Outputs:  none
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function hide(pId) {
	var field = getObjectByID(pId);
	if (field != null) { //hide this
		field.style.display = "none";
		field.style.visibility = "hidden";
	}
}

/*************************************************************
   Function name:  show
         Purpose:  show an object
          Inputs:  string - object id (or the actual object)
         Outputs:  none
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function show(pId) {
	var field = getObjectByID(pId);
	if (field != null) { //hide this
		field.style.display = "inline";
		field.style.visibility = "visible";
	}
}


/*************************************************************
   Function name:  showhide
         Purpose:  show or hide an object
          Inputs:  string - object id 
         Outputs:  none
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function showHide(pId)
{
    var field = getObjectByID(pId);
    if (field != null)
    {
        if (field.style.visibility == "hidden")
        {
			show(pId);
//        field.style.display = "block";
        } else {
			hide(pId);
        }
    }
}


/*************************************************************
   Function name:  SetImageUrlOrHideIt
         Purpose:  change the image based on the selected ID
          Inputs:  string - url, string - id of the img element
         Outputs:  changes an image (or hides it)
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function SetImageUrlOrHideIt(pUrl, pClientImageId)
{
	if (pUrl == "" || pUrl == null || pClientImageId == null || pClientImageId == "") {
		if (pClientImageId != null && pClientImageId != "")
			hide(pClientImageId);
	} else {
		getObjectByID(pClientImageId).src = pUrl;
		show(pClientImageId);
	}
}

/*************************************************************
   Function name:  ChangeCssClass
         Purpose:  change the css class of the object
          Inputs:  string - object name, string - css class
         Outputs:  changes the css class
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function ChangeCssClass(pObject, pCssClass)
{	
	if (pObject)
		pObject.className = pCssClass;
}

/*************************************************************
   Function name:  ChangeCssClass
         Purpose:  change the css class of the object
          Inputs:  string - object name, string - css class
         Outputs:  changes the css class
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function ChangeCssClassById(pObjectId, pCssClass)
{
	if (pObject)
		getObjectByID(pObjectId).className = pCssClass;
}


/*************************************************************
   Function name:  SetBackgroundColor
         Purpose:  change the background of an object
          Inputs:  string - object name, string - css class
         Outputs:  nothing
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function SetBackgroundColor(pObject, pColor, pShowWarningYn)
{
	try
	{
		pObject.style.backgroundColor = pColor;
	}
	catch(err)
	{
		if (pShowWarningYn == "Y" || pShowWarningYn=="y") {
			txt="The color '" + pColor + "' is invalid.\n\n";
			txt+="Please choose another color.\n\n";
			//txt+="Error description: " + err.description + "\n\n";
			txt+="Click OK to continue.\n\n";
			alert(txt);
		}
	}
}

/*************************************************************
   Function name:  SetBackgroundColor
         Purpose:  change the background of an object
          Inputs:  string - object name, string - css class
         Outputs:  nothing
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function SetBackgroundColorById(pObjectId, pColor, pShowWarningYn)
{
	SetBackgroundColor(getObjectByID(pObjectId), pColor, pShowWarningYn);
}


/*************************************************************
   Function name:  IncludeJs
         Purpose:  include another js file
          Inputs:  string - js file name (and path if necessary)
         Outputs:  the html to include a js file
         Returns:  the html to include a js file (just in case the user wants it)
         Creator:  Aaron K. Murray
         Example: <script language="javascript" type="text/javascript">IncludeJs("scripts/date.js");</script>
*************************************************************/
function IncludeJs(pPathAndFilename)
{
    document.write('<script src="' + pPathAndFilename + '"><\/script>');
    return "<script src='" + pPathAndFilename + "'><\/script>";
}




function ShowProgress()
{
    img = getObjectByID('statusDiv');        
    if (img)
    {        
        img.style.display = "block";
    }
}

function HideProgress()
{
    img = getObjectByID('statusDiv');
    if (img)
    {
        img.style.display = "none";
    }
}


function RemoveAllQuotes(pText) {
	return RemoveSingleQuotes(RemoveDoubleQuotes(pText));
}

function RemoveSingleQuotes(pText) {
	var regString = /\'/g;
	return pText.replace(regString, ""); 
}

function RemoveDoubleQuotes(pText) {
	var regString = /\"/g;
	return pText.replace(regString, ""); 
}

function RemovePeriod(pText) {
	var regString = /./g;
	return pText.replace(regString, ""); 
}

function OnlyLettersNumbersAndSpaces(pText) {
	var acceptableCharacters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
	return RemoveBadChars(pText, acceptableCharacters);
}

function RemoveBadChars(pText, pGoodCharacterString) {
	var acceptableCharacters = pGoodCharacterString;
	var newString = "";
	for(i=0; i<pText.length; i++){
		if (acceptableCharacters.indexOf(pText.charAt(i))<0){
			//no match - add a space
			//newString += " ";
		} else {
			//good char
			newString += pText.charAt(i);
		}
	}
	return newString;
}

function GetBaseFilename(pPathAndFilename) {
	var splitArray=pPathAndFilename.split("\\");
	stringLastWord = splitArray[splitArray.length-1];
	stringBaseWordArray = stringLastWord.split(".");
	stringBaseWord = stringBaseWordArray[0];
	stringBaseWord = OnlyLettersNumbersAndSpaces(stringBaseWord);
	return stringBaseWord;
}

/*************************************************************
   Function name:  ChangeFormActionAndSubmit
         Purpose:  change the current forms action, then submit
          Inputs:  nothing
         Outputs:  none
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function OutsideSubmit(pAction) {
	var theFirstForm = document.forms[0];

	//now we need to strip out the special hidden .net fields so the receiving site doesn't puke	
	var i;
	var f;
	var urlParams = "";

	//HACK: This needs to only collect fields that are from the form that this function was called from within
	
	for (f=0; f<document.forms.length; f++) {
		var formElements = document.forms[f].elements;
		for (i=0; i<formElements.length; i++) {
			// types: text|textarea|password|checkbox|radio|submit|reset|file|hidden|image|button|undefined
			if (formElements[i].type == "hidden") { //then we have a potential offender, check for _ (later: : or $)
				try {
					if (formElements[i].id.substr(0, 1) == "_" || formElements[i].name.substr(0, 1) == "_") {
						clearFieldValue(formElements[i]);
					} else {
						//alert("Valid (" + formElements[i].id+"/"+formElements[i].name+"): "+ formElements[i].value);
						if (formElements[i].id == "") //try the name
							urlParams += formElements[i].name
						else //use the id
							urlParams += formElements[i].id
							
						urlParams += "=" + encodeURIComponent(formElements[i].value) + "&"
					}
				} catch (err) {
					//alert("Error processing form: "+ err);
				}
			} else {
				//not a hidden field, but may be a field we want added
				if (formElements[i].type != "submit" && formElements[i].type != "reset" && formElements[i].type != "image" && formElements[i].type != "button") {
					//the we want to include this as a passed field
					//alert("Valid (" + formElements[i].id+"/"+formElements[i].name+"): " + formElements[i].value);
					if (formElements[i].id) {
						//use the id
						urlParams += formElements[i].id
						urlParams += "=" + encodeURIComponent(formElements[i].value) + "&"
					} else if (formElements[i].name) {
						//use the name
						urlParams += formElements[i].name
						urlParams += "=" + encodeURIComponent(formElements[i].value) + "&"
					} 
				} else {
				//	alert("Invalid Type: " + formElements[i].type);
				}
			}
		}
	}


	//change the action
	if (pAction.indexOf('?') > 1) {
		//then we already have a question mark
		theFirstForm.action = pAction + "&" + urlParams;
	} else {
		theFirstForm.action = pAction + "?" + urlParams;
	}
	//alert("Action: " + theFirstForm.action);	

	//set the method to POST (GET will throw an "access denied" message)
	//theFirstForm.method = "POST";
	//theFirstForm.submit();
	
	//or use goTo()
	
	goTo(theFirstForm.action);
}


/*************************************************************
   Function name:  MiniFormSubmit
         Purpose:  change the current forms action, then submit
          Inputs:  pCallingObject (passed as 'this'), ex: onclick="MiniFormSubmit(this, 'Y');"
         Outputs:  none
         Returns:  nothing
         Creator:  Aaron K. Murray
*************************************************************/
function MiniFormSubmit(pCallingObject, pOpenPopup) {
	var theForm = pCallingObject.form;	//the form that the calling object was in
	var theAction = theForm.action;		//the action of the form we are on

	//now we need to strip out the special hidden .net fields so the receiving site doesn't puke	
	var i;
	var urlParams = "";
	alert(theForm.name + " :: " + theAction);
	var formElements = theForm.elements;
	for (i=0; i<formElements.length; i++) {
		// types: text|textarea|password|checkbox|radio|submit|reset|file|hidden|image|button|undefined
		if (formElements[i].type == "hidden") { //then we have a potential offender, check for _ (later: : or $)
			try {
				if (formElements[i].id.substr(0, 1) == "_" || formElements[i].name.substr(0, 1) == "_") {
					clearFieldValue(formElements[i]);
				} else {
					//alert("Valid (" + formElements[i].id+"/"+formElements[i].name+"): "+ formElements[i].value);
					if (formElements[i].id == "") //try the name
						urlParams += formElements[i].name
					else //use the id
						urlParams += formElements[i].id
						
					urlParams += "=" + encodeURIComponent(formElements[i].value) + "&"
				}
			} catch (err) {
				//alert("Error processing form: "+ err);
			}
		} else {
			//not a hidden field, but may be a field we want added
			if (formElements[i].type != "submit" && formElements[i].type != "reset" && formElements[i].type != "image" && formElements[i].type != "button") {
				//the we want to include this as a passed field
				//alert("Valid (" + formElements[i].id+"/"+formElements[i].name+"): " + formElements[i].value);
				if (formElements[i].id) {
					//use the id
					urlParams += formElements[i].id
					urlParams += "=" + encodeURIComponent(formElements[i].value) + "&"
				} else if (formElements[i].name) {
					//use the name
					urlParams += formElements[i].name
					urlParams += "=" + encodeURIComponent(formElements[i].value) + "&"
				} 
			} else {
			//	alert("Invalid Type: " + formElements[i].type);
			}
		}
	}


	//change the action
	if (theAction.indexOf('?') > 1) {
		//then we already have a question mark
		theForm.action = theAction + "&" + urlParams;
	} else {
		theForm.action = theAction + "?" + urlParams;
	}
	//alert("Action: " + theForm.action);	

	//set the method to POST (GET will throw an "access denied" message)
	//theForm.method = "POST";
	//theForm.submit();
	
	//or use goTo()
	
	if (pOpenPopup == "N") {
		goTo(theForm.action);
	} else {
		openPopupWindow(theForm.action, "minipopup");
	}
}

