//Karol Tyl
//kartyl@gmail.com

function rozwinMenu(id) {
    e = document.getElementById('pozycjaMenu' + id);
    if (e.style.display == 'block') {
        e.style.display = 'none';
        e = e.parentNode;
        e = e.getElementsByTagName('img').item(0);
        e.src = '_img/arrow_red.gif';
        return;
    }
    e = document.getElementById('lewy');
    e = e.getElementsByTagName('div');
    for (i=0; i < e.length; i++) {
        el = e.item(i);
        if (el.tagName != 'DIV') {
            continue;
        }
        div = el.getElementsByTagName('div');
        div = div.item(0);
        if (div == null || div.parentNode.parentNode.id != 'lewy') {
            continue;
        }
        img = el.getElementsByTagName('img');
        img = img.item(0);
        if (el.id == 'grupaMenu'+id) {
            div.style.display = 'block';
            if (img != null) {
                img.src = '_img/arrow_red_down.gif';
            }
        } 
        /*
         * Ponizszy kawalek kodu odpowiada za chowanie pozostalych pozycji menu
         * oprocz tej na ktora kliknal uzytkownik
    	 */
        /* else {
            div.style.display = 'none';
            if (img != null) {
                img.src = '_img/arrow_red.gif';
            }
        }*/
    }
}

var szukajFocusPierwszy = true;

function szukajFocus(id) {
    
    el = document.getElementById(id);
    if (el == null) {
        return;
    }
    if (szukajFocusPierwszy) {
        el.value='';
        szukajFocusPierwszy = false;
    }
    el.select();
}


//wst�pne za�adowanie obrazk�w
var preloadFlag = false;
var menuHidden = false;
var images = new Array (
        'arrow_red.gif',
        'arrow_red_down.gif'
    )

function newImage(arg) {
    if (document.images) {
	    res = new Image();
		res.src = arg;
		return res;
	}
}

function preloadImage(element, index, array) {
    img = newImage('_img/' + element);
}

function init() {
    if (!preloadFlag) {
        focus();
		if (document.images) {
		    for (i=0; i<images.length; i++) {
    		    preloadImage(images[i]);
    		}
		}
        preloadFlag = true;
    }
}

document.onload = init();

function dogoryin() {
    document.getElementById('dogory1').style.display="inline";
    document.getElementById('dogory2').style.display="inline";
}

function dogoryout() {
    document.getElementById('dogory1').style.display="none";
    document.getElementById('dogory2').style.display="none";
}

function changeKadencja(loc, id_menu) {
    k=document.getElementById('kadencja').value;
    window.location.href=loc + '?id=26&p0=szczegoly&p1='+id_menu+'&p2=' + k;
}

function changeKadencjaListaOsob(loc, id_menu) {
    k=document.getElementById('kadencja').value;
//    alert(id_menu);
//    alert(k);
    window.location.href=loc + '?id=' + id_menu + '&kadencja=' + k;
}

var window_tab = new Array();
function popup(dest, title) {    
	if(!window_tab[dest])
	{
		window_tab[dest] = window.open(dest,'_blank' ,"menubar=yes,scrollbars=yes,width=430,height=450,toolbar=no,resizable=yes");
	}
	if(!window_tab[dest].closed)
	   window_tab[dest].focus();
   	else if(window_tab[dest].closed){
   		window_tab[dest] = window.open(dest,'_blank' ,"menubar=yes,scrollbars=yes,width=430,height=450,toolbar=no,resizable=yes");
   	}
}

function showHide(link) {
	var stan = document.getElementById('inne_stanowiska').style.display;
	
	if (stan=='none'){
		document.getElementById('inne_stanowiska').style.display = '';
		link.innerHTML='Ukryj inne stanowiska';
	}
	else{
		document.getElementById('inne_stanowiska').style.display = 'none';
		link.innerHTML='Pokaż inne stanowiska';
	}
	
}

function eformularz_iframe(id, address)
{
    var ifr = document.getElementById(id);
    ifr.src = address;
    ifr.style.height = "500px";
    ifr.style.display = "block";
}

function maxLength3(o,v,m){
  if(o.value.length>m)
    document.getElementById(v).innerHTML=
      ((o.value=o.value.substr(0,m)).length);
}

function pokazOswiadczenia(id, obj){

if($('#'+id+'_t').css('display') == 'none'){
	$('#'+id+'_t').show();
	$('#'+id+'_d').hide();
	$(obj).html('Ukryj oświadczenia');
}
else{
	$('#'+id+'_t').hide();
	$('#'+id+'_d').show();
	$(obj).html('Pokaż oświadczenia');

}
}
