// Reset the form
function init()
{
	document.getElementById('contactform').reset();
}

// Validates that the required dropdowns have been selected before submission
/*updated Aug 26/08 by Dave McVittie: Removing required fields as client requested*/
function checkDropdownsPublic()
{
	msg = "";

    if (document.forms[0].salutation.value == "")
	{
		msg = msg + "You must enter a salutation to continue\n";
	}
	if (document.forms[0].firstname.value == "")
	{
		msg = msg + "You must enter a first name to continue\n";
	}
	if (document.forms[0].lastname.value == "")
	{
		msg = msg + "You must enter a last name to continue\n";
	}
	if (document.forms[0].companyname.value == "")
	{
		msg = msg + "You must enter a company name to continue\n";
	}
	if (document.forms[0].address1.value == "")
	{
		msg = msg + "You must enter an address to continue\n";
	}
	if (document.forms[0].city.value == "")
	{
		msg = msg + "You must enter a city to continue\n";
	}
	if (document.forms[0].state_province.selectedIndex == 0)
	{
		msg = msg + "You must select a state/province from the dropdown to continue\n";
	}	
	if (document.forms[0].zip_postalcode.value == "")
	{
		msg = msg + "You must enter a zip/postal code to continue\n";
	}
	/*if (document.forms[0].country.selectedIndex == 0)
	{
		msg = msg + "You must select a country from the dropdown to continue\n";
	}*/	
	if (document.forms[0].email.value == "")
	{
		msg = msg + "You must enter an email to continue\n";
	}
	if (document.forms[0].phone.value == "")
	{
		msg = msg + "You must enter a contact phone number to continue\n";
	}
	
	/* prospective project location*/
	checkObj_sameaddress = document.contactform["sameaddress"];
	if (checkObj_sameaddress.checked==false){
	    if (document.forms[0].property_address1.value == "")
    	{
    		msg = msg + "You must enter the prospective project address to continue\n";
    	}
	    if (document.forms[0].property_city.value == "")
    	{
    		msg = msg + "You must enter the prospective project city to continue\n";
    	}
    	if (document.forms[0].property_state_province.selectedIndex == 0)
    	{
    		msg = msg + "You must enter the prospective project state to continue\n";
    	}
    	if (document.forms[0].property_country.value == "")
    	{
    		msg = msg + "You must enter the prospective project country to continue\n";
    	}
	}
	
	if (document.forms[0].primarybrand.selectedIndex == 0)
	{
		msg = msg + "You must select a primary brand of interest from the dropdown to continue\n";
	}
	radioObj_everOwnedFranchise = document.contactform["everOwnedFranchise"];
	if (radioObj_everOwnedFranchise[0].checked == false && radioObj_everOwnedFranchise[1].checked == false)
	{
		msg = msg + "You must answer whether you have ever owned a hotel franchise to continue\n";
	}
	radioObj_everOwnedHotel = document.contactform["everOwnedHotel"];
	if (radioObj_everOwnedHotel[0].checked == false && radioObj_everOwnedHotel[1].checked == false && radioObj_everOwnedHotel[2].checked == false)
	{
		msg = msg + "You must answer whether you currently or have ever owned a hotel/motel to continue\n";
	}
	if (document.forms[0].role.selectedIndex == 0)
	{
		msg = msg + "You must select a role from the dropdown to continue\n";
	}
	radioObj_everDoneCendantBusiness = document.contactform["everDoneCendantBusiness"];
	if (radioObj_everDoneCendantBusiness[0].checked == false && radioObj_everDoneCendantBusiness[1].checked == false)
	{
		msg = msg + "You must enter if you have done buisness with Wyndham Worldwide before to continue\n";
	}
	radioObj_propertyType = document.contactform["propertyType"];
	if (radioObj_propertyType[0].checked == false && radioObj_propertyType[1].checked == false)
	{
		msg = msg + "You must enter whether you are interested in new construction or converting an existing property to continue\n";
	}
	radioObj_ownership = document.contactform["ownership"];
	if (radioObj_propertyType[0].checked == true && radioObj_ownership[0].checked == false && radioObj_ownership[1].checked == false)
	{
		msg = msg + "You must enter if you currently own a hotel or land for your converting existing property to continue\n";
	}
	if (document.forms[0].capital.selectedIndex == 0)
	{
		msg = msg + "You must enter how much capital do you have to invest from the dropdown to continue\n";
	}
	if (document.forms[0].investmentTimeframe.selectedIndex == 0)
	{
		msg = msg + "You must enter an investment timeframe from the dropdown to continue\n";
	}	
	
	if (msg == "")
	{
		return true;
	}
	else
	{
		alert(msg);
		return false;
	}
}

// Validates that the required dropdowns have been selected before submission
// Edited by Dave McVittie on Aug 26/08 to remove field requirements as the client requested
// Edited by Dave McVittie on Sept 24/08 to add new fields for prospective project location address
function checkDropdownsInternal()
{
	msg = "";
	
	if (document.forms[0].lead_source.selectedIndex == 0)
	{
		msg = msg + "You must select the lead source from the dropdown to continue\n";
	}
	/*if (document.forms[0].lead_source.selectedIndex == 10 || document.forms[0].lead_source.selectedIndex == 1)
	{
		if (document.forms[0].periodical.selectedIndex == 0)
		{
			msg = msg + "You must select a periodical from the dropdown to continue\n";
		}
	}*/
	if (document.forms[0].salutation.value == "")
	{
		msg = msg + "You must enter a salutation to continue\n";
	}
	if (document.forms[0].firstname.value == "")
	{
		msg = msg + "You must enter a first name to continue\n";
	}
	if (document.forms[0].lastname.value == "")
	{
		msg = msg + "You must enter a last name to continue\n";
	}
	/*if (document.forms[0].companyname.value == "")
	{
		msg = msg + "You must enter a company name to continue\n";
	}*/
	if (document.forms[0].address1.value == "")
	{
		msg = msg + "You must enter an address to continue\n";
	}
	if (document.forms[0].city.value == "")
	{
		msg = msg + "You must enter a city to continue\n";
	}
	if (document.forms[0].state_province.selectedIndex == 0)
	{
		msg = msg + "You must select a state/province from the dropdown to continue\n";
	}	
	/*if (document.forms[0].zip_postalcode.value == "")
	{
		msg = msg + "You must enter a zip/postal code to continue\n";
	}*/
	/*if (document.forms[0].country.selectedIndex == 0)
	{
		msg = msg + "You must select a country from the dropdown to continue\n";
	}	*/
	/*if (document.forms[0].email.value == "")
	{
		msg = msg + "You must enter an email to continue\n";
	}*/
	if (document.forms[0].phone.value == "")
	{
		msg = msg + "You must enter a contact phone number to continue\n";
	}
    if (document.forms[0].ref_firstname.value == "")
	{
		msg = msg + "You must enter the referrer's first name to continue\n";
	}
	if (document.forms[0].ref_lastname.value == "")
	{
		msg = msg + "You must enter the referrer's last name to continue\n";
	}
	if (document.forms[0].ref_phone.value == "")
	{
		msg = msg + "You must enter the referrer's phone number to continue\n";
	}
	/*if (document.forms[0].ref_email.value == "")
	{
		msg = msg + "You must enter the referrer's email to continue\n";
	}*/
	if (document.forms[0].primarybrand.selectedIndex == 0)
	{
		msg = msg + "You must select a primary brand of interest from the dropdown to continue\n";
	}
	
	/* prospective project location*/
	checkObj_sameaddress = document.contactform["sameaddress"];
	if (checkObj_sameaddress.checked==false){ 
	    if (document.forms[0].property_address1.value == "")
    	{
    		msg = msg + "You must enter the prospective project address to continue\n";
    	}
	    if (document.forms[0].property_city.value == "")
    	{
    		msg = msg + "You must enter the prospective project city to continue\n";
    	}
    	if (document.forms[0].property_state_province.selectedIndex == 0)
    	{
    		msg = msg + "You must enter the prospective project state to continue\n";
    	}
    	if (document.forms[0].property_country.value == "")
    	{
    		msg = msg + "You must enter the prospective project country to continue\n";
    	}
	}
	

	/*radioObj_everOwnedFranchise = document.contactform["everOwnedFranchise"];
	if (radioObj_everOwnedFranchise[0].checked == false && radioObj_everOwnedFranchise[1].checked == false)
	{
		msg = msg + "You must answer whether you have ever owned a hotel franchise to continue\n";
	}	
	radioObj_everOwnedHotel = document.contactform["everOwnedHotel"];
	if (radioObj_everOwnedHotel[0].checked == false && radioObj_everOwnedHotel[1].checked == false && radioObj_everOwnedHotel[2].checked == false)
	{
		msg = msg + "You must answer whether you currently or have ever owned a hotel/motel to continue\n";
	}
	if (document.forms[0].role.selectedIndex == 0)
	{
		msg = msg + "You must select a role from the dropdown to continue\n";
	}
	radioObj_everDoneCendantBusiness = document.contactform["everDoneCendantBusiness"];
	if (radioObj_everDoneCendantBusiness[0].checked == false && radioObj_everDoneCendantBusiness[1].checked == false)
	{
		msg = msg + "You must enter if you have done business with Wyndham Worldwide before to continue\n";
	}*/
	radioObj_propertyType = document.contactform["propertyType"];
	if (radioObj_propertyType[0].checked == false && radioObj_propertyType[1].checked == false && radioObj_propertyType[2].checked == false)
	{
		msg = msg + "You must enter whether you are interested in new construction or converting an existing property to continue\n";
	}
	radioObj_ownership = document.contactform["ownership"];
	if (radioObj_ownership[0].checked == false && radioObj_ownership[1].checked == false && radioObj_ownership[2].checked == false)
	{
		msg = msg + "You must enter if you currently own a hotel or land for your converting existing property to continue\n";
	}
	
	
	/*if (document.forms[0].investmentTimeframe.selectedIndex == 0)
	{
		msg = msg + "You must enter an investment timeframe from the dropdown to continue";
	}*/
	
	if (msg == "")
	{
		return true;
	}
	else
	{
		alert(msg);
		return false;
	}
}

// Validates that the required dropdowns have been selected before submission for contact_callcenter.cfm
// Edited by Dave Mcvittie on Aug 26/08 to remove field requirements as the client requested
function checkDropdownsCallCenter()
{
	msg = "";
	
	if (document.forms[0].lead_source.selectedIndex == 0)
	{
		msg = msg + "You must select the lead source from the dropdown to continue\n";
	}
	if (document.forms[0].salutation.value == "")
	{
		msg = msg + "You must enter a salutation to continue\n";
	}
	if (document.forms[0].lead_source.selectedIndex == 10 || document.forms[0].lead_source.selectedIndex == 1)
	{
		if (document.forms[0].periodical.selectedIndex == 0)
		{
			msg = msg + "You must select a periodical from the dropdown to continue\n";
		}
	}
	if (document.forms[0].firstname.value == "")
	{
		msg = msg + "You must enter a first name to continue\n";
	}
	if (document.forms[0].lastname.value == "")
	{
		msg = msg + "You must enter a last name to continue\n";
	}
	if (document.forms[0].companyname.value == "")
	{
		msg = msg + "You must enter a company name to continue\n";
	}
	if (document.forms[0].address1.value == "")
	{
		msg = msg + "You must enter an address to continue\n";
	}
	if (document.forms[0].city.value == "")
	{
		msg = msg + "You must enter a city to continue\n";
	}
	if (document.forms[0].state_province.selectedIndex == 0)
	{
		msg = msg + "You must select a state/province from the dropdown to continue\n";
	}	
	if (document.forms[0].zip_postalcode.value == "")
	{
		msg = msg + "You must enter a zip/postal code to continue\n";
	}
	/*if (document.forms[0].country.selectedIndex == 0)
	{
		msg = msg + "You must select a country from the dropdown to continue\n";
	}	*/
	if (document.forms[0].email.value == "")
	{
		msg = msg + "You must enter an email to continue\n";
	}
	if (document.forms[0].phone.value == "")
	{
		msg = msg + "You must enter a contact phone number to continue\n";
	}
	if (document.forms[0].primarybrand.selectedIndex == 0)
	{
		msg = msg + "You must select a primary brand of interest from the dropdown to continue\n";
	}
	

	radioObj_everOwnedFranchise = document.contactform["everOwnedFranchise"];
	if (radioObj_everOwnedFranchise[0].checked == false && radioObj_everOwnedFranchise[1].checked == false)
	{
		msg = msg + "You must answer whether you have ever owned a hotel franchise to continue\n";
	}	
	radioObj_everOwnedHotel = document.contactform["everOwnedHotel"];
	if (radioObj_everOwnedHotel[0].checked == false && radioObj_everOwnedHotel[1].checked == false && radioObj_everOwnedHotel[2].checked == false)
	{
		msg = msg + "You must answer whether you currently or have ever owned a hotel/motel to continue\n";
	}
	if (document.forms[0].role.selectedIndex == 0)
	{
		msg = msg + "You must select a role from the dropdown to continue\n";
	}
	radioObj_everDoneCendantBusiness = document.contactform["everDoneCendantBusiness"];
	if (radioObj_everDoneCendantBusiness[0].checked == false && radioObj_everDoneCendantBusiness[1].checked == false)
	{
		msg = msg + "You must enter if you have done business with Wyndham Worldwide before to continue\n";
	}
	radioObj_propertyType = document.contactform["propertyType"];
	if (radioObj_propertyType[0].checked == false && radioObj_propertyType[1].checked == false)
	{
		msg = msg + "You must enter whether you are interested in new construction or converting an existing property to continue\n";
	}
	radioObj_ownership = document.contactform["ownership"];
	if (radioObj_propertyType[0].checked == true && radioObj_ownership[0].checked == false && radioObj_ownership[1].checked == false)
	{
		msg = msg + "You must enter if you currently own a hotel or land for your converting existing property to continue\n";
	}
	if (document.forms[0].capital.selectedIndex == 0)
	{
		msg = msg + "You must enter how much capital do you have to invest from the dropdown to continue\n";
	}	
	if (document.forms[0].investmentTimeframe.selectedIndex == 0)
	{
		msg = msg + "You must enter an investment timeframe from the dropdown to continue";
	}
	
	if (msg == "")
	{
		return true;
	}
	else
	{
		alert(msg);
		return false;
	}
}

function checkState_province()
{
	/*stateSelectBox = document.forms[0].state_province;
	stateChosen = stateSelectBox.options[stateSelectBox.selectedIndex].value;

	countrySelectBox = document.forms[0].country;
	countryChosen = countrySelectBox.options[countrySelectBox.selectedIndex].value;
	
	if (stateChosen == "N/A" && (countryChosen == "USA" || countryChosen == "CA") ){
		alert("Please choose a State/Province in order to continue");
		return false;
	} else {
		return true;	
	}*/
	
	// I've taken this part out since country/state is no longer a mantitory field, if it ever becomes one then uncomment the above
	return true;
}

function checkEmail()
{
	/*emailValue = document.contactform["email"].value;
				
	if (emailValue == "" && document.contactform["subscriptions"].checked == true)
	{
		alert("Please enter an email for notifications in order to continue");
		return false;
	}
	else
	{
		return true;
	}*/
	
	// TAS (April 28): We now check for email in all cases so moved check to general checking function above
	return true;
}

// runs when the lead source
function lead_source_changed()
{
	// If its call center or periodicals then show the periodicals dropdown.
	if(document.contactform["lead_source"].selectedIndex == 1 || document.contactform["lead_source"].selectedIndex == 10)
	{
		document.getElementById("periodical_section").style.display = "block";
		document.getElementById("periodical_label").style.display = "block";
	}
	else
	{
		document.getElementById("periodical_section").style.display = "none";
		document.getElementById("periodical_label").style.display = "none";
	}
}

// runs when the primary brand interest changes
function primarybrand_changed()
{
	if(document.contactform["primarybrand"].selectedIndex > 0)
	{
		update_secondarybrand_area(document.contactform["primarybrand"].selectedIndex);
		document.getElementById("secondarybrand_area").style.display = "block";
	}
	else
	{
		document.getElementById("secondarybrand_area").style.display = "none";
	}
}

// runs when question 2 response changes
function q2_changed()
{
	radioObj = document.contactform["everOwnedFranchise"];
	if(radioObj[0].checked)
	{
		document.getElementById("q2yes").style.display = "block";
	}
	else
	{
		document.contactform["everOwnedFranchiseDetails"].value = "";
		document.getElementById("q2yes").style.display = "none";
	}
}


/*  Added by Dave McVittie, 25/09/08 */
// runs when question 2's check box is changed on the internal page
// remove or add the fields based on whether you are selecting the same address as above or not
function q2_changed_internal()
{
	checkObj = document.contactform["sameaddress"];
	if(checkObj.checked)
	{
	    
		document.getElementById("different_address").style.display = "none";
	}
	else
	{
		document.getElementById("different_address").style.display = "block";
	}
}

// runs when question 2 response changes
function q2_changed_callcenter_version()
{
	radioObj = document.contactform["everOwnedFranchise"];
	if(radioObj[0].checked)
	{
		document.getElementById("q2yes").style.display = "block";
	}
	else
	{
		//converting_from
		//periodical
		//sameaddress
		document.contactform["property_address1"].value = "";
		document.contactform["property_address2"].value = "";
		document.contactform["property_city"].value = "";
		document.contactform["property_state_province"].value = "";
		document.contactform["property_zip_postalcode"].value = "";
		document.contactform["property_country"].value = "";
		document.contactform["property_company_website"].value = "";
		document.contactform["property_property_website"].value = "";
		document.contactform["property_num_rooms"].value = "";

		//document.contactform["everOwnedFranchiseDetails"].value = "";
		document.getElementById("q2yes").style.display = "none";
	}
}

// runs when question 3 response changes
function q3_changed()
{
	radioObj = document.contactform["everOwnedHotel"];
	if(radioObj[0].checked)
	{
		document.getElementById("q3yes").style.display = "block";
	}
	else
	{
		document.contactform["everOwnedHotelDetails"].value = "";
		document.getElementById("q3yes").style.display = "none";
	}
}

// runs when question 4 response changes
function q4_changed()
{
	if(document.contactform["role"].selectedIndex == 7)
	{
		document.getElementById("q4other").style.display = "block";
	}
	else
	{
		document.getElementById("q4other").style.display = "none";
		document.contactform["roleOther"].value = "";
	}
}

// runs when question 5 response changes
function q5_changed()
{
	radioObj = document.contactform["everDoneCendantBusiness"];
	if(radioObj[0].checked)
	{
		document.getElementById("q5yes").style.display = "block";
	}
	else
	{
		document.contactform["everDoneCendantBusinessdetails"].value = "";
		document.getElementById("q5yes").style.display = "none";
	}
}

// runs when question 6 response changes
function q6_changed()
{
	radioObj = document.contactform["propertyType"];
	if(radioObj[0].checked)
	{
		document.getElementById("q6converting").style.display = "block";
	}
	else
	{
		document.contactform["everDoneCendantBusinessdetails"].value = "";
		document.getElementById("q6converting").style.display = "none";
	}
}			

function q6_changed_internal()
{
	radioObj = document.contactform["propertyType"];
	if(radioObj[0].checked)
	{
		document.getElementById("q6converting").style.display = "block";
	}
	else
	{
		document.getElementById("q6converting").style.display = "none";
	}
}			

function sameaddress_clicked()
{
	if (document.contactform["sameaddress"].checked == true)
	{
		document.getElementById("franchise_address").style.display = "none";
	}
	else
	{
		document.getElementById("franchise_address").style.display = "block";
	}
}			

// Rebuild the innerhtml for the secondary brand div area depending what was chosen above dropdown which has the index of idx
function update_secondarybrand_area(idx)
{
	var brandlist = new Array();
	brandlist[0] = "All";
	brandlist[1] = "Baymont";
	brandlist[2] = "Days Inn";
	brandlist[3] = "Hawthorn Suites";
	brandlist[4] = "Howard Johnson";
	brandlist[5] = "Knights Inn";
	brandlist[6] = "Microtel Inns &amp; Suites";
	brandlist[7] = "Ramada";
	brandlist[8] = "Super 8";
	brandlist[9] = "Travelodge";
	brandlist[10] = "Wyndham";
	brandlist[11] = "Wyndham Garden";
	brandlist[12] = "Wyndham Vacation Ownership";
	brandlist[13] = "Wingate";
	brandlist[14] = "";
	
	// remove the idx selection
	for (i=idx;i<brandlist.length;i++)
	{
		brandlist[i] = brandlist[i+1];
	}
				
	temp = "<p>Which other Wyndham Worldwide brands are you also interested in?</p><table><tbody><tr><td width='20%' valign='top'>";

	// 1st column
	temp = temp + "<input type='checkbox' name='brand' value='"+brandlist[0]+"'>"+brandlist[0]+"<br>"
	temp = temp + "<input type='checkbox' name='brand' value='"+brandlist[1]+"'>"+brandlist[1]+"<br>"
	temp = temp + "<input type='checkbox' name='brand' value='"+brandlist[2]+"'>"+brandlist[2]+"<br>"
	temp = temp + "<input type='checkbox' name='brand' value='"+brandlist[3]+"'>"+brandlist[3]+"<br>"

	temp = temp + "</td><td width='20%' valign='top'>"

	// 2nd column
	temp = temp + "<input type='checkbox' name='brand' value='"+brandlist[4]+"'>"+brandlist[4]+"<br>"
	temp = temp + "<input type='checkbox' name='brand' value='"+brandlist[5]+"'>"+brandlist[5]+"<br>"
	temp = temp + "<input type='checkbox' name='brand' value='"+brandlist[6]+"'>"+brandlist[6]+"<br>"
	temp = temp + "<input type='checkbox' name='brand' value='"+brandlist[7]+"'>"+brandlist[7]+"<br>"
	
	temp = temp + "</td><td width='30%' valign='top'>"

	// 3rd column
	temp = temp + "<input type='checkbox' name='brand' value='"+brandlist[8]+"'>"+brandlist[8]+"<br>"
	temp = temp + "<input type='checkbox' name='brand' value='"+brandlist[9]+"'>"+brandlist[9]+"<br>"
	temp = temp + "<input type='checkbox' name='brand' value='"+brandlist[10]+"'>"+brandlist[10]+"<br>"
	temp = temp + "<input type='checkbox' name='brand' value='"+brandlist[11]+"'>"+brandlist[11]+"<br>"
	temp = temp + "<input type='checkbox' name='brand' value='"+brandlist[12]+"'>"+brandlist[12]+"<br>"
	
	temp = temp + "</td></tr></tbody></table>";
	
	document.getElementById("secondarybrand_area").innerHTML = temp;
}