// JavaScript Document


$(function() {
	
	$("#cust-rvTypes").html("<option>loading...</option>");
	$.ajax({
		type: "POST",
		url: "/order/wizard/adco/ajax/cust/_rvtypes.cfm",
		data: "",
		cache: false,
		success: function(msg){
			$("#cust-rvTypes").html(msg);
		}
	});	
	
	$("#cust-fabtype").change(function() {
		if ($(this).val()!="") {
			$("#cust-sku").html("<option value=''>loading...</option>")
			$.ajax({
				type: "POST",
				url: "/order/wizard/adco/ajax/cust/_colors.cfm",
				data: "fabtype=" + $(this).val(),
				cache: false,
				success: function(msg){
					$("#cust-sku").html(msg);
				}
			});
		}
	});
	
	$("#cust-addcart").click(function() {
		$("#cust-errmsg").html("");
		var errors = "";
		
		if ($("#cust-feet").val()=="") {
			errors += "Choose length of RV<br/>";
		}	
		if ($("#cust-fabtype").val()=="") {
			errors += "Choose fabric type<br/>";
		}
		if ($.trim($("#cust-make").val())=="") {
			errors += "Provide your RV make<br/>";
		}
		if ($.trim($("#cust-model").val())=="") {
			errors += "Provide your RV model<br/>";
		}
		if ($.trim($("#cust-phone").val())=="") {
			errors += "Provide your phone number<br/>";
		}

		if ($.trim(errors).length) {
			$("#cust-errmsg").html(errors);
			$("#cust-err").slideDown("500");
		}
		else {
			$("#cust-err").slideUp("500");
			
			var custracks = $("#cust-racks").attr("checked")?"Y":"N";
			var custladder = $("#cust-ladder").attr("checked")?"Y":"N";
			var custacunit = $("#cust-acunit").attr("checked")?"Y":"N";
			var custfoldedsatdish = $("#cust-foldedsatdish").attr("checked")?"Y":"N";
			var custdomedsatdish = $("#cust-domedsatdish").attr("checked")?"Y":"N";
			var custspotlight = $("#cust-spotlight").attr("checked")?"Y":"N";
			var custhorns = $("#cust-horns").attr("checked")?"Y":"N";
			var custsparetire = $("#cust-sparetire").attr("checked")?"Y":"N";
			var custawnings = $("#cust-awnings").attr("checked")?"Y":"N";
			var lengthfoot = $("#cust-feet").val()
			var lengthinch = $("#cust-inch").val()
			var length = lengthfoot + "ft." + lengthinch + "in. "
			
			$.ajax({
				type: "POST",
				url: "/order/wizard/adco/ajax/cust/_addtocart.cfm",
				data: "customSku=" + $("#cust-sku").val() 
						+ "&year=" + $("#cust-year").val()
						+ "&make=" + $("#cust-make").val() 
						+ "&model=" + $("#cust-model").val() 
						+ "&rvTypeExt=" + $("#cust-extType").val() 
						+ "&length=" + length
						+ "&racks=" + custracks
						+ "&ladders=" + custladder
						+ "&acunit=" + custacunit
						+ "&foldeddish=" + custfoldedsatdish
						+ "&domeddish=" + custdomedsatdish
						+ "&spotlight=" + custspotlight
						+ "&horns=" + custhorns
						+ "&sparetire=" + custsparetire
						+ "&awnings=" + custawnings
						+ "&othercomment=" + $.trim($("#cust-comments-other").val())
						+ "&phone=" + $.trim($("#cust-phone").val())
						+ "&tireSize=" + $.trim($("#cust-tire").val())
						+ "&parentsku=" + $.trim($("#parentsku").val())
						+ "&cordgroup=" + $.trim($("#cordgroup").val())
						+ "&affiliateID=" + $.trim($("#affiliateID").val())
						+ "&lengthfoot=" + lengthfoot
						+ "&lengthinch=" + lengthinch,
				cache: false,
				success: function(msg){
					location.href="/order";
				}
			});
		}		
		
		return false;
	});
	
});



