/* =================================================================================
	Created by B Bisgard after creators of the JS sitewide.
	This "template specific IsFormValid" routine is designed to pull all javascript off 
	the pages and in here.  
	Most of these routines call the overall mohincformValidation.js file.
	
	A list of functions that have moved here are included for easy indexing:
	
	isQuickAddFormValid()
	isFormF280Valid()
	isFormF340Valid()
	isFormF341Valid()
	isFormI730Valid()
	isFormL800Valid()
	isFormL830Valid()
	isFormP366Valid()
	isFormP420Valid()
	isFormP324Valid()
	
	Revision:
	
	11/15/00 Meddie : Added form validation for Move Organizer (MOH324)
	
*/

function isQuickAddFormValid(formName)	{

	validateText(formName, 'txtTitle', 0, 1, 45, 'Task Title');
	
}

function isFormF280Valid(formName)	{

	validateText(formName, 'acctFname', 0, 1, 50, 'First Name');
	validateText(formName, 'acctLname', 0, 1, 50, 'Last Name');
	validateText(formName, 'acctPassword', 0, 4, 25, 'Password');
		validateEmail(document.form.acctEmailAddress.value, '');
	
	
	if (document.form.acctSecretQuestion.value == "") {
		isValid = false ;
		errMsg += "\r" + "You must enter a Secret Question.";	
	}

	if (document.form.acctQuestionResponse.value == "") {
		isValid = false ;
		errMsg += "\r" + "You must enter a Question Response.";	
	}
	
	// Check password confirmation
	if (!isEqual(document.form.acctPassword.value, document.form.acctPasswordConfirm.value))	{
		isValid = false ;
		errMsg += "\r" + "Confirm Your Password";
	}

	// Check email confirmation
	if (!isEqual(document.form.acctEmailAddress.value, document.form.acctEmailAddressConfirm.value))	{
		isValid = false ;
		errMsg += "\r" + "Confirm Your Email Address";
	}

	if (errMsg != "")	alert (errMsgHead + errMsg);
	return isValid;
}

function isFormF340Valid(formName)	{

	var form = eval("document." + formName);
	var now = new Date();
	var mmInDate = now.getMonth() + 1;
	var ddInDate = now.getDate();
	var yyInDate = now.getFullYear();
	var mmOutDate = form.mmOutDate.value;
	var ddOutDate = form.ddOutDate.value;
	var yyOutDate = eval(parseInt(form.yyOutDate.value) + 2000);
	
	var inDate = new Date(yyInDate, mmInDate, ddInDate);
	var outDate = new Date(yyOutDate, mmOutDate, ddOutDate);

	if (inDate >= outDate) {
		errMsg = "The date entered is invalid or is earlier than today!";
		isValid = false;
	}
	
	if ((mmOutDate == "") || (ddOutDate == "") || (yyOutDate == ""))	{
		errMsg = "You must enter a move out date!";
		isValid = false;
	} 

	if (errMsg != "")	alert (errMsgHead + errMsg);
	return isValid;
}

function isFormF341Valid(formName)	{

	var form = eval("document." + formName);
	var now = new Date();
	var mmInDate = form.mmInDate.value;
	var ddInDate = form.ddInDate.value;
	var yyInDate = eval(parseInt(form.yyInDate.value) + 2000);
	var mmOutDate = now.getMonth() + 1;
	var ddOutDate = now.getDate();
	var yyOutDate = now.getFullYear();
	
	var inDate = new Date(yyInDate, mmInDate, ddInDate);
	var outDate = new Date(yyOutDate, mmOutDate, ddOutDate);

	if (inDate <= outDate) {
		errMsg = "The date entered is invalid or is earlier than today!";
		isValid = false;
	}
	
	if ((mmOutDate == "") || (ddOutDate == "") || (yyOutDate == ""))	{
		errMsg = "You must enter a move out date!";
		isValid = false;
	} 

	if (errMsg != "")	alert (errMsgHead + errMsg);
	return isValid;
}

function isFormI730Valid(formName)	{

	validateText(formName, 'txtSqr', 1, 0, 5, 'Square footage')
	validateText(formName, 'txtAdults', 2, 1, 2, 'Adults')
	validateText(formName, 'txtChildren', 1, 0, 2, 'Children')
	validateText(formName, 'txtBeds', 1, 0, 2, 'Bedrooms')
	validateText(formName, 'txtRooms', 1, 0, 2, 'Other rooms')
	validateText(formName, 'txtStories', 1, 0, 2, 'Stories')
	validateText(formName, 'txtAutos', 1, 0, 2, 'Autos')
	validateText(formName, 'txtBoats', 1, 0, 2, 'Boat')
	validateText(formName, 'txtMotorcycles', 1, 0, 2, 'Motorcycles')
	validateText(formName, 'txtPianos', 1, 0, 2, 'Pianos')
	validateText(formName, 'txtBicycle', 1, 0, 2, 'Bicycle')
	validateText(formName, 'txtAppliance', 1, 0, 2, 'Large appliance')

	validateDate(formName, 'mmOutDate', 1, 'Move Out Month')
	validateDate(formName, 'ddOutDate', 2, 'Move Out Day')
	validateDate(formName, 'yyOutDate', 3, 'Move Out Year')
	validateDate(formName, 'mmInDate', 1, 'Move In Month')
	validateDate(formName, 'ddInDate', 2, 'Move In Day')
	validateDate(formName, 'yyInDate', 3, 'Move In Year')

	var form = eval("document." + formName);
	var mmInDate = form.mmInDate.value;
	var ddInDate = form.ddInDate.value;
	var yyInDate = eval(parseInt(form.yyInDate.value) + 2000);
	var mmOutDate = form.mmOutDate.value;
	var ddOutDate = form.ddOutDate.value;
	var yyOutDate = eval(parseInt(form.yyOutDate.value) + 2000);
	
	var inDate = new Date(yyInDate, mmInDate, ddInDate);
	var outDate = new Date(yyOutDate, mmOutDate, ddOutDate);

//if (inDate > outDate)	m = "good";
	if (inDate <= outDate) {
		errMsg = "Your Move Out Date is later than your Move In Date!";
		isValid = false;
	}

	if (errMsg != "")	alert (errMsgHead + errMsg);
	return isValid;
}

function isFormL800Valid(formName)	{

	validateEmail(document.form.txtEmailAddress.value, '');
	validateText(formName, 'txtPassword', 0, 4, 25, 'Password');

	if (errMsg != "")	alert (errMsgHead + errMsg);
	return isValid;
}

function isFormL830Valid(formName)	{
	var CurrentPassword = eval("document." + formName + ".txtPassword.value");
	var NewPasswordA = eval("document." + formName + ".txtNewPassword.value");
	var NewPasswordB = eval("document." + formName + ".txtRNewPassword.value");
	var NewPasswordHint = eval("document." + formName + ".txtPasswordHint.value");

	// New password must match
	if (!isEqual(NewPasswordA,NewPasswordB)) { isValid = false ; errMsg += "\r" + "Please confirm your new password";}
	// New password cannot be the same as the old one
	if (isEqual(CurrentPassword, NewPasswordA)) { isValid = false ; errMsg += "\r" + "The new password must be different than the current one";}
	
	validateText(formName, 'txtPassword', 0, 4, 25, 'Password');
	validateText(formName, 'txtNewPassword', 0, 4, 25, 'New Password');
	validateText(formName, 'txtPasswordHint', 0, 1, 40, 'Password Hint');

	if (errMsg != "")	alert (errMsgHead + errMsg);
	return isValid;
}

function isFormP366Valid(formName)	{

	var roomIndex = getSelectedIndex('cmbRoom');
	var itemIndex = getSelectedIndex('cmbItem');
	var locationIndex = getSelectedIndex('cmbLocation');
	var roomName = getSelectedName('cmbRoom',roomIndex);
	var itemID = getSelectedName('cmbItem',itemIndex);
	var locationID = getSelectedName('cmbLocation',locationIndex);
	
	if (roomName == "" || itemID == "" || locationID == "")	{ isValid = false ; errMsg += "\r" + "Please provide Room, Item and Location information";}

	validateText(formName, 'txtWeight', 0, 1, 5, 'Weight');

	if (errMsg != "")	alert (errMsgHead + errMsg);
	return isValid;
}

function isFormP420Valid(formName)	{
	validateText(formName, 'txtFirstName', 0, 1, 30, 'First Name');
	validateText(formName, 'txtLastName', 0, 1, 30, 'Last Name');
	
	var email = eval('document.' + formName + ".txtEmail.value");
	if (email.length > 0) {
		validateEmail(email, '');
	}
	else {
		isValid = false ; 
		errMsg += "\r" + "Email address cannot be blank.";
	}
	
	var phone = eval('document.' + formName + ".txtHomePhone.value");
	if (phone.length > 0) {
		if (!isValidPhoneNumber(phone))	{ 
			isValid = false ; 
			errMsg += "\r" + "Invalid Home Phone Number";
		}
	}
	else {
		isValid = false ; 
		errMsg += "\r" + "Home Phone number cannot be blank.";
	}
	
	if (errMsg != "")	alert (errMsgHead + errMsg);
	return isValid;
}

function isFormP324Valid(formName) {
	validateText(formName, 'numAdults', 1, 1, 99, 'Number of Adults');
	validateText(formName, 'numChildren', 1, 1, 99, 'Number of Children');
	
	validateDate(formName, 'mmOutDate', 1, 'Move Out Month')
	validateDate(formName, 'ddOutDate', 2, 'Move Out Day')
	validateDate(formName, 'yyOutDate', 3, 'Move Out Year')
	validateDate(formName, 'mmInDate', 1, 'Move In Month')
	validateDate(formName, 'ddInDate', 2, 'Move In Day')
	validateDate(formName, 'yyInDate', 3, 'Move In Year')
	
	var form = eval("document." + formName);
	var mmInDate = form.mmInDate.value;
	var ddInDate = form.ddInDate.value;
	var yyInDate = eval(parseInt(form.yyInDate.value) + 2000);
	var mmOutDate = form.mmOutDate.value;
	var ddOutDate = form.ddOutDate.value;
	var yyOutDate = eval(parseInt(form.yyOutDate.value) + 2000);
	
	var inDate = new Date(yyInDate, mmInDate, ddInDate);
	var outDate = new Date(yyOutDate, mmOutDate, ddOutDate);

//if (inDate > outDate)	m = "good";
	if (inDate <= outDate) {
		errMsg = "Your Move Out Date is later than your Move In Date!";
		isValid = false;
	}
		
	var CurZip = eval('document.' + formName + '.txtCurZip.value');
	if (!isValidZipCode(CurZip) || CurZip == "") { isValid = false ; errMsg += "\r" + "Current Zip Code is Invalid";}
	
	var DestZip = eval('document.' + formName + '.txtDestZip.value');
	if (!isValidZipCode(DestZip) || DestZip == "") { isValid = false ; errMsg += "\r" + "Destination Zip Code is Invalid";}

	if (errMsg != "")	alert (errMsgHead + errMsg);
	return isValid;
}

