// JavaScripts for MicFac Website, Basic form controls
// SCKuo 2008_1119, v1
// SCKuo 2009_0528, added MF_forceSelect to force selection beyond default message (item 0)

function MF_name(x) {
	if (typeof x == "string") {
		var t=document.getElementsByName(x);
		return t[0]; //return first element
		}
	return x;
}

function MF_NiceHTime(h) { //h=duration in hours; returns "d hh:mm"
	var str="";
	if (h<0) {str="-("; h=-h}
	if (h>24) {
		var quot= Math.floor(h/24); h= h - 24*quot;
		str+= quot + 'd ';
	}
	str+= Math.floor(h);
	var minutes=Math.round(60*(h - Math.floor(h)));
	str += ":";
	if (minutes < 10) str += "0";
	str += minutes;
	if (str.charAt(0) == '-') str+= ')';
	return str
}

function MF_NiceTDuration(h) { //h=duration in hours; returns "d days h.xx hours"
	var str="";
	if (h<0) {str="-("; h=-h}
	if (h>24) {
		var quot= Math.floor(h/24); h= h - 24*quot;
		str+= quot + 'days ';
	}
	str+= h.toFixed(2) + 'hrs';
	if (str.charAt(0) == '-') str+= ')';
	return str
}

function MF_forceSelect(selectName, msg) {//Make sure valid selection in select list
	var tag = MF_name(selectName);
	var sInd = tag.selectedIndex;
	var opt= tag.options[sInd];
	if (sInd == 0) { //default location always first
		alert(msg);
		return false;
	}
	return true;
}


