                                                                                                                                                                                                                                                               
function getObject(id) {
	var ret=null;
    if (document.getElementById) {
        eval("ret = document.getElementById(id)");
    } else {
        if (document.layers) {
            ret = document.layers[id];
        } else {
            if (document.all) {
                eval("ret = document.all." + id);
            }
        }
    }
	return(ret);
}

function changeDisplay(id, show) {
	action = "none";
	if(show) {
       action  =  "block";
	}
	getObject(id).style.display = action;
}

function tarkenna(sourceId, targetId, aihePuu) {
	if(!isDHTML()) {
		return;
	}
	var target = getObject(targetId);
	var source = getObject(sourceId);
	
	for(j in aihePuu) {
		var tmp = aihePuu[j].value;
		if(tmp==undefined) {
			tmp = aihePuu[j].teksti;
		}
		if(source.value == tmp) {
			loadOptions(target.options, aihePuu[j].arr);
			target.disabled=false;
			return;
		}
	}
	target.disabled=true;
}

function loadOptions(target, lista) {
	target.length=0;
	var c=0, hasArray;

	for(i in lista) {
		
		target[c] = new Option(lista[i].teksti, lista[i].teksti);
		
		if(lista[i].arr!=undefined) {
			target[c].className="otsikko";
		} else {
			target[c].className="normaali";
		}
		c++;
		var tmpLista = lista[i].arr;
		for(j in tmpLista) {
			var tmp = tmpLista[j].teksti;
			if(getInternetExplorerVersion() != null) {
				target[c]= new Option("     " + tmpLista[j].teksti,tmpLista[j].teksti);
			} else {
				target[c]=new Option(tmpLista[j].teksti,tmpLista[j].teksti);
			}
			target[c].className="ala";
			c++
		}
	}	
}


function aihe(teksti, value, arr) {
	this.teksti=teksti;
	this.value=value;
	this.arr=arr;
}

function isDHTML() {
	if( document.getElementById || document.all || document.layers) {
		return true;
	}
}

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = null; // Return value assumes failure
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    rv = -1;
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}


