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")=='zh_CN')//中文
 {
 	document.cookie="LANGUAGECOOKIE=en_US";
 	//location.href="/en/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>");
document.write("<td style=\"padding:5px 0px 3px 0px;\"><div class=\"language_left\"><a href=\"/ChangeLanguage.do?language=en&repath=http://"+web_site+web_url.replace("?","&")+"\"><span class=\"language_color\">E</span>nglish</a> | <a href=\"/ChangeLanguage.do?language=zh&repath=http://"+web_site+web_url.replace("/en/","/").replace("?","&")+"\"><span class=\"language_color\">C</span>hinese</a></div>");

document.write("<div class=\"language_right\">");
if(GetCookie_("LOGONNAME")!='')
{
	document.write("Hi <a href='http://www.pi-ukchina.org.cn/en/register/member_edit.jsp'>"+GetCookie_("LOGONNAME")+"</a>    | <a href='http://www.pi-ukchina.org.cn/logout.do?rnd="+getRnd()+"'> Withdraw</a> | ");
}
else
{
	document.write("<span style=\"font-family:Arial;\"><a href=\"#\" onClick=\"this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.pi-ukchina.org/en/');return(false);\" style=\"BEHAVIOR: url(#default#homepage)\">Home</a> | ");
	document.write("<a href=\"#\" onClick=\"javascript:window.external.AddFavorite('http://www.pi-ukchina.org/en/', 'PI UKChina')\">Collections</a> | ");
}


document.write("<a href=\"http://www.pi-ukchina.org.cn"+language_this+"/help/help.jsp\">Help</a></span></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  style=\"font-size:11px;\" height=\"24\" background=\"http://www.pi-ukchina.org.cn"+language_this+"/images/img-back.gif\">");
document.write("<div style=\"padding-left:3px; 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\">Home</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\">PIs Profile</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\">Member Profile</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\">Visit & Event</a></div>");
//document.write("\"><a href=\"http://www.pi-ukchina.org.cn"+language_this+"/info/info1.jsp?id=1&catid=20\">Visit Events</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\">Collaboration</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\">E-Journal</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\">Scholarship</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\">Job</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\">Forum</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\">Invitation</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\">Search</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>");
