// Original:  Cyanide_7 (leo7278@hotmail.com) //
// Web Site:  http://members.xoom.com/cyanide_7 //

// This script and many more are available free online at //
// The JavaScript Source!! http://javascript.internet.com //

window.onerror = errorHandler;
function errorHandler(e,f,l){
alert("Error en archivo: " + f + ", línea: " +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 = "Select a type of new release:"; // default

this.addChild = addChild;
this.relate = relate;
this.loadSelection = loadSelection;
this.back = back;
this.jmp = jmp;
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.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("ATRÁS", 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){
location.href = this.children[index].value; // optional redirect for navigation
return true;
}
function write(rows, cols, 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;
}

var v = (typeof(Option)!="undefined");
var DURPMArray = new Array();
