///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
//THIS CONTAINS USER PROFILE MANAGEMENT FUNCTIONS
///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////////
// AUTHOUR: WBQ
// CREATED: 2007-07-07
// UPDATED: 2007-07-10 WBQ
// DESCRIPTION: GENERATES USERID VALUE, EMAIL (FLNAME@EMAIL) BASED ON VALUES PASSED

function generateUserID(fName,lName){
	var	gendUserID = '';
	gendUserID = fName.substring(0,1) + lName;
	gendUserID = gendUserID.toLowerCase();
	return gendUserID;
}
function generateEmail(fName,lName,eMail){
	var	gendEmail = '';
	gendEmail = generateUserID(fName,lName) + '@' + eMail; 
	gendEmail = gendEmail.toLowerCase();
	return gendEmail;
}
///////////////////////////////////////////////////////////////////////////////////////////////



///////////////////////////////////////////////////////////////////////////////////////////////
// AUTHOUR: WBQ
// CREATED: 2007-07-10
// UPDATED: 
// DESCRIPTION: VALIDATES MYPROFILE SCREEN PWD AND EMAIL UPDATES

function checkUserProfileFields(theForm) {
//	form= document.getElementById(theForm);
	var minQLength = 8; 
	var minALength = 3; 
	var updateProfile = 0; //dirty flag to see if any changes are made
	var CurrentPassword = document.getElementById('CurrentPassword');
	var SQuestion = document.getElementById('SQuestion');
	var PWD = document.getElementById('PWD');
	var REPEATPASSWORD = document.getElementById('REPEATPASSWORD');
	var SAnswer = document.getElementById('SAnswer');
	var NewEmail = document.getElementById('NewEmail');
	var NewEmail2 = document.getElementById('NewEmail2');
	var QMsg= 'Please choose a question and answer to aid in the retrieval of your password that is at least ';
	var AMsg= 'Please choose a question and answer to aid in the retrieval of your password that is at least ';
	QMsg = QMsg + minQLength + ' characters long.';
	AMsg = AMsg + minALength + ' characters long.';
	// CHECK THE CURRENT PASSWORD ENTRY
	if (CurrentPassword.value.length < pwdMinLength) // pwdMinLength IS SET IN _GENERAL.JS
	{
	alert('Please enter your current password to update your profile.');
	CurrentPassword.select();
	CurrentPassword.focus();
	CC('CurrentPassword'); 
	return false;
	}
	else CB('CurrentPassword');
		
	//If the NewEmail is entered, check its validity
	if (NewEmail.value.length != 0)
	{
		if(emailCheck(NewEmail.value) == false) 
		{
		alert("Please Enter A Valid New Email.");
		NewEmail.select();
		NewEmail.focus();
		CC('NewEmail'); 
		return false;
		}
	else CB('NewEmail');
	}

	//If the NewEmail2 is entered, check its validity
	if (NewEmail2.value.length != 0) 
	{
		if(emailCheck(NewEmail2.value) == false) 
		{
		alert("Please Enter A Valid New Email.");
		NewEmail2.select();
		NewEmail2.focus();
		CC('NewEmail2'); 
		return false;
		}
	else CB('NewEmail2');
	}

	//Check if the emails match
	if (NewEmail.value != NewEmail2.value) 
	{
		alert("Please Make Sure Your Emails Match."); 
		NewEmail.select();
		NewEmail.focus();
		CC('NewEmail');	
		NewEmail2.select();
		NewEmail2.focus();
		CC('NewEmail2');	
		return false;
	}
	else {
		CB('NewEmail2') ; 
		CB('NewEmail');	
		if (NewEmail2.value.length != 0 && NewEmail.value.length != 0) {updateProfile = 1;} //if email is not blank, set update=1
	}	
	
	//CHECK THE STANDARD PASSWORD FIELDS
	if (PWD.value.length != 0 || REPEATPASSWORD.value.length != 0) {
		if (checkPwdFields('EDITUSERPROFILE') != true) // USES THE PASSWORD CHECKER IN _SCRIPTS/__PASSWORDS.JS
			{
			return false;
			}		
		else {if (PWD.value.length != 0 && REPEATPASSWORD.value.length != 0) {updateProfile = 1;} }//if PWD is not blank, set update=1}	
	}
	
	//CHECK THE Q&A FIELDS
	else if (SQuestion.value.length < minQLength) 
	{
		alert(QMsg);
		SQuestion.select();
		SQuestion.focus();
		CC('SQuestion'); 
		return false;
	}
	else CB('SQuestion');

	if (SAnswer.value.length < minALength) 
	{
		alert(AMsg);
		SAnswer.select();
		SAnswer.focus();
		CC('SAnswer'); 
		return false;
	}
	
	//if any changes were made to the Q&A fields	
	if (SAnswerChange == 1 || SQuestionChange == 1 ) 
	{
		updateProfile = 1;
	}

	//final outcome if everything is okay
	if (updateProfile == 1){CB('SAnswer'); return true;}
	else {	alert('There are no changes to submit'); return false;}

}

///////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////////
// AUTHOUR: WBQ
// CREATED: 2004
// UPDATED: 2007-07-07 - HIGHLY SIMPLIFIED THIS TO REUSE BASE FUNCTIONS
// DESCRIPTION: CHECKS FIELDS FOR ADDING NEW USER BEFORE SUBMISSION
function checkNewUserFields(theForm){
	form= document.getElementById(theForm);
	var invalid = pwdInvalid; // Invalid character is a space - set in _scripts/_general.js
	var minPLength = pwdMinLength; // Minimum password length - set in _scripts/_general.js
	var minULength = userMinULength; // Minimum userid length - set in _scripts/_general.js
	var minNLength = userMinNLength; // Minimum name length - set in _scripts/_general.js
	
		
	if (form.FNAME.value.length < minNLength) 	
		{
		CB('USERID');
		CC('FNAME');
		form.FNAME.select();
		form.FNAME.focus();
		alert('Please Provide A First Name At Least ' + minNLength + ' characters long.');
		return false;
		}	
		
	else if (form.LNAME.value.length < minNLength) 	
		{
		CB('FNAME');
		CC('LNAME');
		form.LNAME.select();
		form.LNAME.focus();
		alert('Please Provide A Last Name At Least ' + minNLength + ' characters long.');
		return false;
		}		
	
	
	else if (form.USERID.value.length < minULength)
		{
		CC('USERID');
		document.getElementById('USERID').select();
		document.getElementById('USERID').focus();
		alert('Please Enter A User ID At Least ' + minULength + ' Characters Long.');
		return false;
		}
	
	else if (form.USERID.value.indexOf(invalid) > -1) 
		{
		CC('USERID');
		document.getElementById('USERID').select();
		document.getElementById('USERID').focus();
		alert('The User ID Cannot Conatain Any Spaces. Please Select A Different User ID.');
		return false;
		}
	
	else if (checkPwdFields('ADDUSER') != true) // USES THE PASSWORD CHECKER IN _SCRIPTS/__PASSWORDS.JS
		{
		CB('LNAME');
		return false;
		}		
	
	else if (form.EMAIL.value.length != 0)
		{ 		CB('PWD');
				CB('REPEATPASSWORD');
			if(emailCheck(form.EMAIL.value) == false) // USES THE EMAIL CHECKER IN _SCRIPTS/_GENERAL.JS
			{
				CC('EMAIL');
				alert("Please Enter A Valid Email.");
				form.EMAIL.select();
				form.EMAIL.focus();
				return false;
			}
			else {
				CB('EMAIL');
				form.submit();
				return false;}
		}
	else {return true;}
}
///////////////////////////////////////////////////////////////////////////////////////////////

