var joinForm = {
	HCOM: false,
	backIntercept: function(newLocation, historyData) {
		$('personalInfo', 'commPref').invoke('toggle');
	},
	checkTerms: function() {
		if($('terms').checked) return(true);
		else {
			alert("You must agree with the Terms & Conditions of the Hyatt Gold Passport");
			return(false);
		}
	},
	showAddressOptions: function(id) {
		if(id == "typeHome") {
			$('phoneExt', 'typeBusinessOptions').invoke('hide');
			$('phoneTitle').innerHTML = "Phone";
		}
		else {
			$('phoneExt', 'typeBusinessOptions').invoke('show');
			$('phoneTitle').innerHTML = "Business Phone";
		}
	},
	showCommunications: function() {
		$('personalInfo', 'commPref').invoke('toggle');
	},
	showOptions: function(id) {
		$('addType').show(); //Show Address Type Options & Set Company Name to default.
		$('companyNameLabel').getElementsByTagName('label')[0].innerHTML = 'Company Name';
		$('companyNameLabel').className = '';
		//Hide All
		$('plannerOptions', 'travelAgentOptions', 'travelAgentOptions2').invoke('hide');
		
		//Show Selected
		if(id == "primaryTypeA") { //Individual
			$('phoneExt','typeBusinessOptions').invoke('hide');
			$('typeHome').checked = true;
			$('typeHome').disabled = false;
			$('phoneTitle').innerHTML = "Phone";
		}
		if(id == "primaryTypeB") { //Travel Agent
			$('typeBusiness').checked = true;
			$('addType').hide();
			$('phoneExt', 'typeBusinessOptions', 'travelAgentOptions', 'travelAgentOptions2').invoke('show');
			$('phoneTitle').innerHTML = "Business Phone";
			$('companyNameLabel').className = 'required';
			$('companyNameLabel').getElementsByTagName('label')[0].innerHTML = 'Travel Agency Name';
		}
		if(id == "primaryTypeC") { //Meeting Planner
			$('typeBusiness').checked = true;
			$('phoneExt', 'typeBusinessOptions', 'plannerOptions').invoke('show');
			$('phoneTitle').innerHTML = "Business Phone";
		}
	},
	initOptions: function() {
		$('addType').show(); //Show Address Type Options & Set Company Name to default.
		$('companyNameLabel').className = '';
		//Hide All
		$('plannerOptions', 'travelAgentOptions', 'travelAgentOptions2', 'typeBusinessOptions').invoke('hide');
		
		//Show Selected
		if($('primaryTypeB').checked == true) { //Travel Agent
			$('typeBusiness').checked = true;
			$('addType').hide();
			$('typeBusinessOptions', 'travelAgentOptions', 'travelAgentOptions2').invoke('show');
			$('companyNameLabel').className = 'required';
			$('companyNameLabel').getElementsByTagName('label')[0].innerHTML = 'Travel Agency Name';
		}
		if($('primaryTypeC').checked == true) { //Meeting Planner
			$('plannerOptions').show();
		}
		if($('typeBusiness').checked == true) {
			$('phoneTitle').innerHTML = "Business Phone";
			$('phoneExt', 'typeBusinessOptions').invoke('show');
		} else {
			$('phoneExt').hide();
		}
	},
	initHCOMOptions: function() {
		//Get addressType and primaryType values.
		primaryType = $('primaryType').value;
		addressType = $('addressType').value;
		
		//Show Selected
		if(primaryType == 1) { //Travel Agent
			$('typeBusinessOptions', 'travelAgentOptions', 'travelAgentOptions2').invoke('show');
			$('companyNameLabel').className = 'required';
			$('companyNameLabel').getElementsByTagName('label')[0].innerHTML = 'Travel Agency Name';
		}
		else if(primaryType == 2) { //Meeting Planner
			$('plannerOptions').show();
		}
		
		if(addressType == 'B') {
			$('phoneTitle').innerHTML = "Business Phone";
			$('phoneExt', 'typeBusinessOptions').invoke('show');
		} else {
			$('phoneExt').hide();
			$('typeBusinessOptions').hide();
		}
	},
	init: function() {
	
		//Is this an HCOM only user?
		if($('addType') == null) joinForm.HCOM = true;
	
		if(joinForm.HCOM) {
			$('commPref', 'plannerOptions', 'travelAgentOptions', 'travelAgentOptions2').invoke('hide');
			Event.observe('continue', 'click', function() { joinForm.showCommunications() });
			
			this.initHCOMOptions();
		} else {
			$('commPref', 'plannerOptions', 'travelAgentOptions', 'travelAgentOptions2').invoke('hide');
			Event.observe('typeHome', 'click', function() { joinForm.showAddressOptions('typeHome') });
			Event.observe('typeBusiness', 'click', function() { joinForm.showAddressOptions('typeBusiness') });
			Event.observe('primaryTypeA', 'click', function() { joinForm.showOptions('primaryTypeA') });
			Event.observe('primaryTypeB', 'click', function() { joinForm.showOptions('primaryTypeB') });
			Event.observe('primaryTypeC', 'click', function() { joinForm.showOptions('primaryTypeC') });
			Event.observe('continue', 'click', function() { joinForm.showCommunications() });
		
			//Initialize Customer Type Options and Address Options
			this.initOptions();
		}
	}
}

joinForm.init();
