//purchase hide

document.write("<style>.purchase #left table th p { display:none;}</style>");

//load func

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

//control foot top

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;
	foot.style.top = leftheight + 140 + "px";
//	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);

//purchase pages,show text in table

function showhide() {
	var hidetext = this.nextSibling;
	if(hidetext.nodeType == 3) {
		hidetext = hidetext.nextSibling;
	}
    hidetext.className = (hidetext.className == "") ? "show":"";
	getheight();
}

function purchase_show() {
	if(!document.getElementById("show_table")) return false;
	var show_table = document.getElementById("show_table");
	var strongs = show_table.getElementsByTagName("strong");
	for(var j=0; j<strongs.length; j++) {
		if(strongs[j].className == "showhide") {
			strongs[j].onclick = showhide;
		}
	}
}

addLoadEvent(purchase_show);
	
	
//all menu effects

//this func only for some cate which have return menu
function rightmenuHover(menuobj) {
	var links = menuobj.getElementsByTagName("a");
	var windowLocationhref = window.location.href.split("/");
	var locationHref;
	if(windowLocationhref[windowLocationhref.length-1] == "") {
		locationHref = windowLocationhref[windowLocationhref.length-2];
	} else {
		locationHref = windowLocationhref[windowLocationhref.length-1];
	}
	for(i=0; i<links.length; i++) {
		var linksHref = links[i].href.split("/");
		var linksRighthref;
		if(linksHref[linksHref.length-1] == "") {
			linksRighthref = linksHref[linksHref.length-2];
		} else {
			linksRighthref = linksHref[linksHref.length-1];
		}
		if(locationHref == linksRighthref) {
			links[i].className = 'here';
		} else {
			links[i].className = '';
		}
		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 = '';
				var linksHref2 = links[j].href.split("/");
				var linksRighthref2;
				if(linksHref2[linksHref2.length-1] == "") {
					linksRighthref2 = linksHref2[linksHref2.length-2];
				} else {
					linksRighthref2 = linksHref2[linksHref2.length-1];
				}
				if(locationHref == linksRighthref2) {
					links[j].className = 'here';
				}
			}
	}
	}
}

//for common menu
function topmenuHover(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';
		} else {
			links[i].className = '';
		}
		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';
				}
			}
	}
	}
}

//top menu effect
function topmenu () {
	if(!document.getElementById("menu")) return false;
	var menuobj = document.getElementById("menu");
	topmenuHover(menuobj);
}

//right menu effect
function rightmenu () {
	if(!document.getElementById("right")) return false;
	var menuobj = document.getElementById("right");
	rightmenuHover(menuobj);
}

addLoadEvent(topmenu);
addLoadEvent(rightmenu);

//products pages,tab

function prepareshow() {
	if(!document.getElementById("description_head")) return false;
	var description_head = document.getElementById("description_head");
	var description_links = description_head.getElementsByTagName("a");
	for(var i=0; i<description_links.length; i++) {
		var sectionId = description_links[i].getAttribute("href").split("#")[1];
		description_links[i].ment = sectionId;
		description_links[i].onclick = function() {
			showtab(this.ment);
			getheight();
			for(var j=0; j<description_links.length; j++) {
				description_links[j].className = '';
			}
			this.className = 'here';
			return false;
		}
		description_links[i].onmouseover = function() {
			for(var j=0; j<description_links.length; j++) {
				description_links[j].className = '';
			}
			this.className = 'here';
		}
		description_links[i].onmouseout = function() {
			for(var j=0; j<description_links.length; j++) {
				description_links[j].className = '';
			}
			var description_content = document.getElementById("description_content");
			var divs = description_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<description_links.length; k++) {
						description_links[k].className = "";
						if(description_links[k].href.indexOf(theid) != -1) description_links[k].className = 'here';
					}
				}
			}
		}
			
	}
}

function showtab(id) {
	var description_content = document.getElementById("description_content");
	var divs = description_content.getElementsByTagName("div");
	for( var i=0; i<divs.length; i++) {
		divs[i].style.display = "none";
		if (divs[i].getAttribute("id") != id) {			
			divs[i].style.display = "none";
		} 
		else {
			divs[i].style.display = "block";
		}
	}
}

function showfirst() {
	if(!document.getElementById("description_content")) return false;
	var description_content = document.getElementById("description_content"); 
	if(!document.getElementById("description_head")) return false;
	var description_head = document.getElementById("description_head");
	var description_links = description_head.getElementsByTagName("a");
	for(var i=0; i<description_links.length; i++) {
		var sectionId = description_links[i].getAttribute("href").split("#")[1];
		description_links[i].ment = sectionId;
		var now_href = window.location.href;
		if(now_href.indexOf(sectionId) != -1) {
			divs[0].style.display = 'none';
			document.getElementById(sectionId).style.display = 'block';
		} else {
			var divs = description_content.getElementsByTagName("div");
			divs[0].style.display = 'block';
		}
		if(now_href.indexOf(description_links[i].getAttribute("href")) != -1) {
			for(var j=0; j<description_links.length; j++) {
				description_links[j].className = '';
			}
			description_links[i].className = "here";
		}
	}
	getheight();
}

addLoadEvent(showfirst);
addLoadEvent(prepareshow);

 

function address_cut() {
	if(!document.getElementById("contact")) return false;
	var contact = document.getElementById("contact");
	var lis = contact.getElementsByTagName("li");
	for(var i=0; i<lis.length; i++) {
		if(lis[i].className == "c_msn") {
			var strContent=lis[i].innerHTML;  
			var strTemp="";
			while(strContent.length>23){
				strTemp+=strContent.substr(0,18)+"<br />";
				strContent=strContent.substr(18,strContent.length); 
				strTemp+=strContent;
				lis[i].innerHTML=strTemp;
			}
		}
	}
}

addLoadEvent(address_cut);

//download openpop

function createXMLHttpRequest() {
	if(window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
	} else if(window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
} 
