﻿// START of exceptions in menu
var menuExceptions = new Array();
// Guide:
// menuExceptions[0] = new Array();
// menuExceptions[0][0] = "<page tab reference you are currently on>";
// menuExceptions[0][1] = "<reference in menu to highlight>";

// END of exceptions listing

function checkMenuExceptions(text) {
	for (var i = 0; i < menuExceptions.length; i++) {
		if (menuExceptions[i][0] == text)
			text = menuExceptions[i][1];
	}
	return text;
}

function loadMenuStyles(obj) {
	for (var i = 0; i < obj.childNodes.length; i++) {
		switchDivStyles(obj.childNodes[i]);
	}
}

function doMenuAction(obj,link) {
	document.location.href = link;
	/*if (obj.parentNode.className == "menuMainOpen" && link != "#")
		switchDivStyles(obj.parentNode.parentNode);
	else {
		if (link == "#") {
			// get menu height
			var menuHeight = document.getElementById("mainMenu").clientHeight;
			// change div styles
			switchDivStyles(obj.parentNode.parentNode);
			// get difference in height between height before div-style change and after
			menuHeight = document.getElementById("mainMenu").clientHeight - menuHeight;
			// increase height of left div
			document.getElementById(getClientIdLeft()).style.height = (document.getElementById(getClientIdLeft()).clientHeight + menuHeight) + "px";
			// resize all tabs
			tryResizeTabs(1);
		} else
			document.location.href = link;
	}*/
}

function switchDivStyles(obj) {
	var k = 0;
	var menuContainsItem = false;
	
	for (var j = 0; j < obj.childNodes.length; j++) {
		if (obj.childNodes[j].nodeName == "DIV") {
			if (k==0) {
				if (obj.childNodes[j].className == "")
					obj.childNodes[j].className = "menuMainClose";
				else if (obj.childNodes[j].className == "menuMainClose")
					obj.childNodes[j].className = "menuMainOpen";
				else if (obj.childNodes[j].className == "menuMainOpen")
					obj.childNodes[j].className = "menuMainClose";
			}
			else {
				if (obj.childNodes[j].className == "") {
					obj.childNodes[j].className = "menuItemNone";
					if (getDocumentURL("") == "appartamentiapraga.tab.aspx")
						menuContainsItem = true;
					else if (getDocumentURL("") == getDocumentURL(obj.childNodes[j].childNodes[0].getAttribute("href")))
						menuContainsItem = true;
				}
				else if (obj.childNodes[j].className == "menuItemNone")
					obj.childNodes[j].className = "menuItemBlock";
				else if (obj.childNodes[j].className == "menuItemBlock")
					obj.childNodes[j].className = "menuItemNone";
			}
			k++;
		}
	}

	if (menuContainsItem)
		switchDivStyles(obj);
}

function openMenuAll() {
	// get menu height
	var menuHeight = document.getElementById("mainMenu").clientHeight;
	// change div styles
	for (var i = 1; i < document.getElementById("mainMenu").getElementsByTagName("DIV").length; i++) {
		if (document.getElementById("mainMenu").getElementsByTagName("DIV")[i].id != "") {
			if (document.getElementById("mainMenu").getElementsByTagName("DIV")[i].className == "menuMainClose") {
				// change div styles
				switchDivStyles(document.getElementById("mainMenu").getElementsByTagName("DIV")[i].parentNode);
			}
		}
	}
	// get difference in height between height before div-style change and after
	menuHeight = document.getElementById("mainMenu").clientHeight - menuHeight;
	// increase height of left div
	document.getElementById(getClientIdLeft()).style.height = (document.getElementById(getClientIdLeft()).clientHeight + menuHeight) + "px";
	// resize all tabs
	tryResizeTabs(1);
}

function getDocumentURL(link) {
	var url = "";
	if (link=="")
		url += document.location;
	else
		url += link;
		
	pos1 = url.lastIndexOf ("/")+1;
	pos2 = url.indexOf(".", pos1);
	url = url.substring(pos1,pos2);
	urlall = ""+document.location;
	
	if (url == "RenderTable" && urlall.indexOf("&") == -1) {
		var url = ""+document.location;
		pos = url.indexOf("TabRef=")+7;
		url = url.substring(pos);
	} else if (url == "RenderTable" && urlall.indexOf("&") != -1) {
		var url = ""+document.location;
		pos = url.indexOf("TabRef=")+7;
		url = url.substring(pos);
		if (url.indexOf("&") != -1) {
			pos = url.indexOf("&");
			url = url.substring(0,pos);
		}
	}
	
	url = checkMenuExceptions(url) + ".tab.aspx";
	return url;
}