// requires - Prototype

function PopupSizes(nazwa,szer,wys,subtitle) {
  void newWin(nazwa,szer,wys,subtitle);
}
function Popup(nazwa, subtitle) {
	if (nazwa.indexOf('xdata:') == 0) {
		//alert('uu');
		nazwa = nazwa.replace(/xdata:/, "");
		myLightbox.start($('img_' + nazwa));
	}
	else if (myLightbox) {
		var splited = nazwa.split('?');
		var title = '';
		if (splited.length > 1) {
			var params = splited[1].split('&');
			if (params.length > 0) {
				var firstParam = params[0];
				title = firstParam.replace(/title\=/, "");
				if (!window[title])
					title = '';
				else
					title = window[title];
			}
		}
		
		var elem = '<a id="dem878" href="' + nazwa + '" rel="lightbox[roadtrip]" title="' + title + '">dem</a>';
		document.body.insert('<div style="display: none;" id="cacheImg">' + elem + '</div>');
		myLightbox.start($('dem878'));
		$('cacheImg').remove();
	}
	else
		void newWin(nazwa,0,0,subtitle);
	
}
function myurlencode(string) {
    return escape(string).replace(/[+]/g, '%2B');
}
function doprint() {
	adr = 'http://' + document.location.host + document.location.pathname + document.location.search;
 
  if (adr.match(/[\?]/))
    NewHtm(adr + '&print=1' + document.location.hash, 700, 400);
  else
    NewHtm(adr + '?print=1' + document.location.hash, 700, 400);
}
function dorecommend() {
  loc = document.location.href;
  NewHtm('/recommend.php?qs='+escape(loc), 400, 480);
}
function newWin(nazwa,szer,wys,subtitle) {
var sizes = false;
if (wys>0) { 
    sizes = true;
    szer = szer+28;
    wys = wys+28;
    odlewa=(screen.width-szer)/2;
    odgory=(screen.height-wys)/2;
} else {
    szer = 800;
    wys = 600;
    odlewa=(screen.width)/4;
    odgory=(screen.height)/8;
}

config='left='+odlewa+',top='+odgory+',width='+szer+',height='+wys+',innerheight='+wys+',innerwidth='+szer+',toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=auto';
cel=window.open('','okno',config)
cel.document.write('<HTML><HEAD>');
cel.document.write('<link rel="stylesheet" href="/css/main.css" type="text/css" />');
cel.document.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">');
cel.document.write('<TITLE>'+document.title+'</title>');
if (!sizes) {
// alert(window.screenX); 
  cel.document.write('<script language="javascript">');
  cel.document.write('	var temp=self.location.href.split("?");');
  cel.document.write('	var picUrl = (temp.length>1)?temp[1]:"";');
  cel.document.write('	var NS = (navigator.appName=="Netscape")?true:false;');
  cel.document.write('	function fitPic() {');
  cel.document.write('		iImg1 = document.getElementById("img1");');
  cel.document.write('		iWidth = (NS)?window.innerWidth:document.body.clientWidth;');
  cel.document.write('		iHeight = (NS)?window.innerHeight:document.body.clientHeight;');
  cel.document.write('		if (iImg1.width>800) iWidth = 640 - iWidth; else { iWidth = iImg1.width - iWidth; }');
  cel.document.write('		if (iImg1.height>600) iHeight = 700 - iHeight; else { iHeight = iImg1.height + '+((subtitle)?'64':'3')+' - iHeight; }');
  cel.document.write('		window.resizeBy(iWidth, iHeight-1);');
  cel.document.write('		window.screenX = screen.width / 2 - document.body.clientWidth / 2; ');
  cel.document.write('		window.screenY = screen.height / 2 - document.body.clientHeight / 2;');
  cel.document.write('		self.focus();');
  cel.document.write('	};');
  cel.document.write('	function setTitle() {');
  cel.document.write('		self.document.title = top.opener.document.title;');
  cel.document.write('	};');
  cel.document.write('</script>');
}
cel.document.write('</HEAD>');
cel.document.write('<body class="imagepopup" scroll="auto">');
cel.document.write('<div id="image"><a href=# onclick="javascript:self.close();"><img src='+nazwa+' id="img1" class=obw alt="Kliknij aby zamknąć okno" onload="javascript: fitPic();" align=center border="0"></a></div>');
if (subtitle)
	cel.document.write('<div id="subtitle">'+subtitle+'</div>');
//if (!sizes) {
//  cel.document.write('<script language="javascript">');
//  cel.document.write('	setTitle();');
//  cel.document.write('</script>');
//}
cel.document.write('</body></html>');
cel.document.close();
cel.focus();
}

function NewHtm(nazwa,szer,wys) {
odlewa=(screen.width-szer)/2;
odgory=(screen.height-wys)/2;		
config='left='+odlewa+',top='+odgory+',width='+szer+',height='+wys+',innerheight='+wys+',innerwidth='+szer+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes';
stadion=window.open(nazwa,'okno',config);
stadion.focus();
}
function NewHtmNoScr(nazwa,szer,wys) {
odlewa=(screen.width-szer)/2;
odgory=(screen.height-wys)/2;		
config='left='+odlewa+',top='+odgory+',width='+szer+',height='+wys+',innerheight='+wys+',innerwidth='+szer+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes';
stadion=window.open(nazwa,'okno',config);
stadion.focus();
}

function gotables() {
    tables = document.getElementsByName('info');
    for (i=0; i<tables.length; i++) {
        trs = tables[i].getElementsByTagName('tr');
        for (j=0; j<trs.length; j++) {
            trs[j].className += ' line'+(j % 2);
        }
    }
}

function isEmailCorrect(el) {
   var emailFilter=/^([\w\-_]+\.)*([\w\-_]+)@([\w\-_]+\.)+([a-zA-Z]{2,4})$/;
   
   if (!emailFilter.test(el))
	return false;
   else
   	return true;
}

function  cleartext(q){
        document.getElementById(q).value = "";
}


function showDiv(elem) {
	showdiv(elem);
}

function showdiv(elem) {
	if (!isNaN(parseInt(elem))) {
		showregion(elem);
	}
	else {
		if (document.getElementById(elem).style.display == 'none')
			document.getElementById(elem).style.display = 'block';
		else
			document.getElementById(elem).style.display = 'none'
			window.focus();
	}
}

function showregion(num) {
	for (var t = 0; t < 10; t++) {
		if ($('region_' + t))
			$('region_' + t).hide();
	}
	if ($('region_' + num))
		$('region_' + num).show();
}

function panelizeDiv(divId, config) {
	// disable horizontal scrollbars:
	var bodyElement = $$('body')[0];
	var htmlElement = $$('html')[0];
	bodyElement.setStyle({overflowX: "hidden"});
	htmlElement.setStyle({overflowX: "hidden"});

	// read layer:
	var panel = $(divId);
	if (!Object.isElement(panel)) {
		alert('Panel does not exists.');
		return;
	}
	
	// position layer:
	var dimms = Element.getDimensions(bodyElement);
	panel.absolutize();
	panel.setStyle({
		left: dimms.width - config.offsetFromRight + "px",
		top: (config['top'] ? config.top : 200) + "px",
		width: (config['width'] ? config.width : 200) + "px",
		height: (config['height'] ? config.height : 200) + "px"
	});
	panel.writeAttribute('state', 'start');
	panel.show();
	
	panel.stopObserving('mouseover');
	panel.observe('mouseover', function() {
		var state = panel.readAttribute('state');
		if (state == 'start') {
			new Effect.Move(panel, {
							x: -1 * (config.width - config.offsetFromRight), 
							queue: { position: 'end', scope: 'fscope' },
							afterFinish: function () {}
						});
			panel.writeAttribute('state', 'moving');
		}
	});
	
	panel.stopObserving('mouseout');
	panel.observe('mouseout', function() {
		var state = panel.readAttribute('state');
		if (state == 'moving') {
			var queue = Effect.Queues.get('fscope');
			queue.each(function(effect) { effect.cancel(); });
			var panelLeft = parseInt(panel.getStyle('left'));
			var toMove = (dimms.width - config.offsetFromRight) - panelLeft;
			new Effect.Move(panel, {
							x: toMove,
							afterFinish: function () { panel.writeAttribute('state', 'start'); }
						});
		}
	});

}
		
