var platnoscipl = "https://www.platnosci.pl/paygw/ISO/NewPayment";
var dotpay = "https://ssl.dotpay.pl/";
var paypal = "https://www.paypal.com/cgi-bin/webscr/";
var przelewy24 = "https://secure.przelewy24.pl/index.php";
var ratyZagiel = "https://www.eraty.pl/symulator/krok1.php";
window.document.onkeypress = CheckEnter;
//document.oncontextmenu = function(){return false;}
function Open(file,title,width,height)
{
	var left=(screen.availWidth-width)/2;
	var top=(screen.availHeight-height)/2;
	window.open(file,title,'toolbar=no,menubar=no,location=no,personalbar=no,status=no,resizable=yes,scrollbars=yes,width='+width+',height='+height+',top='+top+',left='+left+'');
}
function Open2(file,title,width,height)
{
	var left=(screen.availWidth-width)/2;
	var top=(screen.availHeight-height)/2;
	w=window.open(file,title,'toolbar=no,menubar=no,location=no,personalbar=no,status=no,resizable=no,scrollbars=no,width='+width+',height='+height+',top='+top+',left='+left+'');
}
function Open3(file,title,width,height)
{
	var left=(screen.availWidth-width)/2;
	var top=(screen.availHeight-height)/2;
	w=window.open(file,title,'toolbar=no,menubar=no,location=no,personalbar=no,status=no,resizable=yes,scrollbars=no,width='+width+',height='+height+',top='+top+',left='+left+'');
}
function Open4(file,title,width,height)
{
	var left=(screen.availWidth-width)/2;
	var top=(screen.availHeight-height)/2;
	w=window.open(file,title,'toolbar=no,menubar=no,location=no,personalbar=no,status=no,resizable=no,scrollbars=yes,width='+width+',height='+height+',top='+top+',left='+left+'');
}
function Reminder(email,page,msg)
{
	if(document.getElementById(email)==null || document.getElementById(email).value=="") 
	{
		alert(msg);
	}
	else
	{	
		SubmitForm(null,page);
	}
}
function GetPayment(pagedest,optID,demoVersion)
{
	var obj = document.getElementsByName(optID);

	for(var i = 0; i < obj.length; i++)
	{
		if(obj[i].checked)
		{
			if(obj[i].value == 3) //platnosci.pl
			{
				if(demoVersion==1){alert(language.Get("key1"));return false;}else{return SubmitForm(null,pagedest);}
			}
			else if(obj[i].value == 7) //raty zagiel
			{
				if(ZagielValidate()){return SubmitForm(null,pagedest);}else{return false;}
			}			
			else{return SubmitForm(null,pagedest);}
		}
	}
	alert(language.Get("key2"));
}
function ChangeUrl(obj, newUrl)
{
	if(obj.href != null)
	{
		obj.href = newUrl;
	}
}
function DeleteProduct(id,page)
{
	document.forms[0].hdnDel.value=id; 	
	SubmitForm(null,page);
}
function SubmitForm(src,page,enctype)
{
	if(src!=null){try{document.getElementById("hdnsubmitsrc").value=src.id;}catch(e){}}
	if(enctype !=null)
	{
		document.forms[0].enctype = enctype;
		document.forms[0].encoding = enctype;
	}		
	document.forms[0].method = "post";
    document.forms[0].action = page;
    document.forms[0].submit(); 	
}
function ChangeImg(uniqueName)
{	
	try
	{
		var parent = document.getElementById("spanImgBig");	
		var tmp = imgprd.GetImage(uniqueName);
		
		if(tmp != null && tmp != undefined)
		{
			parent.innerHTML = "<img id='"+tmp.id+"' src='"+tmp.src+"' alt='' width='"+tmp.width+"' height='"+tmp.height+"'>"; //width='"+tmp.width+"' height='"+tmp.height+"'
		}
	}catch(e){}
}

function GetImgID(idobj)
{
		var img= document.getElementById(idobj).getElementsByTagName("IMG");
		return img[0].id;
}
function Img()
{
	this.uniqueName = "";
	this.img = null;	
}
function ImagePrd(http_host,img_type,water_mark)
{
	this.arrImages = new Array();
	this.host = http_host;
	this.imgType = img_type;
	this.waterMark = water_mark;
			
	this.Add = function(id,uniqueName,fileName2Disc,width,height)
	{
		var im = new Img();
		im.uniqueName = uniqueName;
		var img = new Image();
		img.src = this.GetUrl(fileName2Disc);
		img.alt = "Picture";
		img.id = id;
		img.width = width;
		img.height = height;
		im.img = img;
		this.arrImages.push(im);
	}
	
	this.GetUrl = function(fileName2Disc)
	{
		if(this.waterMark == 1)
		{
			return "image.php?wm=1&src=images/upload/"+fileName2Disc;
		}
		else
		{
			return "../images/upload/"+fileName2Disc;
		}
	}
	
	this.GetImage = function(uniqueName)
	{
		for(var i=0; i< this.arrImages.length;i++)
		{
			if((this.arrImages[i]).uniqueName == uniqueName)
			{
				return this.arrImages[i].img;
			}
		}
	}	
}
function SetPrice(src,dest,token)
{
	var src = document.getElementById(src);
	var dest = document.getElementById(dest);
	dest.innerHTML = src.value+" "+token;
}
function CheckPrice(price,dest,token)
{
	var dest = document.getElementById(dest);
	if(dest.innerHTML == "")
	{
		dest.innerHTML = price +" "+token;	
	}
}
function SetLogin(val)
{
	if(val.length == 0)
	{
		var email = document.getElementById("Login");
		val = email.value;
	}

	try
	{
		var login = document.getElementById("PassEmail");
		login.value = val;
	}
	catch(e){};
}
function CheckEnter(e)
{
	if (!e) {var e = window.event;}
		
	if(IsMSIE())
	{
		if(e.srcElement.type == "textarea")
		{
			return true;
		}
	}
	else
	{
		var node = e.target;
		if(node.type == "textarea")
		{
			return true;
		}
	}
	
	if(e.keyCode == 13)
	{
		return false;
	}
	
	return true;
}
function ChangeOrder(obj,url,mode)
{
	if(mode==1)//url friendly
	{
		var arr = Array();
		arr = url.split(",");
		arr[7] = obj[obj.selectedIndex].value;
		url = arr.join(",");
		window.location = url;
	}
	else
	{
		var m = obj[obj.selectedIndex].value;
		url = url.replace(/order=([0-9]+)/,"order="+m);
		window.location = url;
	}
}
function ValidateQuantity(control,unit,unittype)
{
	var quantity = control;
	var v = new Validate();
	
	if(unittype==0)
	{			
		v.Add(quantity.id,"intplus",language.Get("key3"),"1, 2, 10");
		if(!v.IsValid())
		{
			quantity.value = 1;
			quantity.style.background="red";
			alert(v.message);
		}		
	}
	else if(unittype == 1)
	{
		v.Add(quantity.id,"floatplus",language.Get("key3"),"0.3, 0.6, 1, 1.5");
		quantity.value = quantity.value.replace(/,/g,".");
		if(!v.IsValid())
		{
			quantity.value = 0.1;
			quantity.style.background="red";
			alert(v.message);
		}		
	}	
}
function AddToBag(id,prdexist,unit,unittype,modeTypeAccount)//id = idprodukt, unit - jednostka miary produktu
{	
	if(prdexist == 0)
	{
		alert(language.Get("key4"));
		return false;
	}
	
	if(CheckBagAccount(id,modeTypeAccount) == false)
	{
		return false;
	}
	
	//textbox z iloscią produktow do dodania  - jesli istnieje
	var quantity = document.getElementById("txtq"+id);	
	if(quantity!=null) 
	{
		var v = new Validate();
		if(unittype == 0)
		{			
			v.Add("txtq"+id,"intplus",language.Get("key3"),"1, 2, 10");			
		}
		else if(unittype == 1)
		{
			v.Add("txtq"+id,"floatplus",language.Get("key3"),"0.3, 0.5, 1, 1.5");
			quantity.value = quantity.value.replace(/,/g,".");
		}
		
		if(!v.IsValid())
		{
			quantity.style.background="red";
			alert(v.message);
			return false;
		}
		else
		{
			SetCookie("bagPrdQuantity", quantity.value);
		}		
	}
	
	//zapis wybranych typow do koszyka
	SaveBagAccount(id);
}
function GetWindowWidth()
{
    if(window.document.documentElement && ( window.document.documentElement.clientWidth || window.document.documentElement.clientHeight ))
    {
        return window.document.documentElement.clientWidth;
    } 
    else if(window.document.body && ( window.document.body.clientWidth || window.document.body.clientHeight ))
    {
        return window.document.body.clientWidth;
    }
    else
    {
        return 0;
    }
}
function GetWindowHeight()
{
    if( window.document.documentElement && ( window.document.documentElement.clientWidth || window.document.documentElement.clientHeight ))
    {
        return window.document.documentElement.clientHeight;
    } 
    else if( window.document.body && ( window.document.body.clientWidth || window.document.body.clientHeight ))
    {
        return window.document.body.clientHeight;
    }
    else
    {
        return 0;
    }
}
function IsMSIE()
{
	var userAgent = window.navigator.userAgent;
	if(userAgent.indexOf("MSIE")>=1)
	{
		return true;
	}
	else
	{
		return false;
	}	
}
function GoTo(dest)
{
	location.href = "#a"+dest;
}
function AddComment(page)
{
	SubmitForm(null,page);
}
function GetScrollXY() 
{
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) 
  {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } 
  else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
  {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } 
  else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
  {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}
function SetScrollXY(scrOfX,scrOfY) 
{
  if( typeof( window.pageYOffset ) == 'number' ) 
  {
    //Netscape compliant
    window.pageYOffset = scrOfY;
    window.pageXOffset = scrOfX;
  } 
  else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    document.body.scrollTop = scrOfY;
    document.body.scrollLeft = scrOfX;
  } 
  else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
  {
    //IE6 standards compliant mode
    document.documentElement.scrollTop = scrOfY;
    document.documentElement.scrollLeft = scrOfX;
  }
}
function AddToFavorite()
{
	var url=document.location;
	var title=document.title;
	
    //FireFox
    if (window.sidebar) { 
        window.sidebar.addPanel(title, url, ""); 
    //IE
    } else if (window.external) {
        window.external.AddFavorite(url, title); 
    //Opera
    } else if (window.opera && window.print) {
        var a = document.createElement("a");
        a.setAttribute("href", url);
        a.setAttribute("title", title);
        a.setAttribute("rel","sidebar");
        a.click();
    }		
}
function CheckZipCode(obj)
{	
	var t = obj.value;
	if (t.match(/^\d+$/) == null)
	{
		obj.value = t.substring(0,t.length-1);
	}
}
function CheckZipLength(obj)
{
	if(obj.value.length == 2)
	{
		document.getElementById('txtplugzipcode2').focus();
	}
}
function MakeRequest(url) 
{
    http_request = false;
	
    if (window.XMLHttpRequest) // Mozilla, Safari,...
	{ 
        http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) 
		{
			http_request.overrideMimeType('text/xml;');
		}		
    } 
	else if (window.ActiveXObject) // IE
	{ 
        try 
		{
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } 
		catch (e) 
		{
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) 
	{
        return false;
    }
	else
	{
		return http_request;
	}
}
function CheckRating(msg,enabled)
{
	if(enabled==1)
	{
		if(document.getElementById('optcomment1').checked==false && document.getElementById('optcomment2').checked==false && document.getElementById('optcomment3').checked==false && document.getElementById('optcomment4').checked==false && document.getElementById('optcomment5').checked==false)
		{
			alert(msg);
			return false;
		}
	}
	return true;
}
function SaveProductComment(idprd,msgok,msgerr)
{
	var comment = document.getElementById('txtacomment').value;
	var author = document.getElementById('txtcomment').value;
	var ratings = document.getElementsByName('optcomment');
	var email = document.getElementById('txtcommentemail').value;	
	var rat = 0;

	for(var k=0;k < ratings.length;k++)
	{
		var rating = ratings[k];
		if(rating.checked == true)
		{
			rat = rating.value;
		}
	}
	var url = 'prdcommentajax.php?language='+langID+'&idprd='+idprd+'&rating='+rat+'&comment='+encodeURIComponent(comment)+'&author='+encodeURIComponent(author)+'&email='+(email)+'';	
	var http_request = MakeRequest(url);
	if(http_request != null)
	{
		http_request.onreadystatechange = function() {return true;};
		http_request.open('GET', url, true);
		http_request.send(null);		
		alert(msgok);
	}
	else
	{
		alert(msgerr);
	}
	
	document.getElementById('txtacomment').value = "";
	document.getElementById('txtcomment').value = "";
	document.getElementById('txtcommentemail').value = "";
}
function SetSrcSearch(src)
{
	document.getElementById('hdnSearchSrc').value = src;
}
//Funkcja do zapisu w cookie stanu formularza wyszukiwania zaawansowanego na liscie produktow 
function SaveSearch()
{
	if(objValid!=null)
	{
		if(!objValid.IsValid())
		{
			alert(objValid.message);
			return false;
		}
	}	

	var obj = document.getElementsByName("chksrch");//kolekcja checkboxow
	var tmp = "";
	
	for(var i = 0; i < obj.length; i++)
	{
		if(obj[i].checked)
		{
			tmp += "" + obj[i].getAttribute("id").replace("chk","") +";";
		}		
	}
	if(tmp.length>0)
	{
		tmp = tmp.substring(0,tmp.length-1);
	}
	
	SetCookie("search[idatr]", tmp);
	SetCookie("search[pricefrom]", document.getElementById("txtPriceFrom").value);
	SetCookie("search[priceto]", document.getElementById("txtPriceTo").value);
	return true;
}
//Kasuje stan formularza wuszukiwania
function DeleteSearch()
{
	DeleteCookie("search[idtree]");
	DeleteCookie("search[idatr]");
	DeleteCookie("search[pricefrom]");
	DeleteCookie("search[priceto]");
	DeleteCookie("search[text]");
}
function SearchAtrMore(obj,idobjtypeatr)
{
	var div = document.getElementById(idobjtypeatr);	
	if(div == null) return;
	if(div.style.display=="none")
	{
		div.style.display = "block";
		obj.innerHTML = language.Get("key15");
	}
	else
	{
		div.style.display = "none";
		obj.innerHTML = language.Get("key16");
	}
}
function DSS()
{
	return DeleteSearch();
}
function SubmitSearch(idControl,page,src)
{
	var s = document.getElementById(idControl);	
	if(s != null && s.value.length>0)
	{
		SetSrcSearch(src);
		SubmitForm(null,page);
	}
	else
	{
		return false;
	}
}
function SubmitSearchExt(page,src)
{
	var onsub = true;
	
	if(objValid!=null)
	{
		if(!objValid.IsValid())
		{
			onsub = false;
			alert(objValid.message);			
		}
	}	
	
	if(onsub)
	{
		SetSrcSearch(src);
		SubmitForm(null,page);
	}
}
function SearchShowHide(obj,objIdToShow,textshow,texthide)
{
	var objToShow = document.getElementById(objIdToShow);
	if(objToShow.style.display=="none")
	{
		objToShow.style.display="block";
		obj.innerText = texthide;
		obj.className = "clssearchshow searchvisible";
	}
	else
	{
		objToShow.style.display="none";
		obj.innerText = textshow;
		obj.className = "clssearchshow searchhide";
	}
}
function ShowPopAdvertising(wait)
{
	if(wait==null)
	{
		setTimeout('ShowPopAdvertising(1)', 1000);
	}
	else
	{
		var advert = document.getElementById("popAdvertising");
		var left=(GetWindowWidth() - advert.style.width.replace("px",""))/2;
		var top=(GetWindowHeight() - advert.style.height.replace("px",""))/2;	
		advert.style.left = left+"px";
		advert.style.top = top+"px";
	}
}
function SetTemplateFolder(obj)
{
	SetCookie("templateFolder", obj[obj.selectedIndex].value);
	SubmitForm(null,"home");
}
function GoProducer(obj,url)
{
	DeleteSearch();
	var name = obj[obj.selectedIndex].innerHTML;
	name = name.replace(" ","-");
	name = name.toLowerCase();
	var url = name + url;
	location.href = url.replace("{ID}",obj[obj.selectedIndex].value);	
}
function SaveUserForm(idform,msgok,msgerr)
{
	var name = document.getElementById('txtform'+idform+'_name');
	var email = document.getElementById('txtform'+idform+'_email');
	var subject = document.getElementById('txtform'+idform+'_subject');
	var body = document.getElementById('txtform'+idform+'_body');	
	
	var url = 'userformajax.php?idform='+idform+'&name='+encodeURIComponent(name.value)+'&body='+encodeURIComponent(body.value)+'&subject='+encodeURIComponent(subject.value)+'&email='+(email.value)+'';	
	var http_request = MakeRequest(url);
	if(http_request != null)
	{
		http_request.onreadystatechange = function() {return true;};
		http_request.open('GET', url, true);
		http_request.send(null);		
		alert(msgok);
	}
	else
	{
		alert(msgerr);
	}
	
	name.value = "";
	email.value = "";
	subject.value = "";
	body.value = "";
}
function FloatRound(original,decimals)
{
	if(decimals == 1) return Math.round(original*10)/10;
	if(decimals == 2) return Math.round(original*100)/100;
	if(decimals == 3) return Math.round(original*1000)/1000;
	return original;
}
function FloatFormat(no)
{
	var number=new String(no);
	if(number.search(/\./)!=-1)
	{
		var arr = new Array();
		arr = number.split(".");
		if(arr[1].length==0)		
		{
			return arr[0]+".00";
		}
		else if(arr[1].length==1)
		{
			return arr[0]+"."+arr[1]+"0";
		}
		else
		{
			return number;
		}
	}
	else
	{
		return number+".00";
	}
}
function CheckRules()
{
	var chk = document.getElementById('chkrules');
	if(chk == null){return true;}
	if(!chk.checked){alert(language.Get("key13"));return false;}
	return true;
}
function ZagielPoliczRate(koszyk,wariantSklepu,numerSklepu) 
{
	var url = 'https://www.eraty.pl/symulator/oblicz.php?numerSklepu='+numerSklepu+'&wariantSklepu='+wariantSklepu+'&typProduktu=0&wartoscTowarow='+koszyk;
	window.open(url, 'Policz_rate','width=630,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}
function ZagielProcedura() 
{
	window.open('https://www.zagiel.com.pl/kalkulator/jak_kupic.html', 'nowe_okno','width=600,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}
function ZagielValidate() 
{
	if (document.getElementById("id_nazwy_pola_raty_zgoda").checked==false){alert ("Zanim złożysz zamówienie, zapoznaj sie z procedurą udzielenia kredytu ratalnego eRaty Żagiel.");return false;} else {return true;}
}

var objValid = new Validate();

function ValidateForm()
{
	if(!objValid.IsValid())
	{
		alert(objValid.message);
		return false;		
	}
	return true;
}

function Validate()
{
	this.arrItems = new Array();
	this.message = "";
	
	this.Add = function(idControl,validateType,caption,correctValue,regex)
	{		
		this.arrItems.push(new Array(idControl,validateType,caption,correctValue,regex));
	}
	
	this.MarkControl = function(obj)
	{
		obj.className = obj.className + " txterr";
		obj.onclick = function(){this.className = "txt";};
	}
	
	this.IsValid = function()
	{
		
		for(var i=0; i < this.arrItems.length; i++)
		{
			var obj = document.getElementById(this.arrItems[i][0]);
			
			if(this.arrItems[i][1] == "float0plusORempty")
			{
				var t = obj.value.replace(/,/g,".");
				obj.value = t;
				
				if (t.length > 0 && (t.match(/^-?\d+(\.\d+)?$/) == null || t < 0))
				{
					this.message = language.Get("key5")+' "' + this.arrItems[i][2] + '" '+language.Get("key6");
					if(this.arrItems[i][3]!= null && this.arrItems[i][3].length > 0)
					{
						this.message += language.Get("key6a") + ' ' + this.arrItems[i][3]
					}	
					this.MarkControl(obj);
					return false;
				}
			}			
			else if(this.arrItems[i][1] == "floatplus")
			{
				var t = obj.value.replace(/,/g,".");
				obj.value = t;
				
				if (t.length == 0 || t.match(/^-?\d+(\.\d+)?$/) == null || t <= 0)
				{
					this.message = language.Get("key5")+' "' + this.arrItems[i][2] + '" '+language.Get("key6");
					if(this.arrItems[i][3]!= null && this.arrItems[i][3].length > 0)
					{
						this.message += language.Get("key6a") + ' ' + this.arrItems[i][3]
					}
					this.MarkControl(obj);
					return false;
				}
			}
			else if(this.arrItems[i][1] == "float0plus")
			{
				var t = obj.value.replace(/,/g,".");
				obj.value = t;
				
				if (t.length == 0 || t.match(/^-?\d+(\.\d+)?$/) == null || t < 0)
				{
					if(this.arrItems[i][2]!= null && this.arrItems[i][2].length > 0)
					{
						this.message = language.Get("key5")+' "' + this.arrItems[i][2] + '" '+language.Get("key6");
					}
					else
					{
						this.message = language.Get("key5")+' '+language.Get("key6");
					}
					
					if(this.arrItems[i][3]!= null && this.arrItems[i][3].length > 0)
					{
						this.message += language.Get("key6a") + ' ' + this.arrItems[i][3]
					}
					this.MarkControl(obj);
					return false;
				}
			}
			else if(this.arrItems[i][1] == "intplus")
			{
				var t = obj.value;
				
				if (t.length == 0 || t.match(/^\d+$/) == null || t <= 0)
				{
					this.message = language.Get("key5")+' "' + this.arrItems[i][2] + '" '+language.Get("key6");
					if(this.arrItems[i][3]!= null && this.arrItems[i][3].length > 0)
					{
						this.message += language.Get("key6a") + ' ' + this.arrItems[i][3]
					}
					this.MarkControl(obj);
					return false;
				}
			}
			else if(this.arrItems[i][1] == "int0plus")
			{
				var t = obj.value;
				
				if (t.length == 0 || t.match(/^\d+$/) == null || t < 0)
				{
					this.message = language.Get("key5")+' "' + this.arrItems[i][2] + '" '+language.Get("key6");					
					if(this.arrItems[i][3]!= null && this.arrItems[i][3].length > 0)
					{
						this.message += language.Get("key6a") + ' ' + this.arrItems[i][3]
					}
					this.MarkControl(obj);
					return false;
				}
			}		
			else if(this.arrItems[i][1] == "int")
			{
				var t = obj.value;
				
				if (t.length == 0 || t.match(/^\d+$/) == null)
				{
					this.message = language.Get("key5")+' "' + this.arrItems[i][2] + '" '+language.Get("key6");					
					if(this.arrItems[i][3]!= null && this.arrItems[i][3].length > 0)
					{
						this.message += language.Get("key6a") + ' ' + this.arrItems[i][3]
					}
					this.MarkControl(obj);
					return false;
				}
			}
			else if(this.arrItems[i][1] == "intempty")
			{
				var t = obj.value;
				
				if(t.length == 0)
				{
					continue;
				}
				
				if (t.match(/^\d+$/) == null)
				{
					this.message = language.Get("key5")+' "' + this.arrItems[i][2] + '" '+language.Get("key6");					
					if(this.arrItems[i][3]!= null && this.arrItems[i][3].length > 0)
					{
						this.message += language.Get("key6a") + ' ' + this.arrItems[i][3]
					}
					this.MarkControl(obj);
					return false;
				}
			}
			else if(this.arrItems[i][1] == "text")
			{
				var t = obj.value;
				
				if (t.length == 0 || t.replace(/ /g,"")=='')
				{
					this.message = language.Get("key7")+' "' + this.arrItems[i][2] + '" '+language.Get("key8");
					this.MarkControl(obj);
					return false;
				}
			}
			else if(this.arrItems[i][1] == "email")
			{
				var t = obj.value;
				
				if (t.length == 0 || t.match(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/) == null)
				{
					this.message = language.Get("key9")+' "' + this.arrItems[i][2] + '" '+language.Get("key10");
					this.MarkControl(obj);
					return false;
				}
			}	
			else if(this.arrItems[i][1] == "regex")
			{
				var t = obj.value;//alert(this.arrItems[i][4]);
				
				if (t.length == 0 || t.match(this.arrItems[i][4]) == null)
				{
					this.message = language.Get("key11")+' "' + this.arrItems[i][2] + '" '+language.Get("key6");
					if(this.arrItems[i][3]!= null && this.arrItems[i][3].length > 0)
					{
						this.message += language.Get("key6a") + ' ' + this.arrItems[i][3]
					}
					this.MarkControl(obj);
					return false;
				}
			}				
		}
				
		return true;
	}
}

var today = new Date();
var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);


function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) { endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));
	}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			return getCookieVal (j);
			}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
		}
	return null;
	}

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 SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
	}

/*******************************************************************************
 * Fading Scroller- ę Dynamic Drive DHTML code library (www.dynamicdrive.com)
 * This notice MUST stay intact for legal use Visit Dynamic Drive at
 * http://www.dynamicdrive.com/ for full source code
 ******************************************************************************/

function FadingScroller(objName, idControl) {
	this.name = objName;
	this.idControl = idControl;
	this.control = document.getElementById(this.idControl);
	this.delay = 2000; // set delay between message change (in miliseconds)
	this.maxsteps = 30; // number of steps to take to change from start color to
						// endcolor
	this.stepdelay = 40; // time in miliseconds of a single step
	// **Note: maxsteps*stepdelay will be total time in miliseconds of fading
	// effect
	this.startcolor = new Array(255, 255, 255); // start color (red, green,
												// blue)
	this.endcolor = new Array(0, 0, 0); // end color (red, green, blue)
	this.fcontent = new Array();
	this.begintag = '<div>'; // set opening tag, such as font declarations
	this.closetag = '</div>';
	this.fadelinks = 1;// should links inside scroller content also fade like
						// text? 0 for no, 1 for yes.
	this.faderdelay = 0;
	this.index = 0;
	this.fadecounter;
	this.ie4 = document.all && !document.getElementById;
	this.DOM2 = document.getElementById;

	this.addcontent = function(content) {

		this.fcontent.push(content);
	}

	/* Rafael Raposo edited function */
	this.changecontent = function() {

		if (this.index >= this.fcontent.length)
			this.index = 0
			
		if (this.DOM2) {
			this.control.style.color = "rgb(" + this.startcolor[0] + ", "
					+ this.startcolor[1] + ", " + this.startcolor[2] + ")"
			this.control.innerHTML = this.begintag + this.fcontent[this.index]
					+ this.closetag
										
			if (this.fadelinks) {
				this.linkcolorchange(1);
			}

			this.colorfade(1, 15);
		} else if (this.ie4)
			this.control.innerHTML = this.begintag + this.fcontent[this.index]
					+ this.closetag;
		this.index++
		
	}

	// colorfade() partially by Marcio Galli for Netscape Communications.
	// ////////////
	// Modified by Dynamicdrive.com

	this.linkcolorchange = function(step) {
		var obj = this.control.getElementsByTagName("A");
		if (obj.length > 0) {
			for (i = 0; i < obj.length; i++)
				obj[i].style.color = this.getstepcolor(step);
		}
	}

	/* Rafael Raposo edited function */

	this.colorfade = function(step) {
		if (step <= this.maxsteps) {
			this.control.style.color = this.getstepcolor(step);
			if (this.fadelinks)
				this.linkcolorchange(step);
			step++;
			this.fadecounter = setTimeout(this.name + ".colorfade(" + step
					+ ")", this.stepdelay);
		} else {
			clearTimeout(this.fadecounter);
			this.control.style.color = "rgb(" + this.endcolor[0] + ", "
					+ this.endcolor[1] + ", " + this.endcolor[2] + ")";
			setTimeout(this.name + ".changecontent()", this.delay);
		}
	}

	/* Rafael Raposo's new function */
	this.getstepcolor = function(step) {
		var diff
		var newcolor = new Array(3);
		for ( var i = 0; i < 3; i++) {
			diff = (this.startcolor[i] - this.endcolor[i]);
			if (diff > 0) {
				newcolor[i] = this.startcolor[i]
						- (Math.round((diff / this.maxsteps)) * step);
			} else {
				newcolor[i] = this.startcolor[i]
						+ (Math.round((Math.abs(diff) / this.maxsteps)) * step);
			}
		}
		return ("rgb(" + newcolor[0] + ", " + newcolor[1] + ", " + newcolor[2] + ")");
	}
}

 function CheckBagAccount(idprd,modeTypeAccount) //modeTypeAccount = 0, sprawdz wszystkie wymagane typy, modeTypeAccount = 1, wsytarczy ze jeden typ  z wymaganych jest zaznaczony/wybrany na stronie
 {
        var rq = document.getElementById("hdntarq" + idprd);
		var check = true;
		var arrMessage = new Array();
		
        if (rq != undefined && rq != null) 
		{
			var items = rq.value.split(",");
            var prd = document.getElementById("divprd" + idprd);
            var types = prd.getElementsByTagName("DIV")
			
            for (var i = 0; i < items.length; i++) //iteracja po typach wymaganych
			{
                check = false;
				var item = document.getElementById("divta" + idprd + "" + items[i]);
                if (item != undefined && item != null) 
				{
                    var ctrls = item.getElementsByTagName("INPUT");
					if (ctrls != undefined && ctrls != null) 
					{        
						for (var j = 0; j < ctrls.length; j++) 
						{                      
                            if (ctrls[j].name == "bagAccount" + idprd) 
							{
                                if (ctrls[j].checked == true) 
								{
                                    check = true;								
                                }
                            }
                        }						
						if(ctrls.length > 0 && check == false)
						{
							arrMessage.push(""+idprd+""+items[i]+"");		
						}						
                    }
					
					ctrls = null;
					ctrls = item.getElementsByTagName("SELECT");
					if (ctrls != undefined && ctrls != null) 
					{
                        for (var j = 0; j < ctrls.length; j++) 
						{                      
                            if (ctrls[j].name == "bagAccount" + idprd) 
							{
                                if (ctrls[j][ctrls[j].selectedIndex].value == "0|0|0|0|0|0")  //idtype|idtypeext|iddet|pricemode|brutto|netto
								{
                                    check = false;
                                }
								else
								{
									check = true;
								}
                            }
                        }
						if(ctrls.length > 0 && check == false)
						{
							arrMessage.push(""+idprd+""+items[i]+"");	
						}	
					}
                }
            } 			
			if(arrMessage.length > 0)
			{
				return TypeAccountMessage(arrMessage,modeTypeAccount,items.length);
			}			
        }
	return true;
 }
function TypeAccountMessage(arr,mode,countTypes)
{		
	if(mode == 0)//wyswietl wszsytkie alerty
	{
		  for (var i = 0; i < arr.length; i++) 
		  {
				TypeAccountAlert(arr[i]);				
		  }		  
	}
	if(mode == 1)//wyswietl tylko jeden alert ze wszsytkich wymaganych typów, poniewaz wystarczy aby wybrac jeden typ
	{
		if(arr.length < countTypes)//liczba alertow mniejsza od liczby typów wymaganych dla produktu
		{
			return true;
		}	
		else
		{
			if(arr.length > 0)
			{
				TypeAccountAlert(arr[0]); //wystarczy pierwszy alert
			}
		}		
	}
	return false;	
}
function TypeAccountAlert(id)
{
	var descr = document.getElementById("divtad"+id);
	var descrAlternative = document.getElementById("hdntad"+id);
	
	if(descrAlternative != null)
	{
		msg = descrAlternative.value;
	}	
	else if(descr == null)
	{
		msg = "Wybierz atrybut dla produktu!";
	}
	else
	{
		msg = language.Get("key12")+" "+descr.innerHTML+"!";
	}
	alert(msg);			
}
function SaveBagAccount(idproduct)
{
	var el = document.getElementsByName("bagAccount"+idproduct);			
	for(var i = 0; i < el.length; i++)
	{		
		if(el[i].tagName == "INPUT")
		{
			if(el[i].checked == true)
			{
				SetCookie("bagAccount["+i+"]", el[i].value);
			}			
		}
		else if(el[i].tagName == "SELECT")
		{			
			SetCookie("bagAccount["+i+"]", el[i].value);
		}		
	}
}
function AccPrice(obj,idprd)
{
	var objBrutto = document.getElementById("pricebrutto"+idprd);
	var objNetto = document.getElementById("pricenetto"+idprd);	
	var objBruttoOrginal = document.getElementById("hdnpriceb"+idprd);
	var objNettoOrginal = document.getElementById("hdnpricen"+idprd);
	var brutto;
	var netto;
	var bruttoOrginal = 0;
	var nettoOrginal = 0;
	var addBrutto = 0;
	var addNetto = 0;	
	
	if(objBrutto != undefined && objBrutto != null && objBruttoOrginal != undefined && objBruttoOrginal != null)
	{
		bruttoOrginal = parseFloat(objBruttoOrginal.value);
	}
	if(objNetto != undefined && objNetto != null && objNettoOrginal != undefined && objNettoOrginal != null)
	{
		nettoOrginal = parseFloat(objNettoOrginal.value);	
	}
		
	var collectionName = obj.getAttribute("name");			
	brutto = bruttoOrginal;
	netto = nettoOrginal;
	var el = document.getElementsByName(collectionName);
	
	for(var i = 0; i < el.length; i++)
	{		
		if(el[i].tagName == "INPUT")
		{
			if(el[i].checked == true)
			{
				var arr = new Array(); 
				arr = el[i].value.split("|"); //idtype|idtypeext|iddet|pricemode|brutto|netto
				if(arr[4] > 0 && arr[3] == 1)//dodaj do ceny
				{
					addBrutto = FloatFormat(parseFloat(addBrutto) + parseFloat(arr[4]));
					addNetto = FloatFormat(parseFloat(addNetto) + parseFloat(arr[5]));
				}
				if(arr[5] > 0 && arr[3] == 0)//nowa cena
				{
					brutto = FloatFormat(parseFloat(arr[4]));
					netto = FloatFormat(parseFloat(arr[5]));
				}				
			}			
		}
		if(el[i].tagName == "SELECT")
		{	
			var arr = new Array(); 
			arr = el[i][el[i].selectedIndex].value.split("|"); //idtype|idtypeext|iddet|pricemode|brutto|netto
			if(arr[4] > 0 && arr[3] == 1)//dodaj do ceny
			{
				addBrutto = FloatFormat(parseFloat(addBrutto) + parseFloat(arr[4]));
				addNetto = FloatFormat(parseFloat(addNetto) + parseFloat(arr[5]));
			}	
			if(arr[5] > 0 && arr[3] == 0)//nowa cena
			{
				brutto = FloatFormat(parseFloat(arr[4]));
				netto = FloatFormat(parseFloat(arr[5]));
			}			
		}		
	}

	if(objBrutto != null){objBrutto.innerHTML = FloatFormat(parseFloat(addBrutto) + parseFloat(brutto));}
	if(objNetto != null){objNetto.innerHTML = FloatFormat(FloatRound(parseFloat(addNetto) + parseFloat(netto),2));}
}

var ATR_RELOAD_NODE = true;//czy klikniecie na grupe ma powodowac odswiezenie strony
var ATR_TREE_EXPAND_ALL = false;
var globalIDPrev = 0;

function MenuItemAtr(divObj)
{
	this.divObj;
	this.lnkObj;
	this.url;
	this.id;
	this.idunique;
	this.idprev;
	this.imgOpen = "minus3.gif";
	this.imgClose = "plus3.gif";
	this.imgDefault = "last.gif";
	this.entityType = 0;
		
	this.Init = function()
	{		
		this.divObj = divObj;				
		this.divObj.style.display = "block";	
		this.id = this.divObj.id;
		var arr = this.id.split("-");
		
		this.idunique = arr[0].replace("div_","");
		this.entityType = arr[1];
		
		if(this.entityType == 0)
		{
			globalIDPrev = this.idunique;	
			this.idprev = 0;			
		}
		else
		{
			this.idprev = globalIDPrev;
		}
		this.lnkObj = document.getElementById("lnk_"+this.id.replace("div_",""));
		this.url = document.getElementById("hdn_"+this.id.replace("div_","")).value;
	}
	
	this.Visible = function()
	{
		if(this.divObj.style.display == "block")
		{
			this.divObj.style.display = "none";
		}
		else
		{
			this.divObj.style.display = "block";
		}
	}
	
	this.SetImage = function()
	{
		if(this.lnkObj.className == "ie")
		{
			return;			
		}
		if(this.lnkObj.className == "ip")
		{
			this.lnkObj.className = "im"
		}
		else
		{
			this.lnkObj.className = "ip"
		}
	}
	
	this.Load = function(displayMode, imageNo)
	{
		if(displayMode == 1)
		{
		    this.divObj.style.display = "block";
		}
		else
		{
		    this.divObj.style.display = "none";
		}
		
		if(imageNo == 1)
		{
			this.lnkObj.className = "im"
		}
		if(imageNo == 2)
		{
			this.lnkObj.className = "ip"
		}
	}
	
	this.Init();
}

function MenuAtr(idContener,idmark)
{
	this.contener = document.getElementById(idContener);
	this.arrItems = Array();
	this.name = idContener;
	this.externalFunctions = Array();//tablica funkcji zew, ktore maja byc uruchomione przed kliknieciem w node drzewa uruchamiający url (nie rozwijajacy drzewka)
	
	this.Init = function()
	{				
		if(this.contener == null)
		{
			return;
		}
		
		globalIDPrev = 0;
		
		for(var i = 0; i < this.contener.childNodes.length; i++)
		{
			var item = new MenuItemAtr(this.contener.childNodes[i]);
			this.arrItems.push(item);				
		}
		
		for(var i = 0; i < this.arrItems.length; i++)
		{			
			if(this.arrItems[i].idprev == 0)
			{									
				this.arrItems[i].divObj.onclick = new Function(this.name+'.ItemAction('+this.arrItems[i].idunique+',"'+this.arrItems[i].url+'")');			
			}
			else
			{
				this.arrItems[i].Visible();
				this.arrItems[i].divObj.onclick = new Function(this.name+'.GoUrl("'+this.arrItems[i].url+'")');
			}			
			
			this.arrItems[i].divObj.onmouseover = function(){this.className = "dmin"};
			this.arrItems[i].divObj.onmouseout = function(){this.className = "dm"};
						
			if(this.arrItems[i].identity == idmark)	
			{								
				this.arrItems[i].lnkObj.className = "ie asel";
			}
		}
		
		if(ATR_TREE_EXPAND_ALL)
		{
			for(var i = 0; i < this.arrItems.length; i++)
			{
				this.Drill(this.arrItems[i].idunique);
			}
			this.Save();
		}
	}
	
	this.ItemAction = function(idprev,url)
	{
		this.Drill(idprev);
		this.Save();
		if(ATR_RELOAD_NODE)
		{
			this.GoUrl(url);
		}		
	}
	
	this.GoUrl = function(url)
	{		
		this.RunExternalFunctions();
		location.href = url;
	}
	
	this.Drill = function(idprev)
	{
		for(var i = 0; i < this.arrItems.length; i++)
		{
			if(this.arrItems[i].idunique == idprev)
			{
				this.arrItems[i].SetImage();
			}
			
			if(this.arrItems[i].idprev == idprev)
			{
				this.arrItems[i].SetImage();
				this.arrItems[i].Visible();								
			}		
		}
	}
	
	this.Save = function()
	{		
		var tmp="";
		for(var i = 0; i < this.arrItems.length; i++)
		{
			if(this.arrItems[i].divObj.style.display != "block")
			{
				continue;
			}		
			
			tmp += this.arrItems[i].idunique;
			tmp += ",1,";//block
					
			if(this.arrItems[i].lnkObj.className == "im")
			{
				tmp += "1";//minus3.gif
			}
			else
			{							
			    if(this.arrItems[i].lnkObj.className == "ip")
			    {
				    tmp += "2";//plus3.gif
			    }
			    else
			    {
				    tmp += "0";//last.gif
			    }	
			}
			tmp += "|";
		}
		
		tmp = tmp.substring(0,tmp.length-1);
		SetCookie(this.name,tmp);
	}
	
	this.GetItem = function(idunique)
	{
	    for(var i = 0; i < this.arrItems.length; i++)
	    {	       
			if(this.arrItems[i].idunique == idunique)
	        {
				return this.arrItems[i];
	        }
	    }
	    return null;
	}
	
	this.Load = function()
	{	    
		if(GetCookie(this.name) == null)	
	    {
	        return false;
	    }
		
		var tmp = GetCookie(this.name);
		var arr = Array();
		arr = tmp.split("|");
				
		for(var i = 0; i < arr.length; i++)
		{
			var arr2 = Array();
			arr2 = arr[i].split(",");
			try
			{
				this.GetItem(arr2[0]).Load(arr2[1],arr2[2]);				
			}
			catch(e){}
		}
	}
	
	this.SetExternalFunctions = function()
	{
		this.externalFunctions.push("DeleteSearch()");
	}
	
	this.RunExternalFunctions = function()
	{
	    for(var i = 0; i < this.externalFunctions.length; i++)
	    {			
	    	eval(this.externalFunctions[i]);
	    }		
	}	
		
	this.Init();
	this.Load();
	this.SetExternalFunctions();
}
