// JavaScript Document
// USTAWIANIE POPRAWNEJ WERSJI DOM
function ustawDOM(idname){
	if (document.getElementById)
		{ return document.getElementById(idname); }
	else if (document.all) 
		{ return document.all[idname]; }
	else if (document.layers)
		{ return document.layers[idname]; }
	else
		{ return null; }
}
function navi(){
		dom_source = new ustawDOM('navi_temp');
		dom_dest = new ustawDOM('paging');
		dom_dest.innerHTML = dom_source.value;
}

function get_cookie(Name) {
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
			if (offset != -1) {
				offset += search.length
				end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset, end))
			}
	}
	return returnvalue;
}

function wyswietlanie_div(tabelka, eff){
var v = 0;
var div_id = tabelka;
var dom = new ustawDOM(tabelka);
		if( (Element.getStyle(tabelka, 'display') == 'block') && (v == 0) ){
			new Effect.BlindUp(tabelka)
			document.cookie=div_id+"= none";
			var v = 1;
		}

		else if( (Element.getStyle(tabelka, 'display') == 'none') && (v == 0) ){
			new Effect.BlindDown(tabelka);
						document.cookie=div_id+"= block";
			var v = 1;
		}
new Ajax.Updater('', 'inc/a_menu_sesje.php', {asynchronous:true});
}

function tree_chowaj(ID){
var dom = new ustawDOM(ID);
    var styleObject;
    styleObject = getStyleById(ID);
		if(styleObject.display == 'block'){
			styleObject.display = "none";
		}
		else if(styleObject.display == 'none'){
			styleObject.display = "block";
		}
}

function lang_sw(lang){
var dom = new ustawDOM('tmp_lang');
dom.lang.value = lang;
dom.submit();
}

function getStyleById(idName){
    if (document.getElementById){
       return document.getElementById( idName ).style;
   }
   else if (document[idName]){
      return (document[idName]) ? document[idName] : null;
   }
   else if (document.all){
        return document.all[idName].style;
    }
}
function dzien() {
	teraz = new Date(); 
	teraz = teraz.getDay();
	if (teraz==0) document.write("Niedziela") ;
	if (teraz==1) document.write("PoniedziaL‚ek") ;
	if (teraz==2) document.write("Wtorek") ;
	if (teraz==3) document.write("Lšroda") ;
	if (teraz==4) document.write("Czwartek") ;
	if (teraz==5) document.write("PiÄ…tek") ;
	if (teraz==6) document.write("Sobota") ;
}	
function data() {
	dzisiaj = new Date(); 
	miesiac = dzisiaj.getMonth()+1 ;
	dzien = dzisiaj.getDate() ;
	if (dzien<10) dzien="0"+dzien; 
	if (miesiac<10) miesiac="0"+miesiac; 
	document.write(dzien+"-"+miesiac+"-"+dzisiaj.getYear()) ;
}
window.onmousedown = rightClick;
document.onmousedown = rightClick;
function rightClick(e) {
  //if ((document.layers && e.which == 3) || (document.all && event.button==2)) { alert("Secure site !!!"); return false; }
return true;
}

var marked_row = new Array;

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    }
    if (currentColor.indexOf("rgb") >= 0) 
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    }
    if (newColor) {
        var c = null;
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            }
        }
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    }

    return true;
}
function powieksz(id){
	var textarea = ustawDOM(id);
	var newrows = parseInt(textarea.style.height.replace('px', ''))+50;
	if (newrows >= 50)
	{
		textarea.style.height = newrows+'px';
	}
	return false;
}
function zmniejsz(id){
	var textarea = ustawDOM(id);
	var newrows = parseInt(textarea.style.height.replace('px', ''))-50;
	if (newrows >= 5)
	{
		textarea.style.height = newrows+'px';
	}
}
function licznik_znakow(co,gdzie,text,ile_znakow) {
  var coObj = ustawDOM(co);
  var gdzieObj = ustawDOM(gdzie);
  var longitud = ile_znakow - coObj.value.length;
//  if(longitud <= 0) {
//    longitud = 0;
    texto = '<span class="small-text"> '+text+' </span>';
    coObj.value=coObj.value.substr(0,ile_znakow);
//  }
  gdzieObj.innerHTML = texto.replace("{CHAR}",longitud);
}
// timeot sesji
function countdown_clock(Target_Date, Todays_Date)
         {
         html_code = '<span id="countdown"></span>';
         document.write(html_code);
         countdown(Target_Date, Todays_Date);                
         }
         
function countdown(Target_Date, Todays_Date)
         {
		 var dom = new ustawDOM('countdown')
         Time_Left = Math.round(Target_Date - Todays_Date);
         
         if(Time_Left < 0)
            Time_Left = 0;
         
                    days = Math.floor(Time_Left / (60 * 60 * 24));
                    Time_Left %= (60 * 60 * 24);
                    hours = Math.floor(Time_Left / (60 * 60));
                    Time_Left %= (60 * 60);
                    minutes = Math.floor(Time_Left / 60);
                    Time_Left %= 60;
                    seconds = Time_Left;
					if( (minutes == '0') && (seconds == '0') ){
						alert("Wykryto brak aktywnoL›ci. Sesja zostaL‚a zakoL„czona. Wymagane jest ponowne zalogowanie!");
						window.location.replace('index.php');
					}
					else{
			         setTimeout('countdown(' + Math.floor(Target_Date - 0.6) + ',' + Todays_Date + ');', 1000);

					}
         }
function logout(){
var dom = new ustawDOM('logout_form')	
	if ( confirm("Uwaga!!! Czy na pewno chcesz siÄ™ wylogowaÄ‡?.") ) {
		dom.submit() ;
	}
}
function generator(pole) {
	var dom = new ustawDOM(pole);
    var dlugosc=8;
    var haslo = "";
    for (i=0; i < dlugosc; i++) {
        znak = RandZnak();
     while (sprawdz(znak)) { znak = RandZnak(); } 
        haslo = haslo + String.fromCharCode(znak);
    }
    dom.value = haslo
    return true;
}

function RandZnak() {
    var rndZnak = Math.random()
    rndZnak = parseInt(rndZnak * 1000);
    rndZnak = (rndZnak % 94) + 33;
    return rndZnak;
}
function sprawdz(znak) {
    if ((znak >=33) && (znak <=47)) { return true; }
    if ((znak >=58) && (znak <=64)) { return true; }
    if ((znak >=91) && (znak <=96)) { return true; }
    if ((znak >=123) && (znak <=126)) { return true; }
    return false;
}

function bread(tresc){
var dom = new ustawDOM('breadcrump');
dom.innerHTML = tresc;
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function getStyleById(objectId) {
    if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	return document.layers[objectId];
    } else {
	return false;
    }
} 