﻿/**
 * @author szsheng
 */
// JScript 文件

var DialogEngine = Class.create();
DialogEngine.prototype = {
	initialize:function(id){
		this.id = id;
		this._titleId = "title"+id;
		this._closeId = "close"+id;
		this.height = "200px";
		this.width = "300px";
		this.title = "ECL Dialog";
		this.backgroundColor = "#ffffff";
		this.border = "2px solid #0595D2";
		this.textAlign = "left";
		this.titleAttach = "";
		this.contentHtml = "";
		this.obj = this.initObj();
	},
	initObj:function(){
	    if($(this.id))
	        return $(this.id);
	    var _this = this;
	    var divPy = window.document.createElement("div");
        divPy.id = _this.id;
        divPy.style.position = "absolute";
        divPy.style.zIndex = 999;
        divPy.style.display = "none";
        window.document.body.appendChild(divPy);
        
        var tmpInitDrag = Draggable.prototype.initDrag;
        Draggable.prototype.initDrag=function(e) {
	        var src = Event.element(e);
	        if(Element.hasClassName(src,'UnableDrag'))return;
	        tmpInitDrag.apply(this,[e]);//'this' is Draggable's instance
        };
        
        new Draggable(divPy.id,{
	        handle:this._titleId,
	        onDrag:function(){
	            divPy.style.border='2px dotted #FFD94F';
	        },
	        onEnd:function(){
	            divPy.style.border='2px solid #0595D2';
	        }
        });
        return divPy;
	},
	show:function(isModify){
        if(isModify)
        {
            this.obj.style.height = this.height;
            this.obj.style.width = this.width;
            this.obj.style.backgroundColor = this.backgroundColor;
            this.obj.style.border = this.border;
            this.obj.style.textAlign = this.textAlign;
            
            var inHtml = "<div id='"+ this._titleId +"' style='text-align:right;background-color:#C8E0ED;border-bottom:1px solid #0394D1;padding:2px 5px 2px 5px'>";
            inHtml += "        <span style='float:left;font-size:14px;font-weight:bold;margin-top:2px;'>" + this.title +"</span>" + this.titleAttach;
            inHtml += "        <img id='"+ this._closeId +"' src='@images/close.gif' style='border:0px;' />";
            inHtml += "    </div>";
            inHtml += this.contentHtml;
            this.obj.innerHTML = inHtml;
        }
        Lightbox.utilShowHtml(this.id, this._closeId);
        var arrayPageSize = LightboxUtil.getPageSize();
		var arrayPageScroll = LightboxUtil.getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);
		var lightboxLeft = (arrayPageSize[2] - parseInt(this.width))/2;
        
        this.obj.style.left = lightboxLeft+"px";
	    this.obj.style.top = lightboxTop+"px";
	},
	hide:function(){
	    var preclose = $(this._closeId);
	    if(preclose)
	        preclose.click();
	}
}
