/*
@function 	= 	chooseAgent()
@purpose 	= 	display form fields for Agent Registration
@parameters = 	
@returns	= 	void
@usage		=	chooseAgent()
*/
function chooseAgent()
{
	clearLabels("userRegistration"); displayObject("customerRegistration", 0); displayObject("agentRegistration", 1); displayObject("agentRegistrationInfo", 1);
	displayObject("customerError", 0); displayObject("agentError", 0); setMessage("regError", ""); setMessage("customerError", ""); setMessage("agentError", "");
	document.userRegistration.reset(); document.userRegistration.whichRegistration[0].checked = true;
}
/*
@function 	= 	chooseCustomer()
@purpose 	= 	display form fields for Customer Registration
@parameters = 	
@returns	= 	void
@usage		=	chooseCustomer()
*/
function chooseCustomer()
{
	clearLabels("userRegistration"); displayObject("customerRegistration", 1); displayObject("agentRegistration", 0); displayObject("agentRegistrationInfo", 0);
	displayObject("customerError", 0); displayObject("agentError", 0); setMessage("regError", ""); setMessage("customerError", ""); setMessage("agentError", "");
	document.userRegistration.reset(); document.userRegistration.whichRegistration[1].checked = true;
}
/*
@function 	= 	validateRegistration()
@purpose 	=  	validation registration based on selected user type
@parameters = 	
@returns	= 	boolean
@usage		=	validateRegistration()
*/
function validateRegistration()
{
	var f = document.userRegistration; var err = ""; var isAgent = false; var isCustomer = false;
	
	clearLabels("userRegistration"); setMessage("regError", ""); setMessage("agentError", ""); setMessage("customerError", ""); displayObject("regError", 0);
	
	if (f.whichRegistration[0].checked) { isAgent = true; } 
	else if (f.whichRegistration[1].checked) { isCustomer = true; }
	else { setMessage("regError", "Please select a type of User."); displayObject("regError", 1); return false; }
	
	if (isAgent) { err = validateAgent(); if (err != "") { setMessage("agentError", err); displayObject("agentError", 1); return false; } }
	if (isCustomer) { err = validateCustomer(); if (err != "") { setMessage("customerError", err); displayObject("customerError", 1); return false; } }
	
	return true;
}
/*
@function 	= 	validateAgent()
@purpose 	=  	validate agent registration fields
@parameters = 	
@returns	= 	string
@usage		=	validateAgent()
*/
function validateAgent()
{
	var f = document.userRegistration; var err = ""; var validUser = true;
	
	if (f.agentUserID.value == "") { validUser = false; errorLabel("lblAgentUserID", 1); }
	else { if (f.agentUserID.value < 4) { err += "Please select another user ID. User IDs must contain at least 4 characters.<br />"; validUser = false; errorLabel("lblAgentUserID", 1); } }
	
	if (f.agentAgencyCode.value == "") { validUser = false; errorLabel("lblAgentAgencyCode", 1); }
	if (f.agentTaxID.value == "") { validUser = false; errorLabel("lblAgentTaxID", 1); }
	if (f.agentContactName.value == "") { validUser = false; errorLabel("lblAgentContactName", 1); }
	if (f.agentPhone.value == "") { validUser = false; errorLabel("lblAgentPhone", 1); }
	if (f.agentPassword.value == "") { validUser = false; errorLabel("lblAgentPassword", 1); }
	if (f.agentConfirmPassword.value == "") { validUser = false; errorLabel("lblAgentConfirmPassword", 1); }
	if ((f.agentPassword.value != "") && (f.agentConfirmPassword.value != "")) 
	{ 
		if (f.agentPassword.value != f.agentConfirmPassword.value) 
		{ 
			err += "The passwords do not match. ";
			validUser = false; errorLabel("lblAgentPassword", 1); errorLabel("lblAgentConfirmPassword", 1);
		}
	}
	if (!validUser) { err += "Please correct the items in red below."; }
	return err;
}
/*
@function 	= 	validateCustomer()
@purpose 	=  	validate customer registration fields
@parameters = 	
@returns	= 	string
@usage		=	validateCustomer()
*/
function validateCustomer()
{
	var f = document.userRegistration; var err = ""; var bDay = ""; var goodBirthDate = true; var validUser = true;
	
	if (f.customerFirstName.value == "") { validUser = false; errorLabel("lblCustomerFirstName", 1); }
	if (f.customerLastName.value == "") { validUser = false; errorLabel("lblCustomerLastName", 1); }
	if (f.customerZipCode.value == "") { validUser = false; errorLabel("lblCustomerZipCode", 1); }
	if (f.customerPolicyNumber.value == "") { validUser = false; errorLabel("lblCustomerPolicyNumber", 1); }
	else { if (!checkPolicyFormat(f.customerPolicyNumber.value)) { err += "Please enter a valid policy number.<br />"; validUser = false; errorLabel("lblCustomerPolicyNumber", 1); } }
	
	if (f.customerDriverLicense.value == "") { validUser = false; errorLabel("lblCustomerDriverLicense", 1); }
	
	if (f.customerDateOfBirth.value == "") { goodBirthDate = false; } 
	else 
	{
		myDate = f.customerDateOfBirth.value; myDateParts = myDate.split("/");
		
		if (myDateParts.length != 3) { goodBirthDate = false; }
		else 
		{
			m = myDateParts[0]; d = myDateParts[1]; y = myDateParts[2];
			
			if ((isNaN(m)) || (isNaN(d)) || (isNaN(y))) { goodBirthDate = false; }
			else if (!validateSplitDate(m, d, y)) { goodBirthDate = false; }
			else { bDay = new Date(y, m, d); today = new Date(); if (today < bDay) { goodBirthDate = false; } }
		}
	}
	
	if (!goodBirthDate) { validUser = false; errorLabel("lblCustomerDateOfBirth", 1); }
	if (f.customerUserID.value == "") { validUser = false; errorLabel("lblCustomerUserID", 1); }
	else { if (f.customerUserID.value.length < 4) { err += "Please select another user ID. User IDs must contain at least 4 characters.<br />"; validUser = false; errorLabel("lblCustomerUserID", 1); } }
	if (f.customerPassword.value == "") { validUser = false; errorLabel("lblCustomerPassword", 1); }
	if (f.customerConfirmPassword.value == "") { validUser = false; errorLabel("lblCustomerConfirmPassword", 1); }
	if ((f.customerPassword.value != "") && (f.customerConfirmPassword.value != ""))
	{
		if (f.customerPassword.value != f.customerConfirmPassword.value)
		{
			err += "The passwords do not match. ";
			validUser = false; errorLabel("lblCustomerPassword", 1); errorLabel("lblCustomerConfirmPassword", 1);
		}
	}
	if (!validUser) { err += "Please correct the items in red below."; }
	return err;
}