(function() { var _drag_drop = new DragDrop(); var _xtools; var index = 10000; var _all_windows = []; function _load(pId) { if ( !(top.document.getElementById(pId + '__window_master')) ) { var xml = _xtools.xml('window'); var name = xml.createElement('name'); name.appendChild(xml.createTextNode(pId)); xml.documentElement.appendChild(name); var _window = top.document.createElement("div"); _window.innerHTML = _xtools.parse(xml, 'window.xsl'); _window.setAttribute('id', pId + '__window_master'); _window.setAttribute('class', 'window'); _window.setAttribute('className', 'window'); _window = this._TARGET.appendChild(_window); _focus(_window); function _click(e) { _focus(e); _window.oncontextmenu = new Function("return false"); return false; } _config(_window, 'onmousedown', _click); _drag_drop.drag(_window); _window.childNodes[1].setAttribute('dragdrop_child','true'); _window.childNodes[1].childNodes[0].setAttribute('dragdrop_child','true'); _window.childNodes[1].childNodes[1].setAttribute('dragdrop_child','true'); _config(_window.childNodes[1].childNodes[2].childNodes[0], 'onclick', _button); _config(_window.childNodes[1].childNodes[2].childNodes[1], 'onclick', _button); _config(_window.childNodes[1].childNodes[2].childNodes[2], 'onclick', _button); _all_windows[pId + '__window_master'] = { 'id' : pId, 'wm' : _window, // wm - window master 'ic' : _window.childNodes[1].firstChild, // wt - window title 'wt' : _window.childNodes[1].childNodes[1], // wt - window title 'bc' : _window.childNodes[1].childNodes[2].childNodes[0], // bc - button close 'bx' : _window.childNodes[1].childNodes[2].childNodes[1], // bx - button maximize 'bz' : _window.childNodes[1].childNodes[2].childNodes[2], // bz - button minimize 'wc' : _window.childNodes[2].firstChild, // wc - window content 'wf' : _window.childNodes[3], // wf - window footer 'button' : _button, 'content' : _content, 'close' : function() { _button(_window.childNodes[1].childNodes[2].childNodes[0]); }, 'focus' : _focus, 'hidden' : function() { _button(_window.childNodes[1].childNodes[2].childNodes[2]); }, 'icon' : _icon, 'loading' : function() { var _information = top.document.createElement('span'); _information.appendChild( top.document.createTextNode(imGetLang('Loading')) ); var _loading = top.document.createElement('div'); _loading.className = 'loading'; _loading.appendChild(_information); _content.call(this, _loading); }, 'position' : _position, 'show' : function() { _window.style.display = 'block'; }, 'size' : _size, 'title' : _title }; } return _all_windows[pId + '__window_master']; } function _browser() { var _width = 0, _height = 0; if ( typeof( window.innerWidth ) == 'number' ) { //Non-IE _width = top.window.innerWidth; _height = top.window.innerHeight; } else if ( top.document.documentElement && ( top.document.documentElement.clientWidth || top.document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' _width = top.document.documentElement.clientWidth; _height = top.document.documentElement.clientHeight; } else if( top.document.body && ( top.document.body.clientWidth || top.document.body.clientHeight ) ) { //IE 4 compatible _width = top.document.body.clientWidth; _height = top.document.body.clientHeight; } return {'width' : _width, 'height' : _height} } function _button() { var b = arguments[0]; b = ( !b.type ) ? b : ( b.target ) ? b.target : b.srcElement; var w = b.parentNode.parentNode.parentNode; switch ( b.title ) { case 'close' : w.parentNode.removeChild(w); delete _all_windows[w.id]; break; case 'minimize' : w.style.display = 'none'; break; case 'maximize' : if ( !w.getAttribute('wParams') ) { var _wParams = (parseFloat(w.style.width) - 13); _wParams += ':' + parseFloat(w.childNodes[2].firstChild.style.maxHeight); _wParams += ':' + parseFloat(w.style.left); _wParams += ':' + parseFloat(w.style.right); _wParams += ':' + parseFloat(w.style.top); _wParams += ':' + parseFloat(w.style.bottom); w.setAttribute('wParams', _wParams); var _bwr = _browser(); w.style.top = "0px"; w.style.left = "0px"; w.style.height = "100%"; w.style.width = "100%"; var _style = w.childNodes[2].firstChild.getAttribute('style'); if ( typeof _style == 'object' && _style.cssText ) _style = _style.cssText; if ( w.childNodes[2].firstChild.style.cssText ) w.childNodes[2].firstChild.style.cssText = ''; _style = _style.replace(/max-height: ?\d+;?/i, ''); w.childNodes[2].firstChild.setAttribute('style', _style); w.childNodes[2].firstChild.style.height = (_bwr.height - 41) + "px"; } else { var _wParams = w.getAttribute('wParams').split(':'); w.removeAttribute('wParams'); var _style = w.getAttribute('style'); if ( typeof _style == 'object' && _style.cssText ) _style = _style.cssText; _style = _style.replace(/height: ?100%;?/i, '').replace(/width: ?100%;?/i, ''); _style = _style.replace(/left: ?0px;?/i, '').replace(/top: ?0px;?/i, ''); // for IE if ( w.style.cssText ) w.style.cssText = ''; w.setAttribute('style', _style); w = _all_windows[w.id]; _style = w.wc.getAttribute('style'); if ( typeof _style == 'object' && _style.cssText ) _style = _style.cssText; _style = _style.replace(/height: ?\d+px;?/i, ''); // for IE if ( w.wc.style.cssText ) w.wc.style.cssText = ''; w.wc.setAttribute('style', _style); w.size(parseFloat(_wParams[0]), parseFloat(_wParams[1])); var x = ''; var _right = false; if ( !isNaN(_wParams[2]) ) x = parseFloat(_wParams[2]); else if ( !isNaN(_wParams[3]) ) { x = parseFloat(_wParams[3]); _right = true; } var y = ''; var _bottom = false; if ( !isNaN(_wParams[4]) ) y = parseFloat(_wParams[4]); else if ( !isNaN(_wParams[5]) ) { y = parseFloat(_wParams[5]); _bottom = true; } w.position(x, y, _right, _bottom); } break; } } function _config(pObj, pEvent, pHandler) { if ( typeof pObj == 'object' ) { if ( pEvent.substring(0, 2) == 'on' ) pEvent = pEvent.substring(2, pEvent.length); if ( pObj.addEventListener ) pObj.addEventListener(pEvent, pHandler, false); else if ( pObj.attachEvent ) pObj.attachEvent('on' + pEvent, pHandler); } } function _content() { var _content = this.wc; while ( _content.hasChildNodes() ) _content.removeChild(_content.firstChild); var l = arguments.length; for ( var i = 0; i < l; i++ ) if ( typeof arguments[i] == 'object' ) _content.appendChild(arguments[i]); else if ( typeof arguments[i] == 'string' ) _content.innerHTML += arguments[i]; } function _focus() { var w; if ( arguments.length ) w = arguments[0]; else w = this.wm; w = ( !w.type ) ? w : ( w.target ) ? w.target : w.srcElement; while ( w.id.indexOf('__window_master') == -1 ) w = w.parentNode; index += 10; w.style.zIndex = index; } function _get(_pId) { var _win = false; if ( _all_windows[_pId + '__window_master'] ) _win = _all_windows[_pId + '__window_master']; return _win; } function _icon(_pIcon) { if ( typeof _pIcon == 'string' ) this.ic.style.backgroundImage = 'url(' + _pIcon + ')'; } function _position(pX, pY) { // for IE //if ( window.ActiveXObject ) // this.wm.style.position = 'absolute'; if ( typeof pX == 'number' ) if ( arguments[2] === true ) this.wm.style.right = pX + 'px'; else this.wm.style.left = pX + 'px'; if ( typeof pY == 'number' ) if ( arguments[3] === true ) this.wm.style.bottom = pY + 'px'; else this.wm.style.top = pY + 'px'; } function _size(pWidth, pHeight) { if ( typeof pWidth == 'number' && !isNaN(pWidth) ) this.wm.style.width = (13 + pWidth) + 'px'; if ( typeof pHeight == 'number' && !isNaN(pHeight) ) this.wc.style.maxHeight = pHeight + 'px'; } function _title(pTitle) { var _title = this.wt; while ( _title.hasChildNodes() ) _title.removeChild(_title.firstChild); _title.appendChild(top.document.createTextNode(pTitle)); } function Windows() { var _argv = arguments; var _argc = _argv.length; if ( (_argv[_argc - 1] != null) && (_argv[_argc - 1]).id ) this._TARGET = _argv[_argc - 1]; else this._TARGET = top.document.body; _xtools = arguments[0]; } Windows.prototype.load = _load; Windows.prototype.get = _get; window.Windows = Windows; } )();