// BOI, followed by one or more whitespace characters, followed by EOI.
var reWhitespace = /^\s+$/

// BOI, followed by one or more digits, followed by EOI.
var reInteger = /^\d+$/
var digitsInZIPCode1 = 5

// Returns true if string s is empty or
// whitespace characters only.

function isWhitespace (s)

{
    return (reWhitespace.test(s));
}

// Check whether string s is empty.
/*
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
*/

/*
 *  This function will verify that the supplied field has the format of a
 *  valid SSN.
 */
function checkSSN( theField ) {
	var normalizedSSN = stripCharsNotInBag( theField.value, "0123456789" );

    if( normalizedSSN.length != 9 ) {
        alert( "Please check the social security number entered. "
               +"\nThe social security number entered should be the members "
               +"and consist of 9 digits." );
            theField.focus();
            return false;
    }
    else {
        //formatAsSSN( theField );
        theField.value = normalizedSSN;
        return true;
    }
}

/*
 *  This function will strip all of the characters within the "bag" from
 *  the string "s".
 */
function stripCharsInBag( s, bag ) {
	var i;
	var returnString = "";
	for (i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if(bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}

/*
 *  This function will strip all of the characters that are NOT in the "bag"
 *  from the string "s".  An example would be to remove non numeric characters
 *  from a social security number string.  This would be accomplished by
 *  calling this function as follows: stripCharsNotInBag( SSN, "0123456789" )
 */
function stripCharsNotInBag( s, bag ) {
	var i;
	var returnString = "";
	for (i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if(bag.indexOf(c) != -1) returnString += c;
	}
	return returnString;
}

/*
 *  This function will reformat a string by adding the arguments passed in at
 *  the requested offset.  An example would be to reformat the social security
 *  string "111223333" into "111-22-3333".  This would be accomplished by
 *  calling this function as follows: reformat( SSN, "", 3, "-", 2, "-", 4 )
 */
function reformat( s ) {
	var arg;
	var sPos = 0;
	var resultString = "";
	for( var i = 1; i < reformat.arguments.length; i++ ) {
		arg = reformat.arguments[i];
		if ( i % 2 == 1 ) {
			resultString += arg;
		}
		else {
			resultString += s.substring(sPos, sPos + arg);
			sPos += arg;
		}
	}
	return resultString;
}

/*
 *  This function will format the field so that it appears as a valid SSN
 *  should.
 */
function formatAsSSN( theField ) {
	theField.value = stripCharsNotInBag( theField.value, "0123456789" );
    theField.value = theField.value.substr( 0, 9 );
	if( theField.value.length == 9 ) {
        theField.value = reformat( theField.value, "", 3, "-", 2, "-", 4 );
    }
}

/*
 *  This function will verify that the supplied field has the format of a
 *  valid phone number.
 */
function checkPhoneNumber( theField )
{
    var normalizedPhoneNumber = stripCharsNotInBag( theField.value,
                                                    "0123456789" );
    if( normalizedPhoneNumber.length > 0 ) {
        if( normalizedPhoneNumber.length != 7 ) {
            alert( "You have entered an invalid phone number.\nA valid " +
                   "phone number will consist of a 3 digit exchange and " +
                   "a 4 digit extension (example: 999-9999).  Please try " +
                   "again." );
            theField.value = normalizedPhoneNumber;
            theField.focus();
            return false;
        }
        else {
            formatAsPhoneNumber( theField );
            return true;
        }
    }
    else {
        return true;
    }
}

/*
 *  This function will format the field so that it appears as a valid phone
 *  number.
 */
function formatAsPhoneNumber( theField )
{
    theField.value = stripCharsNotInBag( theField.value, "0123456789" );
    theField.value = theField.value.substr( 0, 7 );
    if( theField.value.length == 7 ) {
        theField.value = reformat( theField.value, "", 3, "-", 4 );
    }
}

/*
 *  This function will verify that the supplied field has the format of a
 *  valid area code.
 */
function checkAreaCode( theField )
{
    var normalizedAreaCode = stripCharsNotInBag( theField.value,
                                                 "0123456789" );
    if( normalizedAreaCode.length > 0) {
        if( normalizedAreaCode.length != 3 ) {
            alert( "You entered an invalid area code.\nA valid area code " +
                   "consists of 3 digits (example: 999).  Please try again." );
            theField.value = normalizedAreaCode;
            theField.focus();
            return false;
        }
        else {
            formatAsAreaCode( theField );
            return true;
        }
    }
    else {
        return true;
    }
}

/*
 *  This function will format the field so that it appears as a valid area
 *  code.
 */
function formatAsAreaCode( theField )
{
    theField.value = stripCharsNotInBag( theField.value, "0123456789" );
    theField.value = theField.value.substr( 0, 3 );
}

/*
 *  This function will verify that the supplied field has the format of a
 *  valid phone extension.
 */
function checkPhoneExtension( theField )
{
    var normalizedPhoneExtension = stripCharsNotInBag( theField.value,
                                                  "0123456789" );
    if( normalizedPhoneExtension.length > 0) {
        if( normalizedPhoneExtension.length > 7 ) {
            alert( "You entered an invalid phone extension.\nA valid phone " +
                   "extension consists of 1 to 7 digits (example: 999 or " +
                   "9999).  Please try again." );
            theField.value = normalizedPhoneExtension;
            theField.focus();
            return false;
        }
        else {
            formatAsPhoneExtension( theField );
            return true;
        }
    }
    else {
        return true;
    }
}

/*
 *  This function will format the field so that it appears as a valid phone
 *  extension.
 */
function formatAsPhoneExtension( theField )
{
    theField.value = stripCharsNotInBag( theField.value, "0123456789" );
    if( theField.value.length > 1 ) {
        theField.value = theField.value.substr( 0, 7 );
    }
}

/*
 *  This function will verify that the supplied field has the format of a
 *  valid user password.
 */
function checkPassword( theField )
{

    var invalidChars = formatAsSMFHPassword( theField);

    if( invalidChars.length > 0 )
    {
        alert( "You must supply a valid Password.\n  Please re-enter your user Password." );
	theField.focus();
	return false;
    }

    normalizedPassword = theField.value;

    if ( ( normalizedPassword.length < 6 ) || ( normalizedPassword.length > 25 ) )
    {
        alert( "Please check the password you have entered."
               +"\nThe password should be between 6 and 12 characters and "
               +" should include at least one number and one letter." );
		theField.focus();
	return false;
    }
    
    //check to see the password contains atleaset a integer.
    var numbersInPassword = stripCharsNotInBag(normalizedPassword,"0123456789");
    
    if (numbersInPassword.length == 0)
    {
        alert( "The password should contain atleast one number " );
	theField.focus();
	return false;    	
    }	
    
    //check to see the password contains atleaset a character.
    var charsInPassword = stripCharsNotInBag(normalizedPassword,
     "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
    
    if (charsInPassword.length == 0)
    {
        alert( "The password should contain atleast one Alphabet" );
	theField.focus();
	return false;    	
    }	
        
    return true;
}

/*
 *  This function will verify that the supplied field has the format of a
 *  valid name (first or last).  This is determined simply by removing
 *  invalid characters.
 */
function checkName( theField )
{
    var normalizedName = formatAsName( theField );
	if( normalizedName.length == 0 ) {
		alert( "You must supply a name.\n  Please re-enter your name." );
		theField.focus();
		return false;
	}
	else {
        formatAsName( theField );
		return true;
	}
}

/*
 *  This function will format the field so that it appears as a valid name.
 */
function formatAsName( theField ) {
    theField.value = theField.value.toUpperCase();
    theField.value = stripCharsNotInBag( theField.value,
        "abcdefghijklmnopqrstuvwxyz-`' ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
    return theField.value;
}

/*
 *  This function will verify that the supplied field has the format of a
 *  valid email address.
 */
function checkEmail( theField ) {
	var normalizedEmail = formatAsEmailAddress( theField);
	var theFieldLength = normalizedEmail.length;
	var i = 1;
	var errorString = "The e-mail address you entered does not appear to be " +
                      "valid.  A valid e-mail address would be similar to " +
                      "webdeveloper@firsthealth.com";
    theField.value = normalizedEmail;
    if( theFieldLength == 0 ) return true;
	while((i < theFieldLength) && (normalizedEmail.charAt(i) != "@")) {
		i++;
	}
	if( (i >= theFieldLength) || (normalizedEmail.charAt(i) != "@") ) {
		alert( errorString );
		theField.focus();
		return false;
	}
	else {
		i += 2;
	}
	while( (i < theFieldLength) && (normalizedEmail.charAt(i) != ".") ) {
		i++;
	}
	if( (i >= theFieldLength - 1) || (normalizedEmail.charAt(i) != ".") ) {
		alert( errorString );
		theField.focus();
		return false;
	}
	else {
		return true;
	}
}

/*
 *  This function will format the field so that it appears as a valid email
 *  address.
 */
function formatAsEmailAddress( theField )
{
    theField.value = stripCharsInBag( theField.value, " :;,/" );

    return theField.value;
}

/*
 * This function returns current data
 */
function fnGetDate()
{
    var today = currDate.toLocaleString().split(/\s/);
    return today[1] + " " + today[2] + " " + today[3]
}


/*
 *  This function will verify that the supplied field has the format of a
 *  valid SMFH User Id.  This is determined simply by removing
 *  invalid characters.
 */
function checkSMFHUserId( theField )
{
    var invalidChars = formatAsSMFHId(theField );

    if( invalidChars.length > 0 )
    {
        alert( "You must supply a valid user Name.\n  Please re-enter your user Name." );
	theField.focus();
	return false;
    }

    var normalizedId = theField.value;

    if ( ( normalizedId.length < 6 ) || ( normalizedId.length > 25 ) )
    {
        alert( "You must enter a User Name that is between 6 and 25 " +
               "characters in length.\nPlease reenter your User Id." );
	theField.focus();
	
	return false;
    }
    
    //check to see whether userid starts with a character.
    
    var invalidChar = stripCharsInBag( normalizedId.charAt(0),
                      "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" );
    
    if (invalidChar.length > 0) 
    {
        alert( "The User Name should start with an Alphabet") ;  
        
        return false;  	
    }

    
    return true;

}

/*
 *  This function will format the field so that it appears as a valid SMFH userId.
 */
function formatAsSMFHId( theField ) {

    var invalidChars = stripCharsInBag( theField.value,
        "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" );
    return invalidChars;

}

/*
 *  This function will format the field so that it appears as a valid SMFH password.
 */
function formatAsSMFHPassword( theField ) {

    var invalidChars = stripCharsInBag( theField.value,
        "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" );
    return invalidChars;

}

/*
 *  This function will verify that the supplied field has the format of a
 *  valid Group Code.  This is determined simply by removing
 *  invalid characters.
 */
function checkGroupCode( theField )
{
    var normalizedCode = formatAsGroupCode(theField );

    if( normalizedCode.length > 0 )
    {
        alert( "You must supply a valid Member's Login Id.\n  Please re-enter Login Id." );
	theField.focus();
	return false;
    }

    return true;

}

/*
 *  This function will format the field so that it appears as a valid GroupCode.
 */
function formatAsGroupCode( theField ) {

     var invalidChars = stripCharsInBag( theField.value,
        "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" );
    return invalidChars;

}

/*
 * Validate Search form and submit
 */
function validateSearchForm(searchform)
{
    var inputError = true;
    //Validate groupCode
    var groupCode = searchform.groupCode.value;

    if ( (isWhitespace(groupCode)) || (isEmpty(groupCode)) )
    {
        alert(" Please enter Member's Login Id ");
        return false;
    }
    else if (!checkGroupCode(searchform.groupCode))
    {
        return false;
    }

    searchform.groupCode.value =  groupCode.toUpperCase();

    //Validate User Id
    var userId = searchform.userId.value;
    if ( (isWhitespace(userId)) || (isEmpty(userId)) )
    {
        alert(" Please enter Social Security Number or User Name");
        return false;
    }

    if (searchform.idType[0].checked)
    {
        //Validate User id for SSN(Memebr Id) format
        if (checkSSN(searchform.userId))
        {
           inputError = false;
        }
    }
    else
    {
        //Validate User id for SMFH UserId format.
        if (checkSMFHUserId(searchform.userId))
        {
           inputError = false;
        }
    }

    if (inputError)
    {
        return false;
    }

    //submit form
    searchform.submit()

}

/*
 *Opens the child window with the given URL
 */

function openChildWindow(url)
{


}

//Validate Profile form in SMFHMS
function validateProfileForm(form)
{
    var groupCode = form.groupCode.value;
    var userId = form.userId.value;
    var memberId = form.memberId.value;
    var busEntId = form.busEntId.value;
    var now = new Date();
    var submit = true;
    var msg = " Please note: The password for this member was reset in the past 10 days. Do you still want to send a new password? \n"
              +" Please click OK to send a new password or click CANCEL."  

    if ( isEmpty(groupCode) || (isEmpty(userId) && isEmpty(memberId))  )
    {
        alert("User Information Missing, Password cannot be reset");
        return false;
    }
    if ( !isEmpty(form.regExpDate.value)  && 
                        !isWhitespace(form.regExpDate.value) )
    {   
        var regDate =  form.regExpDate.value.split(",");
        regDate = new Date(regDate[0],regDate[1]-1,regDate[2]); 
        var diff = daysElapsed(now,regDate);
        if ( regDate < now )
        {
           alert("Please note: The password for this member can not be reset at this time. This member's registration has expired. Member needs to re-register his/her account with us again to receive a new password to proceed with activation.");
           return false; 
        }     
    } 
    if ( !isEmpty(form.pwdSendDate.value)  && 
                        !isWhitespace(form.pwdSendDate.value) )
    {   
        var pwdDate =  form.pwdSendDate.value.split(",");
        pwdDate = new Date(pwdDate[0],pwdDate[1]-1,pwdDate[2]); 
        var diff = daysElapsed(now,pwdDate);
        if ( parseInt(diff) <= 10 )
        {
           submit = confirm(msg); 
        }     
    }    
     
    if ( submit ) 
    {
        form.submit();
    }
    else
    {
        return false;
    }       

}//function validate Profile form ends

//Validate Profile form for User Unlock reuest in SMFHMS
function validateUnLockForm(form)
{
    var groupCode = form.groupCode.value;
    var userId = form.userId.value;
    var memberId = form.memberId.value;
    var busEntId = form.busEntId.value;

    if ( isEmpty(groupCode) ||  isEmpty(memberId)  )
    {
        alert("User Information Missing, User cannot be unlocked");
        return false;
    }

    form.action = form.unlockAction.value;
    
    //Submit form
    form.submit();

}//function validateUnLock Form ends

//Validate Registration form of SMFH

function validateRegForm(form)
{
    groupCode = form.groupCode.value;
    memberId= form.memberId.value;

    if ( isEmpty(groupCode) )
    {
        alert("ClientId/GroupCode Missing, Registration cannot be perfomed");
        return false;
    }

    if ( (isWhitespace(memberId)) || (isEmpty(memberId)) )
    {
        alert(" Please enter the Social Security Number ");
        return false;
    }

    //Validate User id for SSN(Memebr Id) format
    if (!checkSSN(form.memberId))
    {
        return false;
    }

    //Submit form
    form.submit();
}//function  validateRegForm  ends

//Validate Authentication Form in SMFH
function validateAuthForm(form)
{
    groupCode = form.groupCode.value;
    memberId = form.memberId.value;
    password = form.password.value;

    if ( isEmpty(groupCode) )
    {
        alert("ClientId/GroupCode Missing, Activation cannot be perfomed");
        return false;
    }

    if ( (isWhitespace(memberId)) || (isEmpty(memberId)) )
    {
        alert(" Please enter all the required fields ");
        return false;
    }

    //Validate User id for SSN(Memebr Id) format
    if (!checkSSN(form.memberId))
    {
        return false;
    }

    if ( (isWhitespace(password)) || (isEmpty(password)) )
    {
        alert(" Please enter all the required fields ");
        return false;
    }

    //Validate User id for SSN(Memebr Id) format
   /* if (!checkPassword(form.password))
    {
        return false;
    }
    */

    //Submit form
    form.submit();

}//function validateAuthForm ends

//Validate Activation form in SMFH
function validateActivationForm(form)
{
    var groupCode       = form.groupCode.value;
    var userId          = form.userId.value;
    var password        = form.password.value;
    var passwordReEnter = form.passwordReEnter.value;
    var SelectedIndex   = form.secretQuesId.selectedIndex;
    var secretQuesId          = form.secretQuesId.options[SelectedIndex].value;
    var secretAnswer          = form.secretAnswer.value;
    var emailAddress          = form.emailAddress.value;
   
    var emailUpdate     = form.emailUpdate.value;
    var emailUpdateseReceived = false;
    
    if ( emailUpdate == "Selection")
    {
        emailUpdateseReceived = form.emailUpdateseReceived.checked;

        if (emailUpdateseReceived)
        {
            form.emailUpdateseReceived.value="Y"; 
        }
        else
        {
            form.emailUpdateseReceived.value="N"; 
        }        
    }
    
    if ( isEmpty(groupCode) )
    {
        alert("ClientId/GroupCode Missing, Activation cannot be perfomed");
        return false;
    }

    if ( (isWhitespace(userId)) || (isEmpty(userId)) )
    {
        alert(" Please enter all the required fields ");
        return false;
    }

    if (!checkSMFHUserId(form.userId))
    {
        return false;
    }

    if ( (isWhitespace(password)) || (isEmpty(password)) )
    {
        alert(" Please enter all the required fields ");
        return false;
    }

    if (!checkPassword(form.password))
    {
        return false;
    }

    if ( (isWhitespace(passwordReEnter)) || (isEmpty(passwordReEnter)) )
    {
        alert(" Please Re enter Member's password");
        return false;
    }

    if (!checkPassword(form.passwordReEnter))
    {
        return false;
    }

    if (password != passwordReEnter)
    {
         alert(" Passwords don't match, Please correct");
         return false;
    }

    if (SelectedIndex == 0)
    {
        alert(" Please select a secret question");
        return false;
    }

    if ( (isWhitespace(secretAnswer)) || (isEmpty(secretAnswer)) )
    {
        alert(" Please enter all the required fields ");
        return false;
    }
    else
    {
        form.secretAnswer.value = secretAnswer.toUpperCase();
    }

    if ( (isWhitespace(emailAddress)) || (isEmpty(emailAddress)) )
    {
        alert(" Please enter all the required fields ");
        return false;
    }

    if (!checkEmail(form.emailAddress))
    {

        return false;
    }

    //Submit form
    form.submit();
}

function goRegistartion(searchForm,regForm)
{
    //Validate groupCode
    var groupCode = searchForm.groupCode.value;
    var status = true;
    if ( (isWhitespace(groupCode)) || (isEmpty(groupCode)) )
    {
        alert(" Please enter Member's Login Id ");
        status = false;
    }
    else if (!checkGroupCode(searchForm.groupCode))
    {
        status = false;
    }

    if (status == true)
    {
        searchForm.groupCode.value =  groupCode.toUpperCase();
        createWindow(regForm.action
                     +"?groupCode="+searchForm.groupCode.value
                     +"&pageAction=GoRegistration"
                     +"&reqOrgin=SMFHMS"
                     +"&portalId=6");
    }
}


/*
 *  This function will create a new window with the specified URL in it.
 *  This function is used solely by the privacy statement window.
 */
function createWindow( URL )
{
    var winWidth = screen.availWidth*.9;
    var winHeight = screen.availHeight*.75;
    var xOffset = (screen.availWidth-winWidth-40)*(1/2);
    var yOffset = (screen.availHeight-winHeight-140)*(1/2);
    var today = new Date();
    var time = today.getTime();

    if ( URL.lastIndexOf("?") == -1 )
    {
        URL = URL + "?uniqueURI=" + time;
    }
    else
    {
        URL = URL + "&uniqueURI=" + time;
    }

    theWindow = window.open( URL,
                             "theWindow",
                             "dependent," +
                             "directories=no," +
                             "location=no," +
                             "menubar=yes," +
                             "personalbar=no," +
                             "resizable=yes," +
                             "scrollbars=yes," +
                             "status=yes," +
                             "toolbar=no," +
                             "height=" + winHeight + "," +
                             "innerheight=" + winHeight + "," +
                             "width=" + winWidth + "," +
                             "innerWidth=" + winWidth + "," +
                             "left=" + xOffset + "," +
                             "screenX=" + xOffset + "," +
                             "top=" + yOffset + "," +
                             "screenY=" + yOffset );

    theWindow.focus();
}

//validate Forgot User Id form
function validateForgotUserID(form)
{
    var groupCode       = form.groupCode.value;
    var memberId        = form.memberId.value;
    var emailAddress    = form.emailAddress.value;

    if ( isEmpty(groupCode) )
    {
        alert("ClientId/GroupCode Missing, Requested service cannot be perfomed");
        return false;
    }

    if ( (isWhitespace(memberId)) || (isEmpty(memberId)) )
    {
        alert(" Please enter all the required fields ");
        return false;
    }

    //Validate User id for SSN(Memebr Id) format
    if (!checkSSN(form.memberId))
    {
        return false;
    }

    if ( (isWhitespace(emailAddress)) || (isEmpty(emailAddress)) )
    {
        alert(" Please enter all the required fields ");
        return false;
    }

    if (!checkEmail(form.emailAddress))
    {

        return false;
    }

    //Submit form
    form.submit();

}//validateForgotUserID ends

//validate validateSecQuesForm
function validateSecQuesForm(form)
{
    var groupCode       = form.groupCode.value;
    var userId          = form.userId.value;
    var secretQuesId          = form.secretQuesId.value;
    var secretAnswer          = form.secretAnswer.value;

    if ( isEmpty(groupCode) )
    {
        alert("ClientId/GroupCode Missing, Requested service cannot be perfomed");
        return false;
    }

    if ( (isWhitespace(userId)) || (isEmpty(userId)) )
    {
        alert("Please enter User Name");
        return false;
    }

    if ( (isWhitespace(secretQuesId)) || (isEmpty(secretQuesId)) )
    {
        alert("secret Question Missing, Requested service cannot be perfomed");
        return false;
    }

    if ( (isWhitespace(secretAnswer)) || (isEmpty(secretAnswer)) )
    {
        alert(" Please enter all the required fields ");
        return false;
    }
    else
    {
        form.secretAnswer.value = secretAnswer.toUpperCase();
    }
    //Submit form
    form.submit();

    //alert("Validation over");

 }//validateSecQuesForm ends


function validateForgotPwd(form)
{
    var groupCode       = form.groupCode.value;
    var userId          = form.userId.value;

    if ( isEmpty(groupCode) )
    {
        alert("ClientId/GroupCode Missing, Requested service cannot be perfomed");
        return false;
    }

    if ( (isWhitespace(userId)) || (isEmpty(userId)) )
    {
        alert("Please enter the User Name" );
        return false;
    }

    //Submit form
    form.submit();
} //validateForgotPwd ends


function validateEditProfileForm(form)
{
    var groupCode       = form.groupCode.value;
    var userId          = form.userId.value;
    var password        = form.password.value;
    var passwordReEnter = form.passwordReEnter.value;
    var SelectedIndex   = form.secretQuesId.selectedIndex;
    var secretQuesId          = form.secretQuesId.options[SelectedIndex].value;
    var secretAnswer          = form.secretAnswer.value;
    var emailAddress          = form.emailAddress.value;
    var checkModified   = false;

    var emailUpdate     = form.emailUpdate.value;
    var emailUpdateseReceived = false;
    
    if ( emailUpdate == "Selection")
    {
        emailUpdateseReceived = form.emailUpdateseReceived.checked;
        
        if (emailUpdateseReceived)
        {
            form.emailUpdateseReceived.value="Y"; 
        }
        else
        {
            form.emailUpdateseReceived.value="N"; 
        }        
    }

    if ( isEmpty(groupCode) )
    {
        alert("ClientId/GroupCode Missing, Profile updation cannot be perfomed");
        return false;
    }

    if ( (isWhitespace(userId)) || (isEmpty(userId)) )
    {
        alert("UserId  Missing, Profile updation cannot be perfomed");
        return false;
    }

    if (!checkSMFHUserId(form.userId))
    {
        return false;
    }

    if ( (!isWhitespace(password)) && (!isEmpty(password)) )
    {
        if (!checkPassword(form.password))
        {
            return false;
        }
        else
        {
           checkModified = true;
        }
    }
    else
    {
        form.password.value = "";
    }


    if ( checkModified )
    {
        if ( isWhitespace(passwordReEnter) || isEmpty(passwordReEnter)  )
        {
           alert("Please ReEnter Password");
           return false;
        }

        if (!checkPassword(form.passwordReEnter))
        {
            return false;
        }

        if (password != passwordReEnter)
        {
            alert(" Passwords don't match, Please correct");
            return false;
        }

    }

    if (SelectedIndex == 0)
    {
        alert(" Please select a secret question");
        return false;
    }

    if ( (isWhitespace(secretAnswer)) || (isEmpty(secretAnswer)) )
    {
        alert(" Please enter all the required fields ");
        return false;
    }
    else
    {
        form.secretAnswer.value = secretAnswer.toUpperCase();
    }

    if ( (isWhitespace(emailAddress)) || (isEmpty(emailAddress)) )
    {
        alert(" Please enter all the required fields ");
        return false;
    }

    if (!checkEmail(form.emailAddress))
    {
        return false;
    }

    //Submit form
    form.submit()
}      
  
/*
 function navigate(appURL)
 {
   var groupCd = document.LinkApps.groupCode.value;
   var portalId = document.LinkApps.portalId.value;
   var pageId = document.LinkApps.pageId.value;
   
   if ( isEmpty(groupCd) || isEmpty(portalId) || isEmpty(pageId) 
                                              || isEmpty(appURL) )
   {
       alert(" Missing User Information , Request cannot be completed");
       return;	
   }	
   
   document.LinkApps.action=appURL;
   //Submit form
   document.LinkApps.submit();
 	
 }	
 
 */
 
 //display instruction pages for my account tab
 function displayInstructions(htmlLink, actionServlet, displayName, displayFlag)
 {
     //Read data from "Instructions" form
     var groupCd = document.Instructions.groupCode.value;
     
     if ( isEmpty(groupCd) || isEmpty(htmlLink) || isEmpty(actionServlet) )
     {
         alert(" Missing User Information , Request cannot be completed");
         return;
     }	

     document.Instructions.pageAction.value = htmlLink;
     document.Instructions.action=actionServlet;
     //Submit form
     document.Instructions.submit();
 	
 }//end displayInstructions
 
 //logout smfhms and close window
 function logoutMS(URLLink)
 {
     document.location.href=URLLink;
     self.close();	
 }
 
 function validateBulkRegForm(form)
 {
    //var busEntId  = form.busEntId.value;
    var filename  = form.filename.value; 
    
    if  ( isWhitespace(filename)  )
            
    {
        alert("Enter the File Name for Bulk Registration");
        return false;
    }
    	
    //Submit form
    form.submit()    	
 }	
 
   function mhbpNavigate( appURL)
    {
        document.LinkApps.groupCode.value = sGroupCode;
        document.LinkApps.portalId.value = sPortalId;
        document.LinkApps.pageId.value = sPageId ;
        document.LinkApps.myAcctURL.value = "javascript:fromNavigation('"+sAccountMenuId+"');";

      if (  isEmpty(sGroupCode)   ||   isEmpty(sPortalId)   ||   isEmpty(sAccountMenuId)    ||   isEmpty(sPageId)   )
      {
         alert(" Missing User Information , Request cannot be completed");
         return;	
      }	
   
      document.LinkApps.action=appURL;
      document.LinkApps.submit();
 	
  }
  
  //Convert Year to above 1900.
  function y2k(number) { return (number < 1000) ? number + 1900 : number; }

  //Calculate days elapsed between dates.
  function daysElapsed(date1,date2) 
  {
    var difference =
        Date.UTC(y2k(date1.getYear()),date1.getMonth(),date1.getDate(),0,0,0)
      - Date.UTC(y2k(date2.getYear()),date2.getMonth(),date2.getDate(),0,0,0);
    return difference/1000/60/60/24;
  }
  
  //document.write(daysElapsed(new Date(2000,0,1),new Date(1999,11,31)));      