var ns = (document.layers) ? 1 : 0;
var ie = (document.all) ? 1 : 0;
var ns6= (!document.all && document.getElementById) ? 1 : 0;

var jest_flash = 0;
if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
    if (navigator.plugins && navigator.plugins["Shockwave Flash"])
        jest_flash = 1;
} else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.userAgent.indexOf("Windows 95")>=0 || navigator.userAgent.indexOf("Windows 98")>=0 || navigator.userAgent.indexOf("Windows NT")>=0)) {
    document.write('<SCRIPT LANGUAGE=VBScript\> \n');
    document.write('on error resume next \n');
    document.write('jest_flash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3")))\n');
    document.write('if ( jest_flash <= 0 ) then jest_flash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")))\n');
    document.write('if ( jest_flash <= 0 ) then jest_flash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7")))\n');
    document.write('if ( jest_flash <= 0 ) then jest_flash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8")))\n');
    document.write('</SCRIPT\> \n');
}
//jest_flash = 0;
function showLayer(id) {
  if(ie || ns6) {document.getElementById(id).style.visibility = 'visible';}
  else if (ns) { document.layers[id].visibility = 'visible';}
}
function hideLayer(id) {
  if(ie || ns6) {document.getElementById(id).style.visibility = 'hidden';}
  else if (ns) { document.layers[id].visibility = 'hide';}
}

function showMe(obj) {
  if(ie || ns6) {obj.style.visibility = 'visible';}
  else if (ns) { obj.visibility = 'visible';}
}
function hideMe(obj) {
  if(ie || ns6) {obj.style.visibility = 'hidden';}
  else if (ns) { obj.visibility = 'hide';}
}

function positionLayer(id,left,top) {
  if(ie) { 
	document.all[id].style.left = left;	
	document.all[id].style.top = top;	
  } else if (ns) { 
	document.layers[id].left = left;
	document.layers[id].top = top;
  } else {
	document.getElementById(id).style.left = left;
	document.getElementById(id).style.top = top;
  }
}
function change(id,img,warstwa)
{
 if(document.images)
 {
  if(ns) {
      warstwa ? document.layers[warstwa].document.images[id].src=img : document.images[id].src=img;
  } else {
  document.images[id].src=img;
  }
 }
}

function show1(url,title,w,h) {
	var url='window.php?img='+url+'&title='+title;
	var showWindow = window.open(url,"ShowWindow",'top=20,left=40,width='+w+',height='+h+',scrollbars=no');
	showWindow.focus();
}
function showWindow(url,w,h) {
	var showWindow = window.open(url,"ShowWindow",'top=20,left=40,width='+w+',height='+h+',scrollbars=no');
	showWindow.focus();
}
function position_logo() {
	if(ns) w = self.innerWidth;
	else if(ns6) w = document.getElementById('checkWidth').offsetLeft;
	else w = document.body.clientWidth;
	w = w/2 - 70;
	positionLayer('logo',w,40);
	showLayer('logo');
}
function addToFav(){
 if (navigator.appName =="Microsoft Internet Explorer") {
   window.external.AddFavorite(location.href, document.title);
 } else {
   //alert('Funkcja ta dostępna jest tylko dla przeglądarek IE.');
 }
}
function addHP(othis) {
 var ms = navigator.appVersion.indexOf("MSIE");
 var ie5 = (ms>0) && (parseInt(navigator.appVersion.substring(ms+5, ms+7)) >= 5);
 if(ie5) {
   othis.style.behavior='url(#default#homepage)';
   othis.setHomePage(location.href);
 } else {
   //alert('Funkcja ta dostępna jest tylko dla przeglądarek IE.');
 }
}

function writeToLayer(layer,value) {
	if(document.all){
		document.all[layer].innerHTML = value;
	} else {
		over = document.getElementById(layer);
		range = document.createRange();
		range.setStartBefore(over);
		domfrag = range.createContextualFragment(value);
		while (over.hasChildNodes()) {
			over.removeChild(over.lastChild);
		}
		over.appendChild(domfrag);
	}
}


function setCookie(name,value,tm){
    var expires = new Date();
    if(tm>0){
            expires.setTime(expires.getTime() + 1000*60*tm);
            expiryDate = expires.toGMTString();
            document.cookie = name+"="+value+"; expires="+ expiryDate;
    }else{
            document.cookie = name+"="+value+"; expires=";
    }
}	

function getCookie(name){
    var cookieFound = false, start = 0, end = 0;
    var cookieString = document.cookie;
    var i = 0;
                                                                                                                        
    while(i<=cookieString.length){
            start = i;
            end = start + name.length;
            if(cookieString.substring(start,end) == name){
                    cookieFound = true;
                    break;
            }
            i++;
    }
    if(cookieFound){
            start = end + 1;
            end = document.cookie.indexOf(";",start);
            if(end < start){
                    end = document.cookie.length;
            }
            return document.cookie.substring(start,end);
    }
    return "";
}

function hideTopLayer(){
	document.all["toplayer"].style.visibility="hidden";
	document.all["search_form"].style.visibility="visible";
}


function getWidth() {
  var myWidth = 0
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && document.documentElement.clientWidth ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && document.body.clientWidth ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  if(!document.all) myWidth -= 18;//for mozilla

  return myWidth;
}