/*******************************************************/ 
/* CopyRight By Dinh The Phuong. THSoft 10/04/2008 */ 
/*******************************************************/ 
var windowExzIndex = 10000; var windowEx = function(config){ this.config = { title: '', width: '', height: '', content: '', resize: true, maximize: true, minimize: true, modal:true }
Object.extend(this.config, config || {}); this.init(); }
windowEx.prototype = { init: function(){ this.W = null; this.wed = null; this.wc = null; this.ws = null; this.IM = null; this.V = null; this.iMX = null; this.iMY = null; this.iX = null; this.iY = null; this.width = null; this.contentHeight = null; 
this.beforeX = null; this.beforeY = null; this.beforeWidth = null; this.beforeContentHeight = null; 
if(this.config.modal) this.initVeil(); this.drawWindow(); }, initVeil: function(){ this.V = document.createElement('div'); this.V.className = "windowEx-veil"; this.V.style.width = (getBody().clientWidth - 2) + 'px'; this.V.style.height = (getBody().clientHeight - 2) + 'px'; document.body.appendChild(this.V); windowExzIndex+=2; this.V.style.zIndex = windowExzIndex-1; hideControl(this.V); }, drawWindow: function(){ 
this.W = document.createElement('div'); this.W.className = "windowEx"; 
this.W.style.width = this.config.width + "px"; this.W.style.height = this.config.height + "px"; 
document.body.appendChild(this.W); 
this.IM = document.createElement('IFRAME'); this.IM.setAttribute("frameborder","0"); document.body.appendChild(this.IM); this.IM.style.position = "absolute"; 
windowExzIndex+=2; this.W.style.zIndex = windowExzIndex; this.wed = document.createElement('div'); this.wed.className = "windowEx-title"; 
var htmlTitle = '<span style="width:10px;height:10px;padding-left:2px"></span><span style="padding:2px">' + this.config.title +'</span>'; htmlTitle += '<div class="windowEx-controls"><img src="' + getAbsolutePath('Images/windowEx/img/w-min.gif') + '" title="Minimize" />'; htmlTitle += '<img src="' + getAbsolutePath('Images/windowEx/img/w-max.gif') + '" title="Maximize" />'; htmlTitle += '<img src="' + getAbsolutePath('Images/windowEx/img/w-close.gif') + '" title="Close"/></div></div>'; this.wed.innerHTML = htmlTitle; this.wc = document.createElement('div'); this.wc.className = 'windowEx-content'; this.wc.style.height = (this.config.height - 30) + "px"; this.wc.innerHTML = this.config.content; 
this.ws = document.createElement('div'); this.ws.className = 'windowEx-status'; this.ws.innerHTML = '<div class="windowEx-resize">&nbsp;</div>'; 
this.W.appendChild(this.wed); this.W.appendChild(this.wc); this.W.appendChild(this.ws); 
var scope = this; 
this.W.onmousedown = function() { scope.setfocus() }
this.wed.onclick = function(e) { scope.controls_click(e); }
this.wed.onmousedown = function(e){ scope.drag(e); }
this.wed.onmouseup = function() { scope.stop(); }
if(this.config.resize) { this.ws.onmousedown = function(e) { scope.drag_resize(e); }
}
this.ws.onmouseup = function() { scope.stop(); }
this.showControl(); hideControl(this.W); hideControl(this.IM); }, drag: function(e){ var e = window.event || e; this.iMX = e.clientX; this.iMY = e.clientY; 
this.iX = parseInt(this.W.offsetLeft); this.iY = parseInt(this.W.offsetTop); 
this.width = parseInt(this.W.offsetWidth); this.contentHeight = parseInt(this.wc.offsetHeight); 
var scope = this; document.onmousemove = function(e){scope.move(e);}
}, move: function(e){ var e = window.event || e; this.distanceX = e.clientX - this.iMX; this.distanceY = e.clientY - this.iMY; 
this.W.style.position = "absolute"; this.W.style.left = this.distanceX + this.iX + "px"; this.W.style.top = this.distanceY + this.iY + "px"; this.W.className = "windowEx"; this.setTwodimension(this.W, this.IM); }, drag_resize: function(e){ var e = window.event || e; this.iMX = e.clientX; this.iMY = e.clientY; 
this.iX = parseInt(this.W.offsetLeft); this.iY = parseInt(this.W.offsetTop); 
this.width = parseInt(this.W.offsetWidth); this.contentHeight = parseInt(this.wc.offsetHeight); var scope = this; document.onmousemove = function(e){scope.resize(e);}
}, resize: function(e){ var e = window.event || e; this.distanceX = e.clientX - this.iMX; this.distanceY = e.clientY - this.iMY; this.W.style.width= Math.max(this.width + this.distanceX, this.config.title.length*11) + "px"; this.wc.style.height= Math.max(this.contentHeight + this.distanceY,50) + "px"; this.W.className = "windowEx"; this.setTwodimension(this.W, this.IM); }, controls_click:function(e){ var controls = window.event? window.event.srcElement : e.target; if (/Minimize/i.test(controls.getAttribute("title"))) this.minimize(); else if (/Restore/i.test(controls.getAttribute("title"))) this.restore(controls); else if (/Maximize/i.test(controls.getAttribute("title"))) this.maximize(controls); else if (/Close/i.test(controls.getAttribute("title"))) this.close(); return false; }, stop: function(){ document.onmousemove = null; document.onmouseup = null; }, setfocus: function(){ windowExzIndex+=2; this.W.style.zIndex = windowExzIndex; this.W.focus(); }, minimize: function(){ }, maximize: function(controls){ this.beforeX = parseInt(this.W.offsetLeft); this.beforeY = parseInt(this.W.offsetTop); this.beforeWidth = parseInt(this.W.offsetWidth); this.beforeContentHeight = parseInt(this.wc.offsetHeight); this.W.style.top = 0 + 'px'; this.W.style.left = 0 + 'px'; this.W.style.width = (getBody().clientWidth - 3) + 'px'; this.wc.style.height = (getBody().clientHeight - this.wed.offsetHeight - this.ws.offsetHeight - 3) + 'px'; 
controls.setAttribute("title","Restore"); this.setTwodimension(this.W, this.IM); }, restore:function(controls){ this.W.style.left = this.beforeX + 'px'; this.W.style.top = this.beforeY + 'px'; this.W.style.width = this.beforeWidth + 'px'; this.wc.style.height = this.beforeContentHeight +'px'; controls.setAttribute("title","Maximize"); this.setTwodimension(this.W, this.IM); }, showControl: function(){ var controls = this.wed.getElementsByTagName('IMG'); for(var i=0; i<controls.length; i++) { if(!this.config.minimize && /Minimize/i.test(controls[i].getAttribute("title"))) destroyControl(controls[i]); if(!this.config.maximize && /Maximize/i.test(controls[i].getAttribute("title"))) destroyControl(controls[i]); }
}, show: function(){ showControl(this.W); showControl(this.IM); this.W.focus(); this.setPositionCenter(); if(this.config.modal) showControl(this.V); }, setPositionCenter: function(){ var mvtop = (getBody().clientHeight - this.W.offsetHeight)/2; var mvleft = (getBody().clientWidth - this.W.offsetWidth)/2; 
this.W.style.position = 'absolute'; this.W.style.top = mvtop + getBody().scrollTop + 'px'; this.W.style.left = mvleft + getBody().scrollLeft + 'px'; 
this.setTwodimension(this.W, this.IM); }, setPosition: function(pos){ this.W.style.top = pos.top + 'px'; this.W.style.left = pos.left + 'px'; this.setTwodimension(this.W, this.IM); }, setTwodimension: function(t,d) { d.style.width = t.offsetWidth - 3 + 'px'; d.style.height = t.offsetHeight + 'px'; d.style.top = t.style.top; d.style.left = t.style.left; d.style.zIndex = t.style.zIndex - 1; }, close: function(){ destroyControl(this.W); destroyControl(this.IM); if(this.config.modal) destroyControl(this.V); this.cleanup(); }, cleanup: function(){ this.W = null; this.wed = null; this.wc = null; this.ws = null; this.IM = null; this.V = null; this.iMX = null; this.iMY = null; this.iX = null; this.iY = null; this.width = null; this.contentHeight = null; 
this.beforeX = null; this.beforeY = null; this.beforeWidth = null; this.beforeContentHeight = null; }
}
