sas_tmstp=Math.round(Math.random()*10000000000);
sas_masterflag=1;
function SmartAdServer(sas_pageid,sas_formatid,sas_target) {
	if (sas_masterflag==1) {
		sas_masterflag=0;
		sas_master='M';
	}
	else {
		sas_master='S';
	}
	document.write('<scr'+'ipt SRC="http://www.smartadserver.com/call/pubj/' + sas_pageid + '/' + sas_formatid + '/'+sas_master + '/' + sas_tmstp + '/' + escape(sas_target) + '?"></scr'+'ipt>');
}
function encodeURL(url) {
	return encodeURI(url.replace(/ /g,'+')).replace(/&/g,'&');
}
function decodeURL(url) {
	return decodeURI(url.replace(/\+/g,' ')).replace(/&/g,'&');
}
function jsRecherche() {
	hideProAide();
	hideLieuAide();
	var professionnel	= $('#pol_search_professionnel').val();
	var localite		= $('#pol_search_lieu').val();
	var lKey		= $('#l_key').val();
	
	if (professionnel == "" && localite == "") {
		$('#pol_search_professionnel').css('background', 'red');
		$('#pol_search_professionnel').css('color', 'white');
		$('#pol_search_professionnel').val('champ obligatoire');
		window.setTimeout("$('#pol_search_professionnel').css('background', 'white')", 1600);
		window.setTimeout("$('#pol_search_professionnel').css('color', 'black')", 1600);
		window.setTimeout("$('#pol_search_professionnel').val('')", 1600);
		$('#pol_search_lieu').css('background', 'red');
		$('#pol_search_lieu').css('color', 'white');
		$('#pol_search_lieu').val('champ obligatoire');
		window.setTimeout("$('#pol_search_lieu').css('background', 'white')", 1600);
		window.setTimeout("$('#pol_search_lieu').css('color', 'black')", 1600);
		window.setTimeout("$('#pol_search_lieu').val('')", 1600);
		
		return false;
	}
	else if (
		$('#pol_search_professionnel').css('background') == 'red'
		|| $('#pol_search_lieu').css('background') == 'red'
		|| professionnel == "champ obligatoire"
		|| localite == "champ obligatoire")  {
		return false;
	}
	else if (localite == "") {
		$('#pol_search_lieu').css('background', 'red');
		$('#pol_search_lieu').css('color', 'white');
		$('#pol_search_lieu').val('champ obligatoire');
		window.setTimeout("$('#pol_search_lieu').css('background', 'white')", 1600);
		window.setTimeout("$('#pol_search_lieu').css('color', 'black')", 1600);
		window.setTimeout("$('#pol_search_lieu').val('')", 1600);
		
		return false;
	}
	else if (professionnel == "") {
		$('#pol_search_professionnel').css('background', 'red');
		$('#pol_search_professionnel').css('color', 'white');
		$('#pol_search_professionnel').val('champ obligatoire');
		window.setTimeout("$('#pol_search_professionnel').css('background', 'white')", 1600);
		window.setTimeout("$('#pol_search_professionnel').css('color', 'black')", 1600);
		window.setTimeout("$('#pol_search_professionnel').val('')", 1600);
		
		return false;
	}
	
	var boutonHTML	= $('#search_button').html();
	$('#search_button').html('<img src="/images/loading_green.gif" alt="loading" class="margin_left_10" />');
	
	$.ajax({
		type: "GET",
		url: "/iframe/search_catego.php",
		data: "professionnel="+encodeURL(professionnel)+'&l_key='+encodeURL(lKey),
		success: function(msg){
			var sCatID		= 0;
			var pro_fulltext	= false;
			var lieu_fulltext	= false;
			var layer		= false;

			if (msg == '0') {
				pro_fulltext	= true;
			}
			else if (msg.substr(0, 3) == "id=") {
				sCatID	= msg.substr(3, msg.length-3);
			}
			else {
				layer	= true;
				$('#content_pol_search_professionnel_aide').html(msg);
				$('#pol_search_professionnel_aide').show('slow', function() {
					$('#pol_search_professionnel_aide').css('border', '1 px solid red');
					$('#pol_search_professionnel_aide').css('z-index', '100');
				});

			}
			
			var cpID	= 0;
			var deptID	= 0;
			localite		= $('#pol_search_lieu').val();
			if (localite != "") {
				$.ajax({
					type: "GET",
					url: "/iframe/search_lieu.php",
					data: "localite="+encodeURL(localite)+'&l_key='+encodeURL(lKey),
					success: function(msg){
						if (msg == '0') {
							lieu_fulltext	= true;
						}
						else if (msg.substr(0, 6) == "cp_id=") {
							cpID	= msg.substr(6, msg.length-6);
						}
						else if (msg.substr(0, 8) == "dept_id=") {
							deptID	= msg.substr(8, msg.length-8);
						}
						else {
							layer	= true;
							$('#content_pol_search_lieu_aide').html(msg);
							/*$('#pol_search_lieu_aide').show('slow', function() {
								alert('ok');
								$('#pol_search_lieu_aide').css('border', '1 px solid red');
								$('#pol_search_lieu_aide').css('z-index', '100');
							});*/
							//$('#pol_search_lieu_aide').css('display', 'block');
							document.getElementById('pol_search_lieu_aide').style.display = 'block';
						}
						
						if (layer == true) {
							$('#search_button').html(boutonHTML);
							return false;
						}
						
						if (lieu_fulltext && pro_fulltext) {
							document.location.href='/annuaire.php?p='+encodeURL(professionnel)+'&l='+encodeURL(localite);
						}
						else if (!layer) {
							if (lieu_fulltext) {
								document.location.href='/annuaire.php?pid='+sCatID+'&l='+encodeURL(localite);
							}
							else if (pro_fulltext) {
								if (cpID > 0) {
									document.location.href='/annuaire.php?p='+encodeURL(professionnel)+'&cid='+cpID;
								}
								else if (deptID > 0) {
									document.location.href='/annuaire.php?p='+encodeURL(professionnel)+'&did='+deptID;
								}
							}
							else if (cpID > 0) {
								document.location.href='/annuaire.php?pid='+sCatID+'&cid='+cpID;
							}
							else if (deptID > 0) {
								document.location.href='/annuaire.php?pid='+sCatID+'&did='+deptID;
							}
						}
						$('#search_button').html(boutonHTML);
					}
				});
			}
		}
	});
	
	return false;
}

function hideProAide() {
	if ($('#pol_search_professionnel_aide').css('display') == "block")
		$('#pol_search_professionnel_aide').hide();
}

function hideLieuAide() {
	if ($('#pol_search_lieu_aide').css('display') == "block")
		$('#pol_search_lieu_aide').hide();
}
function recalculeRestant(numero) {
	max	= 280;
	if (numero != "")
		addId	= "_"+numero;
	else	addId	= "";
	calcul	= max - $('#sms_visu'+addId).val().length;
	
	if (calcul < 0) {
		$('#sms_visu'+addId).val($('#sms_visu'+addId).val().substring(0, max));
		calcul = max - $('#sms_visu'+addId).val().length;
	}
	$('#sms_counter'+addId).html(calcul + ' caractères restant');
}

function chargeInputPro(val) {
	$('#pol_search_professionnel').val(val);
}

function chargeInputLieu(val) {
	$('#pol_search_lieu').val(val);
}

function popupCarte(url) {
	window.open(url, "Carte", "width=520,height=520,toolbar=no,status=no,scrollbars=no,resizable=no,dependent=yes");
}