// JavaScript Document

if (!document.getElementById) {
    document.getElementById = function() { return null; };
}

var initselect=0;

function setInitSelect(select){
    if(select>0){
	  initselect=select-1;
	}
}

function deleteCookie(name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function setCookie(name,value,expires,path,domain,secure) {

  var expdate = new Date();
  expdate.setTime(expdate.getTime() + (3600000 ));
  path = '/';
  document.cookie = name + "=" + escape (value) +
    ("; expires=" + expdate.toGMTString()) +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");

}


function getCookie(name) {

	var prefix = name + "=";
	var start = document.cookie.indexOf(prefix);

	if (start==-1) {
		return null;
	}

	var end = document.cookie.indexOf(";", start+prefix.length);
	if (end==-1) {
		end=document.cookie.length;
	}

	var value=document.cookie.substring(start+prefix.length, end);
	return unescape(value);
}

function activateMenu(gurl) {

    var menu = document.getElementById("menuCon");    //链接的上层ID
    var items = menu.getElementsByTagName("a");
	var activeitem = -1;

    var cururl =""+gurl;
    if(cururl == ''){
        cururl = self.location.toString();
	}
    for (var i=0; i < items.length; i++) {

        var url = items[i].getAttribute("href");
        if (cururl.indexOf(url) != -1){
			activeitem = i;
			break;
		}
		items[i].className="";     //默认样式
    }
	
    // only one found, match on URL
    if(activeitem > -1){
        var linkindex = activeitem+0;

        var docel = document.getElementById('novTit'+linkindex);      //novBtn 链接的ID
		if(docel){			
			docel.className="novOn";   //点击后的样式	
			document.getElementById("novLink"+linkindex).style.display="block";
		}
    }else{
	    if(initselect < items.length)
	    {
			var linkindex = 0;
			var docel = document.getElementById('novTit'+linkindex);
			if(docel){
				docel.className="";  //未点击的样式
				document.getElementById("novLink"+linkindex).style.display="none";
			}
		}
	}
}
// Select the menu that matches the URL when the page loads
function navgpos(){

	var allurls = "/index.html,/html/xyjj/1196.html,/html/zxzx/,/plus/list.php?tid=3,/plus/list.php?tid=18,/plus/list.php?tid=4,/plus/list.php?tid=5,/html/wbtz/1501.html";   //与页面链接的比较

	var cururl = self.location.toString();
	url = cururl.substring(cururl.lastIndexOf('/')+1);

	if(url == '' ){
		url = 'index.html';
	}
	if(allurls.indexOf(url)>=0)
	{
    	activateMenu(cururl);
    	deleteCookie('headerKeepUrl','/');
		setCookie("headerKeepUrl",cururl);
    }else
    {
		var oldurl = getCookie("headerKeepUrl");
		if(!oldurl){
			oldurl = 'index.html';
		}
		activateMenu(oldurl);
		url = oldurl;
    }
}
window.onload=function(){
	navgpos();
}
