//
// Javascript functions for handling the creation of new main meny elements
//
// Author: Johnny Danielsen
// Email: johnny@gc.no
//

function menuDialog() {
	window.open('mainMenuDialog.php','mainMenuDialog','height=200, width=400');
}

function createMenuSubmit(newName) {
	document.getElementById('newMenuName').value=newName;
	document.getElementById('newMainMenuForm').submit();
}

function menyDialog_create() {
	if (!document.formData.newName.value) {
		alert("Du må oppgi et navn!");
		document.formData.newName.focus();
	}
	window.opener.createMenuSubmit(document.formData.newName.value);
	window.close();
}

function menyDialog_cancel() {
	window.close();
}

function menuMoveUp(menuId) {
	document.getElementById("moveMenuId").value=menuId;
	document.getElementById("moveMenuDir").value="up";
	document.getElementById('newMainMenuForm').submit();
}
function menuMoveDown(menuId) {
	document.getElementById("moveMenuId").value=menuId;
	document.getElementById("moveMenuDir").value="down";
	document.getElementById('newMainMenuForm').submit();
}

function menuMoveLeft(menuId) {
	document.getElementById("moveMenuId").value=menuId;
	document.getElementById("moveMenuDir").value='left';
	document.getElementById('newMainMenuForm').submit();
}

function menuMoveRight(menuId) {
	document.getElementById("moveMenuId").value=menuId;
	document.getElementById("moveMenuDir").value='right';
	document.getElementById('newMainMenuForm').submit();
}

function menuEdit(menuId) {
	window.open("mainMenuDialog.php?editMenu="+menuId,'mainMenuDialog','height=200, width=400');
}

function editMenuSubmit(menuId,newName) {
	document.getElementById('editMenuId').value=menuId;
	document.getElementById('newMenuName').value=newName;
	document.getElementById('newMainMenuForm').submit();
}

function menuDialog_edit(menuId) {
	if (!document.formData.newName.value) {
		alert("Du må oppgi et navn!");
		document.formData.newName.focus();
	}
	window.opener.editMenuSubmit(menuId,document.formData.newName.value);
	window.close();
}

function menuDelete(menuId) {
	if (confirm("Er du sikker på at du vil slette denne menyen?")) {
		document.getElementById("deleteMenuId").value=menuId;
		document.getElementById('newMainMenuForm').submit();
	}
}