// JavaScript Document
// JavaScript Document
function ftn_menuItem(strTitle, strPrice, strDescription, menuItemClass){
	var strCurrency = '&pound;';
	if (!menuItemClass){
		menuItemClass = 'menuItem';
	}else{
		strCurrency = '<br />&pound;';
	}
	
	if(!strPrice)
		strCurrency = '';
	var strMenuItem = '<div class="' + menuItemClass + '" style="width:249px;cursor:pointer" onClick="ftnAddToOrder(\'' + strTitle + '\');">' +
						'<div class="menuItemTitle" style="width:200px;" >' + strTitle + '</div>' + 
						'<div class="menuItemPrice" style="width:49px;">'  + strCurrency + strPrice + '</div>' + 
						'<div class="menuItemDescription" style="width:249px;"><img src="/images/global/labesi.png" width="210" height="4"></div>' +
						'<div class="menuItemDescription" style="width:249px; text-align:left">' + strDescription + '</div>' + 
						'<div class="menuItemDescription" style="width:249px;"><img src="/images/global/labesi.png" width="210" height="8"></div>' +
					'</div>';
	return strMenuItem;				
				
}
function ftn_InsertMenu(menuNumber){
	
	var d = document.getElementById('thefood');
  
	var strItem1 = '<img src="images/menu/menusStarters.png"  alt="Starters">' +
					'<div class="menuItemDescription" style="width:249px;"><img src="/images/global/labesi.png" width="210" height="6"></div>' +
					ftn_menuItem('GARLIC PIZZA WITH CHEESE', '2.50', 'Freshl Bread with a cheese topping') + 
					ftn_menuItem('GARLIC PIZZA BREAD', '2.40', 'Freshly made Pizza Bread with Tomato sauce and garlic') + 
					ftn_menuItem('BRUSCHETTA', '1.95', 'Toasted Italian bread with fresh tomato, garlic, olive oil and basil') + 
					ftn_menuItem('CALAMARI FRITTI', '3.50', 'Deep fried calamari with homemade tartar sauce') + 
					ftn_menuItem('FUNGHETTI  ALL CREMA', '3.10', 'Garlic mushrooms in cream and white wine sauce') + 
					ftn_menuItem('ANTIPASTO LA BESI', '4.50', 'With boscalola olives, a selection of salami, marinated mixed pickled vegetables') +
					ftn_menuItem('MOZZARELLA FRITTA', '4.30', 'Deep fried mozzarella wrapped in Parma ham with rocket and tomato gramolata') + 
					ftn_menuItem('INSALATA TRICOLORE', '3.50', 'Fresh tomato, avocado, mozzarella, fresh basil with olive oil') + 
					ftn_menuItem('COCKTAIL DI GAMBERETTI', '4.25', 'Prawns served with lettuce, Marie-Rose sauce');
					
	
					
	var strItem2 = '<img src="images/menu/menusPizzas.png"  alt="Pizzas">' +
					'<div class="menuItemDescription" style="width:249px;"><img src="/images/global/labesi.png" width="249" height="6"></div>' +
					'<div class="menuItemDescription" style="width:249px;"><img src="/images/global/labesi.png" width="249" height="6"></div>' +
					ftn_menuItem('FRANCESCANA PIZZA', '6.25', 'Tomato Sauce, Mozzarella cheese, parma ham and fresh rocket.') +
					ftn_menuItem('PIZZA BELLA', '6.20', 'Tomato sauce, Mozzarella cheese, Chicken, Sweetcorn and Fresh Basil') +
					ftn_menuItem('BOLOGNESE PIZZA', '5.95', 'Mozzarella cheese,Tomato Sauce, Bolognese Sauce and Onions') +
					ftn_menuItem('CALZONE KIEV', '6.10', 'Mozzarella cheese, Tomato Sauce, Mushrooms, Garlic, Chicken and Ham') +
					ftn_menuItem('MARGHERITA', '4.50', 'Mozzarella, tomato sauce and fresh basil') +
					ftn_menuItem('NAPOLI', '4.70', 'Mozzarella, tomato sauce, anchovies, capers, and black olives') +
					ftn_menuItem('ALLA FUNGHI', '4.85', 'Tomato sauce, mozzarella cheese, fresh mushrooms') +
					ftn_menuItem('TROPICANA', '5.80', 'Tomato sauce, mozzarella cheese, ham and pineapple') +
					ftn_menuItem('PIZZA ROSA', '5.65', 'Tomato sauce, mozzarella cheese, onions and tuna.') +
					ftn_menuItem('MARINARA', '6.35', 'Tomato sauce, mozzarella cheese, prawns, calamari, clams and olives') +
					ftn_menuItem('LA BESI PIZZA', '6.55', 'Our Chef\'s own irresistible recipe, a little bit of everything and a lot of love') +
					ftn_menuItem('CALZONE', '6.20', 'Folded pizza with mozzarella cheese, tomato sauce, ham and salami pepperoni and oregano') +
					ftn_menuItem('QUATTRO FORMAGGI', '6.95', 'Tomato sauce with four cheeses') +
					ftn_menuItem('VEGETARIAN', '5.55', 'Tomato sauce, Mozzarella cheese, mixed peppers, onions and mushrooms') +
					ftn_menuItem('QUATTRO STAGIONI', '6.25', 'Ham, mixed peppers, mushrooms and pepperoni') + 
					ftn_menuItem('MAMA MIA PIZZA', '6.25', 'Mozzarella cheese, Tomato sauce, chicken, peperoni and Jalapeno peppers. ') + 
					ftn_menuItem('MEDITERRANEAN', '5.50', 'Mozzarella cheese, tomato sauce, sliced tomato, olives, feta cheese and oregano ') + 
					ftn_menuItem('AL CAPONE', '6.35', 'Mozzarella cheese, tomato sauce, Garlic, Ham, Salami and Peperoni') + 
					ftn_menuItem('MAFIOSO PIZZA', '6.60', 'Mozzarella cheese, Tomato sauce, Parma Ham and Gorgonzolla Cheese.');
	
	var strItem3 = '<img src="images/menu/menusPasta.png"  alt="Pasta">' +
					'<div class="menuItemDescription" style="width:249px;"><img src="/images/global/labesi.png" width="210" height="6"></div>' +
					'<div class="menuItemDescription" style="width:249px;"><img src="/images/global/labesi.png" width="210" height="6"></div>' +
					ftn_menuItem('LASAGNE', '5.95', 'Made with 100% prime beef mince, Bolognese sauce, béchamel, tomato and parmesan') +
					ftn_menuItem('CANNELLONI', '5.95', 'Pasta rolls filled with spinach and ricotta cheese and oven baked') +
					ftn_menuItem('TAGLIATELLE SALMONE', '6.65', 'Pasta strips tossed with fresh salmon, broccoli, shallots, parsley and a creamy white wine and tomato sauce') +
					ftn_menuItem('TAGLIATELLE PRIMAVERA', '5.75', 'Pasta strips in tomato and cream sauce with mushrooms and ham') +
					ftn_menuItem('SPAGHETTI ALLA CARBORANA', '6.20', 'Spaghetti with bacon and egg yolk in a creamy sauce with parmesan cheese') +
					ftn_menuItem('SPAGHETTI ALLA MARE', '6.60', 'Spaghetti tossed in a seafood sauce of mussels, clams, prawns, calamari and tomato sauce') +
					ftn_menuItem('SPAGHETTI BOLOGNESE', '4.95', 'Made with 100% prime beef mince, and tomato sauce') +
					ftn_menuItem('RISOTTO DELLA NONNA', '6.85', 'Rice with chicken, mushrooms and tomato sauce') +
					ftn_menuItem('PENNE ARRABBIATA', '5.60', 'Penne with hot peperoni, olives, chillies in tomato sauce') +
					ftn_menuItem('PENNE AL FORNO', '5.95', 'Oven baked pasta with fresh vegetables, tomato sauce and mozzarella cheese');
					
	
	
					

					
	
	switch(menuNumber) {
      case 1: d.innerHTML = strItem1; break
	
      case 2: d.innerHTML = strItem2; break
	  
      case 3: d.innerHTML = strItem3; break   
	  
	  

   }

	

}

function fn_validateFieldIsEmpty(formDOMObj, fieldname, identifier){
	/* this function validates a form field, basically it checks to 
	see if a parameter sent to it is empty and if it is, return false */
	
	if(formDOMObj[fieldname].value.length < 1){
		
		//set the two fields which proclaim an error ro "inline" (ie. visible)
		
		
		alert('The ' +  identifier + ' is blank.\nPlease enter your ' + identifier);
		return false;
	}
	return true;
}

function ftnValidateOrder(formDOMObj){
	//alert();
	
	 if(fn_validateFieldIsEmpty(formDOMObj, 'strName', 'name') == false
			|| fn_validateFieldIsEmpty(formDOMObj,  'strTelephone', 'telephone number') == false
			|| fn_validateFieldIsEmpty(formDOMObj,  'strOrder', 'order') == false){
			 
		 	return false;
	 }
	 if(formDOMObj.strDeliveryType.value=='For delivery'){
		 if(fn_validateFieldIsEmpty(formDOMObj,  'strAddress', 'address') == false){
				 
				return false;
		 }
	 }
		//otherwise return true
		return true;
	

}



function ftnAddToOrder(orderTitle){
	
	//define new line variable
	var strNewLine = '\n';
	//define the current takeaway order
	var strCurrentOrder = document.frmOrderOnline.strOrder.value;
	//if the current order is blank, no need for a new line
	if(document.frmOrderOnline.strOrder.value.length <= 1){
		strNewLine = '';
	}else{
		//if not blank, check for a match betweek the current order and the new order item
		var intIndexOf = strCurrentOrder.indexOf(orderTitle);
	}
	
	//if there is a match we need to increase the quantity by one
	if(intIndexOf > 1){
		var intTens = (strCurrentOrder.charAt(intIndexOf-5));
		var intQuantityOf = parseInt(strCurrentOrder.charAt(intIndexOf-4));
		
		//intQuantityOf = parseInt(intQuantityOf);
		
		intQuantityOf += 1;
		
		if(intTens.length>0 && intQuantityOf==10){
			intTens = parseInt(strCurrentOrder.charAt(intIndexOf-5));
			
			intQuantityOf = (intTens*10) + intQuantityOf;
			
			strCurrentOrder = strCurrentOrder.substring(0,intIndexOf-5) + intQuantityOf + ' x ' + strCurrentOrder.substring(intIndexOf)
		}else{
			strCurrentOrder = strCurrentOrder.substring(0,intIndexOf-4) + intQuantityOf + ' x ' + strCurrentOrder.substring(intIndexOf)
		};
		
		
		
		
		
		
	}else{
		strCurrentOrder += strNewLine + '1 x ' + orderTitle;	
	}
		 
		
	
	
	document.frmOrderOnline.strOrder.value = strCurrentOrder;
	
}
