	var HomeForm = Class.create();
	HomeForm.prototype =
	{
		initialize: function(form_id){
			this.step						=	parseInt($F("step"));
			this.total_steps		=	7;
			this.lockReturnKey	= false;
			this.initializeDisplay();
			this.initializeEvents();
		},

		/***************************************************************************************************
		 *initialize the elements of the form, hide and show as directed
		 */
		initializeDisplay : function(){
			this.showCurrentlyInsured();
			this.showResidenceUnits();
			this.showGarageCapacity();
		},

		/***************************************************************************************************
		 *add event listeners for submit button, return key and custom onclick/onchange
		 */
		initializeEvents : function(){
			if(isDefined("currently_insured_1") && isDefined("currently_insured_0")){
				Event.observe('currently_insured_1', 'click', this.showCurrentlyInsured.bindAsEventListener(this));
				Event.observe('currently_insured_0', 'click', this.showCurrentlyInsured.bindAsEventListener(this));
			}
			if(isDefined("residence_garage_attached")){
				Event.observe('residence_garage_attached', 'change', this.showGarageCapacity.bindAsEventListener(this));
			}
			if(isDefined("residence_type")){
				Event.observe('residence_type', 'change', this.showResidenceUnits.bindAsEventListener(this));
			}
			if(isDefined('go-to-step2')){
				Event.observe('go-to-step2', 'click', this.validateFields.bindAsEventListener(this));
			}
			if(isDefined('go-to-step3')){
				Event.observe('go-to-step3', 'click', this.validateFields.bindAsEventListener(this));
			}
			if(isDefined('go-to-step4')){
				Event.observe('go-to-step4', 'click', this.validateFields.bindAsEventListener(this));
			}
			if(isDefined('go-to-step5')){
				Event.observe('go-to-step5', 'click', this.validateFields.bindAsEventListener(this));
			}
			if(isDefined('go-to-step6')){
				Event.observe('go-to-step6', 'click', this.validateFields.bindAsEventListener(this));
			}
			if(isDefined('go-to-step7')){
				Event.observe('go-to-step7', 'click', this.validateFields.bindAsEventListener(this));
			}
			if(isDefined('get-quote')){
				Event.observe('get-quote', 'click', this.validateFields.bindAsEventListener(this));
			}
		},

		validateFields: function(e){
			var elements			= Form.getElements($("home-insurance"));
			var form_elements	= new Validator(elements);
			
			var is_valid			= form_elements.isFormValid();
						
			if(!is_valid){ 
				Event.stop(e);
				if(isDefined("error_message")){ $("error_message").show(); }
			}else{
				if(isDefined("error_message")){ $("error_message").hide(); }
			}
		},

		validateOnReturnKey: function(e){
			if(e.keyCode == Event.KEY_RETURN){
				this.validateFields(e);
			}
		},

		/***************************************************************************************************
		 *Custom functions
		 */
		showCurrentlyInsured : function(){
			if(isDefined("currently_insured_1") && isDefined("currently_insured_0")){
				if( $("currently_insured_1").checked ){
					$$("tr.existing_carrier_rows").each(function(ele){ ele.style.display = ""; });
					$("existing_carrier").addClassName("required");
					$("policy_expires_yyyy_on").addClassName("validate-dates");
					$("policy_started_yyyy_on").addClassName("validate-dates");
				}else{
					$$("tr.existing_carrier_rows").each(function(ele){ ele.style.display = "none"; });
					$("existing_carrier").removeClassName("required");
					$("policy_expires_yyyy_on").removeClassName("validate-dates");
					$("policy_started_yyyy_on").removeClassName("validate-dates");
				}
			}
		},
				
		showResidenceUnits : function(){
			if(isDefined("residence_type") && isDefined("residence_units")){
				var residence_type	=	$F("residence_type");
				if(residence_type == "multi_family" || residence_type == "apartment" || residence_type == "condo" || residence_type == "duplex" || residence_type == "other"){
					$$("td.residenceUnits").each(function(ele){ ele.style.display = ""; })
					$("residence_units").addClassName("validate-number");
				}else{
					$$("td.residenceUnits").each(function(ele){ ele.style.display = "none"; })
					$("residence_units").removeClassName("validate-number");
				}
			}
		},
		
		showGarageCapacity : function(){
			if(isDefined("residence_garage_attached") && isDefined("residence_garage_type")){
				if($F("residence_garage_attached") == "1" || $F("residence_garage_attached") == "0"){
					$$("td.garage").each(function(ele){ ele.style.display = ""; })
					$("residence_garage_type").addClassName("required");
				}else{
					$$("td.garage").each(function(ele){ ele.style.display = "none"; })
					$("residence_garage_type").removeClassName("required");
				}
			}
		}
	}

	if (!(BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 6)) {
		Event.observe(window, 'load', function() {
			var home_form = new HomeForm();
		});
	}
