function aig_raty_kalkulator(b,k)
{

var win = window.open('about:blank', 'nowe_okno','width=850,height=890,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
win.document.write('<form action="http://www.aigcredit.pl/kalkulator/index.php" method=post>') ;
win.document.write('Wczytywanie...') ;
win.document.write('<input type=hidden name="partnerId" value="'+k+'">') ;
win.document.write('<input type=hidden name="cena" value="'+b+'">') ;
win.document.write('</form>') ;
win.document.write('<sc'+'ript>document.forms[0].submit()</sc'+'ript>') ;
}
/*function aig_raty_kalkulator(b,k)
  {
  if(document.getElementById("_x_raty_aig_form"))
    {
    document.getElementById("_x_raty_aig_form").submit() ;
    }else{

    var win = window.open('about:blank', 'nowe_okno','width=800,height=600,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
    var f = win.document.createElement('form') ;
    f.method="post";
    f.action="http://www.aigcredit.pl/kalkulator/index.php" ;
    f.target="_blank";
    f.id="_x_raty_aig_form" ;
    var i1 = document.createElement('input');
    i1.name="partnerId"
    i1.value=k ;
    i1.type="hidden" ;
    f.appendChild(i1);
    var i2 = document.createElement('input');
    i2.name="cena"
    i2.value=b ;
    i2.type="hidden" ;
    f.appendChild(i2);
    win.document.body.appendChild(f) ;
    f.submit() ;
    }
  }
*/
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


// ------------------------------------

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)|(\..{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 bookmark2(id){
	document.getElementById('bm2_1d').style.display='none';
	document.getElementById('bm2_2d').style.display='none';
	document.getElementById('bm2_3d').style.display='none';
	
	document.getElementById('bm2_'+id+'d').style.display='block';
	
	document.getElementById('bm2_1a').style.background='none';
	document.getElementById('bm2_1b').style.background='none';
	document.getElementById('bm2_1b').style.color='#404040';
	document.getElementById('bm2_1c').style.background='none';
	document.getElementById('bm2_2a').style.background='none';
	document.getElementById('bm2_2b').style.background='none';
	document.getElementById('bm2_2b').style.color='#404040';
	document.getElementById('bm2_2c').style.background='none';
	document.getElementById('bm2_3a').style.background='none';
	document.getElementById('bm2_3b').style.background='none';
	document.getElementById('bm2_3b').style.color='#404040';
	document.getElementById('bm2_3c').style.background='none';
	
	document.getElementById('bm2_'+id+'a').style.backgroundImage='url(themes/theme1/img/s_62.jpg)';
	document.getElementById('bm2_'+id+'b').style.backgroundImage='url(themes/theme1/img/s_64.jpg)';
	document.getElementById('bm2_'+id+'c').style.backgroundImage='url(themes/theme1/img/s_66.jpg)';
	document.getElementById('bm2_'+id+'b').style.color='#73ae00';
}

function email_login(fform) {
    if(fform['dane_klient[uzytkownik]']!=undefined)
        fform['dane_klient[uzytkownik]'].value = fform['dane_klient[email]'].value;
}