
var isIE = false;

var req;

var tmpdata = "";

too_big='上传的附件过大，请重新上选择...';
without_exp='上传的附件类型不支持！请重新选择...';
upload_errors='上传附件失败,请稍候再试...';

function Trim(str) {
  return str.replace(/(^\s*)|(\s*$)/g,"");
}

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---帐号(必需以字母开头)

是否必要:
	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]);
			val_obj=val;
			if (val) {
				nm=val.title;
				if(val.value.length >0){
					val.value=Trim(val.value);
				}
				if ((val=val.value)!="") {
					if (test.indexOf('MAIL')!=-1) {
						p=val.indexOf('@');
						point=val.indexOf('.');
						if (p<1 || p==(val.length-1) || point<1 || point==(val.length-1)) 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('MAX')!=-1){
						p=test.indexOf(':');
						max=test.substring(p+1,p);
						if(val.length>max)
							errors+=nm+'必需在'+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)
							errors+= nm+'必需在'+max+'个字符之内.\n';
					} else if (test.indexOf('USERID') !=-1) {
						if(val.length>13){
							errors+= nm+'的长度不能长于12个字符!\n';
						}else if(val.length<4){
							errors+= nm+'的长度不能小于4个字符!\n';
						}
						exp=/\D\S{3,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(test.indexOf('CHECKBOX') !=-1){
						i_count=0;
						for(i=0;i<val_obj.length;i++){
							if(val_obj[i].checked){
								i_count++;
							}
							nm=val_obj[i].title;
						}
						if(i_count<=0)
							errors+=nm+'必需至少选择一个.\n';
					} else if(test.indexOf('file') !=-1){
//						alert(val);
						list = test.substring(test.indexOf(':'),test.length);
						ext = val.substring(val.length,val.length-3);
						if(list.indexOf(ext) !=-1){
							//nothing
						}else{
							errors+=nm+'附件的文件类型不支持,请重新选择!\n';
						}
					} else if(test.indexOf('RADIO') !=-1){
						i_count=0;
						for(i=0;i<val_obj.length;i++){
							if(val_obj[i].checked){
								i_count++;
							}
							nm=val_obj[i].title;
						}
						if(i_count<=0)
							errors+=nm+'必需至少选择一个.\n';
					} else if(test.indexOf('SELECT') !=-1){
						if(val<0 || val=="") 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 ckForm_new() {
	var i,p,q,nm,test,num,min,max,tmp='',errors='',args=ckForm_new.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]);
			val_obj=val;
			if (val) {
				nm=val.title;
				tips=eval("document.all."+val.name+"_tips");
				if ((val=val.value)!="") {
					if (test.indexOf('MAIL')!=-1) {
						p=val.indexOf('@');
						point=val.indexOf('.');
						if (p<1 || p==(val.length-1) || point<1 || point==(val.length-1)){
							tmp = nm+'必须是一个正确的EMAIL地址!\n';
						}
					} else if (test.indexOf('NUM') != -1) {
						num = parseFloat(val);
				        if (isNaN(val)){
							tmp = 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){
								tmp = nm+'必须是一个介于'+min+'和'+max+'的数字!\n';
							}
						}
					}else if(test.indexOf('MAX')!=-1){
						p=test.indexOf(':');
						max=test.substring(p+1,p);
						if(val.length>max){
							tmp =nm+'必需在'+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){
							tmp = nm+'必需在'+max+'个字符之内.\n';
						}
					} else if (test.indexOf('USERID') !=-1) {
						if(val.length>13){
							tmp = nm+'的长度不能长于12个字符!\n';
						}else if(val.length<2){
						tmp = nm+'的长度不能小于2个字符!\n';
						}
					//	exp=/\S{3,12}\d{0}/;
					//	aa=exp.test(val);
					//	if(!aa){ tmp = nm+'的格式不正确请重新检查！\n';}
					} else if (test.indexOf('PASSWD') !=-1) {
						if(val.length>13){
							tmp = nm+'的长度不能长于12个字符!\n';
						}else if(val.length<6){
							tmp = nm+'的长度不能小于6个字符!\n';
						}else if(val!=document.forms[0].comfpasswd.value){
							tmp =nm+'两次输入的密码不相同，请重新输入!\n';
						}
					} else if(test.indexOf('CHECKBOX') !=-1){
						i_count=0;
						for(i=0;i<val_obj.length;i++){
							if(val_obj[i].checked){
								i_count++;
							}
							nm=val_obj[i].title;
						}
						if(i_count<=0)
							tmp =nm+'必需至少选择一个.\n';
					} else if(test.indexOf('RADIO') !=-1){
						i_count=0;
						for(i=0;i<val_obj.length;i++){
							if(val_obj[i].checked){
								i_count++;
							}
							nm=val_obj[i].title;
						}
						if(i_count<=0)
							tmp =nm+'必需至少选择一个.\n';
					} else if(test.indexOf('SELECT') !=-1){
						if(val<0 || val=="") tmp = nm+'必需至少选择一个.\n';
					}
				}else if (test2.charAt(0) == 'R'){
					tmp = '请输入'+nm+'!\n';
				}
			}
			if(tips!=undefined)	tips.innerHTML="<font color=red>"+tmp+"</font>";
			errors+=tmp;
			tmp="";
		 }
		 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 op_array(arr,op,src,target){
	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('/bbs/viewprofile.jsp?bas_no='+bas_no+"&"+new Date(),'ViewPorFile');
}

	
     
 function add_friend(bas_no){
           if (confirm('真的要添加 '+bas_no+' 这个好友吗？')) {
			location.href='/bbs/add_friend.jsp?bas_no='+bas_no+'&backurl='+encodeURIComponent(location.href);
			}	
		}	                        

function send_pm(bas_no){
	window.open('/bbs/pmsg.jsp?op=new&bas_no='+bas_no+"&"+new Date(),'Send_PM');
}

/*
1级
初级游民
10
2级
职业游侠
50
3级
资深猎人
100
4级
天马骑士
200
5级
神殿骑士
300
6级
圣骑士
800
7级
精灵
1000
8级
精灵王
1500
9级
法师
2000
10级
大法师
3000
11级
风云使者
4000
12级
光明使者
5000
13级
天使
8000
14级
大天使
12000
15级
精灵使
20000
16级
法王
30000
17级
光明大帝
40000
18级
天神
60000

*/
function get_level(credit){
	if(credit < 10)return '初级游民';
	if(credit >= 10 && credit < 50 )return '职业侠客';
	if(credit >= 50 && credit < 100 )return '资深猎人';
	if(credit >= 100 && credit < 200 )return '天马骑士';
	if(credit >= 200 && credit < 300 )return '神殿骑士';
	if(credit >= 300 && credit < 800 )return '圣骑士';
	if(credit >= 800 && credit < 1000 )return '精灵';
	if(credit >= 1000 && credit < 1500 )return '精灵王';
	if(credit >= 1500 && credit < 2000 )return '法师';
	if(credit >= 2000 && credit < 3000 )return '大法师';
	if(credit >= 3000 && credit < 4000 )return '风云使者';
	if(credit >= 4000 && credit < 5000 )return '光明使者';
	if(credit >= 5000 && credit < 8000 )return '天使';
	if(credit >= 8000 && credit < 12000 )return '大天使';
	if(credit >= 12000 && credit < 20000 )return '精灵使';
	if(credit >= 20000 && credit < 30000 )return '法王';
	if(credit >= 30000 && credit < 40000 )return '光明大帝';
	if(credit >= 40000 && credit < 60000 )return '天神';
	if(credit >= 60000 && credit < 80000 )return '天王';
	if(credit >= 80000 && credit < 99999 )return '法老';
	if(credit >= 99999 )return '不是人';
}

function get_star(credit){
	star=1;
	if(credit < 10)star=1;
	if(credit >= 10 && credit < 50 )star=2;
	if(credit >= 50 && credit < 100 )star=3;
	if(credit >= 100 && credit < 200 )star=4;
	if(credit >= 200 && credit < 300 )star=5;
	if(credit >= 300 && credit < 800 )star=6;
	if(credit >= 800 && credit < 1000 )star=7;
	if(credit >= 1000 && credit < 1500 )star=8;
	if(credit >= 1500 && credit < 2000 )star=9;
	if(credit >= 2000 && credit < 3000 )star=10;
	if(credit >= 3000 && credit < 4000 )star=11;
	if(credit >= 4000 && credit < 5000 )star=12;
	if(credit >= 5000 && credit < 8000 )star=13;
	if(credit >= 8000 && credit < 12000 )star=14;
	if(credit >= 12000 && credit < 20000 )star=15;
	if(credit >= 20000 && credit < 30000 )star=16;
	if(credit >= 30000 && credit < 40000 )star=17;
	if(credit >= 40000 && credit < 60000 )star=18;
	if(credit >= 60000 && credit < 80000 )star=19;
	if(credit >= 80000 && credit < 99999 )star=20;
	return '<img src="images/star/level'+star+'.gif" border="0">';
}


function get_status(bbs_status){
	if(bbs_status == -2) return '特邀嘉宾';
	if(bbs_status == -1) return '<font color=blue><strong>特约写手</strong></font>';
	if(bbs_status == 0) return '普通会员';
	if(bbs_status == 1) return '<span class="huifu">论坛版主</span>';
	if(bbs_status == 2) return '论坛管理员';
	if(bbs_status == 3) return '普通会员';
}


//根據會員級別和會員類型來設置上傳附件的大少。
function get_upload_file_size(/*credit , */bbs_status){
	filesize=0;
	if(bbs_status < 1){
		filesize=1024*1024;
/*		if(credit < 10)filesize=0;
		if(credit >= 10 && credit < 50 )filesize=1024*100;
		if(credit >= 50 && credit < 100 )filesize=1024*200;
		if(credit >= 100 && credit < 200 )filesize=1024*300;
		if(credit >= 200 && credit < 300 )filesize=1024*400;
		if(credit >= 300 && credit < 800 )filesize=1024*500;
		if(credit >= 800 && credit < 1000 )filesize=1024*600;
		if(credit >= 1000 && credit < 1500 )filesize=1024*700;
		if(credit >= 1500 && credit < 2000 )filesize=1024*800;
		if(credit >= 2000 && credit < 3000 )filesize=1024*900;
		if(credit >= 3000 && credit < 4000 )filesize=1024*1000;
		if(credit >= 4000 && credit < 5000 )filesize=1024*1100;
		if(credit >= 5000 && credit < 8000 )filesize=1024*1200;
		if(credit >= 8000 && credit < 12000 )filesize=1024*1300;
		if(credit >= 12000 && credit < 20000 )filesize=1024*1400;
		if(credit >= 20000 && credit < 30000 )filesize=1024*1500;
		if(credit >= 30000 && credit < 40000 )filesize=1024*1600;
		if(credit >= 40000 && credit < 60000 )filesize=1024*1700;
		if(credit >= 60000 && credit < 80000 )filesize=1024*1800;
		if(credit >= 80000 && credit < 99999 )filesize=1024*1900;
*/	}else{
		filesize=1024*2048;
	}
	return filesize;
}

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 && fid!='-1')
		location.href="threads.jsp?fid="+fid;
}
function ask(msg) {
	if( msg=='' ) {
		msg='真的要这样做吗？';
	}
	if (confirm(msg)) {
		return true;
	} else {
		return false;
	}
}

function getInt(value,pos){
	base = 1;
	for(i=0;i<pos;i++)
		base=base*10;
	return Math.round(value * base) / base;
}

function get_att_ico(ext){
	txt="";
	switch(ext){
		case "gif":
			txt="<img src='images/image.gif'>";
			break;
		case "jpg":
			txt="<img src='images/image.gif'>";
			break;
		case "png":
			txt="<img src='images/image.gif'>";
			break;
		case "rar":
			txt="<img src='images/rar.gif'>";
			break;
		case "zip":
			txt="<img src='images/zip.gif'>";
			break;
		case "txt":
			txt="<img src='images/common.gif'>";
			break;
	}
return txt
}
function bbimg(o){
	var zoom=parseInt(o.style.zoom, 10)||100;
	zoom+=event.wheelDelta/12;
	if (zoom<=30)return false;
	if (zoom>200)return false;
	o.style.zoom=zoom+'%';
	return false;
}


function loadXMLDoc(url) {
//	show_static(0);
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processReqChange() {
    if (req.readyState == 4) {
        if (req.status == 200) {
            handleResult();
//			show_static(1);
        } else {
            alert("There was a problem retrieving the XML data:\n" +req.statusText);
        }
    }
}

function show_static(now){
		var details = document.getElementById("details");
	if(now>0){
		details.innerHTML="";
	}else{
		details.innerHTML="<font color=red>Loading...</font>";
	}
}

function add_url_and_split_str(str){
	if(str.length>0){
		tmpstrs=str.split(',');
		str=" ";
		for(i=0;i<tmpstrs.length;i++){
			loadXMLDoc("get_moderators.jsp?moderators="+tmpstrs[i]);
			
			if(i>0){
				str=str+'<a href="javascript:view_user(\''+tmpstrs[i]+'\')" class="fanye1">'+tmpdata+'</a>  ';
			}else{
				str=str+'<a href="javascript:view_user(\''+tmpstrs[i]+'\')" class="fanye1"><b>'+tmpdata+'</b></a>';
			}
			if(i!=tmpstrs.length-1) str=str+' ';
		}
		return str;
	}
	return '暂无版主';
}

function handleResult() {
//	var select = document.getElementById("area_id");
    var items = req.responseXML.getElementsByTagName("city");
//	clearSelect(select);
	if(items.length>0){
//		select.style.visibility="visible";
		for(j=0;j<items.length;j++){
			tmpdata=items[j].firstChild.data;
//			addSelect(select,i,tmpdata[1],tmpdata[0]);
		}
	}
}

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(); } 
}