var corruptForm = 0;
function Validation(NumberOfValidations, inwhat)
{
var errors = ''
errors += parseValidations( NumberOfValidations, inwhat)
if (corruptForm == 0)
{
if ((errors))
{
alert('The following error(s) occurred:\n'+ errors);
return(false);
}
else
{
return (true);
}
}
else
{
alert("You have changed information that should not be altered this form cannot be processed");
return(false);
}
}
function MM_corruptForm()
{
alert("You have changed information that should not be altered this form cannot be processed");
corruptForm = 1;
}
function emptyFieldCheck( fieldValue, fieldName, errorMessage )
{
var retVal = '';
if (eval(fieldValue) == "")
{
retVal =  '- ' + fieldName +' '+ errorMessage+'\n';
}
else
{
retVal =  '';
}
return (retVal);
}
function isSelectedCheck( fieldValue, fieldName, errorMessage )
{
var retVal = '';
if (eval(fieldValue) < 0)
{
retVal =  '- ' + fieldName +' '+ errorMessage+'\n';
}
else
{
retVal =  '';
}
return (retVal);
}
function isSelectedCheck_Size1_WithBlank_1Form_check( fieldValue, fieldName, errorMessage )
{
var optionValue = eval( 'document.forms[0].'+fieldName+'.options[document.forms[0].'+fieldName+'.selectedIndex].value');
var retVal = '';
if (optionValue == '')
{
retVal =  '- ' + fieldName +' '+ errorMessage+'\n';
}
else
{
retVal =  '';
}
return (retVal);
}
function checkLinkFormat( fieldValue, fieldName, errorMessage )
{
var retVal = '';
var fv = (eval(fieldValue)).toLowerCase();
if (fv == '')
{
retVal = '';
}
else
{
var fvsub = fv.substring(0,7);
if (fvsub == "http://")
{
retVal =  '';
}
else
{
retVal =  '- ' + fieldName +' '+ errorMessage+'\n';
}
}
return (retVal);
}
function checkPhotoExtFormat( fieldValue, fieldName, errorMessage )
{
var retVal = '';
var filename = (eval(fieldValue));
var ext = filename.substring((filename.indexOf('.')+1),(filename.length));
var extension = ext.toUpperCase();
if ((extension == 'JPEG' )||(extension == 'JPG' )||(extension == 'GIF' ))
{
}
else
{
retVal = '- ' + fieldName +' '+ errorMessage+'\n';
}
return (retVal);
}
function checkDateFormat( fieldValue, fieldName, errorMessage )
{
var retVal = '';
var date = (eval(fieldValue));
var day = date.substring(0,(date.indexOf('/',0)));
var month = date.substring((date.indexOf('/')+1),(date.lastIndexOf('/')));
var year = date.substring((date.lastIndexOf('/')+1),(date.length));
if ((isNaN(day)) || (isNaN(month)) || (isNaN(year)))
{
retVal = '- ' + fieldName +' '+ errorMessage+ '\n';
}
else
{
if (((parseInt(eval(day)) < 1 || 31 < parseInt(eval(day))))||(parseInt(eval(month)) < 1 || 12 < parseInt(eval(month)))||(parseInt(eval(year)) < 1000 || 10000 < parseInt(eval(year))))
{
retVal = '- ' + fieldName +' '+ errorMessage+ '\n';
}
if (! (checkMonthLength(day, month) == ''))
{
retVal += '- ' + fieldName +' '+ errorMessage +' '+ checkMonthLength(day, month)+'\n';
}
if( month==2)
{
if (! (checkLeapMonth(day,month,year) == ''))
{
retVal += '- ' + fieldName +' '+ errorMessage +' '+ checkLeapMonth(day,month,year)+'\n';
}
}
}
return (retVal);
}
function checkMonthLength(dd,mm)
{
var months = new Array('','January','February','March','April','May','June','July','August','September','October','November','December')
if ((mm == 4 || mm == 6 || mm == 9 || mm == 11) && dd > 30)
{
return  months[mm] + ' has only 30 days.'
}
else if (dd > 31)
{
return months[mm] + ' has only 31 days.'
}
return ''
}
function checkLeapMonth(dd,mm,yyyy)
{
if (yyyy % 4 > 0 && dd > 28)
{
return 'February of ' + yyyy + ' has only 28 days.'
}
else if (dd > 29)
{
return 'February of ' + yyyy + ' has only 29 days.'
}
return ''
}
function isNumericCheck(fieldValue, fieldName, errorMessage)
{
var retVal = '';
var theNum =  eval(fieldValue);
var Result = (parseFloat(eval(fieldValue)) - theNum);
if (Result != 0)
{
retVal = '- ' + fieldName +' '+ errorMessage+'\n';
}
else
{
retVal =  '';
}
return (retVal);
}
function inRangeCheck(  fieldValue, fieldName, minimum, maximum)
{
var retVal = '';
if (parseInt(eval(fieldValue)) < minimum || maximum < parseInt(eval(fieldValue)))
{
//bad range
retVal =  '- ' + fieldName +' must contain a number between '+minimum+' and '+maximum+'.\n';
}
else
{
retVal =  '';
}
return (retVal);
}
function isEmailCheck(fieldValue, fieldName, errorMessage)
{
var retVal = '';
var theAddress =  eval(fieldValue);
var at="@"
var dot="."
var lat=theAddress.indexOf(at)
var lstr=theAddress.length
var ldot=theAddress.indexOf(dot)
if (theAddress != '')
{
if (theAddress.indexOf(at)==-1){
retVal = '- ' + fieldName +' '+ errorMessage+'\n';
}
if (theAddress.indexOf(at)==-1 || theAddress.indexOf(at)==0 || theAddress.indexOf(at)==lstr){
retVal = '- ' + fieldName +' '+ errorMessage+'\n';
}
if (theAddress.indexOf(dot)==-1 || theAddress.indexOf(dot)==0 || theAddress.indexOf(dot)==lstr){
retVal = '- ' + fieldName +' '+ errorMessage+'\n';
}
if (theAddress.indexOf(at,(lat+1))!=-1){
retVal = '- ' + fieldName +' '+ errorMessage+'\n';
}
if (theAddress.substring(lat-1,lat)==dot || theAddress.substring(lat+1,lat+2)==dot){
retVal = '- ' + fieldName +' '+ errorMessage+'\n';
}
if (theAddress.indexOf(dot,(lat+2))==-1){
retVal = '- ' + fieldName +' '+ errorMessage+'\n';
}
if (theAddress.indexOf(" ")!=-1){
retVal = '- ' + fieldName +' '+ errorMessage+'\n';
}
}
else
{
retVal =  '';
}
return (retVal);
}
function parseValidations( NumberOfValidations, inwhat)
{
var n = 0
var wstr = 0
var i = 0
var f = 0
var SeperatorChar = ':'
var FormObjectName = ''
var SubmittedFieldsPerCheck = 4
var errorMsg = ''
var FunctionName = ''
var errorsFound = ''
var FormObjectValue = ''
var v = 0
for(v = 0; v < NumberOfValidations; v++)
{
for(i = 0; i < 4; i++)
{
n = inwhat.indexOf(SeperatorChar,n)
if (n < 0)
{
return ''
}
n++
if( n >= 0)
{
var f = inwhat.indexOf(SeperatorChar,n)
if(f < 0) f = inwhat.length
wstr = inwhat.substring(n,f)
}
if (i == 0)
{
FormObjectValue = wstr
}
if (i == 1)
{
FormObjectName = wstr
}
if (i == 2)
{
errorMsg = wstr
}
if (i == 3)
{
FunctionName = wstr
}
if ((FunctionName == 'emptyFieldCheck')&&(i == 3))
{
errorsFound += emptyFieldCheck( FormObjectValue, FormObjectName, errorMsg )
}
if ((FunctionName == 'isSelectedCheck')&&(i == 3))
{
errorsFound += isSelectedCheck( FormObjectValue, FormObjectName, errorMsg )
}
if ((FunctionName == 'isSelectedCheck_Size1_WithBlank_1Form_check')&&(i == 3))
{
errorsFound += isSelectedCheck_Size1_WithBlank_1Form_check( FormObjectValue, FormObjectName, errorMsg )
}
if ((FunctionName == 'checkLinkFormat')&&(i == 3))
{
errorsFound += checkLinkFormat( FormObjectValue, FormObjectName, errorMsg )
}
if ((FunctionName == 'checkDateFormat')&&(i == 3))
{
errorsFound += checkDateFormat( FormObjectValue, FormObjectName, errorMsg )
}
if ((FunctionName == 'checkPhotoExtFormat')&&(i == 3))
{
errorsFound += checkPhotoExtFormat( FormObjectValue, FormObjectName, errorMsg )
}
if ((FunctionName == 'isNumericCheck')&&(i == 3))
{
errorsFound += isNumericCheck( FormObjectValue, FormObjectName, errorMsg )
}
if ((FunctionName == 'isEmailCheck')&&(i == 3))
{
errorsFound += isEmailCheck( FormObjectValue, FormObjectName, errorMsg )
}
if ((FunctionName == 'inRangeCheck')&&(i == 3))
{
var index = 0
var Seperator = '-'
var n1 = 0
var MinVal = 0
var MaxVal = 0
var wstr1 = 0
for(index = 0; index < 2; index++)
{
n1 = errorMsg.indexOf(Seperator,n1)
if (n1 < 0)
{
return ''
}
n1++
if( n1 >= 0)
{
var f1 = errorMsg.indexOf(Seperator,n1)
wstr1 = errorMsg.substring(n1,f1)
}
if (index == 0)
{
MinVal = wstr1
}
if (index == 1)
{
MaxVal = wstr1
}
}
errorsFound += inRangeCheck( FormObjectValue, FormObjectName, MinVal, MaxVal)
}
}
}
return errorsFound
}

