/* 	

	sProfile.js | School Profile JavaScript Functions
	----------------------------------------------------------
	ALL JavaScript included in this file is the property of 
	Teachers-Teachers.com
	
	None of this code may be used (in current or altered form) 
	by any other party without the express written consent of
	Teachers-Teachers.com
	
	Copyright 2000 Teachers-Teachers.com
	
*/


function stepBack()
{
	var theStep = document.forms[0].sRegStep.value;
	document.forms[0].sRegStep.value = theStep - 1;

	document.forms[0].eddie.value = 'back';
	document.forms[0].submit();
}


/**********************************************************
*
*     name:    checkSchoolInformation
*     author:  Adrian Breeman (abreeman@teachers-teachers.com)
*     date:    11/04/2002
*
*     Checks the first step of school registration
*
**********************************************************/

function checkSchoolInformation()
{
	var alerted = true;
	var formVar = document.forms[0];

	formVar.sRegDistrictName.value	= trimCapitals(formVar.sRegDistrictName.value);
	formVar.sRegAddress1.value 	= trimCapitals(formVar.sRegAddress1.value);
	formVar.sRegAddress2.value 	= trimCapitals(formVar.sRegAddress2.value);
	formVar.sRegCity.value 		= trimCapitals(formVar.sRegCity.value);

	alerted = chkNotNull(1,'sRegDistrictName,sRegAddress1,sRegCity,sRegZip');
	if(alerted)
		alerted = checkZip(formVar.sRegZip);
	if(alerted) {
		if(!(formVar.sRegNeighborhoodType[0].checked || formVar.sRegNeighborhoodType[1].checked || formVar.sRegNeighborhoodType[2].checked)) {
			alert('Please indicate a type of neighborhood.'); formVar.sRegNeighborhoodType[0].focus(); 
			alerted = false;
		}
	}

// Does not check:
//   web page address.
//   mission statement.
//   description of school/schoolSystem.
//   neighborhood type.	
	
	return(alerted);
}


/**********************************************************
*
*     name:    checkContactInformation()
*     author:  Adrian Breeman (abreeman@teachers-teachers.com)
*     date:    11/04/2002
*
*     based on checkContactInfo()
*       author:  shanon levenherz (shanonvl@hotmail.com)
*       date:    05/21/2000
*
*     Checks the second step of school registration
*
**********************************************************/

function checkContactInformation()
{

	var alerted = true;
	var formVar = document.forms[0];
	
	if(formVar.sEmail)
	{
		alerted = chkNotNull(1,'sRegContactFirstName,sRegContactLastName,sRegContactPosition,sRegContactPhone,sRegContactEmail,sRegNumberOfSchools');
	}
	else
	{
		alerted = chkNotNull(1,'sRegContactFirstName,sRegContactLastName,sRegContactPosition,sRegContactPhone');	
	}
	
	if(alerted)
	{
		formVar.sRegContactFirstName.value = trimCapitals(formVar.sRegContactFirstName.value);
		formVar.sRegContactLastName.value  = trimCapitals(formVar.sRegContactLastName.value);
		formVar.sRegContactPosition.value  = trimCapitals(formVar.sRegContactPosition.value);
		alerted = checkPhone(formVar.sRegContactPhone,'Phone');
	}
	
	if(alerted && isNotNull(formVar.sRegContactFax))
		alerted = checkPhone(formVar.sRegContactFax,'Fax');
	if(alerted && formVar.sRegContactEmail)
		alerted = checkEmail(formVar.sRegContactEmail);

	// num schools.
	if(alerted && formVar.sRegNumberOfSchools)
	{
		if(!(parseInt(formVar.sRegNumberOfSchools.value) > 0))
		{
			alert('You must specify an integer greater than zero in this field.');
			formVar.sRegNumberOfSchools.focus();
			alerted = false;
		}
		else
		{
			formVar.sRegNumberOfSchools.value = parseInt(formVar.sRegNumberOfSchools.value);
		}
	}

	return(alerted);

}




/**********************************************************
*
*     name:    checkBillingInformation()
*     author:  Adrian Breeman (abreeman@teachers-teachers.com)
*     date:    11/04/2002
*
*     based on checkBillingInfo()
*       author:  shanon levenherz (shanonvl@hotmail.com)
*       date:    05/21/2000
*
*     Checks the third step of school registration
*
**********************************************************/

function checkBillingInformation()
{
	var formVar = document.forms[0];
	
	if(!chkNotNull(1,'sRegPONumber'))
	{
		return false;
	}
	
	var good = confirm('Please confirm your purchase order number:\n\nYou entered: \''+formVar.sRegPONumber.value+'\'\n\nIf this is correct, click OK.');

	if(!good)
		formVar.sRegPONumber.focus();

	return(good);	

}


function checkBillingInformationVirginia(eddie)
{
	var formVar = document.forms[0];
	
	if(eddie != '1') {
	if(document.forms[0].sAccess[1].checked)
	{
		if(document.forms[0].sRegPONumber.value.length == 0)
		{
			alert('You chose to have regular education access.\n\nPlease supply a purchase order number.');
			return false;
		}
	
	var good = confirm('Please confirm your purchase order number:\n\nYou entered: \''+formVar.sRegPONumber.value+'\'\n\nIf this is correct, click OK.');

	if(!good)
		formVar.sRegPONumber.focus();
	}
	return(good);
	}

}


function checkBillingInformationColorado(eddie)
{
	var formVar = document.forms[0];
	
	if(eddie != '1') {
	if(document.forms[0].sAccess[1].checked)
	{
		if(document.forms[0].sRegPONumber.value.length == 0)
		{
			alert('You chose to have regular education access.\n\nPlease supply a purchase order number.');
			return false;
		}
	
	var good = confirm('Please confirm your purchase order number:\n\nYou entered: \''+formVar.sRegPONumber.value+'\'\n\nIf this is correct, click OK.');

	if(!good)
		formVar.sRegPONumber.focus();
	}
	return(good);
	}

}


function checkBillingInformationRhodeIsland(eddie)
{
	var formVar = document.forms[0];
	
	if(eddie != '1') {
	if(document.forms[0].sAccess[1].checked)
	{
		if(document.forms[0].sRegPONumber.value.length == 0)
		{
			alert('You chose to have regular education access.\n\nPlease supply a purchase order number.');
			return false;
		}
	
	var good = confirm('Please confirm your purchase order number:\n\nYou entered: \''+formVar.sRegPONumber.value+'\'\n\nIf this is correct, click OK.');

	if(!good)
		formVar.sRegPONumber.focus();
	}
	return(good);
	}

}


function checkBillingInformationKentucky(eddie)
{
	var formVar = document.forms[0];
	
	if(eddie != '1') {
	if(document.forms[0].sAccess[1].checked)
	{
		if(document.forms[0].sRegPONumber.value.length == 0)
		{
			alert('You chose to have regular education access.\n\nPlease supply a purchase order number.');
			return false;
		}
	
	var good = confirm('Please confirm your purchase order number:\n\nYou entered: \''+formVar.sRegPONumber.value+'\'\n\nIf this is correct, click OK.');

	if(!good)
		formVar.sRegPONumber.focus();
	}
	return(good);
	}

}


function checkBillingInformationMinnesota(eddie)
{
	var formVar = document.forms[0];
	
	if(document.forms[0].sAccess[1].checked)
	{
		if(document.forms[0].sRegPONumber.value.length == 0)
		{
			alert('You chose to have regular education access.\n\nPlease supply a purchase order number.');
			return false;
		}
	
	var good = confirm('Please confirm your purchase order number:\n\nYou entered: \''+formVar.sRegPONumber.value+'\'\n\nIf this is correct, click OK.');

	if(!good)
		formVar.sRegPONumber.focus();
	}
	return(good);

}


function checkBillingInformationPortal(eddie)
{
	var formVar = document.forms[0];
	
	if(eddie != '1') {
	if(document.forms[0].sAccess[1].checked)
	{
		if(document.forms[0].sRegPONumber.value.length == 0)
		{
			alert('You chose to have regular education access.\n\nPlease supply a purchase order number.');
			return false;
		}
	
	var good = confirm('Please confirm your purchase order number:\n\nYou entered: \''+formVar.sRegPONumber.value+'\'\n\nIf this is correct, click OK.');

	if(!good)
		formVar.sRegPONumber.focus();
	}
	return(good);
	}

}


/**********************************************************
*
*     name:    checkUserProfile()
*     author:  Adrian Breeman (abreeman@teachers-teachers.com)
*     date:    11/05/2002
*
*     based on checkUserProfile()
*       author:  shanon levenherz (shanonvl@hotmail.com)
*       date:    05/21/2000
*
*     Checks the fourth step of school registration
*
**********************************************************/

function checkUserProfile()
{
	var valid_pw = "abcdefghijklmnopqrstuvwxyz1234567890_!*-#+";
	var valid_user = "abcdefghijklmnopqrstuvwxyz1234567890_!*-#+@.";
	var alertStr = "The 'Password' field is invalid.  Passwords contain no spaces, are between 4 and 50 characters, and can contain only alphanumeric characters, !, *, -, #, and +.";
	var alertUsernameStr = "The 'Username' field is invalid.  Usernames contain no spaces, are between 4 and 60 characters, and can contain only alphanumeric characters, !, *, -, #, and +.";
	var formVar = document.forms[0];
	
	if(!chkNotNull(1,'sUserName,sPassWord,sPassConf'))
	{
		return false;
	}

	formVar.sPassWord.value = trim(formVar.sPassWord.value);
	formVar.sPassConf.value = trim(formVar.sPassConf.value);

	pw_val = formVar.sPassWord.value.toLowerCase();
	pc_val = formVar.sPassConf.value.toLowerCase();
	susernameValue = formVar.sUserName.value.toLowerCase();
	if(susernameValue.length > 60 || susernameValue.length < 4)
	{
		alert(alertUsernameStr);
		formVar.sUserName.focus();						
		return false;
	}
	for(var i=0;i<susernameValue.length;i++)
	{
		if(valid_user.indexOf(susernameValue.charAt(i)) < 0)
		{
			alert(alertUsernameStr );
			formVar.sUserName.focus();			
			return false;
		}
	}


	if(pw_val.length > 50 || pw_val.length < 4)
	{

		alert(alertStr);
		pw_val = '';
		pc_val = '';
		formVar.sPassWord.focus();						
		return false;
	}
		
	for(var i=0;i<pw_val.length;i++)
	{
		if(valid_pw.indexOf(pw_val.charAt(i)) < 0)
		{
			alert(alertStr);
			pw_val = '';
			pc_val = '';
			formVar.sPassWord.focus();			
			return false;
		}
	}
	
	if(pw_val != pc_val)
	{
		alert('The \'Password\' and the \'Confirm Password\' fields do not match.  Please try again.');
		pw_val = '';
		pc_val = '';
		formVar.sPassWord.focus();			
		return false;
	}
	
	return true;

}




/***********************************************************************************
*
*	NAME:		checkSchoolInfo
*	AUTHOR:		shanon levenherz (shanonvl@hotmail.com)
*	DATE:		05.21.2000
*
*	DESCRIPTION:	checks school information page for schoolProfile section.
*
***********************************************************************************/
function checkSchoolInfo()
{

	var alerted = true;
	var formVar = document.forms[0];

	formVar.sSchoolName.value   = trimCapitals(formVar.sSchoolName.value);
	formVar.sAddress1.value 	= trimCapitals(formVar.sAddress1.value);
	formVar.sAddress2.value 	= trimCapitals(formVar.sAddress2.value);
	formVar.sCity.value 		= trimCapitals(formVar.sCity.value);

	alerted = chkNotNull(1,'sSchoolName,sAddress1,sCity,sZip');
	if(alerted)
		alerted = checkZip(formVar.sZip);

// web page address.
// mission statement.
// description of school/schoolSystem.
// neighborhood type.	
	
	return(alerted);
}

/***********************************************************************************
*
*	NAME:	checkContactInfo
*	AUTHOR:	shanon levenherz (shanonvl@hotmail.com)
*	DATE:	05.21.2000
*
*	DESCRIPTION:	checks contact information page for schoolProfile section.
*
***********************************************************************************/
function checkContactInfo()
{

	var alerted = true;
	var formVar = document.forms[0];
	
	if(formVar.sEmail)
	{
		alerted = chkNotNull(1,'sFirstName,sLastName,sPosition,sPhone,sEmail,sNumHiring');
	}
	else
	{
		alerted = chkNotNull(1,'sFirstName,sLastName,sPosition,sPhone');	
	}
	
	if(alerted)
	{
		formVar.sFirstName.value = trimCapitals(formVar.sFirstName.value);
		formVar.sLastName.value = trimCapitals(formVar.sLastName.value);
		formVar.sPosition.value = trimCapitals(formVar.sPosition.value);
		alerted = checkPhone(formVar.sPhone,'Phone');
	}
	
	if(alerted && isNotNull(formVar.sFax))
		alerted = checkPhone(formVar.sFax,'Fax');
	if(alerted && formVar.sEmail)
		alerted = checkEmail(formVar.sEmail);

	// num schools.
	if(alerted && formVar.sNumHiring)
	{
		if(!(parseInt(formVar.sNumHiring.value) > 0))
		{
			alert('You must specify an integer greater than zero in this field.');
			formVar.sNumHiring.focus();
			alerted = false;
		}
		else
		{
			formVar.sNumHiring.value = parseInt(formVar.sNumHiring.value);
		}
	}

	return(alerted);

}


/***********************************************************************************
*
*	NAME:	checkBillingInfo
*	AUTHOR:	shanon levenherz (shanonvl@hotmail.com)
*	DATE:	05.21.2000
*
*	DESCRIPTION: checks billing information page for schoolProfile section
*
***********************************************************************************/
function checkBillingInfo()
{
	var formVar = document.forms[0];
	
	if(!chkNotNull(1,'sPONumber'))
	{
		return false;
	}
	
	var good = confirm('Please confirm your purchase order number:\n\nYou entered: \''+formVar.sPONumber.value+'\'\n\nIf this is correct, click OK.');

	if(!good)
		formVar.sPONumber.focus();

	return(good);	

}

/***********************************************************************************
*
*	NAME:	checkUserProfile
*	AUTHOR:	shanon levenherz (shanonvl@hotmail.com)
*	DATE:	05.21.2000
*
*	DESCRIPTION: checks user profile page for schoolProfile section.
*
***********************************************************************************/
function checkUserProfileold()
{
	var valid_pw = "abcdefghijklmnopqrstuvwxyz1234567890_!*-#+";
	var valid_user = "abcdefghijklmnopqrstuvwxyz1234567890_!*-#+@.";
	var alertStr = "The 'Password' field is invalid.  Passwords contain no spaces, are between 4 and 50 characters, and can contain only alphanumeric characters, !, *, -, #, and +.";
	var alertUsernameStr = "The 'Username' field is invalid.  Usernames contain no spaces, are between 4 and 60 characters, and can contain only alphanumeric characters, !, *, -, #, and +.";
	var formVar = document.forms[0];
	
	if(!chkNotNull(1,'sUserName,sPassWord,sPassConf'))
	{
		return false;
	}

	formVar.sPassWord.value = trim(formVar.sPassWord.value);
	formVar.sPassConf.value = trim(formVar.sPassConf.value);

	pw_val = formVar.sPassWord.value.toLowerCase();
	pc_val = formVar.sPassConf.value.toLowerCase();
	susernameValue = formVar.sUserName.value.toLowerCase();
	if(susernameValue.length > 60 || susernameValue.length < 4)
	{
		alert(alertUsernameStr);
		formVar.sUserName.focus();						
		return false;
	}
	for(var i=0;i<susernameValue.length;i++)
	{
		if(valid_user.indexOf(susernameValue.charAt(i)) < 0)
		{
			alert(alertUsernameStr );
			formVar.sUserName.focus();			
			return false;
		}
	}


	if(pw_val.length > 50 || pw_val.length < 4)
	{

		alert(alertStr);
		pw_val = '';
		pc_val = '';
		formVar.sPassWord.focus();						
		return false;
	}
		
	for(var i=0;i<pw_val.length;i++)
	{
		if(valid_pw.indexOf(pw_val.charAt(i)) < 0)
		{
			alert(alertStr);
			pw_val = '';
			pc_val = '';
			formVar.sPassWord.focus();			
			return false;
		}
	}
	
	if(pw_val != pc_val)
	{
		alert('The \'Password\' and the \'Confirm Password\' fields do not match.  Please try again.');
		pw_val = '';
		pc_val = '';
		formVar.sPassWord.focus();			
		return false;
	}
	
	return true;

}
/***********************************************************************************
*
*	NAME: 	isNotNull(formElem)
*	AUTHOR:	shanon levenherz (shanonvl@hotmail.com)
*	DATE:	05.21.2000
*
*	DESCRIPTION: checks that the input element has a user-input value (length > 0)
*
***********************************************************************************/
function isNotNull(f_var)
{
	f_var.value = trim(f_var.value);
	if(f_var.value.length <= 0)
	{
		return false;
	}
	return true;		
}
/***********************************************************************************
*
*	NAME:		checkZip
*	AUTHOR:		shanon levenherz (shanonvl@hotmail.com)
*	DATE:		05.20.2000
*
*	DESCRIPTION: uses JavaScript regular expressions to check 5 digit zip codes.
*
*	RETURNS:	true if is valid zip code, else false.
*
***********************************************************************************/
function checkZip(c_zip)
{

	var zipExp = /^([0-9]{5})$/;

	if(!zipExp.test(c_zip.value))
	{
		alert('Invalid zip code \''+c_zip.value+'\'\nZip codes must be in 5-digit format: XXXXX');
		c_zip.focus();
		return false;
	}

	return true;
	
}
/***********************************************************************************
*
*	NAME:		checkPhone
*	AUTHOR:		shanon levenherz (shanonvl@hotmail.com)
*	DATE:		05.20.2000
*
*	DESCRIPTION: uses JavaScript regular expressions to check valid phone numbers.
*
*		These formats are valid:  	XXX-XXX-XXXX
*									(XXX)XXX-XXXX
*									XXX.XXX.XXXX
*
*	RETURNS:	true if is valid zip code, else false.
*
***********************************************************************************/
function checkPhone(c_phone,elemName)
{
        var tmpStr = '';
        tmpStr=c_phone.value;

	if (tmpStr.substring(0,1) == '1') 
        {
          c_phone.value=tmpStr.substring(1);
        }
        var phoneExp = (c_phone.value.indexOf('(') > -1) ? /\((\d{3})\)(\d{3})[-.](\d{4})/ : /(\d{3})[-. ]?(\d{3})[-. ]?(\d{4})/;
	
	//trim the values.
	c_phone.value = trim(c_phone.value);
	
	if(!phoneExp.test(c_phone.value))
	{
		alert('The \''+elemName+'\' field is invalid.\nPhone numbers must be formatted as follows:\n555-555-5555');
		c_phone.focus();
		return false;
	}
	else // if there's a match, fix the value how we want it.
	{
		c_phone.value = c_phone.value.replace(phoneExp,"$1-$2-$3");
	}
	return true;
	
}
/***********************************************************************************
*
*	NAME:	checkEmail
*	AUTHOR:	shanon levenherz (shanonvl@hotmail.com)
*	DATE:	05.20.2000
*
*	DESCRIPTION:	uses Javascript regular expressions to check valid email addresses.
*
*		Input is required to have at least the following pattern:
*			alphanumerictext@alphanumerictext.alphanumerictext
*
***********************************************************************************/
function checkEmail(c_email)
{

	var emailExp = /^[\S]+@[\S]+.[\S]+$/;
	
	c_email.value = trim(c_email.value);
	
	if(!emailExp.test(c_email.value))
	{
		alert('The \'Email\' field is invalid.\nEmail addresses must be formatted as follows:\njoesmith@teachers-teachers.com');
		c_email.focus();
		return false;
	}	
	
	return true;
	
}

function checkSchoolInfo2()
{

	var alerted = true;

	document.forms[0].sSchoolName.value = trimCapitals(document.forms[0].sSchoolName.value);
	document.forms[0].sCity.value 		= trimCapitals(document.forms[0].sCity.value);
	document.forms[0].sAddress1.value 	= trimCapitals(document.forms[0].sAddress1.value);
	document.forms[0].sAddress2.value 	= trimCapitals(document.forms[0].sAddress2.value);
	alerted = checkField(document.forms[0].sZip.value,'Zip Code',5,3);
	document.forms[0].sFirstName.value 	= trimCapitals(document.forms[0].sFirstName.value);
	document.forms[0].sLastName.value 	= trimCapitals(document.forms[0].sLastName.value);
	document.forms[0].sPosition.value 	= trimCapitals(document.forms[0].sPosition.value);
	if(alerted == true)
		alerted = checkField(document.forms[0].sPhone.value,'Phone',9,5);
	if(alerted == true)
		alerted = checkField(document.forms[0].sFax.value,'Fax',10,5);
	if(alerted == true)
		alerted = checkField(document.forms[0].sEmail.value,'E-mail',11,4);
	if(alerted == true)
		alerted = checkNotNull(1,"0,1,2,6,7,8,9,11");
		
	return(alerted);
}
