function getRnd(){
  var date=new Date();
  var rnd=date.getTime();
  return rnd;
}

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 + "=";
     var alen = arg.length;
     var 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 "";
}
//document.write("测试现在语言版本: "+GetCookie_ ("LANGUAGECOOKIE"));
//jsp js 语言版本的更换
//add by denny 2007/08/02
//jsp js 语言版本的更换
//只用于JS,并且要将所有的jsp页面都包含此JS
//英文的所有文件都放在en目录下
//LANGUAGECOOKIE是语言更换的Cookie Name
//当域名出现group(groug是MVC模式,由spring国际化实现)时,此JS将不起作用
//类似piuk的项目可以采用此方法

var en_url="/en/";
var en_url_path="/en";
var not_chenge = "group.";
var documentURL = document.URL;
var web_site = documentURL.replace(/(http:\/\/)(.+?)(\/.*)/gi,'$2');
var web_url = documentURL.substring(documentURL.indexOf(web_site)+web_site.length,documentURL.length);
var isNotChenge = false;
if(web_site.indexOf(not_chenge)!=-1||web_site.indexOf(".do")!=-1)
	isNotChenge = true;
var language_this = "";

if(web_url.indexOf("/en/")==-1){
	if(GetCookie_ ("LANGUAGECOOKIE")=='en_US')//中文
 {
 	document.cookie="LANGUAGECOOKIE=zh_CN";
 	//document.location.href="/chuliCook.jsp?rath="+web_url;
  }
}

if(GetCookie_ ("LANGUAGECOOKIE")=='en_US')//英文
{
	language_this ="/en";
}


if(!isNotChenge)
{
	if(GetCookie_ ("LANGUAGECOOKIE")=='zh_CN')//中文
	{
		var URLGoto ="/";
		if(web_url==en_url_path)
		{
				URLGoto="http://"+web_site+"/";
				if(URLGoto!=("http://"+web_site+"/en/en")&&URLGoto!=("http://"+web_site+"/en/en/"))
					document.location.href=URLGoto;
		}
		
		if(web_url.length>4)
		{
			var web_urls = web_url.substring(0,4);
			if(web_urls==en_url)
			{
				URLGoto="http://"+web_site+"/"+web_url.substring(4,web_url.length);
				if(URLGoto!=("http://"+web_site+"/en/en")&&URLGoto!=("http://"+web_site+"/en/en/"))
					document.location.href=URLGoto;
			}
			
		}


		
	}
	if(GetCookie_ ("LANGUAGECOOKIE")=='en_US')//英文
	{
		var URLGoto ="/";
		if(web_url.length>4)
		{
			var web_urls = web_url.substring(0,4);
			if(web_urls!=en_url)
			{
				URLGoto="http://"+web_site+en_url_path+web_url;
				if(URLGoto!=("http://"+web_site+"/en/en")&&URLGoto!=("http://"+web_site+"/en/en/"))
					document.location.href=URLGoto;
			}
			
		}
		else
		{
			if(web_url!=en_url_path)
			{
				URLGoto="http://"+web_site+"/en"+web_url;
				if(URLGoto!=("http://"+web_site+"/en/en")&&URLGoto!=("http://"+web_site+"/en/en/"))
					document.location.href=URLGoto;
			}
			
		}
		
		
	}
}

//jsp js 语言版本的更换

document.write("<table width=\"778\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
document.write("<tr>");
if(!isNotChenge)
	document.write("<td style=\"padding:5px 0px 3px 0px;\"><div class=\"language_left\"><a href=\"/ChangeLanguage.do?language=en&repath=http://"+web_site+"/en"+web_url.replace("?","&")+"\"><span class=\"language_color\">E</span>nglish</a> | <a href=\"/ChangeLanguage.do?language=zh&repath="+document.URL.replace("?","&")+"\"><span class=\"language_color\">中</span>文</a></div>");
else
	document.write("<td style=\"padding:5px 0px 3px 0px;\"><div class=\"language_left\"><a href=\"/ChangeLanguage.do?language=en&repath="+document.URL.replace("?","&")+"\"><span class=\"language_color\">E</span>nglish</a> | <a href=\"/ChangeLanguage.do?language=zh&repath="+document.URL.replace("?","&")+"\"><span class=\"language_color\">中</span>文</a></div>");	
document.write("<div class=\"language_right\">");
if(GetCookie_("LOGONNAME")!='')
{
	document.write("您好 <a href='http://www.pi-ukchina.org.cn/register/member_edit.jsp'>"+GetCookie_("LOGONNAME")+"</a>   <a href='http://www.pi-ukchina.org.cn/logout.do?rnd="+getRnd()+"'> 退出</a> ");
}
else
{
	document.write("<a href=\"#\" onClick=\"this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.pi-ukchina.org/');return(false);\" style=\"BEHAVIOR: url(#default#homepage)\">设为首页</a> | ");
	document.write("<a href=\"#\" onClick=\"javascript:window.external.AddFavorite('http://www.pi-ukchina.org/', 'PI UKChina')\">加入收藏</a> | ");
}

document.write("<a href=\"http://www.pi-ukchina.org.cn"+language_this+"/help/help.jsp\">帮助</a></div></td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td height=\"1\" background=\"http://www.pi-ukchina.org.cn"+language_this+"/images/img-line.gif\"><img src=\"http://www.pi-ukchina.org.cn"+language_this+"/images/spacer.gif\" width=\"1\" height=\"1\" /></td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td height=\"76\"><div style=\"float:left\"><a href=\"http://www.pi-ukchina.org.cn\"><img src=\"http://www.pi-ukchina.org.cn"+language_this+"/images/piuk-logo.jpg\" alt=\"PI-UKChina\" border=\"0\" /></a></div>");
document.write("<div style=\"float:right\"><a href=\"http://www.britishcouncil.org.cn/\" target=\"_blank\"><img src=\"http://www.pi-ukchina.org.cn"+language_this+"/images/bc-logo.jpg\" alt=\"英国文化协会中国办公室\" border=\"0\" /></a></div></td>");
document.write("</tr>");
document.write("</table>");

document.write("<table width=\"778\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
document.write("<tr>");
document.write("<td bgcolor=\"#B2B2B2\"><img src=\"http://www.pi-ukchina.org.cn"+language_this+"/images/spacer.gif\" width=\"1\" height=\"1\" /></td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td height=\"24\" background=\"http://www.pi-ukchina.org.cn"+language_this+"/images/img-back.gif\">");
document.write("<div style=\"padding-left:60px; text-align:left\">");
document.write("<div class=\"");
if(document.URL.indexOf("index")!=-1) 
document.write("menuon_2"); 
else 
document.write("menuoff_2");
document.write("\"><a href=\"http://www.pi-ukchina.org.cn"+language_this+"/index.jsp\">首页</a></div>");
document.write("<div class=\"");

if(document.URL.indexOf("?id=1&")!=-1&&document.URL.indexOf("?id=1&catid=20")==-1) 
document.write("menuon_2"); 
else 
document.write("menuoff_2");
document.write("\"><a href=\"http://www.pi-ukchina.org.cn"+language_this+"/info/info1.jsp?id=1&catid=15\">学会</a></div>");
document.write("<div class=\"");

if(document.URL.indexOf("/info/")!=-1 && document.URL.indexOf("?id=7")!=-1) 
document.write("menuon_2"); 
else 
document.write("menuoff_2");
document.write("\"><a href=\"http://www.pi-ukchina.org.cn"+language_this+"/info/info1.jsp?id=7\">会员名录</a></div>");
document.write("<div class=\"");

if(document.URL.indexOf("/event/")!=-1||document.URL.indexOf("?id=1&catid=20")!=-1) 
document.write("menuon_2"); 
else
document.write("menuoff_2");
document.write("\"><a href=\"http://www.pi-ukchina.org.cn"+language_this+"/info/info1.jsp?id=1&catid=20\">访问活动</a></div>");
document.write("<div class=\"");

if(document.URL.indexOf("/info/")!=-1 && document.URL.indexOf("?id=2&")!=-1) 
document.write("menuon_2"); 
else 
document.write("menuoff_2");
document.write("\"><a href=\"http://www.pi-ukchina.org.cn"+language_this+"/info/info.jsp?id=2&catid=4\">国际合作</a></div>");
document.write("<div class=\"");

if(document.URL.indexOf("/info/")!=-1 && document.URL.indexOf("?id=8")!=-1) 
document.write("menuon_2"); 
else 
document.write("menuoff_2");
document.write("\"><a href=\"http://www.pi-ukchina.org.cn"+language_this+"/info/info1.jsp?id=8\">电子杂志</a></div>");
document.write("<div class=\"");

if(document.URL.indexOf("/info/")!=-1 && document.URL.indexOf("?id=9")!=-1) 
document.write("menuon_2"); 
else 
document.write("menuoff_2");
document.write("\"><a href=\"http://www.pi-ukchina.org.cn"+language_this+"/info/info.jsp?id=9\">奖学金</a></div>");
document.write("<div class=\"");

if(document.URL.indexOf("/info/")!=-1 && document.URL.indexOf("?id=6")!=-1) 
document.write("menuon_2"); 
else 
document.write("menuoff_2");
document.write("\"><a href=\"http://www.pi-ukchina.org.cn"+language_this+"/info/info.jsp?id=6\">工作机会</a></div>");
document.write("<div class=\"");

if(document.URL.indexOf("http://group.")!=-1) 
document.write("menuon_2"); 
else
document.write("menuoff_2");
document.write("\"><a href=\"http://group.pi-ukchina.org.cn/random_tribe.do\">论坛</a></div>");
document.write("<div class=\"");

if(document.URL.indexOf("/invite/")!=-1) 
document.write("menuon_2"); 
else 
document.write("menuoff_2");
document.write("\"><a href=\"http://www.pi-ukchina.org.cn"+language_this+"/invite/invite.jsp\">邀请</a></div>");
document.write("<div class=\"");

if(document.URL.indexOf("/search/")!=-1) 
document.write("menuon_2"); 
else 
document.write("menuoff_2");
document.write("\"><a href=\"http://www.pi-ukchina.org.cn"+language_this+"/search/search.jsp\">搜索</a></div>");
document.write("</div></td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td bgcolor=\"#D73037\"><img src=\"http://www.pi-ukchina.org.cn"+language_this+"/images/spacer.gif\" width=\"1\" height=\"5\" /></td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td><img src=\"http://www.pi-ukchina.org.cn"+language_this+"/images/spacer.gif\" width=\"1\" height=\"10\" /></td>");
document.write("</tr>");
document.write("</table>");