var  nav_initial = function(){
    	for(var i = 0; i < menuLength; i ++)
    	{
    		document.getElementById("menuli"+i).menuIndex = i;
    		document.getElementById("navli"+i).menuIndex = i;
    	}
        document.getElementById("navli"+0).style.display = "block";
        setNav2(0,defaultIndex);
}

//path_filter use to handler sub path repeat: like /mc/mc/mc_faq.html
function write_head(index){
    defaultIndex = index;
    
    if (window.addEventListener)
        window.addEventListener("load",nav_initial, false);
    else if (window.attachEvent) 
        window.attachEvent("onload", nav_initial);
    
    var content = '\
    <div id="head-top">\
      <div id="topnav">\
        <ul>\
          <li><a href="/map.html" title="网站地图" class="nav_1" >网站地图</a></li>\
          <li>│</li>\
          <li><a href="javascript:addBookmark(\'http://wapclick.com\', \'Wapclick[手机广告联盟]\')" title="收藏本站" class="nav_2">收藏本站</a></li>\
          <li>│</li>\
          <li><a href="http://bbs.wapclick.com" title="客户留言" class="nav_3">客户留言</a></li>\
          <li>│</li>\
          <li><a href="http://blog.wapclick.com" title="我们的博客" class="nav_4">我们的博客</a></li>\
        </ul>\
        <span id="logo"><a href="/"><img src="/image/top_2/logo.gif" alt="WAPclick[无限点击]" /></a></span>\
        <span id="roll_ad"><marquee style="float:right;margin-top:25px;" onmouseout="start()" onmouseover="stop()" scrollamount="3" scrolldelay="150" width="580px" dataformatas="html" behavior="scroll" loop="-1" direction="left"><a href="/top2/show_news.cgi?id=89">[公告] v8书客活动暂停通知 (2008-06-17)</a></marquee></span>\
      </div>\
      <!-- menu begin-->\
      <div class="menubox" id = "menubox" onmouseout="setNav(event, this, true)">\
        <ul id="menu" class="tab0">\
          <li id="menuli0"  onmouseover="setNav(event, this, true)"><a href="/" class="nav1">首页</a> </li>\
          <li id="menuli1"  onmouseover="setNav(event, this, true)"><a href="/mc/mc.html" class="nav1">广告主 </a> </li>\
          <li id="menuli2"  onmouseover="setNav(event, this, true)"><a href="/as/as.html" class="nav1">网站主 </a> </li>\
          <li id="menuli3"  onmouseover="setNav(event, this, true)"><a href="/service.html" class="nav1">产品与服务 </a> </li>\
          <li id="menuli4"  onmouseover="setNav(event, this, true)"><a href="/top2/news_index.cgi" class="nav1">新闻中心 </a> </li>\
          <li id="menuli5"  onmouseover="setNav(event, this, true)"><a href="/ourpartner.html" class="nav1">客户与伙伴 </a> </li>\
          <li id="menuli6"  onmouseover="setNav(event, this, true)"><a href="/aboutus.html" class="nav1">关于我们 </a> </li>\
        </ul>\
        <ul id="nav" class="subtab0">\
          <li id="navli0" class="subnav1">欢迎来到WapClick</li>\
          <li id="navli1" class="subnav2"><a href="/mc/mc.html#mc_step_achor">注册流程介绍</a><a href="/mc/mc.html#mc_zy_achor">注意事项</a><a href="/mc/mc-faq.html">FAQ</a></li>\
          <li id="navli2" class="subnav3"><a href="/as/as.html#as_step_achor">注册流程介绍</a><a href="/as/as.html#as_zy_achor">注意事项</a><a href="/as/as-faq.html">FAQ</a></li>\
          <li id="navli3" class="subnav4"><a href="/service.html#service_desc_achor">业务介绍</a><a href="/service.html#service_area_achor">业务范围</a><a href="/successcase.html">成功案例</a></li>\
          <li id="navli4" class="subnav5"><a href="/top2/news_index.cgi">业界新闻</a><a href="/top2/news_actpage.cgi">活动公告</a><a href="/news/news-picdownload.html">Wapclick桌面下载</a></li>\
          <li id="navli5" class="subnav6">等待您的加盟，期待与您合作</li>\
          <li id="navli6" class="subnav7"><a href="/joinus.html">加入我们</a><a href="/contactus.html">联系我们</a></li>\
        </ul>\
      </div>\
    </div>';
    
    document.write(content);
    //default tab
    document.getElementById("menuli"+index).className = "hover";
    document.getElementById("navli"+index).style.display = "block";
    
//    getRollAd();

}

function write_footer(){
    
    var content = '\
        <p id="left"><img src="/image/top_2/footer-left.gif"/></p>\
    <p id="right"><img src="/image/top_2/footer-right.gif"/></p>\
    <div>\
      <ul>\
        <li><a href="/">首页</a></li>\
        <li> │ </li>\
        <li><a href="/mc/mc.html">广告主</a></li>\
        <li> │ </li>\
        <li><a href="/as/as.html">网站主</a></li>\
        <li> │ </li>\
        <li><a href="/service.html">产品与服务</a></li>\
        <li> │ </li>\
        <li><a href="/news/news-index.html">新闻中心</a></li>\
        <li> │ </li>\
        <li><a href="/ourpartner.html">客户与伙伴</a></li>\
        <li> │ </li>\
        <li><a href="/aboutus.html">关于我们</a></li>\
      </ul>\
      <p id="copyright">Copyright @ 2006 WAPclick.com All Rights Reserved</p>\
    </div>\
    <div id="float_1"><a href="#"> <img src="/image/top_2/gobacktotop.gif" alt="go back to top" /></a></div>';
    
    document.write(content);
    
    
}

function addBookmark(url,title) {
    if (window.sidebar) { 
        window.sidebar.addPanel(title, url,""); 
    } else if( document.all ) {
        window.external.AddFavorite( url, title);
    } else if( window.opera && window.print ) {
        return true;
    }
}

function setCookie(name, value){
　　var expireDate= new Date;
　　expireDate.setHours(expireDate.getHours()+1);
//　　expireDate.setMonth(expireDate.getMonth()+6);
	var Cookie=escape(name)+"="+escape(value)+";expires="+expireDate.toGMTString();
	document.cookie=Cookie;
}

function getCookie(cookieName) {
  var cookieString = document.cookie;
  var start = cookieString.indexOf(cookieName + '=');
  if (start == -1) // 找不到
    return '';
  start += cookieName.length + 1;
  var end = cookieString.indexOf(';', start);
  if (end == -1) return unescape(cookieString.substring(start));
  return unescape(cookieString.substring(start, end));
}

var rollAdXmlHttp;
function getRollAd(){
    var ad_text = getCookie('ad_text');
    var ad_url = getCookie('ad_url');
    if(ad_text=='' || ad_url ==''){
    	if(window.ActiveXObject){
    		rollAdXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    	}
    	else if(window.XMLHttpRequest){
    		rollAdXmlHttp = new XMLHttpRequest();
    	}
        var url = "/top2/get_roll_ad.cgi";
    	rollAdXmlHttp.open("POST",url,true);
    	rollAdXmlHttp.onreadystatechange = getRollAdBack;
    	rollAdXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    	rollAdXmlHttp.send('');
    }else{
        var str = '<marquee style="float:right;margin-top:25px;" onmouseout="start()" onmouseover="stop()" scrollamount="3" scrolldelay="150" width="580px" dataformatas="html" behavior="scroll" loop="-1" direction="left"><a href="'+ad_url+'">'+ad_text+'</a></marquee>';
        document.getElementById('roll_ad').innerHTML = str;
    }
}

function getRollAdBack(){
    if(rollAdXmlHttp.readyState == 4){
		if(rollAdXmlHttp.status == 200 || rollAdXmlHttp.status == 0){
			var result = rollAdXmlHttp.responseText;
            var param_list = result.split("\n");
            var ad_text = param_list[0];
            var ad_url = param_list[1];
            var str = '<marquee style="float:right;margin-top:25px;" onmouseout="start()" onmouseover="stop()" scrollamount="3" scrolldelay="150" width="580px" dataformatas="html" behavior="scroll" loop="-1" direction="left"><a href="'+ad_url+'">'+ad_text+'</a></marquee>';
            document.getElementById('roll_ad').innerHTML = str;
            setCookie('ad_text',ad_text);
            setCookie('ad_url',ad_url);
		}
	}
}

