/* menu g³owne */

var activeMenu = -999;
var delay_hide=500
var menuobj=document.getElementById? document.getElementById("submenu") : document.all? document.all.submenu : "";

function showit(which){
	if (which!='-1' && which!='-999') activeMenu = which;
	clear_delayhide()
	thecontent=(which==-1 || which==-999)? submenu[0] : submenu[which]
	if (document.getElementById||document.all) {
		menuobj.innerHTML=thecontent
		if (which!='-1' && which!='-999') { 
			for (a = 0; a < submenu.length; ++a) btnOff(a);
			btnOn(which);
		}
	} else if (document.layers){
		menuobj.document.write(thecontent)
		menuobj.document.close()
	}
}


function resetit(e){
	if (document.all&&!menuobj.contains(e.toElement))
		delayhide=setTimeout("showit(-1),btnOff(activeMenu)",delay_hide)
	else if (document.getElementById&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
	delayhide=setTimeout("showit(-1),btnOff(activeMenu)",delay_hide)
}

function btnOff(which) {
	if (which != '-999' && which != '0') {
		var menuobj2=document.getElementById('m'+which);
		menuobj2.className = 'off';
	};
}

function btnOn(which) {
	if (which != '-999') {
		var menuobj2=document.getElementById('m'+which);
		menuobj2.className = 'on';
	};
}

function clear_delayhide(){
if (window.delayhide)
clearTimeout(delayhide)
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

/**********************************/
/* funkcje sprawdzajace formularz */

function questionDialog(pytanie,url) {
	if (confirm(pytanie)) {
	  document.location = url;
	  return true;
	}
};

function lr_onchange(plik){
  var lr = document.grid_lr.lr.value;
  location.href = plik+'&lr='+lr;
};

if(document.all && !document.getElementById) {

		// For IE5 and other 
    document.getElementById = function(id) {
         return document.all[id];
    }
}

// It checks if [09] are only signs in a string.
function is09length(formName,fieldName,message) {
  var test = eval("document."+formName+"."+fieldName+".value.match(/^[0-9, ,-]+$/)");
  var dlugosc = eval("document."+formName+"."+fieldName+".value.length;");
  var wartosc = eval("document."+formName+"."+fieldName+".value;");
  var znak = wartosc.substring(0,1);
  var s;
  var liczba_cyfr;
  
  
  if ( test==null ) { 
	alert(message);
	eval('document.'+formName+'.'+fieldName+'.focus();');
	return false;
  }
  else {
  	   liczba_cyfr = 0;
        for (var i = 0; i < dlugosc; i++) {
		
			if ((wartosc.substring(i,1+i) == '-')){
			   s = 'myslnik';
			} else if ((wartosc.substring(i,1+i) == ' ')){
			   s='spacja';
			} else {
			   s='cyfra';
			   liczba_cyfr++;
			};
        }
		if (liczba_cyfr == 10) {
		  return true;
		} else {
		  alert(message);
	  	  eval('document.'+formName+'.'+fieldName+'.focus();');
		  return false;		
		};
  };
}

// sprawdza czy jedynymi znakami w lancuchu to [az][AZ][09][.][_]
function isAZaz09_kropka_kreska(formName,fieldName,message) {
  var test = eval("document."+formName+"."+fieldName+".value.match(/^[A-Z,a-z,0-9,.,_]+$/)");
  if ( test==null ) { 
	alert(message);
	eval('document.'+formName+'.'+fieldName+'.focus();');
	return false;
  }
  else {return true;};
}

// sprawdza czy jedynymi znakami w lancuchu to [az][AZ][09]
function isAZaz09(formName,fieldName,message) {
  var test = eval("document."+formName+"."+fieldName+".value.match(/^[A-Z,a-z,0-9]+$/)");
  if ( test==null ) { 
	alert(message);
	eval('document.'+formName+'.'+fieldName+'.focus();');
	return false;
  }
  else {return true;};
}


// sprawdza czy jedynymi znakami w lancuchu to [09]
function is09(formName,fieldName,message) {
  var test = eval("document."+formName+"."+fieldName+".value.match(/^[0-9]+$/)");
  if ( test==null ) { 
	alert(message);
	eval('document.'+formName+'.'+fieldName+'.focus();');
	return false;
  }
  else {return true;};
}

// sprawdza czy jedynymi znakami w lancuchu to [09][ ][-]
function is09_(formName,fieldName,message) {
  var test = eval("document."+formName+"."+fieldName+".value.match(/^[0-9, ,-]+$/)");
  if ( test==null ) { 
	alert(message);
	eval('document.'+formName+'.'+fieldName+'.focus();');
	return false;
  }
  else {return true;};
}

// sprawdza czy jedynymi znakami w lancuchu to [az][AZ][-]
function isAZaz_(formName,fieldName,message) {
  var test = eval("document."+formName+"."+fieldName+".value.match(/^[A-Z,a-z,-,±,¡,ê,Ê,æ,Æ,³,£,ñ,Ñ,ó,Ó,¶,¦,¼,¬,¯,¿]+$/)");
  if ( test==null ) { 
	alert(message);
	eval('document.'+formName+'.'+fieldName+'.focus();');
	return false;
  }
  else {return true;};
}

// sprawdza czy jedynymi znakami w lancuchu to [az][AZ][ ]
function isAZaz(formName,fieldName,message) {
  var test = eval("document."+formName+"."+fieldName+".value.match(/^[A-Z,a-z, ,±,¡,ê,Ê,æ,Æ,³,£,ñ,Ñ,ó,Ó,¶,¦,¼,¬,¯,¿]+$/)");
  if ( test==null ) { 
	alert(message);
	eval('document.'+formName+'.'+fieldName+'.focus();');
	return false;
  }
  else {return true;};
}

// sprawdza czy jedynymi znakami w lancuchu to [az][AZ][ ][.]
function isAZaz_kropka(formName,fieldName,message) {
  var test = eval("document."+formName+"."+fieldName+".value.match(/^[A-Z,a-z, ,.,±,¡,ê,Ê,æ,Æ,³,£,ñ,Ñ,ó,Ó,¶,¦,¼,¬,¯,¿]+$/)");
  if ( test==null ) { 
	alert(message);
	eval('document.'+formName+'.'+fieldName+'.focus();');
	return false;
  }
  else {return true;};
}


// sprawdza czy jedynymi znakami w lancuchu to [az][AZ][ ][.][-]
function isAZaz_kropka_kreska(formName,fieldName,message) {
  var test = eval("document."+formName+"."+fieldName+".value.match(/^[A-Z,a-z,0-9, ,-,.,±,¡,ê,Ê,æ,Æ,³,£,ñ,Ñ,ó,Ó,¶,¦,¼,¬,¯,¿]+$/)");
  if ( test==null ) { 
	alert(message);
	eval('document.'+formName+'.'+fieldName+'.focus();');
	return false;
  }
  else {return true;};
}


function checkIsNumber(formName, fieldName, message){
  var liczba = eval('document.'+formName+'.'+fieldName+'.value;');
  var rex = /,/g;
  var liczba = liczba.replace(rex, '.');

  if (liczba >= 0)
  {
    eval('document.'+formName+'.'+fieldName+'.value=liczba;');
	return true;
  } else
  {
    alert(message);
    eval('document.'+formName+'.'+fieldName+'.focus();');
    return false;
  };
};

function checkIsCurrency(formName,fieldName, message){

var kwota = eval('document.'+formName+'.'+fieldName+'.value;');
var rex = /,/g;
var kwota = kwota.replace(rex, '.');

 if (kwota > 0)
  {
    eval('document.'+formName+'.'+fieldName+'.value='+kwota+';')
	return true;
  } else
    {
      alert(message);
      eval('document.'+formName+'.'+fieldName+'.focus();')
      return false;
    }; 
};


function chS(obj, new_style) {
    obj.className = new_style;
}


// sprawdza dlugosc lancucha z danego pola jezeli mniejsza niz
// length to wyswietla komunikat
function checkLengthText(formName,fieldName,length,message){
  var string = eval('document.'+formName+'.'+fieldName+'.value;');
  
  if (string.length < length){
    alert(message);
    eval('document.'+formName+'.'+fieldName+'.focus();');
	return false;  
  } else {
      return true;
    };
};

// porownuje czy hasla sa takie same
function checkEqualityText(formName,fieldName_1,fieldName_2,message){

var field_1 = eval('document.'+formName+'.'+fieldName_1+'.value;');
var field_2 = eval('document.'+formName+'.'+fieldName_2+'.value;');

if (field_1 != field_2) {
   alert(message);
   eval('document.'+formName+'.'+fieldName_1+'.focus();');
   return false;
} else {
    return true;
  };

};


// sprawdza czy pole typu text jest wype³nione
function checkFormText(formName,fieldName, message) {
  if (eval('document.'+formName+'.'+fieldName+'.value == ""') ) {
    alert(message);
	eval('document.'+formName+'.'+fieldName+'.focus();');
    return false;
  } else {return true;};
};

// sprawdza czy pole typu select ma wartosc inna niz 0
function checkFormSelect(formName,selectName, message) {
  if (eval('document.'+formName+'.'+selectName+'.selectedIndex == 0')) {
    alert(message);
	eval('document.'+formName+'.'+selectName+'.focus();')
    return false;
  } else {return true}
};


// sprawdza czy pole typu select ma wartosc 999 (dla slownikow przy dopisywaniiu
// innej wartosci
function checkFormSelect999(formName,selectName, message) {

var val_1 = eval('document.'+formName+'.'+selectName+'.value;');
var val_2 = eval('document.'+formName+'.'+selectName+'_inna.value;');

  if ((val_1 == 999) && (val_2 == '')) {
    alert(message);
	eval('document.'+formName+'.'+selectName+'_inna.focus();')
    return false;
  } else {return true}
};


// sprawdza czy pole typu select ma wartosc inna niz 0
function checkFormSelectRok(formName,selectName_1,selectName_2, message) {

  var rok_1 = eval('document.'+formName+'.'+selectName_1+'.selectedIndex');
  var rok_2 = eval('document.'+formName+'.'+selectName_2+'.selectedIndex');

  
  if (rok_1>rok_2) {
    alert(message);
	eval('document.'+formName+'.'+selectName_1+'.focus();')
    return false;
  } else {return true}
};



// sprawdza czy pole typu select ma wartosc inna niz '-' 
function checkFormTextData(formName,fieldName, message) {
  if (eval('document.'+formName+'.'+fieldName+'.value == "-"')) {
    alert(message);
	eval('document.'+formName+'.'+fieldName+'.focus();');
    return false;
  } else {return true;};
};

// sprawdza czy pole typu select ma wartosc inna niz '-' 
function checkFormTextDataDouble(formName,fieldName, message) {
  if (eval('document.'+formName+'.'+fieldName+'.value == "--"')) {
    alert(message);
	eval('document.'+formName+'.'+fieldName+'.focus();');
    return false;
  } else {return true;};
};

// sprawdza czy ktorykolwiek radiobutton z danej grupy jest zaznaczony
function readRadioVal(formName,radioName) {
	
	var theRadio = eval('document.'+formName+'.elements[\''+radioName+'\'];');
	
    theValue = 'Unknown';
    if (typeof theRadio != 'undefined') {
        if (typeof theRadio.length == 'undefined') {
            theRadio = new Array(theRadio);
        }
        for (var i = 0; i < theRadio.length; i++) {
            if (theRadio[i].checked) {
                theValue = theRadio[i].value;
                break;
            }
        }
    }
	return theValue;
}

// sprawdza czy radiobutton z danej grupy jest zaznaczony
function checkRadio(formName,radioName,message) {
  valueRadio = readRadioVal(formName,radioName);
  if (valueRadio == 'Unknown') {
	alert(message);		
	return false;
  } else {return true}
}


// sprawdza czy pole typu checkbox jest zaznaczone
function checkFormCheckbox(formName,fieldName, message) {
  if (!eval('document.'+formName+'.'+fieldName+'.checked') ) {
    alert(message);
	eval('document.'+formName+'.'+fieldName+'.focus();')
    return false;
  } else {return true}
};


function checkKodPocztowy(formName, message_1,message_2){

  var k1 = eval('document.'+formName+'.kod_1.value;');
  var k2 = eval('document.'+formName+'.kod_2.value;');
  var isOK_1 = false;
  var isOK_2 = false;
  var isOK_3 = false;
  var isOK_4 = false;

  if (k1 == "" || k2 == "")
    {
      if (!checkFormText(formName,'kod_1',message_1)) {return false}
      if (!checkFormText(formName,'kod_2',message_1)) {return false}
    }
/*
  if (k2 == '000') {
    alert(message_2);
	eval('document.'+formName+'.kod_1.focus();');
	return false;
  } else {
	 isOK_1 = true;
  };	
*/
	isOK_1 = true;
	
  if ((k1 >= 0)&&(k1.length == 2)&&(k2 >= 0)&&(k2.length == 3))
	{
	isOK_2 = true;
	}
  else {
    alert(message_2);
	eval('document.'+formName+'.kod_1.focus();');
	return false;
  };

  if (!is09(formName,'kod_1',message_2)) {return false} else {isOK_3 = true;};
  if (!is09(formName,'kod_2',message_2)) {return false} else {isOK_4 = true;};

  if ((isOK_1) && (isOK_1) && (isOK_1) && (isOK_1)) {
    return true;
  };
  
};


function checkKodPocztowy_kor(formName, message_1,message_2){

  var k1 = eval('document.'+formName+'.kod_1_kor.value;');
  var k2 = eval('document.'+formName+'.kod_2_kor.value;');
  var isOK_1 = false;
  var isOK_2 = false;
  var isOK_3 = false;
  var isOK_4 = false;

  if (k1 == "" || k2 == "")
    {
      if (!checkFormText(formName,'kod_1_kor',message_1)) {return false}
      if (!checkFormText(formName,'kod_2_kor',message_1)) {return false}
    }

  if ((k1 =='00') || (k2 == '000')) {
    alert(message_2);
	eval('document.'+formName+'.kod_1_kor.focus();');
	return false;
  } else {
	 isOK_1 = true;
  };	
	
  if ((k1 >= 0)&&(k1.length == 2)&&(k2 >= 0)&&(k2.length == 3))
	{
	isOK_2 = true;
	}
  else {
    alert(message_2);
	eval('document.'+formName+'.kod_1_kor.focus();');
	return false;
  };

  if (!is09(formName,'kod_1_kor',message_2)) {return false} else {isOK_3 = true;};
  if (!is09(formName,'kod_2_kor',message_2)) {return false} else {isOK_4 = true;};

  if ((isOK_1) && (isOK_1) && (isOK_1) && (isOK_1)) {
    return true;
  };
  
};







//otwiera okno
function openWin (path,Xsiz,Ysiz,top,left,scrBar) {
	if (scrBar == '') { scrBar = 'no'; }
	window.open(path, 'okno', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrBar+',resizable=yes,fullscreen=no,channelmode=no,width='+Xsiz+',height='+Ysiz+',top='+top+',left='+left);
	void(0);
};


// sprawdza czy zostal wpisany email i jego poprawnoœæ
function testEmail(formName,fieldName,message) {
  var test = eval("document."+formName+"."+fieldName+".value.match(/^.*\@.*\..*$/)");
  if ( test==null ) { 
	alert(message);
	eval('document.'+formName+'.'+fieldName+'.focus();');
	return false;
  }
  else {return true;};
}

function flash(name,src,x,y,ver,opcja) {
		
	if (is_ie) { b = 'ie' }
	else if (is_gecko) { b = 'gecko' }
	else if (is_opera) { b = 'opera' }

	if (opcja == 'w3c' || (opcja == 'jsOpti' && b != 'ie')) {
		document.write ('<object id="'+name+'" type="application/x-shockwave-flash" data="'+src+'?browser='+b+'" width="'+x+'" height="'+y+'" >');
		document.write ('<param name="movie" value="'+src+'?browser='+b+'" >');
		document.write ('<param name="swliveconnect" value="true">');
		document.write ('</object>');
	}
	else if (opcja == 'fsc' || (opcja == 'jsOpti' && b == 'ie')) {

		document.write ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
		document.write ('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+ver+',0,0,0"');
		document.write ('width='+x+' height='+y+' id="'+name+'">');
		document.write ('<param name=movie value="'+src+'?browser='+b+'">');
		document.write ('<param name=quality value=high>');
		document.write ('<param name="swliveconnect" value="true">');
		document.write ('<embed src="'+src+'?browser='+b+'" quality="high" width="'+x+'" height="'+y+'"');
		document.write (' type="application/x-shockwave-flash"');
		document.write (' pluginspage="http://www.macromedia.com/downloads/"');
		document.write (' name="'+name+'" swliveconnect="true">');
		document.write ('</embed>');
		document.write ('</object>');
	}
}

function wOver (w) {
		if (document.getElementById("FlashMap")) document.getElementById("FlashMap").SetVariable('w', w);
}
function wOut () {
		if (document.getElementById("FlashMap")) document.getElementById("FlashMap").SetVariable('w', 0);
}

function accessToElement(formName,fieldName, access){
  if (access) {
    eval('document.'+formName+'.'+fieldName+'.disabled = false');
  } else {
   eval('document.'+formName+'.'+fieldName+'.disabled = true');
  };  
};

function accessToElementById(fieldNameId, access){
  if (access) {
	document.getElementById(fieldNameId).disabled = '';
  } else {
    document.getElementById(fieldNameId).disabled = 'disabled';
  };  
};



function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.lastIndexOf("@") == email.length-1) {  // @ must not be the last character
        return false;
    } else if (email.lastIndexOf(".") == email.length-1) {  // . must not be the last character
        return false;
    }

	
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}


// sprawdza czy zostal wpisany email i jego poprawnoœæ
function testEmail2(formName,fieldName,message) {
  var test = eval('isValidEmail(document.'+formName+'.'+fieldName+'.value);');
  if (test == false) { 
	alert(message);
	eval('document.'+formName+'.'+fieldName+'.focus();');
	return false;
  }
  else {return true;};
}



/* ---------- */

function start() {
	menuobj.innerHTML=submenu[0];
		
}



