function validateContactForm(form)
{
	if (!emailcheck(document.getElementById("mail").value)) {
		alert('Niepoprawny adres email');
		return false;
	}
	if (document.getElementById("wiadomosc").value=="") {
		alert('Wypełnij pole wiadomość');
		return false;
	}
	document.getElementById(form).submit();
}

function addFormChange(step, source)
{
	makeRequest(source,'step'+step);
	for (i=step+1; i<8; i++)
	{
		document.getElementById('step'+i).innerHTML='';
	}
}

function validateChecks()
{
	if (document.getElementById('regulamin').checked!=true)
	{
		alert("Musisz zatwierdzić regulamin");
		return false;
	}
	if (document.getElementById('zgoda').checked!=true)
	{
		alert("Musisz wyrazić zgodę na przetwarzanie danych");
		return false;
	}
	if (document.getElementById('btnNextStep').disabled=="")
	{
		document.getElementById('formularz').submit();
	}
}

function rebuildList(answer, listId)
{
	var list=document.getElementById(listId);

  	while (list.length > 0)
  	{
    	list.remove(list.length - 1);
  	}

	var xmlResponse = answer.responseXML;
	if (xmlResponse!=null)
	{
		xmlRoot = xmlResponse.documentElement;
		elementArray = xmlRoot.getElementsByTagName("element");

		var opt = document.createElement('option');
		opt.text='wszystkie';
		opt.value=-1;
  		try {
  			list.add(opt,null);
		} catch(ex) {
			list.add(opt);
		}

		for (var i=0; i<elementArray.length; i++)
		{
			var opt = document.createElement('option');
			opt.text=elementArray.item(i).firstChild.data;
			opt.value=elementArray.item(i).getAttribute("id");
//			opt.value=i;
	  		try {
	  			list.add(opt,null);
			} catch(ex) {
				list.add(opt);
			}
		}
	}
	calculateMatchingAds();
}

function searchCount(answer)
{
	var xmlResponse = answer.responseXML;

	if (xmlResponse!=null)
	{
		xmlRoot = xmlResponse.documentElement;
		count = xmlRoot.getElementsByTagName("count");
		document.getElementById('miniSearchBtn').value='Wyszukaj ('+count.item(0).firstChild.data+')';
	}

}

function calculateMatchingAds()
{
	var str='';

	str+=document.getElementById('miniMarka').value;
	str+=',';
	str+=document.getElementById('miniModel').value;
	str+=',';
	str+=document.getElementById('miniCena').value;
	str+=',';
	str+=document.getElementById('miniRokProd').value;
	str+=',';
	str+=document.getElementById('miniPrzebieg').value;
	str+=',';
	str+=document.getElementById('miniPaliwo').value;
	str+=',';
	str+=document.getElementById('miniNadwozie').value;
	getXmlAnswer('index.php?xtm=ajaxDataSource.jxtm&section=Count&subsection=all&data='+str,'searchCount',Array());
}

function addToFav(id)
{
	getXmlAnswer('addToFav.php?id='+id,'addToFavFinish',Array());
}

function addToFav2(id)
{
	getXmlAnswer('addToFav.php?id='+id+'&n=1','addToFavFinish',Array());
}

function addToFavFinish()
{
	document.getElementById('addToFavC').innerHTML='Dodano do ulubionych';
}

function changeAdPhoto(id,x,y)
{
	document.getElementById('bigPhoto').src="mainpage/data/an_zdjecia/plik/"+id+".jpg";
	document.getElementById('bigPhoto').width=x;
	document.getElementById('bigPhoto').height=y;
}

function changeAdPhoto2(id,x,y)
{
	document.getElementById('bigPhoto').src="mainpage/data/an_zdjecia_nieruchomosci/plik/"+id+".jpg";
	document.getElementById('bigPhoto').width=x;
	document.getElementById('bigPhoto').height=y;
}

function openGallery(img)
{
	window.open('adGallery.php?src='+img,'newWindow','width=880, height=600, resizable=1, scrollbars=no, menubar=no');
}

function changeZasieg()
{
	var typReklamy = document.getElementById("typReklamy").value;
	if(typReklamy==1)
	{
		document.getElementById("zasiegCheckbox").style.display = "block";
		document.getElementById("zasiegNieruchomosciCheckbox").style.display = "none";
	}
	if(typReklamy==2)
	{
		document.getElementById("zasiegCheckbox").style.display = "none";
		document.getElementById("zasiegNieruchomosciCheckbox").style.display = "block";
	}

}
