function arrayFind(array, element) {
	var elementInArray = false;
	for (var i=0; i<array.length; i++) {
		if (array[i]==element) {elementInArray = true}
	}
	
	return elementInArray;
}

function listFind(list, element, separator) {
	if (!separator) {separator = ","}
	
	var listArray = list.split(separator);
	
	return arrayFind(listArray, element)
}

function reverseString(string) {
	returnString = "";
	for (var i=(string.length-1); i>=0; i--) {
		returnString += string.charAt(i);
	}
	return returnString;
}

function lTrim(string) {
	returnString = "";
	for (var i=0; i<string.length; i++) {
		returnString += (string.charAt(i)==" " && returnString.length==0) ? "" : string.charAt(i);
	}
	return returnString;
}

function rTrim(string) {
	returnString = lTrim(reverseString(string));
	return reverseString(returnString);
}

function trim(string) {
	returnString = rTrim(lTrim(string));
	return returnString;
}

var formCount = 0; 	
function submitOnce() {
	if (formCount==0) {
	formCount = 1;
	return true; 
	}
else {
	alert("The form has already been submitted.\n\nPlease be patient...");
	return false; 
	}
}

function goFolder() {
	document.location = "folder.cfm?FolderID=" + document.GoToFolder.FolderID[document.GoToFolder.FolderID.selectedIndex].value;
}

function goMessageFolder() {
	document.location = "private_message_list.cfm?MessageFolderID=" + document.GoToFolder.MessageFolderID[document.GoToFolder.MessageFolderID.selectedIndex].value;
}

function setURLVar(URL, Variable, Value) {
	URL = URL.toString();

	if (URL.indexOf(Variable)==-1) {
		returnURL = URL + ((URL.indexOf("?")==-1) ? "?" : "&") + Variable + "=" + Value;
	}
	else {
		if (URL.indexOf("&")==-1) {
			returnURL = URL.split("?")[0] + "?" + Variable + "=" + Value;
		}
		else {
			returnURL = URL.split("?")[0] + "?";
			URLVarArray = URL.split("?")[1].split("&");
			
			for (var i=0; i<URLVarArray.length; i++) {
			 returnURL += ((URLVarArray[i].split("=")[0]==Variable) ? (Variable + "=" + Value) : URLVarArray[i]);
			returnURL += (i==(URLVarArray.length-1)) ? "" : "&";
			}
		}
	}
	return returnURL;
}

function selectDate(formName, formElement, relPath) {
	if (!relPath) relPath = "../";
	
	if (formName && formElement) {
		var theDate = new Date();
		var formDate = eval("document."+formName+"."+formElement+".value");
		if (formDate.split("/").length==3 && 0<formDate.split("/")[0]<=31 && 0<formDate.split("/")[1]<=12 && formDate.split("/")[2].length==4) {
			theDate = new Date(formDate.split("/")[2], (formDate.split("/")[1]-1), formDate.split("/")[0]);
		}
		theDay = new String(theDate.getDate());
			if (theDay<10) theDay = "0"+theDay;
		theMonth = new String(theDate.getMonth()+1);
			if (theMonth<10) theMonth = "0"+theMonth;
		theYear = new String(theDate.getYear());
			if (theDate.getYear().length<4) theYear = "20"+theYear;

		dateString = theDay + "/" + theMonth + "/" + theYear;
		
		dateSelector = window.open(relPath+"select_date.cfm?Date="+escape(dateString)+"&FormElement="+formName+"."+formElement, "dateSelector", "width=140,innerWidth=140,height=100,innerHeight=100");
	}
}

function popUp(sURL, iPrimaryKeyValue, sIDList) {
	popUpWin = window.open(sURL+"?ID="+iPrimaryKeyValue+"&IDList="+escape(sIDList), "popUpWin", "width=520,innerWidth=520,height=300,innerHeight=300,scrollbars=1");
}
