function wordcount(count) {
	var words = count.split(/\s/);
	return (words.length);
}

var order = [];

$(document).ready(function(){

	$("textarea.descrtext").keyup(function(){
		var targ = $(this).attr("title");
		var wordsleft = 65 - wordcount($(this).val());
		$("#" + targ + "-wordcount").empty().append(wordsleft);
		if (wordsleft < 10) {
			$("#" + targ + "-wordcount").css("color", "red");
		}
	});
	
	$("#step1").click(function(){
	
		var totaldue = 0;
		var listings = [];
		var freep2 = false;
						
		if ($("#firstStd:checked").val() == "on") { 
			listings.push($("#firstStd").attr("alt") + "^" + $("#firstStd").attr("title")); 
			totaldue = totaldue + ($("#firstStd").attr("title")*1); 		
		}
		
		if ($("#firstPkg1:checked").val() == "on") { 
			listings.push($("#firstPkg1").attr("alt") + "^" + $("#firstPkg1").attr("title")); 
			totaldue = totaldue + ($("#firstPkg1").attr("title")*1); 	
		}
		
		
		
		if ($("#firstPkg3:checked").val() == "on") { 
			listings.push($("#firstPkg3").attr("alt") + "^" + $("#firstPkg3").attr("title")); 
			totaldue = totaldue + ($("#firstPkg3").attr("title")*1); 		
		}
		
		if ($("#firstPkg4:checked").val() == "on") { 
			listings.push($("#firstPkg4").attr("alt") + "^" + $("#firstPkg4").attr("title")); 
			totaldue = totaldue + ($("#firstPkg4").attr("title")*1); 		
		}
		
		if ($("#addlStd").val() > 0) { 
			if ($("#firstStd:checked").val() == "on") {
				for (i=1; i<=$("#addlStd").val(); i++) {
					listings.push($("#addlStd").attr("alt") + "^" + $("#addlStd").attr("title")); 
					totaldue = totaldue + ($("#addlStd").attr("title")*1); 
				}			
			} else {
				$("#addlStd").val(0);
			}	
		}
		
		if ($("#addlPkg1").val() > 0) { 
			if ($("#firstPkg1:checked").val() == "on") {
				for (i=1; i<=$("#addlPkg1").val(); i++) {
					listings.push($("#addlPkg1").attr("alt") + "^" + $("#addlPkg1").attr("title")); 
					totaldue = totaldue + ($("#addlPkg1").attr("title")*1); 
				}			
			} else {
				$("#addlPkg1").val(0);
			}
		}
		
		if ($("#addlPkg2").val() > 0) { 
			if ($("#firstPkg2:checked").val() == "on") {
				for (i=1; i<=$("#addlPkg2").val(); i++) {
					listings.push($("#addlPkg2").attr("alt") + "^" + $("#addlPkg2").attr("title")); 
					totaldue = totaldue + ($("#addlPkg2").attr("title")*1); 
				}			
			} else {
				$("#addlPkg2").val(0);
			}		
		}
		
		if ($("#addlPkg3").val() > 0) { 
			if ($("#firstPkg3:checked").val() == "on") {
				for (i=1; i<=$("#addlPkg3").val(); i++) {
					listings.push($("#addlPkg3").attr("alt") + "^" + $("#addlPkg3").attr("title")); 
					totaldue = totaldue + ($("#addlPkg3").attr("title")*1); 
				}			
			} else {
				$("#addlPkg3").val(0);
			}	
		}
		
		if ($("#addlPkg4").val() > 0) { 
			if ($("#firstPkg4:checked").val() == "on") {
				for (i=1; i<=$("#addlPkg4").val(); i++) {
					listings.push($("#addlPkg4").attr("alt") + "^" + $("#addlPkg4").attr("title")); 
					totaldue = totaldue + ($("#addlPkg4").attr("title")*1); 
				}			
			} else {
				$("#addlPkg4").val(0);
			}
		}
		
		if ($("#strip1-2").val() > 0) { 
			var q = $("#strip1-2").val();
			var cost = 0;
			if (q >= 1 && q <= 2) {
				cost = 695;
			} else if (q >= 3 && q <= 5) {
				cost = 595;
			} else if (q >= 6 && q <= 9) {
				cost = 495;
			} else {
				cost = 450;
			}
			
			for (i=1; i<=$("#strip1-2").val(); i++) {
				listings.push($("#strip1-2").attr("alt") + "^" + cost); 
				totaldue = totaldue + cost; 
			}
		}
		
//		if ($("#strip3-5").val() > 0) { 
//			for (i=1; i<=$("#strip3-5").val(); i++) {
//				listings.push($("#strip3-5").attr("alt") + "^" + $("#strip3-5").attr("title")); 
//				totaldue = totaldue + ($("#strip3-5").attr("title")*1); 
//			}
//		}
//		
//		if ($("#strip6-9").val() > 0) { 
//			for (i=1; i<=$("#strip6-9").val(); i++) {
//				listings.push($("#strip6-9").attr("alt") + "^" + $("#strip6-9").attr("title")); 
//				totaldue = totaldue + ($("#strip6-9").attr("title")*1); 
//			}
//		}
//		
//		if ($("#strip10plus").val() > 0) { 
//			for (i=1; i<=$("#strip10plus").val(); i++) {
//				listings.push($("#strip10plus").attr("alt") + "^" + $("#strip10plus").attr("title")); 
//				totaldue = totaldue + ($("#strip10plus").attr("title")*1); 
//			}
//		}
		
		if ($("#oneSixth").val() > 0) { 
			for (i=1; i<=$("#oneSixth").val(); i++) {
				listings.push($("#oneSixth").attr("alt") + "^" + $("#oneSixth").attr("title")); 
				totaldue = totaldue + ($("#oneSixth").attr("title")*1);
			} 
			freep2 = true;
			$("#firstPkg2").attr("checked", true);
		}
		
		if ($("#oneThird").val() > 0) { 
			for (i=1; i<=$("#oneThird").val(); i++) {
				listings.push($("#oneThird").attr("alt") + "^" + $("#oneThird").attr("title")); 
				totaldue = totaldue + ($("#oneThird").attr("title")*1); 
			}
			freep2 = true;
			$("#firstPkg2").attr("checked", true);
		}
		
		if ($("#oneHalf").val() > 0) { 
			for (i=1; i<=$("#oneHalf").val(); i++) {
				listings.push($("#oneHalf").attr("alt") + "^" + $("#oneHalf").attr("title")); 
				totaldue = totaldue + ($("#oneHalf").attr("title")*1); 
			}
			freep2 = true;
			$("#firstPkg2").attr("checked", true);
		}
		
		if ($("#twoThirds").val() > 0) { 
			for (i=1; i<=$("#twoThirds").val(); i++) {
				listings.push($("#twoThirds").attr("alt") + "^" + $("#twoThirds").attr("title")); 
				totaldue = totaldue + ($("#twoThirds").attr("title")*1); 
			}
			freep2 = true;
			$("#firstPkg2").attr("checked", true);
		}
		
		if ($("#fullPage").val() > 0) {
			for (i=1; i<=$("#fullPage").val(); i++) { 
				listings.push($("#fullPage").attr("alt") + "^" + $("#fullPage").attr("title")); 
				totaldue = totaldue + ($("#fullPage").attr("title")*1); 
			}
			freep2 = true;
			$("#firstPkg2").attr("checked", true);
		}
		
		if ($("#topLeaderboard").val() > 0) { 
			for (i=1; i<=$("#topLeaderboard").val(); i++) { 
				listings.push($("#topLeaderboard").attr("alt") + "^" + $("#topLeaderboard").attr("title")); 
				totaldue = totaldue + ($("#topLeaderboard").attr("title")*1); 
			}
			freep2 = true;
			$("#firstPkg2").attr("checked", true);
		}
		
		if ($("#skyscraper").val() > 0) { 
			for (i=1; i<=$("#skyscraper").val(); i++) { 
				listings.push($("#skyscraper").attr("alt") + "^" + $("#skyscraper").attr("title")); 
				totaldue = totaldue + ($("#skyscraper").attr("title")*1); 
			}
			freep2 = true;
			$("#firstPkg2").attr("checked", true);
		}
		
		if ($("#homeBanner").val() > 0) { 
			for (i=1; i<=$("#homeBanner").val(); i++) { 
				listings.push($("#homeBanner").attr("alt") + "^" + $("#homeBanner").attr("title")); 
				totaldue = totaldue + ($("#homeBanner").attr("title")*1); 
			}
			freep2 = true;
			$("#firstPkg2").attr("checked", true);
		}
		
		if ($("#staticButton").val() > 0) { 
			for (i=1; i<=$("#staticButton").val(); i++) { 
				listings.push($("#staticButton").attr("alt") + "^" + $("#staticButton").attr("title")); 
				totaldue = totaldue + ($("#staticButton").attr("title")*1); 
			}
			freep2 = true;
			$("#firstPkg2").attr("checked", true);
		}
		
		if ($("#catBanner").val() > 0) { 
			for (i=1; i<=$("#catBanner").val(); i++) { 
				listings.push($("#catBanner").attr("alt") + "^" + $("#catBanner").attr("title")); 
				totaldue = totaldue + ($("#catBanner").attr("title")*1); 
			}
			freep2 = true;
			$("#firstPkg2").attr("checked", true);
		}
		
		if ($("#firstPkg2:checked").val() == "on") { 			
			if (freep2 == false) { 
				listings.push($("#firstPkg2").attr("alt") + "^" + $("#firstPkg2").attr("title")); 
				totaldue = totaldue + ($("#firstPkg2").attr("title")*1); 		
			} else {
				listings.push($("#firstPkg2").attr("alt") + "^0"); 
			}
		}
	 			
		$("#total").empty().append("$" + totaldue);
		$("#listings").val(listings.toString());
	});

});
