//*******************************************	
function setwindow(flag){
var temp_h1 = document.body.clientHeight;
var temp_h2 = document.documentElement.clientHeight;
var isXhtml = (temp_h2<=temp_h1&&temp_h2!=0)?true:false; 
var htmlbody = isXhtml?document.documentElement:document.body;
var newdivs = flag;
if (newdivs){
   newdivs = false;
   htmlbody.style.overflow = "auto";
}else{
   newdivs = true;
   htmlbody.style.overflow = "hidden";
}
}
var Obj='';
document.onmouseup=MUp;
document.onmousemove=MMove;

function MDown(Object){
Obj=Object.id;
document.all(Obj).setCapture();
pX=event.x-document.all(Obj).style.pixelLeft;
pY=event.y-document.all(Obj).style.pixelTop;
}

function MMove(){
if(Obj!=''){
	document.all(Obj).style.left=event.x-pX;
	document.all(Obj).style.top=event.y-pY;
	}
}

function MUp(){
if(Obj!=''){
	document.all(Obj).releaseCapture();
	Obj='';
	}
}	
//-----------------------------------------------------------------
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-----------------------------------------------------------------------------------

function SetCookie(name,value,expires){
var exp=new Date();
exp.setTime(exp.getTime()+expires*60000);
document.cookie=name+"="+escape(value)+";expires="+exp.toGMTString();
} 
function readcookie(name){
var oRegex=new RegExp(name+'=([^;]+)','i');
var oMatch=oRegex.exec(document.cookie);
if(oMatch&&oMatch.length>1)return unescape(oMatch[1]);
else return 1;
}
//------------------------------------------------------------------------------------------------
//document.ns = navigator.appName == "Microsoft Internet Explorer"
var bdy = (document.documentElement && document.documentElement.clientWidth)?document.documentElement:document.body;
//-----------------------------------------------------------------
function closepopu(){
        setwindow(true);
		var bgObj = document.getElementById("bgDiv");
		var title = document.getElementById("msgTitle");
		var msgObj = document.getElementById("msgDiv");
		var msgIframe = document.getElementById("bgIframe");
		if (typeof(title)=="object"){      
			document.getElementById("msgDiv").removeChild(title);
		}
		if (typeof(msgObj)=="object"){   
			document.body.removeChild(msgObj); 
		}
		if ((typeof(bgObj)=="object")&&(bgObj!="")){ 
			document.body.removeChild(bgObj);
		}
		if (typeof(msgIframe)=="object"){  
			document.body.removeChild(msgIframe); 
		}		
}
//--------------------------------------
function TpopuWindows(divname,width,heigth,titHeigth){ 
	 this.Gname = divname;
	 this.top = 0;
	 this.left = 0;
	 this.titlecolor = "#FFFFFF";
	 this.bgcolor = "#FCF1F6";
	 this.bordercolor="#FCF1F6";
	 this.titleurl = "";
	 //----------------------------
	 this.winWidth = 400;
	 this.winHeigth = 300;
	 this.titleheight = 18;
     if (arguments.length>=2){this.winWidth = parseInt(arguments[1]);}
     if (arguments.length>=3){this.winHeigth = parseInt(arguments[2]);}    
     if (arguments.length>=4){this.winTitHeigth = parseInt(arguments[3]);}
	 //-----------------------
	 this.titlename="";
	 //------------------------
	 this.showmodalflag=1; 
	 this.bgtop = 0;
	 this.bgleft = 0;
	 this.bgwidth= screen.width;
	 this.bgheight= screen.Height;
	 this.resizeDef();
  }  
   TpopuWindows.prototype.resizeDef = function(){  
	 var sWidth,sHeight;
	 sWidth = bdy.clientWidth-10;
	 sHeight = window.screen.height-window.screenTop;
	 if (this.left<=0)
	    this.left = (screen.width-this.winWidth)/2;
	 if (this.top<=0)
	    this.top = (screen.height-this.winHeigth)/2;
  }
  
  TpopuWindows.prototype.sAlert = function (disdiv,titleName){ 
    setwindow(false);
    if (arguments.length>=2){this.titlename = arguments[1];} 
	
	if (this.showmodalflag==1){
	var bgObj=document.createElement("div"); 
	bgObj.setAttribute('id','bgDiv'); 
	bgObj.style.position="absolute"; 
	bgObj.style.top="0px"; 
    bgObj.style.left="0px"; 
	bgObj.style.width=screen.width+"px"; 
	bgObj.style.height=screen.height+"px"; 
	bgObj.style.background="#ccccff"; 
	bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75"; 
	bgObj.style.opacity="0.6"; 
	bgObj.style.zIndex = "100000"; 
	document.body.appendChild(bgObj);
	} 
	
	if (this.showmodalflag==1){
	var bgfrmae=document.createElement("iframe");
	bgfrmae.setAttribute('id','bgIframe');	
	bgfrmae.style.position="absolute"; 
	bgfrmae.style.top="0px"; 
    bgfrmae.style.left="0px"; 
	bgfrmae.style.width=screen.width+"px"; 
	bgfrmae.style.height=screen.height+"px";
	bgfrmae.style.zIndex = "500";
	bgfrmae.style.background="#cccccc"; 
	bgfrmae.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75"; 
	bgfrmae.style.opacity="0.6"; 
    document.body.appendChild(bgfrmae);
	}
	  
	var msgObj=document.createElement("div"); 
	msgObj.setAttribute("id","msgDiv"); 
	msgObj.setAttribute("align","center"); 
	msgObj.style.background= this.bgcolor; 
	msgObj.style.border="1px solid " + this.bordercolor; 
	msgObj.style.position = "absolute"; 
	msgObj.style.left = this.left+"px"; 
	msgObj.style.top = this.top+"px"; 
	msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif"; 
	msgObj.style.width = this.winWidth; 
	//msgObj.style.height =msgh + "px"; 
	msgObj.style.textAlign = "center"; 
	msgObj.style.lineHeight ="25px"; 
	msgObj.style.zIndex = "100001";
	document.body.appendChild(msgObj); 
	
	var title=document.createElement("div"); 
	title.setAttribute("id","msgTitle"); 
	title.setAttribute("align","right"); 
	title.style.margin="0"; 
	title.setAttribute("align","left");
	title.style.textAlign = "left";
	title.style.background=this.titlecolor;
	if (this.titleurl!=""){title.style.backgroundImage = "url("+this.titleurl+")";}
	title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20,finishX=100,finishY=100,style=1,opacity=75,finishOpacity=100);"; 
	title.style.opacity="0.75"; 
	title.style.border="1px solid " + this.bordercolor; 
	title.style.height= this.titleheight;
	title.style.width = this.winWidth;
	title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif"; 
	title.style.color="white"; 
	title.style.cursor="pointer"; 
	title.innerHTML="<div onmousedown=MDown(msgDiv) style='width:"+(this.winWidth - 28)+"px;float:left;'>"+this.titlename+"</div><span style='float:left;width:12px;' onclick='"+this.Gname+".reWinDef();'>_</span><span style='float:left;width:12px;' onclick='"+this.Gname+".ok()'>×</span></div><br/>";
	
	document.getElementById("msgDiv").appendChild(title); 
	
	var txt=document.createElement("div");
	txt.setAttribute("id","msgTxt");
	txt.style.display = "block";
	//txt.style.height = (this.winHeigth-this.titleheight)+"px";
	txt.innerHTML = disdiv;
	//txt.style.margin="1em 0" 
	//txt.innerHTML=str; 
	document.getElementById("msgDiv").appendChild(txt);
	this.myMove();
    } 
		
	TpopuWindows.prototype.ok = function (){ 
        closepopu();
    }  	
	
    TpopuWindows.prototype.reWinDef = function (){ 	
       var flg = msgTxt.style.display=="none";
	   var post = 0;
       if(flg){
        	msgTxt.style.display = "block";
		    //重写标题栏的位置 
		    post = 30;
		    msgDiv.style.top = this.top;
		    msgDiv.style.left = this.left;
		//SetCookie('51ctobbs_fad_stat',1,1440);//设置cookie来保存浮动广告的状态 ，1为显示
		//SetCookie('51ctobbs_fad_post',post,1440);//保存post变量，位置
       }else{
            msgTxt.style.display = "none";
		    //重写标题栏的位置
		    post = -85;
			this.top = msgDiv.style.top;
			this.left = msgDiv.style.left;
		    //msgDiv.style.top = bdy.offsetHeight+bdy.scrollHeight-50+"px";
			msgDiv.style.top = "2px";
		    msgDiv.style.left = bdy.offsetWidth-this.winWidth-30+"px";
		//SetCookie('51ctobbs_fad_stat',2,1440);//设置cookie来保存浮动广告的状态 ，2为最小化，3为关闭
		//SetCookie('51ctobbs_fad_post',post,1440);//保存post变量，位置
       }
    }  	
	TpopuWindows.prototype.myMove = function(){ //自动移动层
		this.resizeDef();
	   //--------------------------
	   var msgObj = document.getElementById("msgDiv");
	   if (msgObj != ""){
	      document.getElementById("msgDiv").style.left = this.left+"px";
	      document.getElementById("msgDiv").style.top = this.top+"px";  
	   }
	   //--------------------------
       // setTimeout(this.Gname+".myMove();",50);
    }	
	
	TpopuWindows.prototype.showDiv = function(divname,titleName){ //显示层
	   var html="";
	   if (arguments.length>=2){var titleN = titleName;}
    	else {titleN=decodeURI("%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA");}
	   html = document.getElementById(divname).innerHTML;
	   if(html!=""){
		   var xobject = document.getElementById(divname);
		   document.body.removeChild(xobject);
		   this.sAlert(html,titleN);
		   this.defDiv=divname;
		   document.body.appendChild(xobject); 
	   }
	}
	
	TpopuWindows.prototype.showHtml = function(htmlname){ //显示html文件
	   var xhtml="";
	   if (arguments.length>=2){this.titlename = arguments[1];}
	   xhtml = "<iframe width="+this.winWidth+" height="+this.winHeigth+" name='xpopuframe' frameborder='0' id='xpopuframe' src='"+htmlname+"'></iframe>";
	   this.sAlert(xhtml);
	}
//---------------------------------------------------------------------------------	
	function TpopuWindowsSc(objname,txtname,formpath,allext){ //上传弹出窗体
	   TpopuWindows.call(this);
	   this.Gname = objname;
	   this.txtfilepath = txtname; 
	   this.objname = objname;
	   this.formpath = formpath;
	   //this.allext = allext;
	   if (arguments.length>=4){this.allext = allext;}
	 else {this.allext = "gif;jpeg;jpg;";}
	}
	TpopuWindowsSc.prototype.inheritFrom(TpopuWindows); 
	
	TpopuWindowsSc.prototype.show = function(){ //显示上传窗体
	  var html = "";
	  var objname = this.objname;
	  var picpath = this.formpath;
	  var allext = this.allext;
	  html += '<form action="inc/upload.asp?action='+objname+'&formPath='+picpath+'&allext='+allext+'" id="formx" name="formx" encType="multipart/form-data" method="post" target="hidden_frame" onsubmit="return '+objname+'.sccheck()">';
   	  html += '<input type="file" id="file" name="file" style="width:300">';
	  html += '<INPUT type="submit" value='+decodeURI("%E4%B8%8A%E4%BC%A0%E6%96%87%E4%BB%B6")+'>';
	  html += '<input name="fileName" type="hidden" id="fileName" value="ddd" /><br />';
	  html += '<font color="red">'+decodeURI("%E6%94%AF%E6%8C%81")+allext+decodeURI("%E6%96%87%E4%BB%B6%E7%9A%84%E4%B8%8A%E4%BC%A0")+'</font> </form>';
	  html += '<div id="msg"></div>';
	  html += '<iframe name="hidden_frame" id="hidden_frame" style="display:none"></iframe></div>';
	  this.sAlert(html);
	}
	TpopuWindowsSc.prototype.sccheck = function(){
	    if (document.formx.file.value==""){
	      alert(decodeURI("%E8%AF%B7%E9%80%89%E6%8B%A9%E6%96%87%E4%BB%B6"));
		  document.formx.file.focus();
		  return false;
		}
	}	
	TpopuWindowsSc.prototype.callback = function(scbool,fname){
      var msg;
      if (scbool==1 ){msg=decodeURI("%E4%B8%8A%E4%BC%A0%E6%88%90%E5%8A%9F");document.getElementById(this.txtfilepath).value=fname;this.ok();}
      if (scbool==0 ){msg=decodeURI("%E4%B8%8A%E4%BC%A0%E5%A4%B1%E8%B4%A5");document.getElementById(this.txtfilepath).value="";}	
	}
//---------------------------------------------------------------------------------------	
function TpopuWindowsFlash(objname,width,height){ //显示Flash
	  TpopuWindows.call(this,objname,width,height);
	  this.width = width;
	  this.height = height;
  }
  TpopuWindowsFlash.prototype.inheritFrom(TpopuWindows); 
  
  TpopuWindowsFlash.prototype.show = function(filename){
     var html = '';
	 html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="main" align="middle" height="'+this.height+'" width="'+this.width+'">';
	 html += '<param name="allowScriptAccess" value="always">';
	 html += '<param name="movie" value="'+filename+'">';
	 html += '<param name="quality" value="high">';
	 html += '<param name="wmode" value="transparent">';
	 html += '<embed src="'+filename+'" quality="high" wmode="transparent" name="main" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" align="middle" height="'+this.height+'" width="'+this.width+'">';
	 html += '</object>';
	 this.sAlert(html);
  }
//-----------------------------------------------------------------
function TpopuWindwsDepart(width,height,typeid,typename){
	  TpopuWindows.call(this,width,height);
	  this.width = width;
	  this.height = height;	
	  this.typeid = typeid;
	  this.typename = typename;
}
TpopuWindwsDepart.prototype.inheritFrom(TpopuWindows); 

TpopuWindwsDepart.prototype.show = function(){
  function doOnSelect(itemId){
	alert(this.typeid);
	alert(this.typename);
   document.getElementById(this.typeid).value= itemId;
   //document.getElementById(this.typename).value =tree.getSelectedItemText();
   this.ok();
}
  var html = "";
  var curwidth = this.width -3;
  alert(this.typeid);
  html += '<div id="xxtree" style="width:'+curwidth+'px; height:'+this.height+'px;background-color:#f5f5f5;border :1px solid Silver;"/>';
  this.sAlert(html);
  tree=new dhtmlXTreeObject("xxtree","100%","100%",-1);
  tree.setImagePath("tree/js/imgs/");
  tree.setOnClickHandler(this.doOnSelect);
  tree.loadXML("tree/tree.asp?action=getTree");
}
TpopuWindwsDepart.prototype.doOnSelect =function(itemId){
	alert(this.typeid);
	alert(this.typename);
   document.getElementById(this.typeid).value= itemId;
   //document.getElementById(this.typename).value =tree.getSelectedItemText();
   this.ok();
}