function countdown(year, month, day, hour, minute){
    Today = new Date();
    Todays_Year = Today.getFullYear() - 2000;
    //console.log(Today.getMonth());
	//console.log(month);
    Months_Left = 0;
	nMonths = "error";
	lang = document.getElementsByTagName('html')[0].getAttribute('lang');
    //Convert both today's date and the target date into miliseconds.                           
    Todays_Date = (new Date(Todays_Year, Today.getMonth(), Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();
    //console.log(Todays_Date);
	Target_Date = (new Date(year, month-1, day, hour, minute, 00)).getTime();
    //console.log(Target_Date);
    //Find their difference, and convert that into seconds.                  
    Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
    //console.log(Time_Left);
	//sprawdz czy termin juz nie minal
    Todays_Month = Today.getMonth() + 1;
	if (Time_Left > 0) {
		//jesli wydarzenie jest w innym roku ustal odpowiednia liczbe miesiecy
		if (Todays_Year != year) {
			Months_Left = (year - Todays_Year) * 12;
		}
		
		Months_Left += month - Todays_Month;
		//roznica dat bez uwzglednienia lat i miesiecy
		Todays_Date = (new Date(0, 0, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();
		Target_Date = (new Date(0, 0, day, hour, minute, 00)).getTime();
		Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
		//console.log(Time_Left);
		if (Time_Left < 0) {
			Months_Left--;
			year_helper1 = year; 
			year_helper2 = year; 
			month_helper1 = month - 1;
			month_helper2 = month- 2;
			if (month == 0) {
				year_helper1 = year;
				year_helper2 = year - 1;
				month_helper2 = 11; 
			}
			Todays_Date = (new Date(year_helper2, month_helper2, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();
			Target_Date = (new Date(year_helper1, month_helper1, day, hour, minute, 00)).getTime();
			Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
			//console.log(Time_Left);
		}
		//jesli wydarzenie jest w innym miesiacu
		/*if (Months_Left > 0){
	 //... i w innym roku przy czym data docelowa jest wczesniejsza od obecnej (bez uwzglednienia roku)
	 if (Time_Left<0){
	 //policz jeszcze raz
	 Todays_Date = (new Date(0, 0, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();
	 Target_Date = (new Date(0, 1, day, hour, minute, 00)).getTime();
	 Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
	 }
	 }*/
		//More datailed.
		days = Math.floor(Time_Left / (60 * 60 * 24));
		Time_Left %= (60 * 60 * 24);
		hours = Math.floor(Time_Left / (60 * 60));
		Time_Left %= (60 * 60);
		minutes = Math.floor(Time_Left / 60);
		Time_Left %= 60;
		seconds = Time_Left;
		
		document.getElementById("countdown").innerHTML = '<ul id="countdown-list"></ul>';
		kolejna = false;
		
			if (lang == "pl-PL") {
				nZa = 'za ';
				
			}
			else if (lang == "en-US") {
				nZa = 'in ';
			}
			
			else if (lang == "es-ES") {
			nZa = 'de ';
			}
		
			if (lang == "pl-PL") {
				if (Months_Left == 1) 
					nMonths = 'miesiąc';
				
				if (Months_Left > 1) 
					nMonths = 'miesiące';
				
				if (Months_Left > 4) 
					nMonths = 'miesięcy';
				
			}
			else if (lang == "en-US") {
				if (Months_Left == 1) 
					nMonths = 'month';
				
				if (Months_Left > 1) 
					nMonths = 'months';
			}
			
			else if (lang == "es-ES") {
				if (Months_Left == 1) 
					nMonths = 'mes';
				
				if (Months_Left > 1) 
					nMonths = 'mes';
			}
		

		
			if (lang == "pl-PL") {
				if (days == 1) 
					nDays = 'dzień';
				
				else {
					nDays = "dni";
				}
			}
			else 
				if (lang == "en-US") {
					if (days == 1) 
						nDays = 'day';
					
					else 
						nDays = "days";
				}
				
				else 
					if (lang == "es-ES") {
						nDays = 'día';
					}
		
	
		
		
			if (lang == "pl-PL") {
				if (hours == 1) {
					nHours = 'godzinę';
				}
				else 
					if (((hours > 1) && (hours <= 4)) || (hours > 21)) {
						nHours = 'godziny';
					}
					else {
						nHours = 'godzin';
					}
			}	
			else if (lang == "en-US") {
				if (hours == 1) {
					nHours = 'hour';
				}
				
				else {
					nHours = "hours";
				}
			}
			
			else if (lang == "es-ES"){
			
				nHours = 'hora';
			
				}
		
		
			if (lang == "pl-PL") {
				reszta = minutes % 10;
				if (minutes == 1) {
					nMinutes = 'minutę';
				}
				else 
					if (((reszta > 1) && (reszta <= 4) && !((minutes > 11) && (minutes <= 14)))) {
						nMinutes = 'minuty';
					}
					else {
						nMinutes = 'minut';
					}
			}
			else 
				if (lang == "en-US") {
					if (minutes == 1) {
						nMinutes = 'minute';
					}
					else {
						nMinutes = "minutes";
					}
				}
				else 
					if (lang == "es-ES") {
						if (minutes == 1) {
							nMinutes = 'minute';
						}
						
						else {
							nMinutes = "minutos";
						}
					}
		
		
		
			if (lang == "pl-PL") {
				reszta = seconds % 10;
				if (seconds == 1) {
					nSeconds = 'sekundę';
				}
				else if (((reszta > 1) && (reszta <= 4) && !((seconds > 11) && (seconds <= 14)))) 
						nSeconds = 'sekundy';
					else 
						nSeconds = 'sekund';
			}
			if (lang == "en-US") {
				if (seconds == 1) {nSeconds = 'second';
				}
				else nSeconds = "seconds";
			}
			if (lang == "es-ES") {
				if (seconds == 1) {
					nSeconds = 'segundo';
				}
				else {
					nSeconds = "segundo";
				}
			}
	
		
		kolejna = printTime(Months_Left,nMonths,kolejna);
		kolejna = printTime(days,nDays,kolejna);
		kolejna = printTime(hours,nHours,kolejna);
		kolejna = printTime(minutes,nMinutes,kolejna);
		//kolejna = printTime(seconds,nSeconds,kolejna);
        //Recursive call, keeps the clock ticking.
        setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute  + ');', 60000);
    }
	else{
		if (lang == "pl-PL") {
			document.getElementById("countdown").innerHTML = '<p>już wkrótce!</p>';
		}
		if (lang == "en-US"){
			document.getElementById("countdown").innerHTML = '<p>coming soon!</p>';
		}
	}
}

function printTime(wartosc, nazwa, kolejna){
	if (wartosc > 0){
		za = '';
		
			if (kolejna == false) za = nZa;
			document.getElementById("countdown-list").innerHTML +='<li>' + za + '<span class="number">'+wartosc+'</span>' +' '+ nazwa +'</li>';
		return true;
		}
	if (kolejna == false) {
		return false;
	}
	else 
		return true;
}
