function ovrTR(tr,color)
{
	tr.bgColor = color; tr.style.cursor="hand";
}
function outTR(tr,color)
{
	tr.bgColor = color; tr.style.cursor="default";
}

function selectall(formid){
	//多选框checkbox,全部框selectall,
	if(document.forms[i].checkbox!=null){
		var length = document.forms[i].checkbox.length;
		document.forms[i].selectall.checked = document.forms[i].selectall.checked|0;
		if (length == 0 ){
			  return;
		}

		if (length ==undefined) document.forms[i].checkbox.checked =document.forms[i].selectall.checked;

		if (length ==1 ){
		   document.forms[i].checkbox.checked=document.forms[i].selectall.checked;
		}
		if (length>1){
		  for (var i = 0; i < length; i++)
		   {
			document.forms[i].checkbox[i].checked=document.forms[i].selectall.checked;
		   }
		}
	}
}

function unselectall(formid) {
    if(document.forms[formid].selectall.checked){
		document.forms[formid].selectall.checked = document.forms[formid].selectall.checked&0;
    }
}

function readCookie(name) {
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0) {
	offset = document.cookie.indexOf(search);
	if (offset != -1) {
	  offset += search.length;
	  end = document.cookie.indexOf(";", offset);
	  if (end == -1) end = document.cookie.length;
	  cookieValue = unescape(document.cookie.substring(offset, end))
	}
  }
  return cookieValue;
}

function writeCookie(name, value, hours) {
  var expire = "";
  if(hours != null){
	expire = new Date((new Date()).getTime() + hours * 3600000);
	expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

function getNumFromString(str){
	var strs="";
	for(i=0;i<str.length;i++){
		if(str.charAt(i)>=0 && str.charAt(i)<=9)
			strs+=str.charAt(i);
		else
		return strs;
	}
	return strs;
}


/*
表单检查函数

在form 的onsubmit事件中加入return ckForm(....)

格式:
	ckForm('输入框名','类型','是否必要')

输入框名:在Form中的输入框名

类型:
	MAIL---邮件
	NUM ---数字
	NUMB1:100----介于1到100的数字
	USERID---帐号(必需以字母开头)
	PASSWD---密码

是否必要:
	R---必要
	空--不一定

注：在每一个输入框必要加上一个"title"的属性，值为该输入框的中文解释！
	例:<input type="text" name="user_name" title="用户名" value="">

*/

function findObj(n, d) {
  var p,i,x;
  if(!d) d=document;
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document;
	n=n.substring(0,p);
	}
  if(!(x=d[n])&&d.all) x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function ckForm() {
	var i,p,q,nm,test,num,min,max,errors='',args=ckForm.arguments;
	if(document.flag==undefined){
		for (i=0; i<(args.length-2); i+=3) {
			test=args[i+1];
			test2=args[i+2]
			val=findObj(args[i]);
			if (val) {
				nm=val.title;
				if ((val=Trim(val.value))!="") {
					if (test.indexOf('MAIL')!=-1) {
						var patn = /^[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]*)*@[a-zA-Z0-9\-]+([\.][a-zA-Z0-9\-]+)+$/;
						if(patn.test(val)){
						}else{
							errors+= nm+'必须是一个正确的EMAIL地址!\n';
						}
					} else if (test.indexOf('NUM') != -1) {
						num = parseFloat(val);
				        if (isNaN(val)) errors+= nm+'必须是一个正确数字!\n';
				        if (test.indexOf('NUMB') != -1) {
							p=test.indexOf(':');
							min=test.substring(8,p); max=test.substring(p+1);
							if (num<min || max<num) errors+= nm+'必须是一个介于'+min+'和'+max+'的数字!\n';
						}
					}else if(test.indexOf('MAXLENGTH') !=-1){
						p=test.indexOf(':');
						p2=test.indexOf(',');
						min=test.substring(p+1,p2);
						max=test.substring(p2+1);
						if(val.length>max || val.length < min)
							errors+= nm+'长度必需在'+min+'和'+max+'个字符之间.';
					} else if (test.indexOf('USERID') !=-1) {
						if(val.length>13){
							errors+= nm+'的长度不能长于12个字符!\n';
						}else if(val.length<6){
							errors+= nm+'的长度不能小于6个字符!\n';
						}
						exp=/\D\S{5,12}\d{0}/;
						aa=exp.test(val);
						if(!aa){ errors+= nm+'的格式不正确请重新检查！\n';}
					} else if (test.indexOf('PASSWD') !=-1) {
						if(val.length>13){
							errors+= nm+'的长度不能长于12个字符!\n';
						}else if(val.length<6){
							errors+= nm+'的长度不能小于6个字符!\n';
						}else if(val!=document.forms[0].comfpasswd.value){
							errors+=nm+'两次输入的密码不相同，请重新输入!\n';
						}
					}
				}else if (test2.charAt(0) == 'R') errors += '请输入'+nm+'!\n';
			}
		 }
		 if (errors){
			 alert('出错:\n'+errors);
			 return false;
		 }else {
	         document.flag="1";
			 return true;
		 }
	}else{
		alert("错误！正在提交，请稍候...");
		return false;
	}
}

function cut_str(str,leng){
	return str.substring(0,leng)+'...';
}

function Trim(str) {
  return str.replace(/(^\s*)|(\s*$)/g,"");
}

function op_array(arr,op,src,target){
	if(arr==undefined)
		return false;
	if(op=='add'){
		arr.push(src);
	}else if(op=='del'){
		for(i=0;i<arr.length;i++){
			if(arr[i]==src){
				arr.splice(i,1);
			}
		}
	}else if(op=='find'){
		for(z=0;z<arr.length;z++){
			if(arr[z]==src){
				return true;
			}
		}
		return false;
	}else if(op=='replace'){
		for(z=0;z<arr.length;z++){
			if(arr[z]==src){
				arr[z]=target;
			}
		}
	}else{
		return arr;
	}
	return arr;
}

function view_user(bas_no){
	window.open('viewprofile.jsp?bas_no='+bas_no,'ViewPorFile');
}

function send_pm(bas_no){
	window.open('pmsg.jsp?op=new&bas_no='+bas_no,'Send_PM');
}

function add_url_and_split_str(str){
	if(str!=undefined){
		tmpstrs=str.split(',');
		str="";
		for(i=0;i<tmpstrs.length;i++){
			str=str+'<a href="javascript:view_user(\''+tmpstrs[i]+'\')" class="nav">'+tmpstrs[i]+'</a>';
			if(i!=tmpstrs.length-1) str=str+',';
		}
		return str;
	}
	return;
}

function get_level(credit){
	if(credit < 400)return '新手上路';
	if(credit >= 400 && credit < 1000 )return '一星级会员';
	if(credit >= 1000 && credit < 2200 )return '二星级会员';
	if(credit >= 2200 && credit < 4000 )return '三星级会员';
	if(credit >= 4000 && credit < 6400 )return '四星级会员';
	if(credit >= 10000 )return '五星级会员';
}

function get_short_str(str,length){
	if(str!=null){
		if(str.length > length){
			return str.substring(0,length)+'...';	
		}else{
			return str;
		}
	}
	return ;
}

function enterSubmit(){
	if(event.keyCode==13){
		submitForm();
	}
}

var submitCheck="false";
function submitForm(){
	if(submitCheck=="true"){
		alert("请不要等待，正在登陆中...");
		return;
	}else{
		if(document.memberLoginActionForm.username.value==null||document.memberLoginActionForm.username.value==""){
			alert("请输入帐号.");
			document.memberLoginActionForm.username.focus();
			return;
		}
		if(document.memberLoginActionForm.password.value==null||document.memberLoginActionForm.password.value==""){
			alert("请输入密码.");
			document.memberLoginActionForm.password.focus();
			return;
		}
		submitCheck="true";
		document.memberLoginActionForm.submit();
		return;
	}
}

function jump_to(fid){
	if(fid!=undefined)
		location.href="threads.jsp?fid="+fid;
}

function centerPopup(mypage, myname, w, h, scroll) { 
	var winl = (screen.width - w) / 2; 
	var wint = (screen.height - h) / 2 -20; 
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no,toolbar=no' 
	win = window.open(mypage, myname, winprops) 
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); } 
}

function ask(msg) {
	if( msg=='' ) {
		msg='真的要这样做吗？';
	}
	if (confirm(msg)) {
		return true;
	} else {
		return false;
	}
}

