// Requires: quirksmode_cookies.js

/**
 * Save a cookie with the current finance fields state.
 * The cookie will expire at the end of the session.
 */
function saveFinanceState(period, deposit) {
	var value = ""+ period +"^"+ deposit;
	createCookie("financeState", value);
}

/**
 * Set the selected item of a select box by value
 */
function setSelectItem(selectField, selectedValue) {
	for (var i=0; i < selectField.options.length; i++){
		if (selectField[i].value == selectedValue) {
			selectField.selectedIndex = i;
			break;
		}
	}
}

function loadFinanceState() {
	var cookieValue = readCookie("financeState");
	if (cookieValue == null) {
		return;
	}
	var values = cookieValue.split('^');
	if (values[1] == undefined) {
		return;
	}
	$('input_deposit').value = values[1];

	setSelectItem($('input_loanPeriod'), values[0]);
}

Event.observe( window, 'load', function () {
//	loadFinanceState();
});


