/* BOFHnet rjs@biuro.net.pl */

var win=null;

function setFontSize (sClassName) {
	var body = $$('body').first();
	if (sClassName === 'smallFont' || sClassName === 'mediumFont' || sClassName === 'largeFont')
		setCookie('bodyClassName', sClassName);
	else if (getCookie('bodyClassName'))
		sClassName = getCookie('bodyClassName');
	else
		sClassName = '';
	body.className = sClassName;
}

function setCookie(name, value){
	document.cookie = name + "=" + escape(value) + '; path=/;';
}

function getCookie(name){
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1)
	{
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	}
	else
	{
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
	{
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
} 

/* ** ** ** */

var slideShowLength = new Array();
var slideTimer;
var slideCurrent = 0;
var slideInterval = 5000;

function initSlideShow () {
	$$('#slideShow > div','#slideLinks > a').each(function(e){
		if (e.nodeName == 'DIV')
			slideShowLength.push(e.id);
		new Event.observe(e, 'mouseover', function(){
			clearTimeout(slideTimer);
    });
		new Event.observe(e, 'mouseout', function(){
			slideTimer = setTimeout( "slideNext()", slideInterval );
    });
	});
	slideTimer = setTimeout( "slideNext()", slideInterval );
}

function slideNext () {
	slideCurrent++;
	if (slideCurrent >= slideShowLength.length)
		slideCurrent = 0;
	showSlide(slideCurrent);
	slideTimer = setTimeout( "slideNext()", slideInterval );
}

function showSlide(oSlide) {
	$$('#slideShow > div').each(function(e){
		e.className = (slideShowLength[oSlide] == e.id)?'':'none';
	});
	$$('#slideLinks > a').each(function(e){
		e.className = (oSlide == e.getAttribute('link'))?'active':'';
	});
}

function switchSlide (oLink) {
	showSlide(oLink.getAttribute('link'));
}

function printPage () {
	window.print();
}

function newWindow(sURL,sWinName,w,h,scroll,pos) {
	if(pos=="random") {
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if(pos=="center") {
		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;
	}
	else if((pos!="center" && pos!="random") || pos==null)
		LeftPosition=0;TopPosition=20
	settings='width='+w+',height='+h+',top='+Math.round(TopPosition)+',left='+Math.round(LeftPosition)+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
	win=window.open(sURL,sWinName,settings);
}

function showRegion(sRegion) {
	$$('#indexed > div').each(function (e){
		e.className = (e.id == sRegion)?'':'none';
	})
}

function selectRegion(oSelect) {
	Element.extend(oSelect);
	showRegion(oSelect.getValue());
} 

function validateForm (oForm) {
	Event.observe(window, 'load', function() {
  	Event.observe(oForm, 'submit', function(event){
  		var invalid = 0;
			$$('#'+this.id+' *[validate]').each(function(e){
				var valid = new RegExp(e.getAttribute("validate"));
				if (!valid.test(e.value)) {
					invalid++;
					e.parentNode.addClassName('error')
				} else {
					e.parentNode.removeClassName('error')
				}
			});
			if (invalid) {
				Event.stop(event);
				$('errorInfo').removeClassName('none');
			}
		});
	});
}

function faqHideAnswers () {
	$$('.faq .answer').each(function(e){
		e.hide();
	});
}

function faqShowAnswer (oQuestion) {
	var answerParentId = oQuestion.parentNode.id;
	faqHideAnswers ();
	$$('#'+answerParentId+' .answer').each(function(e){
		e.show();
	});
}

function switchBanner(oNode, sBannerId) {
	var banner = $(sBannerId);
	if (banner)
		oNode.parentNode.innerHTML = banner.innerHTML;
}

function initFaq () {
	var faqId = 0;
	faqHideAnswers ();
	$$('.faq a.question').each(function(e){
		e.href = 'javascript:void(0)';
		e.onclick = function(){faqShowAnswer(this)};
		e.parentNode.id = 'faqId'+faqId++;
	});
}

Event.observe(window, 'load', function() {
	setFontSize('');
	initSlideShow();
	initFaq();
});
