<!--

//---------------------------------------------------------

function isEmpty(s) 
{
	return ((s == null) || (s.length == 0))
}

//---------------------------------------------------------

function isEmptyNoSpace(s) 
{
	var str
	str = s.replace(' ', '');
	return ((str.length == 0))
}

//---------------------------------------------------------

function checkEmail (o, descr) 
{
	if (isEmpty(o.value)) return true;
    
	var s = o.value;
	var posAt = s.indexOf('@');
	var msg = '';
	var ret = true;

	if (s.indexOf(' ') > -1 ) 
	{
		msg = msg + "\n   There must be no spaces";
	}

	if (posAt == 0) 
	{
      msg = msg + "\n   There must be a name before the @ symbol";
	} 
    
	if (posAt == -1) 
	{
		msg = msg + "\n   There must be an @ symbol";
	}

	if (s.indexOf('@', posAt +1) > -1) 
	{
		msg = msg + "\n   There must only be one @ symbol";
	}

	if (posAt == s.length -1) 
	{
		msg = msg + "\n   Something must follow the @ symbol";
	}

	var posDot = s.indexOf('.', posAt);

	if (posDot == -1) 
	{
		msg = msg + "\n   There must be a host containing a dot following the @ symbol";
	}

	if (posDot == posAt + 1) 
	{
		msg = msg + "\n   There must be a name between the @ and . symbols";
	}

	if (posDot == s.length-1) 
	{
		msg = msg + "\n   A dot cannot be the last character";
	}

	if (msg != '')
		ret = false;
	else
		ret = true;
		
	//if (ret == false)
	//	alert (msg + ' in your ' + descr);

	//return ret;
	return msg;
}

//---------------------------------------------------------

function isNumeric(s) 
{
	var i;
	for (i = 0; i < s.length; i++) 
	{
		if ( !( s.charAt(i) >= '0' && s.charAt(i) <= '9') )
			return false;
	}

	return true;
}

//---------------------------------------------------------

function isPhoneNo(o) 
{
	var s = o.value;
	var i;
	for (i = 0; i < s.length; i++) 
	{
		if ( !(( s.charAt(i) >= '0' && s.charAt(i) <= '9') ||
			   s.charAt(i) == '-' || 
				s.charAt(i) == '_' || 
				s.charAt(i) == ' ') )
			return false;
	}

	return true;
}

//---------------------------------------------------------

function checkDateParts (strDay, strMth, strYear) 
{
	var intDay;
	var intMth;
	var intYear;
	var errMsg;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "January";
	strMonthArray[1] = "February";
	strMonthArray[2] = "March";
	strMonthArray[3] = "April";
	strMonthArray[4] = "May";
	strMonthArray[5] = "June";
	strMonthArray[6] = "July";
	strMonthArray[7] = "August";
	strMonthArray[8] = "September";
	strMonthArray[9] = "October";
	strMonthArray[10] = "November";
	strMonthArray[11] = "December";
	errMsg = "";

	// Check the year value is numeric and 4 digits in length
	intYear = parseInt(strYear, 10);
	if (isNaN( intYear ) || strYear.length != 4)
	{
		errMsg = "The year value must be four digits.";
	}
	
	// Check the month value is numeric and no more than 2 digits in length
	intMth = parseInt(strMth, 10);
	if (isNaN( intMth ) || (strMth.length < 1 || strMth.length > 2))
	{
		errMsg = "The month value must be a number between 1 and 12 inclusive.";
	}

	// Check the day value is numeric and no more than 2 digits in length
	intDay = parseInt(strDay, 10);
	if (isNaN( intDay ) || (strDay.length < 1 || strDay.length > 2))
	{
		errMsg = "The day value must be a positive one or two digit number.";
	}

	// Check the month value is between 1 and 12 inclusive
	if (intMth > 12 || intMth < 1)
	{
		errMsg = "The month value must be between 1 and 12 inclusive.";
	}

	// Check the day value is valid for the month value (and year value if month is 2)
	if ((intMth == 1 || intMth == 3 || intMth == 5 || intMth == 7 || intMth == 8 || intMth == 10 || intMth == 12) && (intDay > 31 || intDay < 1)) 
	{
		errMsg = "The day value is invalid for " + strMonthArray[intMth-1] + ".  Please enter a value between 1 and 31 inclusive.";
	}
	if ((intMth == 4 || intMth == 6 || intMth == 9 || intMth == 11) && (intDay > 30 || intDay < 1)) 
	{
		errMsg = "The day value is invalid for " + strMonthArray[intMth-1] + ".  Please enter a value between 1 and 30 inclusive.";
	}
	if (intMth == 2) 
	{
		if (intDay < 1) 
		{
			errMsg = "The day value must be a positive one or two digit number.";
		}
		if (leapYear( intYear ) == true) 
		{
			if (intDay > 29) 
			{
				errMsg = "The day value is invalid for " + strMonthArray[intMth-1] + " " + strYear + ".  Please enter a value between 1 and 29 inclusive.";
			}
		}
		else 
		{
			if (intDay > 28) 
			{
				errMsg = "The day value is invalid for " + strMonthArray[intMth-1] + " " + strYear + ".  Please enter a value between 1 and 28 inclusive.";
			}
		}
	}

	return errMsg;
}

//---------------------------------------------------------

// compareDates function 
// After validating date parts passed in, it compares the date values passed in and 
// returns either an error message or the comparison result.
// PARAMS: the date parts and a descriptive name each for two dates.
//			e.g. '12', '5', '2002', 'Start Date', '21', '5', '2002', 'End Date'
//			The descriptive name is used in the error message.
// RETURNS: 1 if date 1 > date 2
//				0 if date 1 = date 2
//				-1 if date 1 < date 2
//				errMsg if either date is invalid
function compareDates (strDay1, strMth1, strYear1, strDateName1, strDay2, strMth2, strYear2, strDateName2) 
{
	var errMsg;

	// Check date 1 is valid before comparison.  If not, return an error message.
	errMsg = checkDateParts(strDay1, strMth1, strYear1);
	if( errMsg.length != 0)
	{
		errMsg = "The " + strDateName1 + " is invalid.  " + errMsg;
		return errMsg;
	}
	else
	{
		// Check date 2 is valid before comparison.  If not, return an error message.
		errMsg = checkDateParts(strDay2, strMth2, strYear2);
		if( errMsg.length != 0)
		{
			errMsg = "The " + strDateName2 + " is invalid.  " + errMsg;
			return errMsg;
		}
		// Perform date comparison.
		else
		{
			var intDay1;
			var intMth1;
			var intYear1;
			var intDay2;
			var intMth2;
			var intYear2;
			intYear1 = parseInt(strYear1, 10);
			intYear2 = parseInt(strYear2, 10);
			if( intYear1 < intYear2 )
				return -1;
			else if( intYear1 > intYear2 )
				return 1;
			else
			{
				intMth1 = parseInt(strMth1, 10);
				intMth2 = parseInt(strMth2, 10);
				if( intMth1 < intMth2 )
					return -1;
				else if( intMth1 > intMth2  )
					return 1;
				else
				{
					intDay1 = parseInt(strDay1, 10);
					intDay2 = parseInt(strDay2, 10);
					if( intDay1 < intDay2 )
						return -1;
					else if( intDay1 > intDay2  )
						return 1;
					else
						return 0;
				}
			}
		}
	}
}

//---------------------------------------------------------

function leapYear(intYear) 
{
	if (intYear % 100 == 0) 
	{
		if (intYear % 400 == 0) { return true; }
	}
	else 
	{
		if ((intYear % 4) == 0) { return true; }
	}
	return false;
}

//---------------------------------------------------------

function checkMinLength(s, intMinLen) 
{
	if (isEmpty(s)) return false;
	
	if (s.length < intMinLen) 
	{
		return false;
	}

	return false;
}

//---------------------------------------------------------

function checkMaxLength(s, intMaxLen) 
{
	if (s.length > intMaxLen) 
	{
		return false;
	}

	return false;
}

//---------------------------------------------------------

//-->

