var idelement_focused='';
var inne_dni='';

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 clp() {
	if(window.clr_clp==true) return false;

	window.clr_clp=true;
	if(window.clipboardData) {
		window.clipboardData.setData("Text","");
	} else {
		var flashcopier='clipb';
		if(!document.getElementById(flashcopier)) {
			var divholder = document.createElement('div');
			divholder.id = flashcopier;
			document.body.appendChild(divholder);
		}

		var clipb = new SWFObject("/includes/_clipboard.swf", "clipb", "0", "0", "8", "#333333", true);
		clipb.write("clipb");
	}
	setTimeout("window.clr_clp=false",2000);
}

function loop_clp() {
	window.onfocus=function() { clp(); }
	window.onblur=function() { clp(); }
	window.oncopy=function() { clp(); }
	window.onkeypress=function() { clp(); }
}

function firmy_sel_woj(woj_id) {
	if(document.getElementById('f_woj_id_'+woj_id)) {
		document.getElementById('f_woj_id_'+woj_id).checked=true;
		firmy_load_miasta(woj_id);
	}
}

var kat_id=0;
var woj_id=0;
function firmy_load_miasta(wid,kid) {
	if(wid===undefined) wid=0;
	if(kid===undefined) kid=0;

	if(wid==='' && kat_id==kid) return false;
	if(kid==='' && woj_id==wid) return false;

	if(wid!=='') {
		if(woj_id!=wid) {
			document.getElementById('f_miasto_content').innerHTML='';
			firmy_choose_miasto('wszystkie miasta');
		}
		woj_id=wid;
	}
	if(kid!=='') {
		if(kat_id!=kid) {
			document.getElementById('f_miasto_content').innerHTML='';
			firmy_choose_miasto('wszystkie miasta');
		}
		kat_id=kid;
	}


	if(woj_id===0 && kat_id===0) {
		document.getElementById('f_miasto_content').innerHTML='';
		firmy_choose_miasto('wszystkie miasta');
	} else {
		advAJAX.post({
			url : "includes/ajax_firmy_miasta.php",
			parameters : { "woj_id": woj_id, "kat_id": kat_id },
			onSuccess : function(obj) { 
				$('f_miasto_content').innerHTML=obj.responseText; 
			}
		});
	}
}

function firmy_choose_miasto(miasto) {
	document.getElementById('f_miasto').value=miasto;
}



function attach_firmy_kat_visualisation() {
	var ile=document.getElementById('firmy_kat_counter').value;

	for(var i=1; i<=ile; i++) {
		var temp_div=document.getElementById('firma_kat_div_'+i);
		temp_div.onmouseover=function() { if(this.className!='firma_kat_sel') this.className='firma_kat_hover'; }
		temp_div.onmouseout=function() { if(this.className!='firma_kat_sel') this.className='firma_kat'; }
	}
}

function firmy_kat_visualisation(selected) {
	var ile=document.getElementById('firmy_kat_counter').value;

	for(var i=1; i<=ile; i++) {
		var temp_div=document.getElementById('firma_kat_div_'+i);
		if(i==selected) {
			temp_div.className='firma_kat_sel';
		} else {
			temp_div.className='firma_kat';
		}
	}
//	bottom(780);
}




function bottom(targetYPos) {
	var y = document[getDocElName()].scrollTop;
	if(y<targetYPos){
		window.scrollBy(0,2);
		bottom(targetYPos);
	}
	return false;
}

function getDocElName(){
	if(document.compatMode && document.compatMode == "CSS1Compat"){
		return "documentElement";
	} else {
		return "body";
	}
}

