// JavaScript Document
var ie = (document.all) ? true : false;

function zmien_kolor_obramowania(el, error, komunikat){
    if(!error){
        el.onmouseover=function anonymous(){}
        el.onmouseout=function anonymous(){}
        el.className = el.className.replace(/[\s]{0,1}error/g, '');
        return true;
    }else{
        el.className += ' error';
        el.onmouseover=function anonymous(){ return overlib(komunikat); }
        el.onmouseout=function anonymous(){nd();}
        el.onclick=function anonymous(){ nd(); this.onmouseover=function anonymous(){} }
        return false;
    }
}



function checkInput(el, zezwalajNaPuste, wyrazenie, komunikat){
    var wartosc = el.value;

    //usuwamy spacje z poczatku i końca ciagu
    wartosc=wartosc.replace(/^(\s)+/,"");
    wartosc=wartosc.replace(/(\s)+$/,"");

    if( wartosc == ""){
        if(zezwalajNaPuste){
            el.onmouseover=function anonymous(){}
            el.onmouseout=function anonymous(){}
            el.className = el.className.replace(/[\s]{0,1}error/g, '');
            return true;
        }else{
            el.className += ' error';
            el.onmouseover=function anonymous(){ return overlib(lang['field_no_empty']); }
            el.onmouseout=function anonymous(){ nd(); }
            el.onclick=function anonymous(){ nd(); this.onmouseover=function anonymous(){} }
            return false;
        }
    }else{
        if( typeof(wyrazenie) != 'string' ) {
            if(wyrazenie.test(wartosc)){
                el.onmouseover=function anonymous(){}
                el.onmouseout=function anonymous(){}
                el.className = el.className.replace(/[\s]{0,1}error/g, '');
                return true;
            }else{
                el.className += ' error';
                el.onmouseover = function anonymous(){ return overlib(komunikat); }
                el.onmouseout=function anonymous(){ nd(); }
                el.onclick=function anonymous(){ nd(); this.onmouseover=function anonymous(){} }
                return false;
            }
        }else{
            el.onmouseover=function anonymous(){}
            el.onmouseout=function anonymous(){}
            el.className = el.className.replace(/[\s]{0,1}error/g, '');
            return true;
        }
    }
}


function checkDateInput( el ){
    zmien_kolor_obramowania(el, check_date(el.value), lang[''] );

}

function set_active( o_image ){
    var slash_pos = o_image.src.lastIndexOf('/');

    if( slash_pos ){
      var img_path = o_image.src.substr(0, slash_pos+1) + 'a' + o_image.src.substr(slash_pos+1)
    }else{
      var img_path = 'a' + o_image.src;
    }

    o_image.src = img_path;
}

function set_deactive( o_image ){
    var slash_pos = o_image.src.lastIndexOf('/');

    if( slash_pos ){
      var img_path = o_image.src.substr(0, slash_pos+1) + o_image.src.substr(slash_pos+2)
    }else{
      var img_path = o_image.src.substr( 1 );
    }

    o_image.src = img_path;
}


function basename( path ){
  var  slash_pos = path.lastIndexOf('/');

  if( slash_pos ){
    return str.substr(slash_pos+1);
  }else{
    return path;
  }
}

function dirname( path ){
  var  slash_pos = path.lastIndexOf('/');

  if( slash_pos ){
    return str.substr(0, slash_pos);
  }else{
    return '.';
  }
}

var blink_tab = new Object();

function blink( el_id, on ){
  var o_blink = null
  if( !typeof(blink_tab[el_id]) != 'object' ){
    blink_tab[el_id] = document.getElementById(el_id);
    if( !blink_tab[el_id] ){
        return false;
    }
  }
  
  o_blink = blink_tab[el_id];

  if( on ){
    o_blink.className = 'blink_on';
    setTimeout('blink( "' + el_id + '", false )', 1000 /*milliseconds*/);
  }else{
    o_blink.className = 'blink_off';
    setTimeout('blink( "' + el_id + '", true )', 1000 /*milliseconds*/);
  }
    
  return true;

}


function informacja(){
     var width = 800;
     var height = 600;
     cx=(screen.availWidth-width)/2;
     cy=(screen.availHeight-height)/2;
     okno = window.open('info.html',"","height="+height+",width="+width+",top="+cy+",left="+cx+",status=0,scrollbars,resizable;");
     okno.focus();
}



function komunikat(id){
     var width = 500;
     var height = 350;
     cx=(screen.availWidth-width)/2;
     cy=(screen.availHeight-height)/2;
     okno = window.open("zjazd-informacje.php?action=komunikat&komunikatID="+id,"komunikat","height="+height+",width="+width+",top="+cy+",left="+cx+",status=0,scrollbars,resizable;");
     okno.focus();
}


function pokaz_ukryj_obiekt(id_obiektu){

    var el = document.getElementById(id_obiektu);
    
    if(!el){
        return null;
    }

    if( el.scrollHeight && el.scrollHeight > 0 ){
        el.style.display = 'none';
    }else{
        el.style.display = 'block';
    }
}

function show_hide(id_obiektu){

    var el = document.getElementById(id_obiektu);

    if( el.scrollHeight && el.scrollHeight > 0 ){
        el.style.display = 'none';
    }else{
        el.style.display = 'block';
    }
}

function check_onclick_show_hide( o_check, id_obiektu ){
    var el = document.getElementById(id_obiektu);

    if( !el ){
        alert( 'Brak obiektu w dokumencie o id: ' + id_obiektu + ' i obiekt nie może zostać pokazany! ');
        return false;
    }
    
    if( o_check.checked ){
        el.style.display = 'block';
    }else{
        el.style.display = 'none';
    }
}

function zwin_rozwin(obrazek, obiekt_id){

    if( typeof(obrazek) == 'string' ){
        obrazek = document.getElementById(obrazek);
    }

    if( typeof(obiekt_id) == 'string' ){
        var el = document.getElementById(obiekt_id);
    }else if( typeof(obiekt_id) == 'object' ){
        var el = obiekt_id;
    }

    //alert( el.clientHeight );

    if( el.scrollHeight > 0  ){
        el.style.display = 'none';
        //zamieniam minus na plus
        //obrazek.src = obrazek.src.replace('minus.png','plus.png');

        obrazek.src = obrazek.src.substring(0, obrazek.src.lastIndexOf('/')+1) + 'plus.png';
        obrazek.alt = obrazek.title = '+'
    }else{
        el.style.display = 'block';
        //zamieniam plus na minus
        //obrazek.src = obrazek.src.replace('plus.png','minus.png');
        obrazek.src = obrazek.src.substring(0, obrazek.src.lastIndexOf('/')+1) + 'minus.png';
        obrazek.alt = obrazek.title = '-';
    }
}

function zwin_rozwin2(obrazek, obiekt_id){
    var el = document.getElementById(obiekt_id);

    if( el.scrollHeight && el.scrollHeight > 0 ){
        el.style.display = 'none';
        //zamieniam minus na plus
        //obrazek.src = obrazek.src.replace('minus.png','plus.png');
        obrazek.src = obrazek.src.substring(0, obrazek.src.lastIndexOf('/')+1) + 'down_arr.gif';

    }else{
        el.style.display = 'block';
        //zamieniam plus na minus
        //obrazek.src = obrazek.src.replace('plus.png','minus.png');
        obrazek.src = obrazek.src.substring(0, obrazek.src.lastIndexOf('/')+1) + 'up_arr.gif';

    }
}

function go2page(el){
      el.submit();
}

function show(id_obiektu){
    var el = document.getElementById(id_obiektu);
    show_obj(el);
}

function show_obj( obj ){
    if( typeof(obj) == 'string' ){
        obj = document.getElementById(obj);
    }
    
    if( obj.tagName == 'DIV'){
        obj.style.display = 'block';
    }else{
        obj.style.display = '';
    }
    obj.style.visibility = 'visible';
}

function show_obj_xy( obj, x, y ){
    obj.style.top = y;
    obj.style.left = x;
    obj.style.display = 'block';
}

function hide(id_obiektu){
    var el = document.getElementById(id_obiektu);

    hide_obj(el);
}

function hide_obj(obj){
    if( typeof(obj) == 'string' ){
        obj = document.getElementById(obj);
    }
    
    obj.style.display = 'none';
    obj.style.visibility = 'hidden';
}



function pokaz_ukryj(id){
	var tab = document.getElementById(id);
	if((tab.style.display == '') || (tab.style.display == 'block')){
		tab.style.display = 'none';
	}else{
		tab.style.display = 'block';
	}
}

var o_tlo_div = null;

function showTlo(){

  if( !o_tlo_div ){
      o_tlo_div = document.getElementById('tlo_div');
      
      if( !o_tlo_div ){
          o_tlo_div = document.createElement('div');

          o_tlo_div.id = 'tlo_div';
          o_tlo_div.className = 'tlo';


          o_tlo_div.style.position = "absolute";
          o_tlo_div.style.top = 0;
          o_tlo_div.style.left = 0;
          
          o_tlo_div.style.display  = "none";
          o_tlo_div.style.visibility = "hidden";

          document.body.insertBefore( o_tlo_div, document.body.firstChild );
      }
  }

  o_tlo_div.style.zIndex = 110;
  o_tlo_div.style.top = 0;
  o_tlo_div.style.left= 0;
  o_tlo_div.style.opacity= 0.6;
  o_tlo_div.style.filter = 'alpha(Opacity=60)';
  o_tlo_div.style.background = '#efefef';
  o_tlo_div.style.width  = document.body.scrollWidth;
  o_tlo_div.style.height = document.body.scrollHeight;
  o_tlo_div.style.visibility = "visible";
  o_tlo_div.style.display = "block";
}


function hideTlo(){
    if( !o_tlo_div ){
        o_tlo_div = document.getElementById('tlo_div');
    }

    o_tlo_div.style.visibility = "hidden";
}



function center_both( s_id ){
    var o_el = null;

    //sprawdzam czy juz ta funkcja była wywoływana
    //i byc moze juz został utworzony odpowiedni obiekt
    if( typeof(window['o_' + s_id]) == 'object' ){
        o_el = window['o_' + s_id];
    }else{
        o_el = document.getElementById(s_id);
        window['o_' + s_id] = o_el;
    }

    center_both_obj( o_el );

    return o_el;
}

function center_both_obj( obj ){

    obj.style.display = 'block';

    var width  = obj.clientWidth;
    var height = obj.clientHeight;

    var winW = screen.width;
    var winH = screen.height;

    if ( parseInt(navigator.appVersion) > 3 ) {
        if (navigator.appName=="Netscape") {
          winW = window.innerWidth;
          winH = window.innerHeight;
        }
        if (navigator.appName.indexOf("Microsoft")!=-1) {
          winW = document.body.offsetWidth;
          winH = document.body.offsetHeight;
        }
    }

    obj.style.left = parseInt( (winW - width) / 2);
    obj.style.position = 'absolute';
    obj.style.top  = document.body.scrollTop + parseInt( (winH - height) / 2);
    obj.style.zIndex = 111;
    obj.style.visibility = 'visible';
}


function select_all(chbox, select_what){
    if( chbox.checked ){
        formularz = chbox.form;
        var i = 0;
        while(typeof(formularz.elements[select_what + '['+ i +']']) == 'object'){
            formularz.elements[select_what + '['+ i +']'].checked = true;
            i++;
        }
    }else{
        formularz = chbox.form;
        var i = 0;
        while(typeof(formularz.elements[select_what + '['+ i +']']) == 'object'){
            formularz.elements[ select_what + '['+ i +']'].checked = false;
            i++;
        }
    }
}

var okno = null;

function otworz_okno(adres, w, h, nazwa_okna ){
    var width = 800;
    var height = 600;
    if( w > 0){
        width = w;
    }
    if( h > 0){
        height = h;
    }
    cx=(screen.availWidth-width)/2;
    cy=(screen.availHeight-height)/2;
    if(!nazwa_okna ){
        nazwa_okna = '';
    }
    
    if( !okno || okno.closed){
        okno = window.open(adres, nazwa_okna, "height="+height+",width="+width+",top="+cy+",left="+cx+",status=1,scrollbars=1,resizable=1;");

    }else{
        okno.location = adres;
    }

    okno.focus();
}







function trim( str ){
    //usuwamy spacje z poczatku i końca ciagu
    str = str.replace(/^(\s)+/,"");
    str = str.replace(/(\s)+$/,"");

    return str;
}

function is_empty(str){
    var wartosc = str.replace(/^(\s)+/,"");
    wartosc = wartosc.replace(/(\s)+$/,"");

    if( wartosc == "" ){
        return true;
    }else{
        return false;
    }
}

function isInt(wartosc){
  wartosc = wartosc.replace(/^(\s)+/, "");
  wartosc = wartosc.replace(/(\s)+$/, "");
  wartosc = parseInt(wartosc);

  if( isNaN(wartosc) ){
      return false;
  }else{
      return true;
  }
}

function toInt(wartosc){
    wartosc = wartosc.replace(/(\s+)/, "");
    wartosc = wartosc.replace(",", ".");
    wartosc = wartosc.replace(/^0+/, "");
    wartosc = parseInt(wartosc);

    if( isNaN(wartosc) ){
        return 0;
    }else{
        return wartosc;
    }
}



function licz_slowa( str ){

  str = trim(str);
  if( str == '' ){
    return 0;
  }
  //zmienne pomocnicze
  var i, j, znak, pos;
  
  //zamieniam znaki interpunkcyjne na spacje
  var nie_litery = [ ',', '.', '!', '?', '<', '>', '/', '\\', '|', '[', ']', '{', '}', ':', '"', '@', '$', '%', '^', '*', '_', '+', "\n" ];
  //str = str.replace();
  var code1, code2;
  
  new_str = new String('');
  for(i = 0; i < str.length; i++){
    znak = str.charAt(i);

    //dla zgodnosci z MS WORD
    if( znak == ',' || znak == '.' || znak == ':' ){
        znak = ' ';
        if( i > 0 && i < str.length - 1 ){
            code1 = str.charCodeAt(i - 1); code2 = str.charCodeAt(i + 1);
            if( (code1 >= 48 && code1 <= 57 ) && (code2 >= 48 && code2 <= 57 ) ){
                znak = '';
            }
        }
    }else {
        for( j = 0; j < nie_litery.length; j++ ){
          if( nie_litery[j] == znak ){
              znak = ' ';
          }
        }
    }

    new_str += znak;
  }
  
  //czyszcze spacje z poczatku i końca
  new_str = trim( new_str );
  if( new_str == '' ){
      return 0;
  }
  
  //licze ile jest spacji w ciagu :)
  pos = new_str.indexOf(' ');
  i = 0;
  while( pos > 0 ){
      i++;

      j = pos + 1;
      while(  new_str.charAt(j) == ' ' ){
        j++;
      }
      pos = new_str.indexOf(' ', j);
  }

  i++;

  return i;

}




function insertTab(event,obj) {
    var tabKeyCode = 9;
    var enterKeyCode = 13;
    if (event.which) // mozilla
        var keycode = event.which;
    else // ie
        var keycode = event.keyCode;
    if (keycode == tabKeyCode) {
        if (event.type == "keydown") {
            if (obj.setSelectionRange) {
                // mozilla
                var s = obj.selectionStart;
                var e = obj.selectionEnd;
                obj.value = obj.value.substring(0, s) +
                    "\t" + obj.value.substr(e);
                obj.setSelectionRange(s + 1, s + 1);
                obj.focus();
            } else if (obj.createTextRange) {
                // ie
                document.selection.createRange().text="\t"
                obj.onblur = function() { this.focus(); this.onblur = null; };
            } else {
                // unsupported browsers
            }
        }
        if (event.returnValue) // ie ?
            event.returnValue = false;
        if (event.preventDefault) // dom
            event.preventDefault();
        return false; // should work in all browsers
    }else if( keycode == enterKeyCode  ){

        if (event.type == "keydown" && event.ctrlKey ) {
            if (obj.setSelectionRange) {
                // mozilla
                var s = obj.selectionStart;
                var e = obj.selectionEnd;
                obj.value = obj.value.substring(0, s) +
                    "<br />\n" + obj.value.substr(e);
                obj.setSelectionRange(s + 7, s + 7);
                obj.focus();
            } else if (obj.createTextRange) {
                // ie
                document.selection.createRange().text="<br />\n"
                obj.onblur = function() { this.focus(); this.onblur = null; };
            } else {
                // unsupported browsers
            }

        if (event.returnValue) // ie ?
            event.returnValue = false;
        if (event.preventDefault) // dom
            event.preventDefault();
        return false; // should work in all browsers
        }

    }

    return true;
}


function htmlspecialchars( str ){
    var old_str = new String(str);
    var new_str = new String('');
    znak = '';

    for( i=0; i < old_str.length; i++ ){
        znak = old_str.charAt(i)

        if( znak  == '"' ){
            new_str += '&quot;'
        }else if( znak  == "'" ) {
            new_str += '&#039;';
        }else if( znak  == "&" ){
            new_str += '&amp;';
        }else if( znak  == "< " ){
            new_str += '&lt;';
        }else if( znak  == ">" ){
            new_str += '&gt;';
        }else{
            new_str += znak;
        }
    }

    return new_str;
}


function porownaj_daty(data1, data2){
    data1 =  data1.split("-");
    data2 =  data2.split("-");

    rok     = data1[2];
    miesiac = data1[1];
    dzien   = data1[0];
    data1   = rok +""+ miesiac +""+ dzien;
    data1   = parseInt(data1);

    rok     = data2[2];
    miesiac = data2[1];
    dzien   = data2[0];
    data2   = rok +""+ miesiac +""+ dzien;
    data2   = parseInt(data2);


    if(data1 < data2 ){
       return -1;
    }else if(data1 == data2){
       return 0;
    }else{
       return 1;
    }
}

var old_row = null;
function podswietl_wiersz( row, multi ){
    if( arguments.length == 1 ){ multi = false; }

    if( !multi && old_row ){
        old_row.className = old_row.className.replace(/[\s]{0,1}highlight/g, '');
    }

    old_row = row;

    if( row ){
        row.className += ' highlight';
    }
}

function clear_select( o_select, skip ){
    var i = 0;

    skip = parseInt(skip);

    if( isNaN(skip ) || skip < 0 || skip > o_select.length){
        skip = 0;
    }

    //usuwam opcje za wyjatkiem pierwszej i która domyslnie to utwórz nowe konto
    for( i = o_select.length - 1; i >= skip; i-- ){
        o_select.remove(i);
    }
}

function make_select( o_select, a_options, selected ){

    //usuwam opcje
    for( i = o_select.length - 1; i >= 0; i-- ){
        o_select.remove(i);
    }

    //opcja wybierz
    opt = document.createElement('option');
    opt.value = '';
    opt.text  = 'Wybierz';

    try{
        o_select.add ( opt, null);
    }catch(err){
        o_select.add(opt);
    }

    for(i in a_options){
        opt = document.createElement('option');
        opt.value = i;
        opt.text  = a_options[i];
        if( selected == i ){
            opt.selected = true;
        }

        try{
            o_select.add(opt, null);
        }catch(err){
            o_select.add(opt);
        }
    }
}

function select_option(oSelect, value, defaultIndex, search_in_names ){

    if( arguments.length < 3 ){
        defaultIndex = 0;
        search_in_names = false;
    }

    var selectedIndex = defaultIndex;

    //pierwsza opcja
    oSelect['options'][defaultIndex].selected == true;


    if( value != '' ){
        if( search_in_names ){
            var value_lower = value.toLowerCase();

            for(var j = 0; j < oSelect.length; j++ ){
                if( oSelect['options'][j].value == value || oSelect['options'][j].text.toLowerCase() == value_lower ){
                    oSelect['options'][j].selected = true;
                    selectedIndex = j;
                    break;
                }
            }
        }else{
            //sprawdzam czy wartosc jest w
            for(var j = 0; j < oSelect.length; j++ ){
                if( oSelect['options'][j].value == value ){
                    oSelect['options'][j].selected = true;
                    selectedIndex = j;
                    break;
                }
            }
        }
    }

    return selectedIndex;

}

function  combo_select( o_sel, s_input_field_name ){
    o_sel.form.elements[s_input_field_name].value = ( o_sel.selectedIndex > 0 ) ? o_sel.value : '';
}

function currency_format( cena ){
    cena = new Number( cena );

    //zamieniam na ciag
    var s_cena = cena.toFixed(2);
    //zamieniam kropki na przecinki
    s_cena = s_cena.replace(/\./, ',');
    //sprawdzam miejsce przecinka
    var pos = s_cena.indexOf(',');

    var czesc_ulamkowa = '';
    var czesc_calkowita = '';
    var cena_f = ''

    if( pos > 0){
        //wycinam miejscea po przecinku
        czesc_ulamkowa = s_cena.substr(pos + 1);
        czesc_calkowita = s_cena.substr(0, pos);
        if( czesc_ulamkowa.length < 2 ){
            czesc_ulamkowa += '0';
        }
    }else{
        czesc_ulamkowa = '00';
        czesc_calkowita = s_cena;
    }
    var i,j;
    for( i = czesc_calkowita.length-1, j = 1; i > 0; i--, j++ ){
        cena_f = czesc_calkowita.charAt(i) + cena_f;
        if( j % 3 == 0 ){
            cena_f = ' ' + cena_f;
            j = 1;
        }
    }
    cena_f = czesc_calkowita.charAt(0) + cena_f;


    return (cena_f + ',' + czesc_ulamkowa);
}

function number_format( value_str ){

    if( typeof(value_str) != 'string' ){
        value_str = new String(value_str);
    }
    value_str = value_str.replace(',', '.' );
    value_str = value_str.replace(' ', '' );

    val = parseFloat( value_str );
    if( isNaN(val) ){
        val = 0;
    }

    return val;
}


function sprintf(){
			if (!arguments || arguments.length < 1 || !RegExp)
			{
				return;
			}
			var str = arguments[0];
			var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
			var a = b = [], numSubstitutions = 0, numMatches = 0;
			while (a = re.exec(str))
			{
				var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
				var pPrecision = a[5], pType = a[6], rightPart = a[7];

				//alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision);

				numMatches++;
				if (pType == '%')
				{
					subst = '%';
				}
				else
				{
					numSubstitutions++;
					if (numSubstitutions >= arguments.length)
					{
						alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).');
					}
					var param = arguments[numSubstitutions];
					var pad = '';
					       if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
					  else if (pPad) pad = pPad;
					var justifyRight = true;
					       if (pJustify && pJustify === "-") justifyRight = false;
					var minLength = -1;
					       if (pMinLength) minLength = parseInt(pMinLength);
					var precision = -1;
					       if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1));
					var subst = param;
					       if (pType == 'b') subst = parseInt(param).toString(2);
					  else if (pType == 'c') subst = String.fromCharCode(parseInt(param));
					  else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0;
					  else if (pType == 'u') subst = Math.abs(param);
					  else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param);
					  else if (pType == 'o') subst = parseInt(param).toString(8);
					  else if (pType == 's') subst = param;
					  else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase();
					  else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase();
				}
				str = leftpart + subst + rightPart;
			}
			return str;
}


function check_date( data ){

    data = trim(data);
    
    var regexpr = new RegExp('^([0-9]{4}([\-\.\/ ])[0-9]{2}\\2[0-9]{2})|([0-9]{2}([\-\.\/ ])[0-9]{2}\\4[0-9]{4})');
    
    if( !regexpr.test(data) ){

        return false;
    }

    var a_data = split_date( data );
    
    
    rok = toInt(a_data[0]) ;
    mies = toInt(a_data[1]);
    dzien = toInt(a_data[2]);
    
    if( mies < 1 ||  mies > 12  ){
        return false;
    }
    
    var miesiace = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
    
    if( mies == 2 ){
        if( rok % 100 == 0  ){
            if( rok % 400 == 0 ){
                miesiace[2] = 29;
            }
        }else if( rok % 4 == 0  ){
            miesiace[2] = 29;
        }
    }

    return (dzien <= miesiace[mies]);
}

function split_date( data ){

    separator = '-';
    if( match = data.match('/[^0-9]/') ){
        separator = match[0];
    }

    parts = data.split(separator) ;

    return (( parts[0].length == '4' ) ? parts : parts.reverse());
}

function date2int( data ){
    a_data = split_date(data);
    return parseInt( a_data[0] + "" + a_data[1] + a_data[2] );
}


function check_pesel( pesel, err){
    pesel = trim(pesel);
    if(arguments.lengt < 2 ){
        err = new Object();
    }
    if( !pesel.match( /^[0-9]{11}$/ ) ){
        err.msg = lang['pesel_bledny_format'];
        return false;
    }

    var wagi = [1,3,7,9,1,3,7,9,1,3];
    var suma = 0;
    var i = 0;

    for ( i = 0; i < 10; i++){
        suma += parseInt(pesel.charAt(i)) * wagi[i];
    }

    var liczba = 10 - suma % 10;

    if (liczba == 10) liczba = 0;
   

    if ( parseInt(pesel.charAt(10) ) == liczba ){
        return true;
    }else{
        err.msg = lang['pesel_bledny_numer'];

        return false;

    }

}


function add_event(type, obj, fn, cpt){
  	if( obj == null ){
        return false;
    }

    if( type.substring(0,2).toLowerCase() == "on" ){
        type = type.substring(2);
    }

    obj[type + "_fun" ]  = fn;
    obj[type + "_cpt" ] = cpt;


    if (obj.addEventListener) {  // DOM Level 2 Event Model
        // Register capturing event handlers
        obj.addEventListener(type, obj[type + "_fun"], cpt);
    } else if (document.attachEvent) {  // IE 5+ Event Model
        // In the IE Event model, we can't capture events, so these handlers
        // are triggered when only if the event bubbles up to them.
        // This assumes that there aren't any intervening elements that
        // handle the events and stop them from bubbling.
        obj.attachEvent("on" + type, obj[type + "_fun"] );
    } else {// IE 4 Event Model
        // In IE 4 we can't use attachEvent(), so assign the event handlers
        // directly after storing any previously assigned handlers so they
        // can be restored.  Note that this also relies on event bubbling.
        obj["on" + type] =  function(){obj[type+fn](window.event)};
    }
}

function remove_event(type, obj){

    if( type.substring(0,2).toLowerCase() == "on" ){
        type = type.substring(2);
    }

    if( obj.detachEvent ){
  		  obj.detachEvent('on'+type, obj[type + "_fun"]);
  	}else if( obj.removeEventListener ) {
  		  obj.removeEventListener(type, obj[type + "_fun"], obj[type+ "_cpt"]);
  	}else{
        obj['on' + type] = function(){};
    }

    obj[type + "_fun"] = null;
}

function add2bookmark(){
    if(document.all){
        window.external.AddFavorite(location.href, document.title);
    }else if(window.sidebar){
        window.sidebar.addPanel(document.title, location.href, '');
    }else{
        alert( teksty['do_ulubionych_ctrld'] );
    }
}


function CreateBookmarkLink() {

 title = "Webpage Title";
  // Blogger - Replace with <$BlogItemTitle$>
  // MovableType - Replace with <$MTEntryTitle$>

 url = "Webpage URL";
  // Blogger - Replace with <$BlogItemPermalinkURL$>
  // MovableType - Replace with <$MTEntryPermalink$>
  // WordPress - <?php bloginfo('url'); ?>

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
}

function empty( mixed_var ) {
    var key;

    if (mixed_var === "" || mixed_var === 0 || mixed_var === "0" || mixed_var === null || mixed_var === false || mixed_var === undefined ){
        return true;
    }

    if (typeof mixed_var == 'object') {
        for (key in mixed_var) {
            if (typeof mixed_var[key] !== 'function' ) {
	            return false;
            }
        }
        return true;
    }
    return false;
}
