function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
  } else {
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}

function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}

//高亮当前页莱单
function highlightPage() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("globalNav")) return false;
  var nav = document.getElementById("globalNav");
  var links = nav.getElementsByTagName("a");
  for (var i=0; i<links.length; i++) {
    var linkurl = links[i].getAttribute("href");
    var currenturl = window.location.href;
	//alert(currenturl);
	//alert(currenturl.indexOf(linkurl));
    if (currenturl.indexOf(linkurl) != -1) {
      links[i].className = "active dropdownTab";
      var linktext = links[i].lastChild.nodeValue.toLowerCase();
      //document.body.setAttribute("id",linktext);
    }
	//alert(linktext);
  }
}

function NavString(){
	String.prototype.getQuery = function(name){ 
		var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); 
		var r = this.substr(this.indexOf("?")+1).match(reg); 
		if (r!=null) return unescape(r[2]); return null; 
	} 
	var myurl=window.location.href;
	var myParameters=myurl.getQuery("kid");
	if (!myParameters) return false;
	NavString=document.getElementById("gl"+ myParameters +"");
	NavString.className = "dropdownTab active";
//	alert(NavString);
//	NavString.setAttribute("className","active");
//	NavString.setAttribute("class","active");
}



// = Stripe tables 
function stripeTables() {
  if (!document.getElementsByTagName) return false;
  //var tables = document.getAttribute.className("datatable");
  var istable = document.getElementById("datalist");
  if(!istable) return false;
  var tables = istable.getElementsByTagName("table");
  //var tables = document.getElementsByTagName("table");
  for (var i=0; i<tables.length; i++) {
    var odd = false;
    var rows = tables[i].getElementsByTagName("tr");
    for (var j=0; j<rows.length; j++) {
      if (odd == true) {
        addClass(rows[j],"odd");
        odd = false;
      } else {
        odd = true;
      }
    }
  }
}

// = High light rows  
function highlightRows() {
  if(!document.getElementsByTagName) return false;
  
  var istable = document.getElementById("datalist");
  if(!istable) return false;
  var rows = istable.getElementsByTagName("tr");
  for (var i=0; i<rows.length; i++) {
    rows[i].oldClassName = rows[i].className
    rows[i].onmouseover = function() {
      addClass(this,"highlight");
    }
    rows[i].onmouseout = function() {
      this.className = this.oldClassName
    }
  }
}

// = Hide link broken line rim 
function hideFocusA(){
	aTag=document.getElementsByTagName("a");
	for(i=0;i<aTag.length;i++){
		aTag[i].setAttribute("onfocus","this.blur();");
		aTag[i].setAttribute("hideFocus","true");
	}
	//for(i=0;i<aTag.length;i++)aTag$[$i$]$.hideFocus=true;
	//for(i=0;i<aTag.length;i++)aTag$[$i$]$.onfocus=function(){this.blur();};
}

// = Hide input broken line rim 
function hideFocusInput(){
	aTag=document.getElementsByTagName("input");
	for(i=0;i<aTag.length;i++){
		aTag[i].setAttribute("onfocus","this.blur();");
		aTag[i].setAttribute("hideFocus","true");
	}
	//for(i=0;i<aTag.length;i++)aTag$[$i$]$.hideFocus=true;
	//for(i=0;i<aTag.length;i++)aTag$[$i$]$.onfocus=function(){this.blur();};
}

//全选
function CheckAll(form){
	for (var i=0;i<form.elements.length;i++){
		var e = form.elements[i];
		if (e.Name != 'chkAll'&&e.disabled==false)
			e.checked = form.chkAll.checked;
	}
}




function showsubmenu(sid){
	whichEl ="submenu" + sid;
	document.getElementById("mainBody").style.height="auto";
	if (document.getElementById(whichEl).style.display == "none"){
	//	for(var i=1;i<9;i++){
	//		if(i !=sid)
	//		document.getElementById("submenu" + i ).style.display="none";
	//	document.getElementById("a" + i ).className="";
	//	}
		document.getElementById("submenu" + sid ).style.display="";
		document.getElementById("faq" + sid ).className="focus";
	}else{
		document.getElementById("submenu" + sid ).style.display="none";
		document.getElementById("faq" + sid ).className="";
	}
	highlyAdaptive();
}



function showNav(sid){
	whichEl ="submenu" + sid;
	if (document.getElementById(whichEl).style.display == "none"){
	//	for(var i=1;i<9;i++){
	//		if(i !=sid)
	//		document.getElementById("submenu" + i ).style.display="none";
	//	document.getElementById("a" + i ).className="";
	//	}
		document.getElementById("submenu" + sid ).style.display="";
		document.getElementById("faq" + sid ).className="focus";
	}else{
		document.getElementById("submenu" + sid ).style.display="none";
		document.getElementById("faq" + sid ).className="";
	}
}


function openLi(){
	var urls = window.location.href;
	/*alert(urls);*/
	if (urls.indexOf("MeasuringGinger")>1){
		document.getElementById("submenu35").style.display="";
		document.getElementById("faq35").className="focus";
	}	
	if (urls.indexOf("LetteringGuide")>1){
		document.getElementById("submenu36").style.display="";
		document.getElementById("faq36").className="focus";
	}	
	if (urls.indexOf("bank")>1){
		document.getElementById("submenu2").style.display="";
		document.getElementById("faq2").className="focus";
		document.getElementById("mainBody").style.height="1100";
	}	
	if (urls.indexOf("post")>1){
		document.getElementById("submenu3").style.display="";
		document.getElementById("faq3").className="focus";
		document.getElementById("mainBody").style.height="1100";
	}	
}



function closeWindows(){
	if (!document.getElementById) return false;
	if (!document.getElementById("closeWindow")) return false;
	closeBtn = document.getElementById("closeWindow");
	closeBtn.onclick = function(){ window.close(); };
//	closeBtn.setAttribute("onclick","javascript:window.close();");
	closeBtn.setAttribute("class","btn_red_74x21");
	closeBtn.setAttribute("className","btn_red_74x21");
}

//close dialogue
function closes(){
	document.getElementById("dialogue_box_1").style.display="none";
}




function dropDown(){
/*	
	if (!document.getElementById) return false;
	if (!document.getElementById("navString")) return false;
	var dropTabs=document.getElementById("navString");
	dropTabs.onmouseover=function(){
		var rows=dropTabs.getElementsByTagName("li");
		for (var i=0; i<rows.length; i++) {
			rows[i].oldClassName = rows[i].className
			rows[i].onmouseover = function() {
				addClass(this,"selected");
			}
			rows[i].onmouseout = function() {
				this.className = this.oldClassName
			}
		}
	}	
*/
	if (!document.getElementById) return false;
	if (!document.getElementById("navString")) return false;
	var dropTabs=document.getElementById("navString");
	dropTabs.onmouseover=function(){
		var rows=dropTabs.getElementsByTagName("li");
		for (var i=0; i<rows.length; i++) {
			rows[i].oldClassName = rows[i].className
			rows[i].onmouseover = function() {
				addClass(this,"hover");
			//	document.getElementById("globalNav").style.zIndex="50";
				document.getElementById("globalSerach").className="hiddenslt";
			}
			rows[i].onmouseout = function() {
				this.className = ""
			//	document.getElementById("globalNav").style.zIndex="1";
				document.getElementById("globalSerach").className="";
			}
		}
	}	
}



//Tab swap
function setTab(area,id) {
	var tabArea=document.getElementById(area);
	var contents=tabArea.childNodes;
	for(i=0; i<contents.length; i++) {
		if(contents[i].className=='tabcontent'){contents[i].style.display='none';}
	}
	document.getElementById(id).style.display='';
	var tabs=document.getElementById(area+'tabs').getElementsByTagName('a');
	for(i=0; i<tabs.length; i++) { tabs[i].className='tab'; }
	document.getElementById(id+'tab').className='tab curtab';
	document.getElementById(id+'tab').blur();
}
	addLoadEvent(stripeTables);
	addLoadEvent(highlightRows);
	addLoadEvent(hideFocusA);
//	addLoadEvent(hideFocusInput);
	
	addLoadEvent(highlightPage);

	addLoadEvent(closeWindows);
	addLoadEvent(openLi);
	
	
	addLoadEvent(NavString);
	
	
	addLoadEvent(dropDown);
	
	
	



