// JavaScript Document

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

//控制footer的位置

function getheight() {
	if(!document.getElementById("left")) return false;
	var left = document.getElementById("left");
	var right = document.getElementById("right");
	var foot = document.getElementById("foot");
	var leftheight = left.clientHeight;
	var rightheight = right.clientHeight;
	if ( leftheight > rightheight) {
		foot.style.top = leftheight + 157 + "px";
	}
	else {
		foot.style.top = rightheight + 157 + "px";
	}
	if (parseInt(foot.style.top) + 90 < document.documentElement.offsetHeight) {
		foot.style.top = document.documentElement.offsetHeight - 90 + "px";
	}
	if (parseInt(foot.style.top) + 90 < window.innerHeight) {
		foot.style.top = window.innerHeight - 90 + "px";
	}
}

addLoadEvent(getheight);

//服务页面打开更多

function showhide(obj) {
	var hidetext = obj.nextSibling;
    if (hidetext.className == '') {
		hidetext.className = 'show';
	}
	else {
		hidetext.className = '';
	}
	getheight();
}

//所有菜单效果

function menuhover(menuobj) {
	var links = menuobj.getElementsByTagName("a");
	for(i=0; i<links.length; i++) {
		if(window.location.href.indexOf(links[i].href) != -1) links[i].className = 'here';
		links[i].onmouseover = function() {
			for(j=0; j<links.length; j++) {
				links[j].className = '';
			}
			this.className = 'here';
		}
		links[i].onmouseout = function() {
			for(j=0; j<links.length; j++) {
				links[j].className = '';
				if(window.location.href.indexOf(links[j].href) != -1) {
					links[j].className = 'here';
				}
			}
	}
	}
}

function topmenu () {
	if(!document.getElementById("menu")) return false;
	var menuobj = document.getElementById("menu");
	menuhover(menuobj);
}

function rightmenu () {
	if(!document.getElementById("right")) return false;
	var menuobj = document.getElementById("right");
	menuhover(menuobj);
}

addLoadEvent(topmenu);
addLoadEvent(rightmenu);

//产品页切换

function prepareshow() {
	if(!document.getElementById("notice_head")) return false;
	var notice_head = document.getElementById("notice_head");
	var notice_links = notice_head.getElementsByTagName("a");
	for(var i=0; i<notice_links.length; i++) {
		var sectionId = notice_links[i].getAttribute("href").split("#")[1];
		notice_links[i].ment = sectionId;
		notice_links[i].onclick = function() {		
			document.getElementById(sectionId).style.display = "none";
			showtab(this.ment);
			getheight();
			for(var j=0; j<notice_links.length; j++) {
				notice_links[j].className = '';
			}
			this.className = 'here';
			return false;
		}
		notice_links[i].onmouseover = function() {
			for(var j=0; j<notice_links.length; j++) {
				notice_links[j].className = '';
			}
			this.className = 'here';
		}
		notice_links[i].onmouseout = function() {
			for(var j=0; j<notice_links.length; j++) {
				notice_links[j].className = '';
			}
			var notice_content = document.getElementById("notice_content");
			var divs = notice_content.getElementsByTagName("div");
			for( var d=0; d<divs.length; d++) {
				if(divs[d].style.display == "block") {
					var theid = divs[d].getAttribute("id");
					for(var k=0; k<notice_links.length; k++) {
						if(notice_links[k].href.indexOf(theid) != -1) notice_links[k].className = 'here';
					}
				}
			}
		}
			
	}
}

function showtab(id) {
	var notice_content = document.getElementById("notice_content");
	var divs = notice_content.getElementsByTagName("div");
	for( var i=0; i<divs.length; i++) {
		if (divs[i].getAttribute("id") != id) {			
			divs[i].style.display = "none";
		} 
		else {
			divs[i].style.display = "block";
		}
	}
}

function showfirst() {
	if(!document.getElementById("notice_content")) return false;
	var notice_content = document.getElementById("notice_content");
	var divs = notice_content.getElementsByTagName("div");
	divs[0].style.display = 'block'; 
	getheight();
}

addLoadEvent(showfirst);
addLoadEvent(prepareshow);

/*判断右侧菜单*/

function doubleright() {
	if(!document.getElementById("right")) return false;
	if(!document.getElementById("content")) return false;
	var content = document.getElementById("content");
	if(content.className != 'product') return false;
	var right = document.getElementById("right");
	var rightlinks = right.getElementsByTagName("a");
	var nowlink = new Array();
	nowlink[0] = "http://www.comsenz.com/products";
	nowlink[1] = "http://www.comsenz.com/products/";
	nowlink[2] = "http://www.comsenz.com/products#";
	nowlink[3] = "http://comsenz.com/products";
	nowlink[4] = "http://comsenz.com/products/";
	nowlink[5] = "http://comsenz.com/products#";
	for(var i =0; i<rightlinks.length; i++) {
		if(window.location.href == nowlink[0] || window.location.href == nowlink[1] || window.location.href == nowlink[2] || window.location.href == nowlink[3] || window.location.href == nowlink[4] || window.location.href == nowlink[5]) {
			rightlinks[0].className = 'here';
		} else {
			rightlinks[0].className = '';
		}
		rightlinks[i].onmouseout = function() {
			for(j=0; j<rightlinks.length; j++) {
				rightlinks[j].className = '';
				if(window.location.href.indexOf(rightlinks[j].href) != -1) {
					rightlinks[j].className = 'here';
				}
				if(window.location.href == nowlink[0] || window.location.href == nowlink[1] || window.location.href == nowlink[2] || window.location.href == nowlink[3] || window.location.href == nowlink[4] || window.location.href == nowlink[5]) {
					rightlinks[0].className = 'here';
				} else {
					rightlinks[0].className = '';
				}
			}
		}
	}
}
addLoadEvent(doubleright);