function ZmienionoIlosc(jednostka)
{
	var poleIlosc = document.getElementById( 'ProduktIlosc' );
	poleIlosc.value = poleIlosc.value.replace( ',', '.' );
	if( poleIlosc.value[ poleIlosc.value.length - 1 ] == '.' ) {
		return ;
	}
	poleIlosc.value = parseFloat(poleIlosc.value);
	if( poleIlosc.value == 'NaN' ) {
		poleIlosc.value = 1;
	}
	if( jednostka == 'szt' ) {
		poleIlosc.value = Math.ceil( poleIlosc.value );
	}
	var ProduktCena = document.getElementById( 'ProduktCena' ).innerHTML;
	var ProduktSumaTxt = document.getElementById( 'ProduktSumaTxt' );
	//dodac zeby bylo zaokraglenie do 2 miejsc po przecinku:P

	
	var liczba = (parseFloat( poleIlosc.value ) * parseFloat( ProduktCena ) );
	ProduktSumaTxt.innerHTML=liczba.toFixed(2);
	
	
//	ProduktSumaTxt
//	var $il = document.getElementById( 'ProduktIlosc' );
   
}


function confirmLink(theLink, theWarning)
{
    var is_confirmed = confirm(theWarning);
    if (is_confirmed) {
        document.location=theLink;
    }
    return is_confirmed;
} // end of the 'confirmLink()' function


function confirmSubmitForm(theForm, theWarning)
{
    var is_confirmed = confirm(theWarning);
    if (is_confirmed) {
        document.forms[theForm].submit();
    }
//    return is_confirmed;
} // end of the 'confirmLink()' function

function sprawdz_formularz(){
  
 if( document.getElementById('temat').value == '' || document.getElementById('tresc').value == '')
  alert( 'Musisz podać tytuł oraz treść.' );
 else
  document.forms.wiadomosc.submit() 
}


function str_repeat(i, m) {
for (var o = ''; m-- > 0; o += i);
return o;
}

function sprintf () {
var a, f = arguments[0], fi= '', i = 1, m = [''], o = '', p;
while (f = f.substring (m[0].length)) {
m = /^([^\%]*)(?:(\x25)((\x25)|(?:(\d+)\$)?(\+)?(0|'([^$]))?(-|\^)?(\d+)?(?:\.(\d+))?([bcdefosuxX])))?/.exec

(f);
if (a = m[12]) {
if (arguments.length < (i = m[5] || i))
throw("sprintf '" + m[0] + "' : No argument " + i);
a = arguments[i++];
s = (/[def]/.test(m[12]) && m[6] && a > 0) ? '+':'';
switch (m[12]) {
case 'b': a = a.toString(2); break;
case 'c': a = String.fromCharCode(a); break;
case 'd': a = parseInt(a); break;
case 'e': a = m[11] ? a.toExponential(m[11]) : a.toExponential(); break;
case 'f': a = m[11] ? parseFloat(a).toFixed(m[11]) : parseFloat(a); break;
case 'o': a = a.toString(8); break;
case 's': a = ((a = String(a)) && m[11] ? a.substring(0, m[11]) : a); break;
case 'u': a = Math.abs(a); break;
case 'x': a = a.toString(16); break;
case 'X': a = a.toString(16).toUpperCase(); break;
}
if (m[10] && (m[10] > a.length)) {
fir=fil=str_repeat(m[7] ? m[8] || '0' : ' ', m[10]-a.length);
if (m[9] == '^') {
fil = fil.substr(0, fil.length / 2);
fir = fir.substr(fil.length);
} else
m[9] == '-' ? (fil = '') : (fir = '');
a = fil + a + fir;
}
}
o += m[1] + ((m[3] ? m[4] || (s + a) : m[2]) || '');
}
return o;
}
 
function AktywujMenu( id ) {
 var poz = document.getElementById( 'menu_' + id );
 poz.className = 'PozycjaMenuAktywna';
}

function DeaktywujMenu( id ) {
 var poz = document.getElementById( 'menu_' + id );
 poz.className = 'PozycjaMenu';
}

function valid_f( e, validType ){

   var jest_ok = true;
   if (e.value == '' ) jest_ok = false;
    
   if( validType == 'kod' ) 
   {
    if( e.value == '00-000' ) 
     jest_ok = false;
   }

   if( jest_ok ) {
     e.style.backgroundColor = 'White';
    var ret = 0;
   } else { 
     e.style.backgroundColor = '#d6c3b2'; 
    var ret = 1;
   }
  return ret;
}

function sprawdz_f(){
 
 var ret = 0;
 ret += valid_f( document.getElementById('f_kod'), 'kod' );
 ret += valid_f( document.getElementById('f_miejscowosc'), 'empty' );
 ret += valid_f( document.getElementById('f_ulica'), 'empty' ); 
 ret += valid_f( document.getElementById('f_nr_domu'), 'empty' );
 ret += valid_f( document.getElementById('nazwa'), 'empty' );
 for( var i = 1; i <= 4; i ++ ) {
  //ret += valid_f( document.getElementById('nip' + i ), 'empty' ); 
  if (document.getElementById('nip' + i).value != '') {
  	ret += valid_dlugosc( 'nip' + i );
  }  
 }

 if( ret > 0 )
  alert( 'Musisz wypełnić wszystkie wymagane pola ');
 else
  document.forms.adresy.submit();
}

function wyczysc_pole(){
	var input = $(".search_input");
	var content = $("#fraza");
	content[0].value = input[0].value;
	input[0].value = "";
	input[0].style.color = "#533F2D";
}

function przywroc_pole(){
	var input = $(".search_input");
	var content = $("#fraza");
	input[0].value = content[0].value;
	input[0].style.color = "#E5D4B6";
}

function zmien_liste(opcja){
	var param = $("#param_list");
	param[0].value = opcja;
	var form = $("#form_list");
	form[0].submit();
}

function wyczysc_kod(){
	var input = $("#f_kod");
	input[0].value = "";
	//input[0].style.color = "#533F2D";
}

function obliczIloscSztuk(id_produktu, ile_w_opakowaniu){
	var ile_opakowan = $("#ile_opakowan_" + id_produktu);
	var ilosc_w_sumie = $("#ilosc_" + id_produktu);
	
	var w_sumie;
	
	if (ile_opakowan[0].value != ""){
		w_sumie = ile_opakowan[0].value * ile_w_opakowaniu;
	} else {
		w_sumie = "";
	}
	ilosc_w_sumie[0].value = w_sumie;
	
}

function obliczIloscSztukKoszyk(id_produktu, ile_w_opakowaniu, kod_produktu){
	
	var ile_opakowan = $("#ile_opakowan_" + id_produktu);	
	var ilosc_w_sumie = $("#ilosc_" + id_produktu);
	
	var w_sumie;
	
	if (ile_opakowan[0].value != ""){
		w_sumie = ile_opakowan[0].value * ile_w_opakowaniu;
	} else {
		w_sumie = "";
	}
	ilosc_w_sumie[0].value = w_sumie;
}


/*uprawnienia*/

function selectAll(val) {
      $('.'+val+' input[@type=checkbox]').attr('checked', 'checked');
      $('.'+val+' #selectall').toggle();
      $('.'+val+' #deselectall').toggle();
       return false;
}

function deSelectAll(val) {
      $('.'+val+' input[@type=checkbox]').removeAttr('checked');
      $('.'+val+' #selectall').toggle();
      $('.'+val+' #deselectall').toggle();      
       return false;
}

function toggleAll(val) {
      $('.'+val+' input[@type=checkbox]').each( function() {
                $(this).attr('checked', !$(this).attr('checked'));
       });
       return false;
}

function showTree(val) {
      $('.'+val+' ul ul').slideDown('slow');
      $('.'+val+' ul a').addClass('uprawnienia_minus');
      $('.'+val+' #showtree').toggle();
      $('.'+val+' #hidetree').toggle();
       return false;
}

function hideTree(val) {
      $('.'+val+' ul ul').slideUp('slow');
      $('.'+val+' ul a').removeClass('uprawnienia_minus');
      $('.'+val+' #showtree').toggle();
      $('.'+val+' #hidetree').toggle();
       return false;
}


function RozwinAktywne(id, aktywna){

	$('#ul_' + id).slideDown(50);
	$('#grupa_' + aktywna).addClass('grupa_aktywna');
	$('#a_' + id).addClass('uprawnienia_minus');
	
	return false;
} 
