var will_be_age_check_shown = 0; 


function checkTrue(){
	createCookie("PivovarJihlavaAgeCheck","true",1);

	newPath = "";
	for ( i = 0; i < pathArray.length; i++ ) {
		if(pathArray[i] != '' && pathArray[i] != undefined) {
			newPath += "/";
			newPath += pathArray[i];
		}
	}
// tohle pouzit pro jazykove verze
//	window.location = window.location.protocol + "//" + window.location.host + newPath; // refresh stranky
	window.location.reload();
			// document.getElementById("age_check_tab").innerHTML= '<div><h1 style="">Vážení příznivci našeho zlatavého moku!<br />Máte-li naši společnost rádi, udělejte si chvilku, podívejte se na <a href="http://www.firma-vysociny.cz/">http://www.firma-vysociny.cz/</a><br />a podpořte hlasem naši firmu v soutěži<br />„Firma Vysočiny".<br />&nbsp;<br />S pivovarským pozdravem „Dej bůh štěstí", zaměstnanci Pivovaru Jihlava </h1><p>&nbsp;<br />&nbsp;<br /><strong><a href="#" onclick="window.location.reload()" style="color: #ffffff; font-size: 120%;">&raquo; pokračovat na stránky pivovaru Jihlava</a></strong></p></div>';

}
function checkFalse(){
	createCookie("PivovarJihlavaAgeCheck","false",1);
  	pathArray = window.location.pathname.split('/');
	if(pathArray[1] == 'en') {
 	    document.getElementById("age_check_tab").innerHTML= '<h1>DÍKY ZA UPŘÍMNOST.<br />STAV SE, AŽ BUDEŠ PLNOLETÝ.</h1>';
	} else if(pathArray[1] == 'de') {
 	    document.getElementById("age_check_tab").innerHTML= '<h1>DÍKY ZA UPŘÍMNOST.<br />STAV SE, AŽ BUDEŠ PLNOLETÝ.</h1>';
	} else if(pathArray[1] == 'ru') {
 	    document.getElementById("age_check_tab").innerHTML= '<h1>Спасибо за честность.<br />Возвращайся, когда будешь<br />совершеннолетним.</h1>';
	} else {
		pathArray[1] = 'cs';
 	    document.getElementById("age_check_tab").innerHTML= '<h1>DÍKY ZA UPŘÍMNOST.<br />STAV SE, AŽ BUDEŠ PLNOLETÝ.</h1>';
    }

}

function resizeLayer(){
	var winH = document.documentElement.scrollHeight;
	ac = document.getElementById("age_check");
	if (ac)	ac.style.height= winH+"px";
}

function startAgeCheck(){
	pathArray = window.location.pathname.split('/');
	if(pathArray[1] == 'en') {
		textH1 = 'I am older than 18<br />and allowed to buy alcohol<br />legally in my country.';
	} else if(pathArray[1] == 'de') {
		textH1 = 'Ich bestätige,<br />dass ich mindestens<br />18 Jahre alt bin.';
	} else if(pathArray[1] == 'ru') {
		textH1 = 'Я старше 18 лет<br />или я попадаю под<br />юрисдикцию США<br />и я старше 21 года.';
	} else {
		pathArray[1] = 'cs';
		textH1 = 'JE MI VÍCE NEŽ 18 LET NEBO JSEM OSOBA<br />PODLÉHAJÍCÍ PRÁVU USA STARŠÍ<br />NEŽ 21 LET.';
		siteAdress = '<strong>Pivovar Jihlava</strong><br />Vrchlického 2, 586 01 Jihlava';
	}
textH2 = '';
	var server = getServer();
	var checked = readCookie("PivovarJihlavaAgeCheck");

	if(checked == null || checked == "false"){

		//document.write('<img src="/_clip/agecheck_0' + (Math.floor(1 + Math.random() * 3)) + '.jpg" alt="" />');
		document.write('<div id="age_check_tab" style="display:none;">'+
		'<h1>'+textH1+'</h1>'+
		'<form><p><input type="button" name="ano" value="" class="btn-ano" onclick="checkTrue();" /><input type="button" name="ne" value="" class="btn-ne" onclick="checkFalse();" /></p></form>'+
		'<p class="adresa">'+siteAdress+'</p>'+
		'</div>');


		$('body').css('visibility', 'hidden');
		$(document).ready(function () {
			$('#age_check_tab').modal({opacity:100});
			$('body').css('visibility', 'visible');
		});



		will_be_age_check_shown = 1;
	}else{
	    will_be_age_check_shown = 0;
	}
}
function getServer(){
	var host = window.location.toString();
	host = host.split('://');
	var protocol = host[0];
	host = window.location.host;

	return protocol+"://"+host;
}

function checkAgeDate()
{
	var den = document.getElementById("den-narozeni").value;
	var mesic = document.getElementById("mesic-narozeni").value;
	var rok = document.getElementById("rok-narozeni").value;
	url = "&den=" + document.getElementById("den-narozeni").value;
	url += "&mesic=" + document.getElementById("mesic-narozeni").value;
	url += "&rok=" + document.getElementById("rok-narozeni").value;

	$.post('/smallapp/ajax/agecheckdate/', {den:den, mesic:mesic, rok:rok}, checkDateCallback, 'json');

	
//    var ajax = new EasyAjax('POST', url, '/smallapp/ajax/agecheckdate/');
//    ajax.onSuccess("checkDateCallback");
//    ajax.doRequest();
    
    return false;	
}

function checkDateCallback(data)
{
	var server = getServer();
	switch (data.status)
	{
		//case 'ERR_EMPTY':
		//	document.getElementById('age_check_nadpis').innerHTML = "Musite uvest mesic a rok narozeni";
		//	break;
		case 'ALL_OK':
			checkTrue();
			break;
		case 'ERR_TOOYOUNG':
			checkFalse();
			window.location(server+'/opustit-stranky.php');
			break;	
	}
}

function spinDecrement(item, min, max) {
	element = document.getElementById(item);
	if(isNaN(element.value)) {
		element.value = Math.round((max+min) / 2);
	} else {
		if(element.value <= min) {
			element.value = max;
		} else {
			element.value = Number(element.value) - 1;
		}
	}
}

function spinIncrement(item, min, max) {
	element = document.getElementById(item);
	if(isNaN(element.value)) {
		element.value = Math.round((max+min) / 2);
	} else {
		if(element.value >= Number(max)) {
			element.value = min;
		} else {
			element.value = Number(element.value) + 1;
		}
	}
}

function startDecrement(item, min, max) {
	spinDecrement(item, min, max);
	if( (window) && (window['spin'+item]) ) {
	} else {
		window['spin'+item] = setInterval("spinDecrement('"+item+"', '"+min+"', '"+max+"')", 200);
	}
}

function stopDecrement(item) {
	if( (window) && (window['spin'+item]) ) {
		clearInterval(window['spin'+item]);
		window['spin'+item] = false;
	}
}

function startIncrement(item, min, max) {
	spinIncrement(item, min, max);
	if( (window) && (window['spin'+item]) ) {
	} else {
		window['spin'+item] = setInterval("spinIncrement('"+item+"', '"+min+"', '"+max+"')", 200);
	}
}

function stopIncrement(item) {
	if( (window) && (window['spin'+item]) ) {
		clearInterval(window['spin'+item]);
		window['spin'+item] = false;
	}
}


startAgeCheck();
