// search_ya pour le mini-moteur intégré chez yahoo 
function check_search_ya()
{

	// single field search
	value = document.recherche.loc_name.value;
	if (value.length == 0 || value == "Ville, département, code postal")
	{
		document.recherche.loc_name.style.border = 'solid 1px #c51e02';
		document.recherche.loc_name.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function search_ya()
{
	if (check_search_ya() == true)
	{
		//set_property_type();
		document.recherche.submit();
	}
}

// search
function check_search_v2()
{
	cancel = false;

	// single field search
	if ($("loc_name"))
	{
		value = $("loc_name").value.trim();

		if (value.length == 0 || value == LABEL["DEFAULT_LOCALITY"])
		{
			cancel = true;
		}
	}
	// multiple fields search
	else
	{
		value = $("loc_name1").value.trim();

		if (value.length > 0 && value != LABEL["DEFAULT_LOCALITY"])
		{
			cancel = false;
		}
		else
		{
			cancel = true;
		}
		
	}

	if (cancel == true)
	{
		if ($("loc_name"))
		{
			$("loc_name").focus();
		}
		else
		{
			$("loc_name1").focus();
		}
		return false;
	}
	else
	{
		return true;
	}
}

function search_v2()
{
	if (check_search_v2() == true)
	{
		set_property_type();

		$("recherche").submit();
	}
}
/*
// search 
function check_search_v2()
{
	// single field search
	//alert($("loc_name"));
	if ($("loc_name"))
	{
		if ($("loc_name").value.length == 0 || $("loc_name").value == LABEL["DEFAULT_LOCALITY"])
		{
			$("loc_name").focus();
			return false;
		}
		else
		{
			return true;
		}
	}
	// multiple fields search
	else
	{
		if ($("loc_name1").value.length == 0 || $("loc_name1").value == LABEL["DEFAULT_LOCALITY"])
		{
			$("loc_name1").focus();
			return false;
		}
		else
		{			
			return true;
		}
	}
}

function search_v2()
{
	if (check_search_v2() == true)
	{
		set_property_type();

		$("recherche").submit();
	}
}
*/
function change_budget(parameter) 
{

	if (parameter==1)
	{
		window.document.getElementById('location').style.display = 'none';
 		window.document.getElementById('vente').style.display = 'block';
	}
	if (parameter==2)
	{
 		window.document.getElementById('location').style.display = 'block';
 		window.document.getElementById('vente').style.display = 'none';
	}
}

function check_alerte()
{
	 if (!check_eml(window.document.FalertBottom.alertMailBottom.value))
	{
		window.document.FalertBottom.alertMailBottom.focus();

		return false;
	}
	else
	{
		return true;
	}
}

function alerte()
{
	if (check_alerte() == true)
	{
		$("FalertBottom").submit();
	}
}
/*
function check_email_agency_ya()
{
	
	if(window.document.Fmailagence.nom.value=="" || window.document.Fmailagence.nom.value == "Votre nom *")
	{
		window.document.Fmailagence.nom.focus();
		return false;
	}
	else if (!check_eml(window.document.Fmailagence.email.value) )
	{
		window.document.Fmailagence.email.focus();
		return false;
	}
	else if(window.document.Fmailagence.tel.value=="" || window.document.Fmailagence.tel.value == "Votre numéro de téléphone *")
	{
		window.document.Fmailagence.tel.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function email_agency_ya()
{
	if (check_email_agency_ya() == true)
	{
		window.document.Fmailagence.submit();
	}
}
*/
// email to agency
function email_agency_ya(parameters)
{
	// 0 - ag id
	// 1 - ag id presto
	// 2 - ad id
	// 3 - ad reference
	// 4 - ad property type
	// 5 - ad nb_rooms
	// 6 - ad area
	// 7 - ad default text
	// 8 - ad default sector
	// 9 - ad post_code
	// 10 - ad price
	// 11 - ad photo id
	// 12 - ag email
	// 13 - ag spoken language

	nom = $("nom").value.trim();
	frm = $("email").value.trim();
	tel = $("tel").value.replace(new RegExp("[^0-9]","g"), "");
	tel = tel.replace(new RegExp("^33"), "0");
	msg = $("message").value.trim();

	if (nom == LABEL["DETAIL_YOUR_NAME"])
	{
		window.document.Fmailagence.nom.focus();
		return;
	}

	if (frm == LABEL["DETAIL_YOUR_EMAIL"] || check_eml(frm) == false)
	{
		window.document.Fmailagence.email.focus();
		return;
	}

	if (tel == LABEL["DETAIL_YOUR_PHONE"] || check_phn(tel) == false)
	{
		window.document.Fmailagence.tel.focus();
		return;
	}

	if (msg == LABEL["DETAIL_YOUR_MESSAGE"])
	{
		window.document.Fmailagence.message.focus();
		return;
	}

	params = 
		{
			site: _site,
			lang: _lang,
			univers: _univ,

			id_agence: parameters[0],
			id_presto: parameters[1],
			id: parameters[2],
			reference: parameters[3],
			property_type: parameters[4],
			nb_rooms: parameters[5],
			area: parameters[6],
			default_text: parameters[7],
			default_sector: parameters[8],
			post_code: parameters[9],
			price: parameters[10],
			photo_id: parameters[11],
			spoken_language: parameters[13],

			nom: nom,
			tel: tel,
			msg: escape(msg),

			from: frm,
			to: parameters[12]
		};

	new Json.Remote("ajax_ya/send_mail_agency.php", {
		onComplete: function(data) {
			if (data["state"] == "OK")
			{
				document.location.href = 'resultats_agence.php?state=1';
			}
			else 
			{
				document.location.href = 'resultats_agence.php?state=0';
			}
		}
	}).send(params);
}

function change_type()
{
	switch (document.getElementById("property_group").selectedIndex)
	{
		case "1,2":
			document.forms['recherche'].property_type.options[1].selected="selected";
			document.forms['recherche'].property_type.options[2].selected="selected";
			break;
		
		case "1":
			document.forms['recherche'].property_type.options[1].selected="selected";
			break;
		
		case "2":
			document.forms['recherche'].property_type.options[2].selected="selected";
			break;
		
		case "3":
			document.forms['recherche'].property_type.options[3].selected="selected";
			break;
		
		case "4,6":
			break;
		
		case "5":
			break;

		case "7":
			break;

		case "8":
			break;
	}
	//alert(document.forms['recherche'].property_group.options[1].selected);
	/*alert(document.getElementById("property_group").selectedIndex);*/
}


// verificat° champ : form contact us
function check_contact_ya()
{
	if ($("statut").value == 0 )
	{
		window.document.getElementById('check_saisie').style.display = 'block';
		return false;
	}
	else if	($("civ").value == "" )
	{
		window.document.getElementById('check_saisie').style.display = 'block';
		return false;
	}
	else if($("nom").value == "" )
	{
		window.document.getElementById('check_saisie').style.display = 'block';
		return false;
	}
	else if ($("cp").value == "" )
	{
		window.document.getElementById('check_saisie').style.display = 'block';
		return false;
	}
	else if ($("msg").value == "" ) 
	{
		window.document.getElementById('check_saisie').style.display = 'block';
		return false;
	}
	else if( $("email").value == "" || check_eml($("email").value)== false)
	{
		window.document.getElementById('check_saisie').style.display = 'block';
		return false;
	}
	else
	{
		return true;
	}
	
}

// verificat° champ : form contact us
function contact_ya()
{
	var choix ;
	

	if (check_contact_ya() == true)
	{
		if (document.forms.Fcontactcontent.civ[0].checked  == true)
		{
			choix = 1;
		}

		if (document.forms.Fcontactcontent.civ[1].checked  == true)
		{
			choix = 2;
		}

		if (document.forms.Fcontactcontent.civ[2].checked == true)
		{
			choix = 3;
		}

		params =
			{	
				cp: $("cp").value,
				civ: choix,
				statut : $("statut").value,
				email: $("email").value,
				raisonsociale: $("raisonsociale").value,
				nom: $("nom").value,
				msg: $("msg").value,
				tel:  $("tel").value
				
				
			};
		new Json.Remote("ajax_ya/contact_us_confirmation.php", { onComplete: function(response) 
		{ 
			if (response == 1)
			{
				document.location.href = "contact_us.php?answer=1"; 
			}
			else
			{
				document.location.href = "contact_us.php?answer=0";
			}
		}}).send(params);
	}
}

