$(function(){
	$(".contact tr:even").addClass("even");
	$("table.contact").css("width" , "100%");
	$(".mesh").hide();
	$("#bags").hide();
	$("#cartridges").hide();
	$("#vessels").hide();

$("input[name='mailtemplate']").change(function(){
    if ($("input[name='mailtemplate']:checked").val() == 'templatebags.txt'){
		$("#cartridges").hide();
		$("#vessels").hide();
		$("#bags").fadeIn();	
		$("#rfqform").append("<input type='hidden' name='subject' value='QUOTE-FILTER BAGS' />").append("<input type='hidden' name='recipient' value='cproctor@strainrite.com' />");
	}
    else if ($("input[name='mailtemplate']:checked").val() == 'templatecartridges.txt'){
		$("#bags").hide();
		$("#vessels").hide();
		$("#cartridges").fadeIn();
		$("#rfqform").append("<input type='hidden' name='subject' value='QUOTE- CARTRIDGES' />").append("<input type='hidden' name='recipient' value='cproctor@strainrite.com' />");
	}
	else if ($("input[name='mailtemplate']:checked").val() == 'templatehousings.txt'){
		$("#bags").hide();
		$("#cartridges").hide();
		$("#vessels").fadeIn();
		$("#rfqform").append("<input type='hidden' name='subject' value='QUOTE- HOUSINGS' />").append("<input type='hidden' name='recipient' value='dcbrown@strainrite.com' />");
	}
})
$("input[name='filterbagtype']").change(function(){
    if ($("input[name='filterbagtype']:checked").val() == 'Felt'){
		$(".mesh").hide();
		$(".felt").fadeIn();	
		$("#bag_options").empty().append('<option></option><option>None</option><option>HS-Handle Strap</option><option>AS-Fully Stitched</option><option>WE- Fully Welded Seams</option><option>Mag Bag</option><option>EVP-Enhance Verticle Pleat</option><option>SL-Single Layer</option><option>Carbon Ready</option><option>Chemical Ready</option><option>C-Absorbrite</option><option>Other</option>');
	}
    else {
		$(".felt").hide();
		$(".mesh").fadeIn();
		$("#bag_options").empty().append('<option></option><option>None</option><option>HS-Handle Strap</option><option>Other</option>');
	}
})

// Place ID's of all required fields here. If using ID's other than #email, #cardnum, or #card_brand, replace them here
	required = ["First_Name", "Last_Name", "Company", "email", "Address", "City", "State", "Zip", "Country", "CompletedBy", "Phone"];
	errornotice = $("#error");
	errornotice.hide();		
	
	$("#rfqform").submit(function(){	
		email = $("#email");
		
		//Validate required fields
		for (i=0;i<required.length;i++) {
			var input = $('#'+required[i]);
			if ((input.val() == "") || (input.val() == "Please fill out this field")) {
				input.addClass("needsfilled");
				input.val("Please fill out this field");
				errornotice.slideDown(750);
			} else {input.removeClass("needsfilled");}
		}
		// Validate the e-mail.
		if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {
			email.addClass("needsfilled");
			email.val("Please enter a valid e-mail.");
		}
		
		if ($("input[name='mailtemplate']:checked").val() == 'blank'){
			$("#typeerror").slideDown();
			errornotice.show();
			return false;
		}
		
		//if any inputs on the page have the class 'needsfilled' the form will not submit
		if ($(":input").hasClass("needsfilled")) {
			if($.browser.safari){
				bodyelem = $("body") } else{ bodyelem = $("html,body") 
			};
			var targetOffset = $('#top').offset().top;
			$(bodyelem).animate({scrollTop: targetOffset}, 500);
			return false;
		} else {
			errornotice.hide();
			return true;
		}
	});
	
	// Clears any fields in the form when the user clicks on them
	$(":input").click(function(){		
	   if ($(this).hasClass("needsfilled") ) {
			$(this).val("");
	   }
	});	

});