// JavaScript Document

var x,y,mX,mY,aH,aW,tH,tW;
var Act,ActId;
var bz=0;
var ShowImages=null,ShowImgIndex=0,Multi=5,EddySize=0;
var zoomTool=-1;

if(window.System){
	var JImageBrowser=System.createObject();
	JImageBrowser.prototype={
		initialize:function(width,height,title,parent){
			this.extend(new JFrame(width,height,title,parent));	
			this.className="JImageBrowser";
		},
		_onMax:function(){
			var eventResult=this.onMax(this,event);
			if(!isUndefined(eventResult)){
				if(!eventResult){
					return false;
				}
			}
		
			if(this._maxButton.getAttribute("action")=="max"){
				this._RestoreBounds=Element.getBounds(this._window);
				var parentBounds=Element.getBounds(this.parent);
				this.setLocation(parentBounds.x,parentBounds.y);
				
				this._window.style.width=document.documentElement.offsetWidth+"px";
				this._window.style.height=document.documentElement.offsetHeight+"px";
				
				this._maxButton.src=CONST_IMAGES_RESOURCE_PATH+"/restoreButton.gif";
				this._maxButton.setAttribute("action","restore");
				this._maxButton.setAttribute("title","还原");
			}else{
				this.setLocation(this._RestoreBounds.x,this._RestoreBounds.y);
				this._window.style.width=this._RestoreBounds.width+"px";
				this._window.style.height=this._RestoreBounds.height+"px";
				this._maxButton.src=CONST_IMAGES_RESOURCE_PATH+"/maxButton.gif";
				this._maxButton.setAttribute("action","max");
				this._maxButton.setAttribute("title","最大化");
			}
			this._contentPanelResize();
			this._window.focus();
		},
		_contentPanelResize:function(){
			
			var height=(this._window.clientHeight-(this._statusPanel.clientHeight+this._titleContentPanel.clientHeight)-2);
			if(height<1) height=1;
			this._JFrame_contentPanel.style.height=height+"px";
			var width=(this._titleContentPanel.clientWidth-(this._appIcoPanel.clientWidth+this._buttonPanel.clientWidth)-20);
			if(width>10){
				this._titlePanel.style.width=width+"px";
				var objScroll=$("ScrollPanel");
			}
			
			width=this._window.offsetWidth-20;
			if(width>10)
				objScroll.style.width=width;
			height=(this._window.offsetHeight-this._titleContentPanel.offsetHeight-this._statusPanel.offsetHeight-$("ToolBar").offsetHeight-20);
			if(height>10)
				objScroll.style.height=height;
	
		},
		_onResize:function(objSource,objEvent){
			var eventResult=this.onResize(this,objSource,objEvent);
			if(!isUndefined(eventResult)){
				if(!eventResult){
					return false;
				}
			}
			
			var objResizeElement=objSource.resizeElement;
			var width=objSource.resizeElementBounds.width+(parseInt(event.x,10)-objSource.beginEventPoint.x);
			var height=objSource.resizeElementBounds.height+(parseInt(event.y,10)-objSource.beginEventPoint.y);
			if(width>CONST_JFRAME_MIN_WIDTH&&height>CONST_JFRAME_MIN_HEIGHT){
					objResizeElement.style.width=width+"px";
					objResizeElement.style.height=height+"px";
					this._contentPanelResize();
					this._RestoreBounds=Element.getBounds(this._window);
			}
		}
	}
}


var objImageBrowser=null;

document.onmousedown=function(){
	Act=event.srcElement;
	ActId=Act.id.toLowerCase();
	if(ActId.indexOf("moveimg")!=-1){
		if(objImageBrowser==null){
			objImageBrowser=new JImageBrowser(750,510,"图片浏览器",document.documentEelement);
			objImageBrowser.onClose=function(){
				var objElements=document.getElementsByTagName("OBJECT");
				for(var i=0;i<objElements.length;i++){
					if(objElements[i].style.display!="block"){
						objElements[i].style.display="block";
					}
				}
				
				objElements=document.getElementsByTagName("SELECT");
				for(var i=0;i<objElements.length;i++){
					if(objElements[i].style.display!="block"){
						objElements[i].style.display="block";
					}
				}
			}
			objImageBrowser.onShow=function(){
				var objElements=document.getElementsByTagName("OBJECT");
				for(var i=0;i<objElements.length;i++){
					if(objElements[i].style.display!="none"){
						objElements[i].style.display="none";
					}
				}
				
				objElements=document.getElementsByTagName("SELECT");
				for(var i=0;i<objElements.length;i++){
					if(objElements[i].style.display!="none"){
						objElements[i].style.display="none";
					}
				}
			}
			
			objImageBrowser.getContentPanel().innerHTML=$("hidPanel").innerHTML;
			document.body.removeChild($("hidPanel"));
			objImageBrowser.showDialog();
/*			var objJWinBlm=new JWinBlindManager();
			objJWinBlm.addWinBlind(objImageBrowser._window,0,0,0.7,"left",true,false);
			objJWinBlm.startMove(100)*/
		}else{
			objImageBrowser.showDialog();
		}
		
		if(ShowImages==null) LoadImgObjs();
		ShowImgIndex=getImgIndex(Act);
		document.getElementById("ImgTag").src=Act.src;
		resetImgSize();

/*		ImgWind.style.visibility="visible";
		ImgWind.style.left=(window.screen.width/2)-(parseInt(ImgWind.offsetWidth)/2);
		ImgWind.style.top=ImgTop;*/
		objImageBrowser.setSize(750,510);
		objImageBrowser._contentPanelResize();
		objImageBrowser.setLocation((window.screen.width/2)-(parseInt(objImageBrowser._window.offsetWidth)/2),document.documentElement.scrollTop+20);
		
		with (document.getElementById("EddyContainer").filters.item(0)) {
			M11=1;M12=0;M21=0;M22=1;
		}
		setEddyContainerWidth();
		document.getElementById("ImgTag").onmouseover=function(){
			if(zoomTool>-1)
			{
				if(zoomTool==0){
						document.getElementById("ImgTag").onclick=function(){
							zoomImage(false);
						}
				}else{
						document.getElementById("ImgTag").onclick=function(){
							zoomImage(true);
						}
				}
			}
			else
			{
				document.getElementById("ImgTag").onclick=null;
			}
		}
	}
}


function setImageByIndex(IsNext){
		if(ShowImages==null) return ;
		if(IsNext){
			if((ShowImgIndex+1)<ShowImages.length){
				document.getElementById("ImgTag").src=ShowImages[ShowImgIndex+1].src;
				resetImgSize();
				ShowImgIndex++;
				with (document.getElementById("EddyContainer").filters.item(0)) {
					M11=1;M12=0;M21=0;M22=1;
				}
			}
		}else{
			if((ShowImgIndex-1)>-1){
				document.getElementById("ImgTag").src=ShowImages[ShowImgIndex-1].src;
				resetImgSize();
				ShowImgIndex--;
				with (document.getElementById("EddyContainer").filters.item(0)) {
					M11=1;M12=0;M21=0;M22=1;
				}
			}
		}
		setEddyContainerWidth();
}

function setEddyContainerWidth(){
	//$("EddyContainer").style.width=	$("EddyContainer").childNodes[0].offsetWidth;
}

function ImgEddy(isRight){
	if(isRight)
	{
		if(EddySize==270)
			EddySize=0;
		else
			EddySize+=90;
	}
	else
	{
		if(EddySize==90)
			EddySize=0;
		else
			EddySize-=90;
	}
	
	var deg=Math.PI*2/360;
	var rad=EddySize*deg;
	var ma = Math.cos(rad);
	var mb = Math.sin(rad);
	with (document.getElementById("EddyContainer").filters.item(0)) {
		M11=ma;M12=-mb;M21=mb;M22=ma;
	}
	setEddyContainerWidth();
}

function resetImgSize(){
	document.getElementById("ImgTag").style.zoom=1;
	Multi=5;
	zoomTool=-1;
	setEddyContainerWidth();
}

function zoomImage(IsMax){
	var ImgObj=document.getElementById("ImgTag");
	if(ImgObj.style.zoom+""=="") ImgObj.style.zoom=0;

	if(IsMax){
		Multi++;
		ImgObj.style.zoom=(Multi/5);
	}
	else{
		if((Multi-1)/5>0)
		{
			Multi--;
			ImgObj.style.zoom=(Multi/5);
		}
	}
	setEddyContainerWidth();
}


function LoadImgObjs(){
	var Temp=document.all("moveimg");
	if(typeof(Temp.length)=="undefined")
		ShowImages=new Array(Temp);
	else
		ShowImages=Temp;
}

function getImgIndex(ImgObj){
	if(ShowImages!=null)
	{
		for(var i=0;i<ShowImages.length;i++)
		{
			if(ShowImages[i]==ImgObj)
				return i;
		}
	}
	else
	{
		return -1;	
	}
}

document.onmousemove=function(){
	if(bz==1){
		mX=parseInt(event.offsetX,10);
		mY=parseInt(event.offsetY,10);
		tW=aW+mX-x;
		tH=aH+mY-y;
		if (tW>20){Act.width=tW;}
		if (tH>20){Act.height=tH;}
	}
}
document.onmouseup=function(){
	bz=0;
}

document.onclick=function(){
if (popbox) popbox.style.display="none";
}
rnd.today=new Date(); 
rnd.seed=rnd.today.getTime(); 
function rnd() { rnd.seed = (rnd.seed*9301+49297) % 233280;return rnd.seed/(233280.0);}
function rand(number) {return Math.ceil(rnd()*number);}


//获得鼠标指针的X坐标（相对于页面）
function getPointerX(){var x = getLeft(event.srcElement)+event.offsetX;return x;}
//获得鼠标指针的Y坐标（相对于页面）
function getPointerY(){var y = getTop(event.srcElement)+event.offsetY;return y;}
//获得对象的Y坐标（相对于页面）
function getTop(e){var t=e.offsetTop;while(e=e.offsetParent){t+=e.offsetTop;}return t;}
//获得对象的X坐标（相对于页面）
function getLeft(e){var l=e.offsetLeft;while(e=e.offsetParent){l+=e.offsetLeft;}return l;}
//获得对象的高度
function getHeight(e){var t=e.offsetHeight;return t;}
//获得对象的宽度
function getWidth(e){var t=e.offsetWidth;return t;}

//展开—隐藏论坛分类
function listMode(inId,inImg){
	var obj=eval("window.list_"+inId);
	if(inImg.src.indexOf("listhidden")!=-1){
		inImg.title="展开此分类";
		inImg.src="images/listshow.gif";
		obj.style.display="none";
	}else{
		inImg.title="收折此分类";
		inImg.src="images/listhidden.gif";
		obj.style.display="";
	}
}
//显示菜单，当前菜单ID，菜单类型
function showbbspop(inId,inType){
	var popCode;
	var popX,popY;
	if (inId==0&&inType==""){	return;}
	else{
		if (inType!="menupop"){
			popCode=getPop(inType);
		}else{
			popCode=getPop(inId);
		}
		popX=getLeft(event.srcElement)+10;
		popY=getTop(event.srcElement)+20;
		popbox.innerHTML='<layer bgcolor="#E6E6E6" width="165" onmouseover="clearhidpop()" onmouseout="delayhidpop()">'+popCode+'</layer>';
		popbox.style.left=popX;
		popbox.style.top=popY;
		popbox.style.display="";
	}
}
//隐藏菜单
function hidpop(){
	if (window.popbox)
		popbox.style.display="none";
}

function delayhidpop(){
		delayhide=setTimeout("hidpop()",500)
}
function clearhidpop(){if (window.delayhide){	clearTimeout(delayhide);}}
//菜单读取
function getPop(inVal){
	var readerr="<DIV class=\"popitem\"><a>读取错误</a> </DIV>";
	var objPop=eval("window.pop_"+inVal);
	if(objPop){return objPop.innerHTML;}
	else{return readerr;}
}
//检查用户登陆信息
function checkLogin(){
	var reg=/\d{4}/ig;
	if (formLogin.userName.value==""){
		alert("登陆名称不能为空!");
		formLogin.userName.focus();
		return false;
		}
	if (formLogin.password.value==""){
		alert("用户密码不能为空!");
		formLogin.password.focus();
		return false;
	}
	if (formLogin.chknum.value=="" || !reg.test(formLogin.chknum.value)){
		alert("请输入正确的验证码!");
		formLogin.chknum.focus();
		return false;
	}
}

//读取在线用户名单
function showUserLists(){
	window.userListBox.style.display='';
	window.hidframe.location='readonlineuser.asp';
}
//上传文件
function addannex(){
	var num=postform.upnum.value;
	if (num==""){num=1}
	num=parseInt(num,10);
	if (num<maxupfile){
		var last=eval("postform.annex"+num);
		if (last.value==""){alert("一次只能上传一个文件!");}
		else{
		num++;
		window.upfilebox.innerHTML+="<div><input name=\"annex\" type=\"text\" class=\"DIVinpu\" id=\"annex"+num+"\" size=\"35\"/></div>\n";
		fileframe.location="user_upfile.asp?formname=postform&textname=annex"+num+"&s="+bbsstyle;
		postform.upnum.value=num;
		}
	}else{
		alert("最多仅允许上传"+maxupfile+"个附件!");
	}
}
//发贴特殊功能
//review        回复贴
//integ         积分贴
//popedom       权限贴
//pass          密码贴
function bbsVIP(cmd){
	var reVal;
	reVal=null;
	switch(cmd){
		case "review" :
			reVal="[REVIEW]<p>在这里输入需要回复的内容</p>[/REVIEW]";
			break;
		case "integ" :
			reVal = prompt("请输入查看本贴内容需要达到的积分数", "0");
			reVal=parseInt(reVal,10);
			if (!isNaN(reVal)){reVal="[INTEG="+reVal+"]<p>&nbsp;</p>[/INTEG]"}
			else{reVal="";alert("您的输入有误!")}
			break;
		case "popedom" :
			reVal = prompt("请输入查看本贴内容需要达到的会员等级(每等级权限相差10)", "0");
			reVal=parseInt(reVal,10);
			if (!isNaN(reVal)){reVal="[POPE="+reVal+"]<p>&nbsp;</p>[/POPE]"}
			else{reVal="";alert("您的输入有误!")}
			break;
		case "pass" :
			reVal = prompt("请输入查看本贴内容需要的密码(请不要使用特殊符号)", "");
			var reg=/\s|\"|'|\[|\]|\(|\)/ig
			if (reVal!=null&&reVal!=""&&!reg.test(reVal)){reVal="[PASS="+reVal+"]<p>&nbsp;</p>[/PASS]"}
			else{reVal="";alert("您输入的密码无效!")}
			break;
	}
	eTxt.SetContent(eTxt.GetContent()+reVal);
	eTxt.focus();
}
//查看投票用户
function showvote(path){
	window.open(path,"newWindow","height=400,width=300,top=200,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no, status=no");
	return false;
}


//论坛回复引用

function quote(intype,inId){
	try{
		var uname,utime,ucont;
		var qtime,qname,qcont;
		var qData;
		if (intype == 0 ){
			uname=eval("window.n_m_"+inId);
			utime=eval("window.t_m_"+inId);
			ucont=eval("window.c_m_"+inId);
		}else{
			uname=eval("window.n_r_"+inId);
			utime=eval("window.t_r_"+inId);
			ucont=eval("window.c_r_"+inId);
		}
		qtime=utime.innerHTML;
		qname=uname.innerHTML;
		qcont=ucont.innerHTML;
		qcont=qcont.replace(/<[^>]*>/ig,"");
		if (qcont.length>100){qcont=qcont.substr(0,100);}
		qData="<DIV style='border:1px dotted #FF9900; background:#FFFFE6;width:70%;text-align:center;margin-left:10px;height:70px;'>";
		qData+="<DIV style='text-align:left;padding-left:30px;border-bottom:1px dotted #f90;font-weight:bold;color:999;margin-left:5px;margin-right:5px;'>以下引用由<u style='color:#000;'>"+qname+"</u>于"+qtime+"的发言：</DIV>";
		qData+="<DIV style='text-align:left;padding-left:10px;'>"+qcont+"</DIV>";
		qData+="</DIV>";
		if (eTxt){
			eTxt.SetContent(eTxt.GetContent()+qData);
			document.getElementById("writename").focus();
			eTxt.focus();
		}
	}catch(E){}
}
	
//提交帖子检查
function checkAdd(inKey){
	if (postform.title.value.replace(/\s/g,"")==""){
		alert("请输入主题!");
		postform.title.focus();
		return false;
	}
	if (inKey=="vote"){
		if(postform.invtxt.value.replace(/\s|\n/ig,"")==""){
			alert("投票选项不能为空");
			postform.invtxt.focus();
			return false;
		}
	}
	if(eTxt.GetContent().replace(/\s/g,"").length<5){
		alert("您输入的内容太短,不能提交.")
		eTxt.focus();
		return false;
	}
	var tit=postform.title.value;
	var cont=eTxt.GetValue();
	tit=tit.replace("<","&lt;");
	tit=tit.replace(">","&gt;");
	postform.title.value=tit;
	cont=cont.replace(/on(load|unload|click|dbclick|mouseover|mousedown|mouseup|focus|blur|keypress|keydown|keyup)=/ig," ");
	cont=cont.replace(/<script/ig,"<!--script");
	cont=cont.replace(/<\/script>/ig,"script-->");
	postform.contents.value=cont;
	return true;
}
//发表回复
function postreview(){
	if(eTxt.GetContent().replace(/\s/g,"").length<5){
		alert("您输入的内容太短,不能提交.")
		eTxt.focus();
		return false;
	}
	var cont=eTxt.GetValue();
	cont=cont.replace(/on(load|unload|click|dbclick|mouseover|mousedown|mouseup|focus|blur|keypress|keydown|keyup)=/ig," ");
	cont=cont.replace(/<script/ig,"<!--script");
	cont=cont.replace(/<\/script>/ig,"script-->");
	rebox.contents.value=cont;
	return true;
}
//编辑回复
function postreviewedit(){
	if(eTxt.GetContent().replace(/\s/g,"").length<5){
		alert("您输入的内容太短,不能提交.")
		eTxt.focus();
		return false;
	}
	var cont=eTxt.GetValue();
	cont=cont.replace(/on(load|unload|click|dbclick|mouseover|mousedown|mouseup|focus|blur|keypress|keydown|keyup)=/ig," ");
	cont=cont.replace(/<script/ig,"<!--script");
	cont=cont.replace(/<\/script>/ig,"script-->");
	postform.contents.value=cont;
	return true;
}
//设置字体
function setFont()
{
  var arr = showModalDialog("editor/fontstyle.htm",null, "dialogWidth:350px;dialogHeight:200px;status:0;help:0;scroll:0");
  if (arr != null){
     postform.tstyle.value=arr;
     demostyle.innerHTML="<span "+arr+">标题样式ABCabc</span>";
  }
}
//****************************************************************
//功能：判断参数Str是不是数字
//参数：字符串
//返回值：是数字返回true，否则返回false
//****************************************************************
function isNumber(Str){  
	var reg=/\s/g;
	if(Str+""=="")
		return false;
	Str=Str.replace(reg,"");
	if(Str=="")
	{
		return false;
	}
	if(isNaN(Str))
	{
		return false;
	}
	else
	{
		var temp=parseInt(Str);
		if(temp<0)
			return false;
		else
			return true;
	}
}
//全选
function SelectAll(theForm)
{
	var theObjName=event.srcElement.name;
	var theObj=event.srcElement;
	var turn;
	if (theObj.checked){turn=true;}else{turn=false;}
	var length=theForm.elements[theObjName].length;
	var i;
	if(length+""=="undefined")
	{
		theForm.elements[theObjName].checked=turn;
	}
	else
	{
		for(i=0;i<length;i++)
		{
			theForm.elements[theObjName][i].checked=turn;
		}
	}	
}

