
	function checkSearchFields(clickedOn) { 

		pID = document.getElementById('errorBoxContainer')
		pID.style.display = 'none';
	
		strError = '';
	
		setTown();
		
		strKeyWords = trim(removeMultipleWhiteSpaces(document.forms[0].keyWords.value));
		document.forms[0].keyWords.value = strKeyWords;
		
		if (isNumeric(trim(document.forms[0].roomsMin.value)) == false) {
			strError = strError + 'Min pièces n\'est pas numérique<BR>';
		}
		if (isNumeric(trim(document.forms[0].roomsMax.value)) == false) {
			strError = strError + 'Max pièces n\'est pas numérique<BR>';
		}
		if (isNumeric(trim(document.forms[0].surfaceMin.value)) == false) {
			strError = strError + 'Min surface n\'est pas numérique<BR>';
		}
		if (isNumeric(trim(document.forms[0].surfaceMax.value)) == false) {
			strError = strError + 'Max surface n\'est pas numérique<BR>';
		}
		if (isNumeric(trim(document.forms[0].priceMin.value)) == false) {
			strError = strError + 'Min prix n\'est pas numérique<BR>';
		}
		if (isNumeric(trim(document.forms[0].priceMax.value)) == false) {
			strError = strError + 'Max prix n\'est pas numérique<BR>';
		}
		if (parseInt(document.forms[0].roomsMin.value) > parseInt(document.forms[0].roomsMax.value)) {
			strError = strError + 'Min pièces > Max pièces<BR>';
		}
		if (parseInt(document.forms[0].surfaceMin.value) > parseInt(document.forms[0].surfaceMax.value)) {
			strError = strError + 'Min surface > Max surface<BR>';
		}
		if (parseInt(document.forms[0].priceMin.value) > parseInt(document.forms[0].priceMax.value)) {
			strError = strError + 'Min prix > Max prix<BR>';
		}
		if (strKeyWords.length > 250) {
			strError = strError + 'Et/ou précisez : Vous dépassez le maximum de 250 caractères. Réduisez le nombre de caractères et essayez à nouveau.<BR>';
		} 

		//SEARCH
		//********************************
		if (clickedOn == 'search') {
		
			if (isNumeric(trim(document.forms[0].advert.value)) == false) {
				strError = strError + 'Référence n\'est pas numérique<BR>';
			}
			
			if (strError == '') {
			
				document.getElementById('batch').value = 1;
				document.getElementById('advertsCumulative').value = 0;
				document.getElementById('advertsLast').value = '';
				document.getElementById('top').value = 100;
				
				document.forms[0].searchButton.disabled = true;
				pID = document.getElementById('errorBoxContainer')
				pID.style.display = 'none';
				setLastClick();
				setPageFirst();
				document.forms[0].submit();							
				return true;	

			} else {
				document.forms[0].searchButton.disabled = false;
				pID = document.getElementById('errorBoxContainer')
				pID.style.display = 'block';
				pID = document.getElementById('errorMessage')
				pID.innerHTML = strError;
				return false;
			}

		//ALERT
		//********************************
		} else if (clickedOn == 'alert') {
		
			strAlertName = trim(removeMultipleWhiteSpaces(document.getElementById('alertName').value)).toUpperCase();
			iAlert = document.getElementById('alert').value
			document.getElementById('alertName').value = strAlertName;
		
			if (strAlertName == "") {
				strError = strError + 'Veuillez saisir le nom de votre alerte<br>';
			} else if (isAlertNameOk(strAlertName) == false) {
				strError = strError + '/\:*?<>| ne sont pas permis dans le nom de votre alerte<br>';
			}

			if (iAlert == "0") {
				doHttpRequest('HttpAlertName.asp', 'alertName=' + strAlertName);
			}			

			if (strError == '') {

				document.forms[0].searchButton.disabled = true;
				pID = document.getElementById('errorBoxContainer')
				pID.style.display = 'none';
				document.forms[0].submit();							
				return true;	

			} else {
				document.forms[0].searchButton.disabled = false;
				pID = document.getElementById('errorBoxContainer')
				pID.style.display = 'block';
				pID = document.getElementById('errorMessage')
				pID.innerHTML = strError;
				window.location="#errorBoxTop"
				return false;
			}
			
		}
	} 

	function setLastClick() {
		strError = "";	
		doHttpRequest('HttpLastClickSet.asp');
	}

	function setPageFirst() {
		strError = "";	
		doHttpRequest('HttpPageDisplaySet.asp', 'pageDisplay=1');
	}
	
	function setMenu(pMenu, pI) {
		document.getElementById('menu').value = pMenu; 
		doHttpRequest('HttpPageDisplaySet.asp', 'pageDisplay=' + pI);
	}


	function showAdverts() {
		
		strError = "";
		doHttpRequest('HttpPageDisplayGet.asp');
		//alert(strError);
		iPage = 1;
		if (strError != ""){
			iPage = parseInt(strError); 
		}
		iTop = parseInt(document.getElementById('top').value);
		
		iAdvertFirst = (iPage-1) * 10;
		if (iTop > 100) {
			iAdvertFirst = iAdvertFirst + (iTop - 100)
		}
		iAdvertLast = iAdvertFirst + 9;

		//set the page menu
		for ( var i = 1; i < 11; i++ ){

			objMenu1page = document.getElementById('menu1page' + i);
			objMenu2page = document.getElementById('menu2page' + i);
			if ( objMenu1page != null ){
				if ( i == iPage ) {
					objMenu1page.className = 'pageMenuSelected';
					if ( objMenu2page != null ) {
						objMenu2page.className = 'pageMenuSelected';
					}
				} else {
					objMenu1page.className = 'pageMenuNotSelected';
					if ( objMenu2page != null ) {
						objMenu2page.className = 'pageMenuNotSelected';
					}
				}
			}

		}
		
		//set the adverts
		for ( var i = 0; i < iTop; i++ ){
		
			objAdvert = document.getElementById('advert' + i);
			if (objAdvert != null) {
				//alert(i);
				if ((i >= iAdvertFirst) && (i <= iAdvertLast)) {
					objAdvert.style.display = "block";
				} else {
					objAdvert.style.display = "none";
				}
			}
					
		}
		
		//alert(document.getElementById('menu').value);
		if ( document.getElementById('menu').value == '2' ) {
			window.location="#results";
		}
	
	}


	function setBatchAndTop(pDirection, pTop) {
	
		objBatch = document.getElementById('batch');
		objBatchDirection = document.getElementById('batchDirection')
		objTop = document.getElementById('top')
		
		iBatch = parseInt(objBatch.value); 
		iTop = parseInt(objTop.value);
	
		if (pDirection == "DOWN") {
			objBatch.value = iBatch-1; 
			objBatchDirection.value= 'DOWN';
			
			if (pTop == "TOP") {
				objTop.value = iTop-100;
			}

		} else if (pDirection == "UP") {
			objBatch.value = iBatch+1; 
			objBatchDirection.value= 'UP';
			
			if (pTop == "TOP") {
				objTop.value = iTop+100;
			}
		}
		
		if (document.getElementById('buttonDown1') != null) {
			document.getElementById('buttonDown1').disabled = true;
		}
		if (document.getElementById('buttonUp1') != null) {
			document.getElementById('buttonUp1').disabled = true;
		}
		if (document.getElementById('buttonDown2') != null) {
			document.getElementById('buttonDown2').disabled = true;
		}
		if (document.getElementById('buttonUp2') != null) {
			document.getElementById('buttonUp2').disabled = true;
		}
				
		document.forms[0].submit();

	}
