function highlight(div) {
	div.setAttribute("className", "hover");
}

function unhighlight(div) {
	div.setAttribute("className", "units");
}

function selectUnitType(units) {
	document.getElementById("unitTitle").innerHTML = units;
	document.getElementById("selectInputDiv").innerHTML = createUnitSelect("selectInput",units);
	document.getElementById("selectOutputDiv").innerHTML = createUnitSelect("selectOutput",units);
}

function createUnitSelect(id,units) {
	var arrName = new Array();
	var arrValue = new Array();
	switch (units) {
		case "Length":
			arrName = ["Meters [m]", "Centimeters [cm]", "Kilometers [km]", "Millimeters [mm]", "Feet [ft]","Yards [yd]", "Miles [mi]", "Inches [in]"];
			arrValue = ["1", "100", ".001","1000","3.28084","1.093613","0.000621","39.370079"];
			break;  
		case "Time":
			arrName = ["Seconds","Minute","Hour"];
			arrValue = ["3600","60","1"];
			break;
		case "Pressure":
			arrName = ["Pascals [PA]","Pounds-force/sq. inch [PSI]","Bars"];
			arrValue = ["1","0.000145","0.00001"];
			break;
		case "Force":
			arrName = ["Newtons [N]","Pounds [LBS]"];
			arrValue = ["1","0.224809"];
			break;
		case "Volume":
			arrName = ["Liters [l]","Gallons"];
			arrValue = ["1","0.264172"];
			break;
	}
	var disp = "<select id='" + id + "' onChange='calculate()' class='unitConversion'>";
	for (var i in arrName) {
		disp += "<option value=\"" + arrValue[i] + "\">" + arrName[i] + "</option>";
	}
	disp += "</select>"
	return disp;
}


function calculate() {
	 var im = document.getElementById("selectInput").value;
	 var om = document.getElementById("selectOutput").value;
	 var i = document.getElementById("input").value;
	 var standard = (i / im);
	 document.getElementById("output").value = (standard * om);
}

function calculateInput() {
	 var im = document.getElementById("selectInput").value;
	 var om = document.getElementById("selectOutput").value;
	 var o = document.getElementById("output").value;
	 document.getElementById("input").value = (o * om * im);

}

function sigdig(str){
   return str.length - (str.indexOf(".") + 1);
}