/********************************** Checkout Page **************************************/
/**** On first page display, decide form (guest/register) to show for new customers ****/
$(function() {
	$('.checkout_createacct').click(function() {
		if ( $('input[name=guestregister]:checked').val() == 'guest') {
			$('#new_or_register').css('display','none');		// hide initial choice
			$('#openguest').css('display','block');				// show guest form
			$('#openshipquestion').css('display','block');		// show shipping question
			$('#openallfields').css('display','block');			// show rest of the fields
			$('#statusdisplay').html('<b>Checkout as a guest</b>');	// update status display
			$("input[name=usertype]").val('guest');				// set user type
		}
		else {
			$('#new_or_register').css('display','none');		// hide initial choice
			$('#openguest').css('display','block');				// show guest form
			$('#openregister').css('display','block');			// show register form
			$('#openshipquestion').css('display','block');		// show shipping question
			$('#openallfields').css('display','block');			// show rest of the fields
			$('#statusdisplay').html('<b>Creating a new account</b>');	// update status display
			$("input[name=usertype]").val('register');			// set user type
		}
	});
});
/******* On first page display, look up user account information if needed **********/
$(function() {
	$('#lookupaccount').click(function() {
		var email = $("input[name=email]").val();
		var password = $("input[name=password]").val();
		var dataString = 
		'email=' + email + 
		'&password=' + password;
		$.ajax( {
			type: "POST",
			url: "loginlookup.php",
			data: dataString,
			success: function(html) {
				$('#new_or_register').css('display','none');
				$("#openguest").html(html);							// Update guest form & ....
				$('#openguest').css('display','block');				// display it.
				$('#statusdisplay').html('<b>Returning customer</b>');	// update status display
				$('#openallfields').css('display','block');			// show rest of the fields
				$("input[name=usertype]").val('returning');			// set user type
			}
		});
	});
});
/************ Decide whether or not to show shipping form ***********/
$(function() {
	$("input[name=shiptobill]").click(function() {
		if ($(this).not(':checked') ) {
			$('#openshipform').css('display','block');
		}
		if ($(this).is(':checked') ) {
			$('#openshipform').css('display','none');
		}
	});
});

/********************* Order page farmer & chef popup ********************/
$(function() {
	$('#frmnchef').click(function() {
		if ( $('#farmernchefpopup').css('display') == 'none' ) {
			$('#farmernchefpopup').fadeIn("slow");
		}
		else {
			$('#farmernchefpopup').css("display", "none");
		}
	});
});

