function is_email(email) {
  var emailPattern = /^[a-z0-9]+((-*)(.*))+([_|-|.][a-z0-9]+)*\@([a-z0-9]+((-*)(.*)[a-z0-9]+)*\.(com|edu|biz|org|gov|int|info|mil|net|arpa|name|museum|coop|aero|[a-z][a-z])|(\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]))$/;                     
  return emailPattern.test(email.toLowerCase());
}


function sprawdzEmail(email)
{
  if (!is_email(email)) {
	return false;
  }
  return true;
}

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 przelaczLista()
{
	var vhtm=window.location.href.split("-") 
	window.location.href =vhtm[0]+'-'+vhtm[1]+'-'+vhtm[2]+'-'+vhtm[3]+'-'+vhtm[4]+'-'+'lista'+'-'+vhtm[6]+'-'+vhtm[7]+'-'+vhtm[8];
	//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()
{
	
	
	var vhtm=window.location.href.split("-") 
	window.location.href =vhtm[0]+'-'+vhtm[1]+'-'+vhtm[2]+'-'+vhtm[3]+'-'+vhtm[4]+'-'+'galeria'+'-'+vhtm[6]+'-'+vhtm[7]+'-'+vhtm[8];
	//alert(window.location.href);
	//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=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 przeliczBruttoNetto(wartoscBrutto, marza, poleNetto, poleBrutto)
{
    var oldNetto=poleNetto.value;
    var oldBrutto=poleBrutto.value;
  	if(!isNaN(poleBrutto.value))
	{
		poleNetto.value = Math.round((poleBrutto.value/(1+(marza/100) ))*100)/100;
	}
	else
	{
		alert('To nie jest liczba !');
				
	}


}
