function sprawdzEmail(email)
{
    return (email.indexOf(".") > 2 && email.indexOf("@") > 0);
}

function getElement(id)
{
	if (document.all)
		var element = document.all[id];
	else if (document.layers)
		var element = document.layers[id];
	else if (document.getElementById)
		var element = document.getElementById(id);
	else
		return null;

	return element;
}

function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function 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));
}

function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function popup(url, name, width, height)
{
	var x = (screen.availWidth - width)/2;
	var y = (screen.availHeight - height)/2;

	win = window.open(url, name, 'width='+width+',height='+height+',left='+x+',top='+y+',toolbar=0,menubar=0,scrollbars=0,resizable=0');

	if (win)
		win.focus();

	return win;
}

function toggle(e)
{
	if (e.style.display == 'none')
		e.style.display = 'block';
	else
		e.style.display = 'none';
}

function przelaczLista()
{
	if (window.location.href.indexOf('&typ=galeria') > 0)
		window.location.href = window.location.href.replace(/&typ=galeria/gi, '&typ=lista');
	else if (window.location.href.indexOf('&typ=lista') == -1)
		window.location.href += window.location.href.indexOf('?') > 0 ? '&typ=lista' : '?typ=lista';
}

function przelaczGaleria()
{
	if (window.location.href.indexOf('&typ=lista') > 0)
		window.location.href = window.location.href.replace(/&typ=lista/gi, '&typ=galeria');
	else if (window.location.href.indexOf('&typ=galeria') == -1)
		window.location.href += window.location.href.indexOf('?') > 0 ? '&typ=galeria' : '?typ=galeria';
}

function pokazKoszyk()
{
	window.location.href = '?module=sklep_koszyk';
}

function parseNIP(input)
{
	input.value = input.value.replace(/[^0-9\-]+/, '');
}

function parseREGON(input)
{
	input.value = input.value.replace(/[^0-9]+/, '');
}

function parseTelefon(input)
{
	input.value = input.value.replace(/[a-zA-Z]+/, '');
}

function potwierdzUsuniecie()
{
	return confirm('Czy na pewno chcesz usun±æ wybrany rekord?');
}

function cacheObrazkow()
{
	new Image().src = 'gfx/layout/zdjecia/1.jpg';
	new Image().src = 'gfx/layout/zdjecia/2.jpg';
	new Image().src = 'gfx/layout/zdjecia/3.jpg';
	new Image().src = 'gfx/layout/zdjecia/4.jpg';
	new Image().src = 'gfx/layout/zdjecia/5.jpg';
	new Image().src = 'gfx/layout/zdjecia/6.jpg';
}

var poprzedniWybrany = 0;

function losujObrazek()
{
	do
	{
		var wybrany = Math.round(Math.random() * 5) + 1;
	}
	while (poprzedniWybrany == wybrany);

	poprzedniWybrany = wybrany;

	if (getElement('obrazek').filters)
		getElement('obrazek').filters.blendTrans.Apply();

	getElement('obrazek').src = '/gfx/layout/zdjecia/' + wybrany + '.jpg';

	if (getElement('obrazek').filters)
		getElement('obrazek').filters.blendTrans.Play();

	setTimeout('losujObrazek();', 5000);
}
