$().ready(function()
{
	//
	// Uploadowanie
	//
	$("#imgsend").MultiFile({
		accept: "gif|jpg|png|jpeg|zip", max: 3,
		STRING: {
			remove:	"<img src=\"styles/icon_remove.gif\" alt=\"Usuń\" title=\"Usuń\" />",
			selected: "Wybrano: $file",
			denied: "Niedozwolone rozszerzenie $ext",
			duplicate: "Plik $file został już wcześniej dodany"
		}
	});

	$("input.autoselect").focus(function()
	{
		this.select();
	});

	$("input.autoselect").click(function()
	{
		this.select();
	});

	//
	// Rejestracja
	//
	$("#captcha").append(" <img src=\"styles/icon_refresh.gif\" id=\"captcha_reload\" style=\"cursor: pointer; margin-left: 5px; margin-top: 3px\" alt=\"Przeładuj Captcha\" title=\"Kliknij tutaj, gdy kod z obrazka jest nieczytelny\" />");
	$("#captcha_reload").click(function()
	{
		var chars = "0123456789";
		var random = "";

		for( var i = 0; i < 32; i++)
		{
			random += Math.floor(Math.random() * chars.length);
		}

		$("#captcha_img").attr("src", "wizualne_potwierdzenie.png?refresh=" + random);
	});
});

function getCookie(name)
{
	cookie = document.cookie.split("; ");

	for( a = 0; a < cookie.length; a++ )
	{
		elName = cookie[a].split("=");
        if(elName[0] == name)
			return unescape(elName[1]);
	}
    return "";
}

function setCookie(name, value)
{
    date = new Date();
    date.setTime(date.getTime() + (1000 * 60 * 60 * 24 * 30));
    document.cookie = name + "=" + escape(value) + "; expires=" + date.toGMTString();
}

function setOpacity(id, value, gomax)
{
	if( document.all && document.getElementById )
	{
		var value = 100;
		//document.getElementById(id).filters.alpha.opacity = value;
	} else {
		document.getElementById(id).style.MozOpacity = value/100;
	}

	if( value < 100 && gomax == true )
	{
		next = Math.round(value + 10);
		setTimeout('setOpacity("config", next, true)', 100);
	}
}

function getPageSize()
{
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY)
	{
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) {
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	if(yScroll < windowHeight) {
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth) {	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
	return arrayPageSize;
}

function getPageScroll()
{
	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('', yScroll);
	return arrayPageScroll;
}

function preload()
{
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var objOverlay = document.getElementById("overlay");
	var objLoadingImage = document.getElementById("overlay_img");
	var objLoadingMessage = document.getElementById("overlay_msg");

	setOpacity("overlay", 50, false);

	objOverlay.onclick = function () {hide(); return false;}
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = "block";

	if (objLoadingImage)
	{
		objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
		objLoadingImage.style.left = (((arrayPageSize[0] - 20 - objLoadingImage.width) / 2) + 'px');
	}

	if (objLoadingMessage)
	{
		objLoadingMessage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 200 + 'px');
		objLoadingMessage.style.left = (((arrayPageSize[0] - 20 - objLoadingImage.width) / 2) + 'px');
	}
}

function hide()
{
	var objOverlay = document.getElementById("overlay");

	objOverlay.style.display = "none";
}