/* (C) 2003 h3 basis GmbH, Germany */
/* All rights reserved             */
/* see h3.basis.com                */
/* use this program only with      */
/* h3 basis generator              */
/* $Id: model.js,v 1.9 2003/06/07 10:13:36 rhoppe Exp $ */
var root;
var items;
var selectedItem;
var leaf;
var lfdNr=0;
var heute=new Date().getTime();
var iconPlus=0;
var iconJoin=1;
var iconMinus=2;
var iconPlusTop=3;
var iconJoinTop=4;
var iconMinusTop=5;
var iconPlusBottom=6;
var iconJoinBottom=7;
var iconMinusBottom=8;
var iconPlusOnly=9;
var iconBlankOnly=10;
var iconMinusOnly=11;
var iconFolderOpen=21;
var iconFolder=22;
var iconDocument=23;
var iconNew=27;
var iconLine=12;
var statusOpened=1;
var statusClosed=-1;
var selected=1;
var unselected=2;
var theTab=1;
var theBrowser=new BrowserInfo();
var theItem;

function BrowserInfo() {
 this.code='unknown';
 this.version=0;
 this.platform='Win';
 var ua=navigator.userAgent;
 var i=ua.indexOf('MSIE');
 if (i >= 0) {
  this.code='MSIE';
  i += 5;
 } else {
  i=ua.indexOf('Mozilla/');
  if (i >= 0) {
   this.code='NS';
   i += 8;
  }
 }
 this.version=parseFloat(ua.substring(i, i+4));
 if (ua.indexOf('Mac') >= 0) {this.platform='Mac';}
 if (ua.indexOf('OS/2') >= 0) {this.platform='OS/2';}
 if (ua.indexOf('X11') >= 0) {this.platform='UNIX';}
 var v=this.version;
 var p=this.platform;
 var NS=(this.code == 'NS');
 var IE=(this.code == 'MSIE');
 this.rootPath=window.location.pathname;
 var lastSlash=this.rootPath.lastIndexOf('/');
 if (lastSlash<=0)
   lastSlash=this.rootPath.lastIndexOf('\\');
 this.rootPath=this.rootPath.substring(0, lastSlash);
}

function Icon(source){
 this.src=source;
 return this;
}

// The ModelItem object. This contains the data and functions for drawing each item.
function ModelItem (owner, item, text, path, desc, proc, quest, created) {
 this.owner=owner;
 this.id=lfdNr++;
 this.item=item;
 this.children=null;
 this.text=text;
 this.path=path;
 this.desc=desc;
 this.proc=proc;
 this.quest=quest;
 this.img=icons[iconDocument];
 this.created=created;
 this.created=new Date(created);
 this.neu=heute-this.created.getTime();
 this.status=0;
 this.paint=paintItem;
 this.addChild=addChildren;
 this.target="h3text";
 this.expand=expandPath;
 if( owner ){
  owner.addChild(this);
 }
 if(! items){
  items=new Array();
 }
 items[this.id]=this;
 return this;
}

function expandPath(){
  if(this.owner && this.owner.status == statusClosed){
    this.owner.status=statusOpened;
    this.owner.expand();
  }
}

function hover(id, status){
 var anc=frames[0].document.anchors;
 for(var i=0; i<anc.length; i++)
   if(anc[i].id && anc[i].id==id)
     break;
 if(i<anc.length){
  switch(status) {
   case "a": // activ
    anc[i].style.color="#0000ff"; // blue
    anc[i].style.fontWeight="bolder";
    break;
   case "n": // normal
    anc[i].style.color="#000000"; // black
    anc[i].style.fontWeight="bold";
    break;
   case "h": // mouse over
    anc[i].style.color="#e00000"; // some kind of red
    anc[i].style.fontWeight="bolder";
    window.status = "Item: "+id;
    break;
   case "o": // mouse out
    anc[i].style.color="#0000ff"; // blue
    if(id != theItem.id) {
     anc[i].style.color="#000000";
     anc[i].style.fontWeight="bold";
    }
    break;
  }
 }
}

function toggle(id){
 items[id].status=( items[id].status == statusOpened ? statusClosed : statusOpened );
 items[id].img=( items[id].status == statusOpened ? icons[iconFolderOpen] : icons[iconFolder] );
}

function disp(tab) {
 theTab=tab;
 go(theItem.item);
}

function follow(item,tab){
  theTab=tab;
  go(item);
  root.paint(frames[0].document);
  hover(theItem.id, "a");
}

function go(item) {
 // deselect last hightlighted item
 if(theItem){
  hover(theItem.id, "n");
 }
 for(i in items){
   if(items[i].item==item){
     theItem=items[i];
     break;
   }
 }
 // expand the tree
 theItem.expand();
 // highlight current item
 hover(theItem.id, "a");
 var file="/empty";
 // try to display the required document or change to the next
 for (i=1; i<=2; i++) {
   if(theTab==1) {
    if(theItem.desc == "" ) {
     theTab=2;
    } else {
     file=theItem.path+"t"+theItem.desc;
     break;
    }
   }
   if(theTab==2) {
    if(theItem.proc == "" ) {
     theTab=3;
    } else {
     file=theItem.path+"p"+theItem.proc;
     break;
    }
   }
   if(theTab==3) {
    if(theItem.quest == "n" ) {
     theTab=1;
    } else {
     file=theItem.path+"q"+theItem.item;
     break;
    }
   }
 }
 open(theBrowser.rootPath+file+".html", theItem.target);
 // highlight register
 var anc = frames[1].document.anchors;
 for(i in anc) {
  if(anc[i].style ) {
   if(anc[i].id == theTab){
    anc[i].style.color="#0000ff";
   } else {
    anc[i].style.color="#000000";
   }
  }
 }
}

function addChildren(child){
 if( ! this.children ){
  this.children=new Array();
  this.status=statusClosed;
 }
 this.children[this.children.length]=child;
 this.img=icons[iconFolder];
}

function paintAll(){
  root.paint(frames["h3menu"].document);
}

function paintItem(doc){
 if (this.owner==null) { // root?
  topOffset=0;
  if(frames[0].document.body) topOffset=frames["h3menu"].document.body.scrollTop;
  with(doc){
  close();
  open("text/html");
  writeln("<head>");
  writeln("<style type=\"text/css\">");
  writeln("p { font-size:10pt; font-style:plain; font-weight:bold; font-family:\"Helvetica\",\"Arial\"; }");
  writeln("a { text-decoration:none; }");
  writeln(" .menuItem {font-size:10pt; font-style:plain; font-weight:bold; font-family:\"Helvetica\",\"Arial\";margin-top:-2pt;white-space:nowrap;}");
  writeln("</style>");
  writeln("<script>");
  writeln("function info(e){");
  writeln("if(event.button==2||event.button==3)alert('Model-Database: "+root.text+" ("+root.proc+")\\nGenerated at "+root.created+ " by "+root.desc+"\\nvisit "+root.path+"');");
  writeln("}");
  writeln("document.onmousedown=info;");
  writeln("</script>");
  writeln("</head>");
  writeln("<br>");
  writeln("<body text=\"#000000\" background=\"/images/toc_bg.jpg\" link=\"#000000\" vlink=\"#000000\" alink=\"#000000\">");
  writeln("<p align=\"center\"><a href=\"http://www.mungo-racing.de\" target=\"_parent\"><img border=\"0\" src=\"/images/mungo_logotoc.gif\" width=\"195\" height=\"50\"></a><br>");
  writeln("<a href=\"/documents/mungo_prasentation.pdf\" target=\"_new\"><img border=\"0\" src=\"/images/download_presentation.gif\" width=\"190\" height=\"12\"></a></p>");
  }
  this.status=statusOpened;
 } else {
  signIcon=1;
  // first child of parent
  if( this.owner == root ){
   if( root.children[0] == this ){
    signIcon+=3;
   }
  }
  signIcon += (this.owner && this.owner.children[this.owner.children.length-1] == this ? 6 : 0 );

  if (! this.children ){
   var beginAnchor="";
   var endAnchor="";
   var onClick="";
  } else {
   var onClick=' onClick="parent.toggle(' +this.id+');return true;"';
   var beginAnchor='<a href="javascript:parent.paintAll()"' +onClick+ '>';
   var endAnchor="</a>";
   signIcon += this.status;
  }
  line='';
  var myParent=this.owner;
  while (myParent && myParent != root){
   if( myParent.owner.children[myParent.owner.children.length-1] != myParent ){
    line='<img src="' +icons[iconLine].src+ '">'+line;
   } else {
    line='<img src="' +icons[iconBlankOnly].src+ '">'+line;
   }
   myParent=myParent.owner;
  }
  line='<div id="m' +this.id+ '" class="menuItem"><nobr>'+line;
  line +=
   beginAnchor
  +'<img src="' +icons[signIcon].src+ '" border="0" alt="'
  + (this.status == statusClosed ? expand : collapse )
  +'">'
  +endAnchor;
  if (this.path != ""){
   line += '<a id="'+this.id+'" href="javascript:parent.go('+this.item+
      ')" onmouseover="parent.hover('+this.id+
      ',\'h\');" onmouseout="parent.hover('+this.id+',\'o\')">';
  }
  line += '<img src="' +this.img.src+ '" border=0>';

  if((this.path != "") && (this.neu < ageMillis)) {
   line += '<img src="'+theBrowser.rootPath+'/images/tree/new.gif" border=0 '
   + 'alt="' + this.created.toLocaleString()
   + '"> ';
  }
  line += this.text;
  if (this.path != ""){
   line += '</a>' ;
  }
  line += '</nobr></div>';
  // alert(line);
  doc.writeln(line);
 }
 if (this.status == statusOpened && this.children ) {
  for (var i=0; i < this.children.length; i++) {
  this.children[i].paint(doc);
  }
 }
 if (this.owner==null) { // root?
  if(topOffset>0) frames[0].scroll(0,topOffset);
 }
}

function hideElement(win, id) {
  win.document.getElementById(id).style.visibility = "hidden";
}

function showElement(win, id) {
  table = win.document.getElementById(id);
  table.style.visibility = "visible";
  table.style.top = win.event.y+50+frames["h3text"].document.body.scrollTop;
  table.style.left = win.event.x+20+frames["h3text"].document.body.scrollLeft;
}

var icons=new Array();
var ip=theBrowser.rootPath+'/images/tree/';
ip += (theBrowser.platform == 'Mac') ? 'mac/' : ((theBrowser.platform == 'OS/2') ? 'os2/' : 'win/');

icons[iconPlus]=new Icon(ip+'plus.gif');
icons[iconJoin]=new Icon(ip+'join.gif');
icons[iconMinus]=new Icon(ip+'minus.gif');
icons[iconPlusTop]=new Icon(ip+'plustop.gif');
icons[iconJoinTop]=new Icon(ip+'jointop.gif');
icons[iconMinusTop]=new Icon(ip+'minustop.gif');
icons[iconPlusBottom]=new Icon(ip+'plusbottom.gif');
icons[iconJoinBottom]=new Icon(ip+'joinbottom.gif');
icons[iconMinusBottom]=new Icon(ip+'minusbottom.gif');
icons[iconPlusOnly]=new Icon(ip+'plusonly.gif');
icons[iconBlankOnly]=new Icon(ip+'blank.gif');
icons[iconMinusOnly]=new Icon(ip+'minusonly.gif');
icons[iconFolder]=new Icon(ip+'folderclosed.gif');
icons[iconFolderOpen]=new Icon(ip+'folderopen.gif');
icons[iconNew]=new Icon(ip+'new.gif' );
icons[iconLine]=new Icon(ip+'line.gif');
var di=theBrowser.rootPath+'/images/tree/'+theBrowser.code.toLowerCase()+'_doc';
icons[iconDocument]=new Icon(di+'.gif');
