function SetFocus() {
}

function SetFocus_old() {
  if (document.forms.length > 0) {
    var field = document.forms[formularz];
    for (i=0; i<field.length; i++) {
      if ( (field.elements[i].type != "image") &&
           (field.elements[i].type != "hidden") &&
           (field.elements[i].type != "reset") &&
           (field.elements[i].type != "submit") ) {

        document.forms[0].elements[i].focus();

        if ( (field.elements[i].type == "text") ||
             (field.elements[i].type == "password") )
          document.forms[0].elements[i].select();

        break;
      }
    }
  }
}

function rowOverEffect(object) {
  if (object.className == 'dataTableRow') object.className = 'dataTableRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'dataTableRowOver') object.className = 'dataTableRow';
}

function toggleDivBlock(id) {
	if (document.getElementById) {
		itm = document.getElementById(id);
	} else if (document.all){
		itm = document.all[id];
	} else if (document.layers){
		itm = document.layers[id];
	}
		
	if (itm) {
		if (itm.style.display != "none") {
			itm.style.display = "none";
		} else {
			itm.style.display = "block";
		}
	}
}

var gsFieldToUpdate = "";

function openFileLibrary(vsFieldToUpdate){
	if(vsFieldToUpdate!="") {
		gsFieldToUpdate = vsFieldToUpdate;
	}
	oFileLibraryWindow = window.open('includes/filebrowser/index.php','winFileLib','width=650,height=600,scrollbars=yes,resizable=yes,status=yes,titlebar=0');
	oFileLibraryWindow.focus();
} // end open_file_library

function insertPath(vsFilePath) {
	eval(gsFieldToUpdate+'.value = vsFilePath;');
}

//==========================================
// Check All boxes
//==========================================
function CheckAll(fmobj) {
  for (var i=0;i<fmobj.elements.length;i++) {
    var e = fmobj.elements[i];
    if ( (e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled) ) {
      e.checked = fmobj.allbox.checked;
    }
  }
}

//==========================================
// Check all or uncheck all?
//==========================================
function CheckCheckAll(fmobj) {
  var TotalBoxes = 0;
  var TotalOn = 0;
  for (var i=0;i<fmobj.elements.length;i++) {
    var e = fmobj.elements[i];
    if ((e.name != 'allbox') && (e.type=='checkbox')) {
      TotalBoxes++;
      if (e.checked) {
       TotalOn++;
      }
    }
  }
  if (TotalBoxes==TotalOn) {
    fmobj.allbox.checked=true;
  }
  else {
   fmobj.allbox.checked=false;
  }
}

function menu() {
  if (document.all) {
    var lists = document.getElementsByTagName("ul");  
    for (var i = 0; i < lists.length; i++) {
      if (lists[i].className == "menu") {
        var menu = lists[i];
        for (var j = 0; j < menu.childNodes.length; j++) {
          var submenu = menu.childNodes[j];
          if (submenu.nodeName == "LI") {
            submenu.onmouseover = function() {
              this.className += " over";
            }
            submenu.onmouseout = function() {
              this.className = this.className.replace(" over", "");
            }
          }
        }
      }
    }
  }
}


function close_div_okno() {
document.getElementById('pop_window').innerHTML = '';
document.getElementById('pop_overlay').style.display = 'none';
document.getElementById('blad').style.display = 'none';
document.getElementById('ekran').style.display = 'none';
}

function okno(tekst) {
document.getElementById('blad').style.display='block';
document.getElementById('pop_overlay').style.display = 'block';
document.getElementById('ekran').style.display = 'block';	
document.getElementById('ekran').innerHTML = "<div id='pop_window' style='display:block;position:absolute; top:25%; left:50%; margin-left:-175px; font-size:20px; z-index:9999;'>"+
   "<table style='background-color:#ffffff;border:1px solid #000000;' width='350px' cellpadding='5' cellspacing='0'><tr><td style='background-color: #333344;border-bottom: 2px solid #000000;border-top: 1px solid #78A3F2;border-left: 1px solid #78A3F2;border-right: 1px solid #204095;' align='center'>"+
   "<table width='98%' border='0' cellpadding='0' cellspacing='0'><tr><td width='50%' align='left' style='font: bold 13px tahoma,arial, sans-serif; color:#ffffff'>UWAGA</td><td width='50%' align='right'>"+
   "<img src='popupbox/close.gif' border='0' style='cursor:pointer' onclick='javascript:close_div_okno()'></td></tr></table></td></tr><tr><td>"+				
   "<center><p style='font: bold 17px tahoma,arial, sans-serif; color:#FF0000'>Komunikat</p></center>"+				
   "<center><p style='font: normal 11px tahoma,arial, sans-serif; color:#616161'>"+tekst+"</p></center><br>&nbsp;"+			
   "<input type='button' value='Zamknij' onclick='javascript:close_div_okno();'>"+
   "</td></tr></table></div>"
}

var tooltip=function(){
	var id = 'tt';
	var top = 10;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				//t = document.createElement('div');
				//t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				//b = document.createElement('div');
				//b.setAttribute('id',id + 'bot');
				//tt.appendChild(t);
				tt.appendChild(c);
				//tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';  
            c.innerHTML = '<span style="color:#fff;font-size:10px;font-family:tahoma;">... wczytuje ...</span>';
            //
            try {
              xml = new ActiveXObject("Microsoft.XMLHTTP"); // IE
            } catch(e) {
            try {
              xml = new XMLHttpRequest(); // Mozilla/FireFox/Opera
            } catch(e) {
              xml = null;
            }
            }
            if (xml != null) {
                xml.open("GET", "display_order.php?q="+v, true);
                xml.onreadystatechange=function() {
                  if (xml.readyState==4) {
                    c.innerHTML = xml.responseText;
                  }
                }
                xml.send(null)
            }
                        
			//c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				//t.style.display = 'none';
				//b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				//t.style.display = 'block';
				//b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.body.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.body.scrollLeft : e.pageX;
			tt.style.top = (u - 100) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();