/* change range price */
function change_price_range(id_type_demand)
{
	ajax_query_html('ajax_maj_combo_list_price', 'id_type_demand='+id_type_demand, 'price_range_list');
}

function new_captcha()
{
    // loads new freeCap image
    if(document.getElementById)
    {
        // extract image name from image source (i.e. cut off ?randomness)
        thesrc = document.getElementById("captcha").src;
        thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
        // add ?(random) to prevent browser/isp caching
        document.getElementById("captcha").src = thesrc+"?"+Math.round(Math.random()*100000);
    } else {
        alert("Sorry, cannot autoreload captcha image\nSubmit the form and a new captcha will be loaded");
    }
}

function new_captcha_request()
{
    // loads new freeCap image
    if(document.getElementById)
    {
        // extract image name from image source (i.e. cut off ?randomness)
        thesrc = document.getElementById("captcha_request").src;
        thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
        // add ?(random) to prevent browser/isp caching
        document.getElementById("captcha_request").src = thesrc+"?"+Math.round(Math.random()*100000);
    } else {
        alert("Sorry, cannot autoreload captcha image\nSubmit the form and a new captcha will be loaded");
    }
}

//vérifie la validiter du mail
function verifMail(email) { // Email valide ?
	var arobase = email.indexOf("@");
	var point = email.lastIndexOf(".");
	
	if((arobase < 1)||(point + 3 > email.length)||(point < arobase)){
		return false;
	}else{
		return true;
	}
}

/* Supprime les espaces inutiles en début et fin de la chaîne passée en paramètre */
function trim(aString) {
	var regExpBeginning = /^\s+/;
	var regExpEnd = /\s+$/;
    return aString.replace(regExpBeginning, "").replace(regExpEnd, "");
}

function verifSimpleContactForm(){

	/* validation Nom du tiers */
	if(trim(document.form_contact_demand.LName.value) == ""){
		alert('Last Name is required');
		document.form_contact_demand.LName.focus();
		return false;
	}
	
	/* validation Prenom du tiers */
	if(trim(document.form_contact_demand.FName.value) == ""){
		alert('First Name is required');
		document.form_contact_demand.FName.focus();
		return false;
	}

	/* validation tel du tiers */
	if(trim(document.form_contact_demand.Tel.value) == ""){
		alert('Tel is required');
		document.form_contact_demand.Tel.focus();
		return false;
	}
	
	/* Validation mail */
	if(trim(document.form_contact_demand.Email.value) == ""){
		alert('Email is required');
		document.form_contact_demand.Email.focus();
		return false;
	}else{
		if(!verifMail(document.form_contact_demand.Email.value)) {
			alert("Invalid Email (xxxxxxx@xxxxxx.xxx)");
			document.form_contact_demand.Email.focus();
			return false;
		}
	}
		
	/* validation Message contact */
	if(trim(document.form_contact_demand.message.value) == ""){
		alert('Message is required');
		document.form_contact_demand.message.focus();
		return false;
	}
	
	/* Validation code anti spam */
	if(trim(document.form_contact_demand.form_code02.value) == ""){
		alert('Copy the word in the image to the field');
		document.form_contact_demand.form_code02.focus();
		return false;
	}
	
}

function verifContactForm(type){

	/* validation type de produit */
	if(document.form_contact_demand.Id_type.value == 0){
		alert('Please select a kind of product');
		document.form_contact_demand.Id_type.focus();
		return false;
	}
	
	/* validation sector */
	if(document.form_contact_demand.Id_sector.value == 0){
		alert('Please select an area');
		document.form_contact_demand.Id_sector.focus();
		return false;
	}
	
	/* validation price */
	if(document.form_contact_demand.Price.value == 0){
		alert('Please choose a price');
		document.form_contact_demand.Price.focus();
		return false;
	}
	
	/* validation periode de location */
	if(type == 'rental')
	{
		if(trim(document.form_contact_demand.DateStart.value) == ""){
			alert('Please choose a period starting date');
			document.form_contact_demand.DateStart.focus();
			return false;
		}
		if(trim(document.form_contact_demand.DateEnd.value) == ""){
			alert('Please choose a period ending date');
			document.form_contact_demand.DateEnd.focus();
			return false;
		}
	}
	
	/* validation nombre de chambres */
	if(type == 'rental')
	{
		if(trim(document.form_contact_demand.Nb_room.value) == ""){
			alert('Please choose a number of rooms');
			document.form_contact_demand.Nb_room.focus();
			return false;
		}
	}
	
	/* validation find out about us */
	if(document.form_contact_demand.Id_howfind.value == 0){
		alert('Please choose how did you find out about us');
		document.form_contact_demand.Id_howfind.focus();
		return false;
	}
	
	/* validation Nom du tiers */
	if(trim(document.form_contact_demand.LName.value) == ""){
		alert('Last Name is required');
		document.form_contact_demand.LName.focus();
		return false;
	}
	
	/* validation Prenom du tiers */
	if(trim(document.form_contact_demand.FName.value) == ""){
		alert('First Name is required');
		document.form_contact_demand.FName.focus();
		return false;
	}
	
	/* validation tel du tiers */
	if(trim(document.form_contact_demand.Country.value) == ""){
		alert('Country is required');
		document.form_contact_demand.Country.focus();
		return false;
	}
	
	/* validation tel du tiers */
	if(trim(document.form_contact_demand.Tel.value) == ""){
		alert('Tel is required');
		document.form_contact_demand.Tel.focus();
		return false;
	}
	
	/* Validation mail */
	if(trim(document.form_contact_demand.Email.value) == ""){
		alert('Email is required');
		document.form_contact_demand.Email.focus();
		return false;
	}else{
		if(!verifMail(document.form_contact_demand.Email.value)) {
			alert("Invalid Email (xxxxxxx@xxxxxx.xxx)");
			document.form_contact_demand.Email.focus();
			return false;
		}
	}
	/* Validation code anti spam */
	if(trim(document.form_contact_demand.form_code02.value) == ""){
		alert('Copy the word in the image to the field');
		document.form_contact_demand.form_code02.focus();
		return false;
	}
	
}



function verifContactForm_scf(){

	/* validation type de demande */
	if(document.scf_form_contact.scf_form_type.value == 0){
		alert('Please select a type of request');
		document.scf_form_contact.scf_form_type.focus();
		return false;
	}
	
	/* validation agence */
	if(document.scf_form_contact.scf_form_office.value == 0){
		alert('Please select an office');
		document.scf_form_contact.scf_form_office.focus();
		return false;
	}
	
	


	/* validation Nom du tiers */
	if(trim(document.scf_form_contact.scf_form_lname.value) == ""){
		alert('Last Name is required');
		document.scf_form_contact.scf_form_lname.focus();
		return false;
	}
	
	/* validation Prenom du tiers */
	if(trim(document.scf_form_contact.scf_form_fname.value) == ""){
		alert('First Name is required');
		document.scf_form_contact.scf_form_fname.focus();
		return false;
	}
		
	/* validation tel du tiers */
	if(trim(document.scf_form_contact.scf_form_tel.value) == ""){
		alert('Phone number is required');
		document.scf_form_contact.scf_form_tel.focus();
		return false;
	}
	
	/* Validation mail */
	if(trim(document.scf_form_contact.scf_form_email.value) == ""){
		alert('Email is required');
		document.scf_form_contact.scf_form_email.focus();
		return false;
	}else{
		if(!verifMail(document.scf_form_contact.scf_form_email.value)) {
			alert("Invalid Email (xxxxxxx@xxxxxx.xxx)");
			document.scf_form_contact.scf_form_email.focus();
			return false;
		}
	}
	/* Validation code anti spam */
	if(trim(document.scf_form_contact.scf_form_spam.value) == ""){
		alert('Copy the word in the image to the field');
		document.scf_form_contact.scf_form_spam.focus();
		return false;
	}
	
}
