/*******
dynamicMenus.js
load and maintain dynamic HTML select objects
Author: Arleigh Crawford
Created: 05:20 01 Aug 2001
Last Modified: 06:03 11 Sep 2001
(c) 2001 Adeo Communications Corporation.  All Rights Reserved.
*******/

function MenuElement(group, text, value){

    this.group = group
    this.option = new Option(text, value)
}

function CloneMenuElement(menuElement){
	return new MenuElement( menuElement.group, menuElement.option.text, menuElement.option.value );
}

function Redraw(){
    //if (supportedBrowser == 'net4plus' && supportedBrowser != 'net5plus') history.go(0);
    if (document.layers && !document.getElementByID) {
        history.go(0);
    }
}

function PopulateList(list, items, title, selectedItem, filter) {
    var j;
    var menuSet = false;
    if (title){
	    list.options[0] = new Option(title, "0" );
	    j = 1;
	}else{
		j = 0;
	}
    for (var i=0; i < items.length; i++) {
        if (filter == 0 || items[i].group == filter) {
        	if (j < 10){
	        	//alert("adding option: " + items[i].option.value);
	        }
            list.options[j] = items[i].option;
            if (list.options[j].value == selectedItem) {
                list.options[j].selected = true;
                menuSet = true;
            }
            j++;
        }
    }
    if (!menuSet && list.options[0]){
        list.options[0].selected = true;
    }
}

function ClearList(list, noTitle){
    var j;
    if (noTitle){
    	j = 0;
    }else{
    	j = 1;
    }
    for (var i=list.options.length - 1; i >= j; i--) {
        list.options[i] = null;
    }
}

function FilteredList(list, items, group, noTitle) {
    var j;
    if (noTitle){
    	j = 0;
    }else{
    	j = 1;
    }
    for (var i=0; i < items.length; i++) {
        if (group == 0 || group == items[i].group) {
            list.options[j++] = items[i].option;
            menuSet = true;
        }
    }
    if (list.options[0]){
	    list.options[0].selected=true;
	}
}

function SetList(list, value){
    for (var i=0; i < list.options.length; i++){
        if (list.options[i].value == value){
            list.selectedIndex = i;
            break;
        }
    }
}

function GetGroupByValue(items, value){
    for (var i=0; i < items.length; i++){
        if (value == items[i].option.value) return items[i].group;
    }
    return 0;
}

function SetSeries(value) {
    var mod = document.forms[0].model;
    ClearList(mod);
    FilteredList(mod, models, value);
    Redraw();
}

function SetModel(value) {
    var ser = document.forms[0].series;
    SetList(ser, GetGroupByValue(models, value));
}

function BrowserDetect()
{
  var agent = navigator.userAgent.toLowerCase();
  var version = parseInt(navigator.appVersion);

  // Internet Explorer
  if (agent.indexOf('msie 5') != -1 || agent.indexOf('msie 6') != -1)
    return 'msie5plus';
  else if (agent.indexOf('msie') != -1 && version >= 4)
    return 'msie4plus';

  // Netscape Navigator
  else if (agent.indexOf('mozilla') != -1 && agent.indexOf('spoofer') == -1 && agent.indexOf('compatible') == -1 && version >= 5)
    return 'net5plus';
  else if (agent.indexOf('mozilla') != -1 && agent.indexOf('spoofer') == -1 && agent.indexOf('compatible') == -1 && version >= 4)
    return 'net4plus';
  // Unsupported broswers
  else return null;
}
