function changeColorMenu(menuId){
	var menuObj = document.getElementById(menuId+"Menu");
	
	if (menuObj != null){
		menuObj.style.color= "#162B71";
	}
}


function calculateAnnual(w_field, a_field) {
	if (((w_field.value >= "A") 
	  && (w_field.value <= "z")) || 
	  parseInt(w_field.value) == "NaN") {
		alert ("Input for Weekly Mileage should only be a number");
		w_field.focus();
		w_field.select();
		return 1;
	}
	w_field.value = Math.round(w_field.value);
	a_field.value = w_field.value * 52;
	return 1;
}

function calculateWeekly(a_field, w_field) {
	if (((a_field.value >= "A") 
	  && (a_field.value <= "z")) || 
	  parseInt(a_field.value) == "NaN") {
		alert ("Input for Annual Mileage should only be a number");
		a_field.focus();
		a_field.select();
		return 1;
	}
	a_field.value = Math.round(a_field.value);
	w_field.value = Math.round(a_field.value / 52);
	return 1;
}
function checkNumberNoAlert(field) {
        if (((field.value >= "A") && (field.value <= "z")) || parseInt(field.value) == "NaN") {
		return false;
	}
	return true;
}

function checkNumber(field, fieldLabel) {
        if (((field.value >= "A") && (field.value <= "z")) || parseInt(field.value) == "NaN") {
		alert ("Input for "+fieldLabel+" should only be a number");
		// field.value = "";
		field.focus();
		field.select();
		return 1;
	}
	return 1;
}

function checkMaxLength(field, fieldLabel, length) {
	if (field.value.length > length) {
		alert (fieldLabel+" should be no longer than "+length);
		// field.value = "";
		field.focus();
		field.select();
		return 1;
	}
	return 1;
}

function validDate(month, day, year) {
	var to_fix = "";
	if (year.value.length < 4) {
		to_fix += "Please enter 4 digit year only\n";
	} else {
		if (year.value < 1918) {
			to_fix += "Check the year, and reenter\n";
		}
	}
	if (month.value > 12 || month.value < 1) {
		to_fix += "Month should be between 1 and 12\n";
	}
	if (day.value > 31 || day.value < 1) {
		to_fix += "Day should be between 1 and 31\n";
	}
	var entered_date = new Date (year.value, month.value-1, day.value);
	var now = new Date();
	if (entered_date.getTime() > now.getTime()) {
		to_fix += "Date is in the future, please reenter\n";
	}
	return to_fix;
}

function validMinLength(field, fieldLabel, length) {
	if (field.value.length < length) {
		alert (fieldLabel+" should be "+length+" digits");
		// field.value = "";
		field.focus();
		field.select();
		return 1;
	}
	return 1;
}

function checkValidMaint() {
	// aForm = document.editmaintenance;
	aForm = document.forms["editmaintenance"];
	wrong = "";

	if (aForm.date_sp_MM.value != "") {
		wrong += validDate(aForm.date_sp_MM, aForm.date_sp_DD, aForm.date_sp_YYYY);
	} else {
		wrong += "Please supply the month service was performed\n";
	}
	if (aForm.odometer_reading.value == "") {
		wrong += "Please supply an odometer reading\n";
	}

	if (wrong == "") {
		return true;
	} else {
		alert (wrong);
		return false;
	}
}


function newWindow(newURL) { 
appWindow = window.open(newURL, 'appwin', 'menubar=no,toolbar=no,location=no,resizable=yes,scrollbars=yes,left=10,top=10,width=620,height=470'); 
} 