if (document.images) {
	img1N= new Image(118,23);
	img1N.src= 'images/commercial-off.png' ;
	img1H= new Image(118,23);
	img1H.src= 'images/commercial-on.png' ;

	img2N= new Image(118,23);
	img2N.src= 'images/residential-off.png' ;
	img2H= new Image(118,23);
	img2H.src= 'images/residential-on.png' ;

	img3N= new Image(118,23);
	img3N.src= 'images/large-buildings-off.png' ;
	img3H= new Image(118,23);
	img3H.src= 'images/large-buildings-on.png' ;

	img4N= new Image(118,23);
	img4N.src= 'images/garage-doors-off.png' ;
	img4H= new Image(118,23);
	img4H.src= 'images/garage-doors-on.png' ;

	img5N= new Image(118,23);
	img5N.src= 'images/accessories-off.png' ;
	img5H= new Image(118,23);
	img5H.src= 'images/accessories-on.png' ;

	img6N= new Image(118,23);
	img6N.src= 'images/sheds-off.png' ;
	img6H= new Image(118,23);
	img6H.src= 'images/sheds-on.png' ;
	
	img7N= new Image(118,23);
	img7N.src= 'images/blog-off.png' ;
	img7H= new Image(118,23);
	img7H.src= 'images/blog-on.png' ;


	function myOn(myImgName) {
		document[myImgName].src=eval(myImgName+ 'H' ).src;
	}

	function myOut(myImgName) {
		document[myImgName].src=eval(myImgName+ 'N' ).src;
	}
} 

var defaultOptions = '';
var optionsForW40 = '';
for(var i=8; i<13; i++)	defaultOptions += '<option value="' + i + '">' + i + '\'</option>';
for(var i=10; i<17; i++) optionsForW40 += '<option value="' + i + '">' + i + '\'</option>';

$(document).ready(function() {
	$("#barn-form, #loafing-form, #lean-to-form, .insulation_form").hide();			
	$("#width-variable").change( onWidthChange );	
	$("#building-select").change( onBuildingChange );			
//	$("#barn-checkbox").click( function(){ $("#barn-form").toggle( 400 ); } );
//	$("#loafing-checkbox").click( function(){ $("#loafing-form").toggle( 400 ); } );
//	$("#lean-to-checkbox").click( function(){ $("#lean-to-form").toggle( 400 ); } );	
});

function validate(form_id, email, name, city, state) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var address = document.forms[form_id].elements[email].value;
	var name = document.forms[form_id].elements[name].value;
	var city = document.forms[form_id].elements[city].value;
	var state = document.forms[form_id].elements[state].value;
	var returnVal = true;
	$("#requirederror, #emailerror").html("");
	$(".error, .nameerror, .cityerror, .stateerror").css("border", "solid 1px #495627");
	if(reg.test(address) == false) {
		$(".error").css("border","2px solid red");
		$("#emailerror").html("Please enter a valid email address.");
		returnVal = false;
	}
	if(name === "") {
		$(".nameerror").css("border","2px solid red");	
		$("#requirederror").html("Please fill in all required fields.");
		returnVal = false;
	}
	if(city === "") {
		$(".cityerror").css("border","2px solid red");	
		$("#requirederror").html("Please fill in all required fields.");
		returnVal = false;
	}
	if(state === "") {
		$(".stateerror").css("border","2px solid red");	
		$("#requirederror").html("Please fill in all required fields.");
		returnVal = false;
	}
	return returnVal;
}


function onWidthChange() {
	var val = parseInt($(this).val());
	var options = (val == 40) ? optionsForW40 : defaultOptions;
	
	$("#height-variable").html(options);
	if( val == 40 ) $("#garage-door").html("2 - 12x10 Garage Doors Included");
	else if(val >= 20 && val <= 30) $("#garage-door").html("1 - 16x7 Garage Door Included");
	else if(val >= 12 && val <= 18) $("#garage-door").html("1 - 9x7 Garage Door Included");
	else $("#garage-door").html("");
}

function onBuildingChange() {
	var val = $(this).val();
	if (val=="Carport") {
		$(".building-width-form").show();
		$(".passenger_form, .garage_form, .insulation_form, #lean-to-form, #loafing-form, #barn-form").hide();
	} else if (val=="Barns") {
		$("#barn-form").show();
		$(".passenger_form, .garage_form, .insulation_form, #loafing-form, #lean-to-form, .building-width-form").hide();
	} else if (val=="Loafing-Sheds") {
		$("#loafing-form").show();
		$(".passenger_form, .garage_form, .insulation_form, #barn-form, #lean-to-form, .building-width-form").hide();
	} else if (val=="Lean-to") {
		$("#lean-to-form").show();
		$(".passenger_form, .garage_form, .insulation_form, #barn-form, #loafing-form, .building-width-form").hide();
	} else if (val=="Garage") {
		$(".insulation_form, .garage_form, .passenger_form").show();
		$("#barn-form, #loafing-form, #lean-to-form").hide();
	} else {
		$(".passenger_form, .garage_form, .building-width-form").show();
		$("#barn-form, #loafing-form, #lean-to-form, .insulation_form").hide();
	}

}

