var licz = 0;

function getAbsoluteTop(elem) {
  if (elem)
    return elem.offsetTop + getAbsoluteTop(elem.offsetParent)

  return 0;

}

function getAbsoluteLeft(elem) {
  if (elem)
    return elem.offsetLeft + getAbsoluteLeft(elem.offsetParent)

  return 0;
}

function loadPage(page)
{
	xbDEBUG.dump('loadPage ' + page);

  document.location = page;

}

function GoURL(url) {
   window.location=url;
}

function KeepVisibleMenuBox(mbox) {
	var menubox = xbGetElementById(mbox);
	var menubox_style = new xbStyle(menubox);
	if (menubox_style.getVisibility != 'visible') {
		menubox_style.setVisibility('visible');
	}
}

function ShowMenuBox(target,mbox) {
	var pointer = xbGetElementById(target);
	var pointer_style = new xbStyle(pointer);

	var menubox = xbGetElementById(mbox);
	var menubox_style = new xbStyle(menubox);

	if (menubox_style.getVisibility == 'visible') {
		menubox_style.setVisibility('hidden');
	}
	
	var top = getAbsoluteTop(pointer);
	var left = getAbsoluteLeft(pointer);
	
  	menubox_style.setTop(top+17);
	menubox_style.setLeft(left);
	menubox_style.setVisibility('visible');
}

function HideMenuBox(mbox) {
	var menubox = xbGetElementById(mbox);
	var menubox_style = new xbStyle(menubox);
	menubox_style.setVisibility('hidden');
}

function HideAllMenuBox() {
	var menubox = xbGetElementById('menu');
	var menubox_style = new xbStyle(menubox);
	menubox_style.setVisibility('hidden');

	var menubox = xbGetElementById('menuprodukty');
	var menubox_style = new xbStyle(menubox);
	menubox_style.setVisibility('hidden');

	var menubox = xbGetElementById('menureferencje');
	var menubox_style = new xbStyle(menubox);
	menubox_style.setVisibility('hidden');
}

function SwapImgRestore() {
  var i,x,a=document.FS_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function PreloadImages() {
  var d=document; if(d.images){ if(!d.FS_p) d.FS_p=new Array();
    var i,j=d.FS_p.length,a=PreloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.FS_p[j]=new Image; d.FS_p[j++].src=a[i];}}
}

function FindObj(n, d) {
  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=FindObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function SwapImage() {
  var i,j=0,x,a=SwapImage.arguments; document.FS_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=FindObj(a[i]))!=null){document.FS_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function IsEmailValid(emailStr)
{
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	
	if (matchArray==null) {
		return false;
	}

	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			return false;
   		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			return false;
		}
	}
	if (user.match(userPat)==null) {
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
	for (var i=1;i<=4;i++) {
		if (IPArray[i]>255) {
			return false;
		}
	}
	return true;
	}
 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			return false;
		}
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		return false;
	}
	if (len<2) {
		return false;
	}
	return true;
}



function CheckForm() {
	var field_name = xbGetElementById('name');
	var field_email = xbGetElementById('from');
	var field_subject = xbGetElementById('subject');
	var field_message = xbGetElementById('feedback');
	if (field_name.value == '') {
		alert('Proszę wpisać imię i nazwisko!');
		return false;
	} else 
        if (IsEmailValid(field_email.value)==false) {
		alert('Proszę podać prawidłowy adres e-mail!');
		return false;
	} else
	
        if (field_subject.value == '') {
		alert('Proszę wpisać temat wiadomości!');
		return false;
	} else
        if (field_message.value == '') {
		alert('Proszę wpisać treść wiadomości!');
		return false;
	} else return true;
}



function Zoom(nazwa,szer,wys) {
config='left=100,top=100,width='+szer+',height='+wys+',innerheight='+wys+',innerwidth='+szer+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no';
liczb='okno'+licz;
stadion=window.open('',liczb,config)
stadion.document.write('<HTML><HEAD>');
stadion.document.write('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">');
stadion.document.write('<TITLE>Fin Skog</title>');
stadion.document.write('<script language="javascript">');
stadion.document.write('setTimeout(');
stadion.document.write('"self.close()');
stadion.document.write(';",70000)');stadion.document.write('</');
stadion.document.write('script>');
stadion.document.write('</HEAD>');
stadion.document.write('<body bgcolor=white leftmargin=0 topmargin=0 marginheight=0 marginwidth=0>');
stadion.document.write('<DIV align="center"><a href="#" onclick="javascript:self.close();"><img src="grafika/screens/'+nazwa+'" border=0></A></DIV>');
stadion.document.write('</body></html>');
licz++;
stadion.focus();
}

