// JavaScript Document
function ShowAdditional() {
	document.getElementById('AdditionalItems').style.display = 'block';
	document.getElementById('AdditionalItemsLink').style.display = 'none';
	document.getElementById('BasicSearchLink').style.display = 'block'; 
}
        
function HideAdditional() {
	document.getElementById('AdditionalItems').style.display = 'none';
	document.getElementById('AdditionalItemsLink').style.display = 'block'; 
	document.getElementById('BasicSearchLink').style.display = 'none';    	
}




function checkDeliveryMinimum2(status,delivery,dflag,del_min,total) {
	
	if (status == 4 ) {
		alert("This restaurant is not yet ready to take Orders.");
		return false
	}
	else if (status == 2) {
		alert("This restaurant does not take Online Orders. Please call in your Order");
		return false
	}
	else if ( status == 5) {
		alert("This restaurant does not take Online orders. You can only view the Menu");
		return false
	}
	else if ( status == 10) {
		alert("Menu is changing - Online temporarily disabled during change");
		return false
	}
	
	if ( delivery == true) {
	
		if ( dflag == true) {
			if ( total < del_min ) {
				alert("You need " + formatCurrency(del_min-total) + " to meet the " + formatCurrency(del_min) + " delivery minimum for this restaurant.\n" +
				  "Please add more food items to meet the delivery minimum or change the order to Pickup.");
				return false;
			} else {
				//alert("No problem - you have met the minimum, continue sucker");
				//window.location="checkout_details.php" + "?" + getUrl();
				return true;
			}
		}
		else 
			//alert("Restaurant deliverys but flag not set (" + getUrl() + ")");
			//window.location="checkout_details.php" + "?" + getUrl();
			return true;

	}
	else {
		//alert("No delivery, move on...");
		//window.location.replace(getUrl());
		//window.location="checkout_details.php" + "?" + getUrl();
		return true;
	}
}


function checkDeliveryMinimum(status,delivery,dflag,del_min,total) {
	
	if (status == 4 ) {
		alert("This restaurant is not yet ready to take Orders.");
	}
	else if (status == 2) {
		alert("This restaurant does not take Online Orders. Please call in your Order");
	}
	else if ( status == 5) {
		alert("This restaurant does not take Online orders. You can only view the Menu");
	}
	else {
		if ( delivery == true) {
		
			if ( dflag == true) {
				if ( total < del_min ) 
					alert("You need " + formatCurrency(del_min-total) + " to meet the " + formatCurrency(del_min) + " delivery minimum for this restaurant.\n" +
					  "Please add more food items to meet the delivery minimum or change the order to Pickup.");
				else
					//alert("No problem - you have met the minimum, continue sucker");
					window.location="checkout_details.php" + "?" + getUrl();
	
			}
			else 
				//alert("Restaurant deliverys but flag not set (" + getUrl() + ")");
				window.location="checkout_details.php" + "?" + getUrl();
	
		}
		else {
			//alert("No delivery, move on...");
			//window.location.replace(getUrl());
			window.location="checkout_details.php" + "?" + getUrl();
		}
	}
}

function check_restaurant(restaurantid,status) {
	if ( restaurantid == 0 ) {
		alert("You must first select a Restaurant.");
		return false;
	}
	else {
		if (status == 1) {
			return true;
		}
		else if (status = 2) {
			alert("This restaurant does not take Online Orders. Please call in your Order");
			return false;
		}
		else if ( status == 4 ) {
			alert("This restaurant is not yet ready to take Orders");
			return false;
		}
		else if ( status == 5) {
			alert("This restaurant does not take Online orders. You can only view the Menu");
			return false;
		}
		else {
			return true;
		}
	}
}
	
function getUrl() {
	
	var url, restUrl, currentUrl, i1, i2;
	
	currentUrl = window.location.href;
	i1 = currentUrl.indexOf("restaurant_id",1);
		//i1 = currentUrl.indexOf("restaurant_id",1);

	restUrl = currentUrl.substring(i1,currentUrl.length);
//alert("i1=(" + i1 + ") and restUrl=(" + restUrl + ")");
	url = document.location.pathname + "?" + restUrl;
	return restUrl;
	
}

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}









