function validateDate(theDate){
	if(theDate.indexOf("/") != -1 || theDate.indexOf("-") != -1){
		// Get date parts
		var theDateParts;
		if(theDate.indexOf("-") != -1)
			theDateParts = theDate.split("-");
		else
			theDateParts = theDate.split("/");
		
		// Not correct length?
		if(theDateParts.length != 3)
			return false;
		
		for(i=0; i<theDateParts.length; i++)
			if(theDateParts[i].length < 1 || isNaN(theDateParts[i]))
				return false;
		
		var theMonth = parseInt(theDateParts[0], 10);
		if(theMonth == 0){
			theDateParts[0].replace("0", "");
			theMonth = parseInt(theDateParts[0], 10);
		}
		var theDay	 = parseInt(theDateParts[1], 10);
		if(theDay == 0){
			theDateParts[1].replace("0", "");
			theDay = parseInt(theDateParts[1], 10);
		}
		
		if(theMonth < 1 || theMonth > 12)
			return false;
		if(theDay < 1 || theDay > 31)
			return false;
		
		//don't do parseInt on year so can get length
		if(theDateParts[2].length < 4 || parseInt(theDateParts[2], 10) < 1900)
			return false;
		
		return true;
	}
	else
		return false;
}

function validateEmail(theAddress)
{
	var returnValue = true;
	var AtSym       = theAddress.indexOf('@');
	var Period      = theAddress.lastIndexOf('.');
	var Space       = theAddress.indexOf(' ');
	var Length      = theAddress.length - 1;  // Array is from 0 to length-1

	// '@' cannot be in first position, Must be at least one valid char btwn '@' and '.'
	// Must be at least one valid char after '.', No empty spaces permitted
	if((AtSym < 1) || (Period <= AtSym+1) || (Period == Length ) || (Space  != -1))
		returnValue = false;

	return returnValue;
}

function validateDollar(fld) 
{
	var returnValue = true;
	var temp_value = fld.value;
	var Chars = "0123456789.,$";
	
	if (temp_value == "")
	{
		fld.value = "0.00";
		return returnValue;
	}
	
	for (var i = 0; i < temp_value.length; i++)
	{
		if (Chars.indexOf(temp_value.charAt(i)) == -1)
		{
			returnValue = false;
		}
	}
	return returnValue;
} 

var remote;
function launchWin(helpURL, size)
{
	// size string should have the format of 'width=#,height=#'
	// this avoids having to change all the function calls to launchHelp()
	var firstEqual = size.indexOf("=")+1;
	var comma = size.indexOf(",")+1;
	var secondEqual =  size.lastIndexOf("=")+1;
	var sizeLen = size.length;
	
	var w = parseInt(size.substring(firstEqual, comma));
	var h = parseInt(size.substring(secondEqual, sizeLen));
	
	var xPos = (screen.height-h)/2;
	var yPos = (screen.width-w)/2;
	remote = window.open(helpURL, "CMH", size+",scrollbars=1,resizable=1,left="+yPos+",top="+xPos);
	remote.focus();
}

var remotePrint;
function launchPrintWin(helpURL, size)
{
	// size string should have the format of 'width=#,height=#'
	// this avoids having to change all the function calls to launchHelp()
	var firstEqual = size.indexOf("=")+1;
	var comma = size.indexOf(",")+1;
	var secondEqual =  size.lastIndexOf("=")+1;
	var sizeLen = size.length;
	
	var w = parseInt(size.substring(firstEqual, comma));
	var h = parseInt(size.substring(secondEqual, sizeLen));
	
	var xPos = (screen.height-h)/2;
	var yPos = (screen.width-w)/2;
	remotePrint = window.open(helpURL, "CMH", size+",toolbar=1,scrollbars=1,resizable=1,left="+yPos+",top="+xPos);
	remotePrint.focus();
}

function trimString(val)
{
	var strLen = val.length;
	
	if(val.lastIndexOf(" ") == strLen-1)
		val = val.substring(0, strLen-1);
	
	if(val.indexOf(" ") == 0)
		val = val.substring(1, strLen);
	
	return val;
}

function ltrim (s){
	return s.replace(/^\s*/, "");
}

function rtrim (s){
	return s.replace(/\s*$/, "");
}

// Combine the rtrim() and ltrim() functions to make the trim() function
function trimString(s){
	return rtrim(ltrim(s));
}

