/*
 *
 * File:      $RCSfile: si_pglayout_b.js,v $
 * Version:   $Revision: 1.0 $
 * Revised:   $Date:  $
 *            $Author: mbm $
 *
 * Created:   2006-06-01
 * Author:    sectra:mbm
 * Project:   Web
 *
 *
 * Description
 *   Scripted page layout.
 *
 * Compatibility:
 *   See si_pglayout.js.
 *
 * Dependencies:
 *   si_pglayout.js
 *
 * General comments:
 *   See si_pglayout.js.
 */



/****************************************************************************
 *
 * GENERAL FUNCTIONS
 *
 */

/*
 * sip_contains()
 *   Tests if a given item is present in a bag.
 *
 * In:
 *   bag:  bag to scan
 *   item: item to look for
 *
 * Returns
 *   Returns true if the item is present, otherwise false.
 */

function sip_contains(bag, item)
{
  for(var i=0; bag!=null && i<bag.length; i++)
  {
    if(bag[i]==item)
      return(true);
  }
  return(false);
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_stripTags(html)
{
  return(html.replace(/[\n\r]+/g, ' ').replace(/<[^>]*>/g, '').replace(/&nbsp;/g, ' ').replace(/^\s+/g, '').replace(/\s+$/g, ''));
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_getOuterHTML(elem)
{
  if(elem.outerHTML != null)
    return(elem.outerHTML);
  else
  {
    var html = '<' + elem.tagName + sip_mkAttributeString('class', elem.className) + '>' + elem.innerHTML + '</' + elem.tagName + '>';
    return(html);
  }
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_parseFloat(value)
{
  value=value.replace(/[\s,:]+/g, '');
  if(value=='')
    return(Number.NEGATIVE_INFINITY);
  else
    return(parseFloat(value));
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_parseDate(value)
{
  value=value.replace(/ +/g, ' ');
  if(value=='' || value==' ')
    return(-1);
  value = Date.parse(value);
  
  // Stupid Opera returns todays date as a number when called with a non-date formatted string. Test for it:
  if(DETECT.is_opera && value==Date.parse(''))
    value=Number.NaN;
  return(value);
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_pathIsDynamic(path)
{
  return(path.indexOf('.php')!=-1 || path.indexOf('/cgi-bin/')!=-1);
}


/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_isCurrentLink(href)
{
  var pos = SIP_GLOBAL.curURL.indexOf(href);
  return((pos!=-1) && (pos==SIP_GLOBAL.curURL.length-href.length))
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

// To be retired!
function sip_getLinkHref(linkElem)
{
  return(linkElem.getAttribute('href', 2));

//  if(DETECT.is_ie && linkElem.href!=null)
//    return(linkElem.outerHTML.replace(/.*href=["']?([^'" >]*).*/, '$1'));
//  else
//    return(linkElem.href);
//
}




/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_getWindowName()
{
  if(!window.name)
    window.name='sectra' + ('' + Math.random()).substr(2);
  return(window.name);
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_getCurrentZone()
{
  if(SIP_GLOBAL.curZone)
    return(SIP_GLOBAL.curZone);

  var zone = null;
  var bodyClass = window.document.body.className;
  var re=/.*\b(.*)zone\b.*/;
  if(bodyClass!=null && bodyClass.match(re))
    zone = bodyClass.replace(re, '$1');
  if(!zone)
  {
    // Get the zone from the URL (top folder name):
    zone = sip_getCurrentPath();
    var re = /\/([^\/]*)\/.*/;
    if(zone.match(re))
      zone=zone.replace(re, '$1');
    else
      zone = '/';
  }
  
  // The top home page is a special case; it belongs to the "corporate" zone 
  // although it's not located there:
  if(zone == '/')
    zone=SIP_CONST.ZONE.NAMES[0];
  
  // If the top folder name of the URL does not match one of the "global zones",
  // it's one of the common folder trees. Get the last visited zone (if any) 
  // from cookie:
  var id = sip_getWindowName();
  if(!sip_contains(SIP_CONST.ZONE.NAMES, zone))
  {
    zone=sip_getCookie(id + 'sip_lastzone');
    // No previously visited zone in this window or tab, but we might know 
    // about a current zone from another window or tab (the URL might be 
    // opened in a new window or tab):
    if(!zone)
      zone=sip_getCookie('sip_lastzone');
  }
  if(zone)
  {
    // Remember the current zone for this window and for any window:
    sip_setCookie(id + 'sip_lastzone', zone);
    sip_setCookie('sip_lastzone', zone);
  }
  else
    zone=SIP_CONST.ZONE.NONAME;
  SIP_GLOBAL.curZone=zone;
  return(zone);
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_setCookie(name, value, persistent)
{
  name=sip_mkId(name);
  var expires;
  if(persistent)
    expires="expires=" + (new Date((new Date()).getTime() + 86400 * 30 * 1000)).toGMTString() + "; ";
  else
    expires='';
  document.cookie = name + "=" + escape(value) + "; " + expires + "path=/";
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_rmCookie(name, _allowDirtyName)
{
  if(!_allowDirtyName)
    name=sip_mkId(name);
  document.cookie = name + "=; expires=Mon, 1 Jan 1990 00:00:00 UTC; path=/";
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_rmAllCookies()
{
  var cookies = document.cookie.split("; ");
  var count = 0;
  for (var i=0; i < cookies.length; i++)
  {
    if(cookies[i])
    {
      var crumb = cookies[i].split("=");
      sip_rmCookie(crumb[0], true);
      count++;
    }
  }
  return(count);
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_getCookie(name)
{
  name=sip_mkId(name);
  var cookie = document.cookie.split("; ");
  for (var i=0; i < cookie.length; i++)
  {
    var crumb = cookie[i].split("=");
    if (name == crumb[0])
    {
      var rc = unescape(crumb[1]);
      if(rc=='null')
        rc=null;
      return(rc);
    }
  }
  return(null);
}




/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_rmClass(element, className)
{
  element.className=element.className.replace(new RegExp('\\b' + className + '\\b\\s*'), '').replace(/ +/, ' ');
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_addClass(element, className)
{
  if(element.className!=null && !element.className.match(new RegExp('\\b' + className + '\\b')))
    element.className += (element.className ? ' ' : '') + className;
}


/*
 * sip_getPosition()
 *   Returns the position of a relatively or absolutely positioned object.
 *
 * In:
 *   obj:      DOM object
 *   vertical: true to retrieve the top position; false to retrieve the left position
 *
 * Returns:
 *   the postion (px) or 0 (zero) if not available
 */


function sip_getPosition(obj, vertical)
{
  var offset={x: 0, y: 0};

  while(obj!=null && obj.tagName!=null && obj.style!=null)
  {
    if((obj.style!=null) && (obj.style.position=="absolute"))
    {
      // In NS6, this might be '0pt' although set to '0px'!
      offset.x+=1*obj.style.left.replace(/\w+$/, '');
      offset.y+=1*obj.style.top.replace(/\w+$/, '');
      
      if(obj.parentNode!=null)
        obj=obj.parentNode;
      else
        obj=obj.parentElement;
    }
    else
    {
      offset.x+=obj.offsetLeft;
      offset.y+=obj.offsetTop;

      if(obj.offsetParent!=null)
        obj=obj.offsetParent;
      else if(obj.parentNode!=null)
        obj=obj.parentNode;
      else
        obj=obj.parentElement;
    }
  }

  switch(vertical)
  {
    case 2:
      return(offset);
    case 1:
    case true:
      return(offset.y);
    default:
      return(offset.x);
  }
}




/*
 * sip_getDimension()
 *   Returns the dimension of a relatively or absolutely positioned object.
 *
 * In:
 *   obj:      DOM object
 *   vertical: true to retrieve the object width; false to retrieve the object height
 *
 * Returns:
 *   the dimension (px) or 0 (zero) if not available
 */

function sip_getDimension(obj, vertical)
  {
    var offset=0;

    if(obj!=null && obj.style!=null)
    {
      if(false && obj.tagName=="DIV") 
        offset=1*(vertical?obj.style.height:obj.style.width).replace(/\w+$/, '');
      else if(obj.tagName!="TBODY")
        offset=vertical?obj.offsetHeight:obj.offsetWidth;
    }
    return(offset);
 }




/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_setElementId(element)
{
  if(!element.id)
  {
    if(element.parentNode!=null)
    {
      var index;
      for(index=0; index<element.parentNode.childNodes.length; index++)
      {
        if(element.parentNode.childNodes[index]==element)
          break;
      }
      element.id=sip_setElementId(element.parentNode) + '_' + element.tagName + index;
    }
    else
      element.id='root';
  }
  return(element.id);
}




/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_showElement(element, show)
{
  if(show==null)
    show=true;

  if(element!=null)
  {
    if(DETECT.is_gecko)
      setTimeout('window.document.getElementById("' + sip_setElementId(element) + '").style.visibility="' + (show?'visible':'hidden') + '"', 10);
    else
      element.style.visibility = show?'visible':'hidden';
  }
}




/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_scrolledIntoView(node, scroller)
{
  scroller = scroller != null ? scroller : window.document.html;
  var pos = sip_getPosition(node, 2);
  return(pos.y > scroller.scrollTop && pos.y < scroller.clientHeight + scroller.scrollTop);
}


/*
 * sip_getCaption()
 *   Returns a reasonable caption for the given element, can be one of
 *   a) element title
 *   b) element alt
 *   c) element inner html (with tags removed)
 *   tested in the order above, or:
 *   d) child title
 *   e) child inner html (with tags removed)
 *   f) child alt
 *
 * In:
 *   elem:        element
 *   defaultText: text returned if no suitable caption could be found
 *
 * Returns
 *   Caption text
 */

function sip_getCaption(elem, defaultText)
{
  if(elem.title)
    return(elem.title);
  if(elem.alt)
    return(elem.alt);
    
  var patterns = [/.*title="([^"]*)".*/g, /([^<>]*)(<[^>]*>)?/g, /.*alt="([^"]*)".*/g];
  for(var i=0; i<patterns.length; i++)
  {
    if(elem.innerHTML.match(patterns[i]))
    {
      var caption = elem.innerHTML.replace(patterns[i], '$1').replace(/[\s]+/g, ' ');
      if(caption.match(/[a-z]+/i))
        return(caption);
    }
  }

  return(defaultText);
}


/*
 * sip_getBgImage()
 *   Returns the URL of the background image.
 *
 * In:
 *   - element: element to query
 *
 * Returns:
 *   URL of the background image, if any, or NULL.
 */

function sip_getBgImage(element)
{
  var url=null;
  // Use getComputedStyle() for compliant browsers:
  if(document.defaultView && document.defaultView.getComputedStyle)
  {
    var computedStyle = document.defaultView.getComputedStyle(element, null);
    if(computedStyle!=null)
      url = computedStyle.getPropertyValue('background-image');
  }
  // Use currentStyle for IE:
  else if(element.currentStyle!=null)
    url=element.currentStyle.backgroundImage;
  
  // Return the found URL, if any:
  if(url && url!="none")
    return(url);
  else
    return(null);
}



/*
 * sip_setImageURL()
 *   Sets the image URL of an <IMG> element or the background image URL of 
 *   an element of another type.
 * 
 * In:
 *   - element: element to query.
 *   - url:     new image URL to set.
 */

function sip_setImageURL(element, url)
{
  if((element==null)||(url==null))
    return;
  if(element.tagName=='IMG' || (element.tagName=='INPUT' && element.src!=null && element.src!=''))
    element.src=url;
  else
    element.style.backgroundImage=url;
}




/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_add2ImageCache(imgUrl)
{
  if(SIP_GLOBAL.imageCache.push==null)
    return;

  imgUrl = imgUrl.replace(/url\(["']*([^"']*)["']*\)/i, '$1');
  for(var i=0; i<SIP_GLOBAL.imageCache.length; i++)
  {
    if(SIP_GLOBAL.imageCache[i].src==imgUrl)
      return;
  }
  var img = new Image();
  img.src = imgUrl;
  SIP_GLOBAL.imageCache.push(img);
}



/*
 * sip_mkAutoHovers()
 *   Sets links/image hover actions on a link element.
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_setAutoHoverScripts(hoverElem, imgElement, imgUrl, _index)
{
  /*
   * Install mouse handlers only of not already installed; the use of a kilroy 
   * flag however enables updating the hover scripts later, should the images 
   * have changed.
   */
  if((hoverElem.onmouseover==null 
      && hoverElem.onmouseout==null 
      && hoverElem.parentNode.onmouseover==null 
      && hoverElem.parentNode.onmouseout==null
     ) 
     || 
     hoverElem.sip_hoverkilroy)
  {
    hoverElem.sip_hoverkilroy=true;

    if(_index==null)
      _index='';

    // Catch mouse over; set hover image:
    hoverElem.onmouseover=function()
    {
      // [c1]
      if(window.sip_setImageURL!=null)
        window.sip_setImageURL(imgElement, imgUrl.replace(/\bdefault\b/, 'hover' + _index));

      if(imgElement.tagName=='INPUT' && window.sip_addClass!=null)
        window.sip_addClass(imgElement, SIP_CONST.ACTIVE_LINKS.BTN_HOVER_CLASS_NAME);
    }

    // Catch mouse out; reset to default image:
    hoverElem.onmouseout=function()
    {
      // [c1]
      if(window.sip_setImageURL!=null)
        window.sip_setImageURL(imgElement, imgUrl.replace(/\bhover[0-9]*\b/, 'default'));

      if(imgElement.tagName=='INPUT' && window.sip_rmClass!=null)
        window.sip_rmClass(imgElement, SIP_CONST.ACTIVE_LINKS.BTN_HOVER_CLASS_NAME);
    }

    sip_add2ImageCache(imgUrl.replace(/\bdefault\b/, 'hover' + _index));
  }
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_addLinkIndicator(linkElem, className, title)
{
  if(linkElem.getElementsByTagName 
     && linkElem.getElementsByTagName("IMG").length==0 
     && !linkElem.parentNode.className.match(SIP_CONST.ACTIVE_LINKS.SKIP_CLASS_PATTERN))
  {
    if(title)
      linkElem.title=title;
    sip_addClass(linkElem, className);
  }
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_mkPopupLink(linkElem)
{
  linkElem.onclick=function()
  {
    var url = this.href;

    // Parse attributes from the URL:
    var attribs = url.split('?')[1];
    url = url.split('?')[0];

    if(url && url.match(SIP_CONST.ACTIVE_LINKS.POPUP.SELECT.FILE_PATTERN))
    {
      var title   = sip_getCaption(this, 'Sectra');
      var height  = window.screen.height - SIP_CONST.ACTIVE_LINKS.POPUP.WINDOW.V_MARGIN*2;
      var width   = Math.min(SIP_CONST.ACTIVE_LINKS.POPUP.WINDOW.MIN_WIDTH, window.screen.width - SIP_CONST.ACTIVE_LINKS.POPUP.WINDOW.H_MARGIN*2);

      var ctrls;

      if(url.match(SIP_CONST.ACTIVE_LINKS.POPUP.SELECT.IMG_FILE_PATTERN))
      {
        ctrls    = 'yes';
        scrolls  = 'yes';
        url      = '/common/launch/image?url=' + url + '&title=' + title + (attribs ? '&' + attribs : '');
      }
      else if(url.match(SIP_CONST.ACTIVE_LINKS.POPUP.SELECT.MOVIE_FILE_PATTERN))
      {
        height   = 551;
        ctrls    = 'no';
        scrolls  = 'no';
        url      = '/common/launch/movie?url=' + url + '&title=' + title + (attribs ? '&' + attribs : '');
      }
      else
      {
        ctrls    = 'no';
        scrolls  = 'no';
      }

      /*
       * 'location' and 'status' would preferably be turned off, but due to 
       * idiocratic security enforcements in IE (XP SP2 ++) these are 
       * displayed for most of the audience anyway. Thus, it's most consistent 
       * to leave them showing for everyone.
       */
      var top     = SIP_CONST.ACTIVE_LINKS.POPUP.WINDOW.V_MARGIN;
      var left    = Math.floor((window.screen.width - width) / 2);
      var options = 'dependent=no,directories=no,hotkeys=no,resizable=yes,titlebar=yes'
                  + ',location=' + ctrls
                  + ',status=' + ctrls
                  + ',menubar=' + ctrls
                  + ',toolbar=' + ctrls
                  + ',scrollbars=' + scrolls
                  + ',screenX='+ left
                  + ',screenY=' + top
                  + ',left=' + left
                  + ',top=' + top
                  + ',outerWidth=' + width
                  + ',outerHeight=' + height
                  + ',width=' + width
                  + ',height=' + height;
      var target = this.target ? this.target : SIP_CONST.ACTIVE_LINKS.POPUP.WINDOW.NAME;
      var win = window.open(url, target, options);
      try 
      {
        win.resizeTo(width, height);
      }
      catch(excp){}
      return(false);
    }
    else
      return(true);
  }

  var ttPrefix;
  if(linkElem.href.match(SIP_CONST.ACTIVE_LINKS.POPUP.SELECT.IMG_FILE_PATTERN))
    ttPrefix = 'Image ';
  else if(linkElem.href.match(SIP_CONST.ACTIVE_LINKS.POPUP.SELECT.MOVIE_FILE_PATTERN))
    ttPrefix = 'Movie ';
  else
    ttPrefix = 'Document ';

  sip_addLinkIndicator(linkElem, SIP_CONST.ACTIVE_LINKS.POPUP.CLASS_NAME, ttPrefix + SIP_CONST.ACTIVE_LINKS.POPUP.TITLE);
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_mkExternalLink(linkElem)
{
  sip_addLinkIndicator(linkElem, SIP_CONST.ACTIVE_LINKS.EXTERNAL.CLASS_NAME, SIP_CONST.ACTIVE_LINKS.EXTERNAL.TITLE);
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_mkSplashLink(linkElem)
{
  linkElem.onclick=function()
  {
    try
    {
      sip_splashBox(linkElem.href);
      return(false);
    }
    catch(excp)
    {
      return(false);
    }
  }
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */



function sip_mkActiveLink(linkElem)
{
  var linkHref = null;

  if(linkElem.href!=null && linkElem.href!='')
  {
    /*
     * Get the link URL and normalize it:
     */
    linkHref = sip_getLinkHref(linkElem);
    if(linkHref==null || linkHref.charAt(0)=='#')
      return;

    linkHref   = sip_stripUrl(linkElem.href);
  }

  /*
   * Get the element holding the image and the URL of that image:
   */
  var imgElement = linkElem.getElementsByTagName('IMG')[0];
  var imgUrl     = null;

  if(imgElement==null)
    imgElement = linkElem.parentNode.getElementsByTagName('IMG')[0]

  if(imgElement!=null)
    imgUrl=imgElement.src;

  if(imgUrl==null)
  {
    imgElement = linkElem;
    imgUrl     = sip_getBgImage(imgElement);
  }

  if(imgUrl==null)
  {
    imgElement = linkElem.parentNode;
    imgUrl     = sip_getBgImage(imgElement);
  }

  if(imgUrl==null)
  {
    imgElement = linkElem.getElementsByTagName('SPAN')[0];
    if(imgElement!=null)
      imgUrl   = sip_getBgImage(imgElement);
  }

  
  /*
   * 
   */
  if(linkHref!=null && sip_isCurrentLink(linkHref) && !sip_isClass(linkElem, 'pageindex'))
  {
    // This is a link to the current page; set 'current' properties:  
    if(imgUrl && imgUrl.indexOf(SIP_CONST.ACTIVE_LINKS.DECORATION.ACTIVE_IMG_PATTERN)!=-1)
      sip_setImageURL(imgElement, imgUrl.replace(/\bdefault\b/, 'active'));

    sip_addClass(linkElem, SIP_CONST.ACTIVE_LINKS.DECORATION.CURRENT_PAGE_CLASS);
  }
  else if(imgUrl && imgUrl.indexOf(SIP_CONST.ACTIVE_LINKS.DECORATION.ACTIVE_IMG_PATTERN)!=-1)
  {
    // Set the hover/out image scripts:
    sip_setAutoHoverScripts(linkElem, imgElement, imgUrl);
  }

  
  // Trap image load errors; reset to default image if error is called:
  if(imgElement!=null)
  {
    imgElement.onerror = function()
    {
      // Avoid posting events to itself in case of error loading default image:
      if(!imgElement.src.match(/\bdefault\b/) && linkElem.onmouseout!=null)
        linkElem.onmouseout();
    }
  }

  /*
   * Set script and link indicators for popup links (but only on links w/o images):
   */
  if(linkElem.href.match(SIP_CONST.ACTIVE_LINKS.POPUP.SELECT.FILE_PATTERN))
    sip_mkPopupLink(linkElem);

  /*
   * Set script for splash links:
   */
  if(linkElem.href.match(SIP_CONST.ACTIVE_LINKS.SPLASH.SELECT.FILE_PATTERN) && sip_getSiteTopWindow()==window)
    sip_mkSplashLink(linkElem);

  /*
   * Set link indicators for external links:
   */
  if(linkElem.href.match(SIP_CONST.ACTIVE_LINKS.EXTERNAL.SELECT.FILE_PATTERN))
    sip_mkExternalLink(linkElem);
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_mkActiveButton(buttonElem)
{
  if(buttonElem!=null)
  {
    var imgUrl = buttonElem.src;
    if(imgUrl==null || imgUrl=='')
      imgUrl = sip_getBgImage(buttonElem);

    if(imgUrl!=null && imgUrl.indexOf(SIP_CONST.ACTIVE_LINKS.DECORATION.ACTIVE_IMG_PATTERN)!=-1)
    {
      // Set the hover/out image scripts:
      sip_setAutoHoverScripts(buttonElem, buttonElem, imgUrl);
    }
  }
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_getRelatedMapImage(mapElem)
{
  if(mapElem.tagName=='AREA')
    mapElem = mapElem.parentNode;
  var mapName = mapElem.name;
  if(mapName==null)
    mapName = mapElem.id;
  mapName = '#' + mapName;

  var imgs = mapElem.parentNode.getElementsByTagName('IMG');

  for(var i=0; i<imgs.length; i++)
  {
    /*
     * In Opera the useMap parameter contains not only the map name but the
     * path to the page as well, strip away everytning preeding the '#' 
     * before comparing:
     */
    if(imgs[i].useMap.replace(/.*#/, '#')==mapName)
      return(imgs[i]);
  }
  return(null);
}




/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_mkActiveMap(mapElem)
{
  if(mapElem!=null)
  {
    var imgElement = sip_getRelatedMapImage(mapElem);
    if(imgElement==null)
      return;

    var imgUrl = imgElement.src;
    if(imgUrl!=null && imgUrl.indexOf(SIP_CONST.ACTIVE_LINKS.DECORATION.ACTIVE_IMG_PATTERN)!=-1)
    {
      var areas = mapElem.getElementsByTagName('AREA');
      for(var i=0; i<areas.length; i++)
      {
        // Set the hover/out image scripts:
        sip_setAutoHoverScripts(areas[i], imgElement, imgUrl, i);
      }
    }
  }
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_mkActiveLinksR(root)
{
  if(root==null)
    return;
  switch(root.tagName)
  {
    case 'IMG':
      sip_mkActiveLink(root.parentNode);
      break;
    case 'A':
      sip_mkActiveLink(root);
      break;
    case 'LI':
      sip_mkActiveLink(root);
      break;
    case 'INPUT':
      sip_mkActiveButton(root);
      break;
    case 'MAP':
      sip_mkActiveMap(root);
    default:
      var links = root.getElementsByTagName('A');
      for(var i=0; i<links.length; i++)
        sip_mkActiveLink(links[i]);
      var buttons = root.getElementsByTagName('INPUT');
      for(var i=0; i<buttons.length; i++)
        sip_mkActiveButton(buttons[i]);
      var maps = root.getElementsByTagName('MAP');
      for(var i=0; i<maps.length; i++)
        sip_mkActiveMap(maps[i]);
      break;
  }
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_mkActiveLinks()
{
  if(window.sip_linkskilroy==true)
    return;

  // Iterate all document body links and extra links from header etc:
  for(var i=0; i<SIP_CONST.ACTIVE_LINKS.ROOT_IDS.length; i++)
    sip_mkActiveLinksR(window.document.getElementById(SIP_CONST.ACTIVE_LINKS.ROOT_IDS[i]));
  
  window.sip_linkskilroy=document.links.length>0;
}


/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_updateHeaderImg(zone, image, imgUrl)
{
  if(image!=null && image.src!=null && image.src.indexOf(SIP_CONST.ZONE.NONAME)!=-1)
  {
    image.src=imgUrl;
    var areaLink = image.parentNode;
    if(areaLink.tagName=='A' && sip_getLinkHref(areaLink)!='#')
      areaLink.href='/' + zone + '/';
  }
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_mkHeader()
{
  var zone = sip_getCurrentZone();
  sip_updateHeaderImg(zone, 
                      window.document.getElementById(SIP_CONST.ZONE.INDICATOR_ID),
                      SIP_CONST.ZONE.INDICATOR_SRC.replace(/%zone%/, zone));
  sip_updateHeaderImg(zone, 
                      window.document.getElementById(SIP_CONST.ZONE.DROPMENU_ID), 
                      SIP_CONST.ZONE.DROPMENU_SRC.replace(/%zone%/, zone));
}




/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function _sip_getCompareValue(value, model)
{
  if(value.cache==null)
  {
    value.cache = sip_stripTags(value);
    if(model==Number)
      value.cache = sip_parseFloat(value.cache);
    else if(model==Date)
      value.cache = sip_parseDate(value.cache);
  }
  return(value.cache);
}




/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function _sip_compare(lhs, rhs, model, flip)
{
  lhs  = _sip_getCompareValue(lhs, model);
  rhs  = _sip_getCompareValue(rhs, model);
  flip = flip ? -1 : +1;

  if(lhs<rhs)
    return(-flip);
  if(lhs>rhs)
    return(+flip);
  else
    return(0);
}




/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 *
 *   http://en.wikipedia.org/wiki/Quicksort
 */

function _sip_qsortMatrix(matrix, column, model, flip)
{
  if(matrix.length <= 1)
     return(matrix);

  var pivot     = Math.floor(matrix.length/2);

  var less      = new Array();
  var pivotList = new Array(matrix[pivot]);
  var greater   = new Array();

  for(var i=0; i<matrix.length; i++)
  {
    if(i!=pivot)
    {
      if(_sip_compare(matrix[i][column], matrix[pivot][column], model, flip) < 0)
        less.push(matrix[i]);
      if(_sip_compare(matrix[i][column], matrix[pivot][column], model, flip) >= 0)
        greater.push(matrix[i]);
    }
  }

  return(_sip_qsortMatrix(less, column, model, flip).concat(pivotList).concat(_sip_qsortMatrix(greater, column, model, flip)));
}




/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function _sip_sortTable(table, column)
{
  var model        = Date;
  var tableContent = new Array();
  var rowClasses   = new Array();
  var rows         = table.getElementsByTagName('TR');
  var headingHTML  = '<tr>' + rows[0].innerHTML + '</tr>\n';
  var captionHTML  = table.getElementsByTagName('CAPTION');

  if(captionHTML.length>0)
    captionHTML = '<caption>' + captionHTML[0].innerHTML + '</caption>\n';
  else
    captionHTML = '';

  for(var ri=0; ri<rows.length; ri++)
  {
    if(ri>0)
    {
      var rowContent = new Array();
      var cols       = rows[ri].childNodes;
      var cellIndex  = 0;
      
      for(var ci=0; ci<cols.length; ci++)
      {
        if(cols[ci].tagName)
        {
          rowContent.push(new String(sip_getOuterHTML(cols[ci])));
          if(cellIndex==column)
          {
            if(model == Date && isNaN(sip_parseDate(sip_stripTags(cols[ci].innerHTML))))
              model=Number;
            if(model == Number && isNaN(sip_parseFloat(sip_stripTags(cols[ci].innerHTML))))
              model=String;
          }
          cellIndex++;
        }
      }
      tableContent.push(rowContent);
    }
    rowClasses.push(rows[ri].className);
  }

  var flip = table._sip_sortCol == column && !table._sip_sortFlip;

  // Now, lets do the sort!
  tableContent = _sip_qsortMatrix(tableContent, column, model, flip);

  // Join row cells together into row strings:
  for(var ri=0; ri<tableContent.length; ri++)
    tableContent[ri] = tableContent[ri].join('');
  
  // Table rows together into table content string:
  var html = captionHTML + headingHTML + '<tr>' + tableContent.join('</tr><tr>') + '</tr>';

  if(DETECT.is_ie)
  {
    // IE can't handle table.innerHTML, we have to replace the whole table:
    var refElem=table.previousSibling;
    table.outerHTML = '<table' + sip_mkAttributeString('class', table.className) + '>' + html + '</table>';
    table = refElem.nextSibling;
  }
  else
    table.innerHTML = html;

  var rows = table.getElementsByTagName('TR');
  for(var ri=0; ri<rows.length; ri++)
    rows[ri].className = rowClasses[ri];

  // Reinstall table sort commands:
  _sip_sortingTable(table);

  var colHeads = rows[0].getElementsByTagName('TH');
  for(var hi=0; hi<colHeads.length; hi++)
  {
    sip_rmClass(colHeads[hi], SIP_CONST.SORT_TABLES.SORT_DESCENDING_CLASS);
    sip_rmClass(colHeads[hi], SIP_CONST.SORT_TABLES.SORT_ASCENDING_CLASS);
  }

  if(flip)
    sip_addClass(colHeads[column], SIP_CONST.SORT_TABLES.SORT_DESCENDING_CLASS);
  else
    sip_addClass(colHeads[column], SIP_CONST.SORT_TABLES.SORT_ASCENDING_CLASS);

  table._sip_sortCol  = column;
  table._sip_sortFlip = flip;

  if(DETECT.is_gecko)
    sip_geckoCaptions();
}




/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function _sip_sortingTable(table, initSort)
{
  var rows     = table.getElementsByTagName('TR');
  var colHeads = rows[0].getElementsByTagName('TH');
  if(colHeads.length==0 || !sip_isClass(table, 'sipusersortable') || table.innerHTML.indexOf('colspan')!=-1 || table.innerHTML.indexOf('rowspan')!=-1)
    return;

  table._sip_sortCol  = -1;
  table._sip_sortFlip = false;

  var col = null;
  if(initSort)
  {
    var className = table.className;
    if(className)
      col = parseInt(className.replace(new RegExp('.*' + 'sipusersortcol' + '([0-9]*).*'), '$1'));
  }

  if(col!=null && !isNaN(col))
    _sip_sortTable(table, col);
  else
  {
    var rows     = table.getElementsByTagName('TR');
    if(rows.length>2)
    {
      var colHeads = rows[0].getElementsByTagName('TH');
      for(var hi=0; hi<colHeads.length; hi++)
      {
        var titleTxt = sip_stripTags(colHeads[hi].innerHTML);
        if(!titleTxt)
          titleTxt = 'this column';
        colHeads[hi].style.cursor='pointer';
        colHeads[hi].title=SIP_CONST.SORT_TABLES.CAPTION_TITLE.replace(/%text%/, titleTxt);
        colHeads[hi].sip_index=hi;
        colHeads[hi].onclick=function()
        {
          if(window.sip_rmClass!=null && window._sip_sortTable!=null)
          {
            window.sip_rmClass(this, SIP_CONST.SORT_TABLES.CAPTION_HOVER_CLASS);
            _sip_sortTable(sip_getAncestorByTagName(this, 'TABLE'), this.sip_index);
          }
        }
        colHeads[hi].onmouseover=function()
        {
          // [c1]
          if(window.sip_addClass!=null)
            window.sip_addClass(this, SIP_CONST.SORT_TABLES.CAPTION_HOVER_CLASS);
        }
        colHeads[hi].onmouseout=function()
        {
          // [c1]
          if(window.sip_rmClass!=null)
            window.sip_rmClass(this, SIP_CONST.SORT_TABLES.CAPTION_HOVER_CLASS);
        }
      }
    }
  }
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_sortingTables()
{
  if(Array.prototype.sort==null)
    return;

  var tables=window.document.getElementsByTagName('TABLE');
  for(var ti=0; ti<tables.length; ti++)
    _sip_sortingTable(tables[ti], true);
}




/*
 * sip_focus()
 *   Sets focus to first non-find-box form field if any, otherwise to the 
 *   first H1 allowing efficient tabbing on the body text links. 
 *
 */

function sip_focus()
{
  var forms=window.document.body.getElementsByTagName('FORM');
  for(var fi=0; fi<forms.length; fi++)
  {
    var nodes=forms[fi].childNodes;
    for(var ni=0; ni<nodes.length; ni++)
    {
      if((nodes[ni].tagName=='INPUT' || nodes[ni].tagName=='SELECT' || nodes[ni].tagName=='TEXTAREA') 
         && nodes[ni].type!='hidden'
         && sip_scrolledIntoView(nodes[ni], SIP_GLOBAL.scroller))
      {
        try
        {
          nodes[ni].focus();
          if(nodes[ni].select!=null)
            nodes[ni].select();
        }
        catch(e){}
        return;
      }
    }
  }

  // Find and select the first H1:
  var bodytop = window.document.getElementsByTagName('H1')[0];
  if(bodytop!=null && sip_scrolledIntoView(bodytop, SIP_GLOBAL.scroller))
  {
    if(document.createRange!=null)
    {
      // DOM compliant, set selection to the H1:
      var range = window.getSelection();
      range.collapse(bodytop, 0);
    }
    else if(document.body.createTextRange!=null && SIP_GLOBAL.scroller.scrollTop==0)
    {
      /* IE: set the tabIndex attribute on the H1 and focus it. A negative 
       * tabIndex will make the element to remain unfocusable but still respond 
       * to the focus() method:
       */
      try
      {
        bodytop.tabIndex = -1;
        bodytop.focus();
      }
      catch(e){}
    }
  }
}



/*
 * sip_init()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_splashBox(splashUrl)
{
  var forceOpen = false;
  if(splashUrl==null)
  {
    var winUrl=window.location.href;
    if(winUrl.match(SIP_CONST.SPLASH.SELECTOR_PATTERN))
      splashUrl=winUrl.replace(SIP_CONST.SPLASH.SELECTOR_PATTERN, '$1');
  }
  else
    forceOpen = true;
  

  if(splashUrl!=null)
  {
    if(splashUrl.indexOf('.htm')==-1)
      splashUrl += '.html';
    if(splashUrl.indexOf(SIP_CONST.SPLASH.PATH_PREFIX_ENBALE)==-1)
      splashUrl=SIP_CONST.SPLASH.PATH_PREFIX + splashUrl;
    splashUrl = sip_url2path(splashUrl);
    var splashID = 'splash_' + splashUrl;    
    if(forceOpen || !sip_getCookie(splashID))
    {
      SIP_GLOBAL.splashID = splashID;
      var splashCanvas = _sip_createSplashBoxCanvas();
      splashCanvas.innerHTML='<div id="sipsplashbg"></div><iframe onload="_sip_splashBoxSlide(true)" scrolling="no" frameborder="0" src="' + splashUrl + '" />';
    }
  }
}



function sip_splashBoxDone()
{
  sip_setCookie(sip_getSiteTopWindow().SIP_GLOBAL.splashID, 'kilroy', true);
  if(sip_getSiteTopWindow().sip_splashBoxClose!=null)
    setTimeout('sip_getSiteTopWindow().sip_splashBoxClose()', 1500);
  else
    alert('Warning: Page called out of context');
}

function sip_splashBoxClose()
{
  if(SIP_GLOBAL.splashCanvas!=null)
  {
    SIP_GLOBAL.splashCanvas.style.visibility='hidden';
    SIP_GLOBAL.splashCanvas.parentNode.removeChild(SIP_GLOBAL.splashCanvas);
    SIP_GLOBAL.splashCanvas=null;
  }
}




function _sip_splashBoxSlide(show)
{
  if(show)
  {
    if(SIP_GLOBAL.splashCanvasReveal==null)
    {
      SIP_GLOBAL.splashCanvasReveal = 1;
      SIP_GLOBAL.splashCanvasStart = null;
    }
    else
    {
      if(SIP_GLOBAL.splashCanvasStart==null)
        SIP_GLOBAL.splashCanvasStart = (new Date()).getTime();
      var timeD = ((new Date()).getTime() - SIP_GLOBAL.splashCanvasStart) / 800;
      SIP_GLOBAL.splashCanvasReveal = Math.ceil(timeD * SIP_GLOBAL.splashCanvas.offsetHeight);
    }

    SIP_GLOBAL.splashCanvas.style.clip='rect(0px ' + SIP_GLOBAL.splashCanvas.offsetWidth + 'px ' + SIP_GLOBAL.splashCanvasReveal + 'px 0px)';

    if(SIP_GLOBAL.splashCanvasReveal < SIP_GLOBAL.splashCanvas.offsetHeight)
      setTimeout('_sip_splashBoxSlide(true)', 10);
  }
  else
    SIP_GLOBAL.splashCanvas.style.clip='rect(0px 0px 0px 0px)';
}


function _sip_createSplashBoxCanvas()
{
  var splashCanvas=document.createElement("DIV");
  SIP_GLOBAL.splashCanvas=splashCanvas;
  
  _sip_splashBoxSlide(false);

  splashCanvas.className="sipsplashcanvas";
  splashCanvas.onclick=function(event)
  {
    var element;
    if(window.event!=null) // Typically IE
      element=window.event.srcElement;
    else // Typically W3C compliant
      element=event.target;
    if(element.id=='sipsplashbg')
      sip_splashBoxClose();
  }
  window.document.body.appendChild(splashCanvas);
  return(splashCanvas);
}



/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_framed()
{
  // Add the framed css:
  var head = window.document.getElementsByTagName('HEAD')[0];
  if(head!=null)
  {
    var link = document.createElement('link');
    link.rel="stylesheet";
    link.title="Sectra style";
    link.type="text/css";
    link.href="/common/styles/framed.css";
    head.appendChild(link);
  }

  // Set all unassigned link targets to '_top':
  var links=window.document.getElementsByTagName('A');
  for(var i=0; i<links.length; i++)
  {
    if(!links[i].target)
      links[i].target='_top';
  }
}


// #PRAGMA COMPACT START SKIP

/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_debug()
{
  if(!SIP_DEBUG.ENABLE)
    return;

  if(!sip_isTestServer())
    return;

  if(sip_getSiteTopWindow().sip_debugkilroy==true)
    return;
  sip_getSiteTopWindow().sip_debugkilroy=true;

  var menu = document.createElement('div');
  menu.style.position='absolute';
  menu.style.left='0px';
  menu.style.top=SIP_GLOBAL.scroller.scrollTop + 'px';
  menu.style.width='140px';
  menu.style.padding='0px';
  menu.style.zIndex='100';

  menu.onmouseover=function(){
    this.style.clip='rect(auto auto auto auto)';
  }
  
  menu.onmouseout=function(){
    this.style.clip='rect(0px 20px 20px 0px)';
  }
  
  menu.onmouseout();

  var html = '<img src="/common/styles/images/_fw_authoringmenuico.gif" width="20" height="20" />';
  html += '<div style="border: 4px double #2060a0; background: #ffffff; padding: 2px 4px 2px 4px; margin: 0px; font: normal 9px Arial, Helvetica, sans-serif">';
  html += sip_debugLink('<span style="float: right; font-weight: bold; font-size: 7pt; background-color: #ffffff; margin: 1px; padding: 0px 2px"><a href="/admin/guide/stb/page_popup.html">?</a></span>Authoring menu', null, 'font-weight: bold; font-size: 8pt; padding: 0px 4px; color: #ffffff; background-color: #2060a0; margin-bottom: 4px; ');
  html += sip_debugLink('Edit file in Dreamweaver', 'sip_debugCommand(null, \'DREAMWEAVER\')');
  html += sip_debugLink('Edit file in Code Editor', 'sip_debugCommand(null, \'CODEEDITOR\')');
  html += sip_debugLink('Explore work folder', 'sip_debugCommand(null, \'EXPLORE\')');
  html += sip_debugLink('Copy work location', 'sip_debugCommand(null, \'COPY\')');
  html += sip_debugLink('---');
  html += sip_debugLink('Start debugger', 'javascript:debugger');
  html += sip_debugLink('List cookies', 'sip_debugCommand(null, \'LISTCOOKIES\')');
  html += sip_debugLink('Remove cookies', 'sip_debugCommand(null, \'RMCOOKIES\')');
  html += sip_debugLink('Kill SWF Ctrls', 'sip_debugCommand(null, \'KILLSWF\')');
  html += sip_debugLink('---');
  html += sip_debugLink('Open at www', window.location.href.replace(/http:\/\/[^\/]*(.*)/, 'http://www.sectra.se$1'));
  html += sip_debugLink('Open at web-devel', window.location.href.replace(/http:\/\/[^\/]*(.*)/, 'http://web-devel.sectra.se$1'));
  html += sip_debugLink('Open at edit', window.location.href.replace(/http:\/\/[^\/]*(.*)/, 'http://edit.sectra.se$1'));
  html += sip_debugLink('Open at localhost', window.location.href.replace(/http:\/\/[^\/]*(.*)/, 'http://localhost$1'));
  html += sip_debugLink('Open at tarrekaise', window.location.href.replace(/http:\/\/[^\/]*(.*)/, 'http://tarrekaise.sectra.se:8089$1'));
  html += sip_debugLink('---');
  html += sip_debugLink('Window name:<br/>&nbsp;&nbsp;<b>' + sip_getWindowName() + '</b><br/>'
                       +'Zone:<br/>&nbsp;&nbsp;<b>' + sip_getCurrentZone() + '</b><br/>'
                       +'Browser:<br/>&nbsp;&nbsp;<b>' + navigator.userAgent + '</b>');
  html += '</div>';
  menu.innerHTML = html;
  window.document.body.appendChild(menu);
}


/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_debugLink(caption, action, style)
{
  if(!style)
    style='';
  style = '; display: block; margin: 0px; padding: 0px; ' + style;
  if(caption.charAt(0)=='-')
    return('<hr size="1" color="#2060a0" noshade="1" width="80" />');
  else if(action)
  {
    if(action.indexOf('(')!=-1)
      return('<a style="color: #203060' + style + '" href="#" onclick="' + action + '; return false">&bull;&nbsp;' + caption + '</a>');
    else
      return('<a style="color: #203060' + style + '" href="' + action + '">&bull;&nbsp;' + caption + '</a>');
  }
  else
    return('<span style="color: #000000' + style + '">' + caption + '</span>');
}



function sip_debugCommand(url, tool)
{
  if(url==null)
    url = sip_getCurrentPath(window.location.href);
  if(url.charAt(url.length-1)=='/')
    url += 'index.html';

  switch(tool)
  {
    case null:
      tool = "DREAMWEAVER";
      break;
  }

  switch(tool)
  {
    case 'KILLSWF':
      var count = sip_killSwfControls();
      if(count)
        alert('Killed ' + count + ' SWF controls')
      else
        alert('No SWF controls to kill')
      break;
    case 'COPY':
      window.clipboardData.setData('Text', SIP_DEBUG.SITE_ROOT + url.replace(/\//g, '\\'));
      break;
    case 'LISTCOOKIES':
    case 'RMCOOKIES':
      var cookies = document.cookie.split("; ");
      var msg='';
      for (var i=0; i < cookies.length; i++)
      {
        if(cookies[i])
        {
          var crumb = cookies[i].split("=");
          msg += '- ' + crumb[0] + ':\n      "' + crumb[1] + '"\n';
        }
      }
      if(msg)
      {
        if(tool=='RMCOOKIES')
        {
          if(confirm('Remove the cookies at ' + SIP_GLOBAL.serverURL + '?\n' + msg))
            alert("Removed " + sip_rmAllCookies() + " cookies");
        }
        else   
          alert('Cookies at ' + SIP_GLOBAL.serverURL + ':\n' + msg);
      }
      else
        alert('No cookies at ' + SIP_GLOBAL.serverURL + '.');
      break;
    case 'EXPLORE':
      url = url.replace(/\/[^\/]*\.[^\/]*$/, '/').replace(/\//g, '\\');
    default:
      sip_debugEdit(url, tool);
      break;
  }
}


function sip_debugEdit(url, editor)
{
  var errMsg;
  for(var i=0; i<SIP_DEBUG[editor].length; i++)
  {
    try
    {
      var wsh = new ActiveXObject("WScript.Shell");
      wsh.Exec(SIP_DEBUG[editor][i] + ' "' + SIP_DEBUG.SITE_ROOT + url.replace(/\//g, '\\') + '"');
      return;
    }
    catch(e)
    {
      errMsg = e.message;
    }
  }
  if(confirm('Could not start ' + editor + ': ' + errMsg + '\n\nDo you want to show help?'))
    window.open("/admin/guide/install_and_configure.html#Configurewebbrowsers");
}

// #PRAGMA COMPACT END SKIP


/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_killSwfControl(control)
{
  if(control.type.indexOf('shockwave-flash')==-1)
    return(false);
  var container = control.parentNode.parentNode;
  container.innerHTML = container.siSwfCtrlStatic;
  return(true);
}




/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_killSwfControls()
{
  var objs = window.document.getElementsByTagName('OBJECT');
  if(objs.length==0)
    objs = window.document.getElementsByTagName('EMBED');
  var count=0;
  for(var i=0; i<objs.length; i++)
  {
    if(sip_killSwfControl(objs[i]))
      count++;
  }
  return(count);
}




/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_initKeyboard()
{
  if(window.document.attachEvent!=null)
    window.document.attachEvent('onkeydown', sip_keyHandler);
  else
    window.document.addEventListener('keydown', sip_keyHandler, false);
}




/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_keyHandler(event)
{
  if(window.event!=null)
    event=window.event;

  if(event.keyCode==70 && event.ctrlKey && event.shiftKey) // Ctrl+Shift+F
  {
    var elem = window.document.getElementById(SIP_CONST.MINISEARCH.INPUT_ID);
    if(elem!=null)
      elem.focus();
  }
}




/*
 * x()
 *   x
 *
 * In:
 *   x
 *
 * Returns
 *   x
 */

function sip_initMiniSearchForm()
{
  var words = window.document.getElementById(SIP_CONST.MINISEARCH.INPUT_ID);
  if(words!=null)
  {
    words.defaultValue=SIP_CONST.MINISEARCH.INPUT_DEFAULT_VALUE;

    // Set up initial layout:
    if(words.value=='' || words.value==SIP_CONST.MINISEARCH.INPUT_DEFAULT_VALUE)
    {
      sip_addClass(words, SIP_CONST.MINISEARCH.INPUT_DEFAULT_CLASS);
      words.value=SIP_CONST.MINISEARCH.INPUT_DEFAULT_VALUE;
    }

    /*
     * Remove initial layout when entered:
     */
    words.onfocus = function()
    {
      // [c1]
      if(window.sip_rmClass!=null)
        window.sip_rmClass(this, SIP_CONST.MINISEARCH.INPUT_DEFAULT_CLASS);
      if(words.value==SIP_CONST.MINISEARCH.INPUT_DEFAULT_VALUE)
        words.value='';
    }

    /*
     * Reinstall initial layout if left blank:
     */
    words.onblur = function()
    {
      if(words.value=='' || words.value==SIP_CONST.MINISEARCH.INPUT_DEFAULT_VALUE)
      {
        // [c1]
        if(window.sip_addClass!=null)
          window.sip_addClass(words, SIP_CONST.MINISEARCH.INPUT_DEFAULT_CLASS);
        words.value=SIP_CONST.MINISEARCH.INPUT_DEFAULT_VALUE;
      }
    }

    /* 
     * Pevent undo (or ESC in FF) to re-insert the default value while the 
     * field is still focused 
     */
    words.onkeyup = function()
    {
      if(words.value==SIP_CONST.MINISEARCH.INPUT_DEFAULT_VALUE)
        words.value='';
    }


  }
}

// EoF

