/* Javascript startWith and endWith method extended */
String.prototype.endWith=function(str){
	if(str==null||str==""||this.length==0||str.length>this.length)
		return false;
	if(this.substring(this.length-str.length)==str)
		return true;
	else
		return false;
	return true;
}

String.prototype.startWith=function(str){
	if(str==null||str==""||this.length==0||str.length>this.length)
		return false;
	if(this.substr(0,str.length)==str)
		return true;
	else
		return false;
	return true;
}

/* toggleMenu start */
var toggleMenu = {
	init : function(sContainerClass, sHiddenClass) {
		if (!document.getElementById || !document.createTextNode) {return;} // Check for DOM support
		var arrMenus = this.getElementsByClassName(document, 'ul', sContainerClass);
		var arrSubMenus, oSubMenu, oLink;
		for (var i = 0; i < arrMenus.length; i++) {
			arrSubMenus = arrMenus[i].getElementsByTagName('ul');
			for (var j = 0; j < arrSubMenus.length; j++) {
				oSubMenu = arrSubMenus[j];
				oLink = oSubMenu.parentNode.getElementsByTagName('a')[0];
				oLink.onclick = function(){toggleMenu.toggle(this.parentNode.getElementsByTagName('ul')[0], sHiddenClass); return false;}
				this.toggle(oSubMenu, sHiddenClass);
			}
		}
	},
	toggle : function(el, sHiddenClass) {
		var oRegExp = new RegExp("(^|\\s)" + sHiddenClass + "(\\s|$)");
		el.className = (oRegExp.test(el.className)) ? el.className.replace(oRegExp, '') : el.className + ' ' + sHiddenClass; // Add or remove the class name that hides the element
	},
/* addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html */
	addEvent : function(obj, type, fn) {
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() {obj["e"+type+fn](window.event);}
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	},
/*
Written by Jonathan Snook, http://www.snook.ca/jonathan
Add-ons by Robert Nyman, http://www.robertnyman.com
*/
	getElementsByClassName : function(oElm, strTagName, strClassName){
	    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	    var arrReturnElements = new Array();
	    strClassName = strClassName.replace(/\-/g, "\\-");
	    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	    var oElement;
	    for(var i=0; i<arrElements.length; i++){
	        oElement = arrElements[i];      
	        if(oRegExp.test(oElement.className)){
	            arrReturnElements.push(oElement);
	        }   
	    }
	    return (arrReturnElements)
	}
};
toggleMenu.addEvent(window, 'load', function(){toggleMenu.init('menu','hidden');});

/* The second level menu selected */
var urls = location.href.split("/");
var action = urls[urls.length-1];
var obj = document.getElementById(action);

if(obj != null){
	obj.firstChild.style.backgroundColor="#A3C75B";
	if(action == "newsFollow.action?query.type=1" || action =="newsFollow.action?query.type=4" || action == "aboutUsSponsorshipFollow.action" || action.startWith("productFollow.action?query.pcategory=") || action.startWith("productFollow.action?query.pclass=")){
		toggleMenu.init('menu','hidden');
	}else if(action.startWith("productFollow.action?query.pclass")){
		toggleMenu.init('menu','hidden');
	}
}/* Overseas View*/
else if(action.startWith("newsFollow.action") && action.endWith("query.type=1")){
	toggleMenu.init('menu','hidden');
	var obj = document.getElementById("newsFollow.action?query.type=1");
	obj.firstChild.style.backgroundColor="#A3C75B";
}/* Corporation News*/
else if(action.startWith("newsFollow.action") && action.endWith("query.type=4")){
	toggleMenu.init('menu','hidden');
	var obj = document.getElementById("newsFollow.action?query.type=4");
	obj.firstChild.style.backgroundColor="#A3C75B";
}
/* New Product Express*/
else if(action.startWith("productFollowNew.action")){
	var obj = document.getElementById("productFollowNew.action?query.newFlag=1");
	obj.firstChild.style.backgroundColor="#A3C75B";
}
/* Our Product */
else if(action.startWith("productFollow.action")){
	var obj;
	if(action.endWith("query.pcategory=1")){
		obj = document.getElementById("productFollow.action?query.pcategory=1");
		obj.firstChild.style.backgroundColor="#A3C75B";
	}else if(action.endWith("query.pcategory=2") || action.substr(0, action.length-1).endWith("query.pcategory=2&pageIndex=")){
		obj = document.getElementById("productFollow.action?query.pcategory=2");
		obj.firstChild.style.backgroundColor="#A3C75B";
	}else if(action.endWith("query.pcategory=3")){
		obj = document.getElementById("productFollow.action?query.pcategory=3");
		obj.firstChild.style.backgroundColor="#A3C75B";
	}else if(action.startWith("productFollow.action") && action.endWith("query.pclass=1")){
		obj = document.getElementById("productFollow.action?query.pclass=1");
		obj.firstChild.style.backgroundColor="#A3C75B";		
	}else if(action.startWith("productFollow.action") && action.endWith("query.pclass=2")){
		obj = document.getElementById("productFollow.action?query.pclass=2");
		obj.firstChild.style.backgroundColor="#A3C75B";		
	}else if(action.startWith("productFollow.action") && action.endWith("query.pclass=3")){
		obj = document.getElementById("productFollow.action?query.pclass=3");
		obj.firstChild.style.backgroundColor="#A3C75B";		
	}else if(action.startWith("productFollow.action") && action.endWith("query.pclass=4")){
		obj = document.getElementById("productFollow.action?query.pclass=4");
		obj.firstChild.style.backgroundColor="#A3C75B";		
	}else if(action.startWith("productFollow.action") && action.endWith("query.pclass=5")){
		obj = document.getElementById("productFollow.action?query.pclass=5");
		obj.firstChild.style.backgroundColor="#A3C75B";		
	}
	
	toggleMenu.init('menu','hidden');
	
}/* Success Store*/
else if(action.startWith("productCustomerCaseFollow.action")){
	var obj = document.getElementById("productCustomerCaseFollow.action?id=1");
	obj.firstChild.style.backgroundColor="#A3C75B";
}
/* Our History*/
else if(action.startWith("history") && action.endWith(".action")){
	var obj = document.getElementById("history1980_1989.action");
	obj.firstChild.style.backgroundColor="#A3C75B";
}
/* Wellness Info*/
else if(action.startWith("introduceFollow.action") && action.endWith("query.type=1")){
	var obj = document.getElementById("introduceFollow.action?query.type=1");
	obj.firstChild.style.backgroundColor="#A3C75B";
}
/* Media focus*/
else if(action.startWith("mediaFocusFollow.action") && action.endWith("query.type=2")){
	var obj = document.getElementById("mediaFocusFollow.action?query.type=2");
	obj.firstChild.style.backgroundColor="#A3C75B";
}
/* Public Welfare*/
else if(action.startWith("environDetailFollow.action")){
	var obj = document.getElementById("environFollow.action");
	obj.firstChild.style.backgroundColor="#A3C75B";
}
/* Download Area*/
else if(action.startWith("downloadAreaFollow.action")){
	var obj;
	if(action.endWith("query.smalltype=4")){
		obj = document.getElementById("downloadAreaFollow.action?query.smalltype=4");
		obj.firstChild.style.backgroundColor="#A3C75B";
	}else if(action.endWith("query.smalltype=3")){
		obj = document.getElementById("downloadAreaFollow.action?query.smalltype=3");
		obj.firstChild.style.backgroundColor="#A3C75B";
	}else if(action.endWith("query.smalltype=2")){
		obj = document.getElementById("downloadAreaFollow.action?query.smalltype=2");
		obj.firstChild.style.backgroundColor="#A3C75B";
	}else if(action.endWith("query.smalltype=1")){
		obj = document.getElementById("downloadAreaFollow.action?query.smalltype=1");
		obj.firstChild.style.backgroundColor="#A3C75B";
	}
}
