function clearText(field)
{
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}

function adult()
{
    document.write('<div id="pre_warning" style="position:absolute;top:0px;left:0px;width:102%;height:100%;background-color:#ffffff;position: fixed;_position: absolute;_top:expression(document.body.scrollTop+document.body.clientHeight-this.clientHeight);filter:alpha(opacity=90);opacity: 0.9;-moz-opacity:0.9;"></div><div id="warning" style="position:absolute;top:0px;left:0px;width:100%;height:100%;position: fixed;_position: absolute;_top:expression(document.body.scrollTop+document.body.clientHeight-this.clientHeight);filter:alpha(opacity=100);opacity: 1.0;-moz-opacity:1.0;"><table width="100%" height="100%"><tr><td align="center" valign="middle"><table style="width:640px; height:400px; border:1px solid #cccccc; background-color:#ffffff;"><tr><td align="center" style="padding-top:12px; color: red;"><font style="font-size: 13pt;"><b>Strona tylko dla dorosłych!</b></font><br><br><div align="center">Strona zawiera treści o tematyce erotycznej.<br>Jeśli nie masz ukończonych 18 lat, natychmiast opuść tę stronę.</div><br><br><input type=checkbox id="warningBox"> <a href="#" onclick="document.getElementById(\'warningBox\').checked ^= 1; return false;" style="color:black; text-decoration:none;">Mam ukończone 18 lat, nie pokazuj tego ostrzeżenia w przyszłości.</a><br><br><div style="margin-top:32px;"><a href="#" onclick="adult_letMeIn(\'Potwierdź, że masz ukończone 18 lat!\'); return false;" style="color:black;"><font style="font-size : 18pt;"><b>Wchodzę</b></font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.google.pl" style="color:black;"><font style="font-size : 18pt;"><b>Rezygnuję</b></font></a></div></td></tr></table></td></tr></table></div>');
}
function adult_letMeIn(not_checked)
{
    if(document.getElementById('warningBox').checked)
    {
    adult_setcookie('adult',1,7);
    document.getElementById('warning').style.visibility = 'hidden';
    document.getElementById('pre_warning').style.visibility = 'hidden';
    document.getElementById("menu1").style.display="";
    document.getElementById("menu2").style.display="";
    document.getElementById("menu3").style.display="";
    document.getElementById("menu4").style.display="";
    }
    else alert(not_checked);
}
function adult_setcookie(cookieName,cookieValue,nDays)
{
    var today = new Date();
    var expire = new Date();
    if (nDays==null || nDays==0) nDays=1;
    expire.setTime(today.getTime() + 3600000*24*nDays);
    document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}
function adult_getcookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) 
    {
	begin = dc.indexOf(prefix);
	if (begin != 0) return null;
    }
    else
    {
	begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
	end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

var fieldlimiter={

defaultoutput: "[int]", //default message that gets output to statusid element

uncheckedkeycodes: /(8)|(13)|(16)|(17)|(18)/, //keycodes that are not checked, even when limit has been reached. See http://www.javascriptkit.com/jsref/eventkeyboardmouse.shtml for avail keycodes

limitinput:function(e, config){
	var e=window.event || e
	var thefield=config.thefield
	var keyunicode=e.charCode || e.keyCode
	if (!this.uncheckedkeycodes.test(keyunicode)){
		if (thefield.value.length>=config.maxlength){
			if (e.preventDefault)
				e.preventDefault()
			return false
		}
	}
},

showlimit:function(config){
	var thefield=config.thefield
	var statusids=config.statusids
	var charsleft=config.maxlength-thefield.value.length
	if (charsleft<0) //if user has exceeded input limit (possible if cut and paste text into field)
		thefield.value=thefield.value.substring(0, config.maxlength) //trim input
	for (var i=0; i<statusids.length; i++){
		var statusdiv=document.getElementById(statusids[i])
		if (statusdiv) //if status DIV defined
			statusdiv.innerHTML=this.defaultoutput.replace("[int]", Math.max(0, charsleft))
	}
	config.onkeypress.call(thefield, config.maxlength, thefield.value.length)
},

cleanup:function(config){
	for (var prop in config){
		config[prop]=null
	}
},


addEvent:function(targetarr, functionref, tasktype){
	if (targetarr.length>0){
		var target=targetarr.shift()
		if (target.addEventListener)
			target.addEventListener(tasktype, functionref, false)
		else if (target.attachEvent)
			target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)})
		this.addEvent(targetarr, functionref, tasktype)
	}
},

setup:function(config){
	if (config.thefield){ //if form field exists
		config.onkeypress=config.onkeypress || function(){}
		config.thefield.value=config.thefield.value
		this.showlimit(config)
		this.addEvent([window], function(e){fieldlimiter.showlimit(config)}, "load")
		this.addEvent([window], function(e){fieldlimiter.cleanup(config)}, "unload")		
		this.addEvent([config.thefield], function(e){return fieldlimiter.limitinput(e, config)}, "keypress")
		this.addEvent([config.thefield], function(){fieldlimiter.showlimit(config)}, "keyup")
	}
}
}
