<!--
//****************************************************
//	PURPOSE: Remove leading blanks from our string.
//	IN: str - the string we want to LTrim
//	RETVAL: An LTrimmed string!
//****************************************************
function LTrim(str)  {
	var whitespace = new String(" \t\n\r");
	
	var s = new String(str);
	
	if (whitespace.indexOf(s.charAt(0)) != -1) {
	    // We have a string with leading blank(s)...
	
	    var j=0, i = s.length;
	
	    // Iterate from the far left of string until we
	    // don't have any more whitespace...
	    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
	        j++;
	
	    // Get the substring from the first non-whitespace
	    // character to the end of the string...
	    s = s.substring(j, i);
	}
	return s;
} // end LTrim()

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//****************************************************
//	PURPOSE: Remove trailing blanks from our string.
//	IN: str - the string we want to RTrim
//	RETVAL: An RTrimmed string!
//****************************************************

function RTrim(str)  {
	// We don't want to strip JUST spaces, but also tabs,
	// line feeds, etc.  Add anything else you want to
	// "trim" here in Whitespace
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
	    // We have a string with trailing blank(s)...
	
	    var i = s.length - 1;       // Get length of string
	
	    // Iterate from the far right of string until we
	    // don't have any more whitespace...
	    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
	        i--;
	
	    // Get the substring from the front of the string to
	    // where the last non-whitespace character is...
	    s = s.substring(0, i+1);
	}
	return s;
} // end RTrim()

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//****************************************************
//	PURPOSE: Remove trailing and leading blanks from our string.
//	IN: str - the string we want to Trim
//	RETVAL: A Trimmed string!
//****************************************************
function Trim(str)  {
		return RTrim(LTrim(str));
} // end Trim()

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//****************************************************
//	PURPOSE: Search for a @ in a string, as a sign of and e-mail address
//	IN: str - the string containing the alleged e-mail address
//	RETVAL: True or False, depending on if the string was or wasn't a 'valid' address
//****************************************************


function isValid_Email(strEmail) {
	if (strEmail.indexOf('@',0)==-1 || strEmail.indexOf('@',0)== 0 || strEmail.indexOf('.',0)==-1) {
		return false;
	} else {
		return true;
	}
} // end isValid_Email()
 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
 
function GetDateParameters(ParameterSet)
{
	//When you call this function, an array of parameters is
	//returned.  
	//YOU MUST SET THE [0] PARAMETER TO THE DATE YOU WANT TO USE.
	//Parameter[1] is the incoming format
	//Parameter[2] is the outgoing format
	var Parameters = new Array()
	switch (ParameterSet)
		{
		case "US":
			Parameters[1] = "mdy" 
			Parameters[2] = "mdyyyy"
			break
		case "UK":
			Parameters[1] = "dmy"
			Parameters[2] = "dmyyyy"
			break
		case "UNK":
			Parameters[1] = "dmy"
			Parameters[2] = "dmyyyy"
			break
		case "ConvertUKToUS":
			Parameters[1] = "dmy"
			Parameters[2] = "mmddyyyy"
			break
		case "ConvertUSToUK":
			Parameters[1] = "mdy"
			Parameters[2] = "ddmmyyyy"
			break
		}
	return Parameters
}// end GetDateParameters()

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//--------------------------------------------------
//Check to make sure date is valid
//--------------------------------------------------
function CheckDate(Parameters)
{
	//Parameter		Type		Descr
	//0				Date.value	date value to check
	//1				String		format the date is coming in 
	//							i.e. "MDY or DMY"
	//							Only need to know the order of the
	//							Month, Day and Year.
	//2				String		the return format 
	//							(not used in this function, but 
	//							reserved for FormatDate() function
	//							(not used in this function, but 
	//							reserved for FormatDate() function
	
	//Function Returns a Number
	//1 = Valid Date
	//2 = Invalid Date
	//3 = Invalid Date - Wrong Format
	//4 = Invalid Day
	//5 = Invalid Month
	//6 = Invalid Year
	//7 = Program Error
	
	//I'm still working on the function.  JDL  12/21/2002

	var MyDay = 0
	var MyMonth = 0
	var MyYear = 0
	
	MyDate = new String(Trim(Parameters[0]))

	//The length of the string includeing the delimeter should
	//never be more than 10 i.e. "01/01/2003" has a length of 10.
	//So if the length of the input date is more than 10, then
	//it's invalid...at least until for the foreseeable future.
	if (MyDate.length > 10) {return 2}

	var ValidDateFormatVariables = "MDY"
	Parameters[1] = Parameters[1].toUpperCase()

	//Make sure that each value of the format is supported in this
	//function.  So loop through the format and if the characters
	//in the submitted format are not in the ValidDateFormatVariables
	//Then return 4, or split the submitted format for later use.
	for (var i=0; i<=Parameters[1].length-1; i++)
		{
		TempChar = Parameters[1].substring(i, i+1)
		if (ValidDateFormatVariables.indexOf(TempChar,0) == -1)
			{return 7}
		}
	arrDateFormat = Parameters[1].split("")
	
	var arrStringDate = MyDate.split("/")

	//Split the date by the submitted delimeter.  If the
	//length of the array does not exactly match the
	//length of the submitted format, then it can't
	//be a correct date (based on whatever the application 
	//is excepting), so return 2.  i.e. if the submitted
	//format is MY (a Month and a Year) and the date submitted
	//is 1/1/2002, then it's incorrect because the application
	//is expecting only a month and a year.
	
	if (arrStringDate.length != Parameters[1].length) {return 3}

	for (var i=0; i<=arrStringDate.length-1; i++)
		{
		var arrCheckNumber = arrStringDate[i].split("")
		for (var j=0; j<=arrCheckNumber.length-1; j++)
			{
			if (isNaN(arrCheckNumber[j]) == true) {return 2}
			}

		//validate each part of the date based on the expected format.
		//This is also a preliminary check of the day to make sure that
		//it is greater than 0 and less than 32.  A more thorough check
		//is performed later.
		switch(arrDateFormat[i])
			{
			case "D":
				MyDay = new Number(arrStringDate[i])
				if (MyDay < 1 || MyDay > 31) {return 4}
				break
			case "M":
				MyMonth = new Number(arrStringDate[i])
				if (MyMonth < 1 || MyMonth > 12) {return 5}
				break
			case "Y":
				if (arrStringDate[i].length == 1 || arrStringDate[i].length == 3 || arrStringDate[i].length > 4) {return 6}
				if (arrStringDate[i].length == 2)
					{arrStringDate[i] = DetermineCentury(arrStringDate[i]) + arrStringDate[i]}
				MyYear = new Number(arrStringDate[i])
				break
			}
		}

	//Now check the day to make sure that it is a correct number
	//for the month.  For February, it also checks for leap years.  If
	//no year is submitted in the date, then the current year is assumed

	for (var i=0; i<=arrDateFormat.length-1; i++)
		{
		switch(arrDateFormat[i])
			{
			case "D":
				var LastDay = 0
				if (MyMonth == 0 || MyMonth == 1 || MyMonth == 3 || 
					MyMonth == 5 || MyMonth == 7 || MyMonth == 8 ||
					MyMonth == 10 || MyMonth == 12) 
					{LastDay = 31}
				if (MyMonth == 4 || MyMonth == 6 || MyMonth == 9 || 
					MyMonth == 11) 
					{LastDay = 30}
				if (MyMonth == 2) 
					{
					if (MyYear == 0)
						{
						MyTempDate = new Date()
						MyYear = MyTempDate.getFullYear()
						}				
					MyTempDate = new Date("2/29/" + MyYear)
					MyTempDay = MyTempDate.getDate()
					if (MyTempDay == 29)
						{LastDay = 29}
					else
						{LastDay = 28}
					}
				if (MyDay < 1 || MyDay > LastDay) {return 4}
				break
			}
		}
	return 1
}


//-->
