var messages_zh_extra={
cvicse:'中创软件商用中间件公司',
version:"TrustieForge 3.1 Build 20100824",
title:'TrustieForge',
username:'用户名',
password:'密     码',
help:'帮助',
home:'登录',
register:'注册新用户',
registerdetail:'没有注册？点此注册',
retrievepassword:'取回密码',
reactivate:'重新激活',
addbookmark:'加入收藏夹',
validatecode:'验证码',
wait:'发送请求中，请稍后...',
refreshvalidatecode:'刷新验证码',
usernameisnull:'用户名不能为空',
passwordisnull:'密码不能为空',
validateisnull:'验证码不能为空',
loginerror:'用户名不存在或密码错误',
validateerror:'验证码不正确',
unknowerror:'连接到服务器发生异常，请稍后重新尝试！',
favoriteerror: '您的浏览器不支持收藏夹',
returnloginpage:'返回登录界面',
ok:'确定',
portalhome:'门户首页',
trustieIntroduction1:'<div class="infoTitle">Trustie协同平台为软件创新筑新巢！</div><div class="infoTitle">Trustie协同平台是国家高技术研究发展计划（863计划）“高可信软件生产工具及集成环境”项目“可信的国家软件资源共享与协同生产环境”。</div><div class="infoTitle">Trustie协同平台最佳运行环境：Microsoft Internet Explorer 7.0+, Mozilla Firefox 3.0+（推荐）。</div>',
trustieIntroduction2:'<div class="infoTitle">Trustie协同平台集成了开发、协同和项目管理等工具套件来支撑企业软件开发流程，以提高个人和团队的生产力、缩短软件开发周期并有助于快速交付高质量的软件。主要功能：</div><ul class="ul_expla"><li><h3>应用生命周期管理 </h3><p>将文档和讨论主题与问题和源代码相关联，以改进可跟踪并提高效率。定义、部署和重用标准开发流程，将其提升为最佳实践。</p></li> <li><h3>数据安全管理</h3><p>使用功能丰富的基于角色的访问框架，精确控制用户对资源的访问。轻松地创建和管理项目工作区，以标准化或自定义项目资源、内容。</p></li><li><h3>软件配置管理</h3><p>建立一个安全、集中的项目源代码仓库，以满足审计和遵从性需求；提供WEB在线SCM存储库的配置和浏览功能；支持细粒度的权限访问控制。</p></li><li><h3>项目计划管理</h3><p>基于敏捷开发思想构建，支持XP、SCRUM等开发理念；管理项目计划和可交付结果，以获得对开发状态的可见性；跟踪活动指标，以实时了解项目活动等。</p></li><li><h3>集成沟通交流工具</h3> <p>提供WEB和桌面两种类型的即时通信工具，用户随时在线；提供在线论坛、邮件列表服务，以便项目成员即时沟通交流。</p> </li> <li class="no_bg"><h3>软件即服务</h3><p>使用Trustie托管服务降低软件开发所需软硬件购置成本和开发环境管理维护成本。</p></li></ul>'
};

var messages_en_extra={
cvicse:'CVIC SE Middleware',
username:'User Name',
password:'Password',
help:'Help',
home:'Login',
register:'Register',
registerdetail:'Create a new account',
retrievepassword:'Retrieve password',
reactivate:'Reactivate',
addbookmark:'Set as favorite',
validatecode:'Validated Code',
wait:'Send request, Please wait...',
refreshvalidatecode:'Refresh Validated Code',
usernameisnull:'User name can not be empty',
passwordisnull:'Password can not be empty',
validateisnull:'Validated Code can not be empty',
loginerror:'Username does not exist or wrong password',
validateerror:'Validated Code does not match',
unknowerror:'An error was returned from the server, please try again later!',
favoriteerror: 'Your browser does not support Favorites',
returnloginpage:'Return login page',
ok:'OK',
portalhome:'Portal Home',
trustieIntroduction1:'<div class="infoTitle">Trustie Collaboration Platform, Hosting Software Innovation!</div><div class="infoTitle">Trustie Collaboration Platform is part of the National 863 Hi-tech project “Trustworthy Software Resource Sharing and Collaborative Development Environment” under “Highly Trustworthy Software Tools and Integrated Environment”.</div> <div class="infoTitle">Trustie Collaboration Platform best in: Microsoft Internet Explorer 7.0+, Mozilla Firefox 3.0+ (Recommended).</div>',
trustieIntroduction2:'<div class="infoTitle">Trustie Collaborative Development Platform facilitate project development, team collaboration and project management in the corporate and as a full suite can be used to support project lifecycle in the corporate, to improve productivity under a time budget but for high quality piece of software.</div><ul class="ul_expla"><li><h3>Software Lifecycle</h3><p> Associate your documents and discussion threads with your source code, to improve your efficiency.</p></li><li><h3>Data Security</h3> <p>A permission integration framework to provide role based user access control to protect your resource. </p></li><li><h3> Project Configuration</h3><p>A central software repository with web access and browsing capability, giving permission definitions.</p></li> <li><h3> Project Plan</h3><p>In an Agile Software Development environment, project Management, track and planning tools is provided here.</p></li><li><h3>Communication tools</h3><p>Contact each other online; News group and mailing list are available to facilitate team communication.</p></li><li class="no_bg"><h3>Software as Services</h3><p>With Trustie Hosting Service, you can reduce the cost for hardware purchasing and software management.</p></li></ul>'
};

var messages;
var language;
//setLanguage(window.navigator.language||window.navigator.browserLanguage);

function setLanguage(lang){
	if(lang&&lang.toLowerCase().indexOf('zh')==0){
		language='zh';
		messages=messages_zh;
	}else{
		language='en';
		messages=messages_en;
	}
	for(var name in messages_zh_extra){
		if(!messages_zh[name]){
		 messages_zh[name]=messages_zh_extra[name];
		}
	}
	
	for(var name in messages_en_extra){
		if(!messages_en[name]){
		 messages_en[name]=messages_en_extra[name];
		}
	}
	
	for(var name in messages_en){
		if(!messages_zh[name]){
		 messages_zh[name]=messages_en[name];
		}
	}
	
	for(var name in messages_zh){
		if(!messages_en[name]){
		 messages_en[name]=messages_zh[name];
		}
	}
	
	window.document.title=messages['title'];
	if(!$('help')){
		window.onload=function(){setLanguage(language);};
	};
	if($('zh'))
	$('zh').style.display=(messages==messages_zh)?"none":"";
	if($('en'))
    $('en').style.display=(messages==messages_en)?"none":"";
    if($('language'))
  	$('language').value=language;
  	if($('version'))
  	$('version').innerHTML=messages['version'];
  	if($('portalhome'))
  	$('portalhome').onclick=function(){window.location.href='../../';};
  	if($('portalhome'))
  	$('portalhome').alt=messages['portalhome'];
  	if($('portalhome'))
  	$('portalhome').title=messages['portalhome'];
  	if($('home'))
  	$('home').innerHTML=messages['home'];
  	if($('home'))
  	$('home').href="../../cas/login?locale="+language+getUrlWithName("&service");
  	if($('register'))
  	$('register').innerHTML=messages['register'];
  	if($('register'))
  	$('register').href="./register.html?language="+language+getUrlWithName("&url");
  	if($('retrievepassword'))
  	$('retrievepassword').innerHTML=messages['retrievepassword'];
  	if($('retrievepassword'))
  	$('retrievepassword').href="./retrievePwd.html?language="+language+getUrlWithName("&url");
  	if($('reactivate'))
  	$('reactivate').innerHTML=messages['reactivate'];
  	if($('reactivate'))
  	$('reactivate').href="./reactivate.html?language="+language+getUrlWithName("&url");
  	if($('refreshImagBtn'))
  	$('refreshImagBtn').title=messages['refreshvalidatecode'];
  	if($('refreshImagBtn'))
  	$('refreshImagBtn').alt=messages['refreshvalidatecode'];
  	if($('refreshImagBtnimg'))
  	$('refreshImagBtnimg').alt=messages['refreshvalidatecode'];
  	if($('help'))
  	$('help').title=messages['version']+" "+messages['help'];
  	if($('help'))
  	$('help').alt=messages['version']+" "+messages['help'];
  	if($('helpimg'))
  	$('helpimg').alt=messages['version']+" "+messages['help'];
  	if($('bookmarka'))
  	$('bookmarka').alt=messages['addbookmark'];
  	if($('bookmarka'))
  	$('bookmarka').title=messages['addbookmark'];
  	if($('bookmarkimg'))
  	$('bookmarkimg').alt=messages['addbookmark'];
  	if($('returnloginpage'))
  	$('returnloginpage').innerHTML=messages['returnloginpage'];
  	if($('returnloginpage'))
  	$('returnloginpage').href="../../cas/login?locale="+language+getUrlWithName("&service");
  	if($('usernamelabel'))
  	$('usernamelabel').innerHTML=messages['username'];
  	if($('passwordlabel'))
 	$('passwordlabel').innerHTML=messages['password'];
 	if($('validatecodelabel'))
  	$('validatecodelabel').innerHTML=messages['validatecode'];
  	if($('cvicse'))
  	$('cvicse').innerHTML=messages['cvicse'];
  	if($('infomationContainer')){
  		if($('infomationContainer').className=='longInfo'){
  		 $('infomationContainer').innerHTML=messages['trustieIntroduction1']+messages['trustieIntroduction2'];
  		}else{
  		 $('infomationContainer').innerHTML=messages['trustieIntroduction2'];
  		}
  	}
}

function setLabels(lang){
  var showMessageText=$('showMessage').innerHTML;
  var msgname;
  for(var key in messages_zh){
    if(messages_zh[key]==showMessageText){
     msgname=key;
     break;
    }
  }
  if(isNull(msgname))
  for(var key in messages_en){
    if(messages_en[key]==showMessageText){
     msgname=key;
     break;
    }
  }
  
 setLanguage(lang||window.navigator.language||window.navigator.browserLanguage);
  
  //show or hidden message
  if(isNull(msgname)){
   hiddenMessage();
  }else{
   showMessage(messages[msgname]);
  }
  if(typeof(setCustomLabels)=='function'){
   setCustomLabels();
  }
 }
 
function setWating(isWait){
	var inputs=document.getElementsByTagName("INPUT");
  	for(var i in inputs){
  		var inputObj=inputs[i];
  		if(inputObj.type=='submit'){
  			if(isWait){
				inputObj.className='loading';
			}else{
				inputObj.className='submit';
			}
  		}
  	}
}

function showMessage(msg){
 $('showMessage').innerHTML=msg;
}

function hiddenMessage(){
 $('showMessage').innerHTML='';
}

function refreshValidateImage(){
 clearTimeout($('validateimage').refreshTimeOut);
 $('validateimage').refreshTimeOut=setTimeout(function(){$('validateimage').src='../validateImage?flag=123456&height=35&width=145&stringDegree=4&startup='+new Date().getTime();},200);
 $('validatecode').value='';
 //$('validatecode').focus();
}

function $(id){
 return document.getElementById(id);
}

String.prototype.Trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function()
{
    return this.replace(/(^\s*)/g, "");
}
String.prototype.Rtrim = function()
{
    return this.replace(/(\s*$)/g, "");
}

function isNull(str){
 return !str || str.Trim().length==0;
}

function getParameter(name){
 try{
  var url=window.location.href;
  var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");  
  var r = url.substr(url.indexOf("\?")+1).match(reg);  
  if (r!=null) return unescape(r[2]); return null; 
  }catch(e){
   return null;
  } 
}

function inputTextColorEvent(){
  var c1='url(./images/inputBg1.png)';
  var c2='url(./images/inputBg2.png)';
  
  function inputTextOnFocus(){this.style.backgroundImage=c2;removeMouseEvent();};
  function inputTextOnBlur(){this.style.backgroundImage=c1;addMouseEvent();};
  function inputTextOnMouseOver(){this.style.backgroundImage=c2;};
  function inputTextOnMouseDown(){this.style.backgroundImage=c2;};
  function inputTextOnMouseOut(){this.style.backgroundImage=c1;};
  function inputTextNullEvent(){};
  
  
  var inputs=document.getElementsByTagName("INPUT");
  var inputTexts=new Array();
  for(var i in inputs){
  	var inputObj=inputs[i];
  	if(inputObj.type=='text'||inputObj.type=='password'){
  		inputTexts[inputTexts.length]=inputObj;
  	}
  }
  
 for(var i=0;i<inputTexts.length;i++){
 	inputTexts[i].onfocus=inputTextOnFocus;
 	inputTexts[i].onblur=inputTextOnBlur;
 }
 
 function addMouseEvent(){
 	 for(var i=0;i<inputTexts.length;i++){
 		inputTexts[i].onmouseover=inputTextOnMouseOver;
 		inputTexts[i].onmousedown=inputTextOnMouseDown;
 		inputTexts[i].onmouseout=inputTextOnMouseOut;
  	}
 }
 function removeMouseEvent(){
  	 for(var i=0;i<inputTexts.length;i++){
 		inputTexts[i].onmouseover=inputTextNullEvent;
 		inputTexts[i].onmousedown=inputTextNullEvent;
 		inputTexts[i].onmouseout=inputTextNullEvent;
  	} 
 }
}
 
function loadImage(){
	var loadingGif=document.createElement("DIV");
	loadingGif.className='loading';
	loadingGif.style.display='none';
	loadingGif.style.height='0';
	loadingGif.style.width='0';
	document.body.appendChild(loadingGif);
}

function setPageInit(_init){
 function init(){inputTextColorEvent();loadImage();_init();}
 
	// 如果支持 W3C DOM2, 则使用 W3C 方法
if (document.addEventListener) {
 document.addEventListener("DOMContentLoaded", init, false);
 
// 如果是 IE 浏览器
} else if (/MSIE/i.test(navigator.userAgent)) {
 // 创建一个 script 标签, 该标签有 defer 属性, 当 document 加载完毕时才会被载入
 document.write('<script id="__ie_onload" defer="defer" src="javascript:void(0)"></script>');
 var script = document.getElementById("__ie_onload");
 // 如果文档确实装载完毕, 调用初始化方法
 script.onreadystatechange = function() {
  if (this.readyState == 'complete') {
   init();
  }
 }
 
// 如果是 Safari 浏览器
} else if (/WebKit/i.test(navigator.userAgent)) {
 // 创建定时器, 每 0.01 秒检验一次, 如果文档装载完毕则调用初始化方法
 var _timer = setInterval( function() {
  if (/loaded|complete/.test(document.readyState)) {
   clearInterval(_timer);
   init();
  }
 }, 10);
 
// 如果以上皆不是, 使用最坏的方法 (本例中, Opera 7 将会跑到这里来)
} else {
 window.onload = function(e) {
  init();
 }
}
}

var Ajax=function(){   
    this.http_request=false;   
    return{   
        init:function(){   
            this.createAjaxObj();   
        },   
        createAjaxObj:function(){   
                //创建XMLHttpRequest实例    
                if (window.XMLHttpRequest)    
                {   //Mozilla 浏览器    
                    this.http_request = new XMLHttpRequest();    
                    if (this.http_request.overrideMimeType)    
                    {//设置MiME类别    
                        this.http_request.overrideMimeType("text/xml");    
                    }   
                }else if (window.ActiveXObject)    
                { // IE浏览器    
                            try    
                            {    
                                this.http_request = new ActiveXObject("Msxml2.XMLHTTP");    
                            }   
                            catch (e)    
                            {    
                                try    
                                {    
                                    this.http_request = new ActiveXObject("Microsoft.XMLHTTP");    
                                }    
                                catch (e)    
                                {    
                                }    
                            }   
                        }    
                if (!this.http_request) { // 异常,创建对象实例失败    
                    //"不能创建XMLHttpRequest对象实例"    
                    window.alert("不能创建XMLHttpRequest对象实例..");    
                    return false;    
                }    
        },   
        sendRequest:function(method,url,content){   
           
              
            // 确定发送请求的方式和URL以及是否异步执行下段代码    
            if (method.toLowerCase() == "get")    
            {    
                if(navigator.userAgent.indexOf("MSIE")<=0){   
                    try{netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");}catch(e){}
                }   
                this.http_request.open(method, url, false);    
                this.http_request.send(null);    
            }    
            else    
            {    
                if (method.toLowerCase() == "post")    
                {   
                	var r=this;
                	function handleRequest(){
           		 	  if (r.http_request.readyState == 4)    
           		 	 {  
           		 	 	var obj;
                		if (r.http_request.status == 200){
                		 if(typeof(ajaxSuccess)=='function')
                    	 	obj=ajaxSuccess(r.http_request.responseText);   
                		}else if(typeof(ajaxFail)=='function')
                		 	obj=ajaxFail(); 
                		 	
                		 if(typeof(ajaxFinish)=='function')
                	     	ajaxFinish(obj); 
            	   	 }
                	}
                	if(typeof(ajaxStart)=='function')
                	 ajaxStart();
                    this.http_request.open(method, url, true);    
                    this.http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')  
                    this.http_request.send(content);
                    this.http_request.onreadystatechange=handleRequest;
                    return false; 
                }    
                else    
                {    
                    //http请求类别参数错误    
                    //window.alert("http请求类别参数错误..");    
                    return false;    
                }    
            }    
            //开始发起浏览请求    
            // 请求已完成    
            if (this.http_request.readyState == 4)    
            {    
                // 信息已经成功返回，开始处理信息    
                if (this.http_request.status == 200)    
                {    
                    //返回的是文本格式信息    
                    return this.http_request.responseText;    
                    //返回的XML格式文档就用alert(http_request.responseXML);    
                }    
                else    
                {    
                    //页面不正常    
                    //"您所请求的页面有异常"    
                    //alert("您所请求的页面有异常");
                }    
            }
            
            return false; 
        },   
        processResponse:function(){
                
        },   
        addParamsGET:function(sURL,key,value)   
        {     
            sURL+=(sURL.indexOf("?")==-1?"?":"&");   
            sURL+=(key+"="+value);   
            return sURL;   
        },   
        addParamsPOST:function(key,value){   
            var params="&";   
                params+=(key+"="+encodeURIComponent(value));
            return params;
        },   
        getTime:function(){   
            var DateTime=new Date();   
            return  DateTime.getFullYear()+"-"+(DateTime.getMonth()+1)+"-"+DateTime.getDate()+" "+DateTime.getHours()+":"+DateTime.getMinutes()+":"+DateTime.getSeconds();   
        }   
    };   
       
}  

/**
 * Class for accessing the cookie store.
 * 
 */
var CookieUtil = {
 
 setCookie : function( name, value, expires, path, domain, secure ) {
  var today = new Date();
  if ( expires )
   expires = expires * 1000 * 60;//3m
  var expires_date = new Date( today.getTime() + (expires) );
 
  document.cookie = name + "="  + escape( value ) +
       ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
       ( ( path ) ? ";path=" + path : "" ) + 
       ( ( domain ) ? ";domain=" + domain : "" ) +
       ( ( secure ) ? ";secure" : "" );
 },

 getCookie : function( cookieName ) {
  var allCookies = document.cookie.split( ';' );
  
  var tempCookie = '';
  var cookie_name = '';
  var cookie_value = '';
  
  var b_cookie_found = false;
  
  for ( i = 0; i < allCookies.length; i++ )
  {
   tempCookie = allCookies[i].split( '=' ); 
   // trim left/right whitespace while we're at it
   cookie_name = tempCookie[0].replace(/^\s+|\s+$/g, '');
  
   if ( cookie_name == cookieName )
   {
    b_cookie_found = true;
    if ( tempCookie.length > 1 )
     cookie_value = unescape( tempCookie[1].replace(/^\s+|\s+$/g, '') );
    return cookie_value;
    break;
   }
   tempCookie = null;
   cookie_name = '';
  }
  if ( !b_cookie_found )
  {
   return null;
  }
 },

 deleteCookie : function( name, path, domain ) {
  if ( this.getCookie( name ) ) 
   document.cookie = name + "=" +
       ( ( path ) ? ";path=" + path : "") +
       ( ( domain ) ? ";domain=" + domain : "" ) +
       ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
 }
};

function checkCookiesEnabled() {
	CookieUtil.setCookie( 'test', 'none', '', '/', '', '' );
	var enabled = CookieUtil.getCookie( 'test' );
	CookieUtil.deleteCookie( 'test', '/', '');
	return enabled;
}

function addBookmark() {
	var url = document.location.href;
	url=url.substring(0,url.indexOf('.html'))+".html?language="+$('language').value;
	try{
		window.external.AddFavorite(url,messages['title']);
	}catch(e){
		try{
			window.sidebar.addPanel(messages['title'], url, "");
		}catch(e){
			alert(messages['favoriteerror']);
		}
	}
}

function getOs()    
{
   if(navigator.userAgent.indexOf("MSIE")>0) {    
                return "MSIE";       //IE浏览器  
   }  
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){    
                return "Firefox";     //Firefox浏览器  
   }  
   if(isSafari=navigator.userAgent.indexOf("Safari")>0) {    
                return "Safari";      //Safan浏览器  
   }  
   if(isCamino=navigator.userAgent.indexOf("Camino")>0){    
                return "Camino";   //Camino浏览器  
   }  
   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){    
                return "Gecko";    //Gecko浏览器  
   }
   return null;
}

function getUrlWithName(name){
	var url=getParameter('url');
	if(!url||url==null||url.Trim().length==0){
		return "";
	}else{
		return name+"="+encodeURIComponent(url.Trim());
	}
}

var EMAIL_REG =/^([\.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,}){1,})$/;
var USERNAME_SPELL_PATTERN= /^[a-zA-Z0-9]+[a-zA-Z0-9_\\-]+[a-zA-Z0-9]$/;
var PWD_SPELL_PATTERN = /^[a-zA-Z0-9]*(([a-zA-Z][0-9])|([0-9][a-zA-Z]))[a-zA-Z0-9]*$/;