// Summary required code
function whenReady() {}
// end Summary required code

function BrowserCheck() {
  var b = navigator.appName;
  if (b=="Netscape") {
    this.b = "ns";
  }
  else if (b=="Microsoft Internet Explorer") {
    this.b = "ie";
  }
  else {
    this.b = b;
  }
  this.v = parseInt(navigator.appVersion);
  this.ns = (this.b=="ns" && this.v>=4);
  if (this.ns) {
    //alert("We are 'Netscape'");
  }
  this.ns4 = (this.b=="ns" && this.v==4);
  this.ns5 = (this.b=="ns" && this.v==5);
  this.ie = (this.b=="ie" && this.v>=4);
  if (this.ie) {
    //alert("We are 'Internet Explorer'");
  }
  this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0);
  this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0);
  if (this.ie5) {
    this.v = 5;
  }
  this.min = (this.ns||this.ie);
}

// automatically create the "is" object
is = new BrowserCheck();

function css(id, left, top, width, height, color, vis, z, other) {
  if (id=="START") {
    return '<STYLE TYPE="text/css">\n';
  }
  else if (id=="END") {
    return '</STYLE>';
  }
  var str = (left!=null && top!=null)? 
		'#' + id + ' {position:absolute; left:' + left + 'px; top:' + top + 'px;' : 
		'#' + id + ' {position:relative;';
  if (arguments.length>=4 && width!=null) {
    str += ' width:' + width + 'px;';
  }
  if (arguments.length>=5 && height!=null) {
    str += ' height:' + height + 'px;';
    if (arguments.length<9 || other.indexOf('clip')==-1) {
      str += ' clip:rect(0px ' + width +'px ' + height + 'px 0px);';
    }
  }
  if (arguments.length>=6 && color!=null) {
    str += (document.layers)? 
      ' layer-background-color:' + color + ';' : 
      ' background-color:' + color + ';';
  }
  if (arguments.length>=7 && vis!=null) {
    str += ' visibility:' + vis + ';';
  }
  if (arguments.length>=8 && z!=null) {
    str += ' z-index:' + z + ';';
  }
  if (arguments.length==9 && other!=null) {
    str += ' ' + other;
  }
  str += '}\n';
  return str;
}

function writeCSS(str, showAlert) {
  str = css('START') + str + css('END');
  document.write(str);
  if (showAlert) {
    alert(str);
  }
}

function winWidth() {
  return (is.ns)? 
    window.innerWidth+10: 
    document.body.offsetWidth;
}

function winHeight() {
  return (is.ns)? 
    window.innerHeight+20 : 
    document.body.offsetHeight;
}

function resized() {
  history.go(0);
}

function show(object) {
  if (document.getElementById && document.getElementById(object) != null) {
    //alert("will show '" + object + "' with getElementById");
    var node = document.getElementById(object);
    //dumpObject(node);
    //alert("Visibility is:" + node.style.visibility);
    node.style.visibility='visible';
    //alert("Visibility is now:" + node.style.visibility);
  }
  else if (document.layers && document.layers[object] != null) {
    //alert("showing '" + object + "' by setting visibility");
    document.layers[object].visibility = 'visible';
  }
  else if (document.all) { 
    //alert("showing '" + object + "' by setting style.visibility");
    document.all[object].style.visibility = 'visible';
  }
  else {
    if (!is.ns4) alert("Can't show '" + object + "'!");
  }
}

function findObjByName(n, d) {
  var p,i,x;  
  if (d == null) {
    d = document; 
  }
  if (!(x=d[n])) {
    //alert("" + n + " is not an attribute");
    if (d.all) {
      x = d.all[n]; 
      //if (x) alert("Found " + n + " in document.all");
    }
    else if (d.getElementById) {
      //alert("No document.all, try getElementById");
      if (!(x=d.getElementById(n))) {
        //alert("No " + n + " using getElementById");
      }
      else {
        //alert("Found " + n + " using getElementById");
      }
    }
    else {
      //alert("Document has no getElementById");
    }
  }
  else {
    //alert("Found " + n + " as direct attribute of document");
  }
  //if (!x && d.forms.length) alert("Look for " + n + " in " + d.forms.length + " forms");
  for (i=0; !x && i<d.forms.length; i++) {
    x = d.forms[i][n];
    //if (x) alert("Found " + n + " in form " + i);
    //else alert("No " + n + " in form " + i);
  }
  //if (!x && d.layers && d.layers.length) alert("Look for " + n + " in " + d.layers.length + " layers");
  for (i=0; !x && d.layers && i<d.layers.length; i++) {
    x = stringToSubLayerObj(d.layers[i], n);
    if (!x) {
      x = findObjByName(n, d.layers[i].document); 
    }
  }
  return x;
}

function stringToSubLayerObj(parentLayerObj, subLayerStr) {
  //alert("sTSLO:" + subLayerStr);
  if (is.ns4) {
    //alert("  ns4:" + subLayerStr);
    //return(parentLayerObj.document[subLayerStr]);
    if (parentLayerObj && parentLayerObj.document && parentLayerObj.document[subLayerStr]) {
      //alert("  return obj from parent.document." + subLayerStr);
      return(parentLayerObj.document[subLayerStr]);
    }
    else {
      //alert("  no obj in parent.document." + subLayerStr + ", *not* trying findObjByName");
      //return(findObjByName(subLayerStr));
      return null;
    }
  }
  else {
    //alert("  not ns4:" + subLayerStr);
    return(eval("document.all."+ subLayerStr +".style"));
  }
}

function setdivdims(divName, wPercent, hPercent, targName) {
  var boxHeight, boxWidth;
  boxWidth = Math.round(winWidth() * wPercent) - 50;
  boxHeight = Math.round(winHeight() * hPercent) - 50;
  //alert("Will set div width, height to:" + boxWidth + "," + boxHeight);
  var div = findObjByName(divName);
  if (div) {
    if (div.style) {
      //alert("Div has style, use it.");
      div = div.style;
    }
    if (is.ns) {
      //alert("We're ns, setting width and height");
      div.width = boxWidth;
      div.height = boxHeight;
    }
    else {
      //alert("We're not ns, setting width and height as strings");
      div.width = "" + boxWidth + "px";
      div.height = "" + boxHeight + "px";
    }
  }
  else {
    //alert("Couldn't find box layer object:" + divName);
  }
  show(divName);
  //alert("just showed, first try");
  // In case that didn't work, set it directly
  if (div.visibility) {
    div.visibility = "visible";
  }
  //alert("just showed, second and last try");
  if (targName) {
    var scrollTarg = findObjByName(targName);
    if (scrollTarg) {
      if (scrollTarg.focus) {
	scrollTarg.focus();
      }
      else {
        alert("Have scroll target:" + targName + ", but it has no 'focus' method");
      }
    }
    else {
      alert("Couldn't get scroll target object:" + targName);
    }
  }
}

function dumpObject(anObject) {
  alert("Dump object");
  var msgStr = "";
  var i = 0;
  var props = new Array();
  for (prop in anObject) {
    if (prop == "font") {
      alert("Skipping property " + prop + "!");
      continue;
    }
    if (anObject[prop]) {
      //alert("Object " + anObject + "'s " + prop + " has value:" + anObject[prop]);
      msgStr += prop + ':' + anObject[prop] + ' ';
      if (msgStr.length > 250) {
	props[i++] = new String(msgStr);
	msgStr = "";
      }
    }
    else {
      //msgStr += prop + ':novalue\n';
    }
  }
  if (props.length > 0) {
    for (var j=0; j<props.length; j++) {
      alert(props[j]);
    }
  }
  alert(msgStr);
}


