var idelement_focused='';

function preloadimages()	{ for (i=0;i<preloadimages.arguments.length;i++) { myimages[i]=new Image(); myimages[i].src=preloadimages.arguments[i];	} } var myimages=new Array();

function check_s(forma) {
	var s1=true;
	var s2=true;
	var s3=true;
	var s4=true;
	var s5=true;

	//pole tekstowe
	var s=forma.s_txt.value;
	if(s=="" || s==" " || s=="  ") s1=false;

	//typ obiektu
	if(forma.s_typ.value=="") s2=false;

	//typ obiektu
	if(forma.s_typ.value=="") s2=false;


   if(s1==false && s2==false && s3==false && s4==false && s5==false) {
		alert('Proszę użyć choć jednego kryterium wyszukiwania!');
      return false;
	} else {
		forma.submit();
	}
}

function switch_search(pos) {
	s1=document.getElementById('s_sbox1').style;
	s2=document.getElementById('s_sbox2').style;

	if(pos==1) {
		s1.display="block";
		s2.display="none";
	} else {
		s1.display="none";
      s2.display="block";
	}
}

function ulubione(title,url){
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,"");
	} else if(window.opera) {

		var mbm = document.createElement('a');
		mbm.setAttribute('rel','sidebar');
		mbm.setAttribute('href',url);
		mbm.setAttribute('title',title);
		mbm.click();
	} else if(document.all) {
		window.external.AddFavorite(url,title);
	}
}

function show_hide(list) {
	var listElementStyle=document.getElementById(list).style; 
	if (listElementStyle.display=="none") {
		listElementStyle.display="inline";
	} else {
		listElementStyle.display="none";
	} 
}

function show_hide_block(list) {
	var listElementStyle=document.getElementById(list).style; 
	if (listElementStyle.display=="none") {
		listElementStyle.display="block";
	} else {
		listElementStyle.display="none";
	} 
}

function check_terminy(changed) {
	if(changed=='s_od' || changed=='s_do') {
			var term1=document.getElementById('s_od').value.replace('-','').replace('-','');
			var term2=document.getElementById('s_do').value.replace('-','').replace('-','');

			if(term1!="" && term2!="" && term1>term2) {
				if(changed=='s_od') {
			      alert('Data rozpoczęcia nie może być większa od daty zakończenia!');
				} else {
			      alert('Data zakończenia nie może być mniejsza od daty rozpoczęcia!');
				}
				document.getElementById(changed).value='';
			}
   } else {
			var term1=document.getElementById('s_od2').value.replace('-','').replace('-','');
			var term2=document.getElementById('s_do2').value.replace('-','').replace('-','');

			if(term1!="" && term2!="" && term1>term2) {
				if(changed=='s_od2') {
			      alert('Data rozpoczęcia nie może być większa od daty zakończenia!');
				} else {
			      alert('Data zakończenia nie może być mniejsza od daty rozpoczęcia!');
				}
				document.getElementById(changed).value='';
			}
	}
}


function check_ceny(changed) {
	var cena1a=document.getElementById('s_cena_od').value;
	var cena2a=document.getElementById('s_cena_do').value;
	var cena1=parseInt(cena1a);
	var cena2=parseInt(cena2a);

//	alert(cena1+" - "+cena2);

	if(isNaN(cena1) && cena1a!="") {
      alert('To nie jest liczba!');
		document.getElementById(changed).value='';
		return false;
	}
	if(isNaN(cena2) && cena2a!="") {
      alert('To nie jest liczba!');
		document.getElementById(changed).value='';
		return false;
	}


	if(cena1!="" && cena2!="" && cena1>cena2) {
		if(changed=='s_cena_od') {
	      alert('Dolna granica cenowa nie może być większa od górnej!');
		} else {
	      alert('Górna granica cenowa nie może być mniejsza od dolnej!');
		}
		document.getElementById(changed).value='';
	}
}


function potwierdzenie(link,pytanie,komunikat) {
	var sprawdz = window.confirm(pytanie);
	if(sprawdz==true) {
		window.location=link;
		if(komunikat!="" && komunikat!=" ") alert(komunikat);
		return false;
	}
}

function link_potwierdzenie(link,pytanie) {
	var sprawdz = window.confirm(pytanie);
	if(sprawdz==true) window.location=link;
}


function input_validator(e, regexp) {
	if(navigator.userAgent.indexOf('Gecko') != -1) charCode = e.which; else charCode = e.keyCode;
	if(charCode > 31) {
		znak = String.fromCharCode(charCode);
		return regexp.test(znak);
	}
}


function isMaxLength(obj){ //maxlength 4 textareas
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if(obj.getAttribute && obj.value.length+1>mlength) {
		obj.value=obj.value.substr(0,mlength);
		return false;
	}
}


function isMaxLength_validated(obj, e, regexp){ //maxlength 4 textareas with input validation
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""

	if(navigator.userAgent.indexOf('Gecko') != -1) charCode = e.which; else charCode = e.keyCode;
	if(charCode > 31 && obj.getAttribute && obj.value.length<mlength) {
		znak = String.fromCharCode(charCode);
		return regexp.test(znak);
	} else {
		return false;
	}

}

function check_email(forma) {
	if(forma.email.value.length > '0') {
		var re = new RegExp("[^@]{1,}[@]{1}[^@.]{1,}[.]{1}[^@]{1,}","gi");
		var wynik = re.test(forma.email.value);
		if (wynik == false) {
			alert('Nieprawidłowy adres E-mail!');
			forma.email.focus();
			return false;
		}
	} else {
		alert('Podaj adres E-mail!');
		forma.email.focus();
		return false;
	}
}


function search_slownik(forma,link) {
	var s=forma.szukaj.value;
	s=s.replace(/^\s+|\s+$/g, '');
	s=encodeURIComponent(s);

	window.location='/'+link+'/szukaj-'+s+'/';
	return false;
}