function ScrollText(text,seed)
{
	var msg = text;
	var out = " ";
	var c   = 1;
	if (seed > 100)
	{
		seed--;
		var cmd="ScrollText(\"" + msg + "\"," + seed + ")";
		timerTwo=window.setTimeout(cmd,100);
	}
	else if (seed <= 100 && seed > 0)
	{
		for (c=0 ; c < seed ; c++)
		{
			out+=" ";
		}
		out+=msg;
		seed--;
		var cmd="ScrollText(\"" + msg + "\"," + seed + ")";
		window.status=out;
		timerTwo=window.setTimeout(cmd,100);
	}
	else if (seed <= 0)
	{
		if (-seed < msg.length)
		{
			out+=msg.substring(-seed,msg.length);
			seed--;
			var cmd="ScrollText(\"" + msg + "\"," + seed + ")";
			window.status=out;
			timerTwo=window.setTimeout(cmd,100);
		}
		else
		{
			var cmd="ScrollText(\"" + msg + "\",100)";
			window.status=" ";
			timerTwo=window.setTimeout(cmd,75);
		}
	}
}

function obetnij_spacje(Str)
{
	dlugosc=Str.length;
	while (Str.slice(0,1) == " ")
	{
		 Str = Str.substr(1,dlugosc-1);
	 	 dlugosc = Str.length
	}
	while (Str.slice(dlugosc-1,dlugosc)== " ")
	{
	 	 Str = Str.substr(0,dlugosc-1);
	 	 dlugosc = Str.length
 	}
	return Str;
}

function blank(pole)
{
	return (pole=="");
}

function search()
{
	if (blank(obetnij_spacje(sz.search_txt.value)))
	{
		sz.search_txt.value='szukaj...';
		sz.op.value='';
	}
	else
		sz.op.value='o';
}

function test()
{
	search()
	ok = true;
	if ((!sz.op.value.length)||blank(obetnij_spacje(sz.search_txt.value)))
		ok=false; //szukana nazwa
	(ok==true)?sz.submit():alert("Wprowadź tekst, który chcesz wyszukać.");
	return false;
}

function zmien(obiekt,numer,link_nr)
{
	aid=document.getElementById(link_nr)
	if(numer>0) {
		obiekt.bgColor = '#FFFFFF';
		aid.style.color='#004185';
	}
	else {
		obiekt.bgColor = '#004185';
		aid.style.color='#FFFFFF';
	}
	return true;
}

function showimg(imgPath,imgFile,imgWidth,imgHeight,imgDescription,imgScale)
{
	//document.images.imgImg.src='/edytorimg_new/empty.gif';
	document.images.imgImg.width=137;
	document.images.imgImg.height=12;
	document.images.imgImg.src='/pimg/loading.gif';
	var MAX_MIN_WIDTH=640;
	var MAX_MIN_HEIGHT=480;
	imgW=imgWidth;
	imgH=imgHeight;
	imgS=imgScale;
	if ((imgS>0) && (parseInt(imgWidth)>MAX_MIN_WIDTH || parseInt(imgHeight)>MAX_MIN_HEIGHT)) {
		dXY = Math.min(MAX_MIN_WIDTH/imgWidth,MAX_MIN_HEIGHT/imgHeight);
		imgW = parseInt(imgWidth*dXY);
		imgH = parseInt(imgHeight*dXY);
		//alert ("imgWidth="+imgWidth+", imgHeight="+imgHeight+"\nimgW="+imgW+", imgH="+imgH);
	}
	else
		imgS=0;

	//Odległość od lewej krawędzi
	if (imgW<document.body.clientWidth)
		document.all.imgTable.style.left=document.body.scrollLeft+((document.body.clientWidth)/2)-(imgW/2)-5;
	else
		document.all.imgTable.style.left=document.body.scrollLeft+5;

	//Odległość od góry
	if (imgH<document.body.clientHeight)
		document.all.imgTable.style.top=document.body.scrollTop+((document.body.clientHeight)/2)-(imgH/2)-15;
	else
		document.all.imgTable.style.top=document.body.scrollTop+15;

	document.images.imgImg.width=imgW;
	document.images.imgImg.height=imgH;
	document.images.imgImg.src=imgPath+imgFile;
	document.all.imgFooter.width=imgW;
	document.all.imgTable.style.visibility='visible';

	imgHeader.innerHTML='<img hspace=1 vspace=1 align=right src=/edytorimg_new/close.gif alt="zamknij" style="cursor:pointer" onclick="imgTable.style.visibility=\'hidden\';imgTable2.style.visibility=\'hidden\';document.images.imgImg.src=\'/edytorimg_new/empty.gif\';hideIMG();">';
	//imgHeader.innerHTML='<img hspace=1 vspace=1 align=right src=/edytorimg_new/close.gif alt="zamknij" style="cursor:pointer" onclick="imgTable.style.visibility=\'hidden\';imgTable2.style.visibility=\'hidden\';document.images.imgImg.src=\'/pimg/loading.gif\';">';
	if (imgS>0) {
		imgHeader.innerHTML+='<img hspace=1 vspace=1 align=right src=/edytorimg_new/max.gif alt="Maksymalizuj" style="cursor:pointer" onclick="showimg(\''+imgPath+'\',\''+imgFile+'\','+imgWidth+','+imgHeight+','+imgDescription+',0);">';
	}
	//imgHeader.innerHTML+='<img src=/edytorimg_new/empty.gif height=13>Ilustracja&nbsp;<b>'+imgFile+'</b>';
	imgHeader.innerHTML+='Ilustracja';
	if (imgDescription>0)
		imgFooter.innerHTML=eval('imgDesc'+imgDescription+'.innerHTML');
	else {
		//Komentarz z treści dokumentu
		var str = document.body.innerHTML;
		var re1 = new RegExp('title=["?](.*?)["?](.*)'+imgFile+'(.*)', 'gi');//Jeśli wielowyrazowe, to w cudzysłowach
		var re2 = new RegExp('title=([^ ]+)(.*)'+imgFile+'(.*)', 'gi');//Jeśli jednowyrazowe, to bez cudzysłowów
		var a;
		if (!(a=re1.exec(str)))
			a=re2.exec(str);
		if (a) {
			imgFooter.innerHTML=""+a[1]+"";
		}
		else
			imgFooter.innerHTML="";
	}
	document.all.imgTable2.style.left=parseInt(document.all.imgTable.style.left)-1;
	document.all.imgTable2.style.top=parseInt(document.all.imgTable.style.top)-1;
	document.all.imgTable2.style.width=imgTable.clientWidth+5;
	document.all.imgTable2.style.height=imgTable.clientHeight+5;
	document.all.imgTable2.style.visibility='visible';
}

function hideIMG()
{
	document.all.imgTable2.style.left=0;
	document.all.imgTable2.style.width=0;
	document.all.imgTable.style.left=0;
	document.images.imgImg.width=0;
}

function rekom()
{
	var r_w = '';
	r_w = window.open("linki.php","linki","width=400,height=400,toolbar=no,menubar=no,scrollbars=yes");
	r_w.location.reload();
	r_w.focus();
//	window.open("/linki.php","linki","width=400,height=400,toolbar=no,menubar=no,scrollbars=yes");
}

function PokazUkryj(idObj, pokaz) 
{ 
nn6 = (document.getElementById) ? true:false; 
nn4 = (document.layers) ? true:false; 
ie4 = (document.all) ? true:false; 
//if ((nn6) && (ie4)) {nn6=null;} 
 
var attribV;
var attribD;
 if (nn6) {
  attribV = (pokaz) ? 'visible' : 'hidden';
  attribD = (pokaz) ? '' : 'none';
  document.getElementById(idObj).style.visibility=attribV; 
  document.getElementById(idObj).style.display=attribD;	
 } 
 else if (ie4){ 
    attribV = (pokaz) ? 'visible' : 'hidden';
	attribD = (pokaz) ? '' : 'none';
	document.all[idObj].style.visibility=attribV;
    document.all[idObj].style.display=attribD;	
 } 
 else if (nn4){ 
     attribV = (pokaz) ? 'show' : 'hide';
     document.layers[idObj].visibility = attribV;
 } 
} 

///////////////////////////////////////////////
var Opera = navigator.userAgent.indexOf('Opera') > -1;
var IE = (!Opera)?navigator.userAgent.indexOf('MSIE') > -1:false;
var FFox = navigator.userAgent.indexOf('Firefox') > -1;
var NetscapeMozilla = (!FFox)?navigator.userAgent.indexOf('Gecko') > -1:false;

//alert(IE +' '+FFox+' '+Opera+' '+NetscapeMozilla+' '+navigator.userAgent);
var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);

var timeout = 1000;
var popTimer = 0;

function getInnerWindowheight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
   
  return myHeight ;
}


//alert(document.documentElement.clientHeight);


function get_object(id) {
	if (isDOM) return document.getElementById(id);
	if (isIE4) return document.all[id];
	if (isNS4) return document.layers[id];
}

function get_style(id) {
	return (isNS4 ? get_object(id) : get_object(id).style);
}



function show(object,left,top,start){
	//clearTimeout(popTimer);
	var new_ID = get_object(object) ;
	if(new_ID){
		new_ID.style.left = left +'px';
		new_ID.style.top = top+'px';
		new_ID.style.display = 'block';
		if(start){
			//alert(new_ID.offsetHeight);
			new_ID.style.top =(top-new_ID.offsetHeight)+'px';
			//alert(top-45-new_ID.offsetHeight);
		}	
		var ilosc = parseInt(MenuModuly_array.length);
		// gaszenie pozostalych menu
	}
	if(ilosc>0){
		for(i=0;i<ilosc;i++){
			if(MenuModuly_array[i]!=object)
				hide(MenuModuly_array[i]);
		}
	}
	
}

function hide_all(){
	var ilosc = parseInt(MenuModuly_array.length);
	if(ilosc>0){
		for(i=0;i<ilosc;i++){
			hide(MenuModuly_array[i]);
		}
	}	
}

function hide(object){
	if(!object.id)	object = get_object(object) ;
	if(object) object.style.display = 'none';
	//popTimer = setTimeout('hide_all()', 500);
}


function getleft(obj, menu_nr){
	//alert(menu_nr.substring(11));
	if(IE || FFox || Opera){
	
		if( obj.offsetParent ) {
			for( var posX = 0; obj.offsetParent; obj = obj.offsetParent ) {
	    		posX += obj.offsetLeft;
	    	}
	    	return posX;
	  	} 
	}
  	else {
		menu_numer = parseInt(menu_nr.replace(/[^0-9]+/,''));
  		if (obj.x)
  			return (obj.x-225+((menu_numer-1)*30));
  		else	alert('Unsupported Browser');
  			
  }
}

function ustaw_menu(menu_nr,ustaw,imagevar,menu_id,start){
	menu = get_object(menu_nr);
	moduly = ('MenuModuly'+menu_id);
	ustaw = parseInt(ustaw);
	if(ustaw>0)	menu.src = imagevar.src ;
	else	menu.src = imagevar.src ;
	if(ustaw){
		// ustawienie pozycji menu rozwijanego
		myleft = getleft(menu,menu_nr);//left_margin
		
		//		window.status=(navigator.userAgent+':'+myleft+':'+left_margin+' '+left+' '+left2+' '+left3);
		if(IE || FFox){
			top_margin = 318;		
			if(start)
				top_margin+=63;
		}
		else if(NetscapeMozilla)	{
			top_margin = 318;		
			if(start)
				top_margin+=50;
		}
		else{
			//Opera
			top_margin = 325;		
			if(start)
				top_margin+=703;
		}
		if(start){
			var top_max = getInnerWindowheight();
			top_margin = (parseInt(top_max/2)+80);
		}	

		show(moduly,myleft,top_margin,start)
	}
}


function mouseEventHandler(mEvent)
{
	// Internet Explorer
	if (mEvent.srcElement) testObjectHide(mEvent, mEvent.srcElement);
	// Netscape and Firefox
	else if (mEvent.target) testObjectHide(mEvent, mEvent.target);
}


function testObjectHide(myEvent,  myElement){
		
	var text='';
	var obj_ok = false;
	if (myElement.id){
		obj_ok = (myElement.id.substring(0,2)=='MM')
		text+="id : '"+myElement.id+"' " + obj_ok;		
	}	
	if (myElement.parentNode.id)
		obj_ok = (obj_ok || (myElement.parentNode.id.substring(0,2)=='MM'));
	if(obj_ok==false)
		hide_all()
//	window.status=text;
}

// Correctly handle PNG transparency in Win IE 5.5 or higher.
// http://homepage.ntlworld.com/bobosola. Updated 02-March-2004

function correctPNG()
{
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	
	if ((version >= 5.5) && (document.body.filters)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
	      var img = document.images[i]
	      var imgName = img.src.toUpperCase()
	      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	      {
	         var imgID = (img.id) ? "id='" + img.id + "' " : ""
	         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
	         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
	         //var imgUsemap = (img.usemap) ? "usemap='" + img.usemap + "' " : ""
	         var imgStyle = "display:inline-block" + img.style.cssText 
	         if (img.align == "left") imgStyle = "float:left;" + imgStyle
	         if (img.align == "right") imgStyle = "float:right;" + imgStyle
	         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
	         var strNewHTML = "<span " + imgID + imgClass + imgTitle
	         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
	         img.outerHTML = strNewHTML
	         i = i-1
	      }
	   }
	}
}
