function czy_liczba(co) {
// funkcja sprawdza, czy podany argument jest liczba (sprawdza, czy jest przecinek lub kropka)
	poz1 = co.indexOf(",");
	poz2 = co.lastIndexOf(",");
	if (poz1==poz2) { //sprawdzamy czy wystepuje tylko 1 przecinek (lub 0)
		if (poz1!=-1) {  //jezeli jest przecinek
			var tmp=co.split(",");
			co=tmp[0]+"."+tmp[1];
		}
		if (!isNaN(co)) return true;
		else return false;
 	} else return false;
}

function zamien_na_kropke2(co) {
// funkcja zamienia ewentualny przecinek w liczbie na kropke
	var str = co.value;
	poz1 = str.indexOf(",");
	poz2 = str.lastIndexOf(",");
	if (poz1==poz2) { //sprawdzamy czy wystepuje tylko 1 przecinek (lub 0)
		if (poz1!=-1) {  //jezeli jest przecinek
			var tmp=str.split(",");
			str=tmp[0]+"."+tmp[1];
		}
 	};
 	//self.document.all[co].value=str;
	return str;
}

function zamien_na_kropke(co) {
// funkcja zamienia ewentualny przecinek w liczbie na kropke
	var str = document.getElementById(co).value;
	poz1 = str.indexOf(",");
	poz2 = str.lastIndexOf(",");
	if (poz1==poz2) { //sprawdzamy czy wystepuje tylko 1 przecinek (lub 0)
		if (poz1!=-1) {  //jezeli jest przecinek
			var tmp=str.split(",");
			str=tmp[0]+"."+tmp[1];
		}
 	};
 	return str;
}

function roundf(liczba, po_przecinku) {
  if (po_przecinku>0) {
    mnoznik=Math.pow(10,po_przecinku);
  	liczba=liczba*mnoznik;
  	liczba=Math.round(liczba);
  	liczba=liczba/mnoznik;
  	return(liczba);
  } else {
    return(Math.round(liczba));
  }
}


NS=(document.layers)?true:false;
IE=(document.all)?true:false;

 if(NS){ window.captureEvents(Event.KEYDOWN);
       window.onkeydown=onKeyDown; }

function key_down(e) {
     var keycode;
     keycode = (NS)? e:event.keyCode;
     if(keycode!=13) { return false; } else { return true; }
}


function iniciuj()
{
	Custom.init();
}

function filtruj(gdzie)
{
    document.location.href=gdzie+',c,'+document.getElementById('cena').value+',r,'+document.getElementById('rozmiar').value+',k,'+document.getElementById('kolor').value
}

function QSObject(querystring){ 
    //Create regular expression object to retrieve the qs part 
    var qsReg = new RegExp("[?][^#]*","i"); 
    hRef = unescape(querystring); 
    var qsMatch = hRef.match(qsReg); 
 
    //removes the question mark from the url 
    qsMatch = new String(qsMatch); 
    qsMatch = qsMatch.substr(1, qsMatch.length -1); 
 
    //split it up 
    var rootArr = qsMatch.split("&"); 
    for(i=0;i<rootArr.length;i++){ 
        var tempArr = rootArr[i].split("="); 
        if(tempArr.length ==2){ 
            tempArr[0] = unescape(tempArr[0]); 
            tempArr[1] = unescape(tempArr[1]); 
 
            this[tempArr[0]]= tempArr[1]; 
        } 
    } 
} 

function init()
{
	optionTest = true;
	lgth = document.getElementById('k').options.length;
	document.getElementById('k').options[lgth] = null;
	if (document.getElementById('k').options[lgth]) optionTest = false;
	populate();
}

function populate()
{
	if (!optionTest) return;
	var box = document.getElementById('k');
	var number = box.selectedIndex+1;
	if (!number) return;
	var list = tabKol[number];
	var box2 = document.getElementById('r');
	stary = box2.value;
	staryIndex = 0;
	
	box2.options.length = 0;
	for(i=0;i<list.length;i+=2)
	{
		box2.options[i/2] = new Option(list[i],list[i+1]);
		if (list[i+1]==stary) { staryIndex = i/2; }
	}
	
	if (stary!="" && staryIndex>1) {
		box2.selectedIndex = staryIndex;
	} else { 
		box2.selectedIndex = 0;
	}
}

function zapal(co,ie6sux){
zgas();
document.getElementById(co).style.display='block';
document.getElementById(co+'_tab').style.background='url(/images/katalog/produkt_menu_off.jpg) 100% 0px';
}

function zgas()
{
    document.getElementById('polec').style.display='none';
    document.getElementById('polecamy').style.display='none';
    document.getElementById('opinie').style.display='none';
    document.getElementById('opinia').style.display='none';
    
    document.getElementById('polec_tab').style.background='url(/images/katalog/produkt_menu_on.jpg)';
    document.getElementById('polecamy_tab').style.background='url(/images/katalog/produkt_menu_on.jpg)';
    document.getElementById('opinie_tab').style.background='url(/images/katalog/produkt_menu_on.jpg)';
    document.getElementById('opinia_tab').style.background='url(/images/katalog/produkt_menu_on.jpg)';
}

function pokaz_faq(co,ile)
{
    for (i=1;i<=ile;i++)
    {
	document.getElementById('faq'+i).style.display='none'
    }
    document.getElementById('faq'+co).style.display='block'
}

function zapal2(co){
    if(document.getElementById(co).style.display=='block'){document.getElementById(co).style.display='none'}else{document.getElementById(co).style.display='block'}
}

function sprawdz_ilosc(co,ile_max)
{	
    var ilosc=roundf(parseInt(document.getElementById(co).value));
    if((isNaN(ilosc))||(ilosc<=0)){
	alert ("Podaj poprawną wartość większą od zera");
	document.getElementById(co).value='1';
    }
    else
    {
    	if(ilosc>ile_max)
    	{
    	    alert ("Dostepna ilość towaru to: "+ile_max);
    	    document.getElementById(co).value=ile_max;
    	}
    	else
    	{
	    document.getElementById(co).value=ilosc;
	}	
    }
}

function change_col(col)
{
    document.getElementById('id_wyb_kolekcji').selectedIndex=col
    document.getElementById('kolform').submit();
}

function erase()
{
    
}

function swapimg(co)
{
    document.getElementById('mainfoto').src=co
    document.getElementById('mainfoto_link').href=co.replace("med","big");
    document.getElementById('mainfoto_link2').href=co.replace("med","big");
    Shadowbox.init();
}

function zmien_klase(jaki)
{
    document.getElementById('klasa').value=jaki;
    document.getElementById('klasa_form').submit();
    //document.getElementById('produkty').className=jaki;
}

function pisz_mail(konto, serwer,klasa)
{
    adres=(konto+'@'+serwer)
    document.write('<A href=\"mailto:' + adres + '\" class=\"'+ klasa +'\">' + adres + '</a>')
}
