/*
	Select Box Functions
	Included in this file:
	bindSelects( select_box_1 , select_box_2 )
*/

function returnObjById( id ) 
{ 
if(document.getElementById) 
	var returnVar = document.getElementById(id);
else if (document.all)
	var returnVar = document.all[id];
else if (document.layers)
	var returnVar = document.layers[id];
return returnVar;
}

function bindSelects(select1,select2){
	select1._bound_select=select2;
	// add trigger event to first select box
	select1.onchange = function(){
		this._bound_select.update(this.value)
	}
	//add update procedure to second select box
	select2.update=function(value){
		while(this.options.length > 0)this.removeChild(this.firstChild);
		var i,option;
		var length=this.optionsArray.length;
		for(i=0;i<length;i++){
			option=this.optionsArray[i];
			if(option.className=="v-"+value)this.appendChild(option);
			
	}//if(select2.length==0){
	
	//option=[0,"plz select",0];
	//this.appendChild(option);
	//alert(select2.length);
	//}
	}
	//remove all options and add to array
	var i, option;
	var length=select2.options.length;
	var select2value=select2.value;
	select2.optionsArray=[];
	//store options in array remove from select
	for(i=0;i<length;i++){
		option=select2.options[0];
		select2.optionsArray.push(option);
		select2.removeChild(option);
	}
	//initialise select2
	select2.update(select1.value);
	
	select2.value=select2value;
	
}