function validEmail(email) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(email);
}

function przeliczWalute()
{

	box = document.getElementById("p_waluta");
	waluta = box.options[box.selectedIndex].value;

	document.getElementById("p_ilosc").value = document.getElementById("p_ilosc").value.replace(new RegExp("[^0-9\.]{1,}", "gi"), '');

	if ( document.getElementById("p_ilosc").value > 0 )
	{

		document.getElementById("p_wynik").innerHTML = parseFloat(waluta * document.getElementById("p_ilosc").value).toFixed(4);

	}

}

function inputDefault(obj, text)
{

	if ( obj.value == text )
	{

		obj.value = "";

	}
	else if ( obj.value == "" )
	{

		obj.value = text;

	}

}

function userlogin(id)
{

	if ( document.getElementById("USR_login_login").value.indexOf('@', 0) == -1 )
	{

		alert("Błąd: login musi mieć postać adresu e-mail! Przykładowo: uzytkownik@domena.pl.");
		return false;

	}


	if ( document.getElementById("USR_login_passwd").value == "" )
	{

	    alert("Błąd: uzupełnij pole z hasłem!");
	    return false;

	}

	document.getElementById(id).submit();

}

function usrmessage_delete(id, user)
{

	var agree = confirm("Czy jesteś pewien, że chcesz usunąć wiadomość od użytkownika " + user + "? Będzie to operacja bezpowrotna!");

	if (agree)
	{

		location.href='?mod=user&do=inbox&deletemsg=' + id;

	}

}

function usrmessage_send(id)
{

	if ( document.getElementById("UMS_text").value.length < 4 )
	{

	    alert("Błąd: tekst wiadomości jest za krótki!");
	    return false;

	}

	document.getElementById(id).submit();

}

function delete_avatar(msg)
{

	var agree = confirm(msg);

	if (agree)
	{

		location.href='?mod=user&do=edit_account&avatar=delete';

	}

}

function edit_account(id)
{

	if ( document.getElementById("USR_passwd").value != "" )
	{

		if ( document.getElementById("USR_passwd").value.length < 6 )
		{

		    alert("Błąd: hasło musi zawierać przynajmniej 6 znaków!");
		    return false;

		}

		if ( document.getElementById("USR_passwd").value != document.getElementById("USR_passwd2").value )
		{

		    alert("Błąd: hasło i jego potwierdzenie się różnią!");
		    return false;

		}

	}

	if ( document.getElementById("USR_email").value != "" )
	{

		if ( document.getElementById("USR_email").value.indexOf('@', 0) == -1 )
		{

			alert("Błąd: niepoprawny adres poczty elektronicznej!");
			return false;
		}

	}

	if ( document.getElementById("USR_www").value != "" )
	{

		if ( document.getElementById("USR_www").value.indexOf('http://', 0) == -1 )
		{

			alert("Błąd: zły adres strony WWW. Prawidłowy ma postać: http://strona.pl!");
			return false;

		}

		if ( document.getElementById("USR_www").value.length < 12 )
		{

			alert("Błąd: adres strony WWW jest zbyt krótki!");
			return false;

		}

	}

	document.getElementById(id).submit();

}

function create_account(id)
{

	if ( !validEmail(document.getElementById("USR_login").value))
	{

	    alert("Błąd: niepoprawny adres poczty elektronicznej!");
	    return false;

	}

	if ( document.getElementById("USR_name").value.length < 2 )
	{

	    alert("Błąd: brak podpisu!");
	    return false;

	}

	if ( document.getElementById("USR_login").value.indexOf('@', 0) == -1 )
	{

		alert("Błąd: niepoprawny adres poczty elektronicznej!");
		return false;
	}

	if ( document.getElementById("USR_passwd").value.length < 6 )
	{

	    alert("Błąd: hasło musi zawierać przynajmniej 6 znaków!");
	    return false;

	}

	if ( document.getElementById("USR_passwd").value != document.getElementById("USR_passwd2").value )
	{

	    alert("Błąd: hasło i jego potwierdzenie się różnią!");
	    return false;

	}

	document.getElementById(id).submit();

}

function showText(type, child)
{

	advAJAX.get({
		url: "index.php",
		parameters : {
			"mod" : "listnews",
			"type" : type,
			"filter" : child
		},
		mimeType: 'text/plain',
		onLoading : function(obj) {
			document.getElementById("playground").innerHTML = "";
			document.getElementById("IMG_loading").style.display = "block";
		},
		onComplete : function(obj) {
			document.getElementById("IMG_loading").style.display = "none";
		},
		onSuccess: function(obj) {

			document.getElementById("playground").innerHTML = obj.responseText;
			for (i=1; i<=3; i++)
			{

				document.getElementById("boxtitle_" + i).className = "boxtitles boxtitlesnoactive";

			}

			document.getElementById("boxtitle_" + type).className = "boxtitles";

		}

	});

}

function sendForm(id)
{

	if ( document.getElementById("name").value.length < 2 )
	{

	    alert("Błąd: brak podpisu...");
	    return false;

	}

	if ( !validEmail(document.getElementById("email").value) )
	{

	    alert("Błąd: niepoprawny adres e-mail");
	    return false;

	}

	if ( document.getElementById("text").value.length < 10 )
	{

	    alert("Błąd, wiadomość jest za krótka...");
	    return false;

	}

	input = document.createElement("input");
	input.type = "hidden";
	input.value = id;
	input.name = "message_send";
	document.getElementById(id).appendChild(input);

	document.getElementById(id).submit();

}

function addComment(formid, nid)
{

	if ( document.getElementById("comment_name").value.length < 2 )
	{

	    alert("Błąd: brak podpisu...");
	    return false;

	}

	if ( document.getElementById("comment_text").value.length < 2 )
	{

	    alert("Błąd: komentarz nie zawiera treści...");
	    return false;

	}

	input = document.createElement("input");
	input.type = "hidden";
	input.value = nid;
	input.name = "comment_add";
	document.getElementById(formid).appendChild(input);

	document.getElementById("comment_form").submit();

}

$(document).ready(function(){
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'fast',
		showTitle: false,
		allowresize: false,
		hideflash: true,
		theme:'facebook'
	});

});

function VideoLaunch(params) {
	$("#VideoLink").attr('href', params);
	$("#VideoLink").trigger('click');
}