var msg="Welcome to www.nga.pl ";
var mywin = null;

function okno_wyb2(link,nazwa,szer,wys)
{
	var SupAg="raczek";
	var FIRMA="58";

	var centerWidth=(window.screen.width-szer)/2;
	var centerHeight=(window.screen.height-wys)/4;
	var lng=link.substring(0,2);

	if(link.substring(3,14)=="wyb_lok.php"){
		if(document.ffind.Ewoj.value=="-"){
			switch (lng){
				case 'en':window.alert("Firstly you have select Province !!");break;
				case 'de':window.alert("Vorher muss eine Woiwodschaft ausgewählet werden !!");break;
				default :window.alert("Wcze¶niej Musisz wybrać Województwo !!");
				}
			document.ffind.Ewoj.focus();
			return true;
			}
		else if(link.substring(20,23)=="lok")if(document.ffind.Egmi.value==""){
			switch (lng){
				case 'en':window.alert("Firstly you have select Commune !!");break;
				case 'de':window.alert("Vorher muss eine Gemeinde ausgewählet werden !!");break;
				default :window.alert("Wcze¶niej Musisz wybrać gminę !!");
				}
			document.ffind.igmi.focus();
			return true;
			}
		}

//alert(typeof mywin=='object');
//if(mywin!=null){mywin.close();}
//if(mywin && typeof mywin=='object' && !mywin.closed)mywin.close()

	if(link.substr(0,28)=="http://www.nga.pl/zdjecia/ag")
		{if (ofertaZ(link)!=FIRMA) link="http://www.nga.pl/zdjecia/ag/"+SupAg+".php";}
	else if (link.substr(0,9)=="offer.php")
	{if (ofertaZ(link)!=FIRMA)link=link+"&FIR="+FIRMA+"&SupAgt="+SupAg;
	link="http://www.nga.pl/"+link;
	}

	mywin=window.open(link,nazwa,
		'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,copyhistory=0,width='+szer+
		',height='+wys+',left=' + centerWidth +',top=' + centerHeight);

	mywin.focus();
//	return mywin.name;
}

// wybiera z linku numer biura nieruch. 
function ofertaZ(str)
{  return(str.substr(str.indexOf("Fid=")+4,2)); }

function wstaw() {
	window.close();
}

function GO_(link){top.menu_r.location.href=link;}

function go_l(link)

{	
    document.location=link;
    /*
    if (window.parent.location!=window.location)top.menu_r.location.href=link;
	else top.location.href='.';
	*/
}

/* filtr lokalizacji */

function IsEmpty(tx) {
	if(tx.value==null)return true;
	if(tx.value.length==0)return true;
	return false;
}	

function onCha_woj() //fun.php
{
	d=document;
	d["ilok"].src="stale/find-g.gif";

	if(d.ffind.Ewoj.value=="-")d["igmi"].src="stale/find-g.gif";
	else d["igmi"].src="stale/find.gif";
	
	d.ffind.Egmi.value="";
	d.ffind.Elok.value="";
}

function onCha_gmi() //OK
{
	d=window.opener.document;
	d.ffind.Egmi.value=window.document.forma.lokS.options[window.document.forma.lokS.selectedIndex].value;

	if(IsEmpty(d.ffind.Egmi))d["ilok"].src="stale/find-g.gif";
	else d["ilok"].src="stale/find.gif";
	
	d.ffind.Elok.value="";
	window.close();
}

function onCha_lok()
{
	window.opener.document.ffind.Elok.value=
		window.document.forma.lokS.options[window.document.forma.lokS.selectedIndex].value;
	window.close();
}

/* filtr lokalizacji END */

// --- Combo + edit ---
var o = null;
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function endEditing(menu){
//alert("koncze");
}

function beforeEdt(menu)	
{
//window.alert("event.keyCode:"+event.keyCode+" "+this.searchString(this.dataBrowser));
if(event.keyCode==8 || event.keyCode==13){return false;}
// 8=BS 13=Enter. W mozilli nie dziala: charCode
}


function beginEditing(menu){
	finish();

//	if(menu[menu.selectedIndex].value == "")
	if(menu.length-menu.selectedIndex==1)
	{
		o = new Object();
		o.editOption = menu[menu.selectedIndex];
		o.editOption.old = o.editOption.text;
		o.editOption.text = "|";
		menu.blur();
		window.focus();
		document.onkeypress = keyPressHandler;
	}

 function keyPressHandler(e){
	var option = o.editOption;
	var keyCode = (isNN) ? e.which : event.keyCode;
//window.alert("key:"+keyCode+" menu.len:"+	(menu.length+0) + " index:"+(menu.selectedIndex+1));
	if(keyCode == 8 || keyCode == 60)	// 8 backsp; 60 to "<" kasowanie
		{
		 if (window.event && window.event.keyCode == 8) { // try to cancel the backspace
			window.event.cancelBubble = true;
			window.event.returnValue = false;
			}
		option.text = option.text.substring(0,option.text.length-2) + "|";
			
		}
	else if (keyCode == 13) finish();
	else 
		{
//		if(keyCode == 32)/*spacja*/ window.aktuali.Ftyp.focus();
		option.text = option.text.substring(0,option.text.length-1) + String.fromCharCode(keyCode) + "|";
		}
	status = keyCode;
}

 function finish() {
	if(o != null) {
		option = o.editOption;
		if(option.text.length > 1) option.text = option.text.substring(0,option.text.length-1);
		else option.text = option.old;
		document.onkeypress = null;
		o = null;
//menu.blur();
	}
 }
}

//string na wyjściu: tylko liczby i '.'
function check(el,fm) {

form = document.forms[fm];
wart = form.elements[el].value;
zwr='';
dl=wart.length;
zmiana=false;

for (var j = 0; j < dl; j++)
 {znak=wart.charAt(j);
	if(isNaN(parseInt(znak)))zmiana=true;
	else zwr+=znak;
	}
if(!zmiana) return;
form.elements[el].value=zwr;
}

//string na wyjściu: TEXT bez liczb i '@'
function checkTx(el,fm) {

form = document.forms[fm];
wart = form.elements[el].value;
zwr='';
dl=wart.length;
zmiana=false;

for (var j = 0; j < dl; j++)
 {znak=wart.charAt(j);
	if((parseInt(znak)<39 || parseInt(znak)>30)|| '@'==znak){zmiana=true;}
	else{zwr+=znak;}
	}
if(!zmiana) return;
form.elements[el].value=zwr;
}

/*
object TheForm
string the name of the form field to check
int the min value
int the max value

return boolean whether a valid number has been submitted or not
*/
function checkLimit(theForm, theFieldName, min, max)
{
var theField	= theForm.elements[theFieldName];
var val			= parseInt(theField.value);

if (val < min || val > max) {
	theField.select();
	alert("Niepoprawna Warto¶ć: " +val);
	theField.focus();
	return false;
}

else{theField.value = val;}
document.ffind.page.value=val;
document.ffind.submit();
return false;
}

function expand(id) // odkrywa/ukrywa text
{
//	ids=document.getElementById(id).style;
	ids=document.getElementById(id).style;
	if (ids.display=='block'){
		ids.display='none';
		document.getElementById('r'+id.substring(1)).innerHTML='<b>...[&#8211;&raquo;]</b> '}
	else{ids.display='block';
		document.getElementById('r'+id.substring(1)).innerHTML='<b>...[&laquo;&#8211;]</b> '}
}

//INNI

var interval = 100;
var spacelen = 120;
var space10=" ";
var seq=0;

function Scroll() {
	len = msg.length;
	window.status = msg.substring(0, seq+1);
	seq++;
	if ( seq >= len ) {
		seq = spacelen;
		window.setTimeout("Scroll2();", interval );
	}
	else window.setTimeout("Scroll();", interval );
}

function Scroll2() {
	var out="";
	for (i=1; i<=spacelen/space10.length; i++) out += space10;
	out = out + msg;
	len=out.length;
	window.status=out.substring(seq, len);
	seq++;
	if ( seq >= len ) { seq = 0; };
	window.setTimeout("Scroll2();", interval );
}