/* global advisor javaScript functions
 Oct. 6,  esc1jxw */

var Area = new Array(   'Acres',
			'Hectares',
			'Square centimeters',
			'Square feet',
			'Square inches',
			'Square kilometers',
			'Square meters',
			'Square miles',
			'Square millimeters',
			'Square yards'
		     );

var Length = new Array(	'Centimeters',
			'Feet',
			'Inches',
			'Kilometers',
			'Meters',
			'Microns',
			'Miles (nautical)',
			'Miles (statute)',
			'Millimeters',
			'Yards');

var Temperature = new Array( 'Celsius',
			     'Fahrenheit');

var Volume = new Array(	'Barrels (US, Oil)',
			'Bushels (US)',
			'Cubic centimeters',
			'Cubic feet',
			'Cubic inches',
			'Cubic meters',
			'Cubic yards',
			'Cups',
			'Gallons (US, Dry)',
			'Gallons (US, Liquid)',
			'Liters',
			'Ounces (US, Fluid)',
			'Pints (US, Dry)',
			'Pints (US, Liquid)',
			'Quarts (US, Dry)',
			'Quarts (US, Liquid)',
			'Tablespoons',
			'Teaspoons');

var Weight = new Array(	'Grams',
			'Kilograms',
			'Milligrams',
			'Ounces (standard)',
			'Pounds (standard)',
			'Tons (long)',
			'Tons (metric)',
			'Tons (US)');




/* -----------------------------------------------
FUNCTION: ga_setUpUnits
DESC: set up the 'units from' and 'units to' select options when this page is loaded
-------------------------------------------------*/

function ga_setUpUnits(aType, aUnitFrom, aUnitTo) {
	var unit_array = Weight;
	if(aType =='Area'){
		unit_array=Area;	
	}else if(aType =='Length'){
		unit_array=Length;
	}else if(aType =='Temperature'){
		unit_array=Temperature;
	}else if( aType == 'Volume'){
		unit_array=Volume;
	}
	
	document.forms.metricConversionForm.unitsFrom.options.length = 0;
	document.forms.metricConversionForm.unitsTo.options.length = 0;
	
	document.forms.metricConversionForm.unitsFrom.options[0]= new Option('Select Unit', '');
	document.forms.metricConversionForm.unitsTo.options[0]= new Option('Select Unit', '');
	
	document.forms.metricConversionForm.unitsFrom.selectedIndex=0;
	document.forms.metricConversionForm.unitsTo.selectedIndex=0;	
	
	for (i=0; i < unit_array.length; i++){	
		document.forms.metricConversionForm.unitsFrom.options[i+1] = new Option(unit_array[i], unit_array[i]);
		document.forms.metricConversionForm.unitsTo.options[i+1] = new Option(unit_array[i], unit_array[i]);
		if( unit_array[i] == aUnitFrom){
		      document.forms.metricConversionForm.unitsFrom.options[i+1].selected = true;
		}                        
		if( unit_array[i] == aUnitTo){
		       document.forms.metricConversionForm.unitsTo.options[i+1].selected = true;                  
                }
	}
}


/* -----------------------------------------------
FUNCTION: updateMetricUnits
DESC: Update units to match conversion type
ARGS:
	type - conversion type
-------------------------------------------------*/
function ga_updateMetricUnits(type, unitsFrom, unitsTo, layerName) {
	var selectedCat = type.options[type.selectedIndex].value;
	var unit_array = Weight;	
	if(selectedCat =='Area'){
		unit_array=Area;	
	}else if(selectedCat=='Length'){
		unit_array=Length;
	}else if(selectedCat=='Temperature'){
		unit_array=Temperature;
	}else if( selectedCat == 'Volume'){
		unit_array=Volume;
	}
	
	
	unitsFrom.options.length = 0;
	unitsTo.options.length = 0;

	unitsFrom.options[0]= new Option('Select Unit', '');
	unitsTo.options[0]= new Option('Select Unit', '');
	
	unitsFrom.selectedIndex=0;
	unitsTo.selectedIndex=0;

	for (i=0; i < unit_array.length; i++)
	{
		unitsFrom.options[i+1] = new Option(unit_array[i], unit_array[i] );
		unitsTo.options[i+1] = new Option(unit_array[i], unit_array[i]);
	}
	
	
	ga_hideLayer(layerName);
}


/* -----------------------------------------------
FUNCTION: ga_hideLayer
DESC: hide this text if other form field is updated
-------------------------------------------------*/
function ga_hideLayer(layerName){
	document.getElementById(layerName).style.visibility="hidden";
}


