			(
				function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

						(i[r].q=i[r].q||[]).push(arguments)
					},i[r].l=1*new Date();
					a=s.createElement(o),

					m=s.getElementsByTagName(o)[0];
					a.async=1;
					a.src=g;
					m.parentNode.insertBefore(a,m)

				})
			(window,document,'script','//www.google-analytics.com/analytics.js','ga');

			ga('create', 'UA-1015874-2', 'foodarena.ch');

			ga('send', 'pageview');

			touchMove = function(event) {
				event.preventDefault();
			}
			function pauseComp(ms) {
				var curr = new Date().getTime();
				ms += curr;
				while (curr < ms) {
					curr = new Date().getTime();
				}
			}

			function getLocation() {
				FoodArena.locationManager.init();
				FoodArena.locationManager.getCurrentLocation();
				$.mobile.loading('show');
				//document.location = '#loading';
				setTimeout(scheduled, 1000);
				//FoodArena.locationManager.getCurrentLocation();
				//pauseComp(1000);
				/*while (FoodArena.locationManager.getCurrentCoordinates() == 0){
				 pauseComp(1000);
				 }*/
				/*if (FoodArena.locationManager.getCurrentCoordinates() == 0){
				 alert('ZIP-code not found!');
				 }
				 else {
				 alert(FoodArena.locationManager.getCurrentCoordinates());
				 }*/
			}

			function scheduled() {
				if (FoodArena.locationManager.getCurrentZIP() == 0) {
					setTimeout(scheduled, 1000);
				} else {
					getZip();
				}
			}

			function sortfunction(a, b) {
				return (a.delivery_time - b.delivery_time) //causes an array to be sorted numerically and ascending
			}

			function inputZip() {
				//document.location += '#menu';
				var zip = prompt(Storage.lang.enter_zip_code);
				if (zip != null && zip != '') {
					getRestaurants(zip);
				}
			}

			function getZip() {
				var testZip = FoodArena.locationManager.getCurrentZIP();
				getRestaurants(testZip);
			}

			function editSavedAddresses() {
				var addressItems = document.getElementById("savedadresses-items");
				if (Storage.edditing == false) {
					Storage.edditing = true;
					for (var i = 0; i < addressItems.childNodes.length; i++) {
						var button = document.createElement("img");
						//button.setAttribute("data-role", "button");
						button.setAttribute("src", "images/recycle.png");
						button.setAttribute("i", i);
						//button.textContent = 'Delete';
						button.onclick = function(button) {
							Storage.block = true;
							if (confirm(Storage.lang.delete_item)) {

								FoodArena.dataContext.init('dataStorageKey');
								FoodArena.dataContext.deleteUserData(this.getAttribute('i'));
								var addressItems = document.getElementById("savedadresses-items");
								var i = this.getAttribute('i');
								while (addressItems.length > i - 1) {
									i--;
								}
								addressItems.removeChild(addressItems.childNodes[i]);
							}

						};
						var td = document.createElement("td");
						td.appendChild(button);
						addressItems.childNodes[i].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].appendChild(td);
					}
				} else {
					for (var i = 0; i < addressItems.childNodes.length; i++) {
						addressItems.childNodes[i].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].removeChild(addressItems.childNodes[i].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1]);
					}
					Storage.edditing = false;

				}
				$("#savedaddresses *").trigger("create");
				;
				//stylizePage();
			}

			function showSavedAddresses() {
				Storage.edditing = false;
				FoodArena.dataContext.init('dataStorageKey');
				var addresses = FoodArena.dataContext.getUserData();
				Storage.addresses = addresses;
				var addressItems = document.getElementById("savedadresses-items");
				addressItems.innerHTML = '';
				//var table = document.createElement("table");
				for (var i = 0; i < addresses.length; i++) {
					var table = document.createElement("table");

					var street = document.createElement("h3");
					var city = document.createElement("h4");
					street.textContent = addresses[i].streetName + ', ' + addresses[i].streetNo;
					city.textContent = addresses[i].zipCode + ', ' + addresses[i].city;
					var div = document.createElement("div");
					var divTable = document.createElement("table");
					divTable.innerHTML = '<tr><td width="100%">' + street.outerHTML + city.outerHTML + '</td></tr>';
					div.name = i;
					//div.id = 'savedaddressdiv' + i;
					div.setAttribute("data-role", "button");

					div.onclick = function() {
						if (Storage.block == false) {
							Storage.curUserData = Storage.addresses[this.name];
							getRestaurants(Storage.curUserData.zipCode);
						}
						Storage.block = false;
					}
					//td.appendChild(div);
					//tr.appendChild(td);
					//divTable.childNodes[0].childNodes[0].childNodes[0].appendChild(div);
					div.appendChild(divTable);
					divTable.setAttribute("class", "savedAddressTable");
					divTable.setAttribute("name", "divTable");
					//table.innerHTML = '<tr><td></td></tr>';
					//table.childNodes[0].childNodes[0].childNodes[0].appendChild(div);
					//table.setAttribute("class", "savedAddressTable");
					addressItems.appendChild(div);
				}
				//addressItems.innerHTML = table.outerHTML;
				$("#savedaddresses *").trigger("create");
				;
				//stylizePage();
				document.location = '#savedaddresses'
			}

			function getRestaurants(zip) {
				document.getElementById('restZIP').innerHTML = Storage.lang.restaurants_for_zip + zip;
				//if(document.location.hash != '#loading'){
				// $('#loading').bind('pageshow', function() {
				//	$('#loading').unbind('pageshow');
				$.mobile.loading('show');
				Storage.restaurantsList = FoodArena.networking.getRestaurantsList(zip);
				//});
				// document.location = "#loading";
				//}else{
				//Storage.restaurantsList = FoodArena.networking.getRestaurantsList(zip);
				//}

			}

			function loadReataurants() {
				Storage.restaurantsList.sort(sortfunction);
				var tablos = [];
				var restaurants = document.getElementById('restaurantsContent');
				restaurants.innerHTML = '';
				var h = document.createElement('h3');
				h.id = 'header_opened';
				h.innerHTML = Storage.lang.currently_open;
				restaurants.appendChild(h);
				for (var i = 0; i < Storage.restaurantsList.length; i++) {
					if (Storage.restaurantsList[i].isOpened == true) {
						var tabloDiv = Storage.restarantListItem.cloneNode(true);
						var divTd = tabloDiv.getElementsByTagName('td');
						var button = tabloDiv.getElementsByTagName('a')[0].parentNode;
						button.name = i;
						button.className = button.className + " orderBttn";
						button.onclick = function() {
							Storage.tmp = this.name;
							//$('#loading').bind('pageshow', function() {
							//$('#loading').unbind('pageshow');
							$.mobile.loading('show');
							getRestaurantMenu(Storage.tmp);

							loadCurDeliveryTimes();
							//});
							//document.location = "#loading";

						}
						//var button = tabloDiv.getElementsByTagName('button')[0];
						//button.name = i;
						if (Storage.restaurantsList[i].isOpened == true) {
							button.innerHTML = Storage.lang.order;
						} else {
							button.innerHTML = Storage.lang.preorder;
						}
						button.setAttribute("href", "#restaurants");
						divTd[0].innerHTML = Storage.restaurantsList[i].title;
						divTd[1].innerHTML = Storage.restaurantsList[i].address;
						divTd[4].innerHTML = Storage.restaurantsList[i].current_delivery_hrs;
						divTd[6].innerHTML = Storage.lang.from + Storage.restaurantsList[i].delivery_time + " min";
						divTd[8].innerHTML = Storage.restaurantsList[i].delivery_charge + " CHF";
						divTd[11].innerHTML = Storage.restaurantsList[i].min_order_value + " CHF";
						var paymentMethods = divTd[12];
						var cash = Storage.paymentMethod.cloneNode(true);
						var online = Storage.paymentMethod.cloneNode(true);
						var cupon = Storage.paymentMethod.cloneNode(true);
						var icon = "";
						if (Storage.restaurantsList[i].card_payment_option == true) {
							icon = "images/yes.png";
						} else {
							icon = "images/no.png";
						}
						online.getElementsByTagName('img')[0].src = icon;
						cupon.getElementsByTagName('img')[0].src = icon;
						online.getElementsByTagName('div')[0].innerHTML = Storage.lang.restourant_online;
						cupon.getElementsByTagName('div')[0].innerHTML = Storage.lang.restourant_voucher;

						paymentMethods.appendChild(cash);
						paymentMethods.appendChild(online);
						paymentMethods.appendChild(cupon);

						tabloDiv.getElementsByTagName('img')[0].src = Storage.restaurantsList[i].picture;

						tablos[tablos.length] = tabloDiv;
						restaurants.appendChild(tabloDiv);
					}
				}
				var h = document.createElement('h3');
				h.id = 'header_closed';
				h.innerHTML = Storage.lang.currently_closed;
				restaurants.appendChild(h);
				for (var i = 0; i < Storage.restaurantsList.length; i++) {
					if (Storage.restaurantsList[i].isOpened == false) {
						var tabloDiv = Storage.restarantListItem.cloneNode(true);
						var divTd = tabloDiv.getElementsByTagName('td');
						var button = tabloDiv.getElementsByTagName('a')[0].parentNode;
						button.name = i;
						//button.classList.add('orderBttn');
						button.className = button.className + " preorderBttn";
						button.onclick = function() {
							Storage.tmp = this.name;
							$.mobile.loading('show');
							//$('#loading').bind('pageshow', function() {
							//$('#loading').unbind('pageshow');
							getRestaurantMenu(Storage.tmp);

							loadCurDeliveryTimes();
							//});
							//document.location = "#loading";

							//order(this);
						}
						//var button = tabloDiv.getElementsByTagName('button')[0];
						//button.name = i;
						if (Storage.restaurantsList[i].isOpened == true) {
							button.innerHTML = Storage.lang.order;
						} else {
							button.innerHTML = Storage.lang.preorder;
						}
						button.setAttribute("href", "#restaurants");
						divTd[0].innerHTML = Storage.restaurantsList[i].title;
						divTd[1].innerHTML = Storage.restaurantsList[i].address;
						divTd[4].innerHTML = Storage.restaurantsList[i].current_delivery_hrs;
						divTd[6].innerHTML = Storage.lang.from + Storage.restaurantsList[i].delivery_time + " min";
						divTd[8].innerHTML = Storage.restaurantsList[i].delivery_charge + " CHF";
						divTd[11].innerHTML = Storage.restaurantsList[i].min_order_value + " CHF";
						tabloDiv.getElementsByTagName('img')[0].src = Storage.restaurantsList[i].picture;

						tablos[tablos.length] = tabloDiv;
						restaurants.appendChild(tabloDiv);
					}
				}
				//var restaurants = document.getElementById('restaurants');
				//var main = document.getElementById('main')
				//document.body.innerHTML=layer3.innerHTML;
				//main.innerHTML = restaurants.innerHTML;
				//document.body.innerHTML = '';
				//document.body.appendChild(layer3);
				try {
					$('.rest').css('font-size', window.screen.width / 30);
					$('.headerButton').attr("data-theme", "b");
					document.location = '#restaurants';
					
					$("#restaurants *").trigger("create");
				} catch(e) {
					alert(e.message);
				}
				//stylizePage();
				//$('div[data-role=button]').button();

			}

			function stylizePage() {
				$('a[data-role=button]').button();
				$('div[class=switchButton]').button();
				$('div[data-role=collapsible]').collapsible();
				$("input[type='checkbox']").checkboxradio();
			}

			function getOffset(el) {
				if (el.getBoundingClientRect)
					return el.getBoundingClientRect().top - 100;
				else {
					var x = 0, y = 0;
					do {
						x += el.offsetLeft - el.scrollLeft;
						y += el.offsetTop - el.scrollTop;
					} while (el = el.offsetParent);

					return y - 100;
				}
			}

			function fillCollapsible(i) {
				var collapsibles = document.getElementById('menu-items').childNodes;
				window.scrollBy(0, getOffset(collapsibles[i]));
				for (var k = 0; k < collapsibles.length; k++) {
					collapsibles[k].childNodes[1].innerHTML = '';
				}
				var hud = document.createElement('img');
				hud.style.opacity = " .18";
				hud.setAttribute("src", "images/ajax-loader.gif");
				hud.setAttribute("id", "hud" + i);
				//collapsibles[k].appendChild(hud);
				collapsibles[i].childNodes[1].appendChild(hud);
				$('#hud' + i).bind('load', function() {
					window.scrollBy(0, getOffset(collapsibles[i]));
					timer = setTimeout(function() {
						window.scrollBy(0, getOffset(collapsibles[i]));
						var itemDiv = document.createElement("div");
						for (var j = 0; j < Storage.curRestaurantMenu.menuGroups[i].menuItems.length; j++) {
							var curItem = Storage.curRestaurantMenu.menuGroups[i].menuItems[j];
							var name = '<td width="50%"><b>' + curItem.itemTitle + '</b></td>';
							var priceInner = '';
							if (curItem.itemPrices[curItem.curPriceIndex] == undefined) {
								curItem.itemPrices[curItem.curPriceIndex] = 0;
								priceInner = 0.00 + " CHF";
							} else {
								priceInner = curItem.itemPrices[curItem.curPriceIndex].itemPriceDeliver + " CHF";
							}
							var price = '<td width="20%" style="text-align:right;"><b>' + priceInner + '</b></td>'
							//var cart = '<td width="30%" rowspan="2"><img src="images/cart.png" onclick="cartClick()"></td>';
							var cart = '<td align="right" width="30%" rowspan="2"><img src="images/cart.png" onclick="cartClick(' + i + ',' + j + ')"></td>';
							var descr = '<td rowspan="2">' + curItem.itemDescription + '</td>';
							var buttonText = document.createElement('div');
							buttonText.textContent = curItem.itemPrices[curItem.curPriceIndex].item_price_desc;

							buttonText.id = "buttontext" + i + '_' + j;
							var switchButton = document.createElement('a');
							switchButton.i = i;
							switchButton.j = j;
							switchButton.setAttribute("data-role", "button");
							//switchButton.setAttribute("data-mini", "true");
							switchButton.setAttribute("class", "switchButton");
							switchButton.setAttribute("onclick", "switchClick(" + i + "," + j + "," + "this)");
							switchButton.innerHTML = buttonText.outerHTML;

							var row1 = '<tr>' + name + price + cart + '</tr>';
							if (curItem.itemPrices.length > 1) {
								var row3 = '<tr class="row3"><td colspan="2">' + switchButton.outerHTML + '</td></tr>';
							} else {
								var row3 = '<tr class="row3"><td colspan="2"></td></tr>';
							}
							var row2 = '<tr class="row2">' + descr + '<td></td></tr>'

							var table1 = '<table class="menutable" cellpadding="0" cellspacing="0">' + row1 + row2 + row3 + '</table>';

							var tableDiv = document.createElement("div");
							tableDiv.setAttribute("class", "menuItemDiv");

							tableDiv.innerHTML = table1;
							itemDiv.appendChild(tableDiv);
						}
						collapsibles[i].childNodes[1].innerHTML = '';
						collapsibles[i].childNodes[1].appendChild(itemDiv);
						$('#hud' + i).unbind('load');
						window.scrollBy(0, getOffset(collapsibles[i]));
						$('div[data-role=collapsible]').collapsible();
						//$("#menu-items").listview("refresh");
						$('a[data-role=button]').button();
						//$("#menu *").trigger( "create" );
						window.scrollBy(0, getOffset(collapsibles[i]));
					}, 500);
				});
				//}

				document.location = '#menu';

			}

			function setPaymentType(type) {
				Storage.curOrder.paymentType = type;
				var cuponCode = document.getElementById("cuponCode");
				if (type == 0) {
					cuponCode.setAttribute("style", "display: none");
					document.getElementById("surcharge").setAttribute("style", "display: none");
					document.getElementById("payment-type-cash").setAttribute("src", "images/cash_bttn_pressed.png");
					document.getElementById("payment-type-online").setAttribute("src", "images/online_bttn.png");
				} else {
					cuponCode.setAttribute("style", "display: block");
					document.getElementById("surcharge").setAttribute("style", "display: block");
					document.getElementById("payment-type-cash").setAttribute("src", "images/cash_bttn.png");
					document.getElementById("payment-type-online").setAttribute("src", "images/online_bttn_pressed.png");
				}
				displayPrice();

			}

			function order() {
				document.location = '#menu';
				var menuHeader = document.getElementById('restMenu');
				menuHeader.innerHTML = Storage.curRestaurant.title;
				var TestTime = new Date()

				//getRestaurantMenu(self.name);
				//Storage.curOrder.items  = Storage.curOrder.items.splice(0, Storage.curOrder.items.length);
				Storage.curOrder.clearItems();
				//Storage.curOrder = new Order();
				document.getElementById("toCart").style.visibility = 'hidden';
				var menu = document.getElementById('menu-items');
				menu.innerHTML = '';
				if (Storage.curRestaurantMenu.menuGroups.length > 0) {
					for (var i = 0; i < Storage.curRestaurantMenu.menuGroups.length; i++) {
						var collapsible = Storage.menuListItem.cloneNode(true);
						collapsible.setAttribute("data-role", "collapsible");
						collapsible.setAttribute("class", "menuitem");
						collapsible.setAttribute("i", i);
						collapsible.setAttribute("id", 'collapsibleid' + i);
						collapsible.firstChild.innerHTML = Storage.curRestaurantMenu.menuGroups[i].groupTitle;
						;
						var hud = document.createElement('img');
						hud.setAttribute("src", "images/ajax-loader.gif");
						collapsible.appendChild(hud);
						//collapsible.trigger( "create" );
						menu.appendChild(collapsible);
						$('#collapsibleid' + i).bind('expand', function() {
							window.scrollBy(0, getOffset(this));
							fillCollapsible(this.getAttribute('i'));
						});
					}
				}

				var TestTime2 = new Date();
				console.log(TestTime - TestTime2);
				TestTime = new Date();
				$('div[data-role=collapsible]').collapsible();
				$('a[data-role=button]').button();
				$("#menu-items").collapsibleset();
				//$("#menu *").trigger( "create" );;
				TestTime2 = new Date();
				console.log(TestTime - TestTime2);
				TestTime = new Date();
				//fillCollapsible();
				TestTime2 = new Date();
				console.log(TestTime - TestTime2);
				return false;

			}

			function cartClick(i, j) {
				Storage.curItem = Storage.curRestaurantMenu.menuGroups[i].menuItems[j];
				if (Storage.curItem.itemExtras.length != 0) {
					var extras = Storage.curItem.itemExtras;
					Storage.curItemExtras = extras;
					var additionals = document.getElementById('additional-items');
					additionals.setAttribute("data-role", "fieldcontain");
					additionals.innerHTML = '';
					for (var i = 0; i < extras.length; i++) {
						var additionalItem = Storage.additionsListItem.cloneNode(true);
						additionalItem.setAttribute("data-role", "content");
						additionalItem.getElementsByTagName("span")[0].innerHTML = extras[i].itemExtraName;
						additionalItem.getElementsByTagName("span")[1].innerHTML = extras[i].itemExtraPrice + ' CHF';
						additionals.appendChild(additionalItem);
					}
					//$("#additional *").trigger( "create" );;
					try {
						stylizePage();
					} finally {
						document.location = '#additional';
					}
				} else {
					addItemToOrder(Storage.curItem);

				}

			}

			function switchClick(i, j, self) {
				var curItem = Storage.curRestaurantMenu.menuGroups[i].menuItems[j];
				if (curItem.curPriceIndex == curItem.itemPrices.length - 1) {
					curItem.curPriceIndex = 0;
				} else {
					curItem.curPriceIndex = curItem.curPriceIndex + 1;
				}
				$('#' + self.getElementsByTagName("div")[0].id).animate({
					width : 'hide'
				});
				$('#' + self.getElementsByTagName("div")[0].id).animate({
					width : 'show'
				});
				$('#' + self.parentElement.parentElement.parentElement.getElementsByTagName("td")[1].id).animate({
					width : 'hide'
				});
				$('#' + self.parentElement.parentElement.parentElement.getElementsByTagName("td")[1].id).animate({
					width : 'show'
				});
				self.getElementsByTagName("div")[0].textContent = curItem.itemPrices[curItem.curPriceIndex].item_price_desc;
				self.parentElement.parentElement.parentElement.getElementsByTagName("td")[1].innerHTML = "<b>" + curItem.itemPrices[curItem.curPriceIndex].itemPriceDeliver + " CHF</b>";
			}

			function loadCurDeliveryTimes() {
				FoodArena.networking.getDeliveryTimeList(Storage.curRestaurant.id, true);
			}

			function addItemToOrder(menuItem, extras) {
				var extraIds = [];
				if (extras && extras.length > 0) {
					for (var i = 0; i < extras.length; i++) {
						extraIds[extraIds.length] = extras[i].id;
					}
				}
				document.getElementById("deleteButton").style.visibility = "hidden";
				document.getElementById("deleteButton").style.display = "none";
				Storage.curOrder.add(menuItem, 1, menuItem.itemPrices[menuItem.curPriceIndex].id, extraIds);
				var orderItems = document.getElementById("order-content");
				orderItems.innerHTML = '';
				var table = document.createElement("table");
				table.setAttribute("width", "100%");
				var items = Storage.curOrder.getItems();
				for (var i = 0; i < items.length; i++) {
					var item = document.createElement("tr");
					var deleteCell = document.createElement("td");
					var label = document.createElement("label");
					label.innerHTML = '<div class = "floatLeft">' + items[i]['name'] + "</div>";
					var deleteCheckBox = document.createElement("input");
					deleteCheckBox.type = "checkbox";
					deleteCheckBox.onchange = function() {
						if (Storage.itemsChecked == undefined) {
							Storage.itemsChecked = 0;
						}
						if (this.checked == true) {
							Storage.itemsChecked++;
							console.log(Storage.itemsChecked + ' ++');
						} else {
							Storage.itemsChecked--;
							console.log(Storage.itemsChecked + ' --');
						}
						if (Storage.itemsChecked == 0) {
							console.log(document.getElementById("deleteButton").style.visibility + '   1');
							document.getElementById("deleteButton").style.visibility = "hidden";
							document.getElementById("deleteButton").style.display = "none";
						} else {
							document.getElementById("deleteButton").style.visibility = "visible";
							document.getElementById("deleteButton").style.display = "";
							console.log(document.getElementById("deleteButton").style.visibility + '   1');
						}

					}
					//deleteCheckBox.class = "custom";
					deleteCheckBox.name = i;
					label.appendChild(deleteCheckBox);
					//deleteCell.appendChild(label);
					var itemData = document.createElement("td");
					var itemName = document.createElement("h3");
					itemName.textContent = items[i]['name'];
					itemData.appendChild(label);
					var itemPrice = document.createElement("div");
					itemPrice.setAttribute("class", "floatRight");
					label.appendChild(itemPrice);
					itemPrice.textContent = items[i]['price'] + " CHF";
					var extraLeftDiv = document.createElement("div");
					//extraLeftDiv.setAttribute("class","floatLeft");
					if (items[i]['price_desc'] != undefined) {
						var itemExtra = document.createElement("h6");
						//itemExtra.setAttribute("class","floatLeft");
						itemExtra.textContent = items[i]['price_desc'];
						extraLeftDiv.appendChild(itemExtra);
					}
					for (var j = 0; j < items[i].extras.length; j++) {
						var itemExtra = document.createElement("h6");
						//itemExtra.setAttribute("class","floatLeft");
						itemExtra.textContent = items[i].extras[j]['name'];
						extraLeftDiv.appendChild(itemExtra);
					}

					var itemPriceData = document.createElement("td");
					var itemPrice = document.createElement("div");
					var extraRightDiv = document.createElement("div");
					extraRightDiv.setAttribute("class", "textAlignRight");
					//itemPriceData.appendChild(itemPrice);
					for (var j = 0; j < items[i].extras.length; j++) {
						var itemExtraPrice = document.createElement("h6");
						itemExtraPrice.textContent = items[i].extras[j]['extra_price'] + " CHF";
						extraRightDiv.appendChild(itemExtraPrice);
					}
					var extraTable = document.createElement('table');
					extraTable.innerHTML = '<tr><td>' + extraLeftDiv.outerHTML + '</td><td>' + extraRightDiv.outerHTML + '</td></tr>';
					//label.appendChild(extraLeftDiv);
					//label.appendChild(extraRightDiv);
					extraTable.setAttribute("class", "floatLeft menutable");
					label.appendChild(extraTable);
					//item.appendChild(deleteCell);
					item.appendChild(itemData);
					item.appendChild(itemPriceData);

					table.appendChild(item);

				}
				//<!--delivery time-->
				var select = document.getElementById("deliverytime");
				select.innerHTML = '';
				for (var i = 0; i < Storage.curDeliveryTime.length; i++) {
					var item = document.createElement("option");
					item.value = i;
					item.textContent = Storage.curDeliveryTime[i];
					select.appendChild(item);
				}
				displayPrice();
				orderItems.appendChild(table);
				document.getElementById("toCart").style.visibility = 'visible';
				try {
					$("#order *").trigger("create");
					//stylizePage();
				} finally {
					document.location = "#order";
				}
			}

			function displayPrice() {
				document.getElementById("deliverycost").textContent = Storage.curRestaurant.delivery_charge + " CHF";
				var totalCost = (Storage.curRestaurant.delivery_charge / 1.0 + Storage.curOrder.getCost() / 1.0);
				if (Storage.curOrder.paymentType == 1) {
					var surcharge = Math.round(totalCost * 0.03 * 100) / 100;
					document.getElementById("surchargeValue").textContent = surcharge + " CHF";
					totalCost = surcharge * 1.0 + totalCost * 1.0;

				}
				document.getElementById("totalcost").textContent = round(totalCost).toFixed(2) + " CHF";
				document.getElementById("totalCostWarning").textContent = '';
				document.getElementById("cont").style.visibility = 'visible';
				if (Storage.curOrder.getCost() / 1.0 < Storage.curRestaurant.min_order_value) {
					document.getElementById("totalCostWarning").textContent = Storage.lang.order_is_less_than + Storage.curRestaurant.min_order_value + ' CHF';
					document.getElementById("cont").style.visibility = 'hidden';
				}
			}

			function addcurItemToOrderExtras(self) {
				self.classname += 'ui-btn-down-a';
				var extrasCheckBoxes = document.getElementById("additional").getElementsByTagName("input");
				var extras = [];
				for (var i = 0; i < extrasCheckBoxes.length; i++) {
					if (extrasCheckBoxes[i].checked == true) {
						extras.push(Storage.curItemExtras[i]);
					}
				}
				addItemToOrder(Storage.curItem, extras);
			}

			function getRestaurantMenu(restaurantNumber) {

				Storage.curRestaurantMenu = FoodArena.networking.getMenuList(Storage.restaurantsList[restaurantNumber].id);
				Storage.curRestaurant = Storage.restaurantsList[restaurantNumber];
				Storage.curOrder.items = Storage.curOrder.items.splice(0, Storage.curOrder.items.length);
				document.getElementById("toCart").style.visibility = 'invisible';
				if (Storage.curRestaurant.card_payment_option == false) {
					document.getElementById("payment-type").setAttribute("style", "display: none;")
				} else {
					document.getElementById("payment-type").setAttribute("style", "display: block;")
				}

			}

			function processVoucherResult(xml) {
				if (xml.children('result').text() * 1.0 == 1) {
					Storage.voucher.discountAmount = (xml.children('discount_amount').text() * 1.0);
					showUserForm();
					//alert('all ok. discount ' + Storage.voucher.discountAmount);
				} else {
					if (xml.children('result').text() * 1.0 == -1) {
						alert(Storage.lang.voulcher_invalid);
					} else {
						alert(Storage.lang.voulcher_order_to_low);
					}
				}

			}

			function showUserForm() {

				FoodArena.dataContext.init('dataStorageKey');
				$('select#flip_register').on('slidestop', function(event) {
					console.log("call");
					if (Storage.block == false) {
						Storage.block = true;
						document.getElementById("userPass").style.visibility = 'hidden';
						document.getElementById("userPassList").style.visibility = 'hidden';
						var button = document.getElementById("orderbutton");
						button.childNodes[0].childNodes[0].textContent = Storage.lang.done;
						document.getElementById("userInfo").setAttribute("style", "");
						Storage.register = false;
						if ($(this).val() == "on") {
							document.getElementById("userPass").style.visibility = 'visible';
							document.getElementById("userPassList").style.visibility = 'visible';
							button.childNodes[0].childNodes[0].textContent = "Register & Go";
							document.getElementById("userInfo").setAttribute("style", "padding-right:8%");
							Storage.register = true;
						}
						Storage.block = false;
					}

				});
				var data = Storage.curUserData;
				if (data) {
					document.getElementById("compName").value = data.compName;
					document.getElementById("userName").value = data.userName;
					document.getElementById("surName").value = data.surName;
					document.getElementById("streetName").value = data.streetName;
					document.getElementById("streetNo").value = data.streetNo;
					document.getElementById("floorNo").value = data.floorNo;
					document.getElementById("zipCode").value = data.zipCode;
					document.getElementById("city").value = data.city;
					document.getElementById("phoneNo").value = data.phoneNo;
					document.getElementById("comments").value = data.comments;
					document.getElementById("mail").value = data.mail;
				}
				document.location = "#userReg";
			}

			function checkVoucherCode() {
				$.mobile.loading('show');
				var code = document.getElementById('voucherCuponCode').value;
				if (code.length > 0 && Storage.curOrder.paymentType != 0) {
					var voucher = new Voucher(code, Storage.curRestaurant.id, Storage.curOrder.getCost());
					Storage.voucher = voucher;
					FoodArena.networking.checkVoucher(voucher);
					return;

				}
				showUserForm();
			}

			function doSendOrder() {
				$.mobile.loading('show');
				Storage.curOrder.setDetails(document.getElementById("compName").value, document.getElementById("userName").value, document.getElementById("surName").value, document.getElementById("streetName").value, document.getElementById("streetNo").value, document.getElementById("floorNo").value, document.getElementById("zipCode").value, document.getElementById("city").value, document.getElementById("mail").value, '20', '10', '2012', document.getElementById("phoneNo").value, document.getElementById("comments").value, Storage.userId == 0 ? '' : Storage.userId, 'true', Storage.curDeliveryTimes[document.getElementById("deliverytime").selectedIndex], Storage.curRestaurant.delivery_charge, Storage.curRestaurant.id);
				//var orderStatus =
				FoodArena.networking.sendOrder(Storage.curOrder);
				//document.getElementById("resultMessage").textContent = orderStatus;
				//$("#ordMes *").trigger( "create" );;
				Storage.amount = ((Storage.curRestaurant.delivery_charge / 1.0 + Storage.curOrder.getCost() / 1.0).toFixed(2)) * 100;
				stylizePage();
				//document.getElementById("payHref").setAttribute("href", 'https://pilot.datatrans.biz/upp/jsp/upStart.jsp?merchantId='+Storage.merchantId+'&amount='+Storage.amount+'&currency='+Storage.currency+'&refno='+Storage.refno+'&uppMobileMode=on&useTouchUI=yes');
				//document.location = "#payment";
			}

			function payWithDatatrans() {
				document.location = 'https://pilot.datatrans.biz/upp/jsp/upStart.jsp?merchantId=' + Storage.merchantId + '&amount=' + Storage.amount + '&currency=' + Storage.currency + '&refno=' + Storage.refno + '&uppMobileMode=on&useTouchUI=yes';
			}

			function processOrderResult(result) {
				var doc = $(result);
				var res = doc[1].children[0].textContent;
				if (res == 'true') {
					if (Storage.curOrder.paymentType == 1) {
						payWithDatatrans();
					} else {
						alert(successMessage(Storage.curRestaurant.title, Storage.curRestaurant.phone));
						document.location = "#";
					}
				} else {
					//alert(doc[1].children[1].textContent);
					alert(failMessage(result));
				}
			}

			function checkUserFields() {
				var data = new Object();
				data.compName = document.getElementById("compName").value;
				data.userName = document.getElementById("userName").value;
				data.surName = document.getElementById("surName").value;
				data.streetName = document.getElementById("streetName").value;
				data.streetNo = document.getElementById("streetNo").value;
				data.floorNo = document.getElementById("floorNo").value;
				data.zipCode = document.getElementById("zipCode").value;
				data.city = document.getElementById("city").value;
				data.phoneNo = document.getElementById("phoneNo").value;
				data.comments = document.getElementById("comments").value;
				data.mail = document.getElementById("mail").value;
				if (!validateSimpleString(data.userName)) {
					alert(Storage.lang.name + Storage.lang.field_invalid);
					return false;
				}
				if (!validateSimpleString(data.surName)) {
					alert(Storage.lang.surname + Storage.lang.field_invalid);
					return false;
				}
				if (!validateSimpleString(data.streetName)) {
					alert(Storage.lang.street + Storage.lang.field_invalid);
					return false;
				}
				if (!validateSimpleNumber(data.zipCode)) {
					alert(Storage.lang.zip_code + Storage.lang.field_invalid);
					return false;
				}
				if (!validateSimpleString(data.city)) {
					alert(Storage.lang.city + Storage.lang.field_invalid);
					return false;
				}
				if (!validateSimpleNumber(data.phoneNo)) {
					alert(Storage.lang.phone_no + Storage.lang.field_invalid);
					return false;
				}
				if (!validateEmail(data.mail)) {
					alert(Storage.lang.email + Storage.lang.field_invalid);
					return false;
				}
				return true;
			}

			function doOrder() {
				if (checkUserFields() == true) {
					FoodArena.dataContext.init('dataStorageKey');
					Storage.curUserId = 0;
					var result;
					if (Storage.register == true) {
						result = FoodArena.networking.registerNewUser(document.getElementById("mail").value, document.getElementById("userName").value, document.getElementById("surName").value, document.getElementById("password").value, document.getElementById("repPass").value, document.getElementById("streetName").value, document.getElementById("streetNo").value, document.getElementById("zipCode").value, document.getElementById("city").value);
						var title = '';
						if (result.status == 'failure') {
							title = Storage.lang.registration_unsuccessfull + result.msg;
							alert(title);
						} else {
							title = 'Registration Successful';
							Storage.curUserId = result.user_id;
						}

					}
					if ((result && result.status != 'failure') || !(result)) {
						var data = new Object();
						data.compName = document.getElementById("compName").value;
						data.userName = document.getElementById("userName").value;
						data.surName = document.getElementById("surName").value;
						data.streetName = document.getElementById("streetName").value;
						data.streetNo = document.getElementById("streetNo").value;
						data.floorNo = document.getElementById("floorNo").value;
						data.zipCode = document.getElementById("zipCode").value;
						data.city = document.getElementById("city").value;
						data.phoneNo = document.getElementById("phoneNo").value;
						data.comments = document.getElementById("comments").value;
						data.mail = document.getElementById("mail").value;
						var datalist = FoodArena.dataContext.getUserData();
						datalist[datalist.length] = data;
						FoodArena.dataContext.saveUserData(datalist);
						var order = document.getElementById("order-content").cloneNode(true);
						var userDetails = document.getElementById("userRegTable").cloneNode(true);
						var nodes = userDetails.getElementsByTagName("input");
						for (var i = 0; i < nodes.length; i++) {
							nodes[i].disabled = true;
						}
						nodes = order.getElementsByTagName("input");
						for (var i = 0; i < nodes.length; i++) {
							nodes[i].disabled = true;
							if (nodes[i].type == 'checkbox') {
								nodes[i].style.visibility = "hidden";
							}
						}
						nodes = order.getElementsByTagName("span");
						for (var i = 0; i < nodes.length; i++) {
							nodes[i].disabled = true;
							if (nodes[i].className == 'ui-icon ui-icon-checkbox-off ui-icon-shadow') {
								nodes[i].style.visibility = "hidden";
							}
						}
						var summary = document.getElementById("summary-content");
						var deltime = document.createElement("div");
						deltime.innerHTML = '<p style="text-align: center;">' + Storage.lang.i_want_my_order_delivered + '</p>';
						deltime.innerHTML = deltime.innerHTML + '<ul data-role="listview" data-inset="true" id="userPassTime"><li style="text-align:center;" class="userField">' + document.getElementById("deliverytime").options[document.getElementById("deliverytime").value].text + '</li></ul>';
						//var deltime = document.getElementById("deliverytime");
						summary.innerHTML = '';
						summary.appendChild(order);
						summary.appendChild(document.getElementById("totalCostTable").cloneNode(true));
						summary.appendChild(deltime);
						summary.appendChild(userDetails);
						try {
							//$("#summary *").trigger( "create" );
							stylizePage();
						} finally {
							document.location = "#summary";
						}
					}
				}
			}

			function deleteSelectedItems() {
				var orderContent = document.getElementById("order-content");
				var delItem = orderContent.getElementsByTagName("input");
				for (var i = 0; i < delItem.length; i++) {
					if (delItem[i].checked == true) {
						Storage.curOrder.removeItemAt(i);
						delItem[i].parentNode.parentNode.parentNode.parentNode.removeChild(delItem[i].parentNode.parentNode.parentNode);
						i--;
					}
				}
				document.getElementById("deleteButton").style.visibility = "hidden";
				document.getElementById("deleteButton").style.display = "none";
				Storage.itemsChecked = 0;
				if (Storage.curOrder.items.length > 0) {
					displayPrice();
				} else {
					document.getElementById("toCart").style.visibility = "hidden";
					document.location = "#menu";
				}
			}

			function init() {

				$(document).bind("mobileinit", function() {
					$.mobile.page.prototype.options.contentTheme = "z";
					//your theme
				});
				/*var UA = navigator.userAgent;
				if(UA.indexOf("Android") !== -1){
					document.getElementById('useragent').textContent = "Android";
				} else if(UA.indexOf("iPad") !== -1){
					document.getElementById('useragent').textContent = "iOS";
				} else if(UA.indexOf("iPhone") !== -1){
					document.getElementById('useragent').textContent = "iOS";
				} else if(UA.indexOf("iPod") !== -1){
					document.getElementById('useragent').textContent = "iOS";
				} else {
					document.getElementById('useragent').textContent = "Other(Desctop)";
				}*/
				//document.getElementById('main').setAttribute("ontouchmove", "touchMove(event)");
				document.getElementById('slogan').style.fontSize = window.screen.width / 20;
				console.log('body onload init');
				$("#main *").trigger("create");
				if (!String.prototype.format) {
					String.prototype.format = function() {
						var args = arguments;
						return this.replace(/{(\d+)}/g, function(match, number) {
							return typeof args[number] != 'undefined' ? args[number] : match;
						});
					};
				}
				applyLang();
				document.getElementById("currentLocationButton").focus();
				// alert(document.activeElement.id);
				
				$(function () { 
					var lang = (navigator.language || navigator.systemLanguage || navigator.userLanguage || 'en');
					if(lang.length > 2){
						lang = lang.substr(3, 5).toLowerCase();
					} else {
						lang = lang.substr(0, 2).toLowerCase();
					}
								$.smartbanner({
									daysHidden: 0,
									daysReminder: 0,
									icon:'images/foodarena_icon.png',
									title: 'Foodarena',
									button: Storage.lang.install,
									price: Storage.lang.price_free,
									inAppStore: Storage.lang.app_store, 
									inGooglePlay: Storage.lang.google_play,
									appStoreLanguage:lang
								}) 
							});
			}
			window.scrollTo(0, 0);