// JavaScript Document

var wysokoscOkna;
var szerokoscOkna;
var siteW = 760, siteH = 570;	
var topSpacer = 30;
	
var ifVerticalCenter;


function insertTopLayers(obrazek, szerokosc, wysokosc)
{
	var flashvars = {};
	var params = {wmode:"transparent", scale:"noborder"};
	var attributes = {};
	swfobject.embedSWF(obrazek + '?ver=' + Math.random(), 'topLayersBannerContainer', szerokosc + 'px', wysokosc + 'px', '8.0.0', 'include/expressInstall.swf', flashvars, params, attributes);
	
	var topLayers = document.getElementById("topLayers");
	topLayers.style.left = '50%';
	topLayers.style.top = '50%';
	topLayers.style.marginLeft = -(szerokosc/2) + "px";
	topLayers.style.marginTop = -(wysokosc/2) + "px";		
}

function hideTopLayers()
{
	var topLayers = document.getElementById("topLayers");
	topLayers.style.display = "none";
}

function resizeSite()
{
	getWindowSize();
	if (ifVerticalCenter) insertRecalculatedPosition(true);
	insertBackground();
	
}

function moveBackground()
{
	var backgroundC = document.getElementById("backgroundContainer");
	backgroundC.style.top = getScrollXY()[1] + 'px';
	backgroundC.style.left = getScrollXY()[0] + 'px';	
}


function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}	


function insertBackground() {
	
	var wholeSite = document.getElementById("indexPanel");
	var wholeSiteW = wholeSite.offsetWidth;
	var wholeSiteH = wholeSite.offsetHeight;
	var scrollBarRealWidth = 18;
	
	
	var overflowH = false, overflowW = false;
	
	if (szerokoscOkna < wholeSiteW) overflowW = true;
	if (wysokoscOkna < (wholeSiteH + topSpacer)) overflowH = true;

	var scrollBarVWidth = 5;
	var scrollBarHHeight = 5;	 
	if( typeof( window.innerWidth ) == 'number' ) {	
		if (overflowH && overflowW) {
			scrollBarHHeight += scrollBarRealWidth;		
			scrollBarVWidth += scrollBarRealWidth;				
		} else if (overflowW) {
			scrollBarHHeight += scrollBarRealWidth;
			if ((wysokoscOkna-scrollBarRealWidth)< (wholeSiteH + topSpacer)) scrollBarVWidth += scrollBarRealWidth;			
		} else if (overflowH) {
			scrollBarVWidth += scrollBarRealWidth;			
			if ((szerokoscOkna-scrollBarRealWidth)< wholeSiteW) scrollBarHHeight += scrollBarRealWidth;					
		}		
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		scrollBarVWidth += 0;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		scrollBarVWidth += 0;
	}	
	



	var flashvars = {file1:nazwaPliku1, scale1:skaluj1, file2:nazwaPliku2, scale2:skaluj2, bgColor:kolor};
	var params = {wmode:"opaque", scale:"default", salign:"tl"};
	var attributes = {};			
	swfobject.embedSWF('media/background_loader.swf?ver=' + Math.random(), 'flashBackgroundContainer', szerokoscOkna - scrollBarVWidth + 'px', wysokoscOkna - scrollBarHHeight + 'px', '9.0.0', 'include/expressInstall.swf', flashvars, params, attributes);

	var backgroundC = document.getElementById("backgroundContainer");
	backgroundC.style.width = szerokoscOkna - scrollBarVWidth + "px";
	backgroundC.style.height = wysokoscOkna - scrollBarHHeight + "px";		
}

function getWindowSize() {


	 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;
	 }
		
	szerokoscOkna = myWidth;
	wysokoscOkna = myHeight;
	
}

function insertRecalculatedPosition(vertical) {
	
		ifVerticalCenter = vertical;
	
		var offsetWDiv = (szerokoscOkna - siteW)/2;
		var offsetHDiv = (wysokoscOkna - siteH)/2;	
		if (offsetHDiv<topSpacer) offsetHDiv=topSpacer;
		
		if (vertical) {
			document.getElementById("indexPanel").style.top = offsetHDiv + 'px';	
		} else {
			document.getElementById("indexPanel").style.top = 	'20px';
		}
			document.getElementById("indexPanel").style.left =	'50%';		
			document.getElementById("indexPanel").style.marginLeft = "-" + (siteW/2) + 'px';

}	



function checkMail() {

	var dobry=0;
	
	if (document.getElementById("mail").value.indexOf('@')>0) dobry++;
	if (document.getElementById("mail").value.length > 5) dobry++;
	
	if (dobry==2) {
		document.getElementById("mailForm").submit();
	} else {
		alert("Podany adres e-mail jest nieprawidłowy!");
	}

}

function checkPassword() {

	if (document.getElementById("password1").value == document.getElementById("password2").value) {
		document.getElementById("forma").submit();
	} else {
		alert("Wpisane hasła powinny być identyczne!");
	}

}
var waitForFillURL = false;

function tryInitDisplayImages() {

	if (waitForFillURL) {				
		if (document.getElementById('stopTryingDisplayImages')) {
			displayImage.initNow();
			waitForFillURL = false;
		} else {
			setTimeout(tryInitDisplayImages,500);
		}
	} 
}

function fillWithURL (url, targetID) {

	if (document.getElementById('stopTryingDisplayImagesParent')) {
		document.getElementById('stopTryingDisplayImagesParent').innerHTML = "";
	}
	waitForFillURL = true;
	tryInitDisplayImages();
	
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}


	try	
	{
		xmlhttp.open("GET", url + "&ver=" + Math.random(),true);
 		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				document.getElementById(targetID).innerHTML = xmlhttp.responseText;
			}
 		}
 		xmlhttp.send(null);
	} catch (e) {
		return false;		
	}
	return false;
}

function initializeMenu() {
	
		navRoot = document.getElementById("menuProducts");
		navRoot.onmouseover=function() {
			this.style.backgroundImage = "url(media/menu/buttonProductsH.png)";
			document.getElementById("menuProductsContainer").style.display = "block";
		}	
		navRoot.onmouseout=function() {
			this.style.backgroundImage = "url(media/menu/buttonProducts.png)";
		}	
		
		navRoot = document.getElementById("menuNews");
		navRoot.onmouseover=function() {
			this.style.backgroundImage = "url(media/menu/buttonNewsH.png)";
		}	
		navRoot.onmouseout=function() {
			this.style.backgroundImage = "url(media/menu/buttonNews.png)";
		}	
		
		navRoot = document.getElementById("menuLocations");
		navRoot.onmouseover=function() {
			this.style.backgroundImage = "url(media/menu/buttonLocationsH.png)";
		}	
		navRoot.onmouseout=function() {
			this.style.backgroundImage = "url(media/menu/buttonLocations.png)";
		}	
		
		navRoot = document.getElementById("menuPartners");
		navRoot.onmouseover=function() {
			this.style.backgroundImage = "url(media/menu/buttonPartnersH.png)";
		}	
		navRoot.onmouseout=function() {
			this.style.backgroundImage = "url(media/menu/buttonPartners.png)";
		}	
		
		navRoot = document.getElementById("menuCompany");
		navRoot.onmouseover=function() {
			this.style.backgroundImage = "url(media/menu/buttonCompanyH.png)";
		}	
		navRoot.onmouseout=function() {
			this.style.backgroundImage = "url(media/menu/buttonCompany.png)";
		}
		
		navRoot = document.getElementById("menuProductsContainer");
		navRoot.onmouseout=function() {
			this.style.display = "none";
		}	
}




// Wyskakujce okienka
/*
	 Skrypt jest darmowy, poki ten komentarz w nim pozostaje.
	 Released under Creative Commons License
	 http://creativecommons.org/licenses/by/2.0/

	 Original author: Kornel Lesinski
	 http://pornel.net/pups/
*/
var displayImage =
{
	/** uaktywnia wszystkie linki w podanym elemencie. z pewnoscia chcesz to wywolac (patrz koniec tego pliku) */
	init: function(element)
	{
		/** wymagany jest element i obsluga DOM */
		if (!element || !element.getElementsByTagName) {return false;}

		var as = element.getElementsByTagName('a');
		for(var i=0;i<as.length;i++)
		{
			/* dzieki ponizszej linijce upopupiane sa tylko linki do obrazkow. zakomentuj ja i bedzie dzialalo na wszystkie. mozesz tez zmienic warunek zeby dzialalo np. tylko na linki z okreslona klasa (tip: .className) */
			if ((as[i].href+'').match(/\.(jpe?g|png|gif)/i))
				as[i].onclick = this.click;
		}

		return true;
	},

	/** tworzenie dokumentu, ktory jest w nowootwartym oknie. zmien HTML wg gustu */
	writedoc: function(win,href,title,alt,h)
	{
		var doc = win.document;
		doc.open('text/html;charset=utf-8');
		doc.write(
		'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' +
		'<html id="popup">' +
		'<head><title>' + (title?title:'') + '</title>' +
		'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' +
		'<meta http-equiv="imagetoolbar" content="false">' +
		'<link rel="stylesheet" href="include/displayImage.css?' + Math.random() + '">' +
		'</head>\n\n<body onclick="window.close();">' +
//		'\t<div align="center">\n\t\t<img src="'+href+'" alt="'+alt+'">\n\t</div>\n' +
//		'\t<table>\n\t\t<tr>\n\t\t\t<td align="left">\n\t\t\t' + (title?'<p class="tytul">'+title+'</p>':'') + '\n\t\t\t</td>\n\t\t\t<td align="right">\n' +
//		'\t\t\t\t<p class="klik">Kliknij gdziekolwiek, aby zamkn</p>\n\t\t\t</td>\n\t\t</tr>\n\t</table>\n' +
		'<div align="center"><img src="'+href+'?ver=' + Math.random() + '" alt="'+alt+'"></div>' +	
		'<p class="klik">Kliknij gdziekolwiek, aby zamknąć</p>' +
		'</body></html>'


		);
		doc.close();
	},

	/** funkcja ma za zadanie wydobyc wymiary z podanego ciagu (tytulu linku)
		zwraca tablice zawierajaca ladnie sformatowany tytul oraz
		wymiary pobrane z podanego ciagu w formacie dla window.open

		zmien ta funkcje, jesli chcesz zapisywac wymiary w inny sposob
	*/
	title2size: function(str)
	{
		if (str)
		{
			/* wyrazenie regularne szuka czegos na wzor "(111x222)" */
			var out = str.match(/\(([0-9]+)x([0-9]+)\)/);

			/* po czym usuwa znaleziony fragment */
			if (out) return new Array(str.replace(/\(([0-9]+)x([0-9]+)\)/g,''),parseInt(out[1]),parseInt(out[2]));
		}
		/* w przypadku problemow - podaje wartosci domyslne (zmien na takie, jakie ci pasuja) */
		return new Array(str,800,600);
	},

	/** obsluga klikniecia */
	click: function()
	{
		/* jesli okno tej miniatury jest otwarte - zamknij (b?dzie otworzone jeszcze raz, jakby uytkownik zgubi? poprzednie...) */
		try {
			if (this.pp_win && this.pp_win.close && !this.pp_win.closed) {this.pp_win.close(); this.pp_win=false;}
		}
		/* explorer ma z tym dziwne problemy, ktore na szczescie mozna olac */
		catch(e){}

		try {
			/* znajdz obrazek, jego alt i title */
			var imgs = this.getElementsByTagName('img');
			var title = imgs[0].getAttribute('title')?imgs[0].getAttribute('title'):this.getAttribute('title');
			var alt = imgs[0].getAttribute('alt');

			/* parametry okna, z wymiarami (tu wymiary sa powiekszane, aby bylo troche miejsca wokol obrazka) */
			var titleandsize = displayImage.title2size(title);
			var winopts = "dependent=no,menubar=no,left=100,top=100,toolbar=no,resizable=no,width=" + (titleandsize[1]+20) + ',height=' + (titleandsize[2]+20);

			/* do the boogie! */
			var win = window.open(this.href,'',winopts);
			if (win && win.opener)
			{
				this.pp_win = win;
				displayImage.writedoc(win,this.href,titleandsize[0],alt,titleandsize[2]);
				return false;
			}
		}
		/* siatka bezpieczenstwa, jakby ktoras funkcja nawalila */
		catch(e){}

		/* jesli nie udalo sie otworzyc okna - zwraca true, co otwiera obrazek w tym samym oknie */
		return true;
	},

	initNow: function()
	{
		this.init(document.body);
	},

	initLoad: function()
	{
		var oldOnload = window.onload;
		var that = this;
		window.onload = function()
		{
			if (oldOnload) try{oldOnload();}catch(e){/*explorer dziwne rzeczy plecie*/}
			that.initNow();
		}
	}
};

/** inicjalizacja przy onload (po zaladowaniu wszsystkich miniatur) */
//displayImage.initLoad();

/** inicjalizacja natychmiastowa. MUSI byc wykonana w body ZA wszystkimi linkami, na ktore ma dzialac */

//		insertRecalculatedPosition(verticalAlign);
//		initializeMenu();		
//		fillWithURL(trescPanelu, 'tableRightContent');		