window.onload = createAdultLayer;
// Tekst wyświetlający się przed wejściem na stronę
var text = "Serwis zawiera treści o tematyce erotycznej i jeżeli nie ukończyłeś 18 lat lub nie chcesz oglądać tego typu treści nie wolno Ci wchodzić dalej. Wchodząc do serwisu oświadczasz, że jesteś osobą pełnoletnią, chcesz oglądać treści o tematyce erotycznej z własnej, nieprzymuszonej woli a prezentacja zawartego tam materiału nie została Ci przez nikogo narzucona. Właściciel serwisu nie ponosi odpowiedzialności za ewentualne roszczenia osób odwiedzających serwis, które podają niezgodnie z prawdą dane o pełnoletności. Zawarte w serwisie zdjęcia i treści mogą służyć wyłącznie do użytku prywatnego i nie wolno w żaden sposób ich powielać i udostępniać. Serwis nie oferuje treści pornograficznych z udziałem małoletnich poniżej 18 roku życia, związanych z użyciem przemocy lub posługiwaniem się zwierzętami (art.202 §3 kk) ani też nie narusza art.202 §1 kk gdyż nie prezentuje publicznie treści pornograficznych w sposób narzucający ich odbiór osobie, która tego sobie nie życzy. Jeżeli chcesz zabezpieczyć ten serwis przed dziećmi skorzystaj z oprogramowania zawartego na stronie http://www.kidprotect.pl.";

// przezroczystość tła wyrażona w procentach
var backgroundDivOpacity = '95';

// Nagłówek
var header = "Serwis od lat 18+";

// Styl elementu div zakrywającego stronę
var backgroundDivStyle = "display:block; position:absolute; top:0%; left:0%; width:800%; height:100%; background-color:#0F0000; z-index:1000; -moz-opacity: 0." + backgroundDivOpacity + "; -khtml-opacity: 0." + backgroundDivOpacity + "; opacity: 0." + backgroundDivOpacity + "; filter: alpha(opacity=" + backgroundDivOpacity + ");";

// Styl elementu div z treścią wiadomości
//Szerokość i wysokość przegladarki w celu ustalenia lewego marginesu (dla position:absolute nie działa margin: 0 auto)
clientSize = getClientSize();
marginLeft = Math.round((clientSize[0]-500)/2);
//var contentDivStyle = "display:block; margin: 0 auto; position: absolute; width:500px; height:328px; padding: 10px; border:1px solid #f00; background-color:#000; z-index:1001; color:#c50000; font-size:14px; color:#D4D4D4; line-height:110%; text-align:center;";
var contentDivStyle = "display:block; position:absolute; top:100px; left:" + marginLeft + "px; width:500px; height:328px; padding: 10px; border:1px solid #f00; background-color:#000; z-index:1001; color:#c50000; font-size:14px; color:#D4D4D4; line-height:110%; text-align:center;";
// Obrazek i tekst buttona odpowiedzialnego za wejście na stronę.
// Uzupełnić ścieżkę do obrazka LUB tekst buttona
var accessButtonImg = "";
var accessButtonText = "WCHODZĘ &raquo;";
// Rozmiary obrazka, jeśli dodany
var accessButtonImgWidth = "";
var accessButtonImgHeight = "";
// Styl buttona odpowiedzialnego za wejście na stronę
var accessButtonStyle = "display:block-inline; border:0; color: #f00; font-weight:bold; font-size:24px; cursor:pointer; text-decoration:none;";
accessButtonStyle += (accessButtonImg) ? "background: url('" + accessButtonImg + "') no-repeat center center; width:" + accessButtonImgWidth + "; height:" + accessButtonImgHeight + ";" : "background:transparent;";

// Obrazek i tekst buttona odpowiedzialnego za opuszczenie strony.
// Uzupełnić ścieżkę do obrazka LUB tekst buttona
var denyButtonImg = "";
var denyButtonText = "&laquo WYCHODZĘ";
//Rozmiary obrazka, jeśli dodany
var denyButtonImgWidth = "";
var denyButtonImgHeight = "";
// Styl buttona odpowiedzialnego za opuszczenie strony
var denyButtonStyle = "display:block-inline; float:left; border:0; color: #570016; font-size:14px; cursor:pointer; text-decoration:none;";
denyButtonStyle += (denyButtonImg) ? "background: url('" + denyButtonImg + "') no-repeat center center; width:" + denyButtonImgWidth + "; height:" + denyButtonImgHeight + ";" : "background:transparent;";

// Nazwa pliku cookie
var adultCookieName = "AdultAccess";
// Czas przechowywania cookie
var adultCookieTime = null; // cookie usuwają się wraz z zamknięciem przeglądarki
//var adultCookieTime = new Date();
//adultCookieTime.setDate(adultCookieTime.getDate()+1) 

// Strona, na którą następuje przekierowanie po kliknięciu przycisku wyjścia - pozostaw puste, jeśli przekierowanie ma prowadzić na poprzednią stronę
var denyLocation = 'http://ww.google.pl';

function getClientSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	clientSize = new Array();
	clientSize[0] = myWidth;
	clientSize[1] = myHeight;
	return clientSize;
}

function checkCookie() {
    if (document.cookie!="") {
    var toCookie=document.cookie.split("; ");
        for (i=0; i<toCookie.length; i++) {
            var cookieName = toCookie[i].split("=")[0];
            var cookieValue = toCookie[i].split("=")[1];
            if (cookieName==adultCookieName) return true;
		}
	}
	return false;
}

function createCookie()
{
	// tworzenie ciasteczek
	document.cookie = adultCookieName + "=true" + ((adultCookieTime==null)? "" : "; expires=" + adultCookieTime.toGMTString());
}

function createAdultLayer()
{
	// ukrycie scrollbarów
	document.body.style.overflow = 'hidden';
	document.body.scroll = "no";
	
	// odwołanie do funkcji checkCookie() - sprawdzenie czy istnieją pliki cookie
	if(checkCookie()) { return false;}

	// tworzenie elementów
	var backgroundDiv = document.createElement("div");
	var contentDiv = document.createElement("div");
	var accessButton = document.createElement("a");
	var denyButton = document.createElement("a");
	var adultAccessButtons = document.createElement("p");

	// Ustawienie parametrów buttonów
	accessButton.setAttribute('href', '#');
	denyButton.setAttribute('href', '#');
	accessButton.innerHTML = accessButtonText;
	denyButton.innerHTML = denyButtonText;
	
	// tworzenie stylów elementów
	backgroundDiv.style.cssText = backgroundDivStyle;
	contentDiv.style.cssText = contentDivStyle;
	accessButton.style.cssText = accessButtonStyle;
	denyButton.style.cssText = denyButtonStyle;
	
	// nadanie ID
	backgroundDiv.id = "AdultBackgroundDiv";
	contentDiv.id = "AdultContentDiv";
	accessButton.id = "AdultAccessButton";
	denyButton.id = "AdultDenyButton";
	adultAccessButtons.id = "AdultAccessButtons";
	
	// wstawienie elementów - tła, kontentu oraz nagłówka
	document.body.appendChild(backgroundDiv);
	document.body.appendChild(contentDiv);
	
	// wprowadzanie tekstu
	contentDiv.setAttribute('align', 'center');
	contentDiv.innerHTML = "<h1 style='text-align:center; color:#f00;'>" + header + "</h1><p>" + text + "</p>";

	// wstawienie przycisków w elemencie AdultAccessButtons
	adultAccessButtons.setAttribute('align', 'right');
	contentDiv.appendChild(adultAccessButtons);
	adultAccessButtons.appendChild(accessButton);
	adultAccessButtons.appendChild(denyButton);
	
	// dodanie efektu najechania myszki dla elementów adultAccessButtons
	accessButton.onmouseover = function accessButtonHover() {
		accessButton.style.color = "#dbdbdb";
	}
	
	accessButton.onmouseout = function accessButtonHoverOut() {
		accessButton.style.color = "#f00";
	}
	
	denyButton.onmouseover = function denyButtonHover() {
		denyButton.style.color = "#a1a1a1";
	}
	
	denyButton.onmouseout = function adenyButtonHoverOut() {
		denyButton.style.color = "#570016";
	}
	
	// przypisanie funkcji dostępu i opuszczenia strony
	accessButton.onclick = function hideLayer() {
		backgroundDiv.style.display = "none";
		contentDiv.style.display = "none";

		// odwołanie do funkcji createCookie - tworzenie ciasteczek
		createCookie();
		
		// ukrycie scrollbarów
		document.body.style.overflow = 'visible';
		document.body.scroll = "yes";
	};

	denyButton.onclick = function redirect() {
		if (denyLocation == null || denyLocation == '') {
			history.back();
		} else {
			window.location.href=denyLocation;
		}
	};
	
	// rozciągnięcie elementu zasłaniającego stronę na całą szerokość i wysokość dokumentu
	function getDocHeight() {
	    var D = document;
	    return Math.max(
	        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
	        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
	        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
	    );
	}

	function getDocWidth() {
	    var D = document;
	    return Math.max(
	        Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
	        Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
	        Math.max(D.body.clientWidth, D.documentElement.clientWidth)
	    );
	}
	docWidth = getDocWidth();
	docHeight = getDocHeight();
	backgroundDiv.style.width = docWidth + 'px';
	backgroundDiv.style.height = docHeight + 'px';
}
