/* 
 @module 对话框        
 @resource globalDiv.js ,boxOk.gif, boxError.gif, boxInfo.gif, boxAsk.gif,boxClose.gif
 @author 戴磊智                                                                        
 @Company: 南方科能                                                                    
 @Copyright: Copyright (c) 2007 
 */


var dialogDivX=0;
var dialogDivY=0;
var context="/jxsr";
function Dialog(){
 this.title="【江西省横峰县政府信息公开】";
 this.canMove=false;//是否能拖动对话框
} 
 /* *
信息对话框
 */  
  Dialog.prototype.showInfo=function(content){
     globalDiv.show();
     var dialogDiv=this.getDialogDiv();
     this.setContent(dialogDiv,content,1);
     dialogDiv.style.visibility='visible';
     dialogDiv.style.display='block';
  }
  
/* *
错误对话框
 */
  Dialog.prototype.showError=function(content){
     globalDiv.show();
     var dialogDiv=this.getDialogDiv();
     this.setContent(dialogDiv,content,2);
     dialogDiv.style.visibility='visible';
     dialogDiv.style.display='block';
  }//end showError function
/* *
成功对话框
 */
  Dialog.prototype.showOk=function(content,okScript){
     globalDiv.show();
     var dialogDiv=this.getDialogDiv();
     this.setContent(dialogDiv,content,3,okScript);
     dialogDiv.style.visibility='visible';
     dialogDiv.style.display='block';
  }
  
  Dialog.prototype.showConfirm=function(content,okScript,cancelScript){
     globalDiv.show();
     var dialogDiv=this.getDialogDiv();
     this.setContent(dialogDiv,content,4,okScript,cancelScript);
     dialogDiv.style.visibility='visible';
     dialogDiv.style.display='block';
  }  
  
//  Dialog.prototype.showRequestStatus=function(content){
//     globalDiv.show();
//     var dialogDiv=this.getRequestStatusDialogDiv();
//     dialogDiv.innerHTML=content;
//     dialogDiv.style.position='absolute';
//     if(self.innerHeight){// all except Explorer
//        x = self.innerWidth;
//        y = self.innerHeight;
//     }else if(document.documentElement && document.documentElement.clientHeight){// Explorer 6 Strict Mode
//        x = document.documentElement.clientWidth;
//        y = document.documentElement.clientHeight;
//     }else if(document.body){// other Explorers
//        //x = document.body.clientWidth;
//        //y = document.body.clientHeight;
//        x = document.body.scrollWidth;
//        y = document.body.scrollHeight;
//        x = (x< document.body.offsetWidth ? document.body.offsetWidth : x);
//        y = (y< document.body.offsetHeight ? document.body.offsetHeight : y);
//     }//end if
//     var objLeft=parseInt((x*(1-0.85))/2);
//     //var top = 25 ;
//     var left = objLeft;
//      //alert();
//	 if( left<=0 ) left = 10;
//	 var top = (y/2) -150 + parseInt(document.body.scrollTop/2);
//	 var left = (x/2) - 200;
//	 if( left<=0 ) left = 10;
//	 if( top<=0 ) top = 10;
//     dialogDiv.style.left= left + "px";
//     dialogDiv.style.top = top + "px";
//     dialogDiv.style.zIndex=99;
//     document.body.onresize=function(event){
//      globalDiv.resize();
//      dialog.reMove();
//     }
//     //注册事件
//     dialogDiv.onmouseup=function(event){
//       this.canMove=false;
//       var dialogDiv=document.getElementById("dialogDiv");
//       dialogDiv.releaseCapture();
//       //("1 "+this.canMove);
//     }
//      //注册事件
//     dialogDiv.onmousedown=function(event){
//          //alert("onmousedown");
//          this.canMove=true;
//          var dialogDiv=document.getElementById("dialogDiv");
//	      var dialogDivLeft = dialogDiv.style.left;
//	      var dialogDivTop = dialogDiv.style.top;
//	      var dialogDivLeft = dialogDivLeft.replace(/p|x/g,"");
//	      var dialogDivTop = dialogDivTop.replace(/p|x/g,"");
//	      if ( event == null ) {//IE必须
//		   event=window.event;
//	      }
//	      var clientX = String(event.clientX).replace(/p|x/g,"");
//	      var clientY = String(event.clientY).replace(/p|x/g,"");
//	      dialogDivX = clientX - dialogDivLeft;
//	      dialogDivY = clientY - dialogDivTop;
//	      dialogDiv.setCapture();
//	      //alert("2 "+this.canMove);
//      }// end dialogDiv.onmousedown
//       //注册事件  
//      dialogDiv.onmousemove = function (event){//start document.body.onmousemove 
//         if(this.canMove==false)return;
//         var dialogDiv=document.getElementById("dialogDiv");
//         if( dialogDivX != 0 && dialogDivY != 0 ) {//start if1
//		  if ( event == null ) {//IE必须
//			event=window.event;
//		  }
//		  if ( event.button == 1 ||  event.button == 2 ){//start if2
//			var dialogDivWidth=dialogDiv.firstChild.clientWidth;
//			var dialogDivHeight=dialogDiv.firstChild.clientHeight;
//            var bodyScrollWidth=document.body.scrollWidth;
//	        var bodyScrollHeight=document.body.scrollHeight;
//			var left= event.clientX-dialogDivX;
//			if ( left < 0 ) {
//				left=0;
//			}
//			if ( left > bodyScrollWidth-dialogDivWidth ) {
//				left=bodyScrollWidth-dialogDivWidth;
//			}
//			var top=event.clientY-dialogDivY;
//			if ( top < 0 ) {
//				top=0;
//			}
//			if ( top > bodyScrollHeight-dialogDivHeight ) {
//				top=bodyScrollHeight-dialogDivHeight;
//			}
//			
//			dialogDiv.style.left=left+'px';
//			dialogDiv.style.top=top+'px';
//		  }//end if 2
//		}//end if1
//       }//end document.body.onmousemove function
//       
//        dialogDiv.style.visibility='visible';
//        dialogDiv.style.display='block';
//  }
//  /* *
//  
//   */
//  Dialog.prototype.getRequestStatusDialogDiv=function(){
//     var dialogDiv=this.getDialogDiv();
//     var x;
//     if(self.innerHeight){// all except Explorer
//        x = self.innerWidth;
//        //y = self.innerHeight;
//     }else if(document.documentElement && document.documentElement.clientHeight){// Explorer 6 Strict Mode
//        x = document.documentElement.clientWidth;
//        //y = document.documentElement.clientHeight;
//     }else if(document.body){// other Explorers
//        //x = document.body.clientWidth;
//        //y = document.body.clientHeight;
//        x = document.body.scrollWidth;
//        //y = document.body.scrollHeight;
//        x = (x< document.body.offsetWidth ? document.body.offsetWidth : x);
//        //y = (y< document.body.offsetHeight ? document.body.offsetHeight : y);
//     }//end if
//     dialogDiv.style.width=x+"px";
//     return dialogDiv;
//  }
  
  
  Dialog.prototype.getDialogDiv=function(){
      var dialogDiv=document.getElementById("dialogDiv");
      if(!dialogDiv||dialogDiv==null){
         dialogStr="<div id=\"dialogDiv\" style=\"display:none;position:absolute;width:600px;\"></div>";
         document.body.insertAdjacentHTML("beforeEnd",dialogStr);
         return document.getElementById("dialogDiv");
      }
      return dialogDiv;
  }

  Dialog.prototype.reMove=function(){
    if(self.innerHeight){// all except Explorer
        x = self.innerWidth;
        y = self.innerHeight;
     }else if(document.documentElement && document.documentElement.clientHeight){// Explorer 6 Strict Mode
        x = document.documentElement.clientWidth;
        y = document.documentElement.clientHeight;
     }else if(document.body){// other Explorers
        x = document.body.scrollWidth;
        y = document.body.scrollHeight;
        x = (x< document.body.offsetWidth ? document.body.offsetWidth : x);
        y = (y< document.body.offsetHeight ? document.body.offsetHeight : y);
     }//end if
     
     var objLeft=parseInt((x*(1-0.85))/2);
     //var top = 25 ;
     var left = objLeft;
	 if( left<=0 ) left = 10;
	 var top = (y/2) -150 + parseInt(document.body.scrollTop/2);
	 var left = (x/2) - 200;
	 if( left<=0 ) left = 10;
	 if( top<=0 ) top = 10;
	 var dialogDiv=document.getElementById("dialogDiv");
     dialogDiv.style.left= left + "px";
     dialogDiv.style.top = top + "px";
  }
/* *
 关闭对话框
 */  
  Dialog.prototype.close=function(){
     globalDiv.hidden();
     var dialogDiv=document.getElementById("dialogDiv");
	 dialogDiv.style.visibility = 'hidden';
	 dialogDiv.style.display = 'none';
   }//end init
   
  
  /* 
   @TODO 生成对话框及显示内容
   @param dialogDiv 对话框div
   @param content 对话框显示内容
   @param type 1:提示对话框, 2:错误对话框,3:成功对话框,4:询问对话框
   @param okScript 询问对话框"确定"按钮click事件的javascript脚本字符串(只对询问对话框有效)
   @param  cancelScript 询问对话框"取消"按钮click事件的javascript脚本字符串(只对询问对话框有效)默认值为关闭对话框
   */
  Dialog.prototype.setContent=function(dialogDiv,content,type,okScript,cancelScript){
     var tb="<table width=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
     tb+="<tr>";
     tb+="<td height=\"24\" bgColor=\"#ff6b2e\" ><table width=\"100%\" height=\"20\"  border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
     tb+="<tr style=\"cursor:move\"><td width=\"500\" class=\"text_wirte\">"+this.title+"</td>";
     tb+="<td class=\"text_wirte\" ><div align=\"right\"><img src=\""+context+"/images/boxClose.gif\" width=\"16\" height=\"16\" onclick=\"dialog.close();\" title=\"关闭对话框\" style=\"cursor:hand;\">&nbsp;</div></td>";
     tb+="</tr></table></td></tr></table>";
     
     tb+="<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" class=\"td_title\">";
     tb+="<tr><td bgcolor=\"#DDEEFD\"><table width=\"100%\" height=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"#DDEEFD\">";
     tb+="<tr><td bgcolor=\"#F4F9FE\"><table width=\"100%\" height=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
     tb+="<tr><td width=\"30%\"><div align=\"center\"><img src=\""+context+"/images/"+(type==1 ? 'boxInfo.gif' : (type==2 ? 'boxError.gif' : (type==3 ? 'boxOk.gif' : 'boxAsk.gif')))+"\" name=\"imgBackGround\" width=\"49\" height=\"50\" id=\"imgBackGround\" /></div>";
     tb+="</td><td width=\"70%\" valign=\"top\"><div id=\"MsgDiv\"><table width=\"88%\" height=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
     tb+="<tr><td style=\"font-weight:bold;font-size:14px;color:#014F8A;height:30px;\"><span id=\"msgTitle\">"+(type==1 ? '提示' : (type==2 ? '错误' : type==3 ? '成功' : '询问'))+"</span></td></tr><tr><td height=\"1\" bgcolor=\"#cccccc\"></td>";
     tb+="</tr><tr><td style=\"font-size: 12px;color: #000000;line-height: 10px;height:10%\">&nbsp;</td>";
     tb+="</tr><tr><td height=\"1\"></td></tr><tr><td height=\"1\"></td></tr><tr><td height=\"5\"></td></tr>";
     tb+="<tr><td height=\"30%\" style=\"word-break: break-all; word-wrap:break-word;\"><p id=\"msgContent\" >"+content+"</p></td></tr><tr><td height=\"10\"></td>";
     tb+="</tr><tr><td height=\"50\">";
     if(type==4){
       tb+="<input type=\"button\" name=\"cButton\" value=\"确  定\" class=\"button_02\" onclick=\"javascript:"+okScript+"\">&nbsp;&nbsp;"
       tb+="<input type=\"button\" name=\"cButton\" value=\"取  消\" class=\"button_02\" onclick=\"javascript:"+(cancelScript==null || cancelScript.length<=0 ? 'dialog.close();' : cancelScript )+"\">"
     }else if(type==3){
        tb+="<input type=\"button\" name=\"cButton\" value=\"确  定\" class=\"button_02\" onclick=\""+(okScript!='undefined' ? okScript : 'dialog.close();')+"\">"
     }else{
        tb+="<input type=\"button\" name=\"cButton\" value=\"确  定\" class=\"button_02\" onclick=\"dialog.close();\">"
     }
     tb+="</td></tr><TR><TD></TD></TR></table></div></td></tr></table></td></tr></table></td></tr><tr><td height=\"10\"></td></tr></table>";
     dialogDiv.innerHTML=tb;
     dialogDiv.style.position='absolute';
     if(self.innerHeight){// all except Explorer
        x = self.innerWidth;
        y = self.innerHeight;
     }else if(document.documentElement && document.documentElement.clientHeight){// Explorer 6 Strict Mode
        x = document.documentElement.clientWidth;
        y = document.documentElement.clientHeight;
     }else if(document.body){// other Explorers
        //x = document.body.clientWidth;
        //y = document.body.clientHeight;
        x = document.body.scrollWidth;
        y = document.body.scrollHeight;
        x = (x< document.body.offsetWidth ? document.body.offsetWidth : x);
        y = (y< document.body.offsetHeight ? document.body.offsetHeight : y);
     }//end if
     var objLeft=parseInt((x*(1-0.85))/2);
     //var top = 25 ;
     var left = objLeft;
      //alert();
	 if( left<=0 ) left = 10;
	 var top = (y/2) -220 + parseInt(document.body.scrollTop/2);
	 var left = (x/2) - 300;
	 if( left<=0 ) left = 10;
	 if( top<=0 ) top = 10;
     dialogDiv.style.left= left + "px";
     dialogDiv.style.top = top + "px";
     dialogDiv.style.zIndex=99;
     document.body.onresize=function(event){
      globalDiv.resize();
      dialog.reMove();
     }
     //注册事件
     dialogDiv.onmouseup=function(event){
       this.canMove=false;
       var dialogDiv=document.getElementById("dialogDiv");
       dialogDiv.releaseCapture();
       //("1 "+this.canMove);
     }
      //注册事件
     dialogDiv.onmousedown=function(event){
          //alert("onmousedown");
          this.canMove=true;
          var dialogDiv=document.getElementById("dialogDiv");
	      var dialogDivLeft = dialogDiv.style.left;
	      var dialogDivTop = dialogDiv.style.top;
	      var dialogDivLeft = dialogDivLeft.replace(/p|x/g,"");
	      var dialogDivTop = dialogDivTop.replace(/p|x/g,"");
	      if ( event == null ) {//IE必须
		   event=window.event;
	      }
	      var clientX = String(event.clientX).replace(/p|x/g,"");
	      var clientY = String(event.clientY).replace(/p|x/g,"");
	      dialogDivX = clientX - dialogDivLeft;
	      dialogDivY = clientY - dialogDivTop;
	      dialogDiv.setCapture();
	      //alert("2 "+this.canMove);
      }// end dialogDiv.onmousedown
       //注册事件  
      dialogDiv.onmousemove = function (event){//start document.body.onmousemove 
         if(this.canMove==false)return;
         var dialogDiv=document.getElementById("dialogDiv");
         if( dialogDivX != 0 && dialogDivY != 0 ) {//start if1
		  if ( event == null ) {//IE必须
			event=window.event;
		  }
		  if ( event.button == 1 ||  event.button == 2 ){//start if2
			var dialogDivWidth=dialogDiv.firstChild.clientWidth;
			var dialogDivHeight=dialogDiv.firstChild.clientHeight;
            var bodyScrollWidth=document.body.scrollWidth;
	        var bodyScrollHeight=document.body.scrollHeight;
			var left= event.clientX-dialogDivX;
			if ( left < 0 ) {
				left=0;
			}
			if ( left > bodyScrollWidth-dialogDivWidth ) {
				left=bodyScrollWidth-dialogDivWidth;
			}
			var top=event.clientY-dialogDivY;
			if ( top < 0 ) {
				top=0;
			}
			if ( top > bodyScrollHeight-dialogDivHeight ) {
				top=bodyScrollHeight-dialogDivHeight;
			}
			
			dialogDiv.style.left=left+'px';
			dialogDiv.style.top=top+'px';
		  }//end if 2
		}//end if1
       }//end document.body.onmousemove function
  }
  
  

var dialog=new Dialog();

