﻿function validateSubmit(currForm)
{
    if (typeof(currForm.skipEdits) !='undefined' && currForm.skipEdits.value =='Y')
    { 
       return true;
    }

    if (currForm.safeSubmit.value !='Y')
    {
        return false;
    }
    else
    {
        if (formCheck(currForm))
        { 
            currForm.safeSubmit.value ='N';
            return true; 
        }
        else
        {
            return false;
        }
    }
}

function validateEmail(currForm)
{
	if(typeof(Form1.emailFromAddress) !='undefined')
	{
    	if(trimAll(Form1.emailFromAddress.value).length == 0)
    	{
           alert("Must have a valid email from address");
           Form1.emailFromAddress.focus()
           return false;
        }
        var at_format = "@";
        var period_format = ".";
        var check_period, check_at;
        var foundPeriod, foundAt;
        foundPeriod = false; 
        foundAt = false; 
        for (var i = 0; i < Form1.emailFromAddress.value.length; i++)
        {
            check_period = period_format.indexOf(Form1.emailFromAddress.value.charAt(i))
            if (check_period == 0)
            {
                foundPeriod = true; 
            }

            check_at = at_format.indexOf(Form1.emailFromAddress.value.charAt(i))
            if (check_at == 0)
            {
                foundAt = true; 
            }
       }
       if (foundAt == false || foundPeriod == false)
       {
            alert("Invalid format for an email address" + foundAt + foundPeriod );
            Form1.emailFromAddress.focus();
            return false;
       }
       
    }
	if(typeof(Form1.emailSubject) !='undefined' && trimAll(Form1.emailSubject.value).length == 0){
       alert("Must have a valid subject");
       Form1.emailSubject.focus()
       return false;
    }
/*
	if(typeof(Form1.emailMessage) !='undefined' && trimAll(Form1.emailMessage.tostring).length == 0){
       alert("Must have a message");
       return false;
    }
*/
    return true;
}

function mySortSubmit(fieldName,sortDirection){
    document.Form1.SORTFIELD.value = fieldName;
    document.Form1.SORTDIRECTION.value = sortDirection;
    document.Form1.submit();
    document.Form1.skipEdits.value ='Y';
}

function formCheck(currForm){
/***********************************************************
    look at the utility.js for further editing functions:
    /* *******************************************
     function checkNumeric(input, fieldName)
         Checks to see if the field is numeric
          input is the input text object
          field name is the name that appears in the error message
    ******************************************* 
    function dateEdit(input,fieldName){
    /* *******************************************
*********************************************************************************************
*   XXXXXX MODIFY the code from the utility goes here  XXXX
*****************************************************************************************/

	if(typeof(currForm.LOGONID) !='undefined' && trimAll(currForm.LOGONID.value).length == 0){
		alert('Please enter Logon ID ');
		currForm.LOGONID.focus();
		return false;
	}
	
	if(typeof(currForm.LOGONID) !='undefined' && trimAll(currForm.LOGONID.value).length < 8){
		alert('The Logon ID must be at least 8 characters in length');
		currForm.LOGONID.focus();
		return false;
	}

	if(!(typeof(currForm.CURRENTPASSWORD) !='undefined' && trimAll(currForm.CURRENTPASSWORD.value).length > 0)){
	    if (typeof (currForm.USERPASSWORD) != 'undefined' && trimAll(currForm.USERPASSWORD.value).length < 8 && trimAll(currForm.USERPASSWORD.value).length != 0) {
		    alert('The Password must be at least 8 characters in length and have at least one numeric.');
		    currForm.USERPASSWORD.focus();
		    return false;
	    }
	}
	
	if(!(typeof(currForm.CURRENTPASSWORD) !='undefined' && trimAll(currForm.CURRENTPASSWORD.value).length > 0)){
	    if(typeof(currForm.USERPASSWORD) !='undefined' && trimAll(currForm.USERPASSWORD.value).length == 0){
		    alert('Please enter Password');
		    currForm.USERPASSWORD.focus();
		    return false;
	    }
	}

    // See if UserPassword is entered but doesn't match Confirm Password

    if(typeof(currForm.USERPASSWORD) !='undefined' && trimAll(currForm.USERPASSWORD.value).length != 0 && currForm.USERPASSWORD.value == currForm.CURRENTPASSWORD.value && trimAll(currForm.CONFIRMUSERPASSWORD.value).length == 0 ) {
    } else 
    
    {
        if(typeof(currForm.USERPASSWORD) !='undefined' && trimAll(currForm.USERPASSWORD.value).length != 0 && currForm.CONFIRMUSERPASSWORD.value != currForm.USERPASSWORD.value) {
            alert('Passwords do not match - reenter both');
            currForm.USERPASSWORD.focus();
            return false;
        }

        // See if confirmPassword is entered but there is no userPassword
        if(typeof(currForm.CONFIRMUSERPASSWORD) !='undefined' && trimAll(currForm.CONFIRMUSERPASSWORD.value).length != 0 && currForm.CONFIRMUSERPASSWORD.value != currForm.USERPASSWORD.value) {
	        alert('Passwords do not match - reenter both');
	        currForm.USERPASSWORD.focus();
	        return false;
        }
    }



	if(typeof(currForm.FIRSTNAME) !='undefined' && trimAll(currForm.FIRSTNAME.value).length == 0){
		alert('Please enter First Name');
		currForm.FIRSTNAME.focus();
		return false;
	}

	if(typeof(currForm.LASTNAME) !='undefined' && trimAll(currForm.LASTNAME.value).length == 0){
		alert('Please enter Last Name');
		currForm.LASTNAME.focus();
		return false;
	}

/*
	if(typeof(currForm.SECURITYLEVEL) !='undefined' && trimAll(currForm.SECURITYLEVEL.value).length == 0){
		alert('Please enter Security');
		currForm.SECURITYLEVEL.focus();
		return false;
	}
*/	
	if(typeof(currForm.SECURITYLEVEL) !='undefined' &&  !checkInteger(currForm.SECURITYLEVEL,'Security')){
		return false;
	}

	if(typeof(currForm.EMAILADDRESS) !='undefined' && trimAll(currForm.EMAILADDRESS.value).length == 0){
		alert('Please enter Emaill');
		currForm.EMAILADDRESS.focus();
		return false;
	}
    return true;
}

function myEditSubmit(keyValue){
	document.Form1.MEMBERID.value = keyValue;
	document.Form1.EDITCLICKED.value = 'Y';
	document.Form1.skipEdits.value =='Y';
	document.Form1.submit();
}

function mySummarySubmit(keyValue){
	document.Form1.MEMBERID.value = keyValue;
	document.Form1.SUMMARYCLICKED.value = 'Y';
	document.Form1.skipEdits.value =='Y';
	document.Form1.submit();
}


function updateUSERCOMMENTSLength(){
	if (typeof(document.Form1.USERCOMMENTS) !='undefined' )
	{
		var fieldLength = document.Form1.USERCOMMENTS.value.length;
		document.Form1.USERCOMMENTSLENGTH.value = fieldLength + 1;
		if (fieldLength > 1500){
			alert('You may only have 1500 characters in your Comments Section');
		}
	}
}

function updateADMINCOMMENTSLength(){
	if (typeof(document.Form1.ADMINCOMMENTS) !='undefined' )
	{
		var fieldLength = document.Form1.ADMINCOMMENTS.value.length;
		document.Form1.ADMINCOMMENTSLENGTH.value = fieldLength + 1;
		if (fieldLength > 1500){
			alert('You may only have 1500 characters in your Admin Comments Section');
		}
	}

}

/***********************************************************
*   XXXX End MODIFY the code from the utility ends here
*****************************************************************************************/
	if(typeof(document.Form1.FILTER_FIRSTNAME) !='undefined'){
	    document.Form1.FILTER_FIRSTNAME.focus();
	}

