function formValidate(){
	var qty = false;

	$(".product_item select option:selected").each(function(i) {
		if (this.text != "0"){
			qty = true;
		}
	});
	
	if (!qty){
		//$('.attention').show();
		$("#dialog span.title").html("");
		$("#dialogMsg p.msg").html("<br />Please select the number of items you require before you continue.<br />&nbsp;");
		$("#dialogMsg h4").html("<br />Select a product");
		$("#dialogMsg p.btn a").html("Close");
		$('.ui-dialog-titlebar').removeClass('modal_congrats');
		$('.ui-dialog-titlebar').removeClass('no-text');
		showDialog();
		return false;
	}
	
};

function showDialog() {
	$('#dialog').dialog('option', 'title', $('#dialog .title').text());
	$('#dialog').dialog('option', 'width', 460);
	$('#dialog').dialog('option', 'modal', true);
	// $('#dialog').dialog('option', 'buttons', {"Close": function(){ $(this).dialog("close");} });
	
	$('#dialog').dialog('open');
};

function closeDialog() {
	$('#dialog').dialog('close');
};

// function showApplicatorRange(){

		// $("#range1 :select, #range2 :select").removeAttr("disabled");
		// $("#range1").hide();
		// $("#applicator").addClass("selected");
		// $("#non_applicator").removeClass("selected");
		// $("#range2").show();
		// $("#applicator_type").val("2");

// };

// function showNonApplicatorRange(){
		
		// $("#range1 :select, #range2 :select").removeAttr("disabled");
		// $("#range2").hide();
		// $("#non_applicator").addClass("selected");
		// $("#applicator").removeClass("selected");
		// $("#range1").show();
		// $("#applicator_type").val("1");

// };

function clearQuantityValues(){
	$("#product_item_selection select option").removeAttr('selected');
	$("#product_item_selection select option[value=0]").attr("selected", "selected");
}

function selectWeek(numWeeks){
	$("#weeks a").removeClass("selected");
	$(".weeks" + numWeeks + " a").addClass("selected");
	$("#selected_delivery").val(numWeeks);
}

$(document).ready(function(){

	// $("#range1, #range2").hide();
	
	$("#non_applicator").bind("click", function(){
	
		// showNonApplicatorRange();
		clearQuantityValues();
		return false;

	});
	
	$("#applicator").bind("click", function(){

		// showApplicatorRange();
		clearQuantityValues();
		return false;

	});
	
	$("#product_item_select").bind("click", function(){
		if ($("#applicator_type").val() == ""){

			$("#dialogMsg h4").html("<br />Please select your applicator preference");
			$("#dialog p").html("<br />Choose from our Applicator or Non-applicator ranges.<br />&nbsp;");
			showDialog();
			return false;
		}
	});
	
	$("#product_item_select select").change(function(){
		$("#product_delivery_select").show();
	});
	
	
	// switch ($('#applicator_type').val()) {
	
		// case "1":

			// // showNonApplicatorRange();
			// break;
			
		// case "2":

			// // showApplicatorRange();
			// break;
			
		// default:
			// // $("#range2").hide();
			// // $("#range1").show();
			// // $("#range1 :select, #range2 :select").attr("disabled","disabled");
			// // showApplicatorRange();
			// //$("#product_delivery_select").hide();
			
	// }


	$("#weeks a").click(function(){
		selectWeek($(this).text());
		return false;
	});
	
/*	
	$(this).submit(function(){
		return(formValidate());
	});
*/	

	$("#start_submit").bind("click", function(){
		return formValidate();
	});
	
	$('#dialog').dialog({autoOpen: false});

});


