<!--

function CHeader(c,pd,pd2,instName,appid,appName,cityChangeFun,gjappid,gjappName)  // c:container  pd : pindao,实例名,appid,appNmae,cityChangeFun(type,appid,name)
{
	var bdUrl = "bd";
	var mapUrl = "map";
	var mapurl = "http://map.sogou.com/new/";
	var navurl = ".sogou.com/nav/nav.jsp";
	var busurl = ".sogou.com/bus/maps.htm";
	var localurl = "http://bd.sogou.com/localnew/local.jsp";
	var secpd;

	if(!c) return;
	if(pd==null) pd=1;
	if(pd2==null) pd2=1;
	if(pd==1){
		secpd=pd2;
	}else{
		secpd= pd2+3;
	}
	c.innerHTML ='<form id="headform"><table width="513" border="0" cellspacing="0" cellpadding="0"><tr><td width=380 border=0 valign=top align=left><table width="380" border="0" cellspacing="0" cellpadding="0" style="margin-left:0; margin-top:0"><tr><td colspan="2" id="HeadLink" width=380>&nbsp;</td></tr><tr><td width="300"  id="HeadInput">input</td><td id="HeadButton" align=left></td></tr></table></td><td width=133 id="HeadPD" valign="top" align="left">&nbsp;</td></tr></table></form>';
	var lks = "<li id='nav'><a id='sogou' href='http://www.sogou.com'>网页</a></li>";
	lks += "<li id='nav'><a id='sogou_news' href='http://news.sogou.com'>新闻</a></li>";
	lks += "<li id='nav'><a id='sogou_music' href='http://d.sogou.com'>音乐</a></li>";
	lks += "<li id='nav'><a id='sogou_pic' href='http://pic.sogou.com'>图片</a></li>";
	if(pd==1){
		lks += "<li id='nav'><b style='color:#4A4A4A'>地图</b></li>";
		lks += "<li id='nav'><a id='sogou_bendi' href='http://bd.sogou.com'>本地</a></li>";
	}else{
		lks +=  "<li id='nav'><a id='sogou_map' href='http://map.sogou.com'>地图</a></li>";
		lks += "<li id='nav'><b style='color:#4A4A4A'>本地</b></li>";
	}
	lks += "<li id='nav'><a id='sogou_s' href='http://s.sogou.com'>说吧</a></li>";
	lks += "<li id='nav' style='width:55px'><a id='sogou_gengduo' href='http://www.sogou.com/docs/more.htm'>更多&gt;&gt;</a></li>";
	if(pd2==1){
		_g("HeadInput").innerHTML="<input type='text' id='query' name='query'  value='' />";
	}else {
		StartEnd();
	}
    _g("HeadButton").innerHTML="<input type=submit name='search' value='搜　索'  id='search' class='search'>";
	_g("HeadLink").innerHTML=lks;
	var pks ='';
	pks += '<input class="h_hidden" type="text" value="" id="H_GJName"><input class="h_hidden" type="text" value="" id="H_GJAppid">';
	pks += '<input class="h_hidden" type="text" value="" id="H_BDName"><input class="h_hidden" type="text" value="" id="H_BDAppid">';
	pks += '<div id="hpd_1" class="c" >';
	if(pd==1){
		pks += '地图';
	}else{
		pks += "本地";
	}
	pks += '</div>';
	pks +='<div  id="hpd_2" class="c" >自驾</div>';
	if(pd2==3){
		var w = 300;
		var h = 300;
		var name ="";
		if(gjappid==null || gjappName==null || gjappid=="" || gjappName==""){
			if(getCookie('go2map_head_GJCity')==null || getCookie('go2map_head_GJCity')==""){
				name ="北京";
				setCookie("go2map_head_GJCity","北京");
				setCookie("go2map_head_GJAppid","1421");
			}
			name = getCookie('go2map_head_GJCity');
		}else{
			name= gjappName;
			setCookie("go2map_head_GJCity",gjappName);
			setCookie("go2map_head_GJAppid",gjappid);
		}
		var s="公交：<font id='head_cityname' class='selectCity'>["+name+"]</font> <span  class='c'  onclick=window.open('selectGJCity.jsp?headName="+instName+"','local_w','width=320,height=165,resize=no,left=308,top=294')>选城市</span>";
		pks +='<div  id="hpd_3" class="c" >'+s+'</div>';
	}else{
		pks +='<div  id="hpd_3" class="c" >公交</div>';
	}
	_g("HeadPD").innerHTML=pks;
	_g( "hpd_"+pd2).className="c2";
	if(gjappid==null || gjappName==null || gjappid=="" || gjappName==""){
		if(getCookie('go2map_head_GJCity')==null || getCookie('go2map_head_GJCity')==""){
			setCookie("go2map_head_GJCity","北京");
			setCookie("go2map_head_GJAppid","1421");
		}
		_g("H_GJName").value=getCookie('go2map_head_GJCity');
		_g("H_GJAppid").value = getCookie('go2map_head_GJAppid');
	}else{
		_g("H_GJName").value=appName
		_g("H_GJAppid").value = appid;
		setCookie("go2map_head_GJCity",gjappName);
		setCookie("go2map_head_GJAppid",gjappid);

	}
	if(appid==null || appName==null || appid=="" || appName==""){
		if(getCookie('appid')==null || getCookie('appid')==""){
			setCookie("go2map_head_BDCity","北京");
			setCookie("appid","1147");
		}
		_g("H_BDName").value=getCookie('go2map_head_BDCity');
		_g("H_BDAppid").value = getCookie('appid');
	}else{
		_g("H_BDName").value=appName
		_g("H_BDAppid").value = appid;
		setCookie("go2map_head_BDCity",appName);
		setCookie("appid",appid);
	}
	if(pd==2 && pd2==1){
		_g("hpd_1").innerHTML =  "本地：<font id='head_cityname' class='selectCity'>["+ getCookie('go2map_head_BDCity')+"]</font> <span  class='c'  onclick=window.open('selectBDCity.jsp?headName="+instName+"','local_w','width=320,height=150,resize=no,scrollbars=no,left=308,top=294')>选城市</span>";
	}
	var t1 = _c("div");
	_r(t1,"id","sosou1");
	_a(c,t1);

	if(pd2==1){
		_g("query").focus();
	}else{
		_g("start").focus();
	}
	_g("hpd_1").onclick=function(){
		_g("HeadInput").innerHTML="<input type='text' id='query' name='query'  value='' />";
		if(pd==2){
			secpd=4;
			var name=_g("H_BDName").value;
			var id=_g("H_BDAppid").value;
			var w = 300;
			var h = 300;
			var s="本地：<font id='head_cityname' class='selectCity'>["+name+"]</font> <span  class='c'  onclick=window.open('selectBDCity.jsp?headName="+instName+"','local_w','width=320,height=150,resize=no,scrollbars=no,left=308,top=294')>选城市</span>";
			_g("hpd_1").innerHTML=s;
		}else{
			secpd=1;
		}
		initPD(1);
	};
	_g("hpd_2").onclick=function(){
		if(pd==2){
			secpd=5;
		}else{
			secpd=2;
		}
		StartEnd();
		initPD(2);
	};
	_g("hpd_3").onclick=function(){
		if(pd==2){
			secpd=6;
		}else{
			secpd=3;
		}
		if(_g("H_GJName").value=="null" || _g("H_GJName").value=="" ){
				_g("H_GJName").value="北京";
				_g("H_GJAppid").value="1421";
		
				setCookie("go2map_head_GJCity","北京");
				setCookie("go2map_head_GJAppid","1421");
		}
		var name=_g("H_GJName").value;
		var id=_g("H_GJAppid").value;
		StartEnd();
		var w = 300;
		var h = 300;
		var s="公交：<font id='head_cityname' class='selectCity'>["+name+"]</font> <span  class='c'  onclick=window.open('selectGJCity.jsp?headName="+instName+"','local_w','width=320,height=150,resize=no,left=308,top=294')>选城市</span>";
		_g("hpd_3").innerHTML=s;
		initPD(3);
		
	};
	_g("headform").onsubmit=function(){
		var str=""
		switch(pd2){
			case 1:
				var kw = _g("query").value;
				var whitespace = new String(" \t\n\r%");
				var s = new String(kw);
				if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
				{
					var i = s.length - 1;
					while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
					{
						i--;
					}
					s = s.substring(0, i+1);
				}
				if (whitespace.indexOf(s.charAt(0)) != -1)
				{
					var j=0, i = s.length;
					while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
					{
						j++;
					}
					s = s.substring(j, i);
				}
				s = s.toUpperCase();
				if(pd==1){
					str = mapurl+"#lq="+s;
				}else if(pd==2){
					str = localurl+"?query="+escape(s)+"&page=1";
				}
				break;
			case 2:
				if(pd==1){
					str = "http://"+mapUrl;
				}else if(pd==2){
					str = "http://"+bdUrl;
				}
				str += navurl+"?from="+_g("start").value.toUpperCase()+"&to="+_g("end").value.toUpperCase();
				break;
			case 3:
				if(pd==1){
					str = "http://"+mapUrl;
				}else if(pd==2){
					str = "http://"+bdUrl;
				}
				str += busurl+"?appid="+_g("H_GJAppid").value+"&start="+_g("start").value.toUpperCase()+"&end="+_g("end").value.toUpperCase()+"&tactic=8&mode=NORMAL";
				break;
		}
		window.location = str;
		return false;
	
	}
	function initPD(n){
		pd2=n;
		for(var i=1;i<4;i++){
			_g( "hpd_"+i).className="c";
		}
		if(pd==2 && n!=1){
			_g( "hpd_1").innerHTML="本地";
		}
		if(n!=3){
			_g( "hpd_3").innerHTML="公交";
		}
		_g( "hpd_"+n).className="c2";
	}
	this.changeGJCity=function(id,name){
		var o = _g("head_cityname");
		if(o!=null){
			o.innerHTML="["+name+"]";
		}
		if(_g("H_GJName")){
			_g("H_GJName").value=name;
			_g("H_GJAppid").value = id;
		}
		setCookie("go2map_head_GJCity",name);
		setCookie("go2map_head_GJAppid",id);
		this.evalChangeCity("GJ",id,name);
	}
	this.changeBDCity=function(id,name){
		var o = _g("head_cityname");
		if(o!=null){
			o.innerHTML="["+name+"]";
		}
		if(_g("H_BDName")){
			_g("H_BDName").value=name;
			_g("H_BDAppid").value = id;
		}
		setCookie("appid",id);
		setCookie("go2map_head_BDCity",name);
		this.evalChangeCity("BD",id,name);
	}
	this.evalChangeCity=function(type,id,name){
		if(cityChangeFun!=null && cityChangeFun!=""){
			var s = cityChangeFun+"('"+type+"',"+id+",'"+name+"')";
			try{
				eval(s);
			}catch(e)
			{
			}
		}
	}
	function StartEnd(){
		_g("HeadInput").innerHTML="从 <input id='start' type='text' value='' > 到 <input id='end' type='text' value=''>";
	}
	function _g(str){
		return document.getElementById(str);
	}
	function _c(str){
		return document.createElement(str);
	}
	function _a(a,b){
		a.appendChild(b);
	}
	function _r(a,b,c){
		a.setAttribute(b,c)
	}
	function setCookie(name,value)
	{
		 var argv=arguments;
		 var argc=argv.length;
		 var date = new Date();
		date.setTime(date.getTime()+31536000);
		 var expires=(2<argc)?argv[2]:date;
		 var path="/";
		 var domain=".sogou.com";
		 var secure=(5<argc)?argv[5]:false;
		 document.cookie=name+"="+escape(value)+((expires==null)?"":("; expires="+expires.toGMTString()))+((path==null)?"":("; path="+path))+((domain==null)?"":("; domain="+domain))+((secure==true)?"; secure":"");
	}
	function getCookieVal(offset)
	{
		var endstr=document.cookie.indexOf(";",offset);
		if(endstr==-1)
		endstr=document.cookie.length;
		return unescape(document.cookie.substring(offset,endstr));
	};
	function getCookie(name)
	{
		var arg=name+"=",alen=arg.length,clen=document.cookie.length;
		var i=0;
		while(i<clen)
		{
			var j=i+alen;
			if(document.cookie.substring(i,j)==arg)
			return getCookieVal(j);
			i=document.cookie.indexOf(" ",i)+1;
			if(i==0)
			break;
		}
		return null;
	};
	this.getStatus=function(){
		return secpd;
	}
}


//-->