/**
 * @projectDescription 提示框类型.
 * @author ice deng
 */
var MsgboxType = {
	/**
	 * 按钮显示的类型.
	 */
	type:{confirm:1,confirmAndCancel:2,ok:3,okAndNo:4},
	/**
	 * 显示的图片的类型.
	 */
	img:{
		plaint:"/images/plaint.gif",//友情提醒图标.
		ask:"/images/ask.gif",//问题提醒图标.
		error:"/images/error.gif",//错误提醒图标.
		success:"/images/yes.gif"//成功提醒图标.
	}
}
/**
 * @projectDescription 提示框.
 * @param (Object) 提示框的消息，传入一个对象格式为：{"title":"系统提示:","msg":"是否要删除?"}.
 * @param (Object) 按钮显示的类型,传入MsgboxType.type.对象.也可以是1-4的数字.
 * @param (Object) 显示的图片的类型,传入MsgboxType.img.对象.
 * @param (Object) 点击按钮后执行的方法,传入一个方法对象数组,数组索引按照先是确定的方法，在是否定的方法.
 * @author ice deng
 * @exception var msg = new Msgbox({title:"什么东西哦？",msg:"好东西啊？？？"},MsgboxType.type.confirmAndCancel,MsgboxType.img.ask,new Array("alert('1');","alert('2');"));
 */
var Msgbox = Class.create();
Msgbox.prototype = {
	initialize:function(_msg,_type,_img,_method){
		if(_msg != undefined)
			this.message = _msg;
		if(_type != undefined)
			this.type = _type;
		if(_img != undefined)
			this.img = _img;
		var num = parseInt(this.img);
		if(!isNaN(num)){
			switch(num){
				case 1:
					this.img = MsgboxType.img.plaint;
					break;
				case 2:
					this.img = MsgboxType.img.ask;
					break;
				case 3:
					this.img = MsgboxType.img.error;
					break;
				case 4:
					this.img = MsgboxType.img.success;
					break;
				default:
					this.img = MsgboxType.img.plaint;
					break;
			}
		}
		if(_method != undefined)
			this.method = _method;
		this.create();
	},
	message:new Object(),
	type:MsgboxType.type.confirm,
	img:MsgboxType.img.plaint,
	method:new Object(),
	create:function(){
		Body = document.getElementsByTagName("body").item(0);
		var Overlay = document.createElement("div");
		Overlay.className = "MessageDiv";
		Overlay.style.position = "absolute";
		Overlay.style.top = "0";
		Overlay.style.left = "0";
		Overlay.style.zIndex = "1000";
		Overlay.style.width = "100%";
		Overlay.style.height = "500px";
		Overlay.style.backgroundColor = "#ffffff";
		var type = arguments[0];
		if(Browser.isIE){
			Overlay.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=10)";
		}else{
			Overlay.style.opacity = "0.5";
		}
		var p_s = getPageSize();
		Overlay.style.display = "";
		Overlay.style.width = p_s[2] + "px";
		Overlay.style.height = p_s[1] + "px";
		Body.appendChild(Overlay);
		var msgMain = document.createElement("div");
		msgMain.className = "MessageDiv";
		var pa = getPageSize();
		var psl = getPageScroll();
		var _height = 180/2;
		var _width = 330/2;
		msgMain.style.top =  (psl[1]+pa[3]/2 - _height) + "px";
		msgMain.style.left =  (pa[0]/2 - _width) + "px";
		msgMain.style.position = "absolute";
		msgMain.style.zIndex = "1001";
		msgMain.style.width = "300px";
		msgMain.style.backgroundColor = "#FFFFFF";
		msgMain.style.border = "solid #CCCCCC 5px";
		msgMain.style.borderWidth = "5px";
		msgMain.style.marginLeft = "auto";
		msgMain.style.marginRight = "auto";
		msgMain.style.padding = "10px";
		msgMain.style.fontFamily = "Arial, Verdana, MingLiU";
		if(Browser.isIE){
			msgMain.style.fontSize = "12px";
		}else{
			msgMain.style.fontSize = "11px";
		}
		Body.appendChild(msgMain);
		var title = this.message.title;
		if(isNull(title)){
			title = "提示:";
		}
		var msgShow = this.message.msg;
		if(isNull(msgShow)){
			msgShow = "";
		}
		var but = "";
		switch(parseInt(this.type)){
			case 1:
				but = "<button onclick=\"DargMessageDivClose();"+this.method[0]+"\" style=\"padding:5px 20px 5px 20px;\">  确定  </button>";
				break;
			case 2:
				but = "<button onclick=\"DargMessageDivClose();"+this.method[0]+"\" style=\"padding:5px 20px 5px 20px;\">  确定  </button> <button onclick=\"DargMessageDivClose();"+this.method[1]+"\" style=\"padding:5px 20px 5px 20px;\">  取消  </button>";
				break;
			case 3:
				but = "<button onclick=\"DargMessageDivClose();"+this.method[0]+"\" style=\"padding:5px 20px 5px 20px;\">  OK  </button>";
				break;
			case 4:
				but = "<button onclick=\"DargMessageDivClose();"+this.method[0]+"\" style=\"padding:5px 20px 5px 20px;\">  是  </button> <button onclick=\"DargMessageDivClose();"+this.method[1]+"\" style=\"padding:5px 20px 5px 20px;\">  否.  </button>";
				break;
			default:
				but = "<button onclick=\"DargMessageDivClose();"+this.method[0]+"\" style=\"padding:5px 20px 5px 20px;\">  确定  </button>";
				break;
		}
		msgMain.innerHTML = "<em style=\"float:right; margin:5px 4px 0px 0px; color:#CCCCCC;margin-top:-0px;\" class=\"closebtn\">"+
					"<a href=\"javascript:DargMessageDivClose();\"><img src=\"/images/iconclose.gif\" style=\"margin-left:2px; border:0px;width:16px;height:16px;border:0px;\" /></a></em>"+
					"<div onmouseover=\"this.style.cursor='move';\" onmousedown=\"DargMessageDiv.init(event,this.parentNode);\" style=\"font-weight:bold; border-bottom:dashed 1px #bfbfbf; margin:0px 8px 0px 8px; line-height:25px; margin-bottom:10px; color:#424242;\">"+title+"</div>"+
					"<div>"+
					"<table width=\"100%\" border=\"0\" >"+
					"<tr><td width=\"110\" align=\"center\" valign=\"middle\" ><img src=\""+this.img+"\" /></td>"+
					"<td width=\"264\" style=\"font-size:14px; height:50px;padding:4px;\">"+msgShow+"</td>"+
					"</tr>"+
					"<tr>"+
					"<td colspan=\"2\" style=\"padding:4px;\" align=\"right\" valign=\"top\">"+but+"</td>"+
    				"</tr>"+
					"</table>"+
					"</div>"+
					"<table style=\"background-color:#000; margin-top:15px;height:7px; width:inherit!important;width:100%;position:absolute;-moz-opacity:0.5;filter:alpha(opacity=50);\"><tr><td></td></tr></table>";
	}
}
function DargMessageDivClose(){
	try{
		var div_ = document.getElementsByClassName("MessageDiv");
		for(var i = 0;i < div_.length;i++){
			try{$(div_[i]).parentNode.removeChild($(div_[i]));}
			catch(e){alerts(e);}
		}
	}catch(e){}
}
/**
 * @projectDescription 层的拖动.
 * @author ice deng
 */
var DargMessageDiv = {
	lastX:0,
	lastY:0,
	moveDiv:new Object(),
	init:function(ev,obj){
		ev = ev?ev:window.event;
		var parentObj = obj;
		this.moveDiv = parentObj;
		try{
			var tmp = this.getInfo(parentObj);
			this.lastX= ev.clientX-tmp.left;
			this.lastY= ev.clientY-tmp.top;
		}catch(e){alerts(e);}
	
		document.onmousemove = function(event){
        	DargMessageDiv.move(event);
      	}
		
      	document.onmouseup = function(){
	        document.onmousemove = null;
	        document.onmouseup = null;
      	}
	},
	move:function(ev){
		try{
			ev = ev?ev:window.event;
		    var cx = ev.clientX;
			var cy = ev.clientY;
		    DargMessageDiv.moveDiv.style.left = cx - this.lastX +'px';
		    DargMessageDiv.moveDiv.style.top  = cy - this.lastY +'px';
		}catch(e){alerts(e);}
	},
	getInfo:function(o){
		var to=new Object();
		to.left=to.right=to.top=to.bottom=0;
		var twidth=o.offsetWidth;
		var theight=o.offsetHeight;
		while(o!=document.body){
			try{
				to.left+=o.offsetLeft;
				to.top+=o.offsetTop;
				o=o.offsetParent;
			}catch(e){break;}
		}
		to.right=to.left+twidth;
		to.bottom=to.top+theight;
		return to;
	}
}
