/*
ScrollSpeed = 140
ScrollChars = 1
function ScrollMarquee() {
window.setTimeout('ScrollMarquee()',ScrollSpeed);

var msg = document.marquee1.text.value;
document.marquee1.text.value =
msg.substring(ScrollChars) +
msg.substring(0,ScrollChars);
}
ScrollMarquee()
*/

function rateIt(id,rate) {
	object = $("ocen");
	advAJAX.get({
		url: 'index.php?module=pokaz&akcja=film&row='+id+'&rate='+rate+'&ajax=1',
		onSuccess: function(obj) {
			object.innerHTML = obj.responseText;
			},
		onInitialization: function(obj) {
			object.innerHTML = '<p style="margin-bottom: 46px;">Trwa zapisywania...</p>';
			},
		onError: function(obj) {
			object.innerHTML = "Wystąpił błąd!";
			}
		});
	}
function reloadItem(name,stan) {
var Tablica = Array();
for (i=0;i<5;i++) {
	id = "ocen_" + i;
	Tablica[i] = document.getElementById(id);
	
	
	if (stan>=i+1) {
		Tablica[i].src = 'tpl/images/img_star_on.gif';
		}
	else {
		Tablica[i].src = 'tpl/images/img_star_off.gif';
		}

	
	
	}
}
function chgItem(name) {
var Tablica = Array();
for (i=0;i<5;i++) {
	id = "ocen_" + i;
	Tablica[i] = document.getElementById(id);
	}
iId = name.id.substr(5);
for (i=0;i<5;i++) {
	if (iId>=i) {
		Tablica[i].src = 'tpl/images/img_star_on.gif';
		}
	else {
		Tablica[i].src = 'tpl/images/img_star_off.gif';
		}
	}

}
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   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 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
         }
      }
   }    
}
if (navigator.appName=='Microsoft Internet Explorer') window.attachEvent("onload", correctPNG);

    function poprawPNG() {
        var divs = document.getElementsByTagName('DIV');
       
        for(var i=0; i<divs.length; i++) {

            var div = divs[i];
            var back = eval('div.currentStyle.backgroundImage');
            if(back.indexOf(".png") != -1) {
                div.style.backgroundImage = 'none';
                div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + back.substring(5, back.length-2) + "', sizingMethod='scale')";
            }           

        }
    }

    if(window.attachEvent) {
        window.attachEvent('onload', poprawPNG);
    }
	 
function showSubmenu(name) {
	$(name).style.display = "";
}
function hideSubmenu(name) {
	$(name).style.display = "none";
}
function PokazUkryj(Nazwa) {
objFirma = document.getElementById(Nazwa);
if (objFirma.style.display=="block") objFirma.style.display="none";
else objFirma.style.display="block";
}

function $( ide ){
	return document.getElementById( ide );
}

function wyswietlMenu( ide ){
	var kont = $( 'kontMenu'+ide );
	
		
	//$('id'+ide).style.color = '#A31113';

		
	advAJAX.get({
				url: 'index.php?module=katalog&akcja=pokazPod&row='+ide+'&ajax=1',
				onInitialization : function() {
					kont.innerHTML = '<img src="tpl/images/czekaj_ico.gif" alt="czekaj" />';
				},
				onSuccess : function(obj) {	
						kont.innerHTML = obj.responseText;	
				},
				onError : function(obj) {
					kont.innerHTML = '<div style="font-weight:bold; color: red;">blad...</div>';
				}	
			});
	
}






function MM_swapImage() { 
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { 
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}
function MM_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}


browserversion = parseInt(navigator.appVersion);
}
function FirmaRoll(Nazwa, Boks) {

advAJAX.get({
		url: 'index.php?module=katalog_firm&akcja=pokaz&ajax=1&op='+Nazwa,
		onInitialization : function() {
			$( Boks ).innerHTML = '<div style="color: #6C0000;">Proszę czekać, trwa ładowanie...</div>';
		},
		onSuccess : function(obj) {	
			$( Boks ).innerHTML = obj.responseText+'<a href="?module=katalog_firm&akcja=dodajfirme&pakiet='+Nazwa+'"><img src=\"tpl/images/rejestruj.gif\" border="0" align="right" alt=\"\"></a>';
			
		},
		onError : function(obj) {
			$( Boks ).innerHTML = '<div style="font-weight:bold; color: red;">blad...</div>';
		}	
	});

}
function rollOutFlash(myToggle,Nazwa)
{
objIn = document.getElementById(Nazwa);
objIn.SetVariable ("_root.myToggle"," " + myToggle);
}
function chkNewsletter() {
objZapisz1_1 = document.getElementById('NewsLetter1_1');
objZapisz1_2 = document.getElementById('NewsLetter1_2');
objWypisz2_1 = document.getElementById('NewsLetter2_1');
objWypisz2_2 = document.getElementById('NewsLetter2_2');
if (objZapisz1_1.style.display == 'inline') {
	objZapisz1_1.style.display = 'none';
	objZapisz1_2.style.display = 'inline';
	objWypisz2_1.style.display = 'inline';
	objWypisz2_2.style.display = 'none';
	}
else {
	objZapisz1_1.style.display = 'inline';
	objZapisz1_2.style.display = 'none';
	objWypisz2_1.style.display = 'none';
	objWypisz2_2.style.display = 'inline';
	}
}
function correctNewsletter() {
wpis = document.getElementById('newsletter');
objZapisz1_1 = document.getElementById('NewsLetter1_1');
todo = document.getElementById('todo');
if (objZapisz1_1.style.display == 'none') todo.value = 'Wypisz';
else todo.value = 'Zapisz';
var regEmail = /^([a-zA-Z0-9._-]{1,})@([a-zA-Z0-9._-]{1,})\.([a-zA-Z]{1,4})$/;
if (!regEmail.test(wpis.value)) {
	alert( "Podaj prawidłowy format e-maila." );
	return false ;
	}
else return true;
}
function chgMenu(name) {
Act = name.substr(5,6);
listObj = document.getElementsByTagName('div');
for (i=0;i<listObj.length;i++) {
	if (listObj[i].id.substr(0,7)=='SubMenu') {
		if (listObj[i].id.substr(8,9) == Act) listObj[i].style.display = "block";
		else listObj[i].style.display = "none";
		};
	}
}

/* gwiazdki */
		var g_clear = 'tpl/images/gw_pusta.gif';
		var g_fill = 'tpl/images/gw_pelna.gif';
		var ile = 5;
		
		var x = 8;
		var y = 7;

	
  
	function generuj( id, start, module){
			
			var iden = $( 'ocena'+id );
			
			for( i = 0; i < ile; i++ ){
			
			docBody = $( 'ocena'+id );
			element = document.createElement("img");
			element.id = i;
			docBody.appendChild(element);
			
			incre = i + 1;
			
			element.setAttribute( "style", "cursor:pointer;" );
			
			if( start > i )
				element.setAttribute( "src", g_fill );
			else
				element.setAttribute( "src", g_clear );
				
			element.setAttribute( "width", x );
			element.setAttribute( "height", y );
			element.setAttribute( "id", 'oc_'+incre+'_'+id );
			element.setAttribute( "name", 'oc_'+incre+'_'+id );

			element.onmouseover=function () { zmien(this.name, id); };
			element.onclick=function () { zlicz(this.name, id, module); };
			element.onmouseout=function () { czysc(id, start);};
			}
			
		}
		
		function zlicz( nr, id, module ){
			var aNum = nr.split( "_" ); 

			
			advAJAX.get({
				url: '?module='+module+'&akcja=zapisz_ocene&ajax=1&ocena='+aNum[1]+'&row='+id,
				onInitialization : function() {
					$( 'ocena'+id ).innerHTML = '<span style="color: green;">zapisuje...</span>';
				},
				onSuccess : function(obj) {	
					$( 'ocena'+id ).innerHTML = '';
					generuj( id, obj.responseText, module ); 
					
				},
				onError : function(obj) {
					$( 'ocena'+id ).innerHTML = '<div style="font-weight:bold; color: red;">blad...</div>';
				}	
			});
			
			
		}
		
		function zmien( nr, id ){
			var aNum = nr.split( "_" ); 
			var a = 1;
			for(i = 0; i < aNum[1]; i++){
				$( 'oc_'+a+'_'+id ).setAttribute("src", g_fill);	
				a++;
			}	
		}
		
		function czysc( id, start ){
			var i = 0;
			var a = 1;
			for( i; i < ile; i++ ){
				$( 'oc_'+a+'_'+id ).setAttribute("src", g_clear);	
				a++;	
			}
			
			//$( 'ocena'+id ).addEventListener('mouseout',doSomething,false);	
		}
		
	
		
	/* koniec gwiazdki */

// Event and Listners //
//if (document.addEventListener){ // Mozilla, Netscape, Firefox
//	window.addEventListener("load", chkNewsletter, false);
//} else { // IE
//	document.attachEvent('onload', chkNewsletter);
//}
function SprawdzLogin( Boks ) {

var login = $( 'login' ).value;

advAJAX.get({
		url: 'index.php?module=formularz&akcja=sprawdzlogin&ajax=1&login='+login,
		onInitialization : function() {
		
		},
		onSuccess : function(obj) {	
			$( Boks ).innerHTML = obj.responseText;
			$( Boks ).style.color = 'red';
		},
		onError : function(obj) {
			$( Boks ).innerHTML = '<div style="font-weight:bold; color: red;">blad...</div>';
		}	
	});

}
function WpiszMail( Boks ) {
$( 'subdomena' ).value = $( Boks ).value = $( 'subdomena' ).value.toLowerCase();
$( 'subdomena' ).value = $( Boks ).value = $( 'subdomena' ).value.replace(/\ /g,'_');
$( 'subdomena' ).value = $( Boks ).value = $( 'subdomena' ).value.replace(/\ą/g,'a');
$( 'subdomena' ).value = $( Boks ).value = $( 'subdomena' ).value.replace(/\ę/g,'e');
$( 'subdomena' ).value = $( Boks ).value = $( 'subdomena' ).value.replace(/\ó/g,'o');
$( 'subdomena' ).value = $( Boks ).value = $( 'subdomena' ).value.replace(/\ł/g,'l');
$( 'subdomena' ).value = $( Boks ).value = $( 'subdomena' ).value.replace(/\ś/g,'s');
$( 'subdomena' ).value = $( Boks ).value = $( 'subdomena' ).value.replace(/\ć/g,'c');
$( 'subdomena' ).value = $( Boks ).value = $( 'subdomena' ).value.replace(/\ż/g,'z');
$( 'subdomena' ).value = $( Boks ).value = $( 'subdomena' ).value.replace(/\Ą/g,'z');
}
function SprawdzSlowaKluczowe( Boks, Pakiet ) {

var slowa_kluczowe = $( 'slowa_kluczowe' ).value;

advAJAX.get({
		url: 'index.php?module=formularz&akcja=sprawdzslowa&ajax=1&slowa='+slowa_kluczowe+'&pakiet='+Pakiet,
		onInitialization : function() {

		},
		onSuccess : function(obj) {	
			$( Boks ).innerHTML = obj.responseText;
			
		},
		onError : function(obj) {
			$( Boks ).innerHTML = '<div style="font-weight:bold; color: red;">blad...</div>';
		}	
	});

}



function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function setWidth(element,w) {
	   	element = $(element);
    		element.style.width = w +"px";
			}
function setHeight(element,h) {
   		element = $(element);
    		element.style.height = h +"px";
			}
function setInnerHTML(element,content) {
			element = $(element);
			element.innerHTML = content;
			}
function setTop(element,t) {
	   	element = $(element);
	    	element.style.top = t +"px";
			}
function setLeft(element,t) {
	   	element = $(element);
	    	element.style.left = t +"px";
			}

	
function start(szer, foto) {	
	  
	  
		// stretch overlay to fill page and fade in
		var arrayPageSize = getPageSize();
		setHeight('tlo_block', arrayPageSize[1]);
		//new Effect.Appear('tlo_block', { duration: 0.2, from: 0.0, to: 0.8 });

	  	// calculate top offset for the lightbox and display 
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);
		
		var ile = (arrayPageSize[2]-szer)/2-16
		
		setLeft('galeria', ile);
		setTop('galeria', lightboxTop);
		
	}

function UstawFooter(){
	var arrayPageSize = getPageSize();
	var ile = arrayPageSize[1] - 53;
	setHeight('content', ile);
	}
	
function PodmienFoto(tresc, szer, ty){
//var objLoadingImage = document.getElementById( 'foto' );
//objLoadingImage.setAttribute('src', foto_img);

Galeria('galeria', tresc, szer, ty);
}
	
function Galeria(Nazwa,tresc,szer, ty) {

var anchors = document.getElementsByTagName('img');
z=0;
nast=0;
var imageArray = new Array;
var imageSzerArray = new Array;
	
	for (var i=0; i<anchors.length; i++){
		  var anchor = anchors[i];

		  if (anchor.getAttribute('src') && (anchor.getAttribute('rel') == ty))
		  	  {
				
				asd = anchor.getAttribute('src').replace('/min','');
				szero = anchor.getAttribute('name');
			
			  	if (asd == tresc){
					nast = z;
					}
				imageArray[z] = asd;
				imageSzerArray[z] = szero;
				z++;
			  }
	}
	
		var arrayPageSize = getPageSize();
		setHeight('tlo_block', arrayPageSize[1]);
		//new Effect.Appear('tlo_block', { duration: 0.2, from: 0.0, to: 0.8 });

	  	// calculate top offset for the lightbox and display 
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);
		
		var ile = (arrayPageSize[2]-szer)/2-16

		setLeft('galeria', ile);
		setTop('galeria', lightboxTop);

objFirma = document.getElementById( 'galeria' );


objFirma.style.display="block";

objBlock = document.getElementById('tlo_block');
objBlock.style.display="block";

var text = new String;
text = '<table cellspacing=0 cellpadding=0 cellpadding=2>';
text +='<tr>';
text +='<td style="background-color: #ffffff; text-align: right;"><img src="public/images/zamknij.gif" alt="" onclick="javascript:Galeria_close();"; style="cursor: pointer;margin:12px;margin-bottom:0px;">';
text +='</td></tr>';
text +='<tr><td style="font-size: 12px; background-color: #ffffff; font-size: 11px; text-align:left;"><img src="'+tresc+'" alt="" style="margin:12px;" id="foto">';
text+='</td></tr>';
text+='<tr><td style="background-color: #ffffff; height:40px;" valign="top">';
if (imageArray[nast+1]) text+='<img src="public/images/nastepne.gif" class="nastepne" onclick=\'javascript:PodmienFoto("'+imageArray[nast+1]+'", "'+imageSzerArray[nast+1]+'", "'+ty+'");\' style="cursor: pointer">';
 else text+='<img src="public/images/nastepne_non.gif" class="nastepne">';
if (imageArray[nast-1]) text+='<img src="public/images/poprzednie.gif" class="poprzednie" onclick=\'javascript:PodmienFoto("'+imageArray[nast-1]+'", "'+imageSzerArray[nast-1]+'", "'+ty+'");\' style="cursor: pointer"/>';
 else text+='<img src="public/images/poprzednie_non.gif" class="poprzednie" />';
text+='</td></tr></table>';

document.getElementById('galeria').innerHTML=text;

}

function Galeria_close() {
 objFirma = document.getElementById('galeria');
 objFirma.style.display="none";
 objBlock = document.getElementById('tlo_block');
 objBlock.style.display="none";
}
function chkEmail(email) {
var regEmail = /^([a-zA-Z0-9._-]{1,})@([a-zA-Z0-9._-]{1,})\.([a-zA-Z]{1,4})$/;
if (!regEmail.test(email)) return false;
else return true;
}
function Email(Name,what) {
Form = $(Name);
if (!chkEmail(Form.email.value)) {
    $('komunikat').innerHTML = "Adres email jest niepoprawny!";
    }
else {
    advAJAX.get({
   url: "index.php?ajax=1&module=newsletter&akcja="+what+"&email="+Form.email.value,
    onInitialization : function() {
        $('komunikat').innerHTML = 'Proszę czekać trwa wysyłanie wiadomości';    
    },
    onSuccess : function(obj) {
        $('komunikat').innerHTML = obj.responseText;
        Form.email.value = '';
     },
    onError : function(obj) { alert("Error: " + obj.status); }
    });
    
    }
}
function newsletter(oBj) {
return false;
}
function clean(oBj) {
oBj.value = '';
}

function sendMeil(Name) {
    oBj = $(Name);
    
/*osobatow = checkRadioAtr(oBj.osobatow);
impreza_dla = checkRadioAtr(oBj.impreza_dla);
typ_impr = checkRadioAtr(oBj.typ_impr);*/

    advAJAX.get({
    url: "index.php?ajax=1&module=wyslij&name="+oBj.name.value+"&email="+oBj.email.value+"&telefon="+oBj.telefon.value+"&miejscowosc="+oBj.miejscowosc.value+"&firma="+oBj.firma.value+"&wiadomosc="+oBj.wiadomosc.value,
    onInitialization : function() {
        $('formKomunikat').innerHTML = 'Proszę czekać trwa wysyłanie wiadomości';    
    },
    onSuccess : function(obj) {
        $('formKomunikat').innerHTML = obj.responseText;
        /*oBj.ile_uczestnikow.value = '';*/
     },
    onError : function(obj) { alert("Error: " + obj.status); }
    });
return false;
}

function checkRadioAtr (Pole) {
    
    for (var i = 0; i < Pole.length; i++) {
          if (Pole[i].checked==true)
            zaznaczone = Pole[i].value;
    }
    return zaznaczone
}

function marquee(x,typ,m){
    typ={
        'up':[-1,'top','offsetHeight'],
        'down':[1,'top','offsetHeight'],
        'left':[-1,'left','offsetWidth'],
        'right':[1,'left','offsetWidth']
    }[typ];
    ((m=this).mOut=document.getElementById(x)).onmouseover=function(){clearTimeout(m.t)};
    m.mOut.appendChild((m.mIn=m.mOut.childNodes)[0].cloneNode(1));
    m.mOut.onmouseout=function(){m.turlaj(m.i,parseInt(m.mIn[0].style[typ[1]]))};
    m.mOut=m.mIn[0][typ[2]];
    
    m.turlaj=function(i,j){
        if(!m.i)m.i=i;
        m.mIn[0].style[typ[1]]=(-2*i*(j+=i)<(i-1)*m.mOut?(j=(-i-1)/2*m.mOut+i):j)+'px';
        m.mIn[1].style[typ[1]]=j+m.mOut+'px';
        m.t=setTimeout(function(){m.turlaj(i,j)},30)
    }
    m.turlaj(typ[0],0)
}