String.prototype.isInteger = function() {
	return this.match(/^[0-9]+$/);
}
String.prototype.isEmail = function() {
	return this.match(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/);
}
String.prototype.trim = function() {
	return this.replace(/^\s+/g,'').replace(/\s+$/g,'');
}
function formRappelImmediat() {
	$.facebox(function() {
	  $.get(url_site + '/scripts/ajax.php', { action: "formRappelImmediat", section: section },
	   function(data) {
		$.facebox(data)
	  })
	})	
}
function checkRappelImmediat(myForm) {
	if (myForm.nom.value == "") {
		alert("Le champ Nom est obligatoire !");
		myForm.nom.focus();
		return false;
	}
	if (myForm.societe.value == "") {
		alert("Le champ Société est obligatoire !");
		myForm.societe.focus();
		return false;
	}			
	if (myForm.t1.value == "") {
		alert("Le champ Téléphone est obligatoire !");
		myForm.t1.focus();
		return false;
	}	
	if (!isInteger(myForm.t1.value)) {
		alert( 'Le champ Téléphone ne doit contenir que des chiffres!' );
		myForm.t1.focus();
		return false;
	}
	regex = new RegExp(/^(01|02|03|04|05|06|08|09)$/gi);
    if(!regex.test(myForm.t1.value)) {
		alert("Le champ Téléphone est Invalide");
		myForm.t1.focus();
		return false;
	}
	if ((myForm.t2.value == "") || (myForm.t3.value == "") || (myForm.t4.value == "") || (myForm.t5.value == "")) {
		alert("Téléphone Invalide");
		return false;
	}
	if (!isInteger(myForm.t2.value)) {
		alert( 'Le champ Téléphone ne doit contenir que des chiffres!' );
		myForm.t2.focus();
		return false;
	}
	if (!isInteger(myForm.t3.value)) {
		alert( 'Le champ Téléphone ne doit contenir que des chiffres!' );
		myForm.t3.focus();
		return false;
	}
	if (!isInteger(myForm.t4.value)) {
		alert( 'Le champ Téléphone ne doit contenir que des chiffres!' );
		myForm.t4.focus();
		return false;
	}
	if (!isInteger(myForm.t5.value)) {
		alert( 'Le champ Téléphone ne doit contenir que des chiffres!' );
		myForm.t5.focus();
		return false;
	}	
	
	return true;
}
function rappelImmediat(myForm, myItem) {
	rez = checkRappelImmediat(myForm);
	if (rez) {
		myItem.disabled = true;
		myItem.value = 'Patientez ...';
		
		t1 = myForm.t1.value;
		t2 = myForm.t2.value;
		t3 = myForm.t3.value;
		t4 = myForm.t4.value;
		t5 = myForm.t5.value;
		
		civilite = myForm.civilite.value;
		nom = myForm.nom.value;
		prenom = myForm.prenom.value;
		societe = myForm.societe.value;
		telephone = t1+t2+t3+t4+t5;
		section = myForm.section.value;
		
		var dataString = 'action=validerRappelImmediat&civilite=' + civilite + '&nom=' + nom + '&prenom=' + prenom + '&societe=' + societe + '&telephone=' + telephone + '&section=' + escape(section);   
		$.ajax({  
			type: "POST",  
			url: url_site + "/scripts/ajax.php",  
			data: dataString,  
			success: function() {   
				$.facebox("<p>Votre demande a été bien envoyée.</p>");  
			}  
		});
		
	} 
}
function Verifier_Numero_Telephone(num_tel) {
	num_tel = num_tel.replace(/[^0-9]/g, "");
	num_tel = $.trim(num_tel);
    if(num_tel.length != 10) {
        alert('Votre numéro de téléphone doit comporter 10 chiffres !');
        return false;
    }
    // Definition du motif a matcher
    var regex = new RegExp(/^(01|02|03|04|05|06|08|09)[0-9]{8}$/gi);
    // Definition de la variable booleene match
    var match = false;
    // Test sur le motif
    if(regex.test(num_tel)){
        chargement();
		
		match = true;
    }
    else {
        match = false;
        alert('Votre numéro de téléphone doit comporter 10 chiffres !');
    }
    // On renvoie match
    return match;
}
function Verifier_Numero_Telephone_NotOk(num_tel) {
	num_tel = num_tel.replace(/[^0-9]/g, "");
	num_tel = $.trim(num_tel);
    if(num_tel.length != 10) {
        alert('Votre numéro de téléphone doit comporter 10 chiffres !');
        return false;
    }
    // Definition du motif a matcher
    var regex = new RegExp(/^(01|02|03|04|05|06|08|09)[0-9]{8}$/gi);
    // Definition de la variable booleene match
    var match = false;
    // Test sur le motif
    if(regex.test(num_tel)){
        ChargementNotOk();
		
		match = true;
    }
    else {
        match = false;
        alert('Votre numéro de téléphone doit comporter 10 chiffres !');
    }
    // On renvoie match
    return match;
}
function chargement() {
	$("#eligibilite").hide();
	$("#chargement").show();
	
}
function ChargementNotOk() {
	$("#chargement-non").show();
	
}
function checkNumTel(num_tel) {
	num_tel = num_tel.replace(/[^0-9]/g, "");
	num_tel = $.trim(num_tel);
    if(num_tel.length != 10) {
        return 'Votre numéro de téléphone doit comporter 10 chiffres !';
    }
    var regex = new RegExp(/^(01|02|03|04|05|06|08)[0-9]{8}$/gi);
    if(!regex.test(num_tel)){
        return 'Votre numéro de téléphone est invalide !';
    }
    return '';
}
function checkZipCode(zipcode) {
	if (zipcode != '')  {
	
	    if(zipcode.length != 5) {
	        return 'Votre zipcode doit comporter 5 chiffres !';
	    }
	    var regex = new RegExp(/^[0-9]{5}$/gi);
	    if(!regex.test(zipcode)){
	        return 'Votre zipcode est invalide !';
	    }
    }
    return '';
}
function isInteger(str) {
	return /([0-9]+)/.test(str);
}
function isValidEmail (email) {
	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);
}
function inscriptionNewsLetter(email) {
	if (isValidEmail(email)) {
		$.get(url_site + '/scripts/ajax.php', { action: "inscriptionNewsLetter", email: email },
			function(data) {
				$.facebox(data)
			})	
	} else {
		alert('Adresse mail invalide');
	}
}
function Autotab(box, longueur, texte) {
    if (texte.length > longueur-1) {
        $('#t'+box).focus();
    }
}
function formDemandeNumTel(prestation) {
	html = '<h1>Devis en ligne</h1>';
	html += '<form method="post" action="">';
	html += '<p>Votre numéro de téléphone : <input type="text" name="telephone" value="" /> <input type="button" value="Valider" onclick="demandeDevisDepuisTel(this.form.telephone.value, \''+prestation+'\');" /></p>';
	html += '</form>';
	$.facebox(html);
}
function demandeDevisDepuisTel(telephone, prestation) {	
	if (Verifier_Numero_Telephone(telephone)) {
		  $.get(url_site+'/scripts/ajax.php', { action: "recupererAdresseDepuisTel", telephone: telephone },
		   function(data) {
			formDemandeDevis(data, prestation)
		  })
	}
}
function formDemandeDevis(c, prestation) {
	$.facebox(function() {
	  $.get(url_site+'/scripts/ajax.php', { action: "formDemandeDevis", c: c, prestation: prestation },
	   function(data) {
		$.facebox(data)
	  })
	})
}
function submitDemandeDevis(myForm) {
	nom = $.trim(myForm.nom.value);
	prenom = $.trim(myForm.prenom.value);
	societe = $.trim(myForm.societe.value);
	telephone = $.trim(myForm.telephone.value);
	adresse = $.trim(myForm.adresse.value);
	cp = $.trim(myForm.cp.value);
	ville = $.trim(myForm.ville.value);
	prestation = myForm.prestation.value;
	err = '';
	if (nom == '') {
		err += "- Nom obligatoire\n";
	}
	if (prenom == '') {
		err += "- Prénom obligatoire\n";
	}
	if (societe == '') {
		err += "- Société obligatoire\n";
	}
	if (telephone == '') {
		err += "- Téléphone obligatoire\n";
	} else {
		e = checkNumTel(telephone);
		if (e != '') err += "- "+e+"\n";
	}
	if (adresse == '') {
		err += "- Adresse obligatoire\n";
	}
	if (cp == '') {
		err += "- Code postale obligatoire\n";
	}
	if (ville == '') {
		err += "- Ville obligatoire\n";
	}
	if (err == '') {
		$.facebox(function() {
		  $.get(url_site+'/scripts/ajax.php', { action: "submitDemandeDevis", nom: nom, prenom: prenom, societe: societe, telephone: telephone, adresse: adresse, cp: cp, ville: ville, prestation: prestation },
		   function(data) {
			$.facebox(data)
		  })
		})
	} else {
		alert('Vérifiez les erreurs suivantes : \n' + err);
	}
}
function cocherDecoder(myItem) {
	myForm = myItem.form;
	for(i=0; i<myForm.length; i++) {
		if (myForm.elements[i].type == 'checkbox') myForm.elements[i].checked = myItem.checked;
	}
}
//iframe google map
function onLoadPage() {
	if (window.addEventListener)
		window.addEventListener("load", resizeCaller, false)
	else if (window.attachEvent)
		window.attachEvent("onload", resizeCaller)
	else
		window.onload=resizeCaller
}
function resizeCaller() {
	document.getElementById('iGoogleMap').style.display = 'none';
}
