﻿
msgBox = {
  name: "msgBox",
  capiton : "消息框",
  content: "提示消息",
  msgbox : null,
  msgcaptioninfo:null,
  msgcontent:null,
  msgContenttxtmsg:null,
  msgbuttonyes:null,
  msbbuttonno:null,
  msgico:null 
};

msgBox.init = function () {
    var msgNameSpaceURI = "http://www.w3.org/1999/xhtml";
    
	if(!msgContainerID){ var msgContainerID= "msgBox"; }
	if(!msgCaptionID){ var msgCaptionID= "msgBox_caption"; }
	if(!msgCaptionInfoID){var msgCaptionInfoID = "msgBox_caption_info";}
	if(!msgContentID){ var msgContentID = "msgBox_content"; }
	if(!msgContentTxtID){ var msgContentTxtID= "msgBox_content_txt"; }
	if(!msgContentTxtICOID){var msgContentTxtICOID="msgBox_content_txt_ico"};
	if(!msgContentTxtMsgID){var msgContentTxtMsgID="msgBox_content_txt_msg"};
	if(!msgButtons){var msgButtonsID="msgBox_buttons"};
	if(!msgButtonYes){var msgButtonYesID="msgBox_buttons_yes"};
	if(!msgButtonNo){var msgButtonNoID="msgBox_buttons_no"};	
	if(!msgButtonOK){var msgButtonOKID="msgBox_buttons_ok"};	

	var msgContainer = $(msgContainerID);
	if(!msgContainer) {
	  msgContainer = document.createElementNS ? document.createElementNS(msgNameSpaceURI, "div") : document.createElement("div");
	  msgContainer.setAttribute("id", msgContainerID);
	  msgContainer.setAttribute("style","margin:0px auto; position:absolute;");


	var msgCaption = $(msgCaptionID);

	if(!msgCaption){
	  msgCaption = document.createElementNS ? document.createElementNS(msgNameSpaceURI, "div") : document.createElement("div") ;
	  msgCaption.setAttribute("id",msgCaptionID);
	  Element.addClassName(msgCaption,"caption");	  

	  
	  var msgCaptionInfo = $(msgCaptionInfoID);
	  if(!msgCaptionInfo){
	  msgCaptionInfo = document.createElementNS ? document.createElementNS(msgNameSpaceURI, "div") : document.createElement("div") ;
	  msgCaptionInfo.setAttribute("id",msgCaptionInfoID);
	  Element.addClassName(msgCaptionInfo,"info");
	  msgCaption.appendChild(msgCaptionInfo);
	  }
	  msgContainer.appendChild(msgCaption);
	  
	}
	
	var msgContent = $(msgContentID);

	if(!msgContent){
	  msgContent= document.createElementNS ? document.createElementNS(msgNameSpaceURI, "div") : document.createElement("div") ;
	  msgContent.setAttribute("id",msgContentID);
	  Element.addClassName(msgContent,"content");
	  
	  var msgContentTxt = $(msgContentTxtID);
	  
	  if(!msgContentTxt ){
	  msgContentTxt = document.createElementNS ? document.createElementNS(msgNameSpaceURI, "div") : document.createElement("div") ;
	  msgContentTxt.setAttribute("id",msgContentTxtID);
	  Element.addClassName(msgContentTxt,"txt");
	 	  
	  var msgContentTxtICO = $(msgContentTxtICOID);
	  if(!msgContentTxtICO)
	  {
	     msgContentTxtICO= document.createElementNS ? document.createElementNS(msgNameSpaceURI, "img") : document.createElement("img") ;
	     msgContentTxtICO.setAttribute("id",msgContentTxtICOID);
         msgContentTxtICO.setAttribute("src","js/msg_icon_alarm.gif");
	     msgContentTxtICO.setAttribute("align","absMiddle");
	     msgContentTxtICO.setAttribute("style","height:18px;width:22px;background-image:url('js/msg_icon_info.gif');");
	     msgContentTxt.appendChild(msgContentTxtICO);
	  }
	  
	  var msgContentTxtMsg= $(msgContentTxtMsgID);
	  if(!msgContentTxtMsg)
	  {
	     msgContentTxtMsg= document.createElementNS ? document.createElementNS(msgNameSpaceURI, "span") : document.createElement("span") ;
	     msgContentTxtMsg.setAttribute("id",msgContentTxtMsgID);
	     
	     msgContentTxt.appendChild(msgContentTxtMsg);
	  }


      var msgButtons = $(msgButtonsID);
      if(!msgButtons)
	  {
	     msgButtons = document.createElementNS ? document.createElementNS(msgNameSpaceURI, "div") : document.createElement("div") ;
	     msgButtons.setAttribute("id",msgButtonsID);
	     Element.addClassName(msgButtons,"btnlist");
         var msgButtonYes = $(msgButtonYesID);
          if(!msgButtonYes)
          {
            msgButtonYes= document.createElementNS ? document.createElementNS(msgNameSpaceURI, "input") : document.createElement("input") ;
	        msgButtonYes.setAttribute("id",msgButtonYesID);
	        msgButtonYes.setAttribute("type","button");
	        msgButtonYes.setAttribute("value","确定");
	        Element.addClassName(msgButtonYes,"input_set");
	    	        
	        msgButtons.appendChild(msgButtonYes); 	        
	     }

	     var msgButtonNo = $(msgButtonNoID);
          if(!msgButtonNo)
          {
            msgButtonNo= document.createElementNS ? document.createElementNS(msgNameSpaceURI, "input") : document.createElement("input") ;
	        msgButtonNo.setAttribute("id",msgButtonNoID);
	        msgButtonNo.setAttribute("type","button");
	        msgButtonNo.setAttribute("value","取消");
	        Element.addClassName(msgButtonNo,"input_set");
	        
	        msgButtons.appendChild(msgButtonNo); 
	        
	     }
	     
	     var msgButtonOK= $(msgButtonOKID);
          if(!msgButtonOK)
          {
            msgButtonOK= document.createElementNS ? document.createElementNS(msgNameSpaceURI, "input") : document.createElement("input") ;
	        msgButtonOK.setAttribute("id",msgButtonOKID);
	        msgButtonOK.setAttribute("type","button");
	        msgButtonOK.setAttribute("value","确定");
	        Element.addClassName(msgButtonOK,"input_set");
	        
	        msgButtons.appendChild(msgButtonOK); 
	        
	     }


	     msgContentTxt.appendChild(msgButtons);
	  }
	  
	  msgContent.appendChild(msgContentTxt);
	  }

	  
	  msgContainer.appendChild(msgContent);
	}

     document.getElementsByTagName("body").item(0).appendChild(msgContainer);
    }
       
    this.msgbox = $(this.name);
    this.msgcaptioninfo = $(msgCaptionInfoID);
	this.msgContent = $(msgContentID);
	this.msgContenttxt = $(msgContentTxtID);
    this.msgContenttxtmsg= $(msgContentTxtMsgID);
    this.msgbuttonyes = $(msgButtonYesID);
    this.msgbuttonno = $(msgButtonNoID);
    this.msgbuttonok = $(msgButtonOKID);
    this.msgico = $(msgContentTxtICOID);
    Element.hide(this.msgbox);
}

msgBox.ShowConfirm = function (caption,msg,YesClick,NoClick) {
	
	if (!this.msgbox ) return;
    DialogModal.Show();
	
	this.msgcaptioninfo.innerHTML = caption;
	this.msgContenttxtmsg.innerHTML = msg;
	this.msgico.setAttribute("src","js/msg_icon_alarm.gif");
    
	Element.show(this.msgbox);
	Element.show(this.msgbuttonyes);
	Element.show(this.msgbuttonno);
	Element.hide(this.msgbuttonok);
	
	var x=0,y=0;
	x = (document.documentElement.scrollLeft || document.body.scrollLeft);
	y = (document.documentElement.scrollTop || document.body.scrollTop);
	
	var theWidth=0,theHeight=0;
	
	if (window.innerWidth) 
    { 
      theWidth = window.innerWidth; 
      theHeight = window.innerHeight; 
    } 
    else if (document.documentElement && document.documentElement.clientWidth) 
    { 
      theWidth = document.documentElement.clientWidth; 
      theHeight = document.documentElement.clientHeight; 
    } 
    else if (document.body) 
    { 
      theWidth = document.body.clientWidth; 
      theHeight = document.body.clientHeight; 
    }
	
	this.msgbox.style.left = (theWidth  - this.msgbox.offsetWidth)/2+x+"px";
	this.msgbox.style.top = (theHeight - this.msgbox.offsetHeight)/2+y+"px"; 

	this.msgbuttonyes.onclick = YesClick;//function(){ alert('yes');};
	this.msgbuttonno.onclick = NoClick;

	Event.observe(this.msgbuttonyes,"click",function(){msgBox.Hide();},true);
	Event.observe(this.msgbuttonno,"click",function(){msgBox.Hide();},true);
}

msgBox.ShowInfo = function (caption,msg,theClick) {
	
	if (!this.msgbox ) return;	
    DialogModal.Show();
    
    this.msgico.setAttribute("src","js/msg_icon_alarm.gif");
    
	this.msgcaptioninfo.innerHTML = caption;
	this.msgContenttxtmsg.innerHTML = msg;
	Element.show(this.msgbox);
	Element.show(this.msgbuttonok);
	Element.hide(this.msgbuttonyes);
	Element.hide(this.msgbuttonno);
	
    var x=0,y=0;
	x = (document.documentElement.scrollLeft || document.body.scrollLeft);
	y = (document.documentElement.scrollTop || document.body.scrollTop);
	
	var theWidth=0,theHeight=0;
	
	if (window.innerWidth) 
    { 
      theWidth = window.innerWidth; 
      theHeight = window.innerHeight; 
    } 
    else if (document.documentElement && document.documentElement.clientWidth) 
    { 
      theWidth = document.documentElement.clientWidth; 
      theHeight = document.documentElement.clientHeight; 
    } 
    else if (document.body) 
    { 
      theWidth = document.body.clientWidth; 
      theHeight = document.body.clientHeight; 
    }
	
	this.msgbox.style.left = (theWidth  - this.msgbox.offsetWidth)/2+x+"px";
	this.msgbox.style.top = (theHeight - this.msgbox.offsetHeight)/2+y+"px";

	this.msgbuttonok.onclick = theClick;

	Event.observe(this.msgbuttonok,"click",function(){msgBox.Hide();},true);
}

msgBox.Hide = function()
{
    if (!this.msgbox ) return;
    Element.hide(this.msgbox);
    DialogModal.Close();
    Event.stopObserving(this.msgbuttonyes,"click",function(){msgBox.Hide();},true)
    Event.stopObserving(this.msgbuttonno,"click",function(){msgBox.Hide();},true)
    Event.stopObserving(this.msgbuttonok,"click",function(){msgBox.Hide();},true)
}


function DialogModal(){ 
    this.blankImgHandle = null; 
    this.tags = new Array("applet", "iframe", "select","object","embed");  
}

 
DialogModal.Show = function() 
{     
debugger;
        var NameSpaceURI = "http://www.w3.org/1999/xhtml";
        this.blankImgHandle = document.createElementNS ? document.createElementNS(NameSpaceURI, "div") : document.createElement("iframe") ;//iframe
        this.blankImgHandle.setAttribute("id","blankImgHanldle");
        with (this.blankImgHandle.style){ 
            position = "absolute"; 
            left     = "0px"; 
            top      = (document.documentElement.scrollTop || document.body.scrollTop)+"px"; 
            height   = document.documentElement.clientHeight+"px"; 
            width    = "100%";
			backgroundColor = "#000";
            zIndex   = "9999"; 
            filter   = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=40)"; 
            opacity  = "0.2";             
        }          
         
       document.getElementsByTagName("body").item(0).appendChild(this.blankImgHandle);         
   }         
         
DialogModal.Close = function(){                
      if (this.blankImgHandle) 
      { 
          Element.remove(this.blankImgHandle);
          this.blankImgHandle = null;
      }             
  }; 


//Event.observe(window, 'load', function(e){msgBox.init();}, false);
Event.observe(window, 'unload', Event.unloadCache, false);
