function getElement(id) {
	var elm = (document.getElementById) ? document.getElementById(id) : document.all[id];
	return elm;
}

function display_calendar(calTarget) {
	var calendar = getElement('calendar');
	calendar.style.display = 'block';
	refresh_calendar(calTarget);
}

function setdate(calTarget,strDate) {
	var dateFld = getElement(calTarget);
	var calendar = getElement('calendar');
	dateFld.value = strDate;
	close_calendar();
}

function refresh_calendar(calTarget,date) {
	var dateStr = (date) ? '&date=' + date : dateStr = "";
	var calendar = getElement('calendar');
	try {
		var	xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
	} catch(e) {
		var	xmlHttpReq = new XMLHttpRequest();
	}
	xmlHttpReq.open('get','/travel/tif/calendar.php?target=' + calTarget + dateStr, false);
	xmlHttpReq.send(null);
	calendar.innerHTML = xmlHttpReq.responseText;
}

function close_calendar() {
	var calendar = getElement('calendar');
	calendar.style.display = 'none';
}

function mk_money(myObj) {
	myObj.value = /\d*\.?\d{0,2}/.exec(myObj.value);
}

function force_int(myObj) {
	myObj.value = /\d*/.exec(myObj.value);
}

function get_float(id) {
	var elm = getElement(id);
	return (isNaN(parseFloat(elm.value))) ?  0 : parseFloat(elm.value);
}

function get_air_total() {
	var air_total = getElement('air_total');
	air_total.value = get_float('air_amnt1') + get_float('air_amnt2') + get_float('air_amnt3') + get_float('air_amnt4');
	return true;
}

function get_other_total() {
	var other_total = getElement('other_total');
	var advance_amnt = getElement('advance_amnt');
	other_total.value = get_float('other_amnt1') + get_float('other_amnt2') + get_float('other_amnt3') + get_float('other_amnt4');
	advance_amnt.value = parseInt((other_total.value * 0.75) + 0.5);
	return true;
}

function send_form() {
	var tifForm = getElement('tif_form');
	var error = 0;
	var auth = getElement('authorized');
	var notes = getElement('notes');
	
	if (!auth.checked) {
		alert('Please do not submit this form until the department head has authorized the trip.');
		error = 1;
	}
	
	if (notes.value == '') {
		alert('You must enter the BUSINESS PURPOSE  before submitting this form');
		error = 1;
	}
	
	if (!error) { tifForm.submit(); }
	return true;
}
	
	
