<!--
// 检查日期有效性
function dateInvalid(val_year, val_mon) {
	if (isNaN(val_year) || isNaN(val_mon) || val_year<1970 || val_year>9999 || val_mon<1 || val_mon>12) {
		return true;
	} else {
		return false;
	}
}

/* 检查付钱的月租时间 */
function checkPayDate(item_id) {

	if (item_id == null || isNaN(item_id))  {
		alert('Invalid parameter');
		return false;
	}
	var idid = parseInt(item_id, 10);
	if (idid==0 || idid==NaN) {
		alert('Invalid parameter');
		return false;
	}

	var diff_mon, start_date, end_date, start_year, end_year;
	start_date = document.getElementById('startdate'+idid).value;
	start_year = document.getElementById('startyear'+idid).value;
	end_date = document.getElementById('enddate'+idid).value;
	end_year = document.getElementById('endyear'+idid).value;

	start_date = parseInt(start_date, 10);
	start_year = parseInt(start_year, 10);
	end_date = parseInt(end_date, 10);
	end_year = parseInt(end_year, 10);

	if (dateInvalid(start_year, start_date)) {
		alert('Invalid pay start date');
		return false;
	}
	if (dateInvalid(end_year, end_date)) {
		alert('Invalid pay end date');
		return false;
	}

	// different months
	diff_mon = (end_year-start_year)*12 + end_date - start_date + 1;
	if (diff_mon <= 0) {
		alert('Payment Start Date must be sooner than Payment End Date');
		document.getElementById('startdate'+idid).focus();
		return false;
	}

	document.getElementById('monthstotal'+idid).innerHTML = diff_mon;

	return true;
}

function checkPayPost(obj) {
	with(obj) {
		var regempty = /^\s*$/;
		var item_id = itemid.value;
		if ( regempty.test(item_id) || isNaN(item_id) || parseInt(item_id, 10)==0) {
			alert('Object is invalid');
			return false;
		}
		item_id = parseInt(item_id, 10);

		if (checkPayDate(item_id) == false) {
			return false;
		}
		var temp_pattern = /^[1-9]{1}[0-9]{0,12}(\.)?[0-9]{0,10}$/;

		if (!regempty.test(amount.value) && !temp_pattern.test(amount.value)) {
			alert ('Rent must be numeric (e.g. 10.55)');
			amount.focus();
			return false;
		}
		
		if (!regempty.test(deposit.value) && !temp_pattern.test(deposit.value)) {
			alert ('Deposit must be numeric (e.g. 10.55)');
			deposit.focus();
			return false;
		}

		if (!regempty.test(other.value) && !temp_pattern.test(other.value) ) {
			alert ('Other Amount must be numeric (e.g. 10.55)');
			other.focus();
			return false;
		}

		return true;
	}
}


function checkRecordsPost(obj) {
	with(obj) {
		var regempty = /^\s*$/;
		var item_id = itemid.value;
		var records_id = recordsid.value;
		if ( regempty.test(records_id) || isNaN(records_id) || parseInt(records_id, 10)==0) {
			alert('Object is invalid');
			return false;
		}
		if ( regempty.test(item_id) || isNaN(item_id) || parseInt(item_id, 10)==0) {
			alert('Object is invalid');
			return false;
		}
		item_id = parseInt(item_id, 10);

		if (yeschange.checked == true) {
			if ( regempty.test(changedate.value) ) {
				alert ('Change Paid Date field is required.');
				changedate.focus();
				return false;
			}

			var d = changedate.value.split("-");
			d[0] = parseInt(d[0], 10);
			d[1] = parseInt(d[1], 10);
			d[2] = parseInt(d[2], 10);
			if (isNaN(d[0]) || isNaN(d[1]) || isNaN(d[2]) || d[0]<1970 || d[0]>9999 || d[1]<1 || d[1]>12 || d[2]<1 || d[2]>31) {
				alert('Change Paid Date is invalid. (yyyy-mm-dd)');
				changedate.focus();
				return false;
			}
		}


		if (checkPayDate(item_id) == false) {
			return false;
		}
		var temp_pattern = /^[1-9]{1}[0-9]{0,12}(\.)?[0-9]{0,10}$/;
		
		if (!regempty.test(amount.value) && !temp_pattern.test(amount.value)) {
			alert ('Rent must be numeric (e.g. 10.55)');
			amount.focus();
			return false;
		}
		
		if (!regempty.test(deposit.value) && !temp_pattern.test(deposit.value)) {
			alert ('Deposit must be numeric (e.g. 10.55)');
			deposit.focus();
			return false;
		}

		if (!regempty.test(other.value) && !temp_pattern.test(other.value) ) {
			alert ('Other Amount must be numeric (e.g. 10.55)');
			other.focus();
			return false;
		}

		return true;
	}
}

// hourly, onetime, expected
function checkRecordsOther(obj) {
	with(obj) {
		var regempty = /^\s*$/;
		var item_id = itemid.value;
		var records_id = recordsid.value;
		if ( regempty.test(records_id) || isNaN(records_id) || parseInt(records_id, 10)==0) {
			alert('Object is invalid');
			return false;
		}
		if ( regempty.test(item_id) || isNaN(item_id) || parseInt(item_id, 10)==0) {
			alert('Object is invalid');
			return false;
		}

		if (yeschange.checked == true) {
			if ( regempty.test(changedate.value) ) {
				alert ('Change Paid Date field is required.');
				changedate.focus();
				return false;
			}

			var d = changedate.value.split("-");
			d[0] = parseInt(d[0], 10);
			d[1] = parseInt(d[1], 10);
			d[2] = parseInt(d[2], 10);
			if (isNaN(d[0]) || isNaN(d[1]) || isNaN(d[2]) || d[0]<1970 || d[0]>9999 || d[1]<1 || d[1]>12 || d[2]<1 || d[2]>31) {
				alert('Change Paid Date is invalid. (yyyy-mm-dd)');
				changedate.focus();
				return false;
			}
		}


		var temp_pattern = /^[1-9]{1}[0-9]{0,12}(\.)?[0-9]{0,10}$/;
		if ( regempty.test(amount.value) ) {
			alert ('Amount field is required.');
			amount.focus();
			return false;
		}
		if (!temp_pattern.test(amount.value)) {
			alert ('Amount must be numeric (e.g. 10.55)');
			amount.focus();
			return false;
		}

		return true;
	}
}
-->