//==============================================================
//  SHOW HIDE CATEGORIES
//==============================================================


function menuOrderShowCat(category)
{
  if(category!=0)
  {
   if(window.menuOrderShowCatCurrent != null)  
   {
    document.getElementById('category_' + window.menuOrderShowCatCurrent).style.display = 'none';
   }
   else
   {
    document.getElementById('chooseCategoryAssist').style.display = 'none';
   }
   window.menuOrderShowCatCurrent = category;   
   document.getElementById('category_' + category).style.display = 'block';
   window.menuOrderShowCatCurrent = category;
  }
}

function menuOrderShowHelp(category)
{
  document.getElementById('orderHelpBox').style.display = 'block';
  document.getElementById('showOrderHelpBox').style.display = 'none';
}

function menuOrderFinaliseOrder(category)
{
  document.getElementById('orderCustomerDetails').style.display = 'block';
  document.getElementById('finaliseOrder').style.display = 'none';
  document.getElementById('chooseCategory').style.display = 'none';
  document.getElementById('category_' + window.menuOrderShowCatCurrent).style.display = 'none';
}

function menuOrderFinaliseOrderUndo(category)
{
  document.getElementById('orderCustomerDetails').style.display = 'none';
  document.getElementById('finaliseOrder').style.display = 'block';
  document.getElementById('chooseCategory').style.display = 'block';
  document.getElementById('chooseCategoryAssist').style.display = 'block';
  document.getElementById('category_' + window.menuOrderShowCatCurrent).style.display = 'block';
}



//==============================================================
//  SHOW LOADING IMAGE ON FORM
//==============================================================

function showLoadingImage(side) {
	document.getElementById('submitbox1' + window.customerBoxSide).style.display = 'none';
	document.getElementById('submitbox2' + window.customerBoxSide).style.display = 'block';
	setTimeout('document.images["loading"].src = "images/loading.gif"', 1);
}


//==============================================================
//  VALIDATE SEND ORDER
//==============================================================

function setCustomerBoxSide(side) {
	window.customerBoxSide = side;
}


//==============================================================
//  VALIDATE SEND ORDER
//==============================================================
function menuOrderSendOrderValidate(form)
{
	var form = document.form;
	var valid = true;
	var theErrorAlert = "";
	var i = 0;
	
	// Check Username
	var check = "userName";
	var theError = " - Customer Name\n";
	var theErrorAlert = theErrorAlert + checkEmpty(check,theError);
	
	var check = "userEmail";
	var theError = " - Invalid email address\n";
	var theErrorAlert = theErrorAlert + checkEmail(check,theError);
	
	var check = "userPhone";
	var theError = " - Phone number required\n";
	var theErrorAlert = theErrorAlert + checkEmpty(check,theError);
	
	if (window.customerBoxSide == "Right") { theErrorAlert=""; }

	if (theErrorAlert != "")
		{
		msg = "Please fill the required fields\n";
		alert(msg + theErrorAlert);
		return false;
		}
	if (valid)
		{
		showLoadingImage();
		return true;
		}
	else {
		msg = "Please fill the required fields";
		alert ( msg );
		return false;
		}
}

function checkEmpty(check,theError) {
	var theField = document.getElementById(check).value;
	if (theField == "")
		{
		return theError;
		}
		else
		{
		return "";
		}
}

function checkEmail(check,theError) {
	var theField = document.getElementById(check).value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(theField)) { return ""; } else { return theError; }
}
