// 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" : "");

/*
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.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("nov");    //连接上层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+1;

        var docel = document.getElementById('nov'+linkindex);      //novBtn 连接ID
		if(docel){			
			docel.className="firstLOn"+linkindex;   //点击后样式
		   //docel.firstChild.style.background='url(../image/btn_novOn.gif)';
		   //docel.firstChild.style.color='#FFF';
		}
    }else{
	    if(initselect < items.length)
	    {
			var linkindex = 1;
			var docel = document.getElementById('novBtn'+linkindex);
			if(docel){
				docel.className="firstL"+linkindex;  //没被点击样式
			  //docel.firstChild.style.background='url(../image/btn_novOff.gif)';
	  		  //docel.firstChild.style.color='#FFF';
			}
		}
	}
}
// Select the menu that matches the URL when the page loads
function navgpos(){

	var allurls = "index.html,eduThought.html,productIntro.html,shop.html,mavin.html,http://bbs.chinaedu.net/forum-39-1.html,show.html,yoyoHollow.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();
}
