/*
 * (c)2006 Dean Edwards/Matthias Miller/John Resig
 * Special thanks to Dan Webb's domready.js Prototype extension
 * and Simon Willison's addLoadEvent
 *
 * For more info, see:
 * http://dean.edwards.name/weblog/2006/06/again/
 * http://www.vivabit.com/bollocks/2006/06/21/a-dom-ready-extension-for-prototype
 * http://simon.incutio.com/archive/2004/05/26/addLoadEvent
 * 
 * Thrown together by Jesse Skinner (http://www.thefutureoftheweb.com/)
 *
 *
 * To use: call addDOMLoadEvent one or more times with functions, ie:
 *
 *    function something() {
 *       // do something
 *    }
 *    addDOMLoadEvent(something);
 *
 *    addDOMLoadEvent(function() {
 *        // do other stuff
 *    });
 *
 */

function addDOMLoadEvent(func) {
   if (!window.__load_events) {
      var init = function () {
          // quit if this function has already been called
          if (arguments.callee.done) return;
      
          // flag this function so we don't do the same thing twice
          arguments.callee.done = true;
      
          // kill the timer
          if (window.__load_timer) {
              clearInterval(window.__load_timer);
              window.__load_timer = null;
          }
          
          // execute each function in the stack in the order they were added
          for (var i=0;i < window.__load_events.length;i++) {
              window.__load_events[i]();
          }
          window.__load_events = null;

          // clean up the __ie_onload event
          /*@cc_on @*/
          /*@if (@_win32)
              document.getElementById("__ie_onload").onreadystatechange = "";
          /*@end @*/
      };
   
      // for Mozilla/Opera9
      if (document.addEventListener) {
          document.addEventListener("DOMContentLoaded", init, false);
      }
      
      // for Internet Explorer
      /*@cc_on @*/
      /*@if (@_win32)
          document.write("<scr"+"ipt id=__ie_onload defer src=javascript:void(0)><\/scr"+"ipt>");
          var script = document.getElementById("__ie_onload");
          script.onreadystatechange = function() {
              if (this.readyState == "complete") {
                  init(); // call the onload handler
              }
          };
      /*@end @*/
      
      // for Safari
      if (/WebKit/i.test(navigator.userAgent)) { // sniff
          window.__load_timer = setInterval(function() {
              if (/loaded|complete/.test(document.readyState)) {
                  init(); // call the onload handler
              }
          }, 10);
      }
      
      // for other browsers
      window.onload = init;
      
      // create event function stack
      window.__load_events = [];
   }
   
   // add function to event stack
   window.__load_events.push(func);
}


/****************************************************
 *
 *  JavaScript Library: deg_commons
 *  
 *  @authors: Dean Edwards, Tino Zijdel, Dirk Engberg  
 *  @requires: -
 */    
 
var deg = {
  // Standard event handling functions to abstract browser specialeties
  // written by Dean Edwards, 2005
  // with input from Tino Zijdel - crisp@xs4all.nl
  // http://dean.edwards.name/weblog/2005/10/add-event/

  addEvent:function(element, type, handler)
  {
  	if (element.addEventListener)
  		element.addEventListener(type, handler, false);
  	else
  	{
  		if (!handler.$$guid) handler.$$guid = deg._addEvent_guid++;
  		if (!element.events) element.events = {};
  		var handlers = element.events[type];
  		if (!handlers)
  		{
  			handlers = element.events[type] = {};
  			if (element['on' + type]) handlers[0] = element['on' + type];
  			element['on' + type] = deg.handleEvent;
  		}
  	
  		handlers[handler.$$guid] = handler;
  	}
  },
  _addEvent_guid:1,
  
  /**********************************
   * removes (=detaches) the event
   **/         
  removeEvent:function(element, type, handler)
  {
  	if (element.removeEventListener)
  		element.removeEventListener(type, handler, false);
  	else if (element.events && element.events[type] && handler.$$guid)
  		delete element.events[type][handler.$$guid];
  },

  /**************************
   * handles the event
   **/  
  handleEvent:function(event)
  {
  	event = event || deg.fixEvent(window.event);
  	var returnValue = true;
  	var handlers = this.events[event.type];
  
  	for (var i in handlers)
  	{
  		if (!Object.prototype[i])
  		{
  			this.$$handler = handlers[i];
  			if (this.$$handler(event) === false) returnValue = false;
  		}
  	}
  
  	if (this.$$handler) this.$$handler = null;
  
  	return returnValue;
  },

  fixEvent:function(event)
  {
  	event.preventDefault = deg._fixEvent_preventDefault;
  	event.stopPropagation = deg._fixEvent_stopPropagation;
  	return event;
  },
  
  _fixEvent_preventDefault:function()
  {
  	this.returnValue = false;
  },
  
  _fixEvent_stopPropagation:function()
  {
  	this.cancelBubble = true;
  },

  // DOM utilities and CSS detach/attach
  // written by D. Engberg
  
  Dom:{
    /**
     * get all direct child nodes of specific type
     */
    getChildNodesByType:function(theElement, theType) {
      var elms=theElement.childNodes;
      if (elms==null) return null;
      var theSet = new Array();
      for (var i=0; i<elms.length; i++) {
        if (elms[i].nodeName==theType) theSet.push(elms[i]);
      }
      return theSet;
    }
  },
  
  Css:{
    /**
     * add style class
     */
    addClass:function(theElement, theClass) {
      if (theElement.className==null || theElement.className=="") {
        theElement.className=theClass;
        return;
      }
      var classes = theElement.className.split(" ");
      for (cl in classes) // check if already existing
        if (classes[cl]==theClass) return;
      classes.push(theClass);
      theElement.className=classes.join(" ");
    },
    
    /**
     * remove style class
     */
    removeClass:function(theElement, theClass) {
      if (theElement.className==null || theElement.className=="") return;
      var classes = theElement.className.split(" ");
      var newClasses = new Array();
      var i=0
      for (cl in classes) {
        if (classes[cl]!=theClass)
          newClasses.push(classes[cl]);
        i++;
      }
      theElement.className=newClasses.join(" ");
    },
    
    /**
     * check if element contains style class
     */
    containsClass:function(theElement, theClass) {
      if (theElement.className==null || theElement.className=="") return false;
      var classes = theElement.className.split(" ");
      for (cl in classes) {
        if (classes[cl]==theClass) return true;
      }
      return false;
    }
  },
  
  Util:{
    IS_IE: (navigator.appName && navigator.appName=="Microsoft Internet Explorer"),
    
    sleep:function(milliseconds) {
      var date = new Date();
      var curDate = null;
      do { curDate = new Date(); }
      while(curDate-date < milliseconds);
    }
  }
  
}
 
 
; 
  
// This little snippet fixes the problem that the onload attribute on the body-element will overwrite
// previous attached events on the window object for the onload event
if (!window.addEventListener)
{
	document.onreadystatechange = function()
	{
		if (window.onload && window.onload != deg.handleEvent)
		{
			deg.addEvent(window, 'load', window.onload);
			window.onload = deg.handleEvent;
		}
	}
}

;

/***********************************************************************
 *
 *  JavaScript Library: deg_navbar
 *  
 *  @authors: Dirk Engberg  
 *  @requires: deg_commons.js
 *
 *  Creates horizontal drop down navigation bar from UL/LI tree.
 *  (one sublevel only!) 
 *  
 *  add class name as defined in STYLESHEET to the UL element you want
 *  to use as root for a dropdown navigation bar.  
 *  
 *  alternatively you can call the method 
 *    deg.DropDownNavBar.applyToElement(elem)
 *  directly with the element object as parameter. 
 *  
 **/ 

deg.DropDownNavBar = {

  /* the stylesheet that will force application of this script */
  STYLESHEET:         "deg_navbar",         
  
  /* the stylesheet which will be assigned to the iframe */
  STYLESHEET_IFRAME:  "deg_navbar__bgframe",
  
  /* the stylesheet that will be assigned to the div */
  STYLESHEET_DIV:     "deg_navbar__dropmenudiv",
  
  /* some default prefix for dynamically created id's */
  DEFAULT_ID_PREFIX:  "0nbid0",
  
  
  /*******************************************************************
   * Initialises automatically all UL trees containing the STYLESHEET
   * as drop down menu. Alternatively, you can 
   **/        
  init:function() {
    var uls = document.getElementsByTagName("UL");
    for (var i=0; i<uls.length; i++) {
      if (deg.Css.containsClass(uls[i], deg.DropDownNavBar.STYLESHEET)) {
        deg.DropDownNavBar.applyToElement(uls[i]);
      }
    }
  },
  
  applyToElement:function(obj) {
    if (obj==null) return false;
    if (typeof(obj)!="object") return false;
    if (!obj.nodeName) return false;
    if (!obj.nodeName=="UL") return false;
    if (!deg.Css.containsClass(obj, deg.DropDownNavBar.STYLESHEET)) deg.Css.addClass(obj, deg.DropDownNavBar.STYLESHEET);
    deg.DropDownNavBar.createDropdownObjects(obj);
    deg.DropDownNavBar.Chrome.startchrome(obj);
  },
  
  /****************************************************************
   * Creates DIV elements and IFRAME (for IE controll overlay hack)
   * that will be used as drop downs, and copies the sub-menu 
   * UL elements in the DIV container.
   *          
   * Note: the root UL of the navigation bar needs to be nested in 
   * a DIV container.       
   **/   
  createDropdownObjects:function(parentUl) {  
    // add unique id if not yet existing
    if (parentUl.id==null || parentUl.id=="") {
      var theId = 0;
      while (document.getElementById(deg.DropDownNavBar.DEFAULT_ID_PREFIX + theId)!=null) theId++;
      parentUl.id= deg.DropDownNavBar.DEFAULT_ID_PREFIX + theId;
    }
    var lis = deg.Dom.getChildNodesByType(parentUl, "LI");
    for (i=0; i<lis.length; i++) {
      // check if there are sub menues
      var childUls = deg.Dom.getChildNodesByType(lis[i], "UL");
      if (childUls!=null && childUls.length > 0) {
        // if there are sub menus, create the necessary divs
        var as = deg.Dom.getChildNodesByType(lis[i], "A");
        if (as==null || as.length==0) return;
        for (k=0; k<as.length; k++) {
          var submenuId =  deg.DropDownNavBar.STYLESHEET + "__" + parentUl.id + "_" + i;
          // create the reference in the A element
          as[k].setAttribute("rel", submenuId);
          // create the div
          var dd_div = document.createElement("DIV");
          dd_div.setAttribute("id", submenuId);
          dd_div.className=deg.DropDownNavBar.STYLESHEET_DIV;
          // move all submenu uls to the dropdown
          for (j=childUls.length-1; j>=0; j--) {
            dd_div.appendChild(childUls[j].cloneNode(true));
            lis[i].removeChild(childUls[j]);
            var dd_iframe = document.createElement("IFRAME");
            dd_iframe.setAttribute("id", submenuId+"_iframe");
            dd_iframe.setAttribute("name", "_" + submenuId+"_iframe");
            dd_iframe.setAttribute("frameBorder", "0");
            dd_iframe.setAttribute("scrolling", "no");
            dd_iframe.className=deg.DropDownNavBar.STYLESHEET_IFRAME;
            dd_iframe.setAttribute("src","javascript:false"); //This prevents from neverending iframe loading
          }
          //append the div and iframe
          document.getElementsByTagName("BODY")[0].appendChild(dd_div);
          document.getElementsByTagName("BODY")[0].appendChild(dd_iframe);
        }
      }
    }
  },
  
  
  /**********************************************************************
   * gets the root UL element (the one with the STYLESHEET set
   * to enable the navigation bar) of the current element.
   *    
   * @param   {Object}  the current Element, which is a (cascading) child 
   *                    of the root UL   
   * @return  {Object}  the container Div, or null if there is none.      
   **/     
  getRootUl:function(currentElement) {
    if (currentElement.nodeName=="BODY") return null;
    if (deg.Css.containsClass(currentElement, deg.DropDownNavBar.STYLESHEET)) return currentElement;
    return deg.DropDownNavBar.getRootUl(currentElement.parentNode);
  },
  
  /****************************************************************
   * Gets the A element in the original UL tree thar refers to
   * the DIV dropdown container of an element within this container   
   * 
   * @param   {Object}  the current Element, which is a (cascading) child 
   *                    of a dropdown DIV   
   * @return  {Object}  the A Elemement that refers to this DIV      
   **/     
  getDropDownParentA:function (currentElement) {
    var thePar = currentElement;
    for (;
         thePar.nodeName!="BODY" && !deg.Css.containsClass(thePar, "deg_navbar__dropmenudiv");
         thePar = thePar.parentNode);
    if (thePar.nodeName=="BODY") {
      return null;
    }
    var theRel=thePar.id;
    var theId=thePar.id.replace(new RegExp(deg.DropDownNavBar.STYLESHEET + "__(.*)_\\d+$"),"$1");
    var theMenuEl = document.getElementById(theId);
    var as = theMenuEl.getElementsByTagName("A");
    var i=0;
    for (;i<as.length&&as[i].rel!=theRel;i++);
    return as[i];
  },




  /* -------------------------------------------------------------------------------- */
  //Based on Chrome Drop Down Menu - Author: Dynamic Drive (http://www.dynamicdrive.com)
  //Last updated: June 14th, 06'
  //modified by D. Engberg for ALSTOM
  
  
  Chrome: {
    disappeardelay: 250, // set delay in miliseconds before menu disappears onmouseout
    disablemenuclick: false, // when user clicks on a menu item with a drop down menu, disable menu item's link?
    enableswipe: 0, // enable swipe effect? 1 for yes, 0 for no
    swipedelay: 1,  // delay for swipe effect
    swipestep: 5,   // pix steps (speed) for swipe effect
    iectlfix: (navigator.appName && navigator.appName=="Microsoft Internet Explorer") , // use iframes behind divs to overlay select objects in IE
    
    //No need to edit beyond here////////////////////////
    dropmenuobj: null, ie: document.all, firefox: document.getElementById&&!document.all, swipetimer: undefined, bottomclip:0,
    
    getposOffset:function(what, offsettype){
      var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
      var parentEl=what.offsetParent;
      while (parentEl!=null){
        totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
        parentEl=parentEl.offsetParent;
      }
      return totaloffset;
    },
    
    swipeeffect:function(){
      if (this.bottomclip<parseInt(this.dropmenuobj.offsetHeight)){
        var delta = this.bottomclip;
        this.bottomclip+=this.swipestep//+(this.bottomclip/this.swipestep); //unclip drop down menu visibility gradually
        if (this.bottomclip>parseInt(this.dropmenuobj.offsetHeight)) this.bottomclip=parseInt(this.dropmenuobj.offsetHeight);
        delta = this.bottomclip - delta
        this.dropmenuobj.style.clip="rect("+(parseInt(this.dropmenuobj.offsetHeight) - this.bottomclip)+"px auto "+this.dropmenuobj.offsetHeight+" 0)";
        this.dropmenuobj.style.top=(parseInt(this.dropmenuobj.style.top) + delta) + "px";
        if (deg.DropDownNavBar.Chrome.iectlfix) {
          //document.getElementById(this.dropmenuobj.id+"_iframe").style.top=this.dropmenuobj.style.top;       
          document.getElementById(this.dropmenuobj.id+"_iframe").style.clip="rect(0 auto "+this.bottomclip+"px 0)";        
        }
      } else return;
      this.swipetimer=setTimeout("deg.DropDownNavBar.Chrome.swipeeffect()", deg.DropDownNavBar.Chrome.swipedelay);
    },
    
    showhide:function(obj, e){
      if (this.ie || this.firefox) {
        this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px"
        if (deg.DropDownNavBar.Chrome.iectlfix) {
          document.getElementById(this.dropmenuobj.id+"_iframe").style.left=document.getElementById(this.dropmenuobj.id+"_iframe").style.top="-500px";
        }
      }
      if (e.type=="click" && obj.style.visibility==hidden || e.type=="mouseover") {
        if (this.enableswipe==1) {
          if (typeof this.swipetimer!="undefined")
            clearTimeout(this.swipetimer);
          obj.style.clip="rect(0 auto 0 0)"; //hide menu via clipping
          if (deg.DropDownNavBar.Chrome.iectlfix) {document.getElementById(obj.id + "_iframe").style.clip="rect(0 auto 0 0)";}
          this.bottomclip=0
          this.swipeeffect();
        }
        if (deg.DropDownNavBar.Chrome.iectlfix) {
          document.getElementById(obj.id + "_iframe").style.height=obj.offsetHeight+"px";
          document.getElementById(obj.id + "_iframe").style.width=obj.offsetWidth+"px";
          document.getElementById(obj.id + "_iframe").style.visibility="visible";
        }
        obj.style.visibility="visible";
        deg.Css.addClass(deg.DropDownNavBar.getDropDownParentA(obj),"hover");
      }
      else if (e.type=="click") {
        obj.style.visibility="hidden";
        deg.Css.removeClass(deg.DropDownNavBar.getDropDownParentA(obj),"hover");
        if (deg.DropDownNavBar.Chrome.iectlfix) {document.getElementById(obj.id + "_iframe").style.visibility="hidden";}
      }
    },
    
    iecompattest:function(){
     return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
    },
    
    clearbrowseredge:function(obj, whichedge){
      var edgeoffset=0
      if (whichedge=="rightedge") {
        var windowedge=this.ie && !window.opera? this.iecompattest().scrollLeft+this.iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
        this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetWidth;
        if (windowedge-this.dropmenuobj.x < this.dropmenuobj.contentmeasure)  //move menu to the left?
          edgeoffset=this.dropmenuobj.contentmeasure-obj.offsetWidth;
      }
      else{
        var topedge=this.ie && !window.opera? this.iecompattest().scrollTop : window.pageYOffset
        var windowedge=this.ie && !window.opera? this.iecompattest().scrollTop+this.iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
        this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetHeight;
        if (windowedge-this.dropmenuobj.y < this.dropmenuobj.contentmeasure) { //move up?
          edgeoffset=this.dropmenuobj.contentmeasure+obj.offsetHeight;
          if ((this.dropmenuobj.y-topedge)<this.dropmenuobj.contentmeasure) //up no good either?
            edgeoffset=this.dropmenuobj.y+obj.offsetHeight-topedge;
        }
      }
      return edgeoffset
    },
    
    dropit:function(obj, e, dropmenuID) {
      if (this.dropmenuobj!=null) {//hide previous menu
        this.dropmenuobj.style.visibility="hidden" //hide menu
        deg.Css.removeClass(deg.DropDownNavBar.getDropDownParentA(this.dropmenuobj),"hover");
        if (deg.DropDownNavBar.Chrome.iectlfix) {document.getElementById(this.dropmenuobj.id + "_iframe").style.visibility="hidden";}
      }
      this.clearhidemenu();
      if (this.ie||this.firefox){
        obj.onmouseout=function(){deg.DropDownNavBar.Chrome.delayhidemenu()};
        obj.onclick=function(){return !deg.DropDownNavBar.Chrome.disablemenuclick}; //disable main menu item link onclick?
        this.dropmenuobj=document.getElementById(dropmenuID);
        this.dropmenuobj.onmouseover=function(){deg.DropDownNavBar.Chrome.clearhidemenu()};
        this.dropmenuobj.onmouseout=function(e){deg.DropDownNavBar.Chrome.dynamichide(e)};
        this.dropmenuobj.onclick=function(){deg.DropDownNavBar.Chrome.delayhidemenu()};
        this.showhide(this.dropmenuobj, e);
        this.dropmenuobj.x=this.getposOffset(obj, "left");
        this.dropmenuobj.y=this.getposOffset(obj, "top");
        this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj, "rightedge")+"px";
        this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px";
        if (this.enableswipe) {
          this.dropmenuobj.style.top=(parseInt(this.dropmenuobj.style.top) - parseInt(this.dropmenuobj.offsetHeight) + this.swipestep) + "px";
        }
        if (deg.DropDownNavBar.Chrome.iectlfix) {
          document.getElementById(this.dropmenuobj.id + "_iframe").style.left=(this.dropmenuobj.x-this.clearbrowseredge(obj, "rightedge"))+"px";
          document.getElementById(this.dropmenuobj.id + "_iframe").style.top=this.dropmenuobj.y-this.clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px";
        }
      }
    },
    
    contains_firefox:function(a, b) {
      while (b.parentNode)
        if ((b = b.parentNode) == a)
          return true;
      return false;
    },
    
    dynamichide:function(e){
      var evtobj=window.event? window.event : e
      if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement))
        this.delayhidemenu();
      else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
        this.delayhidemenu();
    },
    
    delayhidemenu:function(){
      this.delayhide=setTimeout("deg.DropDownNavBar.Chrome.hidedropdown()",this.disappeardelay) //hide menu
    },
    
    hidedropdown:function() {
      if (deg.DropDownNavBar.Chrome.iectlfix) {document.getElementById(deg.DropDownNavBar.Chrome.dropmenuobj.id+"_iframe").style.visibility="hidden";}
      deg.DropDownNavBar.Chrome.dropmenuobj.style.visibility='hidden';
      deg.Css.removeClass(deg.DropDownNavBar.getDropDownParentA(deg.DropDownNavBar.Chrome.dropmenuobj),"hover");
    },
    
    clearhidemenu:function(){
      if (this.delayhide!="undefined");
      clearTimeout(this.delayhide,this.disappeardelay);
    },
    
    startchrome:function(){
      for (var ids=0; ids<arguments.length; ids++){
      var chromeObject = (typeof(arguments[ids])=="object") ? (arguments[ids]) : (document.getElementById(arguments[ids]));
      var menuitems=chromeObject.getElementsByTagName("a");
        for (var i=0; i<menuitems.length; i++){
          if (menuitems[i].getAttribute("rel")) {
            var relvalue=menuitems[i].getAttribute("rel");
            menuitems[i].onmouseover= function(e) {
                var event=typeof e!="undefined"? e : window.event
                deg.DropDownNavBar.Chrome.dropit(this,event,this.getAttribute("rel"));
              }
          }
        }
      }
    }
  }
}
;
addDOMLoadEvent(deg.DropDownNavBar.init);
;


/**
 *
 * @pseudoCSS deg_popup      
 *              should be in a A element
 *            deg_expand
 *              should be in a A element, together with the corresponding REL attribute
 *              refering to the ID or the NAME of the element(s) to expand/collapse   
 */      
  
  
deg.UIEvents = {
  
  init:function() {
    //deg.UIEvents.Focus.init();
    deg.UIEvents.Popup.init();
    deg.UIEvents.Expand.init();
  },
  
  attachEventCSS:function(element, addEvent, removeEvent, stylesheet) {
      deg.addEvent(element, addEvent,    function(evt) {deg.Css.addClass(this, stylesheet);});
      deg.addEvent(element, removeEvent, function(evt) {deg.Css.removeClass(this, stylesheet);});
  },
  
  Focus: {
  
    STYLESHEET: "focus",
    ELEMENTS:   ["A", "INPUT", "TEXTAREA", "SELECT"],      
          
    init:function() {
      for (var a=0; a<deg.UIEvents.Focus.ELEMENTS.length; a++) {
        var els = document.getElementsByTagName(deg.UIEvents.Focus.ELEMENTS[a]);
        deg.UIEvents.Focus.applyToElements(els);
      }
    },
    
    applyToElements:function(obj) {
      if (obj==null) return;
      if (typeof(obj)!="object") return;
      if (obj.length) {
        for (var i=0; i<obj.length; i++) deg.UIEvents.Focus.applyToElements(obj[i]);
      } else {
        if (!obj.nodeName) return;
        deg.UIEvents.attachEventCSS(obj, "focus", "blur", deg.UIEvents.Focus.STYLESHEET);
      }
    }
  },
  
  Popup: {
  
    STYLESHEET:        "deg_popup",
    PARAM__NO_NAV:     "deg__nonav_",
	PARAM__IMG_FIT:    "deg__imgfit",
    PARAM__SIZE:       "\\bdeg__size_(\\d+)x(\\d+)\\b",
    
    DEFAULT_HEIGHT:    "400",
    DEFAULT_WIDTH:     "800",
    OPTIONS__DEFAULT:  "resizable,top=10,left=0,status=yes,toolbar=yes,menubar=yes,location=yes,scrollbars=yes",
    OPTIONS__NONAV:    "resizable,top=10,left=0,status=yes,toolbar=no,menubar=yes,location=no,scrollbars=yes",
    OPTIONS__NONAVFIT: "resizable,top=5,left=0,status=no,toolbar=no,menubar=no,location=no,scrollbars=no",

    TARGET_PREFIX:     "degPopUp",
    VISITED_STYLE:     "visited",
             
    init:function() {
      var elems;
      elems=document.getElementsByTagName("A");
      for (var i=0; i<elems.length; i++)
        if (deg.Css.containsClass(elems[i], deg.UIEvents.Popup.STYLESHEET))
          deg.UIEvents.Popup.applyToElement(elems[i]);
      elems=document.getElementsByTagName("FORM");
      for (var i=0; i<elems.length; i++)
        if (deg.Css.containsClass(elems[i], deg.UIEvents.Popup.STYLESHEET))
          deg.UIEvents.Popup.applyToElement(elems[i]);
    },
    
    applyToElement:function(obj) {
      if (obj==null) return;
      if (typeof(obj)!="object") return;
      if (!obj.nodeName) return;
      // for A elements
      if (obj.nodeName=="A") {
        deg.addEvent(obj, "click", function(evt) {
        			   deg.Css.addClass(this, deg.UIEvents.Popup.VISITED_STYLE);
                                   var re = new RegExp(deg.UIEvents.Popup.PARAM__SIZE);
                                   var m = re.exec(this.className);
                                   var theWidth = deg.UIEvents.Popup.DEFAULT_WIDTH;
                                   var theHeight = deg.UIEvents.Popup.DEFAULT_HEIGHT;
                                   if (m != null) {
                                     try {
                                      theWidth = m[1];
                                      theHeight = m[2];
                                     } catch (e) {alert ("Error in regex: " + e);}
                                   }

                                   var wopts = null;

								// update popup size to fit to image width and height
								   if (deg.Css.containsClass(this, deg.UIEvents.Popup.PARAM__IMG_FIT) )
									{
										/***  IMS 2289 & 3233 - 2007 june     **/
										wopts = (deg.UIEvents.Popup.OPTIONS__NONAVFIT );
										var ip = new ImagePreloader(this.href, onPreload, wopts);	
										
									}else
									{
									    var exists_param_no_nav = deg.Css.containsClass(this, deg.UIEvents.Popup.PARAM__NO_NAV);
										wopts = (exists_param_no_nav) ? (deg.UIEvents.Popup.OPTIONS__NONAV ) : (deg.UIEvents.Popup.OPTIONS__DEFAULT ) ;

										wopts= wopts+ ",width=" + theWidth + ",height=" + theHeight;
										window.open(this.href, this.target,wopts); 
									}
									
                                   evt.preventDefault();
                                   return false;
                                 });
      }
      // for FORM elements
      if (obj.nodeName=="FORM") {
        // add a unique target if not yet defined
        if (!obj.target || obj.target=="") {
          obj.target = deg.UIEvents.Popup.TARGET_PREFIX + ((new Date()).getTime());
        }
        deg.addEvent(obj, "submit", function(evt) {
                                   var re = new RegExp(deg.UIEvents.Popup.PARAM__SIZE);
                                   var m = re.exec(this.className);
                                   var theWidth = deg.UIEvents.Popup.DEFAULT_WIDTH;
                                   var theHeight = deg.UIEvents.Popup.DEFAULT_HEIGHT;
                                   if (m != null) {
                                     try {
                                      theWidth = m[1];
                                      theHeight = m[2];
                                     } catch (e) {alert ("Error in regex: " + e);}
                                   }
                                   var wopts =  (!deg.Css.containsClass(this, deg.UIEvents.Popup.PARAM__NO_NAV)) ? (deg.UIEvents.Popup.OPTIONS__DEFAULT + ",width=" + theWidth + ",height=" + theHeight) : (deg.UIEvents.Popup.OPTIONS__NONAV + ",width=" + theWidth + ",height=" + theHeight);
                                   window.open('', this.target, wopts); 
                                   return true;
                                });
      }
      
    }
    
  },
  
  Expand: {
    STYLESHEET:        "deg_expand",
    STYLE_EXPANDED:    "deg__expanded_",
    STYLE_COLLAPSED:   "deg__collapsed_",
    ELEMENTS:          ["A"], 
    
    init:function() {
      for (var a=0; a<deg.UIEvents.Focus.ELEMENTS.length; a++) {
        var els = document.getElementsByTagName(deg.UIEvents.Focus.ELEMENTS[a]);
        for (var i=0; i<els.length; i++) {
          if (deg.Css.containsClass(els[i]), deg.UIEvents.Expand.STYLESHEET) {
            deg.UIEvents.Expand.applyToElements(els[i]);
          }
        }
      }
    },
    
    applyToElements:function(obj) {
      if (obj==null) return;
      if (typeof(obj)!="object") return;
      if (obj.length) {
        for (var i=0; i<obj.length; i++) deg.UIEvents.Expand.applyToElements(obj[i]);
      } else {
        if (!obj.nodeName) return;
        if (!obj.rel || obj.rel=="") return;
        if (!document.getElementById(obj.rel) && !document.getElementsByName(obj.rel)) return;
        deg.UIEvents.Expand.refreshElement(obj);
        deg.addEvent(obj, "click", function(evt) {
                                    // handle by name
                                    if (deg.Css.containsClass(this, deg.UIEvents.Expand.STYLE_COLLAPSED))  {
                                      deg.Css.removeClass(this, deg.UIEvents.Expand.STYLE_COLLAPSED);
                                      //deg.Util.sleep(50);
                                      deg.Css.addClass(this, deg.UIEvents.Expand.STYLE_EXPANDED);
                                    } else {
                                      deg.Css.removeClass(this, deg.UIEvents.Expand.STYLE_EXPANDED);
                                      //deg.Util.sleep(50);
                                      deg.Css.addClass(this, deg.UIEvents.Expand.STYLE_COLLAPSED);
                                    } 
                                    deg.UIEvents.Expand.refreshElement(this);
                                });
      }
    },
    
    refreshElement: function (obj) {
        if (!obj.nodeName) return;
        if (!obj.rel || obj.rel=="") return;
        if (!document.getElementById(obj.rel) && !document.getElementsByName(obj.rel)) return;
        var dObj = document.getElementById(obj.rel);
        // handle by name
        if (!dObj) {
          var dObs = document.getElementsByName(obj.rel);
          if (!dObs || dObs.length<1) return;
          for (i = 0; i<dObs.length; i++) {
            if (deg.Css.containsClass(obj, deg.UIEvents.Expand.STYLE_COLLAPSED))  {
              deg.Css.addClass(dObs[i], "hidden"); 
            } else if (deg.Css.containsClass(obj, deg.UIEvents.Expand.STYLE_EXPANDED)) {
              deg.Css.removeClass(dObs[i], "hidden"); 
            } else {
              deg.Css.addClass(obj, deg.UIEvents.Expand.STYLE_EXPANDED);
              deg.Css.removeClass(dObs[i], "hidden");
            }
          }
        // handle by Id
        } else {
            if (deg.Css.containsClass(obj, deg.UIEvents.Expand.STYLE_COLLAPSED))  {
              deg.Css.addClass(dObj, "hidden"); 
            } else if (deg.Css.containsClass(obj, deg.UIEvents.Expand.STYLE_EXPANDED)) {
              deg.Css.removeClass(dObj, "hidden"); 
            } else {
              deg.Css.addClass(obj, deg.UIEvents.Expand.STYLE_EXPANDED);
              deg.Css.removeClass(dObj, "hidden");
            }
        }
        if (deg.Util.IS_IE) deg.Util.sleep(300); // Fu**ing IE needs this delay to propperly refresh style display :-(
    }
    
  }
}
  
;
addDOMLoadEvent(deg.UIEvents.init);
;


/**
 *
 * @pseudoCSS deg_tree        
 *              should be in a UL element; will automatically be rendered as tree  
 * @pseudoCSS deg__singlebranch_  
 *              if in same UL as the deg_tree, one branch will be open at the same time only
 * @pseudoCSS deg__initclose_  
 *              if in same UL as the deg_tree, all branches that are not explicitly defined
 *              as deg__open_ or deg__closed_ will be changed to deg__closed_ 
 *
 */      
  
  
deg.TreeView = {
  
  STYLESHEET:           "deg_tree",
  PARAM__SINGLE_BRANCH: "deg__singlebranch_",
  PARAM__INIT_CLOSED:   "deg__initclose_",
  PARAM__ALLOW_BOUBLE:  "deg__allowbubble_",

  CSS_CLOSED_BRANCH:    "deg__closed_",
  CSS_OPEN_BRANCH:      "deg__open_",
  CSS_ACTIVE_ITEM:      "deg__active_",
  
  init:function() {
    var uls = document.getElementsByTagName("UL");
    for (var i=0; i<uls.length; i++) {
      if (deg.Css.containsClass(uls[i], deg.TreeView.STYLESHEET)) {
        deg.TreeView.applyToElement(uls[i], deg.Css.containsClass(uls[i], deg.TreeView.PARAM__SINLE_BRANCH), deg.Css.containsClass(uls[i], deg.TreeView.PARAM__INIT_CLOSED));
      }
    }
  },
  
  applyToElement:function(obj, singleBranched, initClosed) {
    if (obj==null) return false;
    if (typeof(obj)!="object") return false;
    if (!obj.nodeName) return false;
    if (!obj.nodeName=="UL") return false;
    deg.Css.addClass(obj, deg.TreeView.STYLESHEET); // add stylesheet if not yet existing
    if (singleBranched) deg.Css.addClass(obj, deg.TreeView.PARAM__SINLE_BRANCH); //add singlebranched parameter ...
    else deg.Css.removeClass(obj, deg.TreeView.PARAM__SINLE_BRANCH); // ... or remove it
    if (initClosed) deg.Css.addClass(obj, deg.TreeView.PARAM__INIT_CLOSED); //add initclosed parameter ...
    else deg.Css.removeClass(obj, deg.TreeView.PARAM__INIT_CLOSED); // ... or remove it
    // go for it ... !
    deg.TreeView.drawBranch(obj, initClosed);         //redraw tree
    deg.TreeView.attachEvents(obj);  //add events
  },
  
  /**
   *  initialise events for menu tab keyboard usage etc.
   */  
  drawBranch:function (parentElement, closeByDefault) {
    deg.Css.addClass(parentElement, "outline");
    var hide=true;
    if (deg.Css.containsClass(parentElement, deg.TreeView.STYLESHEET)) hide = false;
    else if (deg.Css.containsClass(parentElement.parentNode, deg.TreeView.CSS_OPEN_BRANCH)) hide=false;
    var lis = deg.Dom.getChildNodesByType(parentElement, "LI");
    for (var i=0; i<lis.length; i++) {
      //check if the node has children
      var uls = deg.Dom.getChildNodesByType(lis[i], "UL");
      var hasChildren=false;
      for (var ii=0; ii<uls.length; ii++) {
        var ullis = deg.Dom.getChildNodesByType(uls[ii], "LI");
        if (ullis.length>0) {
          hasChildren=true;
        }
        deg.TreeView.drawBranch(uls[ii], closeByDefault);
      }
      //change icon to open/close
      if (hasChildren && !(deg.Css.containsClass(lis[i], deg.TreeView.CSS_CLOSED_BRANCH) || deg.Css.containsClass(lis[i], deg.TreeView.CSS_OPEN_BRANCH))) {
          deg.Css.addClass(lis[i], ((closeByDefault) ? (deg.TreeView.CSS_CLOSED_BRANCH) : (deg.TreeView.CSS_OPEN_BRANCH)));
      }
      
      //hide/unhide
      for (var ii=0; ii<uls.length; ii++) {
        if (deg.Css.containsClass(lis[i], deg.TreeView.CSS_CLOSED_BRANCH)) deg.Css.addClass(uls[ii], "hidden");
        if (deg.Css.containsClass(lis[i], deg.TreeView.CSS_OPEN_BRANCH)) deg.Css.removeClass(uls[ii], "hidden");
      }
    }
    deg.Css.removeClass(parentElement, "outline");
  },
  
  attachEvents:function(parentElement) {
    var lis = deg.Dom.getChildNodesByType(parentElement, "LI");
    for (var i=0; i<lis.length; i++) {
      deg.addEvent(lis[i], "click", deg.TreeView.evtCloseOpenBranch);
      var uls = deg.Dom.getChildNodesByType(lis[i], "UL");
      for (var ii=0; ii<uls.length; ii++) {
        deg.TreeView.attachEvents(uls[ii]);
      }
    }
  },
  
  /**
   * activate a navigation item
   * @parameter elm    the li element     
   */         
   
  evtCloseOpenBranch:function (evt) {
    if (!evt) evt=windowns.event;
    if (evt.target) elem = evt.target;
    else if (event.srcElement) elem = event.srcElement;
    if (elem==this || deg.Css.containsClass(deg.TreeView.getRootUl(this), deg.TreeView.PARAM__ALLOW_BOUBLE)) {
      if (deg.Css.containsClass(this, deg.TreeView.CSS_OPEN_BRANCH)) {
        deg.Css.removeClass(this, deg.TreeView.CSS_OPEN_BRANCH);
        deg.Css.addClass(this, deg.TreeView.CSS_CLOSED_BRANCH);
      } else if (deg.Css.containsClass(this, deg.TreeView.CSS_CLOSED_BRANCH)) {
        if (deg.Css.containsClass(deg.TreeView.getRootUl(this), deg.TreeView.PARAM__SINGLE_BRANCH)) {
          deg.TreeView.closeAllChildren(this.parentNode);
        }
        deg.Css.removeClass(this, deg.TreeView.CSS_CLOSED_BRANCH);
        deg.Css.addClass(this, deg.TreeView.CSS_OPEN_BRANCH);
      }

      //deactivate all others and activate this one
      if (elem!=this && !deg.Css.containsClass(deg.TreeView.getRootUl(this), deg.TreeView.PARAM__ALLOW_BOUBLE)) {
        deg.TreeView.deactivateAllChildren(deg.TreeView.getRootUl(this));
        deg.Css.addClass(this, deg.TreeView.CSS_ACTIVE_ITEM);
      }
      //hide/unhide
      var uls = deg.Dom.getChildNodesByType(this, "UL");
      for (var ii=0; ii<uls.length; ii++) {
        if (deg.Css.containsClass(this, deg.TreeView.CSS_CLOSED_BRANCH)) deg.Css.addClass(uls[ii], "hidden");
        if (deg.Css.containsClass(this, deg.TreeView.CSS_OPEN_BRANCH)) deg.Css.removeClass(uls[ii], "hidden");
      }
      try {
        window.event.cancelBouble();
      } catch (e) {
        evt.stopPropagation();
      }
    }
  },
  
  /**
   * remove all "active" or "open" states recoursively from an element ongoing
   */         
  closeAllChildren:function(parentElement) {
    var lis = deg.Dom.getChildNodesByType(parentElement, "LI");
    for (var i=0; i<lis.length; i++) {
      if (deg.Css.containsClass(lis[i], deg.TreeView.CSS_OPEN_BRANCH)) {
        deg.Css.addClass(lis[i], deg.TreeView.CSS_CLOSED_BRANCH);
        deg.Css.removeClass(lis[i], deg.TreeView.CSS_OPEN_BRANCH);
      }
      var uls = deg.Dom.getChildNodesByType(lis[i], "UL");
      for (var ii=0; ii<uls.length; ii++) {
        deg.Css.addClass(uls[ii], "hidden");
        deg.TreeView.closeAllChildren(uls[ii]);
      }
    }
  },
  
  /**
   * remove all "active" or "open" states recoursively from an element ongoing
   */         
  openAllChildren:function(parentElement) {
    var lis = deg.Dom.getChildNodesByType(parentElement, "LI");
    for (var i=0; i<lis.length; i++) {
      if (deg.Css.containsClass(lis[i], deg.TreeView.CSS_CLOSED_BRANCH)) {
        deg.Css.addClass(lis[i], deg.TreeView.CSS_OPEN_BRANCH);
        deg.Css.removeClass(lis[i], deg.TreeView.CSS_CLOSED_BRANCH);
      }
      var uls = deg.Dom.getChildNodesByType(lis[i], "UL");
      for (var ii=0; ii<uls.length; ii++) {
        deg.Css.removeClass(uls[ii], "hidden");
        deg.TreeView.openAllChildren(uls[ii]);
      }
    }
  },
  
  /**
   * remove all "active" or "open" states recoursively from an element ongoing
   */         
  deactivateAllChildren:function(parentElement) {
    var lis = deg.Dom.getChildNodesByType(parentElement, "LI");
    for (var i=0; i<lis.length; i++) {
      if (deg.Css.containsClass(lis[i], deg.TreeView.CSS_ACTIVE_ITEM)) {
        deg.Css.removeClass(lis[i], deg.TreeView.CSS_ACTIVE_ITEM);
      }
      var uls = deg.Dom.getChildNodesByType(lis[i], "UL");
      for (var ii=0; ii<uls.length; ii++) {
        deg.TreeView.deactivateAllChildren(uls[ii]);
      }
    }
  },
  
  getRootUl:function (currentElement) {
    if (deg.Css.containsClass(currentElement, deg.TreeView.STYLESHEET)) return currentElement;
    return deg.TreeView.getRootUl(currentElement.parentNode);
  }
  
}
;
addDOMLoadEvent(deg.TreeView.init);
;

/**
 ===== Non regression functions ==========================================
 */

function openAttDocumentPopup(url) {
	window.open(url, "","width=600,height=330,status=no,toolbar=no,menubar=1,location=no,titlebar=no,scrollbars=1");
}

function openEditorialPopup(url) {
	window.open(url, "","top=0,left=0,width=600,height=450,status=no,toolbar=no,menubar=no,location=no,titlebar=no,scrollbars=1");
}

function logAccessAndPerform(logRDUrl, attachUrl) {
	window.open(logRDUrl, "windowFull", "width=800,height=440,status=yes,toolbar=yes,menubar=no,location=yes,resizable=yes,titlebar=yes,scrollbars=yes");
	//popupAttachUrl(attachUrl);
	//statLinkTo(attachUrl);
}

function popupAttachUrl(url){
	if (url != "") {
		window.open(url,"","top=0,left=0,width=820,height=560,menubar=yes,scrollbars=yes, toolbar=yes, location=yes");
	}
}

function popupAttachUrlWithoutNav(url){
  if (url != "") {
    window.open(url,"","top=0,left=0,width=820,height=560,menubar=yes,scrollbars=yes, toolbar=no");
  }
}

/***  start IMS 3233 - 07/06/2007     **/

ImagePreloader.prototype.onComplete = function(){
	// execute function onPreload
	this.call_back(this.myImg, this.option);
}

ImagePreloader.prototype.onload = function(){	   
	this.bLoaded = true;
	this.oImagePreloader.onComplete();
}

ImagePreloader.prototype.onerror = function(){
	this.bError = true;	 
	this.oImagePreloader.onComplete();
}	

ImagePreloader.prototype.onabort = function(){
	this.bAbort = true;
	this.oImagePreloader.onComplete();	
}

ImagePreloader.prototype.preload = function(image){	   
	// create new Image object and add to array	 
	var oImage = new Image();	
	this.myImg = oImage;
	// set up event handlers for the Image object	
	oImage.onload = ImagePreloader.prototype.onload;
	oImage.onerror = ImagePreloader.prototype.onerror;
	oImage.onabort = ImagePreloader.prototype.onabort;	
	// assign pointer back to this.	 
	oImage.oImagePreloader = this;
	oImage.bLoaded = false;	   // assign the .src property of the Image object
	oImage.src = image;
}

function ImagePreloader(path, call_back, option)	
{
	// store the call_back
	this.call_back = call_back;
	// initialize internal state.	  
	this.myImg = new Image();
	this.option = option;

	this.preload(path);
}	

function onPreload(myImg, option)	
{	
	if(myImg.width>myImg.height && myImg.width>600)
	{											
		myImg.height=myImg.height*(600/myImg.width);
		myImg.width=600;
		theWidth = myImg.width+36;
		theHeight = myImg.height+35;
	}/*else if(myImg.width<myImg.height && myImg.height>600)
	{											
		myImg.width=myImg.width*(600/myImg.height);				
		myImg.height=600;

	}*/ else {
		theWidth = myImg.width+20;
		theHeight = myImg.height+20;
	}

	option = option+ ",width=" + theWidth + ",height=" + theHeight;
	window.open(myImg.src,'wf',option);
	return;
}

/***  end IMS 3233 - 07/06/2007     **/