JavaScript Widgets -- Banners : Banner « Ajax Layer « JavaScript DHTML

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Event
7. Event onMethod
8. Form Control
9. GUI Components
10. HTML
11. Javascript Collections
12. Javascript Objects
13. Language Basics
14. Node Operation
15. Object Oriented
16. Page Components
17. Security
18. Style Layout
19. Table
20. Utilities
21. Window Browser
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
JavaScript DHTML » Ajax Layer » Banner 
JavaScript Widgets -- Banners


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML>
<HEAD>
<TITLE>JavaScript Widgets -- Examples/Banners</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2963" name=GENERATOR>
<style title="Website Style" type=text/css rel=stylesheet>
DIV.footnote {
  BORDER-RIGHT: black 2px solid; PADDING-RIGHT: 5px; BORDER-TOP: black 2px solid; PADDING-LEFT: 5px; Z-INDEX: 2; LEFT: 10px; VISIBILITY: hidden; PADDING-BOTTOM: 5px; OVERFLOW: hidden; BORDER-LEFT: black 2px solid; PADDING-TOP: 5px; BORDER-BOTTOM: black 2px solid; POSITION: absolute; TOP: 10px; BACKGROUND-COLOR: white; TEXT-ALIGN: justify
}
A.note {
  FONT-WEIGHT: bold; FONT-SIZE: 8pt; COLOR: blue; FONT-STYLE: normal; POSITION: relative
}
A.topic {
  FONT-WEIGHT: bold; COLOR: black; TEXT-DECORATION: none
}
A.topic:hover {
  COLOR: red
}
SPAN.topic {
  FONT-WEIGHT: bold; COLOR: blue
}
DIV.menuBar {
  BORDER-RIGHT: silver 2px outset; PADDING-RIGHT: 1px; BORDER-TOP: silver 2px outset; PADDING-LEFT: 1px; VISIBILITY: visible; PADDING-BOTTOM: 1px; BORDER-LEFT: silver 2px outset; PADDING-TOP: 1px; BORDER-BOTTOM: silver 2px outset; WHITE-SPACE: nowrap; POSITION: absolute; BACKGROUND-COLOR: blue; TEXT-ALIGN: center
}
IMG.menuBar {
  BORDER-TOP-WIDTH: 0px; PADDING-RIGHT: 0px; PADDING-LEFT: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; PADDING-BOTTOM: 0px; MARGIN: 1px; PADDING-TOP: 0px; BORDER-RIGHT-WIDTH: 0px
}
DIV.menuBody {
  BORDER-RIGHT: silver 2px outset; BORDER-TOP: blue 0px solid; Z-INDEX: 1; VISIBILITY: hidden; BORDER-LEFT: silver 2px outset; BORDER-BOTTOM: silver 2px outset; POSITION: absolute; BACKGROUND-COLOR: blue
}
DIV.menuItem {
  BORDER-RIGHT: silver 0px outset; PADDING-RIGHT: 0px; BORDER-TOP: blue 2px solid; PADDING-LEFT: 2px; FONT-SIZE: 10pt; LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; BORDER-LEFT: silver 0px outset; CURSOR: pointer; COLOR: white; PADDING-TOP: 2px; BORDER-BOTTOM: silver 0px outset; FONT-FAMILY: "Times New Roman", Times, serif; WHITE-SPACE: nowrap; POSITION: absolute; TOP: 0px; BACKGROUND-COLOR: blue; TEXT-ALIGN: left
}

</style>
<!-- browser.js -->
<SCRIPT language=JavaScript>
function Is() {
  var appName = navigator.appName.toLowerCase();
  var version = navigator.appVersion.toLowerCase();
  var agent   = navigator.userAgent.toLowerCase();
  var platform = navigator.platform.toLowerCase();
  this.major = parseInt(version);
  this.minor = parseFloat(version);
  this.nsa = (agent.indexOf('netscape') != -1);
  this.mza = (agent.indexOf('mozilla') != -1);
  this.gla = (agent.indexOf('galeon') != -1);
  this.mza = (this.mza && !this.nsa);

  if (this.mza) {
    version = agent.substring(agent.indexOf("rv:")+3,agent.indexOf(")"));
    this.nsa = false;
    if (agent.indexOf("rv:"!= -1) {
      this.major = parseInt(version);
      this.minor = parseFloat(version);
      this.mz1 = (this.mza && (this.major == 1));
    else {
      this.mza = false;
      version = this.minor;
    }
  }

    if (this.gla) {
      version = agent.substring(agent.indexOf("galeon/")+7,agent.indexOf("(")-1);
      this.nsa = false;
      if (agent.indexOf("galeon/"!= -1) {
        this.major = parseInt(version);
        this.minor = parseFloat(version);
        this.gl1 = (this.gla && (this.major == 1));
      else {
        this.gla = false;
        version = this.version;
      }
    }

  this.version = version;

  this.nsn = (appName.indexOf('netscape') != -1);
  this.ns2 = (this.nsn && (this.major == 2));
  this.ns3 = (this.nsn && (this.major == 3));
  this.ns4 = (this.nsn && (this.major == 4));
  this.ns6 = (this.nsa && (this.major >= 5));
  if (this.ns6) {
    this.version = agent.slice(agent.indexOf("netscape6/")+10,agent.length);
  }

  this.ie = ((appName.indexOf("internet explorer"!= -1)
    && (agent.indexOf("opera"== -1));
  this.ie3 = (this.ie && (this.major == 3));
  this.ie4 = (this.ie && (this.major == 4)
    && (agent.indexOf("msie 4."!= -1));
  this.ie5 = (this.ie && (this.major == 4)
    && (agent.indexOf("msie 5."!= -1));
  this.ie6 = (this.ie && (this.major == 4)
    && (agent.indexOf("msie 6."!= -1));
  if (this.ie4 || this.ie5 || this.ie6) {
    this.version = agent.slice(agent.indexOf("msie ")+5,agent.length);
    this.version = this.version.slice(0,this.version.indexOf(";"));
  }
  this.ieX = (this.ie && !this.ie3 && !this.ie4);

  this.op  = (agent.indexOf('opera') != -1);
  this.op4 = (this.op && (this.major == 4)
    && (agent.indexOf("opera 4."!= -1));
  this.op5 = (this.op && (this.major == 4)
    && (agent.indexOf("opera 5."!= -1));
  this.op6 = (this.op && (this.major == 4)
    && (agent.indexOf("opera 6."!= -1));
  if (this.op) {
    this.ie = false;
    this.ie4 = false;
    this.ie5 = false;
    this.ie6 = false;
    this.version = agent.slice(agent.indexOf("opera")+6,agent.length)
    this.version = parseFloat(this.version);
  }

  this.kq  = (agent.indexOf("konqueror"!= -1);
  if (this.kq) {
    this.version = agent.substring(agent.indexOf("konqueror/")+10,agent.length);
    this.version = this.version.substring(0,this.version.indexOf(";"));
    this.major = parseInt(this.version);
    this.minor = parseFloat(this.version);
    this.mza = false;
  }
  this.kq2 = (this.kq && (this.major == 2));
  this.kq3 = (this.kq && (this.major == 3));

  this.w3c = (!(!(document.getElementById)));
  this.win32 = (platform.indexOf("win32"!= -1);
  this.linux = (platform.indexOf("linux"!= -1);
  this.bsd   = (platform.indexOf("bsd"!= -1);
}

var is = new Is();

function setTagFontColor(tag, color) {

  if (is.ie4 || is.w3c) {
    tag.style.color = color;
  else if (is.ns4) {
    tag.color = color;
  else {
    return;
  }
}

function setTagFontStyle(tag, style) {

  if (is.ie4 || is.w3c) {
    tag.style.fontStyle = style;
  else if (is.ns4) {
    tag.fontStyle = style;
  else {
    return;
  }
}

function mousePosLeft(event) {

  var leftPos;

  if (is.ie4 || (is.w3c && !(is.ns6 || is.mza))) {
    leftPos = event.clientX;
    //alert("event.clientX = " + event.clientX);
  else if (is.ns4 || is.ns6 || is.mza) {
    leftPos = event.pageX;
  }
  return leftPos;
}

function mousePosTop(event) {

  var topPos;

  if (is.ie4 || (is.w3c && !(is.ns6 || is.mza))) {
    topPos = event.clientY;
    //alert("mousePosTop is clientY = " + event.clientY);
  else if (is.ns4 || is.ns6 || is.mza) {
    topPos = event.pageY;
    //alert("mousePosTop is pageX = " + event.pageX);
  }
  return topPos;
}
</SCRIPT>
<!-- layers.js -->
<SCRIPT language=JavaScript>
function getNSLayer(inNode, inName) {

  var node, i;

  node = inNode[inName];
  for (i = 0; !node && inNode.layers && i < inNode.layers.length; i++) {
    node = getNSLayer(inNode.layers[i].document,inName);
  }
  return node;
}

function getLayer(inNode,inName) {

  var node;

  if (inNode.getElementById) {
    node = inNode.getElementById(inName);
  else if (inNode.all) {
    node = inNode.all[inName];
  else if (inNode.layers) {
    node = getNSLayer(inNode, inName);
  }
  if (!nodealert("Could not find layer " + inName + ".");
  return node;
}

function getStyle(inNode) {

  var style;

  if (is.w3c || is.ie4) {
    style = inNode.style;
  else if (is.ns4) {
    style = inNode;
  else {
    style = 0;
  }
  return style;
}

function setLayerPos(inNode, left, top) {

  if (is.ie4 || is.w3c) {
    inNode.style.left = left + "px";
    inNode.style.top  = top + "px";
  else if (is.ns4) {
    inNode.left = left;
    inNode.top  = top;
  }
}

function showLayer(mNode) {

  var style;

  style = getStyle(mNode);
  if (stylestyle.visibility = "visible";
}

function hideLayer(mNode) {

  var style;

  style = getStyle(mNode);
  if (stylestyle.visibility = "hidden";
}

function isPositioned(mNode) {

  return (mNode.left || mNode.style.left);
}

function layerWidth(mNode) {

  var nWidth;

  if (is.ie4 || is.w3c) {
    //alert("Node width = " + mNode.style.width);
    nWidth  = parseInt(mNode.style.width);
  else if (is.ns4) {
    nWidth  = parseInt(mNode.width);
  }
  return nWidth;
}

function expandLayer(mNode) {

  var style;

  style = getStyle(mNode);
  if (stylestyle.display = "block";
}

function contractLayer(mNode) {

  var style;

  style = getStyle(mNode);
  if (stylestyle.display = "none";
}

function insertLayer(mNode) {

  var style;

  style = getStyle(mNode);
  if (stylestyle.display = "inline";
}

function setLayerColor(tag,bgColor,tColor) {

  var elLayer;

  elLayer = getLayer(document,tag);
  elStyle = getStyle(elLayer);
  if (elStyle) {
    if (is.ns4) {
      elStyle.bgColor = bgColor;
      //Netscape 4.xx browsers don't support this!
      //elStyle.fgColor = tColor;
    else {
      elStyle.backgroundColor = bgColor;
      elStyle.color = tColor;
    }
  }
}

var NSVisType = new Array();
  NSVisType["visible""show";
  NSVisType["hidden"]  "hide";
  NSVisType["inherit""inherit";

function setStyle(divType, fontSize, left, top, width, height, zIndex, bgColor, visibility) {

   var dStyle;

   if (divType == "layer") {
    dStyle  = 'left="' + left;
    dStyle += '" top="' + top;
    dStyle += '" width="' + width;
    dStyle += '" height="' + height;
    if (zIndex) dStyle += '" z-index="' + zIndex;
    if (bgColor) {
        dStyle += '" bgColor="' + bgColor;
    } else {
        dStyle += '" bgColor="#000000';
    }
    if (visibility) dStyle += '" visibility="' + NSVisType[visibility];
    dStyle += '" ';
   else {
    dStyle  = 'style="font-size : ' + fontSize + 'pt; ';
    dStyle += 'left : ' + left + 'px; ';
    dStyle += 'top : ' + top + 'px; ';
    dStyle += 'width : ' + width + 'px; ';
    dStyle += 'height : ' + height + 'px; ';
    if (zIndex) dStyle += 'z-index : ' + zIndex + '; ';
    if (bgColor) dStyle += 'background-color : ' + bgColor + '; ';
    if (visibility) dStyle += 'visibility : ' + visibility + '; ';
    dStyle += '" ';
   }
   //alert("dStyle = " + dStyle);
   return dStyle;
}

</SCRIPT>
<!-- brmenu.js -->
<SCRIPT language=JavaScript>
function BrowserMenuInfo() {

  //alert("Creating instance of BrowserLayerInfo.");
  if (is.ns4) {
    if (is.win32) {
      this.itemHeight = 16;
    else if (is.linux) {
      this.itemHeight = 15;
    else {
      this.itemHeight = 15;
    }
    this.cellOffset  = 2;
    this.leftOffset  = 2;
    this.mTopOffset  = 2;
    this.wBarPadding = 4;
    this.hBarPadding = 6;
    this.itemPadding = 10;
    this.itemSpacing = 2;
    this.menuPadding = -2;
    this.mBarOffset  = 4;
    this.bBarOffset  = -2;
    this.dividerHeight = 2;
    this.bwPadding = 4;
    this.bhPadding = 4;
    this.fontSize = 12;
    if (is.win32) {
      this.charWidth = 7;
    else if (is.linux) {
      this.charWidth = 6;
    else {
      this.charWidth = 6;
    }
    this.divType = "layer";
    //Now set foreground/background colors -- Netscape 4.xx only.
    window.mtActive   = "#FFFF00";
    window.mtPassive  = "#FFFFFF";
    window.mbActive   = "#FF0000";
    window.mbPassive  = "#081C92";
  else if (is.kq) {
    this.itemHeight  = 18;
    this.cellOffset  = 4;
    this.leftOffset  = 0;
    this.mTopOffset  = 0;
    this.wBarPadding = 2;
    this.hBarPadding = 6;
    this.itemSpacing = 0;
    this.itemPadding = 2;
    this.menuPadding = 0;
    this.mBarOffset  = 4;
    this.bBarOffset  = 4;
    this.dividerHeight = 1;
    this.bwPadding = 2;
    this.bhPadding = 4;
    this.fontSize = 10;
    this.charWidth = 7;
    this.divType = "div";
  else if (is.op5 || is.op6) {
    this.itemHeight  = 17;
    this.cellOffset  = 4;
    this.leftOffset  = 2;
    this.mTopOffset  = 0;
    this.wBarPadding = 2;
    this.hBarPadding = 6;
    this.itemPadding = 10;
    this.itemSpacing = 2;
    this.menuPadding = 2;
    this.mBarOffset  = 6;
    this.bBarOffset  = 4;
    this.dividerHeight = 1;
    this.bwPadding = 2;
    this.bhPadding = 4;
    this.fontSize = 10;
    this.charWidth = 6;
    this.divType = "div";
  else if (is.ie4) {
    this.itemHeight  = 18;
    this.cellOffset  = 0;
    this.leftOffset  = 0;
    this.mTopOffset  = 0;
    this.wBarPadding = 4;
    this.hBarPadding = 5;
    this.itemPadding = 10;
    this.itemSpacing = 2;
    this.menuPadding = -2;
    this.mBarOffset  = 3;
    this.bBarOffset  = -3;
    this.dividerHeight = 1;
    this.bwPadding = 4;
    this.bhPadding = 2;
    this.fontSize = 10;
    this.charWidth = 6;
    this.divType = "div";
  else if (is.ie5) {
    this.itemHeight  = 20;
    this.cellOffset  = 0;
    this.leftOffset  = 0;
    this.mTopOffset  = 0;
    this.wBarPadding = 4;
    this.hBarPadding = 8;
    this.itemPadding = 11;
    this.itemSpacing = 0;
    this.menuPadding = 2;
    this.mBarOffset  = 4;
    this.bBarOffset  = -2;
    this.dividerHeight = 1;
    this.bwPadding = 4;
    this.bhPadding = 2;
    this.fontSize = 10;
    this.charWidth = 6;
    this.divType = "div";
  else if (is.ie6) {
    this.itemHeight  = 18;
    this.cellOffset  = 4;
    this.leftOffset  = 0;
    this.mTopOffset  = 0;
    this.wBarPadding = 0;
    this.hBarPadding = 6;
    this.itemPadding = 11;
    this.itemSpacing = 2;
    this.menuPadding = 2;
    this.mBarOffset  = 4;
    this.bBarOffset  = 4;
    this.dividerHeight = 1;
    this.bwPadding = 2;
    this.bhPadding = 4;
    this.fontSize = 10;
    this.charWidth = 6;
    this.divType = "div";
  else if (is.mza || is.gla || is.ns6) {
    this.itemHeight = 18;
    this.cellOffset  = 4;
    this.leftOffset  = 0;
    this.mTopOffset  = 0;
    this.wBarPadding = 2;
    this.hBarPadding = 6;
    this.itemSpacing = 0;
    this.itemPadding = 2;
    this.menuPadding = 0;
    this.mBarOffset  = 4;
    this.bBarOffset  = 4;
    this.dividerHeight = 1;
    this.bwPadding = 2;
    this.bhPadding = 4;
    if (is.win32) {
      this.fontSize = 10;
    else if (is.linux) {
      this.fontSize = 12;
    else {
      this.fontSize = 10;
    }
    this.charWidth = 7;
    this.divType = "div";
  else if (is.w3c) {
    this.itemHeight  = 19;
    this.cellOffset  = 0;
    this.leftOffset  = 0;
    this.mTopOffset  = 0;
    this.wBarPadding = 0;
    this.hBarPadding = 0;
    this.itemSpacing = 6;
    this.itemPadding = 2;
    this.menuPadding = 0;
    this.mBarOffset  = 3;
    this.bBarOffset  = 5;
    this.dividerHeight = 1;
    this.bwPadding = 0;
    this.bhPadding = 0;
    this.fontSize = 10;
    this.charWidth = 7;
    this.divType = "div";
  else {
    alert("This should never happen.");
    return 0;
  }
}
</SCRIPT>
<!-- menu.js -->
<SCRIPT language=JavaScript>
var blInfo     = new BrowserMenuInfo();

//  Create a test cell to read the style.
    document.write("<" + blInfo.divType + ' id="test.cell"');
    document.write('" class="menuItem" ');
    document.write(setStyle(blInfo.divType, blInfo.fontSize, 0010020,null,null,"hidden"">");
    document.write("test.cell");
    document.writeln('</' + blInfo.divType + '>');
//  Read the style during activateMenus();


function startSiteMap(mName,mTarget) {

  window.menuName   = mName;
  window.menuTarget = mTarget;
  window.menuPntr   = "/images/tri.gif";
  window.menuCells  = new Array();
  window.menuPopups = 0;
  window.menuHeads  = 0;
  window.menuLevel  = 0;
  window.menuMain   = 0;
  window.menuLayers = new Object();
  window.menuStack  = new Array();
  window.menuBody   = new Array();
  window.bodyCells  = new Array();
  window.mbActive   = "#FF0000";
  window.mtActive   = "#FFFF00";
}

function menuItem(label,action,width,level,popup) {

  if (label == 0) {
    this.label = label;
  else {
    this.label = "&nbsp;" + label;
  }
  this.action = action;
  this.width  = width;
  this.level  = level;
  this.popup  = popup;
}

function bodyItem(cells,popup,level,left,top,width,height) {

  this.cells  = cells;
  this.popup  = popup;
  this.level  = level;
  this.left   = left;
  this.top    = top;
  this.width  = width;
  this.height = height;
}

function stackMenuBody(queue,bPopup,bLevel,bLeft,bTop,bWidth,bHeight) {

  var mBody,i;

  mBody = new bodyItem(window.bodyCells.length,bPopup,bLevel,bLeft,bTop,bWidth,bHeight);
  window.menuBody[window.menuBody.length= mBody;
  for (i = 0; i < queue.length; i++) {
    window.bodyCells[window.bodyCells.length= queue[i];
  }
  window.bodyCells[window.bodyCells.length0;
}

function addMenuDivider() {

  var mItem,mLevel;

  mLevel = window.menuLevel;
  mItem  = new menuItem(0,0,0,mLevel,0);
  window.menuCells[window.menuCells.length