// JavaScript Document

function getFeet(rvtype){
	if (rvtype!='') {
		$.ajax({
			type: "POST",
			url: "/order/wizard/adco/ajax/univ/_getfeet.cfm",
			data: "rvtype=" + rvtype,
			cache: false,
			success: function(msg){
				$("#univ-lengthFoot").html(msg);
				getSFSInfo(rvtype);
				getTyvekInfo(rvtype);	
				if (rvtype=='1' || rvtype=='3') {
					getDesignerInfo(rvtype);
				}
				else {
					$("#univ-designerInfo").html("Not available");
				}
			}
		});	
	}
		
}

function setInches(){
	
	var inches = $("#univ-lengthInch");
	var feet = $("#univ-lengthFoot");
	
	$("#univ-lengthInch").html("");	
	
	if (feet.selectedIndex == 0 || feet.selectedIndex == feet.length-1){
		$("#univ-lengthInch").append("<option value='0'>0</option>");
		//inches[inches.length]=new Option("0","0");
	}
	else{
		for (var x = 0; x < 12; x++){
			$("#univ-lengthInch").append("<option value='" + x + "'>" + x + "</option>");
			//inches[inches.length]=new Option(x,x);
		}
	}
}

function getSFSInfo(rvtype){
	if (! rvtype.length){
		$("#univ-sfsInfo").html("");
	}
	else{
		var myfeet = parseInt($("#univ-lengthFoot").val());
		var myinch = parseInt($("#univ-lengthInch").val());
	
		var length = myfeet + (myinch / 12)
								
		$("#univ-sfsInfo").html("<img src='/images/wizard/adcocover/rotating.gif'>");
		$.ajax({
			type: "POST",
			url: "/order/wizard/adco/ajax/univ/_getsfs.cfm",
			data: "rvtype=" + rvtype + "&length=" + length,
			cache: false,
			success: function(msg){
				$("#univ-sfsInfo").html(msg);
			}
		});	
	}
}

function getTyvekInfo(rvtype){
	if (! rvtype.length){
		$("#univ-tyvekInfo").html("");
	}
	else{
		var myfeet = parseInt($("#univ-lengthFoot").val());
		var myinch = parseInt($("#univ-lengthInch").val());
		
		var length = myfeet + (myinch / 12)
		
		$("#univ-tyvekInfo").html("<img src='/images/wizard/adcocover/rotating.gif'>");
		$.ajax({
			type: "POST",
			url: "/order/wizard/adco/ajax/univ/_gettyvek.cfm",
			data: "rvtype=" + rvtype + "&length=" + length,
			cache: false,
			success: function(msg){
				$("#univ-tyvekInfo").html(msg);
			}
		});	
	}
}

function getDesignerInfo(rvtype){
	if (! rvtype.length){
		$("#univ-designerInfo").html("");
	}
	else{
		var myfeet = parseInt($("#univ-lengthFoot").val());
		var myinch = parseInt($("#univ-lengthInch").val());
		
		var length = myfeet + (myinch / 12)
		
		$("#univ-designerInfo").html("<img src='/images/wizard/adcocover/rotating.gif'>");
		$.ajax({
			type: "POST",
			url: "/order/wizard/adco/ajax/univ/_getdesigner.cfm",
			data: "rvtype=" + rvtype + "&length=" + length,
			cache: false,
			success: function(msg){
				$("#univ-designerInfo").html(msg);
			}
		});	
	}
}

function validateAdcoForm(){

	var errors = "";
	
	if ($("#univ-rvTypes").val() == ""){
		errors += "Please choose an RV Type<br>";
	}
	if ($("#univ-lengthFoot").val() == ""){
		errors += "Please choose the length of your RV<br>";
	}
	
	if ($.trim(errors).length){
		$("#univ-errmsg").html(errors);
		$("#univ-err").slideDown("500");
	}
	else {
		$.ajax({
			type: "POST",
			url: "/order/wizard/adco/ajax/univ/_addtocart.cfm",
			data: "rvType=" + $("#univ-rvTypes").val() 
					+ "&lengthFoot=" + $("#univ-lengthFoot").val()
					+ "&lengthInch=" + $("#univ-lengthInch").val()
					+ "&fabric=" + $("#univ-fabric").val()
					+ "&parentsku=" + $.trim($("#parentsku").val())
					+ "&cordgroup=" + $.trim($("#cordgroup").val())
					+ "&affiliateID=" + $.trim($("#affiliateID").val()),
			cache: false,
			success: function(msg){
				if ($.trim(msg).length) {
					$("#univ-errmsg").html(msg);
					$("#univ-err").slideDown("500");
				}
				else {
					location.href="/order";
				}				
			}
		});		
	}
	
	
}

function setfabric(type) {
	$("#univ-fabric").val(type);
}

