noSunday = function(date){
	var day = date.getDay();
	if(isPickupOrDelivery != 'pickup')
	{
	    return [(day > 0), ''];
	}
	else
	{
	    return [true, day];
	}
};
$(document).ready(function(){
	$('#print-order').click(function(){
        window.open(this.href,'','left=20,top=20,width=850,toolbar=0,menubar=1,resizable=0,scrollbars=1');
        return false;
    });
	var urlForImage = '';
	if (typeof(imageURL) != 'undefined')
	{
		urlForImage = imageURL;
		$('#order_delivery_date').datepicker({
		    changeMonth: true,
		    changeYear: true,
		    showOn: 'button',
		    buttonImage: urlForImage,
		    buttonImageOnly: true,
			showButtonPanel: true,
			multi: false,
			dateFormat: 'mm-dd-yy',
			beforeShowDay: noSunday	
		});
	}
	
	$('#order_account_1').change(function(){
		$('#with-account').show();
		$('#without-account').hide();
	});
	$('#order_account_0').change(function(){
		$('#with-account').hide();
		$('#without-account').show();
	});
	
	$('#order_destination_1').change(function(){
		$('#business-name-holder').show();
		$('#address').html('Business Address');
		$('#suite').html('Floor');
	});
	$('#order_destination_2').change(function(){
		$('#business-name-holder').hide();
		$('#address').html('Address');
		$('#suite').html('Apt.');
	});
	
	if(typeof businessSelected != 'undefined' && businessSelected == false) {
		$('#business-name-holder').hide();
		$('#address').html('Address');
		$('#suite').html('Apt.');
	}
	
	$('#order-picker').change(function(){
		if (messengerId == $('#order-picker').val())
			$('#messenger-details').show();
		else 
			$('#messenger-details').hide();
	});
	
	if(typeof displayMessengerDetails != 'undefined' && displayMessengerDetails == true) {
		$('#messenger-details').show();
	}
	if(typeof loginSelected != 'undefined' && loginSelected == false) {
		$('#order_account_0').trigger('change');
	}
	
	$('#same-person-ordering').bind("click", function(){		
		if($('#same-person-ordering')[0].checked == true) {
			arOldPersonOrdering['full_name'] = $('#order_delivery_for').val();
			arOldPersonOrdering['phone_number'] = $('#order_delivery_phone').val();
			$('#order_delivery_for').val(arPersonOrdering['full_name']);
			$('#order_delivery_phone').val(arPersonOrdering['phone_number']);
		}
		else {
			$('#order_delivery_for').val(arOldPersonOrdering['full_name']);
			$('#order_delivery_phone').val(arOldPersonOrdering['phone_number']);
		}
	});
	
	$('#delivery-fee-icon').click(function() {
		togglePopup('deliveryFeeInfo', new Array('gratuityInfo'));
	});
	
	$('#gratuity-icon').click(function() {
		togglePopup('gratuityInfo', new Array('deliveryFeeInfo'));
	});
	
	if($('#order_credit_card_number').length > 0)
	{
		$('#order_credit_card_number').numeric();
	}
});
