function show_row(pytid,zal){ 
	if(document.getElementById('odp['+pytid+']') != null){
		if(document.getElementById('odp['+pytid+']').checked){
			if(document.getElementById(zal) != null){coreDisplay(zal,'on');} 
		} else {
			if ((document.getElementById(zal) != null)){
				coreDisplay(zal,'off');
				document.getElementById('odp['+zal+']').value = '';
			}
		} 
	}      
}
function show_row_child_combo(zbior,pytid){   
	var pytid_arr = zbior.split("-");
	if(document.getElementById(pytid) != null){
		if(document.getElementById('odp['+pytid+']').value != pytid_arr[0]){coreDisplay(pytid_arr[1],'on');
		}else{
			for(i=1;i<pytid_arr.length; i++){
				if (document.getElementById(pytid_arr[i]) != null){coreDisplay(pytid_arr[i],'off');}
			}
		}
	}
}
function show_rows_child_combo(zbior,pytid){    
	var pytid_arr = zbior.split("-");
	if(document.getElementById(pytid) != null){
		if(document.getElementById('odp['+pytid+']').value != pytid_arr[0]){
			for(j=1;j<pytid_arr.length; j++){
				if (document.getElementById(pytid_arr[j]) != null){coreDisplay(pytid_arr[j],'on');}
			}
			coreDisplay(pytid_arr[1],'on'); 
		}
		else {
			for(i=1;i<pytid_arr.length; i++){
				if (document.getElementById(pytid_arr[i]) != null){coreDisplay(pytid_arr[i],'off');}
			}
		}
	}
}
function show_row_child_check(zbior,pytid){ 
	var pytid_arr = zbior.split("-");   
	if(document.getElementById(pytid) != null){
		if(document.getElementById('odp['+pytid+']').checked){
			document.getElementById(pytid_arr[1]).style.display = ''; 
		} else {
			for(i=1;i<pytid_arr.length; i++){
				if (document.getElementById(pytid_arr[i]) != null){
					document.getElementById(pytid_arr[i]).style.display = 'none';
					document.getElementById('odp['+pytid_arr[i]+']').value='';
				}
			}
		}
	}  
}
function show_rows(pytid,zbior){
	var pytid_arr = zbior.split("-"); 
	if(document.getElementById('odp['+pytid+']') != null){
		if(document.getElementById('odp['+pytid+']').checked){
			for(i=0;i<pytid_arr.length; i++){
				if(document.getElementById(pytid_arr[i]) != null){
					document.getElementById(pytid_arr[i]).style.display = '';
				}
			}
		} else {
			for(i=0;i<pytid_arr.length; i++){
				if(document.getElementById(pytid_arr[i]) != null){
					document.getElementById(pytid_arr[i]).style.display = 'none';
				}
			}
		}
	}
}
function show_row_young(pytid,zalpytid){ 
  if ((document.getElementById(pytid) != null)){
    var birthdate = document.getElementById(pytid).value;

    if(birthdate != '') {
      var birth_array = birthdate.split("-");
      var new_date = new Date();
      roznica = new_date.getYear() - birth_array[2];
      if(roznica > 24) {
        if ((document.getElementById(zalpytid) != null)){
          document.getElementById(zalpytid).style.display = 'none';
        }
      } else {
        if ((document.getElementById(zalpytid) != null)){
          document.getElementById(zalpytid).style.display = '';
        }
      }
    } else {
      if ((document.getElementById(zalpytid) != null)){
        document.getElementById(zalpytid).style.display = 'none';
      }
    }
  }
}
function copy_value(from, src) { 
  document.getElementById(src).value = from.value;
}	
function otworz(adres) {

	noweOkno = window.open(adres, 'pomoc', 'menubar=no, toolbar=no, location=no, scrollbars=yes, resizable=yes, status=no, width=300, height=300, left=80, top=150')
	noweOkno.focus()
}
function show_div(name){
	var divTabAll = new Array('zakres_ubezp','co_chronione','udzial_wlasny','wylaczenia','limity');
	var divTabHide = new Array();
	var k = 0;
	
	for(i=0; i<divTabAll.length; i++){
		if(divTabAll[i] != name){
			divTabHide[k] = divTabAll[i];
			k++;
		}
	}
	if(document.forms['radioForm'].selOptions.value != ''){
		if(document.getElementById(name) != null){
			if(document.getElementById(name).style.display == 'none') {
				document.getElementById(name).style.display = '';
				document.getElementById(name+'1').className = 'porownaj_td_header_on';
				document.getElementById(name+'2').className = 'porownaj_td_header_on';
				document.getElementById(name+'3').style.display = 'none';
				document.getElementById(name+'4').style.display = '';
				
				for(j=0; j<divTabHide.length; j++){
					if(document.getElementById(divTabHide[j]) != null){
						document.getElementById(divTabHide[j]).style.display = 'none';
						document.getElementById(divTabHide[j]+'1').className = 'porownaj_td_header_off';
						document.getElementById(divTabHide[j]+'2').className = 'porownaj_td_header_off';
						document.getElementById(divTabHide[j]+'3').style.display = '';
						document.getElementById(divTabHide[j]+'4').style.display = 'none';
					}
				}  
			} else {
				document.getElementById(name).style.display = 'none';
				document.getElementById(name+'1').className = 'porownaj_td_header_off';
				document.getElementById(name+'2').className = 'porownaj_td_header_off';
				document.getElementById(name+'3').style.display = '';
				document.getElementById(name+'4').style.display = 'none';
			}
		}
	}
	if(name == 'all'){
		for(k=0; k<divTabAll.length; k++){
			if(document.getElementById(divTabAll[k]) != null){
				document.getElementById(divTabAll[k]).style.display = 'none';
			}
			if(document.getElementById(divTabAll[k]+'1') != null){
				document.getElementById(divTabAll[k]+'1').className = 'porownaj_td_header_off';
			}
			if(document.getElementById(divTabAll[k]+'2') != null){
				document.getElementById(divTabAll[k]+'2').className = 'porownaj_td_header_off';
			}
			if(document.getElementById(divTabAll[k]+'3') != null){
				document.getElementById(divTabAll[k]+'3').style.display = '';
			}
			if(document.getElementById(divTabAll[k]+'4') != null){
				document.getElementById(divTabAll[k]+'4').style.display = 'none';
			}
		}
	}
}
function newline() {
  var total = document.getElementById("newline-wrapper").getElementsByTagName("div").length;
  if(!total || total > 10) {
    document.getElementById("newline").style.display = "none";
    return false;
  }
  var lb = document.getElementById("label-"+total);
  var ip = document.getElementById("date-"+total);
  var newlb = lb.cloneNode(true);
  newlb.id  = "label-"+(total + 1);
  var newip = ip.cloneNode(true);
  newip.id  = "date-"+(total + 1);
  newip.name  = "date-"+(total + 1);
  newip.value = "";

  if(newlb["htmlFor"]) {
    newlb["htmlFor"] = newlb["htmlFor"].replace(/[0-9]+/, total + 1);
  } else if(newlb.getAttribute("for")) {
    newlb.setAttribute("for", newlb.getAttribute("for").replace(/[0-9]+/, total + 1));
  }
  var newDiv = document.createElement('div');
  newDiv.appendChild(newlb);
  newDiv.appendChild(newip);
  document.getElementById("newline-wrapper").appendChild(newDiv);
  document.getElementById("date-"+ (total + 1)).focus();
  datePickerController.create();
  return false;       
}
function postcode(pytid,edind) {
  if (edind==1) {
  post = document.getElementById(pytid+'_1').value;
  if(post.length >= 2){
    document.getElementById(pytid+'_2').focus();
  }
  } else {// second ed
  	document.getElementById('odp['+pytid+']').value=document.getElementById(pytid+'_1').value+'-'+document.getElementById(pytid+'_2').value;
  }
  
}
function fi_os(id) {
  if(id == 'firma_1'){
    if(document.getElementById(id).checked){
      document.getElementById('dane_os_1').style.display = 'none';
      document.getElementById('dane_firma_1').style.display = '';
    } else {
      document.getElementById('dane_os_1').style.display = '';
      document.getElementById('dane_firma_1').style.display = 'none';
    }
  }

  if(id == 'firma_2'){
    if(document.getElementById(id).checked){
      document.getElementById('dane_os_2').style.display = 'none';
      document.getElementById('dane_firma_2').style.display = '';
    } else {
      document.getElementById('dane_os_2').style.display = '';
      document.getElementById('dane_firma_2').style.display = 'none';
    }
  }
}
function u2u() { 
  if(document.getElementById('ub_vendor').value == '1'){
    document.getElementById('dane_os_2').style.display = 'none';
    document.getElementById('dane_firma_2').style.display = 'none';
    document.getElementById('tr_hdr_ub2').style.display = 'none';
    document.getElementById('tr_firma_2').style.display = 'none';
    document.getElementById('ub_vendor_hd').value = '1';
  } 
  if(document.getElementById('ub_vendor').value == '2'){
    document.getElementById('dane_os_2').style.display = '';
    document.getElementById('dane_firma_2').style.display = 'none';
    document.getElementById('tr_hdr_ub2').style.display = '';
    document.getElementById('tr_firma_2').style.display = '';
    document.getElementById('ub_vendor_hd').value = '2';
	document.getElementById('data[imie_os1]').value = '';
	document.getElementById('data[pesel_os1]').value = '';
	document.getElementById('data[data_ur_os1]').value = '';
  }
}
function niptodate(id_1,id_2){
  var pesel = document.getElementById(id_1).value; 
  var data_ur= ''; 

  if(pesel != ''){
    document.getElementById(id_2).value='';
    data_ur = pesel.charAt(4)+pesel.charAt(5)+'-'+pesel.charAt(2)+pesel.charAt(3);
    if(pesel.charAt(0) == '0'){
      data_ur = data_ur+'-20'+pesel.charAt(0)+pesel.charAt(1);
    } else {
      data_ur = data_ur+'-19'+pesel.charAt(0)+pesel.charAt(1);
    }
    document.getElementById(id_2).value=data_ur;
  }
}
function hidePost(id1,id2){ 
  if(document.getElementById(id1).checked){
    document.getElementById(id2).style.display='';
  } else {
    document.getElementById(id2).style.display='none';
  }
}
function opis_show(fir){
  if(fir == '1'){
    document.getElementById('data[opis_f1]').value=opis[document.getElementById('data[pkd_f1]').selectedIndex];
  }
  if(fir == '2'){
    document.getElementById('data[opis_f2]').value=opis[document.getElementById('data[pkd_f2]').selectedIndex];
  }
}
function move_adres(koniec_from,koniec_to){
  if(document.getElementById('data['+koniec_to+']') != null){
    if(document.getElementById('data['+koniec_from+']') != null){
      document.getElementById('data['+koniec_to+']').value = document.getElementById('data['+koniec_from+']').value;
    }
  }
}
function move_adres2(koniec_from,koniec_to1,koniec_to2){
  if(document.getElementById('data['+koniec_to1+']') != null){
    if(document.getElementById('data['+koniec_from+']') != null){
      document.getElementById('data['+koniec_to1+']').value = document.getElementById('data['+koniec_from+']').value;
    }
  }
  if(document.getElementById('data['+koniec_to2+']') != null){
    if(document.getElementById('data['+koniec_from+']') != null){
      document.getElementById('data['+koniec_to2+']').value = document.getElementById('data['+koniec_from+']').value;
    }
  }
}
function only_one_checked(pytid){
  if(pytid == '270'){
    if(document.getElementById('odp[270]').checked){
      document.getElementById('odp[271]').checked = false;
    }
  }
  if(pytid == '271'){
    if(document.getElementById('odp[271]').checked){
      document.getElementById('odp[270]').checked = false;
    }
  }
  if(pytid == '327'){
    if(document.getElementById('odp[327]').checked){
      document.getElementById('odp[328]').checked = false;
    }
  }
  if(pytid == '328'){
    if(document.getElementById('odp[328]').checked){
      document.getElementById('odp[327]').checked = false;
    }
  }
  if(pytid == '332'){
    if(document.getElementById('odp[332]').checked){
      document.getElementById('odp[333]').checked = false;
    }
  }
  if(pytid == '333'){
    if(document.getElementById('odp[333]').checked){
      document.getElementById('odp[332]').checked = false;
    }
  }
  if(pytid == '62'){
    if(document.getElementById('odp[62]').checked){
      document.getElementById('odp[370]').checked = false;
    }
  }
  if(pytid == '370'){
    if(document.getElementById('odp[370]').checked){
      document.getElementById('odp[62]').checked = false;
    }
  }
}
function show_section(source,section){ 
  if(document.getElementById(source).checked){
    document.getElementById(section).style.display='';
  } else {
	document.getElementById(section).style.display='none';
  }
}
function show_section2(source,section,hid){ 
  if(document.getElementById(source).checked){
    document.getElementById(section).style.display='none';
	document.getElementById(hid).value='1';
  } else {
	document.getElementById(section).style.display='';
	document.getElementById(hid).value='0';
  }
}
function show_two_sections(source,section1,section2){ 
  if(document.getElementById(source).checked){
    document.getElementById(section1).style.display='';
	document.getElementById(section2).style.display='';
  } else {
	document.getElementById(section1).style.display='none';
	document.getElementById(section2).style.display='none';
  }
}
function kupuj() {
	
	var tmp_but = document.forms['radioForm'].but.value;
	var controlTab = tmp_but.split("_");
	var zestaw = 'raport'+controlTab[1];
	
	if(controlTab[0] == '1'){//1 rata
		document.forms[zestaw].skladka.value = document.forms[zestaw].suma1.value;
		document.forms[zestaw].rata.value = document.forms[zestaw].part1.value;
		document.forms[zestaw].ilosc_rat.value = 1;
	}
	if(controlTab[0] == '2'){//2 raty
		document.forms[zestaw].skladka.value = document.forms[zestaw].suma2.value;
		document.forms[zestaw].rata.value = document.forms[zestaw].part2.value;
		document.forms[zestaw].ilosc_rat.value = 2;
	}
	if(controlTab[0] == '3'){//4 raty
		document.forms[zestaw].skladka.value = document.forms[zestaw].suma3.value;
		document.forms[zestaw].rata.value = document.forms[zestaw].part3.value;
		document.forms[zestaw].ilosc_rat.value = 4;
	}
	
	document.forms[zestaw].submit();
}
function makePopup(identyfikator,pole,opcja,max_wart){
	if(opcja == '1'){
		var adres = 'popuptool.php?pyt_id='+pole+'&opcja='+opcja;
		if(document.getElementById('odp['+ pole +']').checked) {
			noweOkno = window.open(adres, 'pomoc', 'menubar=no, toolbar=no, location=no, scrollbars=yes, resizable=yes, status=no, width=800, height=450, left=80, top=150');
			noweOkno.focus();
		} else {
			if(pole == '319') {
				document.forms['formularz'].elements['odp[320]'].value = '';
			}
			if(pole == '324') {
				document.forms['formularz'].elements['odp[325]'].value = '';
			}
			if(pole == '371') {
				document.forms['formularz'].elements['odp[368]'].value = '';
			}
		} 
	}
	if(opcja == '2'){
		var adres2 = 'popuptool.php?pyt_id='+identyfikator+'&opcja='+opcja+'&max='+max_wart;
		if(document.getElementById(pole).checked) {
			noweOkno = window.open(adres2, 'pomoc', 'menubar=no, toolbar=no, location=no, scrollbars=yes, resizable=yes, status=no, width=800, height=450, left=80, top=150');
			noweOkno.focus();
		} else {
			document.forms['form1'].elements['popupTab2'].value = '';
		} 
	}
}
function processPopup(identyfikator, opcja, max_wart) {
	var call_back_function = "makeChange";
	var call_back_function = eval("window.opener." + call_back_function);
	var popContent = '';
	var popContent2 = '';
	var suma = 0;
	var suma2 = 0;
	
	if(opcja == '1'){
		for(i=1;i<9;i++){
			if(document.getElementById('cena'+i) != null){
				if(document.getElementById('cena'+i).value != ''){
					popContent = popContent + document.getElementById('nazwa'+i).value;
					popContent = popContent + '|##|';
					popContent = popContent + document.getElementById('cechy'+i).value;
					popContent = popContent + '|##|';
					popContent = popContent + document.getElementById('cena'+i).value;
					popContent = popContent + '|##|';
					popContent = popContent + document.getElementById('data'+i).value;
					popContent = popContent + '@@';
					suma = (suma)*1 + (document.getElementById('cena'+i).value)*1;
				}
			}
		}
	}
	if(opcja == '2'){
		var error1 = false;
		var error2 = false;
		
		for(i=1;i<9;i++){
			if(document.getElementById('cena'+i) != null){
				if(document.getElementById('cena'+i).value != ''){
					popContent2 = popContent2 + document.getElementById('nazwa'+i).value;
					popContent2 = popContent2 + '|##|';
					popContent2 = popContent2 + document.getElementById('marka'+i).value;
					popContent2 = popContent2 + '|##|';
					popContent2 = popContent2 + document.getElementById('cechy'+i).value;
					popContent2 = popContent2 + '|##|';
					popContent2 = popContent2 + document.getElementById('cena'+i).value;
					popContent2 = popContent2 + '|##|';
					popContent2 = popContent2 + document.getElementById('data'+i).value;
					if(document.getElementById('cena'+i).value < 2000){
						error1 = true;
					}
					popContent2 = popContent2 + '@@';
					suma2 = (suma2)*1 + (document.getElementById('cena'+i).value)*1;
				}
			}
		}
		if(suma2>max_wart){
			error2 = true;
		}
	}
	
	if(opcja == '1'){
		call_back_function(suma, popContent, identyfikator, opcja);
		window.close();
	}
	if(opcja == '2'){
		if(error1 == true){
			alert('Wszystkie pozycje muszą mieć wartość min 2000 zł');
		} else if(error2 == true){
			alert('Suma wszystkich pozycji przekracza podaną wcześniej wartość wyposażenia.');
		} else {
			call_back_function(suma2, popContent2, identyfikator, opcja);
			window.close();
		}
	}
}
function makeChange(suma, popContent, identyfikator, opcja){

	if(opcja == '1'){
		if(identyfikator == '319'){
			window.document.forms['formularz'].elements['odp[320]'].value = suma;
		}
		if(identyfikator == '324'){
			window.document.forms['formularz'].elements['odp[325]'].value = suma;
		}
		if(identyfikator == '371'){
			window.document.forms['formularz'].elements['odp[368]'].value = suma;
		}
		window.document.forms['formularz'].elements['popupTab'].value = popContent;
	}
	if(opcja == '2'){
		window.document.forms['form1'].elements['popupTab2'].value = popContent;
	}
}
function roof(pytid){

	if (document.getElementById('odp['+ pytid +']').selectedIndex == '8' || document.getElementById('odp['+ pytid +']').selectedIndex == '9') {
		document.getElementById('329').style.display='';
	} else {
		document.getElementById('329').style.display='none';
		document.getElementById('337').style.display='none';
		document.getElementById('338').style.display='none';
	}	
}
function roof2(){
	if(document.getElementById('odp[329]').selectedIndex == '2' || document.getElementById('odp[329]').selectedIndex == '3'){
		document.getElementById('337').style.display='';
		document.getElementById('338').style.display='';
	} else {
		document.getElementById('337').style.display='none';
		document.getElementById('338').style.display='none';
	}
}
function calcBis(skladkaStart,nRaty) {

	var mainStawka = skladkaStart;
	var check = false;
	
	if(document.getElementById('ch1').checked){
		var suma1 = document.getElementById('sum1').value;
		var skl1 = Math.round(suma1*0.06);
		document.getElementById('skl1').value = skl1;
		mainStawka = Math.round(mainStawka*1 + skl1*1);
		check = true;
	} else {
		document.getElementById('skl1').value = '';
	}
	
	if(document.getElementById('ch2').checked){
		var suma2 = document.getElementById('sum2').value;
		var skl2 = Math.round(suma2*0.08);
		document.getElementById('skl2').value = skl2;
		mainStawka = Math.round(mainStawka*1 + skl2*1);
		check = true;
	} else {
		document.getElementById('skl2').value = '';
	}
	
	if(document.getElementById('ch3').checked){
		if (document.getElementById('lzw').value == '')
			document.getElementById('lzw').value = 1;
		var suma_zw = document.getElementById('lzw').value;
		var skl3 = Math.round(suma_zw*45);
		document.getElementById('skl3').value = skl3;
		mainStawka = Math.round(mainStawka*1 + skl3*1);
		check = true;
	} else {
		document.getElementById('skl3').value = '';
	}
	
	if(document.getElementById('ch4').checked){
		var skl4 = 30;
		document.getElementById('skl4').value = skl4;
		mainStawka = Math.round(mainStawka*1 + skl4*1);
		check = true;
	} else {
		document.getElementById('skl4').value = '';
	}
	
	if(document.getElementById('ch5').checked){
		var suma5 = document.getElementById('sum5').value;
		var skl5 = Math.round(suma5*0.0011);
		document.getElementById('skl5').value = skl5;
		document.getElementById('ch6').checked = false;
		document.getElementById('skl6').value = '';
		mainStawka = Math.round(mainStawka*1 + skl5*1);
		check = true;
	} else {
		document.getElementById('skl5').value = '';
	}
	
	if(document.getElementById('ch6').checked){
		var suma6 = document.getElementById('sum6').value;
		var skl6 = Math.round(suma6*0.0014);
		document.getElementById('skl6').value = skl6;
		document.getElementById('ch5').checked = false;
		document.getElementById('skl5').value = '';
		mainStawka = Math.round(mainStawka*1 + skl6*1);
		check = true;
	} else {
		document.getElementById('skl6').value = '';
	}
	
	if(check == true){
		if(nRaty == '1' || nRaty == ''){
			document.getElementById('r11').value = mainStawka;
		}
		if(nRaty == '2'){
			document.getElementById('r21').value = Math.round((mainStawka*1.05)*1/2);
			document.getElementById('r22').value = Math.round((mainStawka*1.05)*1/2);
			mainStawka = Math.round(mainStawka*1.05);
		}
		if(nRaty == '4'){
			document.getElementById('r41').value = Math.round((mainStawka*1.1)*1/4);
			document.getElementById('r42').value = Math.round((mainStawka*1.1)*1/4);
			document.getElementById('r43').value = Math.round((mainStawka*1.1)*1/4);
			document.getElementById('r44').value = Math.round((mainStawka*1.1)*1/4);
			mainStawka = Math.round(mainStawka*1.1);
		}
	}
	
	document.getElementById('skladka').value = mainStawka;
}
function only_four_checked(wariant, prods){
	
	var grey = new Array();
	var counter = 0;
	var count_grey = 0;
	
	if(document.getElementById(wariant).checked){
		for(i=1;i<prods+1;i++){
			if(document.getElementById('war'+i) != null){
				if(document.getElementById('war'+i).checked){
					counter++;
				} else {
					grey[count_grey] = i;
					count_grey++;
				}
			}
		}
		
		if(counter == 4){
			for(j=0;j<grey.length;j++){
				if(document.getElementById('war'+grey[j]) != null){
					document.getElementById('war'+grey[j]).disabled = true;
				}
			}
		}
	} else {
		for(k=1;k<prods+1;k++){
			if(document.getElementById('war'+k) != null){
				if(document.getElementById('war'+k).checked){
					counter++;
				}
			}
		}		
		if(counter < 4){
			for(l=1;l<prods+1;l++){
				if(document.getElementById('war'+l) != null){
					if(document.getElementById('war'+l).disabled){
						document.getElementById('war'+l).disabled = false;
					}
				}
			}
		}
	}
}
function compare(prods,option) {
	var countGroup1 = 0;
	var countGroup2 = 0;
	var countGroup3 = 0;
	var countGroup4 = 0;
	var onTab = new Array();
	var counter = 0;
	var selected = document.forms['radioForm'].selOptions.value;
	var selectedTab = selected.split("-");
	var newSelected = "";
	var selectedRata = document.forms['radioForm'].but.value;
	var SelectedRataTab = selectedRata.split("_");
	var isSelected = false;
	
	show_div('all');
	
	for(i=1;i<=prods;i++){
		//if(document.getElementById('war'+i) != null){
			if(document.getElementById('war'+i) != null && document.getElementById('war'+i).checked){
				isSelected = true;
				onTab[counter] = i;
				counter++;
				if(option == 't') {
					if(i == 1 || i == 2 || i == 3){ countGroup1++;}
					if(i == 4 || i == 5){ countGroup2++;}
					if(i == 6 || i == 7){ countGroup3++;}
				}
				if(option == 'm') {
					if(i == 1 || i == 2){ countGroup1++;}
					if(i == 3 || i == 4){ countGroup2++;}
					if(i == 5 || i == 6 || i == 7){ countGroup3++;}
					if(i == 8 || i == 9 || i == 10){ countGroup4++;}
				}
			
				var exists = false;
				for(p=0; p<selectedTab.length; p++){
					if(selectedTab[p] == i){
						exists = true;
					}
				}
				if(exists == false){
					for(c=1;c<200;c++){
						if(document.getElementById('wariant'+i+'-'+c) != null){
							document.getElementById('wariant'+i+'-'+c).style.display='';
						}	
					}
					if(document.getElementById('rata'+SelectedRataTab[0]+'_'+i) != null){
						document.getElementById('rata'+SelectedRataTab[0]+'_'+i).style.display='';	
					}
				}
			
			} else {
				for(j=1;j<200;j++){
					if(document.getElementById('wariant'+i+'-'+j) != null){
						document.getElementById('wariant'+i+'-'+j).style.display='none';
					}	
				}
				for(z=1;z<4;z++){
					if(document.getElementById('rata'+z+'_'+i) != null){
						document.getElementById('rata'+z+'_'+i).style.display='none';
					}		
				}
			}
		//}
	}
	if(isSelected == true){
		changeCompare('1');
	if(onTab.length == 1){
		widthCell = 540;
		if(countGroup1 == 1) {widthCell1 = 540;}
		if(countGroup2 == 1) {widthCell2 = 540;}
		if(countGroup3 == 1) {widthCell3 = 540;}
		if(countGroup4 == 1) {widthCell4 = 540;}
	}
	if(onTab.length == 2){
		widthCell = 270;
		if(countGroup1 == 1) {widthCell1 = 270;}
		if(countGroup1 == 2) {widthCell1 = 543;}
		if(countGroup2 == 1) {widthCell2 = 270;}
		if(countGroup2 == 2) {widthCell2 = 543;}
		if(countGroup3 == 1) {widthCell3 = 270;}
		if(countGroup3 == 2) {widthCell3 = 543;}
		if(countGroup4 == 1) {widthCell4 = 270;}
		if(countGroup4 == 2) {widthCell4 = 543;}
	}
	if(onTab.length == 3){
		widthCell = 180;
		if(countGroup1 == 1) {widthCell1 = 180;}
		if(countGroup1 == 2) {widthCell1 = 363;}
		if(countGroup1 == 3) {widthCell1 = 546;}
		if(countGroup2 == 1) {widthCell2 = 180;}
		if(countGroup2 == 2) {widthCell2 = 363;}
		if(countGroup2 == 3) {widthCell2 = 546;}
		if(countGroup3 == 1) {widthCell3 = 180;}
		if(countGroup3 == 2) {widthCell3 = 363;}
		if(countGroup3 == 3) {widthCell3 = 546;}
		if(countGroup4 == 1) {widthCell4 = 180;}
		if(countGroup4 == 2) {widthCell4 = 363;}
		if(countGroup4 == 3) {widthCell4 = 546;}
	}
	if(onTab.length == 4){
		widthCell = 135;
		if(countGroup1 == 1) {widthCell1 = 135;}
		if(countGroup1 == 2) {widthCell1 = 273;}
		if(countGroup1 == 3) {widthCell1 = 411;}
		if(countGroup1 == 4) {widthCell1 = 549;}
		if(countGroup2 == 1) {widthCell2 = 135;}
		if(countGroup2 == 2) {widthCell2 = 273;}
		if(countGroup2 == 3) {widthCell2 = 411;}
		if(countGroup2 == 4) {widthCell2 = 549;}
		if(countGroup3 == 1) {widthCell3 = 135;}
		if(countGroup3 == 2) {widthCell3 = 273;}
		if(countGroup3 == 3) {widthCell3 = 411;}
		if(countGroup3 == 4) {widthCell3 = 549;}
		if(countGroup4 == 1) {widthCell4 = 135;}
		if(countGroup4 == 2) {widthCell4 = 273;}
		if(countGroup4 == 3) {widthCell4 = 411;}
		if(countGroup4 == 4) {widthCell4 = 549;}
	}
	for(h=0; h<onTab.length; h++){
		for(g=1;g<200;g++){
			if(document.getElementById('wariant'+onTab[h]+'-'+g) != null){
				document.getElementById('wariant'+onTab[h]+'-'+g).width=widthCell;
			}
		}
		for(q=1; q<4; q++){
			if(document.getElementById('rata'+q+'_'+onTab[h]) != null){
				document.getElementById('rata'+q+'_'+onTab[h]).width=widthCell;
			}
				
		}
	}
	
	var t;
	var j;
	if(countGroup1 == 0){
		for(j=1;j<200;j++){
			if(document.getElementById('wariantX1-'+j) != null){
				document.getElementById('wariantX1-'+j).style.display='none';
			}
				
		}
	} else {
		for(t=1;t<200;t++){
			if(document.getElementById('wariantX1-'+t) != null){
				document.getElementById('wariantX1-'+t).style.display='';
				document.getElementById('wariantX1-'+t).width=widthCell1;
			}
				
		}
	}
	if(countGroup2 == 0){
		for(j=1;j<200;j++){
			if(document.getElementById('wariantX2-'+j) != null){
				document.getElementById('wariantX2-'+j).style.display='none';
			}
				
		}
	} else {
		for(t=1;t<200;t++){
			if(document.getElementById('wariantX2-'+t) != null){
				document.getElementById('wariantX2-'+t).style.display='';
				document.getElementById('wariantX2-'+t).width=widthCell2;
			}
				
		}
	}
	if(countGroup3 == 0){
		for(j=1;j<200;j++){
			if(document.getElementById('wariantX3-'+j) != null){
				document.getElementById('wariantX3-'+j).style.display='none';
			}
				
		}
	} else {
		for(t=1;t<200;t++){
			if(document.getElementById('wariantX3-'+t) != null){
				document.getElementById('wariantX3-'+t).style.display='';
				document.getElementById('wariantX3-'+t).width=widthCell3;
			}
				
		}
	}
	if(countGroup4 == 0){
		for(j=1;j<200;j++){
			if(document.getElementById('wariantX4-'+j) != null){
				document.getElementById('wariantX4-'+j).style.display='none';
			}
				
		}
	} else {
		for(t=1;t<200;t++){
			if(document.getElementById('wariantX4-'+t) != null){
				document.getElementById('wariantX4-'+t).style.display='';
				document.getElementById('wariantX4-'+t).width=widthCell4;
			}
				
		}
	}
	
	newSelected = onTab.join("-");
	document.forms['radioForm'].selOptions.value = newSelected;
	}
}
function changeRaty(prods) {
	var selected = document.forms['radioForm'].selOptions.value;
	var selectedTab = selected.split("-");
	for(i=1; i<prods+1; i++){
		coreDisplay('rata1_'+i, 'off');
		coreDisplay('rata2_'+i, 'off');
		coreDisplay('rata3_'+i, 'off');	
	}
	if(document.getElementById('ratyOption').selectedIndex == '0'){
		for(j=0; j<selectedTab.length; j++){coreDisplay('rata1_'+selectedTab[j], 'on');}
		document.getElementById('rata1_'+selectedTab[0]+'i').checked=true;
		document.forms['radioForm'].but.value = '1_'+selectedTab[0];
		chooseRaty('1_'+selectedTab[0],prods);
	}
	if(document.getElementById('ratyOption').selectedIndex == '1'){
		for(j=0; j<selectedTab.length; j++){coreDisplay('rata2_'+selectedTab[j], 'on');}
		document.getElementById('rata2_'+selectedTab[0]+'i').checked=true;
		document.forms['radioForm'].but.value = '2_'+selectedTab[0];
		chooseRaty('2_'+selectedTab[0],prods);
	}
	if(document.getElementById('ratyOption').selectedIndex == '2'){
		for(j=0; j<selectedTab.length; j++){ coreDisplay('rata3_'+selectedTab[j], 'on');}
		document.getElementById('rata3_'+selectedTab[0]+'i').checked=true;
		document.forms['radioForm'].but.value = '3_'+selectedTab[0];
		chooseRaty('3_'+selectedTab[0],prods);
	}
}
function changeRatyAll(prods) {
	var i = 0;
	for(i=1; i<prods+1; i++){
		coreDisplay('rataA1_'+i, 'off');
		coreDisplay('rataA2_'+i, 'off');
		coreDisplay('rataA3_'+i, 'off');
	}
	if(document.getElementById('ratyOptionAll').selectedIndex == '0'){
		for(i=1; i<prods+1; i++){
			coreDisplay('rataA1_'+i, 'on');
		}
		document.getElementById('rataA1_1i').checked=true;
		document.forms['radioForm'].but.value = '1_1';
		chooseRatyAll('1_1',prods);
	}
	if(document.getElementById('ratyOptionAll').selectedIndex == '1'){
		for(i=1; i<prods+1; i++){
			coreDisplay('rataA2_'+i, 'on');
		}
		document.getElementById('rataA2_1i').checked=true;
		document.forms['radioForm'].but.value = '2_1';
		chooseRatyAll('2_1',prods);
	}
	if(document.getElementById('ratyOptionAll').selectedIndex == '2'){
		for(i=1; i<prods+1; i++){
			coreDisplay('rataA3_'+i, 'on');
		}
		document.getElementById('rataA3_1i').checked=true;
		document.forms['radioForm'].but.value = '3_1';
		chooseRatyAll('3_1',prods);
	}
}
function chooseRatyAll(id,prods){
	for(i=1; i<=prods; i++){
		if(document.getElementById('rataA1_'+i) != null) document.getElementById('rataA1_'+i).className = 'porownaj_td_normal';
		if(document.getElementById('rataA2_'+i) != null) document.getElementById('rataA2_'+i).className = 'porownaj_td_normal';
		if(document.getElementById('rataA3_'+i) != null) document.getElementById('rataA3_'+i).className = 'porownaj_td_normal';
	}
	document.forms['radioForm'].but.value = id;
	document.getElementById('rataA'+id).className = 'porownaj_td_normal_or';	
}
function chooseRaty(id,prods){
	for(i=1; i<=prods; i++){
		if(document.getElementById('rata1_'+i) != null) document.getElementById('rata1_'+i).className = 'porownaj_td_normal';
		if(document.getElementById('rata2_'+i) != null) document.getElementById('rata2_'+i).className = 'porownaj_td_normal';
		if(document.getElementById('rata3_'+i) != null) document.getElementById('rata3_'+i).className = 'porownaj_td_normal';
	}
	document.forms['radioForm'].but.value = id;
	document.getElementById('rata'+id).className = 'porownaj_td_normal_or';	
}
function changeCompare(mode){
	if(mode == 0){
		coreDisplay('porownywarka_dol','off');
		coreDisplay('porownywarka_gora','on');
	}
	if(mode == 1){
		coreDisplay('porownywarka_dol','on');
		coreDisplay('porownywarka_gora','off');
	}
}
function setSort(option){
	var where = document.getElementById('strSort').value;
	var suffix = "asc";	
	if(where != ''){
		var where_arr = where.split("-");
		if(where_arr[0] == option){
			if(where_arr[1] == suffix){
				suffix = "desc";
				document.getElementById('strSort').value = option+'-'+suffix;
			} else {
				document.getElementById('strSort').value = option+'-'+suffix;
			}
		} else {
			document.getElementById('strSort').value = option+'-'+suffix;
		}
	} else {
		document.getElementById('strSort').value = option + '-' + suffix;
	}
	document.forms['list'].submit();
}
function showSelected(elements, mode){
	for(h=0; h<elements.length; h++){coreDisplay('odp['+elements[h]+']', mode);}
}
function coreDisplay(element, mode){
	if(mode == 'on'){
		if(document.getElementById(element) != null){ document.getElementById(element).style.display='';}
	} 
	if(mode == 'off'){
		if(document.getElementById(element) != null){document.getElementById(element).style.display='none';}
	}
}

function showLayer() {
	var div = document.createElement('div');
	div.id = 'layer';	
	div.innerHTML = '<div id="layerPage" style="z-index:999;position:absolute;top:0px;left:0px;width:'
			+ getPageSize()[0]
			+ 'px;height:'
			+ getPageSize()[1]
			+ 'px;background:#FFFFFF;opacity: 0.6; -moz-opacity: 0.6; filter: progid:DXImageTransform.Microsoft.Alpha(opacity=60); zoom:1;"><!--? --></div>';
	document.body.appendChild(div);
}
function showAjaxLoad( link, textDiv ) {
	div = document.createElement('div');
	div.id = 'ajaxLoader';
	x = screen.width / 2 - 100;
	y = screen.availHeight / 2 - 150;
	div.innerHTML = '<div style="position:fixed;width:400px;line-height:100px;height:200px;text-align:center;z-index:9999;left:'
			+ x
			+ 'px;top:'
			+ y
			+ 'px;font-size:23px;background: url(htdocs/system/new_templates/gfx/content/ajaxLoad.gif) no-repeat top center;"><br />'
			+ '<div style="line-height:30px">'+textDiv+'</div></div>';
	document.body.appendChild(div);
	showLayer();
	if (link != '' ) {
		window.location.href=link;
		return false;
	}
}
function hiddenAjaxLoad() {
	var layer = document.getElementById('ajaxLoader');
	if (layer)
		layer.parentNode.removeChild(layer);
	var layer = document.getElementById('layer');
	if (layer)
		layer.parentNode.removeChild(layer);	
}
function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // all
		// but
		// Explorer
		// Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla
		// and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		if (document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement
			&& document.documentElement.clientHeight) { // Explorer 6 Strict
		// Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	// for small pages with total height less then height of the viewport
	if (yScroll < windowHeight) {
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if (xScroll < windowWidth) {
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
	return arrayPageSize;
}

function value_replace(element, val, id) {
	if (typeof id != "undefined") 
		var object = $('#'+ element);
	else
		var object = $('[name='+ element +']');

	var current_val = object.val();
	
	if(val == current_val)
		object.val('');
	else if(current_val == "")
		object.val(val);
}

function save_comment() {
	$.post(
		"index.php?m=wnioski&a=fullPreview", {
			comment_content: document.getElementById('comment_content').value,
			comment_history: document.getElementById('comment_history_input').value,
			tid: document.getElementById('tid').value
		},
	function(data){
		$("#comment_history").hide('clip');
		$("#comment_history").html(data.content);
		$("#comment_history").show('clip');
		$("#comment_content").val('');
		$("#comment_history_input").val(data.content);

	}, "json");

	$("#ajax_loader").fadeIn('slow'); 
	$("#ajax_loader").queue(function() { 
		setTimeout(function(){ 
			$("#ajax_loader").dequeue(); 
		}, 400 );
	}); 
	$("#ajax_loader").fadeOut('slow'); 
}

function get_price_brake(tid) {
	$.post("index.php?m=wnioski&a=get_price_brake", 
		{ price_brake_tid: tid },
	function(data){
		var message = 'Rozbicie kwoty ubezpieczenia (PLN):\n\n';
		if(data.bb)
			message += "* OC: "+data.skladka_produkt_1r_oc;
		if(data.skladka_produkt_1r_ac)
			message += "\n* AC: "+data.skladka_produkt_1r_ac;
		if(data.skladka_produkt_nnw)
			message += "\n* NNW: "+data.skladka_produkt_nnw;
		if(data.skladka_produkt_ass)
			message += "\n* ASS: "+data.skladka_produkt_ass;
		if(data.skladka_produkt_op)
			message += "\n* OP: "+data.skladka_produkt_op;

		if(message == 'Rozbicie kwoty ubezpieczenia (PLN):\n\n')
			message += "Brak danych.";

		alert(message);
	}, "json");
}

function clear_spaces(id) {
    var str = document.getElementById('odp['+id+']').value;
    var res = '';
    res = str.replace(/ /gi, '');
    res = res.replace(/\./gi, '');
    res = res.replace(/\,/gi, '');
    res = res.replace(/['A-Z']/gi, '');
    document.getElementById('odp['+id+']').value = res;
}

function edit_data($code) {
    var answer = confirm("Czy na pewno chcesz edytować?");
    if(answer) {
        $(".but").css("display", "none");
        document.getElementById('button_'+$code).innerHTML = '<a href="javascript:void()" style="font-size:9px;color:#F57402" onclick="modify_data(\''+$code+'\')">[ zastosuj ]</a> <a href="javascript:void()" style="font-size:9px;color:red" onclick="abort_editing_data(\''+$code+'\')">[ anuluj edycję ]</a>';
        document.getElementById('button_'+$code).style.display = 'inline';
        document.getElementById('divinput_'+$code).style.display = 'inline';
    }
}

function modify_data($code) {
	$.post(
		"index.php?m=wnioski&a=edit_data", {
			code: $code,
			tid: document.getElementById('tid').value,
            input_content: document.getElementById('input_'+$code).value
		}, function(data) {
            $("#loader_"+$code).fadeIn(500)
            setTimeout(function(){
                $("#divinput_"+$code).fadeOut(500);
                $("#button_"+$code).css("display", "none");
                $("#loader_"+$code).fadeOut(500);
                setTimeout(function(){
                    abort_editing_data($code);
                    for(i in data) {
                        $("#label_"+$code).text(data[i]);
                    }
                }, 500 );
            }, 500 );
    }, "json");
}

function abort_editing_data($code) {
    $(".but").fadeIn(1000);
    $(".but").css("display", "inline");
    $("#button_"+$code).css("display", "inline");
    document.getElementById('button_'+$code).innerHTML = '<a href="javascript:void()" onclick="edit_data(\''+$code+'\')" style="font-size:9px;">[ edytuj ]</a>';
    document.getElementById('divinput_'+$code).style.display = 'none';
}

function callback_send() {
	$.post(
		"index.php?m=html&a=callback_send", {
			callback_name: document.getElementById('callback_name').value,
			callback_tel: document.getElementById('callback_tel').value,
			callback_date: document.getElementById('callback_date').value,
			callback_hours: document.getElementById('callback_hours').value
		}
	);
		setTimeout(function(){
			$(".callback_submit").fadeOut(500);
			$("#loader").fadeIn(500);

            setTimeout(function(){
				
				$("#loader").fadeOut(500);

				open_send_end();

				$("#callback_msg").fadeIn(3000);
				$("#callback_msg").fadeOut(500);
            }, 2000 );
		});
}

function open_send_end() {
	jQuery('#callback_send_end').dialog('open');
    return false;
}

function clear_callback() {
	$(".callback_submit").fadeIn(500);
	document.getElementById('callback_name').value = '';
	document.getElementById('callback_tel').value = '';
	document.getElementById('callback_hours').value = 2;
}

function delete_send_flag(tid) {
	var answer = confirm("Czy na pewno chcesz usunąć?");
	if(answer)
		window.location = "?m=wnioski&a=send_post_office&tid="+tid;
}

function change_disable_reffrom() {
	var partner_id = document.getElementById('partner_admin_id').value;
	var partner_name_obj = document.getElementById('partner');
	var ref_from_obj = document.getElementById('ref_from');
	if(partner_id == 0) {
		partner_name_obj.disabled = '';
		partner_name_obj.style.background = '';
		ref_from_obj.disabled = '';
		ref_from_obj.style.background = '';
	} else {
		partner_name_obj.disabled = 'disabled';
		partner_name_obj.style.background = '#f2f2f2';
		ref_from_obj.disabled = 'disabled';
		ref_from_obj.style.background = '#f2f2f2';
	}
}

function rewrite_value(id, id2) {
	var val = document.getElementById(id).value;
	var id2_obj = document.getElementById(id2);
	if(!id2_obj.disabled)
		id2_obj.value = val;
	else
		id2_obj.value = '';
}