 		
	var ajaxCom = false;
	var tmpCommune;
	var ajaxAlertReq = false;
	if (window.XMLHttpRequest) 
		ajaxAlertReq = new XMLHttpRequest();
	
	if (window.XMLHttpRequest) 
	ajaxCom = new XMLHttpRequest();
	if (window.XMLHttpRequest) 
		ajaxCom1 = new XMLHttpRequest();

rnd=Math.random();
	function showPopup() {
		$("#PopupContentDiv").css('display', 'block');

		d = document.getElementById('PopupContentDiv');
		var h = d.offsetHeight;
		var w = d.offsetWidth;
		
		/*do our best to center it*/
		
		var x = (((screen.width)-w) / 2) + document.documentElement.scrollLeft;
		var y = (((screen.height)-h) / 2) + document.documentElement.scrollTop;
		$("#PopupContentDiv").css('position', 'absolute');
		$("#PopupContentDiv").css('top', "30%");
		$("#PopupContentDiv").css('left', '15%');	
		d.onmousedown = grabMe;
		d.onmouseup = releaseMe;		
	    popContent	=	'PopupContentDiv';
		grabMe();
	}
	function closePopup() {
		document.getElementById('loadOption').value = '';
		document.getElementById('loadDivContent').innerHTML = '';
		//document.getElementById('loadDivContent5').innerHTML = '';
		$("#PopupContentDiv").css('display', 'none');
	}
	
	/*function loadContent(val) {	
	showPreloader();
	var modeValue;
	if (val == 'opt1') modeValue = 'Immobilier';
	if (val == 'opt2') modeValue = 'Automobile';
	if (val == 'opt3') modeValue = 'Moto';
	if (val == 'opt4') modeValue = 'EmploiDemande';
	if (val == 'opt5') modeValue = 'EmploiOffre';
	if (val!='opt1' && val!='opt2' && val!='opt3' && val!='opt4' && val!='opt5' && val!='')
	    modeValue = 'Divers';
		//alert("index.php?f=popup_content"+'&mode='+modeValue+ '&value=' +val+'&rnd='+rnd);
	
		$.ajax({
			type: "GET",
			url : "index.php?f=popup_content",
			data: 'mode=' +modeValue+
				  '&value=' +val+
				  '&rnd=' + rnd,
			beforeSend: function(){
			},
			success: function(contentRes){				
				$("#loadDivContent").html(contentRes);
			}
	
		});
	hidePreloader();
	}*/
	
function showbox() {
	$("#email").css('display', 'none');
	if(document.getElementById('accept').checked==true)
		$("#email").css('display', 'block');
	}
function shownombre(nombre,forfait)
	{
			$("#forfait").css('display', 'none');
			$("#nombre").css('display', 'block');
					
	}
function showforfait(forfait)
	{	
			$("#nombre").css('display', 'none');
			$("#forfait").css('display', 'block');
	}

function validationimmobilier() {
 prix1 = document.getElementById('prix').value;
 prix2 = document.getElementById('endprix').value;
	if((prix1!='') && (prix2!='')) {
		prix1 	= parseInt(prix1);
		prix2 	= parseInt(prix2);
		if(prix1>prix2) {
			alert("La deuxième valeur doit être plus élevée que la première");
			return false;
		}
	}
}

function validationautomobile() {
annee1 = document.getElementById('recherAnnee').value;
annee2 = document.getElementById('recharAnneeEnd').value;
if((annee1!='') && (annee2!='')) {
		annee1 	= parseInt(annee1);
		annee2 	= parseInt(annee2);
		if(annee1>annee2) {
			alert("Veuillez écrire une plus grande que d'abord valeur de année de la deuxième valeur de année");
			return false;
		}
	}

prix1 = document.getElementById('recherprix').value;
prix2 = document.getElementById('endrecherprix').value;
	if((prix1!='') && (prix2!='')) {
		prix1 	= parseInt(prix1);
		prix2 	= parseInt(prix2);
		if(prix1>prix2) {
			alert("La deuxième valeur doit être plus élevée que la première");
			return false;
		}
	}
}
// for reacher
	function mainCategory(categoeyNames) {
		//if(categoeyNames!='') {
			$.ajax({
				type: "GET",
				url : "index.php?f=reacher_marque",
				data: 'category=' +categoeyNames+
					  '&rnd=' + rnd,
				beforeSend: function(){
				},
				success: function(contentRes){
					CatArray	=	new Array ('','immobilier','automobile','emploi','divers');
					$("#displayCategory").html(contentRes);
					if(document.getElementById('reachercategory')) {
						for(i=1;i<CatArray.length;i++)
						{
							$('#'+CatArray[i]).css("display", "none");
						}
							category = $('#reachercategory').val();
							$('#'+CatArray[category]).css("display", "block");
							if(category==2)selectMarque(category);
							$('#reachercategory').focus();
							// for selection the form action
							selectFormAction(CatArray[category]);
					}
				}
			});
			
		/*} else {
			alert('Le champ type est vide');
			$('#reacher').focus();
		}*/
	}
	function selectFormAction(formNames) {
		if(formNames == 'automobile') {
			document.getElementById('main_reacher').action ='index.php?f=autoMotoList';
		}else if(formNames == 'immobilier') {
			document.getElementById('main_reacher').action ='index.php?f=immobilierList';
		}else if(formNames == 'emploi') {
			document.getElementById('main_reacher').action ='index.php?f=emploiList';
		}else if(formNames == 'divers') {
			document.getElementById('main_reacher').action ='index.php?f=diversList';
		}
	}
	function selectCategory(category) {
	//alert("category");
		CatArray	=	new Array ('','immobilier','automobile','emploi','divers');
		//if(document.getElementById('reacher').value!='') {
			for(i=1;i<CatArray.length;i++) {
				$('#'+CatArray[i]).css("display", "none");
			}
				$('#'+CatArray[category]).css("display", "block");
			for(i=1;i<CatArray.length;i++) {
				$('#but'+CatArray[i]).css("display", "none");
			}
				$('#but'+CatArray[category]).css("display","block");
				//alert(CatArray[category]);
				
				if(category==2)selectMarque(category);
			// for selection the form action
			selectFormAction(CatArray[category]);
			
		/*} else {
			alert('Le champ recherche est vide');
			$('#reacher').focus();
		}*/
	}
	function selectMarque(category) {
		var marquevalue = '';
		$.ajax({
				type: "GET",
				url : "index.php?f=reacher_marque",
				data: 'marque=' +marquevalue+
					  '&maincategory=' +category+
					  '&rnd=' + rnd,
				beforeSend: function(){
				},
				success: function(contentRes){
					$("#displayMarque").html(contentRes);
				}
			});
			
			//var htmlContent = '<select name="recherModele" id="recherModele" style="width:120px;"><option value="">Sélectionnez</option></select>'
			//$("#displayModele").html(htmlContent);
	}
	function selectModele(marquevalue) {
		$.ajax({
				type: "GET",
				url : "index.php?f=reacher_modele",
				data: 'marque=' +marquevalue+
					  '&rnd=' + rnd,
				beforeSend: function(){
				},
				success: function(contentRes){				
					$("#displayModele").html(contentRes);
					$('#recherModele').focus();
				}
			});
			
	}
	function selectAutoModele(marquevalue) {
		$.ajax({
				type: "GET",
				url : "index.php?f=reacher_automodele",
				data: 'marque=' +marquevalue+
					  '&rnd=' + rnd,
				beforeSend: function(){
				},
				success: function(contentRes){				
					$("#displayModele").html(contentRes);
				}
			});
			
	}
	function checkMainCategory() {
		if($("#reachercategory").val()=='') {
			alert('Le champ type est vide');
			$('#reachercategory').focus();
			return false;
		}
	}
	/*function toSubmitForm(eventkey) {
	alert("tesing");
	alert(eventKey.KeyCode);
		if(navigator.appName.indexOf("Netscape")>(-1)) {
		    if (eventkey.keyCode == 13) {
	             if($('#reachercategory').val()!='') {
				 	$('#main_reacher').submit();
				 } else {
				 	alert('Le champ type est vide');
					$('#reachercategory').focus();
					return false;
				 }
	        }
	    }
	    if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){
			if ( (eventkey.keyCode == 13) ) {
				 if($('#reachercategory').val()!='') {
				 	$('#main_reacher').submit();
				 } else {
				 	alert('Le champ type est vide');
					$('#reachercategory').focus();
					return false;
				 }
			}	           		        
	    }
	}
	*/
	function submitLinkForm(id,formnames) {
		 if(formnames == 'divers') {		
		 	if(document.getElementById('diversPhoto').checked == true){
				document.getElementById('diversPhoto').value = id;
											
			 //if(document.getElementById('diversPhoto').checked==true) {
			 //	document.getElementById('diversPhoto').value = 'on';
			 //}
			 //alert(document.getElementById('diversPhoto').value);
			 //	document.getElementById('diversPhoto').name = 'diversPhoto';
			document.getElementById('diversSubmit').name = 'diversSubmit';
			document.getElementById('main_reacher').action ='index.php?f=diversList';
			document.forms.main_reacher.submit();
			}
		}
		
	}
	function okRecherche(eventkey,getpath) {
	    var error = '';
		if (eventkey.keyCode == 13) {			
             if($('#reacher').val()!='') {
			 	var reacher = $('#reacher').val();
				if(reacher.length>3) {
					document.getElementById('main_reacher').action ='index.php?f=allannounceList';
					$('#main_reacher').submit();
				} else {
					var AJAXRoot = getpath;
					if (window.XMLHttpRequest) 
						ajaxCom = new XMLHttpRequest();
						ajaxCom.open("GET", AJAXRoot + "Views/searchvalue.php?rechertext="+reacher);
						ajaxCom.onreadystatechange = checkTextFound;
						ajaxCom.send(null);
					return false;
				}
			 } else error = 'Le champ recherche est vide';
			 			
			 if(error!='') {
				alert(error);
				$('#reacher').focus();
				return false;
			}
        }
	}
	function okSubmitRecherche(getpath) {
		var error = '';
		if(trim($('#reacher').val())!='') {
			var reacher = $('#reacher').val();
			if(reacher.length>3) {
				document.getElementById('main_reacher').action ='index.php?f=allannounceList';
				$('#main_reacher').submit();
			} 
			else {
					var AJAXRoot = getpath;					
					if (window.XMLHttpRequest) 
						ajaxCom = new XMLHttpRequest();
						ajaxCom.open("GET", AJAXRoot + "Views/searchvalue.php?rechertext="+reacher);
						ajaxCom.onreadystatechange = checkTextFound;
						ajaxCom.send(null);
					return false;
			}
			
		}
		else { 
			$('#reacher').val("");
			error = 'Le champ recherche est vide';
		}
		if(error!='') {
			alert(error);
			$('#reacher').focus();
			return false;
		}
	}
	function checkTextFound() {
		if(ajaxCom.readyState==4) {		
			var tmpCommune=trim(ajaxCom.responseText);
			if( (tmpCommune=='error') || (tmpCommune=='') ) {
				alert('Tapez au moins 4 caractères');
				$('#reacher').focus();
				return false;
			}else {
				document.getElementById('main_reacher').action ='index.php?f=allannounceList';
				$('#main_reacher').submit();
			}
		}
	}
	function LTrim( value ) {
		var re = /\s*((\S+\s*)*)/;
		return value.replace(re, "$1");
			
	}		
	function RTrim( value ) {			
		var re = /((\s*\S+)*)\s*/;
		return value.replace(re, "$1");
	}		
	function trim( value ) {			
		return LTrim(RTrim(value));			
	}