PageSourceSearch

https://calefatorgold.com.br/js/prototype/window.js

js calefatorgold.com.br collected 2026-10-06 13:16:08 UTC 65,752 bytes, 1,871 lines download raw bytes

1// Copyright (c) 2006 Sébastien Gruhier (http://xilinus.com, http://itseb.com)
2// 
3// Permission is hereby granted, free of charge, to any person obtaining
4// a copy of this software and associated documentation files (the
5// "Software"), to deal in the Software without restriction, including
6// without limitation the rights to use, copy, modify, merge, publish,
7// distribute, sublicense, and/or sell copies of the Software, and to
8// permit persons to whom the Software is furnished to do so, subject to
9// the following conditions:
10// 
11// The above copyright notice and this permission notice shall be
12// included in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21//
22// VERSION 1.3
23
24var Window = Class.create();
25
26Window.keepMultiModalWindow = false;
27Window.hasEffectLib = (typeof Effect != 'undefined');
28Window.resizeEffectDuration = 0.4;
29
30Window.prototype = {
31  // Constructor
32  // Available parameters : className, blurClassName, title, minWidth, minHeight, maxWidth, maxHeight, width, height, top, left, bottom, right, resizable, zIndex, opacity, recenterAuto, wiredDrag
33  //                        hideEffect, showEffect, showEffectOptions, hideEffectOptions, effectOptions, url, draggable, closable, minimizable, maximizable, parent, onload
34  //                        add all callbacks (if you do not use an observer)
35  //                        onDestroy onStartResize onStartMove onResize onMove onEndResize onEndMove onFocus onBlur onBeforeShow onShow onHide onMinimize onMaximize onClose
36  
37  initialize: function() {
38    var id;
39    var optionIndex = 0;
40    // For backward compatibility like win= new Window("id", {...}) instead of win = new Window({id: "id", ...})
41    if (arguments.length > 0) {
42      if (typeof arguments[0] == "string" ) {
43        id = arguments[0];
44        optionIndex = 1;
45      }
46      else
47        id = arguments[0] ? arguments[0].id : null;
48    }
49    
50    // Generate unique ID if not specified
51    if (!id)
52      id = "window_" + new Date().getTime();
53      
54    if ($(id))
55      alert("Window " + id + " is already registered in the DOM! Make sure you use setDestroyOnClose() or destroyOnClose: true in the constructor");
56
57    this.options = Object.extend({
58      className:         "dialog",
59      windowClassName:   null,
60      blurClassName:     null,
61      minWidth:          100, 
62      minHeight:         20,
63      resizable:         true,
64      closable:          true,
65      minimizable:       true,
66      maximizable:       true,
67      draggable:         true,
68      userData:          null,
69      showEffect:        (Window.hasEffectLib ? Effect.Appear : Element.show),
70      hideEffect:        (Window.hasEffectLib ? Effect.Fade : Element.hide),
71      showEffectOptions: {},
72      hideEffectOptions: {},
73      effectOptions:     null,
74      parent:            document.body,
75      title:             " ",
76      url:               null,
77      onload:            Prototype.emptyFunction,
78      width:             200,
79      height:            300,
80      opacity:           1,
81      recenterAuto:      true,
82      wiredDrag:         false,
83      closeOnEsc:        true,
84      closeCallback:     null,
85      destroyOnClose:    false,
86      gridX:             1, 
87      gridY:             1      
88    }, arguments[optionIndex] || {});
89    if (this.options.blurClassName)
90      this.options.focusClassName = this.options.className;
91      
92    if (typeof this.options.top == "undefined" &&  typeof this.options.bottom ==  "undefined") 
93      this.options.top = this._round(Math.random()*500, this.options.gridY);
94    if (typeof this.options.left == "undefined" &&  typeof this.options.right ==  "undefined") 
95      this.options.left = this._round(Math.random()*500, this.options.gridX);
96
97    if (this.options.effectOptions) {
98      Object.extend(this.options.hideEffectOptions, this.options.effectOptions);
99      Object.extend(this.options.showEffectOptions, this.options.effectOptions);
100      if (this.options.showEffect == Element.Appear)
101        this.options.showEffectOptions.to = this.options.opacity;
102    }
103    if (Window.hasEffectLib) {
104      if (this.options.showEffect == Effect.Appear)
105        this.options.showEffectOptions.to = this.options.opacity;
106    
107      if (this.options.hideEffect == Effect.Fade)
108        this.options.hideEffectOptions.from = this.options.opacity;
109    }
110    if (this.options.hideEffect == Element.hide)
111      this.options.hideEffect = function(){ Element.hide(this.element); if (this.options.destroyOnClose) this.destroy(); }.bind(this)
112    
113    if (this.options.parent != document.body)  
114      this.options.parent = $(this.options.parent);
115      
116    this.element = this._createWindow(id);       
117    this.element.win = this;
118    
119    // Bind event listener
120    this.eventMouseDown = this._initDrag.bindAsEventListener(this);
121    this.eventMouseUp   = this._endDrag.bindAsEventListener(this);
122    this.eventMouseMove = this._updateDrag.bindAsEventListener(this);
123    this.eventOnLoad    = this._getWindowBorderSize.bindAsEventListener(this);
124    this.eventMouseDownContent = this.toFront.bindAsEventListener(this);
125    this.eventResize = this._recenter.bindAsEventListener(this);
126    this.eventKeyUp = this._keyUp.bindAsEventListener(this);
127 
128    this.topbar = $(this.element.id + "_top");
129    this.bottombar = $(this.element.id + "_bottom");
130    this.content = $(this.element.id + "_content");
131    
132    Event.observe(this.topbar, "mousedown", this.eventMouseDown);
133    Event.observe(this.bottombar, "mousedown", this.eventMouseDown);
134    Event.observe(this.content, "mousedown", this.eventMouseDownContent);
135    Event.observe(window, "load", this.eventOnLoad);
136    Event.observe(window, "resize", this.eventResize);
137    Event.observe(window, "scroll", this.eventResize);
138    Event.observe(document, "keyup", this.eventKeyUp);
139    Event.observe(this.options.parent, "scroll", this.eventResize);
140    
141    if (this.options.draggable)  {
142      var that = this;
143      [this.topbar, this.topbar.up().previous(), this.topbar.up().next()].each(function(element) {
144        element.observe("mousedown", that.eventMouseDown);
145        element.addClassName("top_draggable");
146      });
147      [this.bottombar.up(), this.bottombar.up().previous(), this.bottombar.up().next()].each(function(element) {
148        element.observe("mousedown", that.eventMouseDown);
149        element.addClassName("bottom_draggable");
150      });
151      
152    }    
153    
154    if (this.options.resizable) {
155      this.sizer = $(this.element.id + "_sizer");
156      Event.observe(this.sizer, "mousedown", this.eventMouseDown);
157    }  
158    
159    this.useLeft = null;
160    this.useTop = null;
161    if (typeof this.options.left != "undefined") {
162      this.element.setStyle({left: parseFloat(this.options.left) + 'px'});
163      this.useLeft = true;
164    }
165    else {
166      this.element.setStyle({right: parseFloat(this.options.right) + 'px'});
167      this.useLeft = false;
168    }
169    
170    if (typeof this.options.top != "undefined") {
171      this.element.setStyle({top: parseFloat(this.options.top) + 'px'});
172      this.useTop = true;
173    }
174    else {
175      this.element.setStyle({bottom: parseFloat(this.options.bottom) + 'px'});      
176      this.useTop = false;
177    }
178      
179    this.storedLocation = null;
180    
181    this.setOpacity(this.options.opacity);
182    if (this.options.zIndex)
183      this.setZIndex(this.options.zIndex)
184
185    if (this.options.destroyOnClose)
186      this.setDestroyOnClose(true);
187
188    this._getWindowBorderSize();
189    this.width = this.options.width;
190    this.height = this.options.height;
191    this.visible = false;
192    
193    this.constraint = false;
194    this.constraintPad = {top: 0, left:0, bottom:0, right:0};
195    
196    if (this.width && this.height)
197      this.setSize(this.options.width, this.options.height);
198    this.setTitle(this.options.title)
199    Windows.register(this);      
200  },
201  
202  // Destructor
203  destroy: function() {
204    this._notify("onDestroy");
205    Event.stopObserving(this.topbar, "mousedown", this.eventMouseDown);
206    Event.stopObserving(this.bottombar, "mousedown", this.eventMouseDown);
207    Event.stopObserving(this.content, "mousedown", this.eventMouseDownContent);
208    
209    Event.stopObserving(window, "load", this.eventOnLoad);
210    Event.stopObserving(window, "resize", this.eventResize);
211    Event.stopObserving(window, "scroll", this.eventResize);
212    
213    Event.stopObserving(this.content, "load", this.options.onload);
214    Event.stopObserving(document, "keyup", this.eventKeyUp);
215
216    if (this._oldParent) {
217      var content = this.getContent();
218      var originalContent = null;
219      for(var i = 0; i < content.childNodes.length; i++) {
220        originalContent = content.childNodes[i];
221        if (originalContent.nodeType == 1) 
222          break;
223        originalContent = null;
224      }
225      if (originalContent)
226        this._oldParent.appendChild(originalContent);
227      this._oldParent = null;
228    }
229
230    if (this.sizer)
231        Event.stopObserving(this.sizer, "mousedown", this.eventMouseDown);
232
233    if (this.options.url) 
234      this.content.src = null
235
236     if(this.iefix) 
237      Element.remove(this.iefix);
238
239    Element.remove(this.element);
240    Windows.unregister(this);      
241  },
242    
243  // Sets close callback, if it sets, it should return true to be able to close the window.
244  setCloseCallback: function(callback) {
245    this.options.closeCallback = callback;
246  },
247  
248  // Gets window content
249  getContent: function () {
250    return this.content;
251  },
252  
253  // Sets the content with an element id
254  setContent: function(id, autoresize, autoposition) {
255    var element = $(id);
256    if (null == element) throw "Unable to find element '" + id + "' in DOM";
257    this._oldParent = element.parentNode;
258
259    var d = null;
260    var p = null;
261
262    if (autoresize) 
263      d = Element.getDimensions(element);
264    if (autoposition) 
265      p = Position.cumulativeOffset(element);
266
267    var content = this.getContent();
268    // Clear HTML (and even iframe)
269    this.setHTMLContent("");
270    content = this.getContent();
271    
272    content.appendChild(element);
273    element.show();
274    if (autoresize) 
275      this.setSize(d.width, d.height);
276    if (autoposition) 
277      this.setLocation(p[1] - this.heightN, p[0] - this.widthW);    
278  },
279  
280  setHTMLContent: function(html) {
281    // It was an url (iframe), recreate a div content instead of iframe content
282    if (this.options.url) {
283      this.content.src = null;
284      this.options.url = null;
285      
286  	  var content ="<div id=\"" + this.getId() + "_content\" class=\"" + this.options.className + "_content\"> </div>";
287      $(this.getId() +"_table_content").innerHTML = content;
288      
289      this.content = $(this.element.id + "_content");
290    }
291      
292    this.getContent().innerHTML = html;
293  },
294  
295  setAjaxContent: function(url, options, showCentered, showModal) {
296    this.showFunction = showCentered ? "showCenter" : "show";
297    this.showModal = showModal || false;
298  
299    options = options || {};
300
301    // Clear HTML (and even iframe)
302    this.setHTMLContent("");
303 
304    this.onComplete = options.onComplete;
305    if (! this._onCompleteHandler)
306      this._onCompleteHandler = this._setAjaxContent.bind(this);
307    options.onComplete = this._onCompleteHandler;
308
309    new Ajax.Request(url, options);    
310    options.onComplete = this.onComplete;
311  },
312  
313  _setAjaxContent: function(originalRequest) {
314    Element.update(this.getContent(), originalRequest.responseText);
315    if (this.onComplete)
316      this.onComplete(originalRequest);
317    this.onComplete = null;
318    this[this.showFunction](this.showModal)
319  },
320  
321  setURL: function(url) {
322    // Not an url content, change div to iframe
323    if (this.options.url) 
324      this.content.src = null;
325    this.options.url = url;
326    var content= "<iframe frameborder='0' name='" + this.getId() + "_content'  id='" + this.getId() + "_content' src='" + url + "' width='" + this.width + "' height='" + this.height + "'> </iframe>";
327    $(this.getId() +"_table_content").innerHTML = content;
328    
329    this.content = $(this.element.id + "_content");
330  },
331
332  getURL: function() {
333  	return this.options.url ? this.options.url : null;
334  },
335
336  refresh: function() {
337    if (this.options.url)
338	    $(this.element.getAttribute('id') + '_content').src = this.options.url;
339  },
340  
341  // Stores position/size in a cookie, by default named with window id
342  setCookie: function(name, expires, path, domain, secure) {
343    name = name || this.element.id;
344    this.cookie = [name, expires, path, domain, secure];
345    
346    // Get cookie
347    var value = WindowUtilities.getCookie(name)
348    // If exists
349    if (value) {
350      var values = value.split(',');
351      var x = values[0].split(':');
352      var y = values[1].split(':');
353
354      var w = parseFloat(values[2]), h = parseFloat(values[3]);
355      var mini = values[4];
356      var maxi = values[5];
357
358      this.setSize(w, h);
359      if (mini == "true")
360        this.doMinimize = true; // Minimize will be done at onload window event
361      else if (maxi == "true")
362        this.doMaximize = true; // Maximize will be done at onload window event
363
364      this.useLeft = x[0] == "l";
365      this.useTop = y[0] == "t";
366
367      this.element.setStyle(this.useLeft ? {left: x[1]} : {right: x[1]});
368      this.element.setStyle(this.useTop ? {top: y[1]} : {bottom: y[1]});
369    }
370  },
371  
372  // Gets window ID
373  getId: function() {
374    return this.element.id;
375  },
376  
377  // Detroys itself when closing 
378  setDestroyOnClose: function() {
379    this.options.destroyOnClose = true;
380  },
381  
382  setConstraint: function(bool, padding) {
383    this.constraint = bool;
384    this.constraintPad = Object.extend(this.constraintPad, padding || {});
385    // Reset location to apply constraint
386    if (this.useTop && this.useLeft)
387      this.setLocation(parseFloat(this.element.style.top), parseFloat(this.element.style.left));
388  },
389  
390  // initDrag event
391
392  _initDrag: function(event) {
393    // No resize on minimized window
394    if (Event.element(event) == this.sizer && this.isMinimized())
395      return;
396
397    // No move on maximzed window
398    if (Event.element(event) != this.sizer && this.isMaximized())
399      return;
400      
401    if (Prototype.Browser.IE && this.heightN == 0)
402      this._getWindowBorderSize();
403    
404    // Get pointer X,Y
405    this.pointer = [this._round(Event.pointerX(event), this.options.gridX), this._round(Event.pointerY(event), this.options.gridY)];
406    if (this.options.wiredDrag) 
407      this.currentDrag = this._createWiredElement();
408    else
409      this.currentDrag = this.element;
410      
411    // Resize
412    if (Event.element(event) == this.sizer) {
413      this.doResize = true;
414      this.widthOrg = this.width;
415      this.heightOrg = this.height;
416      this.bottomOrg = parseFloat(this.element.getStyle('bottom'));
417      this.rightOrg = parseFloat(this.element.getStyle('right'));
418      this._notify("onStartResize");
419    }
420    else {
421      this.doResize = false;
422
423      // Check if click on close button, 
424      var closeButton = $(this.getId() + '_close');
425      if (closeButton && Position.within(closeButton, this.pointer[0], this.pointer[1])) {
426        this.currentDrag = null;
427        return;
428      }
429
430      this.toFront();
431
432      if (! this.options.draggable) 
433        return;
434      this._notify("onStartMove");
435    }    
436    // Register global event to capture mouseUp and mouseMove
437    Event.observe(document, "mouseup", this.eventMouseUp, false);
438    Event.observe(document, "mousemove", this.eventMouseMove, false);
439    
440    // Add an invisible div to keep catching mouse event over iframes
441    WindowUtilities.disableScreen('__invisible__', '__invisible__', this.overlayOpacity);
442
443    // Stop selection while dragging
444    document.body.ondrag = function () { return false; };
445    document.body.onselectstart = function () { return false; };
446    
447    this.currentDrag.show();
448    Event.stop(event);
449  },
450  
451  _round: function(val, round) {
452    return round == 1 ? val  : val = Math.floor(val / round) * round;
453  },
454
455  // updateDrag event
456  _updateDrag: function(event) {
457    var pointer =  [this._round(Event.pointerX(event), this.options.gridX), this._round(Event.pointerY(event), this.options.gridY)];  
458    var dx = pointer[0] - this.pointer[0];
459    var dy = pointer[1] - this.pointer[1];
460    
461    // Resize case, update width/height
462    if (this.doResize) {
463      var w = this.widthOrg + dx;
464      var h = this.heightOrg + dy;
465      
466      dx = this.width - this.widthOrg
467      dy = this.height - this.heightOrg
468      
469      // Check if it's a right position, update it to keep upper-left corner at the same position
470      if (this.useLeft) 
471        w = this._updateWidthConstraint(w)
472      else 
473        this.currentDrag.setStyle({right: (this.rightOrg -dx) + 'px'});
474      // Check if it's a bottom position, update it to keep upper-left corner at the same position
475      if (this.useTop) 
476        h = this._updateHeightConstraint(h)
477      else
478        this.currentDrag.setStyle({bottom: (this.bottomOrg -dy) + 'px'});
479        
480      this.setSize(w , h);
481      this._notify("onResize");
482    }
483    // Move case, update top/left
484    else {
485      this.pointer = pointer;
486      
487      if (this.useLeft) {
488        var left =  parseFloat(this.currentDrag.getStyle('left')) + dx;
489        var newLeft = this._updateLeftConstraint(left);
490        // Keep mouse pointer correct
491        this.pointer[0] += newLeft-left;
492        this.currentDrag.setStyle({left: newLeft + 'px'});
493      }
494      else 
495        this.currentDrag.setStyle({right: parseFloat(this.currentDrag.getStyle('right')) - dx + 'px'});
496      
497      if (this.useTop) {
498        var top =  parseFloat(this.currentDrag.getStyle('top')) + dy;
499        var newTop = this._updateTopConstraint(top);
500        // Keep mouse pointer correct
501        this.pointer[1] += newTop - top;
502        this.currentDrag.setStyle({top: newTop + 'px'});
503      }
504      else 
505        this.currentDrag.setStyle({bottom: parseFloat(this.currentDrag.getStyle('bottom')) - dy + 'px'});
506
507      this._notify("onMove");
508    }
509    if (this.iefix) 
510      this._fixIEOverlapping(); 
511      
512    this._removeStoreLocation();
513    Event.stop(event);
514  },
515
516   // endDrag callback
517   _endDrag: function(event) {
518    // Remove temporary div over iframes
519     WindowUtilities.enableScreen('__invisible__');
520    
521    if (this.doResize)
522      this._notify("onEndResize");
523    else
524      this._notify("onEndMove");
525    
526    // Release event observing
527    Event.stopObserving(document, "mouseup", this.eventMouseUp,false);
528    Event.stopObserving(document, "mousemove", this.eventMouseMove, false);
529
530    Event.stop(event);
531    
532    this._hideWiredElement();
533
534    // Store new location/size if need be
535    this._saveCookie()
536      
537    // Restore selection
538    document.body.ondrag = null;
539    document.body.onselectstart = null;
540  },
541
542  _updateLeftConstraint: function(left) {
543    if (this.constraint && this.useLeft && this.useTop) {
544      var width = this.options.parent == document.body ? WindowUtilities.getPageSize().windowWidth : this.options.parent.getDimensions().width;
545
546      if (left < this.constraintPad.left)
547        left = this.constraintPad.left;
548      if (left + this.width + this.widthE + this.widthW > width - this.constraintPad.right) 
549        left = width - this.constraintPad.right - this.width - this.widthE - this.widthW;
550    }
551    return left;
552  },
553  
554  _updateTopConstraint: function(top) {
555    if (this.constraint && this.useLeft && this.useTop) {        
556      var height = this.options.parent == document.body ? WindowUtilities.getPageSize().windowHeight : this.options.parent.getDimensions().height;
557      
558      var h = this.height + this.heightN + this.heightS;
559
560      if (top < this.constraintPad.top)
561        top = this.constraintPad.top;
562      if (top + h > height - this.constraintPad.bottom) 
563        top = height - this.constraintPad.bottom - h;
564    }
565    return top;
566  },
567  
568  _updateWidthConstraint: function(w) {
569    if (this.constraint && this.useLeft && this.useTop) {
570      var width = this.options.parent == document.body ? WindowUtilities.getPageSize().windowWidth : this.options.parent.getDimensions().width;
571      var left =  parseFloat(this.element.getStyle("left"));
572
573      if (left + w + this.widthE + this.widthW > width - this.constraintPad.right) 
574        w = width - this.constraintPad.right - left - this.widthE - this.widthW;
575    }
576    return w;
577  },
578  
579  _updateHeightConstraint: function(h) {
580    if (this.constraint && this.useLeft && this.useTop) {
581      var height = this.options.parent == document.body ? WindowUtilities.getPageSize().windowHeight : this.options.parent.getDimensions().height;
582      var top =  parseFloat(this.element.getStyle("top"));
583
584      if (top + h + this.heightN + this.heightS > height - this.constraintPad.bottom) 
585        h = height - this.constraintPad.bottom - top - this.heightN - this.heightS;
586    }
587    return h;
588  },
589  
590  
591  // Creates HTML window code
592  _createWindow: function(id) {
593    var className = this.options.className;
594    var win = document.createElement("div");
595    win.setAttribute('id', id);
596    win.className = "dialog";
597    if (this.options.windowClassName) {
598      win.className += ' ' + this.options.windowClassName;
599    }
600
601    var content;
602    if (this.options.url)
603      content= "<iframe frameborder=\"0\" name=\"" + id + "_content\"  id=\"" + id + "_content\" src=\"" + this.options.url + "\"> </iframe>";
604    else
605      content ="<div id=\"" + id + "_content\" class=\"" +className + "_content\"> </div>";
606
607    var closeDiv = this.options.closable ? "<div class='"+ className +"_close' id='"+ id +"_close' onclick='Windows.close(\""+ id +"\", event)'> </div>" : "";
608    var minDiv = this.options.minimizable ? "<div class='"+ className + "_minimize' id='"+ id +"_minimize' onclick='Windows.minimize(\""+ id +"\", event)'> </div>" : "";
609    var maxDiv = this.options.maximizable ? "<div class='"+ className + "_maximize' id='"+ id +"_maximize' onclick='Windows.maximize(\""+ id +"\", event)'> </div>" : "";
610    var seAttributes = this.options.resizable ? "class='" + className + "_sizer' id='" + id + "_sizer'" : "class='"  + className + "_se'";
611    var blank = "../themes/default/blank.gif";
612    
613    win.innerHTML = closeDiv + minDiv + maxDiv + "\
614      <a href='#' id='"+ id +"_focus_anchor'><!-- --></a>\
615      <table id='"+ id +"_row1' class=\"top table_window\">\
616        <tr>\
617          <td class='"+ className +"_nw'></td>\
618          <td class='"+ className +"_n'><div id='"+ id +"_top' class='"+ className +"_title title_window'>"+ this.options.title +"</div></td>\
619          <td class='"+ className +"_ne'></td>\
620        </tr>\
621      </table>\
622      <table id='"+ id +"_row2' class=\"mid table_window\">\
623        <tr>\
624          <td class='"+ className +"_w'></td>\
625            <td id='"+ id +"_table_content' class='"+ className +"_content' valign='top'>" + content + "</td>\
626          <td class='"+ className +"_e'></td>\
627        </tr>\
628      </table>\
629        <table id='"+ id +"_row3' class=\"bot table_window\">\
630        <tr>\
631          <td class='"+ className +"_sw'></td>\
632            <td class='"+ className +"_s'><div id='"+ id +"_bottom' class='status_bar'><span style='float:left; width:1px; height:1px'></span></div></td>\
633            <td " + seAttributes + "></td>\
634        </tr>\
635      </table>\
636    ";
637    Element.hide(win);
638    this.options.parent.insertBefore(win, this.options.parent.firstChild);
639    Event.observe($(id + "_content"), "load", this.options.onload);
640    return win;
641  },
642  
643  
644  changeClassName: function(newClassName) {    
645    var className = this.options.className;
646    var id = this.getId();
647    $A(["_close", "_minimize", "_maximize", "_sizer", "_content"]).each(function(value) { this._toggleClassName($(id + value), className + value, newClassName + value) }.bind(this));
648    this._toggleClassName($(id + "_top"), className + "_title", newClassName + "_title");
649    $$("#" + id + " td").each(function(td) {td.className = td.className.sub(className,newClassName); });
650    this.options.className = newClassName;
651  },
652  
653  _toggleClassName: function(element, oldClassName, newClassName) { 
654    if (element) {
655      element.removeClassName(oldClassName);
656      element.addClassName(newClassName);
657    }
658  },
659  
660  // Sets window location
661  setLocation: function(top, left) {
662    top = this._updateTopConstraint(top);
663    left = this._updateLeftConstraint(left);
664
665    var e = this.currentDrag || this.element;
666    e.setStyle({top: top + 'px'});
667    e.setStyle({left: left + 'px'});
668
669    this.useLeft = true;
670    this.useTop = true;
671  },
672    
673  getLocation: function() {
674    var location = {};
675    if (this.useTop)
676      location = Object.extend(location, {top: this.element.getStyle("top")});
677    else
678      location = Object.extend(location, {bottom: this.element.getStyle("bottom")});
679    if (this.useLeft)
680      location = Object.extend(location, {left: this.element.getStyle("left")});
681    else
682      location = Object.extend(location, {right: this.element.getStyle("right")});
683    
684    return location;
685  },
686  
687  // Gets window size
688  getSize: function() {
689    return {width: this.width, height: this.height};
690  },
691    
692  // Sets window size
693  setSize: function(width, height, useEffect) {    
694    width = parseFloat(width);
695    height = parseFloat(height);
696    
697    // Check min and max size
698    if (!this.minimized && width < this.options.minWidth)
699      width = this.options.minWidth;
700
701    if (!this.minimized && height < this.options.minHeight)
702      height = this.options.minHeight;
703      
704    if (this.options. maxHeight && height > this.options. maxHeight)
705      height = this.options. maxHeight;
706
707    if (this.options. maxWidth && width > this.options. maxWidth)
708      width = this.options. maxWidth;
709
710    
711    if (this.useTop && this.useLeft && Window.hasEffectLib && Effect.ResizeWindow && useEffect) {
712      new Effect.ResizeWindow(this, null, null, width, height, {duration: Window.resizeEffectDuration});
713    } else {
714      this.width = width;
715      this.height = height;
716      var e = this.currentDrag ? this.currentDrag : this.element;
717
718      e.setStyle({width: width + this.widthW + this.widthE + "px"})
719      e.setStyle({height: height  + this.heightN + this.heightS + "px"})
720
721      // Update content size
722      if (!this.currentDrag || this.currentDrag == this.element) {
723        var content = $(this.element.id + '_content');
724        content.setStyle({height: height  + 'px'});
725        content.setStyle({width: width  + 'px'});
726      }
727    }
728  },
729  
730  updateHeight: function() {
731    this.setSize(this.width, this.content.scrollHeight, true);
732  },
733  
734  updateWidth: function() {
735    this.setSize(this.content.scrollWidth, this.height, true);
736  },
737  
738  // Brings window to front
739  toFront: function() {
740    if (this.element.style.zIndex < Windows.maxZIndex)  
741      this.setZIndex(Windows.maxZIndex + 1);
742    if (this.iefix) 
743      this._fixIEOverlapping(); 
744  },
745   
746  getBounds: function(insideOnly) {
747    if (! this.width || !this.height || !this.visible)  
748      this.computeBounds();
749    var w = this.width;
750    var h = this.height;
751
752    if (!insideOnly) {
753      w += this.widthW + this.widthE;
754      h += this.heightN + this.heightS;
755    }
756    var bounds = Object.extend(this.getLocation(), {width: w + "px", height: h + "px"});
757    return bounds;
758  },
759      
760  computeBounds: function() {
761     if (! this.width || !this.height) {
762      var size = WindowUtilities._computeSize(this.content.innerHTML, this.content.id, this.width, this.height, 0, this.options.className)
763      if (this.height)
764        this.width = size + 5
765      else
766        this.height = size + 5
767    }
768
769    this.setSize(this.width, this.height);
770    if (this.centered)
771      this._center(this.centerTop, this.centerLeft);    
772  },
773  
774  // Displays window modal state or not
775  show: function(modal) {
776    this.visible = true;
777    if (modal) {
778      // Hack for Safari !!
779      if (typeof this.overlayOpacity == "undefined") {
780        var that = this;
781        setTimeout(function() {that.show(modal)}, 10);
782        return;
783      }
784      Windows.addModalWindow(this);
785      
786      this.modal = true;      
787      this.setZIndex(Windows.maxZIndex + 1);
788      Windows.unsetOverflow(this);
789    }
790    else    
791      if (!this.element.style.zIndex) 
792        this.setZIndex(Windows.maxZIndex + 1);        
793      
794    // To restore overflow if need be
795    if (this.oldStyle)
796      this.getContent().setStyle({overflow: this.oldStyle});
797      
798    this.computeBounds();
799    
800    this._notify("onBeforeShow");   
801    if (this.options.showEffect != Element.show && this.options.showEffectOptions)
802      this.options.showEffect(this.element, this.options.showEffectOptions);  
803    else
804      this.options.showEffect(this.element);  
805      
806    this._checkIEOverlapping();
807    WindowUtilities.focusedWindow = this
808    this._notify("onShow");   
809    $(this.element.id + '_focus_anchor').focus();
810  },
811  
812  // Displays window modal state or not at the center of the page
813  showCenter: function(modal, top, left) {
814    this.centered = true;
815    this.centerTop = top;
816    this.centerLeft = left;
817
818    this.show(modal);
819  },
820  
821  isVisible: function() {
822    return this.visible;
823  },
824  
825  _center: function(top, left) {    
826    var windowScroll = WindowUtilities.getWindowScroll(this.options.parent);    
827    var pageSize = WindowUtilities.getPageSize(this.options.parent);    
828    if (typeof top == "undefined")
829      top = (pageSize.windowHeight - (this.height + this.heightN + this.heightS))/2;
830    top += windowScroll.top
831    
832    if (typeof left == "undefined")
833      left = (pageSize.windowWidth - (this.width + this.widthW + this.widthE))/2;
834    left += windowScroll.left      
835    this.setLocation(top, left);
836    this.toFront();
837  },
838  
839  _recenter: function(event) {     
840    if (this.centered) {
841      var pageSize = WindowUtilities.getPageSize(this.options.parent);
842      var windowScroll = WindowUtilities.getWindowScroll(this.options.parent);    
843
844      // Check for this stupid IE that sends dumb events
845      if (this.pageSize && this.pageSize.windowWidth == pageSize.windowWidth && this.pageSize.windowHeight == pageSize.windowHeight && 
846          this.windowScroll.left == windowScroll.left && this.windowScroll.top == windowScroll.top) 
847        return;
848      this.pageSize = pageSize;
849      this.windowScroll = windowScroll;
850      // set height of Overlay to take up whole page and show
851      if ($('overlay_modal')) 
852        $('overlay_modal').setStyle({height: (pageSize.pageHeight + 'px')});
853      
854      if (this.options.recenterAuto)
855        this._center(this.centerTop, this.centerLeft);    
856    }
857  },
858  
859  // Hides window
860  hide: function() {
861    this.visible = false;
862    if (this.modal) {
863      Windows.removeModalWindow(this);
864      Windows.resetOverflow();
865    }
866    // To avoid bug on scrolling bar
867    this.oldStyle = this.getContent().getStyle('overflow') || "auto"
868    this.getContent().setStyle({overflow: "hidden"});
869
870    this.options.hideEffect(this.element, this.options.hideEffectOptions);  
871
872     if(this.iefix) 
873      this.iefix.hide();
874
875    if (!this.doNotNotifyHide)
876      this._notify("onHide");
877  },
878
879  close: function() {
880    // Asks closeCallback if exists
881    if (this.visible) {
882      if (this.options.closeCallback && ! this.options.closeCallback(this)) 
883        return;
884
885      if (this.options.destroyOnClose) {
886        var destroyFunc = this.destroy.bind(this);
887        if (this.options.hideEffectOptions.afterFinish) {
888          var func = this.options.hideEffectOptions.afterFinish;
889          this.options.hideEffectOptions.afterFinish = function() {func();destroyFunc() }
890        }
891        else 
892          this.options.hideEffectOptions.afterFinish = function() {destroyFunc() }
893      }
894      Windows.updateFocusedWindow();
895      
896      this.doNotNotifyHide = true;
897      this.hide();
898      this.doNotNotifyHide = false;
899      this._notify("onClose");
900    }
901  },
902  
903  minimize: function() {
904    if (this.resizing)
905      return;
906    
907    var r2 = $(this.getId() + "_row2");
908    
909    if (!this.minimized) {
910      this.minimized = true;
911
912      var dh = r2.getDimensions().height;
913      this.r2Height = dh;
914      var h  = this.element.getHeight() - dh;
915
916      if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow) {
917        new Effect.ResizeWindow(this, null, null, null, this.height -dh, {duration: Window.resizeEffectDuration});
918      } else  {
919        this.height -= dh;
920        this.element.setStyle({height: h + "px"});
921        r2.hide();
922      }
923
924      if (! this.useTop) {
925        var bottom = parseFloat(this.element.getStyle('bottom'));
926        this.element.setStyle({bottom: (bottom + dh) + 'px'});
927      }
928    } 
929    else {      
930      this.minimized = false;
931      
932      var dh = this.r2Height;
933      this.r2Height = null;
934      if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow) {
935        new Effect.ResizeWindow(this, null, null, null, this.height + dh, {duration: Window.resizeEffectDuration});
936      }
937      else {
938        var h  = this.element.getHeight() + dh;
939        this.height += dh;
940        this.element.setStyle({height: h + "px"})
941        r2.show();
942      }
943      if (! this.useTop) {
944        var bottom = parseFloat(this.element.getStyle('bottom'));
945        this.element.setStyle({bottom: (bottom - dh) + 'px'});
946      }
947      this.toFront();
948    }
949    this._notify("onMinimize");
950    
951    // Store new location/size if need be
952    this._saveCookie()
953  },
954  
955  maximize: function() {
956    if (this.isMinimized() || this.resizing)
957      return;
958  
959    if (Prototype.Browser.IE && this.heightN == 0)
960      this._getWindowBorderSize();
961      
962    if (this.storedLocation != null) {
963      this._restoreLocation();
964      if(this.iefix) 
965        this.iefix.hide();
966    }
967    else {
968      this._storeLocation();
969      Windows.unsetOverflow(this);
970      
971      var windowScroll = WindowUtilities.getWindowScroll(this.options.parent);
972      var pageSize = WindowUtilities.getPageSize(this.options.parent);    
973      var left = windowScroll.left;
974      var top = windowScroll.top;
975      
976      if (this.options.parent != document.body) {
977        windowScroll =  {top:0, left:0, bottom:0, right:0};
978        var dim = this.options.parent.getDimensions();
979        pageSize.windowWidth = dim.width;
980        pageSize.windowHeight = dim.height;
981        top = 0; 
982        left = 0;
983      }
984      
985      if (this.constraint) {
986        pageSize.windowWidth -= Math.max(0, this.constraintPad.left) + Math.max(0, this.constraintPad.right);
987        pageSize.windowHeight -= Math.max(0, this.constraintPad.top) + Math.max(0, this.constraintPad.bottom);
988        left +=  Math.max(0, this.constraintPad.left);
989        top +=  Math.max(0, this.constraintPad.top);
990      }
991      
992      var width = pageSize.windowWidth - this.widthW - this.widthE;
993      var height= pageSize.windowHeight - this.heightN - this.heightS;
994
995      if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow) {
996        new Effect.ResizeWindow(this, top, left, width, height, {duration: Window.resizeEffectDuration});
997      }
998      else {
999        this.setSize(width, height);
1000        this.element.setStyle(this.useLeft ? {left: left} : {right: left});
1001        this.element.setStyle(this.useTop ? {top: top} : {bottom: top});
1002      }
1003        
1004      this.toFront();
1005      if (this.iefix) 
1006        this._fixIEOverlapping(); 
1007    }
1008    this._notify("onMaximize");
1009
1010    // Store new location/size if need be
1011    this._saveCookie()
1012  },
1013  
1014  isMinimized: function() {
1015    return this.minimized;
1016  },
1017  
1018  isMaximized: function() {
1019    return (this.storedLocation != null);
1020  },
1021  
1022  setOpacity: function(opacity) {
1023    if (Element.setOpacity)
1024      Element.setOpacity(this.element, opacity);
1025  },
1026  
1027  setZIndex: function(zindex) {
1028    this.element.setStyle({zIndex: zindex});
1029    Windows.updateZindex(zindex, this);
1030  },
1031
1032  setTitle: function(newTitle) {
1033    if (!newTitle || newTitle == "") 
1034      newTitle = "&nbsp;";
1035      
1036    Element.update(this.element.id + '_top', newTitle);
1037  },
1038   
1039  getTitle: function() {
1040    return $(this.element.id + '_top').innerHTML;
1041  },
1042  
1043  setStatusBar: function(element) {
1044    var statusBar = $(this.getId() + "_bottom");
1045
1046    if (typeof(element) == "object") {
1047      if (this.bottombar.firstChild)
1048        this.bottombar.replaceChild(element, this.bottombar.firstChild);
1049      else
1050        this.bottombar.appendChild(element);
1051    }
1052    else
1053      this.bottombar.innerHTML = element;
1054  },
1055
1056  _checkIEOverlapping: function() {
1057    if(!this.iefix && (navigator.appVersion.indexOf('MSIE')>0) && (navigator.userAgent.indexOf('Opera')<0) && (this.element.getStyle('position')=='absolute')) {
1058        new Insertion.After(this.element.id, '<iframe id="' + this.element.id + '_iefix" '+ 'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' + 'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
1059        this.iefix = $(this.element.id+'_iefix');
1060    }
1061    if(this.iefix) 
1062      setTimeout(this._fixIEOverlapping.bind(this), 50);
1063  },
1064
1065  _fixIEOverlapping: function() {
1066      Position.clone(this.element, this.iefix);
1067      this.iefix.style.zIndex = this.element.style.zIndex - 1;
1068      this.iefix.show();
1069  },
1070  
1071  _keyUp: function(event) {
1072      if (27 == event.keyCode && this.options.closeOnEsc) {
1073          this.close();
1074      }
1075  },
1076
1077  _getWindowBorderSize: function(event) {
1078    // Hack to get real window border size!!
1079    var div = this._createHiddenDiv(this.options.className + "_n")
1080    this.heightN = Element.getDimensions(div).height;    
1081    div.parentNode.removeChild(div)
1082
1083    var div = this._createHiddenDiv(this.options.className + "_s")
1084    this.heightS = Element.getDimensions(div).height;    
1085    div.parentNode.removeChild(div)
1086
1087    var div = this._createHiddenDiv(this.options.className + "_e")
1088    this.widthE = Element.getDimensions(div).width;    
1089    div.parentNode.removeChild(div)
1090
1091    var div = this._createHiddenDiv(this.options.className + "_w")
1092    this.widthW = Element.getDimensions(div).width;
1093    div.parentNode.removeChild(div);
1094    
1095    var div = document.createElement("div");
1096    div.className = "overlay_" + this.options.className ;
1097    document.body.appendChild(div);
1098    //alert("no timeout:\nopacity: " + div.getStyle("opacity") + "\nwidth: " + document.defaultView.getComputedStyle(div, null).width);
1099    var that = this;
1100    
1101    // Workaround for Safari!!
1102    setTimeout(function() {that.overlayOpacity = ($(div).getStyle("opacity")); div.parentNode.removeChild(div);}, 10);
1103    
1104    // Workaround for IE!!
1105    if (Prototype.Browser.IE) {
1106      this.heightS = $(this.getId() +"_row3").getDimensions().height;
1107      this.heightN = $(this.getId() +"_row1").getDimensions().height;
1108    }
1109
1110    // Safari size fix
1111    if (Prototype.Browser.WebKit && Prototype.Browser.WebKitVersion < 420)
1112      this.setSize(this.width, this.height);
1113    if (this.doMaximize)
1114      this.maximize();
1115    if (this.doMinimize)
1116      this.minimize();
1117  },
1118 
1119  _createHiddenDiv: function(className) {
1120    var objBody = document.body;
1121    var win = document.createElement("div");
1122    win.setAttribute('id', this.element.id+ "_tmp");
1123    win.className = className;
1124    win.style.display = 'none';
1125    win.innerHTML = '';
1126    objBody.insertBefore(win, objBody.firstChild);
1127    return win;
1128  },
1129  
1130  _storeLocation: function() {
1131    if (this.storedLocation == null) {
1132      this.storedLocation = {useTop: this.useTop, useLeft: this.useLeft, 
1133                             top: this.element.getStyle('top'), bottom: this.element.getStyle('bottom'),
1134                             left: this.element.getStyle('left'), right: this.element.getStyle('right'),
1135                             width: this.width, height: this.height };
1136    }
1137  },
1138  
1139  _restoreLocation: function() {
1140    if (this.storedLocation != null) {
1141      this.useLeft = this.storedLocation.useLeft;
1142      this.useTop = this.storedLocation.useTop;
1143      
1144      if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow)
1145        new Effect.ResizeWindow(this, this.storedLocation.top, this.storedLocation.left, this.storedLocation.width, this.storedLocation.height, {duration: Window.resizeEffectDuration});
1146      else {
1147        this.element.setStyle(this.useLeft ? {left: this.storedLocation.left} : {right: this.storedLocation.right});
1148        this.element.setStyle(this.useTop ? {top: this.storedLocation.top} : {bottom: this.storedLocation.bottom});
1149        this.setSize(this.storedLocation.width, this.storedLocation.height);
1150      }
1151      
1152      Windows.resetOverflow();
1153      this._removeStoreLocation();
1154    }
1155  },
1156  
1157  _removeStoreLocation: function() {
1158    this.storedLocation = null;
1159  },
1160  
1161  _saveCookie: function() {
1162    if (this.cookie) {
1163      var value = "";
1164      if (this.useLeft)
1165        value += "l:" +  (this.storedLocation ? this.storedLocation.left : this.element.getStyle('left'))
1166      else
1167        value += "r:" + (this.storedLocation ? this.storedLocation.right : this.element.getStyle('right'))
1168      if (this.useTop)
1169        value += ",t:" + (this.storedLocation ? this.storedLocation.top : this.element.getStyle('top'))
1170      else
1171        value += ",b:" + (this.storedLocation ? this.storedLocation.bottom :this.element.getStyle('bottom'))
1172        
1173      value += "," + (this.storedLocation ? this.storedLocation.width : this.width);
1174      value += "," + (this.storedLocation ? this.storedLocation.height : this.height);
1175      value += "," + this.isMinimized();
1176      value += "," + this.isMaximized();
1177      WindowUtilities.setCookie(value, this.cookie)
1178    }
1179  },
1180  
1181  _createWiredElement: function() {
1182    if (! this.wiredElement) {
1183      if (Prototype.Browser.IE)
1184        this._getWindowBorderSize();
1185      var div = document.createElement("div");
1186      div.className = "wired_frame " + this.options.className + "_wired_frame";
1187      
1188      div.style.position = 'absolute';
1189      this.options.parent.insertBefore(div, this.options.parent.firstChild);
1190      this.wiredElement = $(div);
1191    }
1192    if (this.useLeft) 
1193      this.wiredElement.setStyle({left: this.element.getStyle('left')});
1194    else 
1195      this.wiredElement.setStyle({right: this.element.getStyle('right')});
1196      
1197    if (this.useTop) 
1198      this.wiredElement.setStyle({top: this.element.getStyle('top')});
1199    else 
1200      this.wiredElement.setStyle({bottom: this.element.getStyle('bottom')});
1201
1202    var dim = this.element.getDimensions();
1203    this.wiredElement.setStyle({width: dim.width + "px", height: dim.height +"px"});
1204
1205    this.wiredElement.setStyle({zIndex: Windows.maxZIndex+30});
1206    return this.wiredElement;
1207  },
1208  
1209  _hideWiredElement: function() {
1210    if (! this.wiredElement || ! this.currentDrag)
1211      return;
1212    if (this.currentDrag == this.element) 
1213      this.currentDrag = null;
1214    else {
1215      if (this.useLeft) 
1216        this.element.setStyle({left: this.currentDrag.getStyle('left')});
1217      else 
1218        this.element.setStyle({right: this.currentDrag.getStyle('right')});
1219
1220      if (this.useTop) 
1221        this.element.setStyle({top: this.currentDrag.getStyle('top')});
1222      else 
1223        this.element.setStyle({bottom: this.currentDrag.getStyle('bottom')});
1224
1225      this.currentDrag.hide();
1226      this.currentDrag = null;
1227      if (this.doResize)
1228        this.setSize(this.width, this.height);
1229    } 
1230  },
1231  
1232  _notify: function(eventName) {
1233    if (this.options[eventName])
1234      this.options[eventName](this);
1235    else
1236      Windows.notify(eventName, this);
1237  }
1238};
1239
1240// Windows containers, register all page windows
1241var Windows = {
1242  windows: [],
1243  modalWindows: [],
1244  observers: [],
1245  focusedWindow: null,
1246  maxZIndex: 0,
1247  overlayShowEffectOptions: {duration: 0.5},
1248  overlayHideEffectOptions: {duration: 0.5},
1249
1250  addObserver: function(observer) {
1251    this.removeObserver(observer);
1252    this.observers.push(observer);
1253  },
1254  
1255  removeObserver: function(observer) {  
1256    this.observers = this.observers.reject( function(o) { return o==observer });
1257  },
1258  
1259  // onDestroy onStartResize onStartMove onResize onMove onEndResize onEndMove onFocus onBlur onBeforeShow onShow onHide onMinimize onMaximize onClose
1260  notify: function(eventName, win) {  
1261    this.observers.each( function(o) {if(o[eventName]) o[eventName](eventName, win);});
1262  },
1263
1264  // Gets window from its id
1265  getWindow: function(id) {
1266    return this.windows.detect(function(d) { return d.getId() ==id });
1267  },
1268
1269  // Gets the last focused window
1270  getFocusedWindow: function() {
1271    return this.focusedWindow;
1272  },
1273
1274  updateFocusedWindow: function() {
1275    this.focusedWindow = this.windows.length >=2 ? this.windows[this.windows.length-2] : null;    
1276  },
1277  
1278  // Registers a new window (called by Windows constructor)
1279  register: function(win) {
1280    this.windows.push(win);
1281  },
1282    
1283  // Add a modal window in the stack
1284  addModalWindow: function(win) {
1285    // Disable screen if first modal window
1286    if (this.modalWindows.length == 0) {
1287      WindowUtilities.disableScreen(win.options.className, 'overlay_modal', win.overlayOpacity, win.getId(), win.options.parent);
1288    }
1289    else {
1290      // Move overlay over all windows
1291      if (Window.keepMultiModalWindow) {
1292        $('overlay_modal').style.zIndex = Windows.maxZIndex + 1;
1293        Windows.maxZIndex += 1;
1294        WindowUtilities._hideSelect(this.modalWindows.last().getId());
1295      }
1296      // Hide current modal window
1297      else
1298        this.modalWindows.last().element.hide();
1299      // Fucking IE select issue
1300      WindowUtilities._showSelect(win.getId());
1301    }      
1302    this.modalWindows.push(win);    
1303  },
1304  
1305  removeModalWindow: function(win) {
1306    this.modalWindows.pop();
1307    
1308    // No more modal windows
1309    if (this.modalWindows.length == 0)
1310      WindowUtilities.enableScreen();     
1311    else {
1312      if (Window.keepMultiModalWindow) {
1313        this.modalWindows.last().toFront();
1314        WindowUtilities._showSelect(this.modalWindows.last().getId());        
1315      }
1316      else
1317        this.modalWindows.last().element.show();
1318    }
1319  },
1320  
1321  // Registers a new window (called by Windows constructor)
1322  register: function(win) {
1323    this.windows.push(win);
1324  },
1325  
1326  // Unregisters a window (called by Windows destructor)
1327  unregister: function(win) {
1328    this.windows = this.windows.reject(function(d) { return d==win });
1329  }, 
1330  
1331  // Closes all windows
1332  closeAll: function() {  
1333    this.windows.each( function(w) {Windows.close(w.getId())} );
1334  },
1335  
1336  closeAllModalWindows: function() {
1337    WindowUtilities.enableScreen();     
1338    this.modalWindows.each( function(win) {if (win) win.close()});    
1339  },
1340
1341  // Minimizes a window with its id
1342  minimize: function(id, event) {
1343    var win = this.getWindow(id)
1344    if (win && win.visible)
1345      win.minimize();
1346    Event.stop(event);
1347  },
1348  
1349  // Maximizes a window with its id
1350  maximize: function(id, event) {
1351    var win = this.getWindow(id)
1352    if (win && win.visible)
1353      win.maximize();
1354    Event.stop(event);
1355  },
1356
1357  // Closes a window with its id
1358  close: function(id, event) {
1359    var win = this.getWindow(id);
1360    if (win) 
1361      win.close();
1362    if (event)
1363      Event.stop(event);
1364  },
1365  
1366  blur: function(id) {
1367    var win = this.getWindow(id);  
1368    if (!win)
1369      return;
1370    if (win.options.blurClassName)
1371      win.changeClassName(win.options.blurClassName);
1372    if (this.focusedWindow == win)  
1373      this.focusedWindow = null;
1374    win._notify("onBlur");  
1375  },
1376  
1377  focus: function(id) {
1378    var win = this.getWindow(id);  
1379    if (!win)
1380      return;       
1381    if (this.focusedWindow)
1382      this.blur(this.focusedWindow.getId())
1383
1384    if (win.options.focusClassName)
1385      win.changeClassName(win.options.focusClassName);  
1386    this.focusedWindow = win;
1387    win._notify("onFocus");
1388  },
1389  
1390  unsetOverflow: function(except) {    
1391    this.windows.each(function(d) { d.oldOverflow = d.getContent().getStyle("overflow") || "auto" ; d.getContent().setStyle({overflow: "hidden"}) });
1392    if (except && except.oldOverflow)
1393      except.getContent().setStyle({overflow: except.oldOverflow});
1394  },
1395
1396  resetOverflow: function() {
1397    this.windows.each(function(d) { if (d.oldOverflow) d.getContent().setStyle({overflow: d.oldOverflow}) });
1398  },
1399
1400  updateZindex: function(zindex, win) { 
1401    if (zindex > this.maxZIndex) {   
1402      this.maxZIndex = zindex;    
1403      if (this.focusedWindow) 
1404        this.blur(this.focusedWindow.getId())
1405    }
1406    this.focusedWindow = win;
1407    if (this.focusedWindow) 
1408      this.focus(this.focusedWindow.getId())
1409  }
1410};
1411
1412var Dialog = {
1413  dialogId: null,
1414  onCompleteFunc: null,
1415  callFunc: null, 
1416  parameters: null, 
1417    
1418  confirm: function(content, parameters) {
1419    // Get Ajax return before
1420    if (content && typeof content != "string") {
1421      Dialog._runAjaxRequest(content, parameters, Dialog.confirm);
1422      return 
1423    }
1424    content = content || "";
1425    
1426    parameters = parameters || {};
1427    var okLabel = parameters.okLabel ? parameters.okLabel : "Ok";
1428    var cancelLabel = parameters.cancelLabel ? parameters.cancelLabel : "Cancel";
1429
1430    // Backward compatibility
1431    parameters = Object.extend(parameters, parameters.windowParameters || {});
1432    parameters.windowParameters = parameters.windowParameters || {};
1433
1434    parameters.className = parameters.className || "alert";
1435
1436    var okButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " ok_button'" 
1437    var cancelButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " cancel_button'" 
1438/*     var content = "\
1439      <div class='" + parameters.className + "_message'>" + content  + "</div>\
1440        <div class='" + parameters.className + "_buttons'>\
1441          <input type='button' value='" + okLabel + "' onclick='Dialog.okCallback()' " + okButtonClass + "/>\
1442          <input type='button' value='" + cancelLabel + "' onclick='Dialog.cancelCallback()' " + cancelButtonClass + "/>\
1443        </div>\
1444    "; */
1445    var content = "\
1446      <div class='" + parameters.className + "_message'>" + content  + "</div>\
1447        <div class='" + parameters.className + "_buttons'>\
1448          <button type='button' title='" + okLabel + "' onclick='Dialog.okCallback()' " + okButtonClass + "><span><span><span>" + okLabel + "</span></span></span></button>\
1449          <button type='button' title='" + cancelLabel + "' onclick='Dialog.cancelCallback()' " + cancelButtonClass + "><span><span><span>" + cancelLabel + "</span></span></span></button>\
1450        </div>\
1451    ";
1452    return this._openDialog(content, parameters)
1453  },
1454  
1455  alert: function(content, parameters) {
1456    // Get Ajax return before
1457    if (content && typeof content != "string") {
1458      Dialog._runAjaxRequest(content, parameters, Dialog.alert);
1459      return 
1460    }
1461    content = content || "";
1462    
1463    parameters = parameters || {};
1464    var okLabel = parameters.okLabel ? parameters.okLabel : "Ok";
1465
1466    // Backward compatibility    
1467    parameters = Object.extend(parameters, parameters.windowParameters || {});
1468    parameters.windowParameters = parameters.windowParameters || {};
1469    
1470    parameters.className = parameters.className || "alert";
1471    
1472    var okButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " ok_button'" 
1473/*     var content = "\
1474      <div class='" + parameters.className + "_message'>" + content  + "</div>\
1475        <div class='" + parameters.className + "_buttons'>\
1476          <input type='button' value='" + okLabel + "' onclick='Dialog.okCallback()' " + okButtonClass + "/>\
1477        </div>";   */
1478    var content = "\
1479      <div class='" + parameters.className + "_message'>" + content  + "</div>\
1480        <div class='" + parameters.className + "_buttons'>\
1481          <button type='button' title='" + okLabel + "' onclick='Dialog.okCallback()' " + okButtonClass + "><span><span><span>" + okLabel + "</span></span></span></button>\
1482        </div>";                  
1483    return this._openDialog(content, parameters)
1484  },
1485  
1486  info: function(content, parameters) {
1487    // Get Ajax return before
1488    if (content && typeof content != "string") {
1489      Dialog._runAjaxRequest(content, parameters, Dialog.info);
1490      return 
1491    }
1492    content = content || "";
1493     
1494    // Backward compatibility
1495    parameters = parameters || {};
1496    parameters = Object.extend(parameters, parameters.windowParameters || {});
1497    parameters.windowParameters = parameters.windowParameters || {};
1498    
1499    parameters.className = parameters.className || "alert";
1500    
1501    var content = "<div id='modal_dialog_message' class='" + parameters.className + "_message'>" + content  + "</div>";
1502    if (parameters.showProgress)
1503      content += "<div id='modal_dialog_progress' class='" + parameters.className + "_progress'>  </div>";
1504
1505    parameters.ok = null;
1506    parameters.cancel = null;
1507    
1508    return this._openDialog(content, parameters)
1509  },
1510  
1511  setInfoMessage: function(message) {
1512    $('modal_dialog_message').update(message);
1513  },
1514  
1515  closeInfo: function() {
1516    Windows.close(this.dialogId);
1517  },
1518  
1519  _openDialog: function(content, parameters) {
1520    var className = parameters.className;
1521    
1522    if (! parameters.height && ! parameters.width) {
1523      parameters.width = WindowUtilities.getPageSize(parameters.options.parent || document.body).pageWidth / 2;
1524    }
1525    if (parameters.id)
1526      this.dialogId = parameters.id;
1527    else { 
1528      var t = new Date();
1529      this.dialogId = 'modal_dialog_' + t.getTime();
1530      parameters.id = this.dialogId;
1531    }
1532
1533    // compute height or width if need be
1534    if (! parameters.height || ! parameters.width) {
1535      var size = WindowUtilities._computeSize(content, this.dialogId, parameters.width, parameters.height, 5, className)
1536      if (parameters.height)
1537        parameters.width = size + 5
1538      else
1539        parameters.height = size + 5
1540    }
1541    parameters.effectOptions = parameters.effectOptions ;
1542    parameters.resizable   = parameters.resizable || false;
1543    parameters.minimizable = parameters.minimizable || false;
1544    parameters.maximizable = parameters.maximizable ||  false;
1545    parameters.draggable   = parameters.draggable || false;
1546    parameters.closable    = parameters.closable || false;
1547
1548    var win = new Window(parameters);
1549    win.getContent().innerHTML = content;
1550    
1551    win.showCenter(true, parameters.top, parameters.left);  
1552    win.setDestroyOnClose();
1553    
1554    win.cancelCallback = parameters.onCancel || parameters.cancel; 
1555    win.okCallback = parameters.onOk || parameters.ok;
1556    
1557    return win;    
1558  },
1559  
1560  _getAjaxContent: function(originalRequest)  {
1561      Dialog.callFunc(originalRequest.responseText, Dialog.parameters)
1562  },
1563  
1564  _runAjaxRequest: function(message, parameters, callFunc) {
1565    if (message.options == null)
1566      message.options = {}  
1567    Dialog.onCompleteFunc = message.options.onComplete;
1568    Dialog.parameters = parameters;
1569    Dialog.callFunc = callFunc;
1570    
1571    message.options.onComplete = Dialog._getAjaxContent;
1572    new Ajax.Request(message.url, message.options);
1573  },
1574  
1575  okCallback: function() {
1576    var win = Windows.focusedWindow;
1577    if (!win.okCallback || win.okCallback(win)) {
1578      // Remove onclick on button
1579      $$("#" + win.getId()+" input").each(function(element) {element.onclick=null;})
1580      win.close();
1581    }
1582  },
1583
1584  cancelCallback: function() {
1585    var win = Windows.focusedWindow;
1586    // Remove onclick on button
1587    $$("#" + win.getId()+" input").each(function(element) {element.onclick=null})
1588    win.close();
1589    if (win.cancelCallback)
1590      win.cancelCallback(win);
1591  }
1592}
1593/*
1594  Based on Lightbox JS: Fullsize Image Overlays 
1595  by Lokesh Dhakar - http://www.huddletogether.com
1596
1597  For more information on this script, visit:
1598  http://huddletogether.com/projects/lightbox/
1599
1600  Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
1601  (basically, do anything you want, just leave my name and link)
1602*/
1603
1604if (Prototype.Browser.WebKit) {
1605  var array = navigator.userAgent.match(new RegExp(/AppleWebKit\/([\d\.\+]*)/));
1606  Prototype.Browser.WebKitVersion = parseFloat(array[1]);
1607}
1608
1609var WindowUtilities = {  
1610  // From dragdrop.js
1611  getWindowScroll: function(parent) {
1612    var T, L, W, H;
1613    parent = parent || document.body;              
1614    if (parent != document.body) {
1615      T = parent.scrollTop;
1616      L = parent.scrollLeft;
1617      W = parent.scrollWidth;
1618      H = parent.scrollHeight;
1619    } 
1620    else {
1621      var w = window;
1622      with (w.document) {
1623        if (w.document.documentElement && documentElement.scrollTop) {
1624          T = documentElement.scrollTop;
1625          L = documentElement.scrollLeft;
1626        } else if (w.document.body) {
1627          T = body.scrollTop;
1628          L = body.scrollLeft;
1629        }
1630        if (w.innerWidth) {
1631          W = w.innerWidth;
1632          H = w.innerHeight;
1633        } else if (w.document.documentElement && documentElement.clientWidth) {
1634          W = documentElement.clientWidth;
1635          H = documentElement.clientHeight;
1636        } else {
1637          W = body.offsetWidth;
1638          H = body.offsetHeight
1639        }
1640      }
1641    }
1642    return { top: T, left: L, width: W, height: H };
1643  }, 
1644  //
1645  // getPageSize()
1646  // Returns array with page width, height and window width, height
1647  // Core code from - quirksmode.org
1648  // Edit for Firefox by pHaez
1649  //
1650  getPageSize: function(parent){
1651    parent = parent || document.body;              
1652    var windowWidth, windowHeight;
1653    var pageHeight, pageWidth;
1654    if (parent != document.body) {
1655      windowWidth = parent.getWidth();
1656      windowHeight = parent.getHeight();                                
1657      pageWidth = parent.scrollWidth;
1658      pageHeight = parent.scrollHeight;                                
1659    } 
1660    else {
1661      var xScroll, yScroll;
1662
1663      if (window.innerHeight && window.scrollMaxY) {  
1664        xScroll = document.body.scrollWidth;
1665        yScroll = window.innerHeight + window.scrollMaxY;
1666      } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
1667        xScroll = document.body.scrollWidth;
1668        yScroll = document.body.scrollHeight;
1669      } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
1670        xScroll = document.body.offsetWidth;
1671        yScroll = document.body.offsetHeight;
1672      }
1673
1674
1675      if (self.innerHeight) {  // all except Explorer
1676        windowWidth = document.documentElement.clientWidth;//self.innerWidth;
1677        windowHeight = self.innerHeight;
1678      } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
1679        windowWidth = document.documentElement.clientWidth;
1680        windowHeight = document.documentElement.clientHeight;
1681      } else if (document.body) { // other Explorers
1682        windowWidth = document.body.clientWidth;
1683        windowHeight = document.body.clientHeight;
1684      }  
1685
1686      // for small pages with total height less then height of the viewport
1687      if(yScroll < windowHeight){
1688        pageHeight = windowHeight;
1689      } else { 
1690        pageHeight = yScroll;
1691      }
1692
1693      // for small pages with total width less then width of the viewport
1694      if(xScroll < windowWidth){  
1695        pageWidth = windowWidth;
1696      } else {
1697        pageWidth = xScroll;
1698      }
1699    }             
1700    return {pageWidth: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight};
1701  },
1702
1703  disableScreen: function(className, overlayId, overlayOpacity, contentId, parent) {
1704    WindowUtilities.initLightbox(overlayId, className, function() {this._disableScreen(className, overlayId, overlayOpacity, contentId)}.bind(this), parent || document.body);
1705  },
1706
1707  _disableScreen: function(className, overlayId, overlayOpacity, contentId) {
1708    // prep objects
1709    var objOverlay = $(overlayId);
1710
1711    var pageSize = WindowUtilities.getPageSize(objOverlay.parentNode);
1712
1713    // Hide select boxes as they will 'peek' through the image in IE, store old value
1714    if (contentId && Prototype.Browser.IE) {
1715      WindowUtilities._hideSelect();
1716      WindowUtilities._showSelect(contentId);
1717    }  
1718  
1719    // set height of Overlay to take up whole page and show
1720    objOverlay.style.height = (pageSize.pageHeight + 'px');
1721    objOverlay.style.display = 'none'; 
1722    if (overlayId == "overlay_modal" && Window.hasEffectLib && Windows.overlayShowEffectOptions) {
1723      objOverlay.overlayOpacity = overlayOpacity;
1724      new Effect.Appear(objOverlay, Object.extend({from: 0, to: overlayOpacity}, Windows.overlayShowEffectOptions));
1725    }
1726    else
1727      objOverlay.style.display = "block";
1728  },
1729  
1730  enableScreen: function(id) {
1731    id = id || 'overlay_modal';
1732    var objOverlay =  $(id);
1733    if (objOverlay) {
1734      // hide lightbox and overlay
1735      if (id == "overlay_modal" && Window.hasEffectLib && Windows.overlayHideEffectOptions)
1736        new Effect.Fade(objOverlay, Object.extend({from: objOverlay.overlayOpacity, to:0}, Windows.overlayHideEffectOptions));
1737      else {
1738        objOverlay.style.display = 'none';
1739        objOverlay.parentNode.removeChild(objOverlay);
1740      }
1741      
1742      // make select boxes visible using old value
1743      if (id != "__invisible__") 
1744        WindowUtilities._showSelect();
1745    }
1746  },
1747
1748  _hideSelect: function(id) {
1749    if (Prototype.Browser.IE) {
1750      id = id ==  null ? "" : "#" + id + " ";
1751      $$(id + 'select').each(function(element) {
1752        if (! WindowUtilities.isDefined(element.oldVisibility)) {
1753          element.oldVisibility = element.style.visibility ? element.style.visibility : "visible";
1754          element.style.visibility = "hidden";
1755        }
1756      });
1757    }
1758  },
1759  
1760  _showSelect: function(id) {
1761    if (Prototype.Browser.IE) {
1762      id = id ==  null ? "" : "#" + id + " ";
1763      $$(id + 'select').each(function(element) {
1764        if (WindowUtilities.isDefined(element.oldVisibility)) {
1765          // Why?? Ask IE
1766          try {
1767            element.style.visibility = element.oldVisibility;
1768          } catch(e) {
1769            element.style.visibility = "visible";
1770          }
1771          element.oldVisibility = null;
1772        }
1773        else {
1774          if (element.style.visibility)
1775            element.style.visibility = "visible";
1776        }
1777      });
1778    }
1779  },
1780
1781  isDefined: function(object) {
1782    return typeof(object) != "undefined" && object != null;
1783  },
1784  
1785  // initLightbox()
1786  // Function runs on window load, going through link tags looking for rel="lightbox".
1787  // These links receive onclick events that enable the lightbox display for their targets.
1788  // The function also inserts html markup at the top of the page which will be used as a
1789  // container for the overlay pattern and the inline image.
1790  initLightbox: function(id, className, doneHandler, parent) {
1791    // Already done, just update zIndex
1792    if ($(id)) {
1793      Element.setStyle(id, {zIndex: Windows.maxZIndex + 1});
1794      Windows.maxZIndex++;
1795      doneHandler();
1796    }
1797    // create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
1798    else {
1799      var objOverlay = document.createElement("div");
1800      objOverlay.setAttribute('id', id);
1801      objOverlay.className = "overlay_" + className
1802      objOverlay.style.display = 'none';
1803      objOverlay.style.position = 'absolute';
1804      objOverlay.style.top = '0';
1805      objOverlay.style.left = '0';
1806      objOverlay.style.zIndex = Windows.maxZIndex + 1;
1807      Windows.maxZIndex++;
1808      objOverlay.style.width = '100%';
1809      parent.insertBefore(objOverlay, parent.firstChild);
1810      if (Prototype.Browser.WebKit && id == "overlay_modal") {
1811        setTimeout(function() {doneHandler()}, 10);
1812      }
1813      else
1814        doneHandler();
1815    }    
1816  },
1817  
1818  setCookie: function(value, parameters) {
1819    document.cookie= parameters[0] + "=" + escape(value) +
1820      ((parameters[1]) ? "; expires=" + parameters[1].toGMTString() : "") +
1821      ((parameters[2]) ? "; path=" + parameters[2] : "") +
1822      ((parameters[3]) ? "; domain=" + parameters[3] : "") +
1823      ((parameters[4]) ? "; secure" : "");
1824  },
1825
1826  getCookie: function(name) {
1827    var dc = document.cookie;
1828    var prefix = name + "=";
1829    var begin = dc.indexOf("; " + prefix);
1830    if (begin == -1) {
1831      begin = dc.indexOf(prefix);
1832      if (begin != 0) return null;
1833    } else {
1834      begin += 2;
1835    }
1836    var end = document.cookie.indexOf(";", begin);
1837    if (end == -1) {
1838      end = dc.length;
1839    }
1840    return unescape(dc.substring(begin + prefix.length, end));
1841  },
1842    
1843  _computeSize: function(content, id, width, height, margin, className) {
1844    var objBody = document.body;
1845    var tmpObj = document.createElement("div");
1846    tmpObj.setAttribute('id', id);
1847    tmpObj.className = className + "_content";
1848
1849    if (height)
1850      tmpObj.style.height = height + "px"
1851    else
1852      tmpObj.style.width = width + "px"
1853  
1854    tmpObj.style.position = 'absolute';
1855    tmpObj.style.top = '0';
1856    tmpObj.style.left = '0';
1857    tmpObj.style.display = 'none';
1858
1859    tmpObj.innerHTML = content;
1860    objBody.insertBefore(tmpObj, objBody.firstChild);
1861
1862    var size;
1863    if (height)
1864      size = $(tmpObj).getDimensions().width + margin;
1865    else
1866      size = $(tmpObj).getDimensions().height + margin;
1867    objBody.removeChild(tmpObj);
1868    return size;
1869  }  
1870}
1871

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.