/* xbdhtml.js (Cross-Browser Nav4/IE4 DHTML API) 

   14 May 98, Eric Krock, Copyright Netscape Communications

   Permission is granted to reuse, redistribute, and modify 

   without charge.

*/

function Is ()

{   // convert all characters to lowercase to simplify testing

    var agt=navigator.userAgent.toLowerCase()



    // --- BROWSER VERSION ---

    this.major = parseInt(navigator.appVersion)

    this.minor = parseFloat(navigator.appVersion)



    this.nav  = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1)

                && (agt.indexOf('compatible') == -1)))

    this.nav2 = (this.nav && (this.major == 2))

    this.nav3 = (this.nav && (this.major == 3))

    this.nav4 = (this.nav && (this.major == 4))



    this.ie   = (agt.indexOf("msie") != -1)

    this.ie3  = (this.ie && (this.major == 2))

    this.ie4  = (this.ie && (this.major == 4))



    this.opera = (agt.indexOf("opera") != -1)

     

    this.nav4up = this.nav && (this.major >= 4)

    this.ie4up  = this.ie  && (this.major >= 4)

}





var is = new Is();





function dw(str, minVersion, maxVersion)

{   if ( ((dw.arguments.length < 3) || (is.major <= maxVersion)) 

         && ((dw.arguments.length < 2) || (is.major >= minVersion)))

    document.write(str)  

}





function dwb (str, aBoolean)

{   if  ((dwb.arguments.length < 2) || aBoolean)

    document.write(str)  

}







function sv(str, minVersion, maxVersion)

{   if ( ((sv.arguments.length < 3) || (is.major <= maxVersion)) 

         && ((sv.arguments.length < 2) || (is.major >= minVersion)))

    return str;

    else return "";

}







function sb (str, aBoolean)

{   if  ((sb.arguments.length < 2) || aBoolean)

    return str;

    else return "";

}









function layerClipOrder (cssClipString)

{  var commaPos = cssClipString.lastIndexOf(",");

   return (cssClipString.substring(commaPos+1) + "," + cssClipString.substring(0,commaPos));

}



function genElt (name, content, left, top, z, width, height, visibility, 

                 backgroundColor, backgroundImage, clip, relative, 

                 hideEltOnOlderBrowsers, useDivInsteadOfLayer, classname) 

{ var markup = "";

  if (is.nav && (is.major>=4 || !hideEltOnOlderBrowsers) && 

      !useDivInsteadOfLayer)

  { var tagname = (relative)?'ILAYER':'LAYER';

    if (visibility && (visibility!=''))

    {  if (visibility=="hidden") visibility = "hide";

       else if (visibility=="visible") visibility = "show";

    }

    markup = '<' + tagname + ' ID="' + name + '"' + ((classname)?' CLASS="' + 

        classname + '"':'') + ((left)?' LEFT="' + left + '"':'') + 

        ((top)?' TOP="' + top + '"':'') + ((width)?' WIDTH="' + width + '"':'') + 

        ((height)?' HEIGHT="' + height + '"':'') + 

        ((visibility && (visibility!='')) ? ' VISIBILITY="' + visibility + '"' : '') + 

        ((z)?' Z-INDEX="' + z + '"':'') + 

        ((backgroundColor)?' BGCOLOR="' + backgroundColor + '"':'') + 

        ((backgroundImage)?' BACKGROUND="' + backgroundImage + '"':'') +  

        ((clip)?' CLIP="' + layerClipOrder(clip) + '"':'') + 

        '>' + ((content)?content:'') + '</' + tagname + '>';

  }

  else if ((is.ie || (is.nav && useDivInsteadOfLayer)) && (is.major>=4 || !hideEltOnOlderBrowsers))

  { markup = '<DIV ID="' + name + '"' +  

        ((classname)?' CLASS="' + classname + '"':'') + 

        ' STYLE="position:' + ((relative)?'relative;':'absolute;') + 

        ' overflow:none;' + 

        ((left)?' left:' + left + 'px;':'') + 

        ((top)?' top:' + top + 'px;':'') + 

        ((height)?' height:' + height + 'px;':'') + 

        ((width)?' width:' + width + 'px;':'') + 

        ((visibility && (visibility!='')) ? ' visibility:' + visibility + ';' : '') + 

        ((z)?' z-index:' + z + ';':'') + 

        ((backgroundColor)?' background-color:' + backgroundColor + ';':'') + 

        ((backgroundImage)?' background-image:url("' + backgroundImage + '");':'') +  

        ((clip)?' clip:rect("' + clip + '");':'') + 

        '">' + ((content)?content:'') + '</DIV>';

  }

  return markup;

}



function writeElt (name, content, left, top, z, width, height, visibility, 

                   backgroundColor, backgroundImage, clip, relative, 

                   hideEltOnOlderBrowsers, useDivInsteadOfLayer, classname) 

{ if (writeElt.arguments.length < 15) classname = false;

  if (writeElt.arguments.length < 14) useDivInsteadOfLayer = false;

  if (writeElt.arguments.length < 13) hideEltOnOlderBrowsers = false;

  if (writeElt.arguments.length < 12) relative = false;

  if (writeElt.arguments.length < 11) clip = false;

  if (writeElt.arguments.length < 10) backgroundImage = false;

  if (writeElt.arguments.length < 9) backgroundColor = false;

  if (writeElt.arguments.length < 8) visibility = false;

  if (writeElt.arguments.length < 7) height = false;

  if (writeElt.arguments.length < 6) width = false;

  if (writeElt.arguments.length < 5) z = false;

  if (writeElt.arguments.length < 4) top = false;

  if (writeElt.arguments.length < 3) left = false;

  if (writeElt.arguments.length < 2) content = false;

  document.write (genElt (name, content, left, top, z, width, height, visibility, 

                    backgroundColor, backgroundImage, clip, relative, 

                 hideEltOnOlderBrowsers, useDivInsteadOfLayer, classname));

}







function getElt () 

{ if (is.nav4up) {

    var currentLayer = document.layers[getElt.arguments[0]];

    for (var i=1; i<getElt.arguments.length && currentLayer; i++)

    {   currentLayer = currentLayer.document.layers[getElt.arguments[i]];

    }

    return currentLayer;

  } 

  else if (is.ie4up) {

    var elt = eval('document.all.' + getElt.arguments[getElt.arguments.length-1]);

    return(elt);

  }

}



//Function added by Timothy High, thigh@cal.berkeley.edu, 8 Feb 1999

function getEltID (elt) 

{ if (isNav4)     return (elt.name);

  else if (isIE4) return (elt.id);

}



function setEltVisibility (elt, value)

{  if (is.nav4up) elt.visibility = value;

   else if (is.ie4up) elt.style.visibility = value;

}







function getEltVisibility (elt)

{  if (is.nav4up) 

   {  var value = elt.visibility;

      if (value == "show") return "visible";

      else if (value == "hide") return "hidden";

      else return value;

   }

   else if (is.ie4up) return elt.style.visibility;

}





function moveEltTo (elt, x, y) 

{ if (is.nav4up) elt.moveTo(x, y);

  else if (is.ie4up) {

    elt.style.pixelLeft = x;

    elt.style.pixelTop  = y;

  }

}





function moveEltBy (elt, x, y) 

{ if (is.nav4up) elt.moveBy(x, y);

  else if (is.ie4up)  {

    elt.style.pixelLeft += x;

    elt.style.pixelTop  += y;

  }

}







function setEltLeft (elt, x) {

  if (is.nav4up)     elt.left=x;

  else if (is.ie4up) elt.style.pixelLeft=x;

}







function getEltLeft (elt) {

  if (is.nav4up)     return (elt.left);

  else if (is.ie4up) return (elt.style.pixelLeft);

}







function setEltTop (elt, y) 

{ if (is.nav4up)     elt.top=y;

  else if (is.ie4up) elt.style.pixelTop=y;

}







function getEltTop (elt) 

{ if (is.nav4up)     return (elt.top);

  else if (is.ie4up) return (elt.style.pixelTop);

}





function getEltWidth (elt)

{ if (is.nav4up) return(elt.width);

  else if (is.ie4up) return(elt.style.pixelWidth);

}





function getEltHeight (elt)

{ if (is.nav4up) return (elt.height);

  else if (is.ie4up) return (elt.style.pixelHeight);

}









function setEltClip (elt, cliptop, clipright, clipbottom, clipleft) 

{ if (is.nav4up) {

    elt.clip.left   = clipleft;

    elt.clip.top    = cliptop;

    elt.clip.right  = clipright;

    elt.clip.bottom = clipbottom;

  }

  else if (is.ie4up)  elt.style.clip = 'rect(' + cliptop + ' ' +  

       clipright + ' ' + clipbottom + ' ' + clipleft +')';

}







function tempClipObj (elt)

{  var clipStr = elt.style.clip;

   clipStr = clipStr.substring (clipStr.indexOf("(") + 1);

   this.top = parseInt(clipStr);

   clipStr = clipStr.substring (clipStr.indexOf(" ") + 1);

   this.right = parseInt(clipStr);

   clipStr = clipStr.substring (clipStr.indexOf(" ") + 1);

   this.bottom = parseInt(clipStr);

   clipStr = clipStr.substring (clipStr.indexOf(" ") + 1);

   this.left = parseInt(clipStr);

}





function getEltClipLeft (elt) 

{ if (is.nav4up)     return (elt.clip.left);

  else if (is.ie4up) 

  {  var tempClip = new tempClipObj (elt);

     return tempClip.left;

  }

}







function getEltClipTop (elt) 

{ if (is.nav4up)     return (elt.clip.top);

  else if (is.ie4up) 

  {  var tempClip = new tempClipObj (elt);

     return tempClip.top;

  }

}







function getEltClipRight (elt) {

  if (is.nav4up)     return (elt.clip.right);

  else if (is.ie4up) 

  {  var tempClip = new tempClipObj (elt);

     return tempClip.right;

  }

}







function getEltClipBottom (elt) 

{ if (is.nav4up)     return (elt.clip.bottom);

  else if (is.ie4up) 

  {  var tempClip = new tempClipObj (elt);

     return tempClip.bottom;

  }

}





function getEltClipWidth (elt) 

{ if (is.nav4up)     return (elt.clip.width);

  else if (is.ie4up) return (getEltClipRight(elt) - getEltClipLeft(elt));

}





function getEltClipHeight (elt) 

{ if (is.nav4up)     return (elt.clip.height);

  else if (is.ie4up) return (getEltClipBottom(elt) - getEltClipTop(elt));

}





function getCurrentWinWidth() 

{ if (is.nav4up)     return(window.innerWidth);

  else if (is.ie4up) return(document.body.clientWidth);

}







function getCurrentWinHeight() 

{ if (is.nav4up)     return(window.innerHeight);

  else if (is.ie4up) return(document.body.clientHeight);

}







function getEltZIndex (elt) 

{ if (is.nav4up) return(elt.zIndex);

  else if (is.ie4up) return (elt.style.zIndex);

}







function setEltZIndex (elt, z) 

{ if (is.nav4up) elt.zIndex = z;

  else if (is.ie4up) elt.style.zIndex = z;

}









function setEltBackgroundImage (elt, imageFilePath) 

{ if (is.nav4up) elt.background.src = imageFilePath;

  else if (is.ie4up) elt.style.backgroundImage = "url(" + imageFilePath + ")";

}







function getEltBackgroundImage (elt) 

{ if (is.nav4up) return (elt.background.src);

  else if (is.ie4up) { 

     var theURL = elt.style.backgroundImage;

     if (typeof(theURL) == "string")

     {  var URLlen = theURL.length;

        return (theURL.substring (4, URLlen-1));

     }

     else return(theURL);

  }

}







function setEltBackgroundColor (elt, colorNumber) 

{ if (is.nav4up) elt.bgColor = colorNumber;

  else if (is.ie4up) elt.style.backgroundColor = colorNumber;

}







var colorNameString = "aqua,black,blue,fuchsia,gray,green,lime,maroon,navy,olive,purple,red,silver,teal,yellow,white";

var colorNames   = new Array ("aqua", "black", "blue", "fuchsia", "gray",   "green", "lime", "maroon", "navy", "olive",  "purple", "red",    "silver", "teal", "yellow", "white");

var colorNumbers = new Array (0xffff, 0,       0xff,   0xff00ff,  0x808080, 0x8000,  0xff00, 0x800000, 0x80,   0x808000, 0x800080, 0xff0000, 0xc0c0c0, 0x8080, 0xffff00, 0xffffff);





function isColorName (aString)

{ return ( (typeof(aString) == "string") && (colorNameString.indexOf(aString) != -1));

}







function colorNameToNumber (colorName)

{ for (var i=0; i<16; i++) if (colorNames[i]==colorName) return colorNumbers[i];

  // Return string name unchanged if not found.

  // This handles IE4 non-CSS1-standard color names gracefully.

  return colorName;

}







function colorNumberToName (colorNumber)

{ for (var i=0; i<16; i++) if (colorNumbers[i]==colorNumber) return colorNames[i];

  return null;

}





function getEltBackgroundColor (elt) 

{ if (is.nav4up) return (elt.bgColor);

  else if (is.ie4up) {

     var colorVal = elt.style.backgroundColor;

     if (isColorName(colorVal)) return colorNameToNumber (colorVal);

     else if (typeof(colorVal) == "string") 

          return (("0x" + colorVal.substring(1)) - 0);

     else return colorVal;

  }

}



