PageSourceSearch

https://appel-a-projets.fondationdefrance.org/eAwards_applicant/template//common/js/popup/window.js

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

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.