var data="DD.MM.RRRR".split("");
var dataEmpty="DD.MM.RRRR".split("");
var selectionStart;
var selectionEnd;

// Pobiera numer nacisnietego klawisza.
function whichKey(event) {
	if (document.all)
		return event.keyCode;
	return event.which;
}

// Po wcisnieciu klawisza weryfikujemy czy jego nacisniecie jest dozwolone.
function dateFieldKeyPress(dataField, event) {
	key = whichKey(event);
	// digit
	if ((key >= 48) && (key <= 57))
		return true;
	// dot
	if (key == 46)
		return true;
	// special chars
	if (key < 32)
		return true;
	return false;
}

// Sprawdzenie poprawnosci daty przy submit.
function validateDateValue(dataField,msg) {
	tData=dataField.value.split(".");
	a=Number(tData[2]);
	b=Number(tData[1]);
	c=Number(tData[0]);
	if (isNaN(a) || isNaN(b) || isNaN(c)) {
		alert(msg);
		dataField.focus();
		return false;
	}
	if (b<1 || b>12 || c<1 || c>31) {
		alert(msg);
		dataField.focus();
		return false;
	}
	return true;
}

function compareDate(dateFrom,dateTo,msg) {
	tDateFrom=dateFrom.value.split(".");
	tDateTo=dateTo.value.split(".");
	if (tDateTo[2] == tDateFrom[2]) {
		if (tDateTo[1] == tDateFrom[1]) {
			if (tDateTo[0] >= tDateFrom[0]) {
				return true;
			}
		} else if (tDateTo[1] > tDateFrom[1]) {
			return true;
		}
	} else if (tDateTo[2] > tDateFrom[2]) {
		return true;
	}
	alert(msg);
	return false;
}
