<!--
  /*************************************************\
    (D)ynamic (U)niversal (R)elated (P)opup (M)enus
    Created : 04022000
    Last Modified : 04032000
    Coded by : Cyanide_7
    URL : http://www7.ewebcity.com/cyanide7/durpm/index.html
    Page : http://www7.ewebcity.com/cyanide7
    Email : leo7278@hotmail.com
  \*************************************************/
window.onerror = errorHandler;
function errorHandler(e,f,l){
  alert("Error in file: " + f + ", line: " +l+"\n\t" + e);
  return true;
}
function DURPM(text,value,parent){
  this.parent = parent;
  this.children = new Array();
  this.text = text;
  this.value = value;
  this.header = "Please make a selection:"; // default
  this.target = "_self"; // default
  this.winArgs = ""; // default
  this.stat = false; // default

  this.addChild = addChild;
  this.relate = relate;
  this.loadSelection = loadSelection;
  this.back = back;
  this.jmp = jmp;
  this.isStatic = isStatic;
  this.redir = redir;
  this.write = write;

  if(typeof(parent)=="undefined"){
    this.parent = null;
    DURPMArray.current = DURPMArray[this.value] = this;
  }

  function addChild(text, value){
    return (this.children[this.children.length] = new DURPM(text, value, this));
  }
  function relate(menu){
    var index = menu.selectedIndex - 1; // remove header
    if(this.parent!=null)
      index--;
    if(index==-1 && this.parent!=null)
      this.back(menu);
    else if(index > -1)
      if(this.children[index].children.length > 0)
        this.children[index].loadSelection(menu);
      else
        this.jmp(index);
  }
  function loadSelection(menu){
    if(menu==null){
      menu = document.forms[this.text][this.value];
      menu.durpm = this;
    }
    for(var i = menu.options.length; i > 0; i--)
      menu.options[i-1] = null;
    menu.options[0] = new Option(this.header, null, true, true);
    if(this.parent!=null)
      menu.options[1] = new Option("BACK", null);
    offset = menu.options.length;
    for(var i = 0; i < this.children.length; i++)
      menu.options[i+offset] = new Option(this.children[i].text, this.children[i].text);
    menu.durpm = this;
  }
  function back(menu){
    this.parent.loadSelection(menu);
  }
  function jmp(index){
    if(!((this.parent!=null)?this.parent.isStatic():this.stat))
      this.redir(this.children[index].value);
  }
  function isStatic(){
    return (this.parent!=null)?this.parent.isStatic():this.stat;
  }
      
  function redir(page){
    if(this.parent!=null)
      this.parent.redir(page);
    else if(page!=null){
      if(this.winArgs.length == 0)
        win = window.open(page, this.target);
      else
        win = window.open(page, this.target, this.winArgs);
      if(typeof(focus)!="undefined")
        win.focus();
    }
  }
  function write(cols, rows, size){
    document.writeln("<select name=\""+this.value+"\" size=\""+size+"\" onChange=\"this.durpm.relate(this);\">");
    for(var i = 0; i < rows-1; i++)
      document.writeln("<option> </option>");
    document.write("<option>");
    for(var i = 0; i < cols; i++)
      document.write("=");
    document.writeln("</option>");
    document.writeln("</select>");
  }
}
function main(){
  for(var durpm in DURPMArray)
    if(typeof(DURPMArray[durpm])=="object")
      DURPMArray[durpm].loadSelection(null);
}
function addCat(text){
  DURPMArray.current = DURPMArray.current.addChild(text);
}
function endCat(){
  if(DURPMArray.current.parent!=null)
    DURPMArray.current = DURPMArray.current.parent;
}
function addItem(text, value){
  DURPMArray.current.addChild(text, value);
}
function addHeader(text){
  DURPMArray.current.header = text;
}
function setWindowArgs(args){
  DURPMArray.current.winArgs = args;
}
function setTarget(target){
  DURPMArray.current.target = target;
}
function setStatic(){
  DURPMArray.current.stat = true;
}
//-->
