function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank";
	}
}

function down(xw, yw, idshp) {
	mywin=window.open('wtb_popup.php?id='+escape(idshp),'Note','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width='+escape(xw)+',height='+escape(yw)+',left=100,top=50');
	mywin.focus();
}
/*
function przewin() {
	
	var przewijanie = new Fx.Scroll('news_content', {
		'duration':'10000'
	});
	
	var szer = 0;
	
	$$("#news_content div.news").each(function(element,index){
		szer += (element.getSize()).scrollSize.x;
	});
	
	$('flex').setStyle('width', szer);

	przewijanie.toRight();

//	$('flex').addEvents({
//		'mouseover': function() {
//			przewijanie.stop();
//		},
//		'mouseleave': function() {
//			przewijanie.toRight();
//		}
//	});
//
}
*/
window.addEvent('load', function(){
	externalLinks();
	
//	przewin();
	
	function RedirectHash(url) {
		if (url.hash) {
			var viewFunction = url.hash.replace('#', '');
			var productId = url.href.split('/');
			productId = productId[productId.length-1];
			productId = productId.split(',');
			productId = productId[0];
			
			if (url.href.match('produkty')) {
				functionTXT.send('show_function.php?productId='+productId+'&function='+viewFunction,'post');
			}
		}
	}
	
	var functionTXT = new XHR({
		onSuccess : function() {
			$('p_content').innerHTML = this.response.text;
		}
	});
	
	RedirectHash(window.location);
	
//	-------------------------------------------------------------------------------------
	$ES('a', 'box_menu').addEvents({
		'focus' : function() {
			this.blur();
		}
	});
	
	$ES('a', 'p_menu').addEvents({
		'focus' : function() {
			this.blur();
		}
	});
	
	if ($('p_functions')) {
		$ES('a', 'p_functions').addEvents({
			'focus' : function() {
				this.blur();
			},
			'click' : function(event) {
				window.location = this.href;
				RedirectHash(window.location);
			}
		});
	}
});

/*-- OPERACJE NA PLYWAJACYCH OKNACH --*/
/*
 *	Plynne przesuwanie okna
 */
function go() {
	if (window.scrollX>=0) { // przesunięcie okna dla Netscape
		x = window.scrollX; y = window.scrollY;
	} else { // dla IE, Opery, Firefox
		x = document.body.scrollLeft;  y = document.body.scrollTop;
	}
	docelowax = pozycjax + x;
	doceloway = pozycjay + y;

	yd = (doceloway - parseInt(obj.style.top)) / 5;
	xd = (docelowax - parseInt(obj.style.left)) / 5;

	obj.style.left = parseInt(obj.style.left) + xd + "px";
	obj.style.top = parseInt(obj.style.top) + yd + "px";

/*	if (widoczne) {*/ setTimeout("go()", 50); //}
//	else { obj.style.visibility = "hidden"; }
}


/**
 *	Otwieranie okna (div) za pomoca funckji AJAX'owych
 *	----
 *	tworzenie diva
 *	ustawianie go na srodku ekranu biorac pod uwage jego rozmiary oraz rozmiary okna przegladarki
 *	nastepna funkcja (np. FillWindow) powinna umiescic w nim tresc HTML (odpowiedz z zadania AJAX)
 *	pokazanie okna (byc moze za pomoca innej funkcji, ktora doda np efekt plynnego pokazania sie)
 *	okno powinno byc zawsze na srodku, nawet jak przesune pasek przewijania w przegladarce
 *	@param int id
 *	@param int szer
 *	@param int wys
 *	@return obj
 */
function CreateWindow(id, szer, wys) {
	var ekranX = ekranY = 0;
	if (typeof(window.innerWidth)=='number') {
		ekranX = window.innerWidth;
		ekranY = window.innerHeight;
	} else if (document.documentElement && (document.documentElement.clientWidth
	|| document.documentElement.clientHeight)) {
		ekranX = document.documentElement.clientWidth;
		ekranY = document.documentElement.clientHeight;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		ekranX = document.body.clientWidth;
		ekranY = document.body.clientHeight;
	}
	
	var x = y = 0;
	if (typeof(window.pageYOffset)=='number') {
		x = window.pageXOffset;
		y = window.pageYOffset;
	} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}

	pozycjax = ekranX/2 - szer/2;	//polowa serokosci diva
	pozycjay  = ekranY/2 - wys/2;	//polowa wysokosci diva
	startpozycjax = pozycjax + x;
	startpozycjay = pozycjay + y;
	

	
	var el = new Element('div', {
		'styles': {
			'width': szer+'px',
			'height': wys+'px',
			'position': 'absolute',
			'top': startpozycjay+'px',		//to musi byc obliczane, aby bylo na srodku ekranu
			'left': startpozycjax+'px',		//to musi byc obliczane, aby bylo na srodku ekranu
			'background-color': '#fff',
			'z-index': '1000',
			'opacity': '0'
		},
		'id': id
	});
	el.injectBefore('main');
	
	//dopisalem do plynnego przesuwania okna
	var widoczne = true; // okienko ma być widoczne
	var yd = 0;
	var xd = 0;
	obj = $(id);
	go();
	
	setCanvas(id);
	
	return el;
}


/*
 *	Wypelnianie okna trescia
 *	@param obj el
 *	@param string dane
 */
function FillWindow(el, dane) {
	el.setHTML(dane);
}


/*
 *	Plynne pokazanie okna (diva)
 *	@param obj id
 */
function ShowWindow(id) {
	var efekt = new Fx.Style(id,'opacity',{
		duration: 600
	});
	
	efekt.start(0,1);
}

/*
 *	Plynne zamkniecie okna (diva)
 *	@param obj id
 */

function CloseWindow(id) {
	var efekt = new Fx.Style(id,'opacity',{
		duration: 600,
		onComplete: function(){
			id.remove();
			var Node = $('Canvas');
			Node.parentNode.removeChild(Node);
		}
	});
	
	efekt.start(1,0);
}

/**
 *	Pokazywanie grafiki przedstawiającej ładowanie danych podczas wczytywania zawartości
 *	@param string divID
 *	@param int imgSize
 */
function Loader(divID, imgSize) {
	divX = $(divID).getStyle('width');
	divY = $(divID).getStyle('height');
	
	if (imgSize == undefined || imgSize == null || imgSize == '' || imgSize > 32) {
		imgSize = 32;		//domyslna maksymalna wartosc
	} else if (imgSize < 12) {
		imgSize = 12;		//domyslna minimalna wartosc
	}
	
	imgLeft = (parseInt(divX) - imgSize) / 2;
	imgTop = (parseInt(divY) - imgSize) / 2;
	
	var el = new Element('div', {
		'styles': {
			'width': divX,
			'height': divY,
			'padding-left': imgLeft+'px',
			'padding-top': imgTop+'px'
		}
	});
	el.injectInside(divID);
	
	var img = new Element('img', {
		'src': 'img/loader.gif',
		'width': imgSize+'px',
		'height': imgSize+'px'
	});
	img.injectInside(el);
}

/*
 *	Flash okna
 *	@param string id
 */
function FlashWindow(id) {
	var efekty = $(id).effects({
		duration: 50
	});
	
	efekty.start({
		"opacity": [1,0.7]
	}).chain(function(){
		efekty.start({
			"opacity": [0.7,1]
		});
	}).chain(function(){
		efekty.start({
			"opacity": [1,0.7]
		});
	}).chain(function(){
		efekty.start({
			"opacity": [0.7,1]
		});
	});
}
/*-- END OPERACJE NA PLYWAJACYCH OKNACH --*/

/*-- GALERIA --*/
var ShowPhoto = new XHR({
	onRequest: function() {
		FillWindow($('gallery'), '');
		Loader($('gallery'));
	},
	onSuccess : function() {
		$('gallery').innerHTML = this.response.text;
	//	ShowFrame('gallery','480','450');
	}
});

var NextPhoto = new XHR({
	onRequest: function() {
		FillWindow($('gallery'), '');
		Loader($('gallery'));
	},
	onSuccess : function() {
		document.getElementById('gallery').innerHTML = this.response.text;
	}
});

function ShowNextPhoto (theURL) {
//	Loader($('gallery'));
	NextPhoto.send(theURL,'get');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	var divID = 'gallery';
	if (!$(divID)) {
		
		div = CreateWindow(divID,'480','480');
		
		ShowPhoto.send(theURL,'get');
		ShowWindow(div);
	} else {
		FlashWindow($(divID));
	}
}

function setCanvas(obj) {
	var divMaster = null;
	var divCanvas = null;
	
	var PageWidth = document.body.scrollWidth+'px';
	var PageHeight = document.body.scrollHeight+'px';
	
	divMaster = document.body;

	var divCanvas = new Element('div', {
		'id': 'Canvas',
		'name': 'Canvas',
		'styles': {
			'position': 'absolute',
			'display': 'none',
			'zindex': '1',
			'top': '0',
			'left': '0',
			'width': PageWidth,
			'height': PageHeight,
			'opacity': '.5',
			'backgroundColor': '#000000'
		},
		'events': {
			'click': function(){
				CloseWindow($(obj));
			}
		}
	});
	divCanvas.injectInside(divMaster);
	divCanvas.setStyle('display', 'block');
}

function HideErrorFrame(divID) {	//alias funkcji
	CloseWindow($(divID));
}
/*-- END GALERIA --*/

function SearchDL(keyword) {
	var product = document.getElementById('product_id').value;
	var category = document.getElementById('category_id').value;
//	var keyword = document.getElementById('keyword').value;
	if (document.getElementById('list')) {
		var per_site = document.getElementById('list').value;
	}
//	keyword = str2b64(keyword);
	location.href = ","+category+","+product+","+keyword+",download.php";
}

function SearchFAQ(keyword) {
	var product = document.getElementById('product_id').value;
	var keyword = document.getElementById('keyword').value;
	if (document.getElementById('list')) {
		var per_site = document.getElementById('list').value;
	}
	keyword = str2b64(keyword);
	location.href = ","+product+",,"+keyword+",pomoc.php";
}


function MM_jumpMenu(keyword){ //v3.0
	var per_site = document.getElementById('quickmenu').list.value;
	var product = document.getElementById('product_id').value;
	var category = document.getElementById('category_id').value;
//	var keyword = document.getElementById('keyword').value;
//	keyword = str2b64(keyword);
	location.href = ","+category+","+product+","+keyword+",download.php";
}

function HideValueTxt (p, txt) {
	if (p.value == txt) {
		p.value = '';
	}
}

function ShowValueTxt (p, txt) {
	if (p.value == '') {
		p.value = txt;
	}
}

function ChangeFaqProduct (p) {
	var product = p.value;
	location.href = ","+product+",,,faq.php";
}

function ChangeReviewProduct (p) {
	var product = p.value;
	location.href = ","+product+",,,recenzje.php";
}

function ChangeSNEnable(wartosc) {
	if (wartosc != 'N') {
		document.getElementById('sn').disabled = false;
	} else {
		document.getElementById('sn').value = '';
		document.getElementById('sn').disabled = true;
	}
}


//++Obsluga bannerów konfigurowalnych z panelu administracyjnego
var updateBanner =  new XHR({
	onSuccess: function() {
		wynik = this.response.text;
		if (wynik != undefined && wynik != '') window.location = wynik;
	}
});
function updateBannerClick(bannerId, loc) {
	updateBanner.send('update_banner_click.php?bannerId='+bannerId+'&loc='+loc,'post');
};
//--