$(document).ready(function () {

	var orderFor = $("#order_hidden").val();
	
	var orderSelf = 0;
	var orderParents = 0;
	var orderOther = 0;

	var orderSelfText = "";
	var orderParentsText = "";
	var orderOtherText = "";
	
	$("#order_self").click(function() {

		if(orderSelf == 0) {
			orderSelfText = "| Myself or Spouse |";
			orderFor = orderSelfText + orderParentsText + orderOtherText;
			orderSelf = 1;
		} else if(orderSelf == 1) {
			orderSelfText = "";
			orderFor = orderSelfText + orderParentsText + orderOtherText;
			orderSelf = 0;
		}

		$("#order_hidden").val(orderFor);

	});

	$("#order_parents").click(function() {

		if(orderParents == 0) {
			orderParentsText = "| Parents |";
			orderFor = orderSelfText + orderParentsText + orderOtherText;
			orderParents = 1;
		} else if(orderParents == 1) {
			orderParentsText = "";
			orderFor = orderSelfText + orderParentsText + orderOtherText;
			orderParents = 0;
		}

		$("#order_hidden").val(orderFor);

	});

	$("#order_other").click(function() {

		if(orderOther == 0) {
			orderOtherText = "| Other |";
			orderFor = orderSelfText + orderParentsText + orderOtherText;
			orderOther = 1;
		} else if(orderOther == 1) {
			orderOtherText = "";
			orderFor = orderSelfText + orderParentsText + orderOtherText;
			orderOther = 0;
		}

		$("#order_hidden").val(orderFor);

	});
	
	// Submit div
	$(".order-now")
		.html("Order Now")
		.show()
		.click(function(){
			var frm = $(this).closest('form');
			
			var err = 0;

			var checkErr = 0;
			
			if ($("#first_name").val() == '')		err = 1;
			if ($("#last_name").val() == '')		err = 1;
			if ($("#street_address").val() == '')	err = 1;
			if ($("#city").val() == '')				err = 1;
			if ($("#zip").val() == '')				err = 1;
			if ($("#reference_dropdown").val() == 'Choose One...') err = 1;
			if ($("#order_self").val() == '') checkErr = checkErr + 1;
			if ($("#order_parents").val() == '') checkErr = checkErr + 1;
			if ($("#order_other").val() == '') checkErr = checkErr + 1;

			if(checkErr == 3) {
				err = 1;
			}
			
			if (err == 1) {
				$("#msg")
					.hide()
					.html("<h2 class='error-msg'>Please complete all fields before ordering.</h2>")
					.slideDown();
				$(".es #msg")
					.html("<h2 class='error-msg'>Por favor, llene todos los espacios antes de pedir su paquete.</h2>");
			} else {
				frm.submit();
			}
			
		});
	$(".es .order-now")
		.html("PÃDALO AHORA");
});
