window.addEvent('domready', function(){

	//ADD HIDE CLASS TO HIDDEN AREAS
	$$('[id^=hidden_]').each(function(item, index){
		item.addClass('hide');
	});
	
	//SET SHOW/HIDE SWITCHES
	$('Facility_Status1').addEvent('click',chkFacilityStatus);
	$('Facility_Status2').addEvent('click',chkFacilityStatus);
	$('Facility_Status3').addEvent('click',chkFacilityStatus);
	
	$('Using_Supplemental_Heat1').addEvent('click',chkSupplementalHeat);
	$('Using_Supplemental_Heat2').addEvent('click',chkSupplementalHeat);
	
	$('Type_of_Supplemental_Heat1').addEvent('click',chkTypeSupplementalHeat);
	$('Type_of_Supplemental_Heat2').addEvent('click',chkTypeSupplementalHeat);
	$('Type_of_Supplemental_Heat3').addEvent('click',chkTypeSupplementalHeat);
	

});

function chkFacilityStatus() {
	if(this.id != "Facility_Status3") {
		$('hidden_Facility_Status3').addClass('hide');
	} else {
		$('hidden_Facility_Status3').removeClass('hide');
	}
}

function chkSupplementalHeat() {
	if(this.id != "Using_Supplemental_Heat1") {
		$('hidden_Using_Supplemental_Heat1').addClass('hide');
	} else {
		$('hidden_Using_Supplemental_Heat1').removeClass('hide');
	}
}

function chkTypeSupplementalHeat() {
	$('hidden_Type_of_Supplemental_Heat1').addClass('hide');
	$('hidden_Type_of_Supplemental_Heat2').addClass('hide');
	$('hidden_Type_of_Supplemental_Heat3').addClass('hide');
	$('hidden_' + this.id).removeClass('hide');
}

function chkForm(form) {
	
	if(chkRequired(form)) {
		//FACILITY STATUS
		var fs1 = $('Facility_Status1');
		var fs2 = $('Facility_Status2');
		var fs3 = $('Facility_Status3');
		if(!fs1.checked && !fs2.checked && !fs3.checked) {
			fs1.getParent('fieldset').addClass('required');
			alert('Please let us know if the facility being insulated will be new, an addition or rehabilitated?');
			fs1.focus();
			return false;
		} else {
			fs1.getParent('fieldset').removeClass('required');
		}
		//CURRENT INSULATION SYSTEM - Rehabilitated FACILITY STATUS
		if(fs3.checked) {
			var ci1 = $('Current_Insulation1');
			var ci2 = $('Current_Insulation2');
			if(!ci1.checked && !ci2.checked) {
				ci1.getParent('fieldset').addClass('required');
				alert('Please let us know if there is a current insulation system?');
				ci1.getParent('fieldset').focus();
				return false;
			} else {
				ci1.getParent('fieldset').removeClass('required');
			}
		}
		//SUPPLEMENTAL HEAT
		var sh1 = $('Using_Supplemental_Heat1');
		var sh2 = $('Using_Supplemental_Heat2');
		if(!sh1.checked && !sh2.checked) {
			sh1.getParent('fieldset').addClass('required');
			alert('Please let us know if the facility will be using supplemental heat?');
			sh1.getParent('fieldset').focus();
			return false;
		} else {
			sh1.getParent('fieldset').removeClass('required');
		}
		//SUPPLEMENTAL HEAT TYPE
		if(sh1.checked) {
			var sht1 = $('Type_of_Supplemental_Heat1');
			var sht2 = $('Type_of_Supplemental_Heat2');
			var sht3 = $('Type_of_Supplemental_Heat3');
			if(!sht1.checked && !sht2.checked && !sht3.checked) {
				sht1.getParent('fieldset').addClass('required');
				alert('Please let us know what type of supplemental heat the facility will be using?');
				sht1.getParent('fieldset').focus();
				return false;
			} else {
				sht1.getParent('fieldset').removeClass('required');
			}
			//if(sht1.checked) {}
			//if(sht2.checked) {}
			//if(sht3.checked) {}
		}


	} else {
		return false;
	}
	
}