var ie4, ns4, ns6;
navi = navigator.appVersion.split(" ");
ie6=(document.all)&&(parseInt(navi[3])<=6);
var i = 0;
var timer;

/*
function chgRepertuar(oBj) 
{
	link = '/'+oBj.kino_rep.value+'/repertuar.html';
	oBj.action = link;
	oBj.submit();
}
*/

function chgRepertuar(oBj) 
{
	//link = '/'+oBj.value+'/repertuar.html';
	
	link = oBj.value+'/repertuar.html';
	form = $("chgRep");
	form.action = link;
	form.submit();
}


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 true;
else return false;
}
function sendJob() {
object = $("ofertaPracy");
kom = $("Komunikat");
id = object.kino.value;
etat = object.stanowisko.value;
file_cv = object.file_cv.value;
file_lm = object.file_lm.value;
zdjecie = object.zdjecie.value;
nazwisko = object.nazwisko.value;
email = object.email.value;
telefon = object.telefon.value;
Error = 0
if (id=="0" || etat=="0" || file_cv=="" || file_lm=="" || nazwisko=="" || !chkEmail(email) || telefon=="") {
	Error = 1;
	kom.innerHTML = "Błąd. Proszę uzupełnić wymagane pola";
	return false;
	}
else return true;
}
function chgKino() {
	object = $("ofertaPracy");
	id = object.kino.value;

	
	//stanowisko = $("st");
		uwagi = $("uwagiPraca");
	
	/*
	advAJAX.get({
		url: 'index.php?ajax=1&module=addon&akcja='+id,
		onSuccess: function(obj) {
			stanowisko.innerHTML = 'Oferta:<select name="stanowisko" id="stanowisko">'+obj.responseText+'</select>';
			},
		onInitialization: function(obj) {
			stanowisko.innerHTML =  'Oferta:<select name="stanowisko" id="stanowisko"><option value="0">Trwa wyszukiwanie</option></select>';
			},
		onError: function(obj) {
			object.innerHTML = 'Oferta:<select name="stanowisko" id="stanowisko"><option value="0">Wystąpił błąd</option></select>';
			}
		});
	*/

	advAJAX.get({
		url: '/index.php?ajax=1&module=addon1&akcja='+id,
		onSuccess: function(obj) {
			uwagi.innerHTML = obj.responseText;
			},
		onInitialization: function(obj) {

			},
		onError: function(obj) {

			}
		});		
	
		

}

/*
function  chgLayer(item1,item2,now) {
	if (now==1) {
		$(item1).style.display = "";
		$(item2).style.display = "none";	
		$('cenniki_left').style.backgroundImage = 'tpl/images/img_cenniki_left.gif';
		$('cenniki_right').style.backgroundImage = 'none';
		}
	else {
		$(item1).style.display = "none";
		$(item2).style.display = "";
		$('cenniki_left').style.backgroundImage = 'none';
		$('cenniki_right').style.backgroundImage = 'tpl/images/img_cenniki_right.gif';
		}
	}
*/
function  chgLayer(item1,item2,now) 
{
	if (now==1) 
	{
		$(item1).style.display = "";
		$(item2).style.display = "none";	
		$("cenniki_right").style.backgroundImage = "none";
		$("cenniki").style.height = document.getElementById('layer_1').clientHeight+22+'px';

		
	}
	else 
	{
		$(item1).style.display = "none";
		$(item2).style.display = "";
		$('cenniki_left').style.backgroundImage = 'none';
		$('cenniki').style.height = document.getElementById('layer_2').clientHeight+22+'px';

		
	}
}

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,path) {
var Tablica = Array();
for (i=0;i<5;i++) {
	id = "ocen_" + i;
	Tablica[i] = document.getElementById(id);

	
	if (stan>=i+1) {
		Tablica[i].src = path+'img_star_on.gif';
		}
	else {
		Tablica[i].src = path+'img_star_off.gif';
		}

	
	
	}
}
function chgItem(name,path) {
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 = path+'img_star_on.gif';
		}
	else {
		Tablica[i].src = path+'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) {
	if (i==0) {
	clearTimeout(timer);
	oBj = $(name);
	oBj.style.display = "";
	oBj.style.height = "1px";
	timer = setTimeout("sliderAdd()",1);
	}
}
function sliderAdd() {
	if (ie6) last = 22;
	else last = 18;
	i+=2;
	oBj.style.height = i+"px";
	
	
	if (i>=last) {clearTimeout(timer);}
	else {timer = setTimeout("sliderAdd()",1);}
}
function sliderDel() {
	i-=2;
	oBj.style.height = i+"px";
	if (i<=0) {clearTimeout(timer);}
	else {timer = setTimeout("sliderDel()",1);}
}
function hideSubmenu(name) {
	i = 0;
	clearTimeout(timer);
	$(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 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 PodmienFoto(tresc, szer){
//var objLoadingImage = document.getElementById( 'foto' );
//objLoadingImage.setAttribute('src', foto_img);

Galeria('galeria', tresc, szer);
}
	
function Galeria(Nazwa,tresc,szer) {

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') == 'galeria_multi'))
		  	  {
				
				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";



text='<table cellspacing=0 cellpadding=0 cellpadding=2>';
text+='<tr><td align="left"><img src="/images/logo.gif" class="lgo"></td></tr>';
text+='<tr>';
text+='<td align="right" style="background-color: #ffffff;">';
text+='<img src="/images/zamknij.gif" alt="Zamknij" 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="/images/nastepne.gif" class="nastepne" onclick=\'javascript:PodmienFoto("'+imageArray[nast+1]+'", "'+imageSzerArray[nast+1]+'");\' style="cursor: pointer">';
 else text+='<img src="/images/nastepne_non.gif" class="nastepne">';
if (imageArray[nast-1]) text+='<img src="/images/poprzednie.gif" class="poprzednie" onclick=\'javascript:PodmienFoto("'+imageArray[nast-1]+'", "'+imageSzerArray[nast-1]+'");\' style="cursor: pointer"/>';
 else text+='<img src="/images/poprzednie_non.gif" class="poprzednie" />';

text+='</td></tr></table>';
document.getElementById(Nazwa).innerHTML=text;
}

function Galeria_close() {
 objFirma = document.getElementById('galeria');
 objFirma.style.display="none";
 objBlock = document.getElementById('tlo_block');
 objBlock.style.display="none";
}

function changeFlash(prev,katalog,file,firstmovie){
	if(document.getElementById){
		var ref = document.getElementById('player');
		var so = new SWFObject('/themes/default/swf/player.swf', 'main', '521', '310', '7');
		so.addParam('wmode','transparent');
		so.addVariable('prev',prev);
		so.addVariable('katalog',katalog);
		so.addVariable('file',file);
		if(firstmovie == "yes") so.addVariable('sPrev','yes');
		//ref.removeChild(ref.childNodes[0]);
		so.write(ref);
		
		//		document.getElementById('filmik').nodeValue=content2;
	}
}

function pracaRozwin(id)
{
	document.getElementById("pracaTresc"+id).style.display="block";
}

function wybStan(nr)
{
	document.getElementById("st_wyb").value = nr;
}


