// 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 sz(t) {
a = t.value.split('\n');
b=1;
for (x=0;x < a.length; x++) {
 if (a[x].length >= t.cols) b+= Math.floor(a[x].length/t.cols);
 }
b+= a.length;
if (b > t.rows) t.rows = b;
}

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 show_hide2(id_obiektu){

    var el = document.getElementById(id_obiektu);

    if( el.scrollHeight && el.scrollHeight > 0 ){
        el.style.display = 'none';
    }else{
        el.style.display = '';
    }
}
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(img_el, el_id){
    var el = document.getElementById(el_id);
    var sciezka = new String(img_el.src);

    
    if( el.scrollHeight && el.scrollHeight > 0 ){
        el.style.display = 'none';
        img_el.src = sciezka.replace(/minus/, 'plus');
    }else{
        el.style.display = 'block';
        img_el.src = sciezka.replace(/plus/, 'minus');
    }

}
function zwin_rozwin3(img_el, el_id){
    var el = document.getElementById(el_id);
    var sciezka = new String(img_el.src);

    
    if( el.scrollHeight && el.scrollHeight > 0 ){
        el.style.display = 'none';
        img_el.src = sciezka.replace(/minus/, 'plus');
    }else{
        el.style.display = '';
        img_el.src = sciezka.replace(/plus/, 'minus');
    }

}
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');

  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 ) - 200;
    obj.style.position = 'absolute';
    obj.style.top  = document.body.scrollTop + parseInt( (winH - height) / 2 ) - 200;
    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 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('Aby dodać strone do ulubionych wciśnij CTRL+D');

}


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; }
}






///////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////                STRESZCZENIA                 //////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////



var autorzy = [];
var afiliacje = [];

var o_autor_div = null;

function show_autor_form(autor_num){

    if( arguments.length == 0 ){
        autor_num = autorzy.length;
    }

/******************************************************************************/

    var f = document.forms['abstract_autor_form'];

    f.elements['autor_num'].value = autor_num;


    var afiliacja_num = 0;
    if( autorzy[autor_num] && autorzy[autor_num].imie ){
        f.elements['imie'].value = autorzy[autor_num].imie;
        f.elements['nazwisko'].value = autorzy[autor_num].nazwisko;
		f.elements['email'].value = autorzy[autor_num].email;
    }


/******************************************************************************/
   // hide_selects();

    try{showTlo();}catch(e){/*ignore errors*/}

    if(!o_autor_div) {
        o_autor_div = document.getElementById( 'autor_div' );
    }
    center_both_obj( o_autor_div );

    f.elements['imie'].focus();
}
function hide_selects(){
    document.forms['StreszczeniaAdminAddForm'].elements['topic'].style.visibility = 'hidden';
}

function show_selects(){
    document.forms['StreszczeniaAdminAddForm'].elements['topic'].style.visibility = 'visible';
}

function check_email( email ){
    var reg_expr = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,3})$/;
    return reg_expr.test(email);
}



function anuluj_autor(){

    var f = document.forms['abstract_autor_form'];

    f.elements['imie'].value = '';
    f.elements['nazwisko'].value = '';
	f.elements['email'].value = '';
    f.elements['autor_num'].value = '';

    hide_obj(o_autor_div);

    try{hideTlo();}catch(e){}
    
    //show_selects();
}
function add_edit_autor( f ){
    if( arguments.length == 0 ){
         f = document.forms['abstract_autor_form'];
    }
    
    var autor_num = parseInt(f.elements['autor_num'].value);
    var imie, nazwisko, afiliacja_num = '';

    if( isNaN(autor_num) || !autor_num){
      autor_num = 0;
    }

    imie = trim(f.elements['imie'].value);
    nazwisko = trim(f.elements['nazwisko'].value);
	email = trim(f.elements['email'].value);
    if( imie == "" ){
        alert("Please enter authors name");
        return false;
    }
    
    if( nazwisko == "" ){
        alert("Please enter authors name");
        return false;
    }
    if( check_email(email) == false ){
	alert('Please enter valid email address');
	return false;
	}
    if( autorzy[autor_num] ){
        autorzy[autor_num].imie =  imie;
        autorzy[autor_num].nazwisko =  nazwisko;
		autorzy[autor_num].email =  email;
    }else{
        autorzy[autor_num] = { 'imie': imie, 'nazwisko': nazwisko,'email': email, 'afiliacje' : [] } ;
    }
    

    print_autorzy();
    anuluj_autor();
}

function print_autorzy(){
    var i = 0,k = 0;

    var stra, str = '';
    for( i= 0; i < autorzy.length; i++ ){
        stra = '';
        for( j = 0; j < autorzy[i].afiliacje.length; j++ ){
            stra += '[<sup>' + (parseInt(autorzy[i].afiliacje[j])+1) + '</sup>]'+
			'<input type="hidden" name="data[Authoraffiliation]['+k+'][affiliation_num]" value="'+autorzy[i].afiliacje[j]+'">' +
			'<input type="hidden" name="data[Authoraffiliation]['+k+'][author_num]" value="'+i+'">' ;k++;
        }
        
        //stra.substring(0, stra.length-1);
          
    
        str += '<div class="aa wiersz'+((i%2)+1)+'" >'+
        '<input type="hidden" name="data[Abstractauthor]['+i+'][sname]" value="'+autorzy[i].nazwisko+'">'+
        '<input type="hidden" name="data[Abstractauthor]['+i+'][fname]" value="'+autorzy[i].imie+'">'+
		'<input type="hidden" name="data[Abstractauthor]['+i+'][email]" value="'+autorzy[i].email+'">'+
		'<input type="hidden" name="data[Abstractauthor]['+i+'][num]" value="'+i+'">'+
        '<input type="button" value="Edit" onclick="show_autor_form('+ i +')" style="float:right"> '+
        '<input type="button" value="Delete" onclick="delete_autor('+ i +')" style="float:right">'+ (i+1) +'. ' + autorzy[i].imie +' '+autorzy[i].nazwisko + ' '+stra+' </div>\n';
    }

    el = document.getElementById('autorzy_div');
    el.innerHTML = str;
}
function delete_autor( num ){

    if(num < autorzy.length){
        autorzy.splice(num, 1);
        
        var indeks = 0;

        for( var i = 0;  i < afiliacje.length; i++ ){
            indeks = -1;
            
            for( var j = 0;  j < afiliacje[i].autorzy.length; j++ ){
                if( afiliacje[i].autorzy[j] == num ){
                    indeks = j;
                }else if( afiliacje[i].autorzy[j] > num ){
                    afiliacje[i].autorzy[j] = afiliacje[i].autorzy[j] -1;
                }
            }
            if( indeks != -1 ){
                afiliacje[i].autorzy.splice(indeks, 1);
            }
        }
    }

    print_autorzy();
    
}
var o_affiliation_autors_div = null
var o_afiliacja_div = null;
function show_afiliacja_form( afiliacja_num ){
    if( autorzy.length == 0 ){
        alert('Please add authors first!');
        return false;
    }
    
    if( arguments.length == 0 ){
        afiliacja_num = afiliacje.length;
    }

    el = document.getElementById('afiliacja_div');


/******************************************************************************/

    var f = document.forms['abstract_afiliacja_form'];

    afiliacja_autorzy = new Array();

    f.elements['afiliacja_num'].value = afiliacja_num;
    
    if( afiliacja_num != afiliacje.length ){
        f.elements['afiliacja'].value = afiliacje[afiliacja_num].nazwa;
        afiliacja_autorzy = afiliacje[afiliacja_num].autorzy;
    }
/******************************************************************************/
    if( !o_affiliation_autors_div ){
        o_affiliation_autors_div = document.getElementById('affiliation_autors_div');
    }

    var html = '';
    for( var  i = 0; i < autorzy.length; i++ ){
        html += '<label> <input type="checkbox" class="checkbox" name="afiliacja_autorzy['+i+']" value="1" '+ ( (check_array(i,afiliacja_autorzy) != -1) ? 'checked' : '') +'> '+autorzy[i].imie+' '+autorzy[i].nazwisko+' </label><br>\n';
    }
    o_affiliation_autors_div.innerHTML = html;

/******************************************************************************/
   // hide_selects();

    try{
        showTlo();
    }catch(e){
        //ignore errors
    }

    if(!o_afiliacja_div) {
        o_afiliacja_div= document.getElementById( 'afiliacja_div' );
    }
    center_both_obj( o_afiliacja_div);
    
    f.elements['afiliacja'].focus();
}

function anuluj_afiliacja(){

    var f = document.forms['abstract_afiliacja_form'];

    f.elements['afiliacja'].value = '';
    f.elements['afiliacja_num'].value = '';

    hide_obj(o_afiliacja_div);
    
    try{
      hideTlo();
    }catch(e){ }

    //show_selects();
}
function check_array(index,tab)
{
	 var return_value = -1;
    
    for ( var i = 0; i < tab.length; i++) {
        if( tab[i] == index) {
            return_value = i;
            break;
        }
    }

    return return_value;

}
Array.prototype.in_array = function(searchStr) {
    var return_value = -1;
    
    for ( var i = 0; i < this.length; i++) {
        if( this[i] === searchStr) {
            return_value = i;
            break;
        }
    }

    return return_value;
}
function add_edit_afiliacja( f ){
    if( arguments.length == 0 ){
         f = document.forms['abstract_afiliacja_form'];
    }
    var afiliacja_num = parseInt(f.elements['afiliacja_num'].value);
    
    if( isNaN(afiliacja_num) || !afiliacja_num ){
        afiliacja_num = 0;
    }

    if( trim( f.elements['afiliacja'].value ) == "" ){
        alert( lang.podaj_nazwe_afiliacji);
        return;
    }
    
    var afiliacja_autorzy = new Array();
    var index = -1;
    for( var i =0;  i < autorzy.length; i++ ){
        if( f.elements['afiliacja_autorzy['+i+']'] && f.elements['afiliacja_autorzy['+i+']'].checked ){
            afiliacja_autorzy.push( i );

            if( (index = check_array(afiliacja_num,autorzy[i].afiliacje)) == -1 ){
			if(autorzy[i].afiliacje == '')autorzy[i].afiliacje = new Array();
                autorzy[i].afiliacje.push( afiliacja_num );
                autorzy[i].afiliacje.sort();
            }


        }else if( (index =check_array( afiliacja_num,autorzy[i].afiliacje )) != -1 ){
            autorzy[i].afiliacje.splice( index, 1);
        }
    }

    if( afiliacja_autorzy.length == 0 ){
        alert("Please select author's name.");
        return;
    }
    
    afiliacje[afiliacja_num] ={
        'nazwa' : f.elements['afiliacja'].value,
        'autorzy' : afiliacja_autorzy
    }
      
    print_afiliacje();
    
    print_autorzy();
    
    anuluj_afiliacja();
}
function print_afiliacje(){
    var i = 0;

    var str = '';
    for( i= 0; i < afiliacje.length; i++ ){
        stra = '';

        str += '<div class="aa wiersz'+((i%2)+1)+'" >'+
        '<input type="button" value="Edit" onclick="show_afiliacja_form('+ i +')" style="float:right"> '+
        '<input type="button" value="Delete" onclick="delete_afiliacja('+ i +')" style="float:right"> '+
		'<input type="hidden" name="data[Abstractaffiliation]['+i+'][num]" value="'+i+'">' +
        stra + '<input type=hidden name="data[Abstractaffiliation]['+i+'][affiliation]" value="'+afiliacje[i].nazwa+'">'+ (i+1) +'. ' + afiliacje[i].nazwa + '  </div>\n';
    }

    el = document.getElementById('afiliacje_div');
    el.innerHTML = str;
}

function delete_afiliacja( num ){

    if(num < afiliacje.length){
        afiliacje.splice( num, 1);

        var indeks = 0;
        
        for( var i = 0;  i < autorzy.length; i++ ){
            if( (indeks =  check_array(num ,autorzy[i].afiliacje)) != -1 ){
                autorzy[i].afiliacje.splice( indeks, 1 );
            }
        }
        
        print_autorzy();

        print_afiliacje();
    }
}

////////////////////////////////////////////////////////////////////////////////
///////////////////////////////REJESTRACJA//////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
  var feestable = [];
  
	function set_payment(val, id, col, data){
	  //console.log('val :' +val+ ',id:'+id+',col:'+col+',data:' + data);
	  //console.log(feestable);

    var $el, bg_color;

    var oplaty = [
        [0, 0],
        [0, 0],
        [0, 0],
        [0, 0]
    ];
    
		for( i = 0; i < 4; i++){
  			for( j = 0; j < 2; j++ ){
            $el = jQuery("#" + i + "" + j);

            if ( $el.length ) {
                bg_color = $el.css('background-color');
                oplaty[i][j] = ( (bg_color == '#deeaf5' || bg_color == 'rgb(222, 234, 245)' ) ? true : false);
                $el.css('backgroundColor', "#ffffff");
            }
  			}
		}
		//console.log(oplaty);
		
		var workshop = oplaty[3][0] || oplaty[3][1];
    var reg_fee = false, reg_fee_i = -1, reg_fee_j = -1;
		for( i = 0; i < 2; i++){
  			for( j = 0; j < 2; j++ ){
          if( oplaty[i][j] ){
              reg_fee = "" + i + "" + j;
              reg_fee_i = i;
              reg_fee_j = j;
          }
        }
    }

		var os_tow = false;

		if( document.forms['UserRegisterForm'].elements['data[User][companion]'] ){
        if( document.forms['UserRegisterForm'].elements['data[User][companion]'].value.replace('/^s+/', '').replace('/s+$/', '') != '' ){
            os_tow = true;
        }
    }
    //console.log('os_tow:' +os_tow);
    var kwota = 0;
    if ( (id == "20" || id == "21" ) && document.forms['UserRegisterForm'].elements['data[User][payment_id]'].value != '' ){
        id = document.forms['UserRegisterForm'].elements['data[User][payment_id]'].value;

        if ( id.substring(1,2) != col ){
            id = id.substring(0,1) + "" + col;
        }
    }
    var row = id.substring(0, 1);
    //console.log(feestable[row]['Payprice']);
    val = parseFloat(feestable[row]['Paytime'][col]['Payprice']['price']);
    //workshop
    

    if ( row == 3 ){
        if ( reg_fee ){
            kwota += parseFloat(feestable[reg_fee_i]['Paytime'][col]['Payprice']['price']);
            document.getElementById(reg_fee_i + "" + col).style.backgroundColor = "#deeaf5";
        }

        if ( !oplaty[row][col] ) {
            kwota += parseFloat(feestable[3]['Paytime'][col]['Payprice']['price']);;
            document.getElementById(3 + "" + col).style.backgroundColor = "#deeaf5";
        }
    } else {
        if ( row != 2 ){
            kwota = val;
            document.getElementById(id).style.backgroundColor = "#deeaf5";
        }
        
        if ( workshop ) {
            document.getElementById(3 + "" + col).style.backgroundColor = "#deeaf5";
            kwota += parseFloat(feestable[3]['Paytime'][col]['Payprice']['price']);
        }
        
        document.forms['UserRegisterForm'].elements['data[User][payment_id]'].value = id;
    }
    
    if ( (reg_fee_i == 1 && row != 0) || row == 1 ) {
        //document.getElementById(3 + "" + col).style.backgroundColor = "#deeaf5";
        jQuery('#student_form_link').slideDown('slow');
        document.forms['UserRegisterForm'].elements['data[User][student]'].value = '1';
    }else{
        jQuery('#student_form_link').slideUp('slow');
        document.forms['UserRegisterForm'].elements['data[User][student]'].value= '';
    }


    if ( os_tow ) {
        kwota += parseFloat(feestable[2]['Paytime'][col]['Payprice']['price']);
        document.getElementById("2" + parseInt(col)).style.backgroundColor = "#deeaf5";
		}
		
		document.getElementById("kwota").value = kwota;
    document.getElementById("reg_oplata_termin").value = col;
	}
	
	function reg_fee(typ,osoba)
	{
		var tabele = document.getElementsByName("osoby_tow");
		for(i=0;i<tabele.length;i++)
			tabele[i].style.display = "none";
		document.getElementById(typ + '' + osoba).style.display = "";
		document.getElementById("reg_fees").value = typ + "=" + 1;
	}
	function show_osoba(value,okres)
	{
		var tabele = document.getElementsByName("osoba");
		for(i=0;i<tabele.length;i++)
			tabele[i].style.display = "none";
		document.getElementById(value + '' + okres).style.display = "";
		
	}
	function show_faktura(val)
	{
		if(val==0)
			document.getElementById("faktura").style.display = "none";
		else 
			document.getElementById("faktura").style.display = "";
	
	}

