//validate Event Coordinator INTEREST form
function ValidateECIForm()
{
	var sErrorMessage = '';

	var selectedRegionIndex;
	selectedRegionIndex = document.ec_interest_form.preferredRegionCode.selectedIndex;

	var city = document.ec_interest_form.preferredCity.value;

	var selectedStateIndex;
	selectedStateIndex = document.ec_interest_form.preferredState.selectedIndex;


	if (selectedRegionIndex == 0 && city == '' && selectedStateIndex == 0)
		sErrorMessage += "Please select a Preferred Location, or provide a City and State.\n";
	else if (city != '' && selectedStateIndex == 0)
		sErrorMessage += "Please select a state for your preferred City.\n";
	else if (city == '' && selectedStateIndex != 0)
		sErrorMessage += "Please provide your preferred City.\n";
	
	if ((document.ec_interest_form.interest[0].checked != true) && 
		(document.ec_interest_form.interest[1].checked != true) && 
		(document.ec_interest_form.interest[2].checked != true) && 
		(document.ec_interest_form.interest[3].checked != true)) 
		sErrorMessage += "Please select your interest(s).\n"

	if (IsEmpty(document.ec_interest_form.name) == true)
		sErrorMessage += "Please provide your Name.\n";
		
	var re = new RegExp(/^[\w.'-]+@[\w-]+\.([\w.-]+\.\w{2,3}|\w{2,3})$/);
	if (document.ec_interest_form.email.value.match(re) == null)
		sErrorMessage += "Please enter a valid Email Address. It should include your domain name and contain no spaces.\n";

	if (document.ec_interest_form.confirmEmail.value.match(re) == null)
		sErrorMessage += "Please enter a valid Confirm Email Address. It should include your domain name and contain no spaces.\n";

	if (document.ec_interest_form.email.value.toLowerCase != document.ec_interest_form.confirmEmail.value.toLowerCase)
		sErrorMessage += "Email Address and Confirm Email Address do not match.\n";




		
	//output the errors to user		
	if (sErrorMessage != '')
	{ 
		alert ("Please correct the following:\n\n" + sErrorMessage);
		return false;
	}
	else
		return true; 
}


//validate Event Coordinator QUESTIONS form
function ValidateECQForm()
{
	var sErrorMessage = '';

	if (document.ec_question_form.FirstName.value == '')
		sErrorMessage += "Please enter your First Name.\n";

	if (document.ec_question_form.LastName.value == '')
		sErrorMessage += "Please enter your Last Name.\n";

	//phones (at least one required, others optional)
	var HomePhone = document.ec_question_form.HomeArea.value + "-" + document.ec_question_form.HomeExch.value + "-" + document.ec_question_form.HomeLast4.value;
	var WorkPhone = document.ec_question_form.WorkArea.value + "-" + document.ec_question_form.WorkExch.value + "-" + document.ec_question_form.WorkLast4.value;
	var CellPhone = document.ec_question_form.CellArea.value + "-" + document.ec_question_form.CellExch.value + "-" + document.ec_question_form.CellLast4.value;

	if (HomePhone == "--" && WorkPhone == "--" && CellPhone == "--")
			sErrorMessage += "Please provide at least one phone number.\n";

	if (HomePhone != "--"){
		if ((document.ec_question_form.HomeArea.value.length != 3)||(document.ec_question_form.HomeExch.value.length != 3)||(document.ec_question_form.HomeLast4.value.length != 4)||(isNaN(document.ec_question_form.HomeArea.value) == true)||(isNaN(document.ec_question_form.HomeExch.value) == true)||(isNaN(document.ec_question_form.HomeLast4.value) == true))
			sErrorMessage += "Please correct your home phone number.\n";
	}

	if (WorkPhone != "--"){
		if ((document.ec_question_form.WorkArea.value.length != 3)||(document.ec_question_form.WorkExch.value.length != 3)||(document.ec_question_form.WorkLast4.value.length != 4)||(isNaN(document.ec_question_form.WorkArea.value) == true)||(isNaN(document.ec_question_form.WorkExch.value) == true)||(isNaN(document.ec_question_form.WorkLast4.value) == true))
			sErrorMessage += "Please correct your work phone number.\n";
	}

	if (CellPhone != "--"){
		if ((document.ec_question_form.CellArea.value.length != 3)||(document.ec_question_form.CellExch.value.length != 3)||(document.ec_question_form.CellLast4.value.length != 4)||(isNaN(document.ec_question_form.CellArea.value) == true)||(isNaN(document.ec_question_form.CellExch.value) == true)||(isNaN(document.ec_question_form.CellLast4.value) == true))
			sErrorMessage += "Please correct your cell phone number.\n";
	}


	var re = new RegExp(/^[\w.'-]+@[\w-]+\.([\w.-]+\.\w{2,3}|\w{2,3})$/);
	if (document.ec_question_form.email.value.match(re) == null)
		sErrorMessage += "Please enter a valid Email Address. It should include your domain name and contain no spaces.\n";
	if (document.ec_question_form.confirmEmail.value.match(re) == null)
		sErrorMessage += "Please enter a valid Confirm Email Address. It should include your domain name and contain no spaces.\n";
	if (document.ec_question_form.email.value.toLowerCase != document.ec_question_form.confirmEmail.value.toLowerCase)
		sErrorMessage += "Email Address and Confirm Email Address do not match.\n";


	if (document.ec_question_form.address1.value == '')
		sErrorMessage += "Please enter your address.\n";
	
	var expression = "^[0-9]{5}-[0-9]{4}$|^[0-9]{5}$|^[A-Z][0-9][A-Z]\\s[0-9][A-Z][0-9]$|^[A-Z][0-9][A-Z][0-9][A-Z][0-9]$" //regular expression for US zip and Canada zip
	var varPostalExpression = new RegExp(expression); //instatiate new reg expression object
	if (document.ec_question_form.zip.value == '')
		sErrorMessage += "Please enter your ZIP/Postal Code.\n";
	else if (document.ec_question_form.zip.value.toUpperCase.match(varPostalExpression) == null)
		sErrorMessage += "ZIP/Postal Code not valid.\n";


	//timezone
	var timezone = "";
	for (counter = 0; counter < document.ec_question_form.timezone.length; counter++)
		{
		if (document.ec_question_form.timezone[counter].checked)
			timezone = document.ec_question_form.timezone[counter].value; 
		}
	if (timezone == "")
		sErrorMessage += "Please select your time zone.\n";	

	//21 or over
	var oldEnough = "";
	for (counter = 0; counter < document.ec_question_form.old_enough.length; counter++)
		{
		if (document.ec_question_form.old_enough[counter].checked)
			oldEnough = document.ec_question_form.old_enough[counter].value; 
		}
	if (oldEnough == "")
		sErrorMessage += "Please answer Are you 21 years of age or older.\n";	
		
		
		
		
	//hours per month has default selected, no need to validate
	
	//plans to move
	var planToMove = "";
	for (counter = 0; counter < document.ec_question_form.planToMove.length; counter++)
		{
		if (document.ec_question_form.planToMove[counter].checked)
			planToMove = document.ec_question_form.planToMove[counter].value; 
		}
	if (planToMove == "")
		sErrorMessage += "Please answer Do you plan on moving more than 25 miles away.\n";	
	
	//computerAccess
	var computerAccess = "";
	for (counter = 0; counter < document.ec_question_form.computerAccess.length; counter++)
		{
		if (document.ec_question_form.computerAccess[counter].checked)
			computerAccess = document.ec_question_form.computerAccess[counter].value; 
		}
	if (computerAccess == "")
		sErrorMessage += "Please answer Do you have regular access to a computer.\n";	
	
	//businessTravel
	var businessTravel = "";
	for (counter = 0; counter < document.ec_question_form.businessTravel.length; counter++)
		{
		if (document.ec_question_form.businessTravel[counter].checked)
			businessTravel = document.ec_question_form.businessTravel[counter].value; 
		}
	if (businessTravel == "")
		sErrorMessage += "Please answer Do you often travel for business.\n";	

	//publicSpeaking
	//dropdown with default value
//	var publicSpeaking = "";
//	for (counter = 0; counter < document.ec_question_form.publicSpeaking.length; counter++)
//		{
//		if (document.ec_question_form.publicSpeaking[counter].checked)
//			publicSpeaking = document.ec_question_form.publicSpeaking[counter].value; 
//		}
//	if (publicSpeaking == "")
//		sErrorMessage += "Please answer How comfortable are you with public speaking.\n";	

	//willing to use cell phone
	var willingCell = "";
	for (counter = 0; counter < document.ec_question_form.willingCell.length; counter++)
		{
		if (document.ec_question_form.willingCell[counter].checked)
			willingCell = document.ec_question_form.willingCell[counter].value; 
		}
	if (willingCell == "")
		sErrorMessage += "Please answer Are you willing to get/use your cell phone.\n";	

	//can you answer cell during business hours
	var answerCell = "";
	for (counter = 0; counter < document.ec_question_form.answerCell.length; counter++)
		{
		if (document.ec_question_form.answerCell[counter].checked)
			answerCell = document.ec_question_form.answerCell[counter].value; 
		}
	if (answerCell == "")
		sErrorMessage += "Please answer Are you able to answer your cell phone during business hours.\n";	
	
	//can you arrive by 5
	var arriveBy5 = "";
	for (counter = 0; counter < document.ec_question_form.arriveBy5.length; counter++)
		{
		if (document.ec_question_form.arriveBy5[counter].checked)
			arriveBy5 = document.ec_question_form.arriveBy5[counter].value; 
		}
	if (arriveBy5 == "")
		sErrorMessage += "Please answer Can you make it to venues no later than 5pm on event nights.\n";	

	//why are you interested
	if (IsEmpty(document.ec_question_form.whyInterested) == true)
		sErrorMessage += "Please answer Why would you like to be a PreDating Event Coordinator.\n";	

	//characteristics
	//happy 
	var happy = "";
	for (counter = 0; counter < document.ec_question_form.happy.length; counter++)
		{
		if (document.ec_question_form.happy[counter].checked)
			happy = document.ec_question_form.happy[counter].value; 
		}
	if (happy == "")
		sErrorMessage += "Please answer You are a happy person.\n";	

	//friendly and social 
	var friendly = "";
	for (counter = 0; counter < document.ec_question_form.friendly.length; counter++)
		{
		if (document.ec_question_form.friendly[counter].checked)
			friendly = document.ec_question_form.friendly[counter].value; 
		}
	if (friendly == "")
		sErrorMessage += "Please answer You are friendly and social.\n";	

	//charismatic 
	var charismatic = "";
	for (counter = 0; counter < document.ec_question_form.charismatic.length; counter++)
		{
		if (document.ec_question_form.charismatic[counter].checked)
			charismatic = document.ec_question_form.charismatic[counter].value; 
		}
	if (charismatic == "")
		sErrorMessage += "Please answer You are charismatic.\n";	

	//organized 
	var organized = "";
	for (counter = 0; counter < document.ec_question_form.organized.length; counter++)
		{
		if (document.ec_question_form.organized[counter].checked)
			organized = document.ec_question_form.organized[counter].value; 
		}
	if (organized == "")
		sErrorMessage += "Please answer You are organized.\n";	

	//punctual 
	var punctual = "";
	for (counter = 0; counter < document.ec_question_form.punctual.length; counter++)
		{
		if (document.ec_question_form.punctual[counter].checked)
			punctual = document.ec_question_form.punctual[counter].value; 
		}
	if (punctual == "")
		sErrorMessage += "Please answer You are punctual.\n";	

	//resume and photo now required
	if (IsEmpty(document.ec_question_form.resumeText) == true)
		sErrorMessage += "Please provide your resume text in the space provided.\n";
		
	if (IsEmpty(document.ec_question_form.photo) == true)
		sErrorMessage += "Please upload a photo of yourself.\n";
	
	
	//output the errors to user		
	if (sErrorMessage != '')
	{ 
		alert ("Please correct the following:\n\n" + sErrorMessage);
		document.ec_question_form.FirstName.focus();
		return false;
	}
	else return true; 
}



function IsEmpty(field) 
{ 
   for (var m=0; m < field.value.length; m++ ) 
      if ( field.value.charAt(m) != " " ) 
          return false; 
   return true;
}

// take out leading spaces
function Trim(sString)
{
	var iCounter=0;
	var OrigLen=sString.length;	
	while ( (sString.charAt(iCounter)==" ") && (iCounter < sString.length) )
		iCounter++;
	if (iCounter != 0)
		 sString = sString.substring(iCounter,OrigLen);
	while (sString.charAt(sString.length-1)==" ")
		sString=sString.substring(0,sString.length-1)
	return sString;
}


function confirmRadio()
{
	var confidChoice = "";
	for (counter = 0; counter < document.ec_agree_form.electronic_agreement.length; counter++)
		{
		if (document.ec_agree_form.electronic_agreement[counter].checked)
			confidChoice = document.ec_agree_form.electronic_agreement[counter].value; 
		}

	if (confidChoice == "")
	{
		alert("Please select either I AGREE or I DISAGREE before submitting form");	
		return false
	}
	else if (confidChoice == "0") 
	{
		return confirm('Are you sure?\n\nWe would like to discuss this opportunity with you further.  However, unless you agree to the terms of our confidentiality agreement, we cannot go any further in our discussions with you about becoming an Event Coordinator for Cupid.com/PreDating.\n\nClick Cancel to reconsider, or OK to disagree.');
	}
	else return true;
}


function validateSchedule()
{
	var sErrorMessage = "";
	var timeChoice = 0;
	if (document.ec_schedule_form.selectedSlot.length > 0)	
	{
		for (var counter = 0; counter < document.ec_schedule_form.selectedSlot.length; counter++)
		{
		if (document.ec_schedule_form.selectedSlot[counter].checked)
			timeChoice = document.ec_schedule_form.selectedSlot[counter].value; 
		}
	}
	// if a single radio button only
	else
	{	
		if (document.ec_schedule_form.selectedSlot.checked == true) 
			timeChoice = document.ec_schedule_form.selectedSlot.value;
	}
	if (timeChoice == 0)
		sErrorMessage += "Select a time for your phone interview\n";

		
		
	var phoneChoice = 0;

	if (document.ec_schedule_form.phone_number.length > 0)	
	{
		for (var counter = 0; counter < document.ec_schedule_form.phone_number.length; counter++)
		{
		if (document.ec_schedule_form.phone_number[counter].checked)
			phoneChoice = document.ec_schedule_form.phone_number[counter].value; 
		}
	}
	// if a single radio button only
	else
	{	
		if (document.ec_schedule_form.phone_number.checked == true) 
			phoneChoice = document.ec_schedule_form.phone_number.value;
	}

	if (phoneChoice == 0)
		sErrorMessage += "Select a phone number to be called at\n";	

	//output the errors to user		
	if (sErrorMessage != '')
	{ 
		alert ("Please correct the following:\n\n" + sErrorMessage);
		return false;
	}
	else return true; 
}

function confirmRadioContract()
{
	var acceptChoice = "";
	for (counter = 0; counter < document.ec_accept_form.accept_offer.length; counter++)
		{
		if (document.ec_accept_form.accept_offer[counter].checked)
			acceptChoice = document.ec_accept_form.accept_offer[counter].value; 
		}

	if (acceptChoice == "")
	{
		alert("Please select either I AGREE or I DISAGREE before submitting form");	
		return false
	}
	else if (acceptChoice == "5") 
	{
		return confirm('Are you sure?\n\nIf you decline this offer, you forfeit this opportunity immediately.\n\nClick Cancel to reconsider, or OK to decline.');
	}
	else return true;

}

function confirmCancel()
{
	if (confirm('Are you sure you want to cancel this interview? Click OK to continue, or Cancel to keep as scheduled') == true)
	{
		document.ec_schedule_form.step.value = 'cancel';
		document.ec_schedule_form.submit();
		return true;
	}
	
}

function ShowCharactersLeft(box,id,maxchars)
{

	var num = maxchars - box.value.length;
	if(num < 0)
	{
		num = 0;
		box.value = box.value.substring(0,maxchars);
		return false;
	}

	var o = document.getElementById(id);
	var str = ''
	
	if(num == 1)
		{str = num + ' character left.';}
	else
		{str = num + ' characters left.';}
		
	if(num < 10)
		{o.innerHTML = '<span class="small"><font style="color:#CC0066;">' + str + '</font></span>';}
	else if(num < 20)
		{o.innerHTML = '<span class="small"><font style="color:#FF9933;">' + str + '</font></span>';}
	else
		{o.innerHTML = '<span class="small">' + str + '</span>';}
		
}
