var movBlock = true;

$(document).ready(function(){
	
	$("#ChangeView").change(function(){
		$(this).submit();
	})
	$("#offerlist .SterNext").click(function(){
		if(movBlock) {
			movBlock = false;
			var num = $(this).parent().attr("id").split("GalSter");
			MoveGal(num[1],'next')
		}
	})
	$("#offerlist .SterPrev").click(function(){
		if(movBlock) {
			movBlock = false;
			var num = $(this).parent().attr("id").split("GalSter");
			MoveGal(num[1],'prev')
		}
	})
	$("#offerlist .SterPrev").animate({opacity:0.2},1);
	
	$("#GalSterOf .SterNext").click(function(){
		if(movBlock) {
			movBlock = false;
			var num = $(this).parent().attr("id").split("GalSter");
			MoveGal(num[1],'next')
		}
	})
	$("#GalSterOf .SterPrev").click(function(){
		if(movBlock) {
			movBlock = false;
			var num = $(this).parent().attr("id").split("GalSter");
			MoveGal(num[1],'prev')
		}
	})
	$("#GalSterOf .SterPrev").animate({opacity:0.2},1);
	
	$('#s_odod').datepicker();
	$('#s_oddo').datepicker();
	$('#s_ozod').datepicker();
	$('#s_ozdo').datepicker();
	$('#offerleft a.show').lightBox({fixedNavigation:true});
	$('#offerlist a.show').lightBox({fixedNavigation:true});
	
	$("#FSZP a").click(function(){
		$("#miniform").animate({ height: 'toggle', opacity: "toggle"}, "slow");
		return false;
	});
	/* 
	$("#FSZU").click(function(){
		$("#miniform").animate({ height: 'hide', opacity: "hide"}, "slow",null,function(){
			$("#FSZU").animate({ height: 'hide', opacity: "hide"}, "slow");
			$("#FSZP").animate({ height: 'show', opacity: "show"}, "slow");
		});
	});
	*/
	
	var wl = window.location.href.split("?");
	if(wl.length>1) {
		if(wl[1].substr(0,5)=='offer') {
			var c =  document.cookie.split( ';' );
			var zez = new Array(false,false);
			for(var i=0;i<c.length;i++) {
				b = c[i].split("=");
				if(b[0].substr(-3)=='oaa'&&b[1].length>0) zez[0] = true;
				if(b[0].substr(-2)=='ol'&&b[1].length>0) zez[1] = true;
			}
			SetFast(zez);
		}
	}
});

function PrintOffer(k) {
	window.open('printoffer.php?k='+k,'pw','width=700,height=880');
	return false;
}

function MoveGal(num,k) {	
	var ipos = $("#GalRow"+num+" img").length;
	var ppos = $("#GalRow"+num+" .Countainer").css("left").split("px");
	var xpos = ppos[0]/260;
	if(k=='next'&&((xpos-3)*-1)<ipos) var d = (xpos-1)*260;
	else if(k=='prev'&&xpos<0) var d = (xpos+1)*260;
	else var d = xpos*260;
	var dd = d/-260;
	if(dd>0) {
		$("#GalSter"+num+" .SterPrev").attr({"disabled":false});
		$("#GalSter"+num+" .SterPrev").animate({opacity:1},"fast");
	}else{
		$("#GalSter"+num+" .SterPrev").attr({"disabled":true});
		$("#GalSter"+num+" .SterPrev").animate({opacity:0.2},"fast");
	}
	if((dd+3)<ipos) {
		$("#GalSter"+num+" .SterNext").attr({"disabled":false});
		$("#GalSter"+num+" .SterNext").animate({opacity:1},"fast");
	}else{
		$("#GalSter"+num+" .SterNext").attr({"disabled":true});
		$("#GalSter"+num+" .SterNext").animate({opacity:0.2},"fast");
	}
	$("#GalRow"+num+" .Countainer").animate({left:d+"px"},"slow", null, function(){
		movBlock = true;
	});
}

function SetFast(zez) {
	onkeydown = function(e) {
		var code;
		if (!e) var e = window.event;
		if (e.keyCode) code = e.keyCode;
		else if (e.which) code = e.which;
		if(code==114&&zez[0]) {
			if($("#OfferId").length) window.open("admin/?showoffer="+$("#OfferId").val(),"adminPage");
		}else if(code==113&&zez[1]) {
			if($("#FastLink").length) window.open($("#FastLink").text(),"_blank");
			else alert("Brak linku do tej oferty...");
		}
	}
}

function PriceSter(z) {
	var op = $("#s_cenam2").val();
	if((isNaN(op)||op=="") && z!="c" ) op = "5000";
	else if(op==""&&z=="c") op = "";
	else if(isNaN(op)&&z=="c") op = "5000";
	else{
		op = op*1;
		if(z=="p") op += 200;
		else if(z=="m") op -= 200;
	}
	$("#s_cenam2").val( op );
}

Nowe=null; 
function ShowPic(id) { 
	winwidth = 400;
	winheight = 400;
	xpoz = screen.width/2 - winwidth/2;
	ypoz = screen.height/2 - winheight/2;
	Nowe=null;
	Nowe=window.open("pokaz.php?name="+id, "","s_toolbar=no,menubar=no,location=no,personalbar=no, scrollbars=yes,status=no,directories=no,resizable=yes,height="+winheight+",width="+winwidth+",left="+xpoz+",top="+ypoz);
	Nowe.focus();
}

function PreviewPic(id) {
	document.getElementById('mainzdj').innerHTML = '<a href="'+id+'" rel="lightbox[onpage]"><img src="images/'+id+'" width="250" height="188" style="width:250px;height:188px" alt="Powiększenie" /></a>';
}
/* 
function PreviewPic(id) {
	document.getElementById('mainzdj').innerHTML = '<a href="javascript:void(null)" onclick="ShowPic(\''+id+'\');"><img src="images/'+id+'" width="250" height="188" style="width:250px;height:188px" alt="Powiększenie" /></a>';
}
*/
function Go2Home() {
	window.location = "index.php";
}
function GoForm(p) {
	n = p.split("|");
	if(n.length==2) window.location = "index.php?typ="+n[0]+"&tr="+n[1];
	else window.location = "index.php";
}
function GoUserForm(p) {
	n = p.split("|");
	if(n.length==2) window.location = "index.php?user&form&typ="+n[0]+"&tr="+n[1];
	else window.location = "index.php?user&form";
}

function GoSearch() {
	if(SprDate()) {
		document.location.href = "index.php?search&"+MakeURL()+"&sort=Odata";
	}
}
function GoMiniSearch(url) {
	if(SprDate()) {
		document.location.href = "index.php?search&"+url+"&"+MakeURL();
	}
}

function MakeURL() {
	if(document.getElementById("s_zgoda") != undefined) url = "zgoda&";
	else url = "";
	url += "typ="+document.getElementById('s_typ').value+"&tr="+document.getElementById('s_tr').value;
	tid = new Array("woj","miej","dziel","ulica","pow1","pow2","cena1","cena2","cenam2","key","sub","nrof","mat","zab","lpok","piet1","piet2","lpiet","rokb1","rokb2","data","powdz1","powdz2","rodzdzia","dojazd","typgru","typnie","doda","odod","oddo","ozod","ozdo");
		for(i=0;i<(tid.length);i++) {
			if(document.getElementById("s_"+tid[i]) != undefined && document.getElementById("s_"+tid[i]).value != '') url += "&"+tid[i]+"="+(document.getElementById("s_"+tid[i]).value);
		}
		tidc = new Array("media1","media2","media3","media4","media5","media6","z","bez","t","m","p");
		for(i=0;i<(tidc.length);i++) {
			if(document.getElementById("s_"+tidc[i]) != undefined) {
				if(document.getElementById("s_"+tidc[i]).checked == true) url += "&"+tidc[i];
			}
		}
return url;
}

function ShowOffer() {
	winwidth = 820;
	winheight = 600;
	xpoz = screen.width/2 - winwidth/2;
	ypoz = screen.height/2 - winheight/2;
	Nowe=null;
	Nowe=window.open("index.php?search&"+MakeURL()+"&sort=Odata", "","s_toolbar=no,menubar=no,location=no,personalbar=no, scrollbars=yes,status=no,directories=no,resizable=yes,height="+winheight+",width="+winwidth+",left="+xpoz+",top="+ypoz);
	Nowe.focus();
}

function SaveForm() {
	blok = document.getElementById("blok").value;
	if(blok==1) {
		if(confirm('Czy chcesz ZMIENIĆ dotychczasowe kryteria ??')) {
			Pola(false);
			document.getElementById("blok").value=0;
			document.getElementById("buttedit").value = 'ZAPISZ';
			return false;
		}else return false;
	}else{
		if(confirm("Czy na pewno chcesz ZAPISAĆ te kryteria ??")) {
			document.form.action = "index.php?user&form&"+MakeURL();
			return true;
		}else return false;
	}
}
function SaveEmptyForm() {
	if(confirm('Czy chcesz USUNˇĆ dotychczasowe kryteria ??')) {
		document.form.action = "index.php?user&form";
		return true;
	}
}

function Pola(tf) {
	t = new Array("woj","miej","dziel","ulica","pow1","pow2","cena1","cena2","cenam2","key","sub","nrof","mat","zab","lpok","piet1","piet2","lpiet","rokb1","rokb2","data","powdz1","powdz2","rodzdzia","dojazd","typgru","typnie","doda","media1","media2","media3","media4","media5","media6","z","bez","t","m","p","odod","oddo","ozod","ozdo","dodatkowy_opis");
	for(i=0;i<(t.length);i++) {
		if(document.getElementById("s_"+t[i]) != undefined) document.getElementById("s_"+t[i]).disabled = tf;
	}
}

function GoFiltr(url) {
	if(SprDate()) {
		tid = new Array("odod","oddo","ozod","ozdo");
		for(i=0;i<(tid.length);i++) {
			if(document.getElementById("s_"+tid[i]) != undefined && document.getElementById("s_"+tid[i]).value != '') url += "&"+tid[i]+"="+escape(document.getElementById("s_"+tid[i]).value);
		}
		tidc = new Array("t","m","p");
		for(i=0;i<(tidc.length);i++) {
			if(document.getElementById("s_"+tidc[i]) != undefined) {
				if(document.getElementById("s_"+tidc[i]).checked == true) url += "&"+tidc[i];
			}
		}
		document.location.href = url;
	}
}

function GoLink(url) {
	document.location.href = url;
}

function DelOffer(key) {
	if(confirm('Czy chcesz USUNˇĆ t± ofertę z notatek ??')) {
		document.getElementById("key2del").value = key;
		document.notes.submit();
	}
}

function ShowMessage(m) {
	alert(m);
}

function Go2Form(f1,f2) {
	if(f2.length>0) {
		if(f1==f2) {
			alert("Te oferty masz już zapisane.");
			return false;
		}else{
			if(confirm('Masz już zapisane oferty, czy chcesz je zast±pić nowymi??')) {
				document.location.href = "index.php?user&form&add"+f1;
			}else return false;
		}
	}else document.location.href = "index.php?user&form&add"+f1;
}

function GoAddForm(p) {
	n = p.split("|");
	if(n.length==2) window.location = "index.php?addform&typ="+n[0]+"&tr="+n[1];
	else window.location = "index.php";
}

/* ================================================================== */

function  CheckUserForm1() {
	
	regemail = /^[a-z0-9][\w\.-]*\w@([\w-]+\.)*[a-z]{2,4}$/;
	regtel = /^[0-9 -]{3,20}$/;
	regimnaz = /^[A-Za-z ęĘóÓ±ˇ¶¦łŁżŻˇ¬ćĆńŃ]{2,80}$/;
	
	var ufimnaz = document.getElementById('ufimnaz').value;
	var ufemail = document.getElementById('ufemail').value;
	var uftelefon = document.getElementById('uftelefon').value;
	
	if(!regimnaz.test(ufimnaz)) {
		alert('Miło nam będzie poznać także Imię i nazwisko');
		return false;
	}	
	if(!regtel.test(zgtelefon)) {
		alert('Wpisz numer telefonu dla łatwiejszego kontaktu');
		return false;
	}	
	if(!regemail.test(zgemail)) {
		alert('Wpisz poprawnie swój email');
		return false;
	}
	return true;
}

function  CheckUserForm1() {
	regemail = /^[a-z0-9][\w\.-]*\w@([\w-]+\.)*[a-z]{2,4}$/;
	regtel = /^[0-9 -]{3,20}$/;
	regimnaz = /^[A-Za-z ęĘóÓ±ˇ¶¦łŁżŻˇ¬ćĆńŃ]{2,80}$/;
	var ufimnaz = document.getElementById('ufimnaz').value;
	var ufemail = document.getElementById('ufemail').value;
	var uftelefon = document.getElementById('uftelefon').value;
	if(!regimnaz.test(ufimnaz)) {
		alert('Miło nam będzie poznać także Imię i nazwisko');
		return false;
	}	
	if(!regemail.test(ufemail)) {
		alert('Wpisz poprawnie swój email');
		return false;
	}
	if(!regtel.test(uftelefon)) {
		alert('Wpisz numer telefonu dla łatwiejszego kontaktu');
		return false;
	}	
	return true;
}

function  CheckUserFormK() {
	regemail = /^[a-z0-9][\w\.-]*\w@([\w-]+\.)*[a-z]{2,4}$/;
	regtel = /^[0-9 -]{3,20}$/;
	regimnaz = /^[A-Za-z ęĘóÓ±ˇ¶¦łŁżŻˇ¬ćĆńŃ]{2,80}$/;
	regkwo = /^[0-9]{2,}$/;
	var ufimnazk = document.getElementById('ufimnazk').value;
	var ufemailk = document.getElementById('ufemailk').value;
	var uftelefonk = document.getElementById('uftelefonk').value;
	var ufkwotak = document.getElementById('ufkwotak').value;
	if(!regimnaz.test(ufimnazk)) {
		alert('Miło nam będzie poznać także Imię i nazwisko');
		return false;
	}	
	if(!regemail.test(ufemailk)) {
		alert('Wpisz poprawnie swój email');
		return false;
	}
	if(!regtel.test(uftelefonk)) {
		alert('Wpisz numer telefonu dla łatwiejszego kontaktu');
		return false;
	}	
	if(!regkwo.test(ufkwotak)) {
		alert('Proszę wpisać kwotę kredytu używaj±c samych cyfr ');
		return false;
	}	
	return true;
}


function  CheckUserForm2() {
	regemail = /^[a-z0-9][\w\.-]*\w@([\w-]+\.)*[a-z]{2,4}$/;
	regtel = /^[0-9 -]{3,20}$/;
	regimnaz = /^[A-Za-z ęĘóÓ±ˇ¶¦łŁżŻˇ¬ćĆńŃ]{2,80}$/;
	var ufimnazz = document.getElementById('ufimnazz').value;
	var ufemailz = document.getElementById('ufemailz').value;
	var uftelefonz = document.getElementById('uftelefonz').value;
	var ufimnaz = document.getElementById('ufimnaz').value;
	var ufemail = document.getElementById('ufemail').value;
	var uftelefon = document.getElementById('uftelefon').value;
	if(!regimnaz.test(ufimnazz)) {
		alert('Miło nam będzie poznać także imię i nazwisko znajomego');
		return false;
	}	
	if(!regemail.test(ufemailz)) {
		alert('Wpisz poprawnie email znajomego');
		return false;
	}
	if(!regtel.test(uftelefonz)) {
		alert('Wpisz numer telefonu znajomego dla łatwiejszego kontaktu');
		return false;
	}	
	if(!regimnaz.test(ufimnaz)) {
		alert('Miło nam będzie poznać także Imię i nazwisko');
		return false;
	}	
	if(!regemail.test(ufemail)) {
		alert('Wpisz poprawnie swój email');
		return false;
	}
	if(!regtel.test(uftelefon)) {
		alert('Wpisz numer telefonu dla łatwiejszego kontaktu');
		return false;
	}	
	return true;
}

function CheckZgodaForm() {
	
	regemail = /^[a-z0-9][\w\.-]*\w@([\w-]+\.)*[a-z]{2,4}$/;
	regtel = /^[0-9 -]{3,20}$/;
	regimie = /^[A-Za-z ęĘóÓ±ˇ¶¦łŁżŻˇ¬ćĆńŃ]{2,80}$/;
	
	var zg1 = document.getElementById('zg_ch1').checked;
	var zg4 = document.getElementById('zg_ch4').checked;
	var zg2 = document.getElementById('zg_ch2').checked;
	
	var zgimie = document.getElementById('zg_imie').value;
	var zgnazwisko = document.getElementById('zg_nazwisko').value;
	var zgemail = document.getElementById('zg_email').value;
	var zgtelefon = document.getElementById('zg_telefon').value;
	
	if(!zg1&&!zg4) {
		alert('Musisz wyrazić zgodę na na przedstawienie oferty po¶rednictwa lub przedstawienie korzystnych ofert  kredytów  hipotecznych (1 lub 2 punkt).');
		return false;
	}
	if(!regimie.test(zgimie)||!regimie.test(zgnazwisko)) {
		alert('Miło nam będzie poznać także Imię i nazwisko');
		return false;
	}	
	if(!regtel.test(zgtelefon)) {
		alert('Wpisz numer telefonu dla łatwiejszego kontaktu');
		return false;
	}	
	if(!regemail.test(zgemail)) {
		alert('Wpisz poprawnie swój email');
		return false;
	}
	if(!zg2) {
		alert('Proszę zastrzec wykorzystywanie swoich danych.');
		return false;
	}
	return true;
}

function SendOffer() {
	
	imnaz = document.getElementById('imnaz').value;
	telefon = document.getElementById('telefon').value;
	email = document.getElementById('email').value;
	
	regemail = /^[a-z0-9][\w\.-]*\w@([\w-]+\.)*[a-z]{2,4}$/;
	regtel = /^[0-9 -]{3,20}$/;
	regimie = /^[A-Za-z ęĘóÓ±ˇ¶¦łŁżŻˇ¬ćĆńŃ]{2,80}$/;
	if(!regimie.test(imnaz)) {
		alert('Miło nam będzie poznać także Imię');
		return false;
	}	
	if(!regtel.test(telefon)) {
		alert('Wpisz numer telefonu dla łatwiejszego kontaktu');
		return false;
	}	
	if(!regemail.test(email)) {
		alert('Wpisz poprawnie swój email');
		return false;
	}
	
	document.getElementById("operation").value = 'sendoffer';
	document.form.submit();
}

function CheckFormOffer() {
	
	email = document.getElementById("lp_email").value;
	pass = document.getElementById("lp_pass").value;
	repass = document.getElementById("ap_repass").value;
	imie = document.getElementById("ap_imie").value;
	plec = false;
	if(document.getElementById("ap_pm").checked==true) plec = "m";
	if(document.getElementById("ap_pk").checked==true) plec = "k";
	maile = document.getElementById("ap_maile").value;
	telefon = document.getElementById("ap_telefon").value;
	regemail = /^[a-z0-9][\w\.-]*\w@([\w-]+\.)*[a-z]{2,4}$/;
	
	if(!regemail.test(email)) {
		alert("Proszę wpisać poprawnie adres email");
		return false;
	}
	if(pass.length==0) {
		alert("Proszę wpisać hasło");
		return false;	
	}
	if(repass.length==0&&imie.length==0&&maile.length==0) {
		document.getElementById("oper").value = "AddOfferAndLogIn";
		return true;
	}else{
	
		if(repass.length==0) {
			alert("Proszę potwierdzić hasło");
			return false;	
		}
		if(pass!=repass) {
			alert("Hasła nie s± zgodne");
			return false;	
		}
		if(imie.length==0) {
			alert("Proszę wpisać imię");
			return false;	
		}	
		if(!plec) {
			alert("Proszę wybrać płeć");
			return false;	
		}
		if(maile.length>0) {
			ma = maile.split(" ");
			maile = "";
			for(i=0;i<ma.length;i++) maile += ma[i];
			document.getElementById("ap_maile").value = maile;
			ma = maile.split(",");
			for(i=0;i<ma.length;i++) {
				if(!regemail.test(ma[i])) {
				alert("¬le wpisano adres email: "+ma[i]);
				return false;
				}else if(ma[i]==document.getElementById("ap_email").value) {
				alert("Adres email: "+ma[i]+" jest już używany jako login");
				return false;
				}
			}
		}
		document.getElementById("oper").value = "AddOfferAndAddAccount";
		return true;
	}
	
}

function CheckForm2(t) {
	
	if(!CheckOffer()) return false;
	else{
	 
	typ = document.getElementById('s_typ').value;
	tr = document.getElementById('s_tr').value;
	document.getElementById("operation").value = 'addnewoffer';
	document.form.action = 'index.php?addform&typ='+typ+'&tr='+tr;
	//document.form.submit();
	return true;
	}
}

function CheckOffer() {
	return true;
   reg = /^[A-Za-z ęĘóÓ±ˇ¶¦łŁżŻˇ¬ćĆńŃ-]{2,200}$/;
   if(!reg.test(document.getElementById("f_miejscowosc").value)) {
		alert("Wpisz miejscowo¶ć !");
		return false;
	}
	reg = /^[A-Za-z0-9 ęĘóÓ±ˇ¶¦łŁżŻˇ¬ćĆńŃ-]{2,250}$/;
   if(!reg.test(document.getElementById("f_ulica").value)) {
		alert("Wpisz ulicę !");
		return false;
	}
	if(document.getElementById("f_dzielnica").value.length>0) {
		reg = /^[A-Za-z ęĘóÓ±ˇ¶¦łŁżŻˇ¬ćĆńŃ-]{2,200}$/;
	   if(!reg.test(document.getElementById("f_dzielnica").value)) {
			alert("Wpisz dzielnicę !");
			return false;
		}
	}
	
   if(document.getElementById("f_typ_zabudowy").value.length==0) {
		alert("Wybierz typ zabudowy !");
		return false;
	}
	if(document.getElementById("f_material").value.length==0) {
		alert("Wybierz materiał !");
		return false;
	}
	reg = /^[0-9]{4}$/;
   if(!reg.test(document.getElementById("f_rok").value)) {
		alert("Wpisz rok budowy !");
		return false;
	}
	reg = /^[0-9]{1,2}$/;
   if(!reg.test(document.getElementById("f_liczba_pokoi").value)) {
		alert("Wpisz liczbę pokoi !");
		return false;
	}
	fpow = document.getElementById("f_powierzchnia").value;
	if(isNaN(fpow) && !fpow>0) {
		alert("Wpisz powierzchnię !");
		return false;
	}
	reg = /^[0-9]{1,2}$/;
   if(!reg.test(document.getElementById("f_pietro").value)) {
		alert("Wpisz piętro !");
		return false;
	}
	reg = /^[0-9]{1,2}$/;
   if(!reg.test(document.getElementById("f_liczba_pieter").value)) {
		alert("Wpisz liczbę pięter !");
		return false;
	}
	if(document.getElementById("f_forma_wlasnosci").value.length==0) {
		alert("Wybierz formę własno¶ci !");
		return false;
	}
	fczynsz = document.getElementById("f_czynsz").value;
	if(fczynsz.length>0) {
		if(isNaN(fczynsz)) {
			alert("Wpisz poprawnie czynsz !");
			return false;
		}
	}
	fcena = document.getElementById("f_cena").value;
	if(fcena.length>0) {
		if(isNaN(fcena)) {
			alert("Wpisz poprawnie cenę !");
			return false;
		}
	}
	
	return true;

}

/* ================================================================== */
function SendMessage(c) {
	
	ftelefon = document.getElementById('ftelefon').value;
	femail = document.getElementById('femail').value;
	tresc = document.getElementById('tresc').value;
	
	regtelefon = /^[0-9 -]{5,20}$/;
	regemail = /^[a-z0-9][\w\.-]*\w@([\w-]+\.)*[a-z]{2,4}$/;
	
	if(tresc=='') {
		alert('Wpisz tre¶ć zapytania');
		return false;
	}
	if(!regemail.test(femail) && femail!='') {
		alert('Wpisz poprawny adres email !');
		return false;
	}
	if(!regtelefon.test(ftelefon)) {
		alert('Wpisz poprawnie numer telefonu !');
		return false;
	}
	document.getElementById('moper').value = c;
	document.form.submit();
	
}

function SendEmail2Friend() {
	femailz = document.getElementById('emailz').value;
	ftemat = document.getElementById('temat').value;
	ftresc = document.getElementById('tresc').value;
	femail = document.getElementById('email').value;
	
	regemail = /^[a-z0-9][\w\.-]*\w@([\w-]+\.)*[a-z]{2,4}$/;
	regtemat = /^[0-9A-Za-z ęĘóÓ±ˇ¶¦łŁżŻˇ¬ćĆńŃ]{2,250}$/;
	
	if(!regemail.test(femailz)) {
		alert('Wpisz poprawnie email znajomego');
		return false;
	}	
	if(!regtemat.test(ftemat)) {
		alert('Wpisz temat wiadomo¶ci');
		return false;
	}	
	if(ftresc.length<3) {
		alert('Wpisz tre¶ć');
		return false;
	}	
	if(!regemail.test(femail)) {
		alert('Wpisz poprawnie swój email');
		return false;
	}	
	if(!regtemat.test(ftemat)) {
		alert('Wpisz imię, nazwisko lub pseudonim');
		return false;
	}	
	
	document.getElementById("operation").value = 'send2friend';
	document.form.submit();
}

/* ================================================================== */

function SprDate() {
	odod = document.getElementById("s_odod");
	oddo = document.getElementById("s_oddo");
	ozod = document.getElementById("s_ozod");
	ozdo = document.getElementById("s_ozdo");
	errors = true;
	if(odod&&oddo&&ozod&&ozdo) {
		if(odod.value!="") {
			if(!CheckDate(odod.value)) {
				errors = false;
				alert("Wpisano niepoprawn± datę w pole: 'Oferty zgłoszone od'");
				odod.focus();
			}
		}
		if(oddo.value!="") {
			if(!CheckDate(oddo.value)) {
				errors = false;
				alert("Wpisano niepoprawn± datę w pole: 'Oferty zgłoszone do'");
				oddo.focus();
			}
		}
		if(ozod.value!="") {
			if(!CheckDate(ozod.value)) {
				errors = false;
				alert("Wpisano niepoprawn± datę w pole: 'Oferty modyfikowane od'");
				ozod.focus();
			}
		}
		if(ozdo.value!="") {
			if(!CheckDate(ozdo.value)) {
				errors = false;
				alert("Wpisano niepoprawn± datę w pole: 'Oferty modyfikowane do'");
				ozdo.focus();
			}
		}
		
	}
	return errors;
}

function CheckDate(date)
{
var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
d = date.split("-");
if(d.length==3) {
	
	year = d[0]*1;
	month = d[1]*1;
	day = d[2]*1;
	
	if (isNaN(day)||isNaN(month)||isNaN(year)) return false;

	if (year/4 == parseInt(year/4))
		monthLength[1] = 29;

	if (day > monthLength[month-1]) return false;

	monthLength[1] = 28;
	
	return true;
	
}else return false;

}

/* ================================================================== */

function GoLogin() {
	regemail = /^[a-z0-9][\w\.-]*\w@([\w-]+\.)*[a-z]{2,4}$/;
	if(!regemail.test(document.getElementById("lp_email").value)) {
		alert("Proszę wpisać poprawnie adres email");
		return false;
	}
	if(document.getElementById("lp_pass").value.length==0) {
		alert("Proszę wpisać hasło");
		return false;	
	}
	//document.lp.action = "index.php";
	return true;
}

function CheckForm(t) {
	regemail = /^[a-z0-9][\w\.-]*\w@([\w-]+\.)*[a-z]{2,4}$/;
	if(!regemail.test(document.getElementById("ap_email").value)) {
		alert("Proszę wpisać poprawnie adres email");
		return false;
	}
	if(t=="a" || t=="c" && (document.getElementById("ap_pass").value.length>0||document.getElementById("ap_repass").value.length>0)) {
		if(document.getElementById("ap_pass").value.length==0) {
			alert("Proszę wpisać hasło");
			return false;	
		}
		if(document.getElementById("ap_repass").value.length==0) {
			alert("Proszę potwierdzić hasło");
			return false;	
		}
		if(document.getElementById("ap_pass").value!=document.getElementById("ap_repass").value) {
			alert("Hasła nie s± zgodne");
			return false;	
		}
	}
	if(document.getElementById("ap_imie").value.length==0) {
		alert("Proszę wpisać imię");
		return false;	
	}	
	if(document.getElementById("ap_pm").checked==false&&document.getElementById("ap_pk").checked==false) {
		alert("Proszę wybrać płeć");
		return false;	
	}
	
	maile = document.getElementById("ap_maile").value;
	if(maile.length>0) {
		ma = maile.split(" ");
		maile = "";
		for(i=0;i<ma.length;i++) maile += ma[i];
		document.getElementById("ap_maile").value = maile;
		ma = maile.split(",");
		for(i=0;i<ma.length;i++) {
			if(!regemail.test(ma[i])) {
			alert("¬le wpisano adres email: "+ma[i]);
			return false;
			}else if(ma[i]==document.getElementById("ap_email").value) {
			alert("Adres email: "+ma[i]+" jest już używany jako login");
			return false;
			}
		}
	}
	//document.ap.action = "index.php";
	return true;
}
