var menu_imgs = new Array();
menu_imgs[0] = "images/framework/about_f2.gif";
menu_imgs[1] = "images/framework/contact_f2.gif";
menu_imgs[2] = "images/framework/home_f2.gif";
menu_imgs[3] = "images/framework/member_f2.gif";
menu_imgs[4] = "images/framework/order_f2.gif";

function PrintOrderSummary(type)
{
	var print_window = window.open("print_order_summary.php?type=" + type, "menu_popup");
}

function PrintCorpOrderSummary()
{
	var print_window = window.open("print_corp_order_summary.php", "menu_popup");
}

function ToggleStarters(clicked)
{
	var the_form = document.getElementById("order_frm");
	
	var checkboxes = the_form.starter_sel;
	
	for(i=0;i<checkboxes.length;i++)
	{
		if(checkboxes[i].checked && checkboxes[i].value != clicked.value)
			checkboxes[i].checked=false;
	}
	
	return true;
}

function ToggleCarteMain(clicked)
{
	var the_form = document.getElementById("order_frm");
	
	var checkboxes = the_form.carte_main;
	
	for(i=0;i<checkboxes.length;i++)
	{
		if(checkboxes[i].checked && checkboxes[i].value != clicked.value)
			checkboxes[i].checked=false;
	}
	
	return true;
}

function ToggleCarteWine(clicked)
{
	var the_form = document.getElementById("order_frm");
	
	var checkboxes = the_form.carte_wine;
	
	for(i=0;i<checkboxes.length;i++)
	{
		if(checkboxes[i].checked && checkboxes[i].value != clicked.value)
			checkboxes[i].checked=false;
	}
	
	return true;
}

function ToggleCarteExtra(clicked)
{
	var the_form = document.getElementById("order_frm");
	
	var checkboxes = the_form.carte_main;
	
	for(i=0;i<checkboxes.length;i++)
	{
		if(checkboxes[i].checked && checkboxes[i].value != clicked.value)
			checkboxes[i].checked=false;
	}
	
	return true;
}

function ToggleMains(clicked)
{
	var the_form = document.getElementById("order_frm");
	
	var checkboxes = the_form.main_sel;
	
	for(i=0;i<checkboxes.length;i++)
	{
		if(checkboxes[i].checked && checkboxes[i].value != clicked.value)
			checkboxes[i].checked=false;
	}
	
	return true;
}

function ToggleCheese(clicked)
{
	var the_form = document.getElementById("order_frm");
	
	var checkboxes = the_form.cheese_sel;
	
	for(i=0;i<checkboxes.length;i++)
	{
		if(checkboxes[i].checked && checkboxes[i].value != clicked.value)
			checkboxes[i].checked=false;
	}
	
	return true;
}

function ToggleDesserts(clicked)
{
	var the_form = document.getElementById("order_frm");
	
	var checkboxes = the_form.dessert_sel;
	
	for(i=0;i<checkboxes.length;i++)
	{
		if(checkboxes[i].checked && checkboxes[i].value != clicked.value)
			checkboxes[i].checked=false;
	}
	
	return true;
}

function ToggleWines(clicked)
{
	var the_form = document.getElementById("order_frm");
	
	var checkboxes = the_form.wine_sel;
	
	for(i=0;i<checkboxes.length;i++)
	{
		if(checkboxes[i].checked && checkboxes[i].value != clicked.value)
			checkboxes[i].checked=false;
	}
	
	return true;
}

function SelectViewOrder()
{
	var the_list = document.getElementById("order_selection");
	
	if(the_list.options[the_list.selectedIndex].value != -1)
		location.href = "index.php?page=3&vieworder=" + the_list.options[the_list.selectedIndex].value;
}

function OpenMenuPopup(id)
{
	var the_date = document.getElementById("calendar");
	var testvar = the_date.value
	//var print_window = window.open("print_menu.php?menu="+id,"menu_popup");
	var print_window = window.open("print_menu.php?menu=" + id + "&menudate="+ testvar, "menu_popup");
}

function AddCorpMeal()
{
	var selected = document.getElementById("in_meal");
	if(selected.options[selected.selectedIndex].value=="-1")
	{
		alert("You must select a valid option to add to the basket");
		return true;
	}
	
	if(!valid_number("meal_quantity"))
	{
		alert("Please enter a valid quantity then click 'Add to basket'");
		return true;
	}
	
	var quantity = document.getElementById("meal_quantity");
	if(quantity.value <= 0)
	{
		alert("Please specify a quantity");
		return true;
	}
	
	var prod_field = document.getElementById("in_prodID");
	prod_field.value = selected.options[selected.selectedIndex].value;
	
	var quant_field = document.getElementById("in_quantity");
	quant_field.value = quantity.value;
	
	var the_form = document.getElementById("corp_frm");
	the_form.submit();
	
	return true;
}

function AddCorpDrink()
{
	var selected = document.getElementById("in_drink");
	if(selected.options[selected.selectedIndex].value=="-1")
	{
		alert("You must select a valid option to add to the basket");
		return false;
	}
	
	if(!valid_number("drink_quantity"))
	{
		alert("Please enter a valid quantity then click 'Add to basket'");
		return false;
	}
	
	var quantity = document.getElementById("drink_quantity");
	if(quantity.value <= 0)
	{
		alert("Please specify a quantity");
		return false;
	}
	
	var prod_field = document.getElementById("in_prodID");
	prod_field.value = selected.options[selected.selectedIndex].value;
	
	var quant_field = document.getElementById("in_quantity");
	quant_field.value = quantity.value;
	
	var the_form = document.getElementById("corp_frm");
	the_form.submit();
	
	return true;
}

function AddCorpExtra()
{
	var selected = document.getElementById("in_extra");
	if(selected.options[selected.selectedIndex].value=="-1")
	{
		alert("You must select a valid option to add to the basket");
		return false;
	}
	
	if(!valid_number("extra_quantity"))
	{
		alert("Please enter a valid quantity then click 'Add to basket'");
		return false;
	}
	
	var quantity = document.getElementById("extra_quantity");
	if(quantity.value <= 0)
	{
		alert("Please specify a quantity");
		return false;
	}
	
	var prod_field = document.getElementById("in_prodID");
	prod_field.value = selected.options[selected.selectedIndex].value;
	
	var quant_field = document.getElementById("in_quantity");
	quant_field.value = quantity.value;
	
	var the_form = document.getElementById("corp_frm");
	the_form.submit();
	
	return true;
}

function RemoveCorpItem(item_id)
{
	location.href="basket.php?remove_item="+item_id;
}

function preload_menu()	//preloads the images in the menu_imgs array
{
	for(i=0;i<menu_imgs.length;i++)
	{
		temp_img = new Image;
		temp_img.src=menu_imgs[i];
	}
}

function swap_menu_img(dom_obj_id,image_url)	//swap an image's src url
{
	//alert("Swapping "+dom_obj_id+" with "+image_url);

	if(document.getElementById)
		the_obj = document.getElementById(dom_obj_id);
	else
	if(document[dom_obj_id])
		the_obj = document[dom_obj_id];
	
	if(the_obj)
		the_obj.src = image_url;
}

var image_timeout=-1;

function ShowImagePopup(num,e)
{
	var img_preview = document.getElementById("image_preview"+num);
		
	if(img_preview)
	{
		if(img_preview.src != "" && image_timeout==-1)
		{
			image_timeout = setTimeout(function(){
				var img_preview = document.getElementById("image_preview"+num);
					img_preview.style.display = 'block';
			},1000);
		}
	}
}

function HideImagePopup(num)
{
	clearTimeout(image_timeout);
	image_timeout=-1;

	var img_preview = document.getElementById("image_preview"+num);
	if(img_preview)
		img_preview.style.display = 'none';
}

function ClickForgotPass()
{
	var usr_in = document.getElementById("in_username");
	
	if(usr_in.value.length==0)
		alert("To retreive your password, please enter your username then click the 'Forgotten Password' link");
	else
		location.href = "retreive.php?user="+usr_in.value;
}

function is_empty(field)
{
	the_field = document.getElementById(field);
	
	if(the_field.value=="")
		return true;
	else
		return false;
}

function is_not_empty(field)
{
	the_field = document.getElementById(field);
	
	if(the_field.value=="")
		return false;
	else
		return true;
}

function matches_expressions(ex_ar,check_against)
{
	for(i=0;i<ex_ar.length;i++)
	{
		var re = new RegExp(ex_ar[i]);

		if(check_against.match(re))
			return true;
	}
	return false;
}

function valid_postcode(field_id)
{
	var valid_codes_regex = new Array();
	
	var alpha = "[A-Z]";
	var num = "[0-9]";
	
	valid_codes_regex[0] = "^" + alpha + num + " ?" + num + alpha + alpha + "$";
	valid_codes_regex[1] = "^" + alpha + num + num + " ?" + num + alpha + alpha + "$";
	valid_codes_regex[2] = "^" + alpha + alpha + num + " ?" + num + alpha + alpha + "$";
	valid_codes_regex[3] = "^" + alpha + alpha + num + num + " ?" + num + alpha + alpha + "$";
	valid_codes_regex[4] = "^" + alpha + num + alpha + " ?" + num + alpha + alpha + "$";
	valid_codes_regex[5] = "^" + alpha + alpha + num + alpha + " ?" + num + alpha + alpha + "$";
	
	var the_obj = document.getElementById(field_id);
	if(the_obj)
	{
		the_obj.value = the_obj.value.toUpperCase();
		
		if(matches_expressions(valid_codes_regex,the_obj.value))
			return true;
	}
	
	return false;
}

function valid_phone(field_id)
{
	var valid_phone_exp = new Array();
	valid_phone_exp[0] = "^[0-9][0-9 ]*$";
	
	var the_obj = document.getElementById(field_id);
	if(the_obj)
		if(matches_expressions(valid_phone_exp,the_obj.value) && the_obj.value.length>6)
			return true;
			
	return false;
}

function valid_email(field_id)
{
	var valid_email_exp = new Array();
	valid_email_exp[0] = "^[a-zA-z.0-9\-\_]+@{1}[a-zA-z0-9\-\_]+[.]{1}[a-zA-z.0-9\-\_]+$";
		
	var the_obj = document.getElementById(field_id);
		if(the_obj)
			if(matches_expressions(valid_email_exp,the_obj.value))
				return true;
				
	return false;
}

function valid_username(field_id)
{
	var valid_username_exp = new Array();
	valid_username_exp[0] = "^[A-Za-z0-9._]+$";
		
	var the_obj = document.getElementById(field_id);
		if(the_obj)
			if(matches_expressions(valid_username_exp,the_obj.value))
				return true;
				
	return false;
}

function valid_password(field_id)
{
	var the_obj = document.getElementById(field_id);
	if(the_obj)
		if(the_obj.value.length<5)
			return false;
				
	return true;
}

function valid_number(field_id)
{
	var valid_number_exp = new Array();
	valid_number_exp[0] = "^[0-9]+$";

	var the_obj = document.getElementById(field_id);
	
	if(the_obj)
		if(matches_expressions(valid_number_exp,the_obj.value))
			return true;

	return false;
}

function equal_values(field_1,field_2)
{
	var the_obj1 = document.getElementById(field_1);
	var the_obj2 = document.getElementById(field_2);
		
	if(the_obj1 && the_obj2)
		if(the_obj1.value == the_obj2.value)
			return true;
			
	return false;
}

function submit_form(form_id)
{
	var the_form=document.getElementById(form_id);
	
	if(the_form)
		the_form.submit();
}

function field_exists(field_id)
{
	var the_obj = document.getElementById(field_id);
	
	if(the_obj)
		return true;
	else
		return false;
}


/*
function ValidateHouseholdAmmend()
{
	var error_title = "There is a problem with the information you have entered\n\n";
		
	var error_msg = "";

	var error_last = "\nPlease enter the above information correctly to continue";

	if(is_empty("in_forename"))
		error_msg += "Please enter your forename\n";

	if(is_empty("in_surname"))
		error_msg += "Please enter your surname\n";

	if(is_empty("in_addr1"))
		error_msg += "Please enter your address line 1\n";

	if(is_empty("in_city"))
		error_msg += "Please enter your town / city\n";

	if(is_empty("in_postcode"))
		error_msg += "Please enter your postcode\n";
	else
		if(!valid_postcode("in_postcode"))
			error_msg += "Please enter a valid postcode\n";

	if(is_empty("in_nodaysstock"))
	{
		var the_obj = document.getElementById("in_nodaysstock");
		the_obj.value = 1;
	}
	else
		if(!valid_number("in_nodaysstock"))
			error_msg += "Please enter a valid number of days for stock delivery\n";

	if(is_empty("in_homephone"))
		error_msg += "Please enter your home telephone number\n";
	else
		if(!valid_phone("in_homephone"))
			error_msg += "Please enter a valid home telephone number\n";

	if(!is_empty("in_mobile"))
		if(!valid_phone("in_mobile"))
			error_msg += "Please enter a valid mobile number\n";

	if(is_empty("in_email"))
		error_msg += "Please enter your email address\n";
	else
		if(!valid_email("in_email"))
			error_msg += "Please enter a valid email address\n";
			
	if(field_exists("in_people"))
		if(!is_empty("in_people"))
			if(!valid_number("in_people"))
				error_msg += "Please enter a valid number of people in this household";
				
	if(field_exists("in_nodays"))
		if(!is_empty("in_nodays"))
			if(!valid_number("in_nodays"))
				error_msg += "Please enter a valid value for No. days stock to deliver";

	if(!is_empty("in_password1"))
	{
		if(!equal_values("in_password1","in_password2"))
			error_msg += "Passwords do not match. Please re-enter and confirm your password\n";
		else
		{
			if(!valid_password("in_password1"))
				error_msg += "Password must be 5 characters or more\n";
		}
	}

	if(error_msg.length>0)
	{
		alert(error_title+error_msg+error_last);
	}
	else
	{
		submit_form("register_form");
	}
}
*/
function ValidateHouseholdAmmend()
{
	var error_title = "There is a problem with the information you have entered\n\n";
		
	var error_msg = "";

	var error_last = "\nPlease enter the above information correctly to continue";

	if(is_empty("in_forename"))
		error_msg += "Please enter your forename\n";

	if(is_empty("in_surname"))
		error_msg += "Please enter your surname\n";

	if(is_empty("in_addr1"))
		error_msg += "Please enter your address line 1\n";

	if(is_empty("in_city"))
		error_msg += "Please enter your town / city\n";

	if(is_empty("in_postcode"))
		error_msg += "Please enter your postcode\n";
	else
		if(!valid_postcode("in_postcode"))
			error_msg += "Please enter a valid postcode\n";


	if( is_not_empty("in_del_city") || is_not_empty("in_del_addr1") ||  is_not_empty("in_del_postcode") || is_not_empty("in_del_addr2")) {
		//alert ("yeah");
		if(is_empty("in_del_postcode"))
			error_msg += "Please enter your delivery postcode\n";
		else
			if(!valid_postcode("in_del_postcode"))
				error_msg += "Please enter a valid delivery postcode\n";
		
		if(is_empty("in_del_addr1"))
			error_msg += "Please enter your delivery address line 1\n";
		
		if(is_empty("in_del_city"))
			error_msg += "Please enter your delivery town / city\n";

	}




	if(is_empty("in_nodaysstock"))
	{
		var the_obj = document.getElementById("in_nodaysstock");
		the_obj.value = 1;
	}
	else
		if(!valid_number("in_nodaysstock"))
			error_msg += "Please enter a valid number of days for stock delivery\n";

	if(is_empty("in_homephone"))
		error_msg += "Please enter your home telephone number\n";
	else
		if(!valid_phone("in_homephone"))
			error_msg += "Please enter a valid home telephone number\n";

	if(!is_empty("in_mobile"))
		if(!valid_phone("in_mobile"))
			error_msg += "Please enter a valid mobile number\n";

	if(is_empty("in_email"))
		error_msg += "Please enter your email address\n";
	else
		if(!valid_email("in_email"))
			error_msg += "Please enter a valid email address\n";
			
	if(field_exists("in_people"))
		if(!is_empty("in_people"))
			if(!valid_number("in_people"))
				error_msg += "Please enter a valid number of people in this household";
				
	if(field_exists("in_nodays"))
		if(!is_empty("in_nodays"))
			if(!valid_number("in_nodays"))
				error_msg += "Please enter a valid value for No. days stock to deliver";

	if(!is_empty("in_password1"))
	{
		if(!equal_values("in_password1","in_password2"))
			error_msg += "Passwords do not match. Please re-enter and confirm your password\n";
		else
		{
			if(!valid_password("in_password1"))
				error_msg += "Password must be 5 characters or more\n";
		}
	}

	if(error_msg.length>0)
	{
		alert(error_title+error_msg+error_last);
	}
	else
	{
		submit_form("register_form");
	}
}

/*
function ValidateRegistration()
{
	var error_title = "There is a problem with the information you have entered\n\n";
	
	var error_msg = "";
	
	var error_last = "\nPlease enter the above information correctly to register";
	
	if(is_empty("in_forename"))
		error_msg += "Please enter your forename\n";
		
	if(is_empty("in_surname"))
		error_msg += "Please enter your surname\n";
		
	if(is_empty("in_addr1"))
		error_msg += "Please enter your address line 1\n";
		
	if(is_empty("in_city"))
		error_msg += "Please enter your town / city\n";
		
	if(is_empty("in_postcode"))
		error_msg += "Please enter your postcode\n";
	else
		if(!valid_postcode("in_postcode"))
			error_msg += "Please enter a valid postcode\n";
			
	if(is_empty("in_nodaysstock"))
	{
		var the_obj = document.getElementById("in_nodaysstock");
		the_obj.value = 1;
	}
	else
		if(!valid_number("in_nodaysstock"))
			error_msg += "Please enter a valid number of days for stock delivery\n";
			
	if(is_empty("in_homephone"))
		error_msg += "Please enter your home telephone number\n";
	else
		if(!valid_phone("in_homephone"))
			error_msg += "Please enter a valid home telephone number\n";
			
	if(!is_empty("in_mobile"))
		if(!valid_phone("in_mobile"))
			error_msg += "Please enter a valid mobile number\n";
			
	if(is_empty("in_email"))
		error_msg += "Please enter your email address\n";
	else
		if(!valid_email("in_email"))
			error_msg += "Please enter a valid email address\n";
		
	if(is_empty("in_username"))
		error_msg += "Please enter a username\n";
	else
		if(!valid_username("in_username"))
			error_msg += "Username can only contain alphanumeric characters, full-stops and underscores (_)\n";
			
	if(is_empty("in_password1"))
		error_msg += "Please enter a password (at least 5 characters)\n";
	else
	if(!valid_password("in_password1"))
		error_msg += "Password must be 5 characters or more\n";
		
	if(is_empty("in_password2"))
		error_msg += "Please confirm password\n";
	else
	if(!equal_values("in_password1","in_password2"))
		error_msg += "Passwords do not match. Please re-enter and confirm password\n";
		
	
		
	if(error_msg.length>0)
	{
		alert(error_title+error_msg+error_last);
	}
	else
	{
		submit_form("register_form");
	}
}

*/

function ValidateRegistration()
{
	var error_title = "There is a problem with the information you have entered\n\n";
	
	var error_msg = "";
	
	var error_last = "\nPlease enter the above information correctly to register";
	
	if(is_empty("in_forename"))
		error_msg += "Please enter your forename\n";
		
	if(is_empty("in_surname"))
		error_msg += "Please enter your surname\n";
		
	if(is_empty("in_addr1"))
		error_msg += "Please enter your address line 1\n";
		
	if(is_empty("in_city"))
		error_msg += "Please enter your town / city\n";
		
	if(is_empty("in_postcode"))
		error_msg += "Please enter your postcode\n";
	else
		if(!valid_postcode("in_postcode"))
			error_msg += "Please enter a valid postcode\n";
	
	
	if( is_not_empty("in_del_city") || is_not_empty("in_del_addr1") ||  is_not_empty("in_del_postcode") || is_not_empty("in_del_addr2")) {
		//alert ("yeah");
		if(is_empty("in_del_postcode"))
			error_msg += "Please enter your delivery postcode\n";
		else
			if(!valid_postcode("in_del_postcode"))
				error_msg += "Please enter a valid delivery postcode\n";
		
		if(is_empty("in_del_addr1"))
			error_msg += "Please enter your delivery address line 1\n";
		
		if(is_empty("in_del_city"))
			error_msg += "Please enter your delivery town / city\n";

	}
	
	if(is_empty("in_nodaysstock"))
	{
		var the_obj = document.getElementById("in_nodaysstock");
		the_obj.value = 1;
	}
	else
		if(!valid_number("in_nodaysstock"))
			error_msg += "Please enter a valid number of days for stock delivery\n";
			
	if(is_empty("in_homephone"))
		error_msg += "Please enter your home telephone number\n";
	else
		if(!valid_phone("in_homephone"))
			error_msg += "Please enter a valid home telephone number\n";
			
	if(!is_empty("in_mobile"))
		if(!valid_phone("in_mobile"))
			error_msg += "Please enter a valid mobile number\n";
			
	if(is_empty("in_email"))
		error_msg += "Please enter your email address\n";
	else
		if(!valid_email("in_email"))
			error_msg += "Please enter a valid email address\n";
		
	if(is_empty("in_username"))
		error_msg += "Please enter a username\n";
	else
		if(!valid_username("in_username"))
			error_msg += "Username can only contain alphanumeric characters, full-stops and underscores (_)\n";
			
	if(is_empty("in_password1"))
		error_msg += "Please enter a password (at least 5 characters)\n";
	else
	if(!valid_password("in_password1"))
		error_msg += "Password must be 5 characters or more\n";
		
	if(is_empty("in_password2"))
		error_msg += "Please confirm password\n";
	else
	if(!equal_values("in_password1","in_password2"))
		error_msg += "Passwords do not match. Please re-enter and confirm password\n";
		
	
		
	if(error_msg.length>0)
	{
		alert(error_title+error_msg+error_last);
	}
	else
	{
		submit_form("register_form");
	}
}
/*function reloadCorporateMenu()
{
	var the_date = document.getElementById("calendar");
		
	exp_ar = new Array();
	exp_ar[0] = "^[0-3][0-9]-[0,1][0-9]-20[0-9]{2}$";

	if(matches_expressions(exp_ar,the_date.value))
	{
		var today = new Date();

		var sel_date = new Date();
		sel_date.setMonth(the_date.value.substr(3,2)-1,the_date.value.substr(0,2));
		sel_date.setYear(the_date.value.substr(6,4));

		if(today.getTime() < sel_date.getTime())
		{
			//reload the page, passing a different date
			location.href = "index.php?page=3&sub_page=1&date="+the_date.value;
		}
		else
		{
			alert("The selected order date must be valid and at least one day in advance");
		}
	}
}*/

function reloadCorporateMenu(cal)
{
	var the_date = document.getElementById("calendar");
	
	exp_ar = new Array();
	exp_ar[0] = "^[0-3][0-9]-[0,1][0-9]-20[0-9]{2}$";
	
	if(matches_expressions(exp_ar,the_date.value))
	{
		var today = new Date();
		
		if(today.getHours() >= 17)
		{
			cutoff=today.getTime()+(60*60*24*1000*2);
			today_str=(today.getDate()+2) + "-" + (today.getMonth()+1) + "-" + today.getFullYear();
		}
		else
		{
			cutoff=today.getTime()+(60*60*24*1000);
			today_str=(today.getDate()+1) + "-" + (today.getMonth()+1) + "-" + today.getFullYear();
		}
			
		var sel_date = new Date();
		sel_date.setMonth(the_date.value.substr(3,2)-1,the_date.value.substr(0,2));
		sel_date.setYear(the_date.value.substr(6,4));
		
		if(sel_date.getTime() < cutoff)
		{
			alert("Please select a later date");
			the_date.value=today_str;
		}
		else
		if(sel_date.getTime()-(60*60*24*28*3*1000) > today.getTime())
		{
			alert("Orders cannot be placed for more than three months in advance");
			the_date.value=today_str; 
		}
		else
			location.href = "index.php?page=3&sub_page=1&date="+the_date.value;
	}
}


/*
function reloadHouseholdMenu(cal)
{
	var the_date = document.getElementById("calendar");
	
	exp_ar = new Array();
	exp_ar[0] = "^[0-3][0-9]-[0,1][0-9]-20[0-9]{2}$";
	
	if(matches_expressions(exp_ar,the_date.value))
	{
		var today = new Date();
		
		if(today.getHours() >= 17)
		{
			cutoff=today.getTime()+(60*60*24*1000*2);
			today_str=(today.getDate()+2) + "-" + (today.getMonth()+1) + "-" + today.getFullYear();
		}
		else
		{
			cutoff=today.getTime()+(60*60*24*1000);
			today_str=(today.getDate()+1) + "-" + (today.getMonth()+1) + "-" + today.getFullYear();
		}
			
		var sel_date = new Date();
		sel_date.setMonth(the_date.value.substr(3,2)-1,the_date.value.substr(0,2));
		sel_date.setYear(the_date.value.substr(6,4));
		
		if(sel_date.getTime() < cutoff)
		{
			alert("Please select a later date");
			the_date.value=today_str;
		}
		else
		if(sel_date.getTime()-(60*60*24*28*3*1000) > today.getTime())
		{
			alert("Orders cannot be placed for more than three months in advance");
			the_date.value=today_str; 
		}
		else
			location.href = "index.php?page=3&sub_page=1&date="+the_date.value;
	}
}
*/

function reloadHouseholdMenu(cal)
{
	var the_date = document.getElementById("calendar");
	//alert("this is what we're doing");
	
	exp_ar = new Array();
	exp_ar[0] = "^[0-3][0-9]-[0,1][0-9]-20[0-9]{2}$";
	
	if(matches_expressions(exp_ar,the_date.value))
	{
		var today = new Date();
		
		if(today.getHours() >= 12.30)
		{
			//Javascript time is in milliseconds, so 60 seconds, 60 minutes, 24 hours, 1000 milliseconds, 2 days
			//This will become cutoff=today.getTime()+(60*60*24*1000*1); as we can order tomorrow
			//cutoff=today.getTime()+(60*60*24*1000*2);
			cutoff=today.getTime()+(60*60*24*1000*1);
			//today_str=(today.getDate()+2) + "-" + (today.getMonth()+1) + "-" + today.getFullYear();
			today_str=(today.getDate()+1) + "-" + (today.getMonth()+1) + "-" + today.getFullYear();
		}
		else
		{
			//Javascript time is in milliseconds, so 60 seconds, 60 minutes, 24 hours, 1000 milliseconds, 1 day	
			//This becomes simply cutoff=today.getTime(); as we can now order today, as long as it's before 12.30
			//cutoff=today.getTime()+(60*60*24*1000);
			cutoff=today.getTime();
			//today_str=(today.getDate()+1) + "-" + (today.getMonth()+1) + "-" + today.getFullYear();
			today_str=(today.getDate()) + "-" + (today.getMonth()+1) + "-" + today.getFullYear();
		}
			
		var sel_date = new Date();
		sel_date.setMonth(the_date.value.substr(3,2)-1,the_date.value.substr(0,2));
		sel_date.setYear(the_date.value.substr(6,4));
		
		if(sel_date.getTime() < cutoff)
		{
			alert("Please select a later date");
			the_date.value=today_str;
			//alert(today_str);
		}
		else
		if(sel_date.getTime()-(60*60*24*28*3*1000) > today.getTime())
		{
			alert("Orders cannot be placed for more than three months in advance");
			the_date.value=today_str; 
			//alert(today_str);
		}
		else
			location.href = "index.php?page=3&sub_page=1&date="+the_date.value;
	}
}
function ClearOrderItem()
{
	var the_frm = document.getElementById("order_frm");
	
	if(the_frm)
		the_frm.reset();
}

function Checkout()
{
	var num_items = document.getElementById("basket_items");
	if(num_items.value == 0)
		alert("No items in basket. Please select items from the menu and click 'Add to Basket' to order food.");
	else
	{
		//location.href = "index.php?page=3&sub_page=1&action=checkout";
		location.href = "index.php?page=9&sub_page=1&action=checkout";
	}
}

function CorpCheckout()
{
	var num_items = document.getElementById("basket_items");
	if(num_items.value == 0)
		alert("No items in basket. Please select items from the menu and click 'Add to Basket' to order food.");
	else
	{
		var checkout=document.getElementById("checkout_frm");
		checkout.submit();
	}
}

function AddToBasket()
{
	var the_frm = document.getElementById("order_frm");
	
	the_frm.submit();
}

function ClearQuantityField()
{
	var field=document.getElementById("in_quantity");
	
	if(field.value=="Quantity")
		field.value="";
}
