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 AddEvent(obj, evType, fn, useCapture)
{
	  if (obj.addEventListener){
	    obj.addEventListener(evType, fn, useCapture);
	    return true;
	  } else if (obj.attachEvent){
	    var r = obj.attachEvent("on"+evType, fn);
	    return r;
	  } else {//alert("Handler could not be attached");
	  }
} 
function RemoveEvent(obj, evType, fn, useCapture)
{
	  if (obj.removeEventListener){
	    obj.removeEventListener(evType, fn, useCapture);
	    return true;
	  } else if (obj.detachEvent){
	    var r = obj.detachEvent("on"+evType, fn);
	    return r;
	  } else {//alert("Handler could not be removed");
	  }
}
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,stockValid)
{	
	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
		{
			if(stockValid != undefined && stockValid != null && stockValid > 0 && quantity.value > stockValid)
			{
				quantity.style.background="red";
				var m = language.Get("key17");
				m = m.replace("{n}",stockValid);
				m = m.replace("{u}","");//unit
				alert(m);
				return false;				
			}
			
			SetCookie("bagPrdQuantity", quantity.value);
		}		
	}	
	//zapis wybranych typow do koszyka
	SaveBagAccount(id);
}
function bu(idctrl,unittype)//basket up
{
	var v = document.getElementById(idctrl);
	if(unittype==0)
		v.value = parseInt(v.value) + 1;
	if(unittype==1)
		v.value = parseFloat(v.value) + 1;	
}
function bd(idctrl,unittype)//basket down
{
	var v = document.getElementById(idctrl);
	if(unittype==0)
		v.value = parseInt(parseInt(v.value) -1);
	if(unittype==1)
		v.value = FloatFormat(parseFloat(v.value) -1);
	if(parseInt(v.value) < 1)
		v.value = 1;
}
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);	
}
var captchaMsg = "";
function SaveUserForm(idform,msgok,msgerr)
{
	captchaMsg = "";
	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 captcha = document.getElementById('txtcaptcha'+idform);	
	var captchaValue = "";
	if(captcha != null)
		captchaValue = captcha.value;
		
	var url = 'userformajax.php?idform='+idform+'&name='+encodeURIComponent(name.value)+'&body='+encodeURIComponent(body.value)+'&subject='+encodeURIComponent(subject.value)+'&email='+(email.value)+'&captcha='+(captchaValue);	
	var http_request = MakeRequest(url);
	
	if(http_request != null)
	{
		if(captcha != null)
		{
			var runFunName = "ChaptchaValid(http_request)";
			http_request.onreadystatechange = function(){eval(runFunName);};
		}
		else
		{
			http_request.onreadystatechange = function(){};
		}
		http_request.open('GET', url, true);
		http_request.send(null);		
		setTimeout("SaveUserFormMsg('"+msgok+"')",500);
	}
	else
	{
		alert(msgerr);
	}
	setTimeout("SaveUserFormClear('txtform"+idform+"_name','txtform"+idform+"_email','txtform"+idform+"_subject','txtform"+idform+"_body','txtcaptcha"+idform+"')",500);
}
function ChaptchaValid(http_request) 
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			captchaMsg = http_request.responseText;		
		} 
		else {}
	}
}
function SaveUserFormMsg(msg)
{
	if(captchaMsg != "")
		alert(captchaMsg);
	else
		alert(msg);
}
function SaveUserFormClear(name,email,subject,body,captcha)
{
	if(captchaMsg == "")
	{
		document.getElementById(name).value = "";
		document.getElementById(email).value = "";
		document.getElementById(subject).value = "";
		document.getElementById(body).value = "";		
		captcha = document.getElementById(captcha);
		if(captcha != null)
			captcha.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;}
}
function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}
function ShowCtrDetails(ctrlID)
{
	var obj = document.getElementById(ctrlID);
	if(obj!=null && obj.style.display=="none"){obj.style.display="block";}else{obj.style.display="none";}	
}

