function getParameter(parameterName) {
	var queryString = window.top.location.search.substring(1);
   	var parameterName = parameterName + "=";	// add "=" to the parameter name (i.e. parameterName=value)
   
   	if (queryString.length > 0) {
    	begin = queryString.indexOf(parameterName);	// find the beginning of the string
      
    	if (begin != -1) {
     		begin += parameterName.length;				// Add the length (integer) to the beginning
     	    end = queryString.indexOf("&", begin);		// Multiple parameters are separated by the "&" sign
      		    
      		if (end == -1) {
         		end = queryString.length
      		}
      		return unescape (queryString.substring(begin, end));
   		}
   		return "null";
   }
}

function updateBirthday(pesel, year, month, day) {
	var peselElem = document.getElementById(pesel);
	var yearElem = document.getElementById(year);
	var monthElem = document.getElementById(month);
	var dayElem = document.getElementById(day);
	if (peselElem && yearElem && monthElem && dayElem) {
		var peselValue = peselElem.value;
		if (peselValue.length == 11) {
			var i = 0;
			while (i < 11) {
				if (peselValue.charAt(i) < '0' || peselValue.charAt(i) > '9') {
					return;
				}
				++i;
			}
			var yearValue = 1900+parseInt(peselValue.substring(0, 2), 10);
			var monthValue = parseInt(peselValue.substring(2, 4), 10);
			var dayValue = parseInt(peselValue.substring(4, 6), 10);
			if (monthValue >= 20) {
				yearValue += 100;
				monthValue -= 20;		
			}
			var d = new Date();
			if (yearValue >= 1900 && yearValue <= d.getFullYear() &&
				monthValue >= 1 && monthValue <= 12 &&
				dayValue >= 1 && dayValue <= 31) {
				yearElem.value = yearValue;
				monthElem.value = monthValue;
				dayElem.value = dayValue;
			}
		}
	}
}

function captializeElement(id) {
	var elem = document.getElementById(id);
	var v = elem.value;
	var change = true;
	for (i = 0; i < v.length; ++i) {
		if (change && v.charAt(i) != ' ') {
			v = v.substr(0, i)+v.charAt(i).toUpperCase()+v.substr(i+1)
			change = false;
		}
		if (v.charAt(i) == ' ') {
			change = true;
		}
	} 
	elem.value = v;
}
