function CheckMandatory(oForm)
{
	var i ;
	var sElementName = new String() ;
	var sElementValue = new String() ;
	var strCrLf = String.fromCharCode(10, 13) ;
	var iMissed = 0 ;
	var strMessage = new String("Please complete the following fields;" + strCrLf) ;

	// Loop through each element, looking for those that should be mandatory
	for (i=0; i<oForm.length; i++)
	{
		sElementName = oForm.elements[i].name ;
		if (sElementName.substring(0,2) == "mn")
		{
			sElementValue = oForm.elements[i].value ;
			if (sElementValue == "")
			{
				strMessage = strMessage + ((iMissed) ? ", " : "") + GetElementName(sElementName) ;
				if (0 == iMissed)  oForm.elements[i].focus() ;
				iMissed++ ;
			}
		}
	}
	if (iMissed)
	{
		alert(strMessage) ;
			
		return false ;
	}
	return true ;
}

function CheckFieldWidths(oForm)
{
	var i ;
	var strCrLf = String.fromCharCode(10, 13) ;
	var iInvalid = 0 ;
	var strMessage = new String("You have exceeded the allowable field size for the following field(s):") ;

	// Loop through each element, looking for those that should be mandatory
	for (i=0; i<oForm.length; i++)
	{
		if (oForm.elements[i].type == "text")
		{
			if (oForm.elements[i].value.length > oForm.elements[i].Maxsize && oForm.elements[i].value.length > oForm.elements[i].size)
			{
				strMessage += strCrLf + "Field: " + GetElementName(oForm.elements[i].name) + " max size: " + oForm.elements[i].Maxsize + " you entered: " + oForm.elements[i].value.length ;
				if (0 == iInvalid) oForm.elements[i].focus() ;
				iInvalid++ ;
			}
		}
		else if (oForm.elements[i].type == "textarea")
		{
			if (oForm.elements[i].value.length > (oForm.elements[i].rows * oForm.elements[i].cols))
			{
				strMessage += strCrLf + "Field: " + GetElementName(oForm.elements[i].name) + " max size: " + (oForm.elements[i].rows * oForm.elements[i].cols) ;
				if (0 == iInvalid) oForm.elements[i].focus() ;
				iInvalid++ ;
			}
		}
	}
	if (iInvalid)
	{
		alert(strMessage) ;
		return false ;
	}
	return true ;
}

function CheckMask(sValue, sMask)
{
	var i ;
	if (sValue.length != sMask.length) return false ;
	for (i=0; i<sMask.length; i++)
	{
		if (sMask.charAt(i) == 'A')
		{
			if (!isalpha(sValue.charAt(i))) return false ;
		}
		else if (sMask.charAt(i) == '9' || sMask.charAt(i) == 'D' || sMask.charAt(i) == 'M' || sMask.charAt(i) == 'Y')
		{
			if (!isnumeric(sValue.charAt(i))) return false ;
		}
		else if (sMask.charAt(i) == 'X')
		{
			if (!isnumeric(sValue.charAt(i)) || !isalpha(sValue.charAt(i))) return false ;
		}
		else
		{
			if (sMask.charAt(i) != sValue.charAt(i)) return false ;
		}
	}
	
	return true ;
}

function CheckMaskToStrLen(sValue, sMask)
{
	var i ;
	for (i=0; i<sValue.length; i++)
	{
		if (sMask.charAt(i) == 'A')
		{
			if (!isalpha(sValue.charAt(i))) return false ;
		}
		else if (sMask.charAt(i) == '9' || sMask.charAt(i) == 'D' || sMask.charAt(i) == 'M' || sMask.charAt(i) == 'Y')
		{
			if (!isnumeric(sValue.charAt(i))) return false ;
		}
		else if (sMask.charAt(i) == 'X')
		{
			if (!isnumeric(sValue.charAt(i)) || !isalpha(sValue.charAt(i))) return false ;
		}
		else
		{
			if (sMask.charAt(i) != sValue.charAt(i)) return false ;
		}
	}
	
	return true ;
}

function CheckValidEmail(sEmailAddr)
{
	return (sEmailAddr.indexOf("@") != -1 && sEmailAddr.indexOf(".") != -1) ;
}

function isalpha(ch)
{
	if (ch.charCodeAt(0) >= 65 && ch.charCodeAt(0) <= 122) return true ;
	return false ;
}

function isnumeric(ch)
{
	if (ch.charCodeAt(0) >= 48 && ch.charCodeAt(0) <= 57) return true ;
	return false ;
}

function GetElementName(sName)
{
	if (sName.substring(0,2) == "mn")
	{
		return sName.substring(2) ;
	}
	return sName ;
}

function PadCurrency(cValue)
{
	var sValue = new String(cValue);
	var iOffset = sValue.indexOf(".") ;
	
	// Check if there is any pence at all.
	if (iOffset == -1)
	{
		sValue += ".00" ;
	}
	// See if the currency is already padded.
	else if (iOffset != sValue.length-3)
	{
		for (var i=0; i<iOffset-(sValue.length-3); i++)
			sValue += "0" ;
	}
	
	return sValue ;
}

function MapWindow()
{
	// Check out Window.showModalDialog to return the value directly to this window.
	window.open("../images/central-florida-map.jpg", "centralmap", "HEIGHT=575,WIDTH=760,screenX=0,screenY=0") ;
}

function CheckDate(sInDate)
{
	var bRetVal = true ;
	var sDate = StringToNeutral(sInDate) ;
	if (sDate.length == 10)
	{
		var dtDate = new Date(sDate) ;
		if (dtDate.toString() == "NaN")
			bRetVal=false ;
		else if (dtDate.getMonth() != (sDate.substr(5, 2)-1))
			bRetVal=false ;
	}
	
	return bRetVal ;
}

function StringToNeutral(sDate)
{
	var sStr = new String(sDate) ;

	if (sStr.length == 10)
	{
		var sNewDate = new String() ;
		sNewDate =  sStr.substr(6, 4) ;
		sNewDate += "/" + sStr.substr(3, 2) ;
		sNewDate += "/" + sStr.substr(0, 2) ;
		return sNewDate ;
	}
	else
	{
		return "" ;
	}
}



