function changeid(id,url) {
	var curclass=document.getElementById(id);
	var subcurclass=document.getElementById("sub-"+id);
	if(curclass){
		curclass.style.background="url("+url+"/resources/site/images/cutover1.jpg)";
		curclass.style.repeat="x";
	}
	if(subcurclass){
		subcurclass.style.display ="block";
		document.getElementById("sublinktd").innerHTML = "<table>" + subcurclass.innerHTML + "</table>";
	}
} 

function change(id) {
	var curclass=document.getElementById(id);
	curclass.style.background='';
}

function changeindex(id,url) {
	var subcurclass=document.getElementById("sublinktd");
	var curclass=document.getElementById(id);
	curclass.style.background="url("+url+"/resources/site/images/cutover1.jpg)";
	curclass.style.repeat="x";
	//subcurclass.innerHTML='';
}
function jumpTo(pagenum) {
	document.listForm.pageNumber.value = pagenum;
	document.listForm.submit();
}

function loginindex() {
	if(document.login.u.value=='' || document.login.p.value==''){
		return;
	}
	document.login.submit();
}

function del() {
	document.insearch.search.value='';
}
function delsearch() {
	document.searchForm.search.value='';
}

function insear() {
	if(document.insearch.search.value =='' || document.insearch.search.value =='Please enter key'){
		return false;
	}
	document.insearch.submit();
}

function searchIt() {
	if(document.searchForm.search.value =='' || document.searchForm.search.value =='Please enter key'){
		return false;
	}
	document.searchForm.submit();
}

function addbookmark()
{
	var url = window.location.protocol + "//" + window.location.host;
	var name = "中国老龄科学研究中心网站";
    if (document.all)
       {
         window.external.addFavorite(url,name);
       }
      else if (window.sidebar)
      {
          window.sidebar.addPanel(name,url, "");
    }
}

function ltrim(s) {return s.replace( /^\s*/, "");}
function rtrim(s) {return s.replace( /\s*$/, "");}
function trim(s) {return rtrim(ltrim(s));} 
function chu(v)	{
	var m5=/^[a-zA-Z0-9]{6,13}$/;
	return m5.test(v);
}
function chn(v) {
	if (trim(v).length<=2 || trim(v).length>10)
	return false;
	else
	return true;
}
function chp(v) {
	if (trim(v).length<=5 || trim(v).length>20) 
	return false;
	else 
	return true;
}
function cn(value){
	document.getElementById("an1").innerHTML= 'The minimum length can be 3 Chinese characters or 10 English number'
	if(value ==''){
		document.getElementById("an1").innerHTML= '<font style="color:red">The minimum length can be 3 Chinese characters or 10 English number</font>'
		return;	
	}
	if(chn(value)){
		document.getElementById("an").innerHTML= '√ ';
	}else{
		document.getElementById("an").innerHTML= 'Format is incorrect ';
	}	
	return;
}
function cp(value){
	document.getElementById("ap1").innerHTML= 'Must be 6-20 characters'
	if(value ==''){
		document.getElementById("ap1").innerHTML= '<font style="color:red">Must be 6-20 characters</font>'
		return;	
	}
	if(chp(value)){
		document.getElementById("ap").innerHTML= '√ ';
	}else{
		document.getElementById("ap").innerHTML= 'Character length is incorrect ';
	}	
	return;
}
function cp2(v) {
	if (v=='') 	
		document.getElementById("ap2").innerHTML='Please re-enter your password ';
	else if(v!=document.getElementById('f_password').value) {
		document.getElementById("ap2").innerHTML='Enter the password for the two inconsistent';
	}else {
		document.getElementById("ap2").innerHTML='√ ';
	}   
}
function ajaxuser(value){
	document.getElementById("au1").innerHTML= 'Must be 6-12 characters long'
	if(value ==''){
		document.getElementById("au1").innerHTML= '<font style="color:red">Must be 6-12 characters long</font>'
		return;	
	}
	if(!chu(value)){
		document.getElementById("au").innerHTML= 'Format is incorrect'
		return;	
	}
	var url ='user-'+value+'.html';
	var my = new Ajax.Request(
		url,{
		method:'get',
		onComplete:ajaxresult
		});
}
function ajaxresult(response){ 
	document.getElementById("au").innerHTML= response.responseText;
}
function deluser(){
	document.getElementById("au").innerHTML= '&nbsp;';
}
function delname(){
	document.getElementById("an").innerHTML= '';
}
function delpassword(){
	document.getElementById("ap").innerHTML= '';
}
function delpassword2(){
	document.getElementById("ap2").innerHTML= '';
}

function registerMe() {
	if (validateRegisterInfo()) {
		document.regfrm.submit();
	}
}

function validateRegisterInfo() {
	var f_name = document.getElementById("f_name");
	var f_caption = document.getElementById("f_caption");
	var f_dept_name = document.getElementById("f_dept_name");
	var f_email = document.getElementById("f_email");
	var f_password = document.getElementById("f_password");
	var psw2 = document.getElementById("psw2");

	if (!chu(f_name.value)) {
		alert('Please input current login name');
		f_name.focus();
		return false;
	}
	if(!chn(f_caption.value)) {
		alert('Please input current user name');
		f_caption.focus();
		return false;
	}
	if(trim(f_dept_name.value).length<=1 || trim(f_dept_name.value).length>50) {
		alert('Please input current work unite');
		f_dept_name.focus();
		return false;
	}
	if(trim(f_email.value).length<=1 || trim(f_email.value).length>120) {
		alert('Please input current email');
		f_email.focus();
		return false;
	}
	if(!chp(f_password.value)) {
		alert('Please input current password');
		f_password.focus();
		return false;
	}
	if(psw2.value!=f_password.value) {
		alert('Enter the password for the two inconsistent');
		psw2.focus();
		return false;
	}
	
	var sign = document.getElementsByName("sign");
	var pass;
	for ( var i = 0; i < sign.length; i++) {
		if (sign[i].checked)
			pass = i;
	}
	if (pass != 0) {
		alert('Different registration agreement, can not complete a user registration');
		return false;
	}
	return true;
}