browser_agent = navigator.userAgent.toLowerCase();
om_safari = browser_agent.indexOf("safari") != -1;
om_opera = browser_agent.indexOf("opera") != -1;
om_ie = browser_agent.indexOf("msie") != -1 && !om_opera;
om_ie7 = browser_agent.indexOf("msie 7") != -1; // ie7 or later
om_ie6Only = om_ie && !om_ie7;
var focusitem, focusstep, hoversub;
function toggleMenuItem(inname) {
	hidelist();
	focusitem = document.getElementById(inname);
	document.getElementById("display-sub").style.display = 'none';
	switch (inname) {
		case 'Product' :
			hoversub = "product-sub";
			break;
		case 'Download' :
			hoversub = "download-sub";
			break;
		case 'Community' :
			hoversub = "community-sub";
			break;
		case 'Support' :
			hoversub = "support-sub";
			break;
		default :
			hoversub = "";
			;
	}
	if (om_ie6Only) {
		if (hoversub == "product-sub") {
			document.getElementById("display-sub").style.margin = "0px 0px 0px 10px";
		} else if (hoversub == "download-sub") {
			document.getElementById("display-sub").style.margin = "0px 0px 0px 35px";
		} else if (hoversub == "community-sub") {
			document.getElementById("display-sub").style.margin = "0px 0px 0px 125px";
		} else if (hoversub == "support-sub") {
			document.getElementById("display-sub").style.margin = "0px 0px 0px 180px";
		}
	} else {
		if (hoversub == "product-sub") {
			document.getElementById("display-sub").style.margin = "0px 0px 0px 20px";
		} else if (hoversub == "download-sub") {
			document.getElementById("display-sub").style.margin = "0px 0px 0px 70px";
		} else if (hoversub == "community-sub") {
			document.getElementById("display-sub").style.margin = "0px 0px 0px 250px";
		} else if (hoversub == "support-sub") {
			document.getElementById("display-sub").style.margin = "0px 0px 0px 360px";
		}
	}

	if (document.getElementById(hoversub)) {
		document.getElementById("display-sub").innerHTML = document
				.getElementById(hoversub).innerHTML;
		document.getElementById("display-sub").style.display = '';
	} else {
		document.getElementById("display-sub").innerHTML = '';
		document.getElementById("display-sub").style.display = '';
	}
}

function hidelist() {
	if (focusstep != null && focusstep.length != 0) {
		if (document.getElementById(focusstep)) {
			document.getElementById(focusstep).style.display = 'none';
		}
	}
}

function initMenuSelectedStatus() {
	var url = window.location.href;
	var path = url.replace(/http:\/\/.*?(\/)+/, '');
	if (path == 'index.faces') {
		selectMenuItem('Home');
	} else if (path.indexOf('products') == 0) {
		selectMenuItem('Product');
	} else if (path.indexOf('demos') == 0) {
		selectMenuItem('Demo');
	} else if (path.indexOf('downloads') == 0) {
		selectMenuItem('Download');
	} else if (path.indexOf('document') == 0) {
		selectMenuItem('Documentation');
	} else if (path.indexOf('learning') == 0) {
		selectMenuItem('Learning');
	} else if (path.indexOf('news') == 0 || path.indexOf('article') == 0 || path.indexOf('topic') == 0) {
		selectMenuItem('Community');
	} else if (path.indexOf('support') == 0) {
		selectMenuItem('Support');
	}
}

function selectMenuItem(menuItemId) {
	var selectedMenuItem = document.getElementById(menuItemId);
	selectedMenuItem.style.background = 'url(/res/img/common/bg_menu_selected.gif) no-repeat';
	selectedMenuItem.style.color = '#00000f';
}

window.onload = initMenuSelectedStatus;

function getCookie(name) {
	var start = document.cookie.indexOf(name + "=");
	var len = start + name.length + 1;
	if ((!start) && (name != document.cookie.substring(0, name.length))) {
		return;
	}
	if (start == -1)
		return;
	var end = document.cookie.indexOf(';', len);
	if (end == -1)
		end = document.cookie.length;
	return unescape(document.cookie.substring(len, end));
}

function checkauth() {
	if(typeof(getCookie('cdb_auth')) == 'undefined'){
		var ans; 
		ans=window.confirm('您还没有登录，是否跳转到登录页面?');
		if(ans == true){
			 var a = document.createElement("a");
    		 if(!a.click) {
         		window.location = 'http://www.operamasks.org/auth/login.faces';
      			return;
    		}
    		a.setAttribute("href", 'http://www.operamasks.org/auth/login.faces');
    		a.style.display = "none";
    		document.body.appendChild(a);
    		a.click();
		}
		return false;
	} 
	return true;
}

String.prototype.endWith=function(oString){  
  var reg=new   RegExp(oString+"$");  
  return reg.test(this);     
}   
