//-----------------------------functional start

function changeOption(id) {	
	document.getElementById("textOptionDisplay").innerHTML = id;
}
function resetOption(id) {	
	document.getElementById("textOptionDisplay").innerHTML = id;	
}

function checkEnableOption(id,id2) {
	//alert(document.getElementById(id).value);	

	if (document.getElementById(id).value == 'Menu') {
		//alert("1");
		document.getElementById(id2).disabled = true;
	}
	else {
		//alert("2");
		document.getElementById(id2).disabled = false;
	}

}

function openTemplatePreview(id) {
	var tmpl_dir = "templates/";
	var tmpl_file = "";
	tmpl_file = document.getElementById(id).value;
	window.open(tmpl_dir + tmpl_file,'TemplatePreview','left=20,top=20,menubar=no,location=no,resizable=yes,scrollbars=yes,status=no,address=no,titlebar=no,directories=no,menubar=no')
}


function setBlank(id) {
	document.getElementById(id).value = '';
}


//-----------------------------functional end

//-----------------------------Menu Functionality Start
function showMenu(callingObject, panelObject){	
	var leftpos = 0;
	var toppos = 0;
	recursiveTag = document.getElementById(callingObject);
	
	if (document.getElementById(panelObject).style.visibility=="visible") {
		keepMenu();
	}
	
	do {
		recursiveTag = recursiveTag.offsetParent;
		leftpos += recursiveTag.offsetLeft;
		toppos += recursiveTag.offsetTop;
	} while(recursiveTag.tagName!="BODY");
	
	leftpos = leftpos - 19;
	toppos = toppos + 22;
	
	document.getElementById(panelObject).style.left = leftpos + "px";
	document.getElementById(panelObject).style.top = toppos + "px";	
	
	panelWidth = parseInt(document.getElementById(panelObject).offsetWidth);
	coWidth = parseInt(document.getElementById(callingObject).offsetParent.offsetWidth);
	
	if (panelWidth < (coWidth+36)) {
		document.getElementById(panelObject).style.width = document.getElementById(callingObject).offsetParent.offsetWidth + 36 + "px";
	}
	
	document.getElementById(panelObject).style.zIndex = '999';
	
	document.getElementById(panelObject).style.visibility="visible";
}

var timer;

function hideMenu(id){
	document.getElementById(id).style.visibility = "hidden";
}

function requestHide(id) {
	document.getElementById(id).style.zIndex = '0';
    timer = setTimeout("hideMenu('" + id + "')", 100);
}

function keepMenu() {
	clearTimeout(timer);
}
//-----------------------------Menu Functionality End

//-----------------------------Add Remove Menu Sorting Start

	function addMenu() {
		var option1 = document.getElementById("new_item");
		var option2 = document.getElementById("existing_items");
	
		if (option1.selectedIndex > -1) { 
			var nOption = document.createElement("OPTION");
			nOption.text = option1.options.item(option1.selectedIndex).text;
			nOption.value = option1.options.item(option1.selectedIndex).value;
			option2.options.add(nOption);
			option1.remove(option1.selectedIndex);			
		}
		else {
			alert("Select a menu to assigned to the ordered list.");
		}
	}
	
	function removeMenu() {
		var option1 = document.getElementById("existing_items");
		var option2 = document.getElementById("new_item");
	
		if (option1.selectedIndex > -1) { 
			var nOption = document.createElement("OPTION");
			nOption.text = option1.options.item(option1.selectedIndex).text;
			nOption.value = option1.options.item(option1.selectedIndex).value;
			option2.options.add(nOption);
			option1.remove(option1.selectedIndex);			
		}
		else {
			alert("Select a menu to remove from the ordered list.");
		}
	}	
	
	function select_OrderList() { 
		var el = document.add_menu_next.existing_items;
		for (j=0;j<el.length;j++) {
			el.options.item(j).selected = true;
		}
	}
	
	function select_OrderListEdit() { 
		var el = document.edit_menu_next.existing_items;
		for (j=0;j<el.length;j++) {
			el.options.item(j).selected = true;
		}
	}
	
	function check_MenuOrder () { 
		var el = document.add_menu_next.new_item;
		if (el.length > 0) { 
			alert('Not all menus exist in the Ordered List');
			return false;
		}
		else {			
			select_OrderList();
			return true;			
		}
	}

	function check_MenuOrderEdit () { 
		var el = document.edit_menu_next.new_item;
		if (el.length > 0) { 
			alert('Not all menus exist in the Ordered List');
			return false;
		}
		else {			
			select_OrderListEdit();
			return true;			
		}
	}
//-----------------------------Add Remove Menu Sorting End


	