function sprawdzEmail(email)
{
	return (email.match(/.+@.+\..+/i))
}

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 = '/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 otworzProdukt(id, typ)
{
	var width = 810;
	var height = 500;
	var name = 'oknoProduktowe';

	//

	if ((document.domain == 'b2b.computers.ropla.eu') || (document.domain == 'rop-b2b.hyziak.pl'))
	{
		var x = (screen.availWidth - width)/2;
		var y = (screen.availHeight - height)/2;

		win = window.open('/sklep/produkt/' + id, name, 'width='+width+',height='+height+',left='+x+',top='+y+',toolbar=0,menubar=0,scrollbars=1,resizable=1');

		if (win)
			win.focus();

		return win;
	}

	if ((document.domain == 'www.er-link.pl') || (document.domain == 'erl.hyziak.pl'))
	{
		window.location.href = '/sklep/produkt/' + id;
	}
}

function dodajDoKoszyka(id)
{
	if ((document.domain == 'www.er-link.pl') || (document.domain == 'erl.hyziak.pl'))
		window.location.href = '/sklep/koszyk/' + id;
	else
	{
		if (opener)
		{
			opener.location.href = '/sklep/koszyk/' + id;

			window.close();
		}
		else
			window.location.href = '/sklep/koszyk/' + id;
	}
}

// object
// icon
// state

function rolloverIcon(o, i, s)
{
	if (s)
		o.src = '/gfx/layout-erlink/ikona_' + i + '_' + s + '.jpg';
	else
		o.src = '/gfx/layout-erlink/ikona_' + i + '.jpg';
}

function rollover(o)
{
	if (o.src.match('_over.gif'))
		o.src = o.src.replace('_over.gif', '.gif');
	else
		o.src = o.src.replace('.gif', '_over.gif');
}

function otworzKalkulatorRat()
{
	window.open('https://www.zagiel.com.pl/kalkulator/index.php?action=gettype&shopNo=13467080');
}

function sprawdzPoleLogowania()
{
	var o = getElement('emailBox');

	if (o.value)
		o.className = 'pustyBox';
	else
		o.className = 'emailBox';

	o = getElement('hasloBox');

	if (o.value)
		o.className = 'pustyBox';
	else
		o.className = 'hasloBox';
}

