function zaznacz_obrazek(ktora_cecha,ktory){
		
	obj=document.getElementsByTagName('div');
	for(i=0;i<obj.length;i++){
		
		if(obj[i].id.substring(0,4)=='img_'){
				var tmp= ktora_cecha+'_'+ktory;
				
			
				if(tmp==obj[i].id.substring(4)){
					
					obj[i].style.border='1px solid black'
				} else {
					if(ktora_cecha==obj[i].id.substring(4,5))
						obj[i].style.border='1px solid white';
				}
			}
	}
	
	
}
function populate(mitems,next,o,name,prices){	
	d=document.getElementById(next);

	if(!d){return;}

	d.options.length=0;
	
	cur=mitems[o.options[o.selectedIndex].value];

	if(!cur){
		d.options.length = 1;
		d.options[0].text='wybierz '+name;
		d.options[0].value=0;
	} else {
	
		d.options.length=cur.length;
		for(var i=0;i<cur.length;i++){
			if(i>0) d.options[i].text=cur[i].text+' '+prices[o.options[o.selectedIndex].value][i];
			else d.options[i].text=cur[i].text;
			d.options[i].value=cur[i].value;
		}
	}
	d.selectedIndex=0;
}

function zmien(fform) {
	if(fform.adres_inny.checked == true) {
			fform['dane_klient[firma_wys]'].className='input_normal';
			fform['dane_klient[imie_wys]'].className='input_normal';
			fform['dane_klient[nazwisko_wys]'].className='input_normal';
			fform['dane_klient[adres_wys]'].className='input_normal';
			fform['dane_klient[miejscowosc_wys]'].className='input_normal';
			fform['dane_klient[kod_poczt_wys]'].className='input_normal';
			fform['dane_klient[kraj_wys]'].className='input_normal';

			fform['dane_klient[firma_wys]'].disabled = false;
			fform['dane_klient[imie_wys]'].disabled = false;
			fform['dane_klient[nazwisko_wys]'].disabled = false;
			fform['dane_klient[adres_wys]'].disabled = false;
			fform['dane_klient[miejscowosc_wys]'].disabled = false;
			fform['dane_klient[kod_poczt_wys]'].disabled = false;
			fform['dane_klient[kraj_wys]'].disabled = false;
	} else {
			fform['dane_klient[firma_wys]'].className='input_disabled';
			fform['dane_klient[imie_wys]'].className='input_disabled';
			fform['dane_klient[nazwisko_wys]'].className='input_disabled';
			fform['dane_klient[adres_wys]'].className='input_disabled';
			fform['dane_klient[miejscowosc_wys]'].className='input_disabled';
			fform['dane_klient[kod_poczt_wys]'].className='input_disabled';
			fform['dane_klient[kraj_wys]'].className='input_disabled';

			fform['dane_klient[firma_wys]'].disabled = true;
			fform['dane_klient[imie_wys]'].disabled = true;
			fform['dane_klient[nazwisko_wys]'].disabled = true;
			fform['dane_klient[adres_wys]'].disabled = true;
			fform['dane_klient[miejscowosc_wys]'].disabled = true;
			fform['dane_klient[kod_poczt_wys]'].disabled = true;
			fform['dane_klient[kraj_wys]'].disabled = true;

			wpisuj(fform);

	}
	return true;
}

function checkEmailAdres(field)
{
		var good = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.biz)|(\.info)|(\..{2,2}))$)\b/gi);
		if (good)
		{
				return true  ;
		} else
		{
				field.focus() ;
				field.select() ;
				alert('Prosimy podać poprawny adres e-mail.');
				return false ;
		}

}

function check_order(fform) {
	if(!check_client(fform)) return false;
	if(!check_regulation(fform)) return false;
	return true;
}

function check_register(fform){
	if(!check_client(fform)) return false;
	if(!check_pass(fform)) return false;
	if(!check_regulation(fform)) return false;
	return true;
}
function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
	  for (var i=0; i<buttonGroup.length; i++) {
		 if (buttonGroup[i].checked) {
			return i+1;
		 }
	  }
   } else {
	  if (buttonGroup.checked) { return 1; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return 0;
}

function check_client(fform) {
		if(!/^[\S ]{3,}$/i.test(fform['dane_klient[imie]'].value)) { alert('Prosimy podać swoje imię.'); fform['dane_klient[imie]'].focus(); return false; }
		if(!/^[\S -]{3,}$/i.test(fform['dane_klient[nazwisko]'].value)) { alert('Prosimy podać swoje nazwisko.'); fform['dane_klient[nazwisko]'].focus(); return false; }
		if(fform['dane_klient[adres]'].value.length<3) { alert('Prosimy podać swój adres zamieszkania.'); fform['dane_klient[adres]'].focus(); return false; }
		else if(!/^.+[0-9]+.*$/i.test(fform['dane_klient[adres]'].value)){ alert('W adresie brakuje numeru domu, prosimy uzupełnić.'); fform['dane_klient[adres]'].focus(); return false; }
		if(fform['dane_klient[kod_poczt]'].value.length<3) { alert('Prosimy podać kod pocztowy.'); fform['dane_klient[kod_poczt]'].focus(); return false; }
		if(fform['dane_klient[miejscowosc]'].value.length<3) { alert('Prosimy podać miejscowość zamieszkania.'); fform['dane_klient[miejscowosc]'].focus(); return false; }

		if (fform.adres_inny.value=='on' || fform.adres_inny.checked) {
			if(fform['dane_klient[imie_wys]'].value.length<3) { alert('Prosimy podać imię (adres do wysyłki).'); fform['dane_klient[imie_wys]'].focus(); return false; }
			if(!/^[\S -]{3,}$/i.test(fform['dane_klient[nazwisko_wys]'].value)) { alert('Prosimy podać nazwisko (adres do wysyłki).'); fform['dane_klient[nazwisko_wys]'].focus(); return false; }
			if(fform['dane_klient[adres_wys]'].value.length<3) { alert('Prosimy podać swój adres zamieszkania(adres do wysyłki).'); fform['dane_klient[adres]'].focus(); return false; }
			else if(!/^.+[0-9]+.*$/i.test(fform['dane_klient[adres_wys]'].value)){ alert('W adresie brakuje numeru domu, prosimy uzupełnić(adres do wysyłki).'); fform['dane_klient[adres]'].focus(); return false; }
			if(fform['dane_klient[kod_poczt_wys]'].value.length<3) { alert('Prosimy podać kod pocztowy (adres do wysyłki).'); fform['dane_klient[kod_poczt_wys]'].focus(); return false; }
			if (fform['dane_klient[miejscowosc_wys]'].value.length<3) { alert('Prosimy podać miejscowość (adres do wysyłki).'); fform['dane_klient[miejscowosc_wys]'].focus(); return false; }
		}
		if(checkEmailAdres(fform['dane_klient[email]'])==false) return false;
		if(!/^[0-9-() ]{5,}$/i.test(fform['dane_klient[telefon]'].value)) { alert('Prosimy podać swój telefon.'); fform['dane_klient[telefon]'].focus(); return false; }

		return true;
}


function check_pass(fform){
		if (fform['dane_klient[uzytkownik]'].value.length<1) { alert('Użytkownik o tej nazwie użytkownika już istnieje!'); fform['dane_klient[uzytkownik]'].focus(); return false; }
		if (fform['dane_klient[haslo]'].value.length<3) { alert('Nie wpisano hasła użytkownika, bądź jest za krótkie!'); fform['dane_klient[haslo]'].focus(); return false; }
		if (fform.haslo_2.value!=fform['dane_klient[haslo]'].value) { alert('Podano dwa różne hasła.'); fform.haslo_2.focus(); return false; }
		
		return true;

}
function check_regulation(fform){
	if (fform.rules.checked==false) { alert('Prosimy zaznaczyć opcję "Zapoznałem się z regulaminem sklepu"'); return false; }
	return true;
}


function wpisuj(fform){
	if(fform.adres_inny.checked==false){
		fform['dane_klient[firma_wys]'].value=fform['dane_klient[firma]'].value;
		fform['dane_klient[imie_wys]'].value=fform['dane_klient[imie]'].value;
		fform['dane_klient[nazwisko_wys]'].value=fform['dane_klient[nazwisko]'].value;
		fform['dane_klient[adres_wys]'].value=fform['dane_klient[adres]'].value;
		fform['dane_klient[miejscowosc_wys]'].value=fform['dane_klient[miejscowosc]'].value;
		fform['dane_klient[kod_poczt_wys]'].value=fform['dane_klient[kod_poczt]'].value;
		fform['dane_klient[kraj_wys]'].value=fform['dane_klient[kraj]'].value;
	}
	return true;
}


function number_format(a, b, c, d) {
// number_format(number, decimals, comma, formatSeparator)
a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
e = a + '';
f = e.split('.');
if(!f[0]) f[0] = '0';
if(!f[1]) f[1] = '';
if(f[1].length < b){
	g = f[1];
	for(i = f[1].length + 1; i <= b; i++) {
		g += '0';
	}
	f[1] = g;
}
if(d != '' && f[0].length > 3) {
	h = f[0];
	f[0] = '';
	for(j = 3; j < h.length; j += 3) {
		i = h.slice(h.length - j, h.length - j + 3);
		f[0] = d + i +  f[0] + '';
	}
	j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
	f[0] = j + f[0];
}
c = (b <= 0) ? '': c;
return f[0] + c + f[1];
}

function show_element(id) {
 if (document.getElementById(id))
	document.getElementById(id).style.display='block';
}

function hide_element(id) {
if (document.getElementById(id))
	document.getElementById(id).style.display='none';
}

function bookmark_change(id) {
	hide_element('bm_g');
	hide_element('bm_ba');
	hide_element('bm_c');
	show_element(id);
	
	document.getElementById('bm_g_l').className='bm_off_l';
	document.getElementById('bm_g_m').className='bm_off_m';
	document.getElementById('bm_g_r').className='bm_off_r';
	
	document.getElementById('bm_ba_l').className='bm_off_l';
	document.getElementById('bm_ba_m').className='bm_off_m';
	document.getElementById('bm_ba_r').className='bm_off_r';

	document.getElementById('bm_c_l').className='bm_off_l';
	document.getElementById('bm_c_m').className='bm_off_m';
	document.getElementById('bm_c_r').className='bm_off_r';
	
	document.getElementById(id+'_l').className='bm_on_l';
	document.getElementById(id+'_m').className='bm_on_m';
	document.getElementById(id+'_r').className='bm_on_r';
}

function chClass(id,nclass)
{
	var item = document.getElementById(id);
	if(item)
	item.className=nclass ;
}