//-- Variables

var shown_location = 0;
var shown_unit = 0;
var shown_segment = 0;
var empty_selection = 0;

//-------------------------------------------------------------------------------


//-------------------------------------------------------------------------------
//-- DropDown change handling

//User has changed location
function locationChanged(objForm) {
	shown_location = objForm.Region[objForm.Region.selectedIndex].value;
	shown_unit = '';
	shown_segment = objForm.Segment[objForm.Segment.selectedIndex].value;

	if (shown_location == '') {
		resetUnitSegments(objForm);
	} else {
		updateUnits(objForm);
		updateSegments(objForm);
	}

}

//User has changed unit
function unitChanged(objForm) {
	//shown_location = document.search.region[document.search.region.selectedIndex].value;
	shown_unit = objForm.Unit[objForm.Unit.selectedIndex].value;
	//shown_segment = document.search.segment[document.search.segment.selectedIndex].value;
	
	updateSegments(objForm);
}

//-------------------------------------------------------------------------------


//-------------------------------------------------------------------------------
//-- Update functions for rows in dropdowns

//Reset Unit and Segment drop downs
function resetUnitSegments(objForm) {
	var i, j
	i=0;
	j=1;

	objForm.Unit.length = 1;

	for(i=0; i<ArrUnits.length; i++) {
		optname = ArrUnits[i].unit;
		optvalue = ArrUnits[i].unit;
		objForm.Unit[j++] = new Option(optname, optvalue);
	}

	i=0;
	j=1;
	
	objForm.Segment.length = 1;

	for(i=0; i<ArrSegments.length; i++) {
		optname = ArrSegments[i].segment;
		optvalue = ArrSegments[i].segment;
		objForm.Segment[j++] = new Option(optname, optvalue);
	}
}

//Update units
function updateUnits(objForm) {
	var i, j, optname, optvalue;
	i=0;
	j=1;

	objForm.Unit.length = 1;

	for(i=0; i<ArrUnitLocations.length; i++) {

		if(ArrUnitLocations[i].location == shown_location) {
			optname = ArrUnitLocations[i].unit;
			optvalue = ArrUnitLocations[i].unit;
			objForm.Unit[j++] = new Option(optname, optvalue);
		}

	}
}

//Update segments
function updateSegments(objForm) {
	var i, j, optname, optvalue;
	i=0;
	j=1;

	objForm.Segment.length = 1;

	for(i=0; i<ArrUnitSegments.length; i++) {

		if(ArrUnitSegments[i].unit == shown_unit) {
			optname = ArrUnitSegments[i].segment;
			optvalue = ArrUnitSegments[i].segment;
			objForm.Segment[j++] = new Option(optname, optvalue);
		}

	}
	// 
	objForm.Segment.selected = 1;
}

//-------------------------------------------------------------------------------


//-------------------------------------------------------------------------------
//-- Create objects

function UnitLocation(unit, location) {
	this.unit = unit;
	this.location = location;
}
function UnitSegment(unit, segment) {
	this.unit = unit;
	this.segment = segment;
}
function Unit(unit) {
	this.unit = unit;
}
function Segment(segment) {
	this.segment = segment;
}

//-------------------------------------------------------------------------------
