//GLOBAL MENU
function setMenuState (menuID) {
	var menuItems = document.getElementById(menuID).getElementsByTagName("li");
	var currentActive;
	
	for (var i = 0 ; i < menuItems.length ; i++) {
		if ((/Active/).test(menuItems[i].className)) {
			currentActive = menuItems[i];
		}
	}
	
	for (var i = 0 ; i < menuItems.length ; i++) {
		menuItems[i].onmouseover = function () {
			/* Only for < IE6 */
			if (/MSIE (5\.5|6\.)/.test(navigator.userAgent)) {
				this.getElementsByTagName("a")[0].style.filter = this.getElementsByTagName("a")[0].style.filter.replace("OFF", "ON");
			}
			/**/
			else {
				if (!(/Active/).test(this.className)) {
					this.className += " Active";
				}
			}
		}
		menuItems[i].onmouseout = function () {
			/* Only for < IE6 */
			if (currentActive != this && (/MSIE (5\.5|6\.)/).test(navigator.userAgent)) {
				this.getElementsByTagName("a")[0].style.filter = this.getElementsByTagName("a")[0].style.filter.replace("ON", "OFF");
			}
			/**/
			else {
				if (currentActive != this && (/Active/).test(this.className)) {
					this.className = this.className.replace(/Active/, "");
				}
			}
		}
	}
}

//Contextual Navigation
NavObj = function (navID, depth) {
	this.options = {
		navID: arguments[0].navID,
		depth: arguments[0].depth
	}
	this.subnav = new Tree(this.options.navID, this.options.depth);
	var self = this;
	/* Handler Level 1 */
    for (var i=0 ; i < this.subnav.LEVEL[0].length ; i++) {
        if (this.subnav.LEVEL[0][i].getElementsByTagName("a")[0]) {
            this.subnav.LEVEL[0][i].getElementsByTagName("a")[0].onclick = function () {
                showHideSubMenu(self.subnav.LEVEL[0], this.parentNode);
                
				if (/#$/.test(this.href)) {
					return false;
				}
				else {
					return true;
				}
            }
        }
    }
	/* Handler Level 2 */
    for (var i=0 ; i < this.subnav.LEVEL[1].length ; i++) {
        if (this.subnav.LEVEL[1][i].getElementsByTagName("a")[0]) {
            this.subnav.LEVEL[1][i].getElementsByTagName("a")[0].onclick = function () {
                showHideSubMenu(self.subnav.LEVEL[1], this.parentNode);
				
                if (/#$/.test(this.href)) {
					return false;
				}
				else {
					return true;
				}
            }
        }
    }
	
	/* Handler Level 3 */
    for (var i=0 ; i < this.subnav.LEVEL[2].length ; i++) {
        if (this.subnav.LEVEL[2][i].getElementsByTagName("a")[0]) {
            this.subnav.LEVEL[2][i].getElementsByTagName("a")[0].onclick = function () {
                showHideSubMenu(self.subnav.LEVEL[2], this.parentNode);
				
                if (/#$/.test(this.href)) {
					return false;
				}
				else {
					return true;
				}
            }
        }
    }
	    
}

function showHideSubMenu (obj, clickedItem) {
    for (var i=0 ; i < obj.length ; i++) {
        if (obj[i] != clickedItem) {
            obj[i].className = obj[i].className.replace(/Active/,"");
        }
    }
    if (!(/Active/).test(clickedItem.className)) {
        clickedItem.className += " Active";
    }
    else {
        clickedItem.className = clickedItem.className.replace(/Active/,"");
    }
}

/* LOGIN FORM */
function setInputStatus () {
	for (var i = 0 ; i < arguments[0].length ; i++) {
		/* Only for < IE6 */
		if (/MSIE (5\.5|6\.)/.test(navigator.userAgent)) {
			var matchStr = new RegExp(/login-input-bg-["1""2"]/);
			var strBack;
		}
		/**/
		document.getElementById(arguments[0][i]).getElementsByTagName("input")[0].onfocus = function () {
			/* Only for < IE6 */
			if (/MSIE (5\.5|6\.)/.test(navigator.userAgent) && this.value == "") {
				strBack = this.parentNode.style.filter;
				this.parentNode.style.filter = this.parentNode.style.filter.replace(matchStr, "login-input-bg-Active");
			}
			/**/
			else {
				if (!(/Active/).test(this.parentNode.className)) {
					this.parentNode.className += " Active";
				}
			}
		}
		document.getElementById(arguments[0][i]).getElementsByTagName("input")[0].onblur = function () {
			/* Only for < IE6 */
			if (/MSIE (5\.5|6\.)/.test(navigator.userAgent) && this.value == "") {
				this.parentNode.style.filter = strBack;
			}
			/**/
			else {
				if ((/Active/).test(this.parentNode.className) && this.value == "") {
					this.parentNode.className = this.parentNode.className.replace(/Active/, "");
				}
			}
		}
	}
}

// Images change linh tinh 
function setActiveThis(ID) {
	var myImage = document.getElementById('myImage');
	
	var x = document.getElementById('items').getElementsByTagName('a');
	for (i=0; i < x.length; i++) {
		x[i].className = '';
	}
	ID.className = 'Active';	
	myImage.src = "images/locations/larges/"+ID.title;
	//ID.className = 'Active';
	//myImage.src = ID.getElementsByTagName('img')[0].src.split(".",1) + '_large.jpg';
}