function popup(num){
	var w = 650;
	var h = 670;
	var x=(window.screen.availWidth - w)/2;
	var y=(window.screen.availHeight- h)/2;
	var Win=window.open('/voitures.html?num='+num,'aide','scrollbars=yes,resizable=yes,width='+w+',height='+h+',screenX='+x+',screenY='+y+',top='+y+',left='+x+'');

	if (Win.opener == null) {
		Win.opener = window;
	}
		Win.focus();
}

/*function popup_photo(num,i){
	var w = 450;
	var h = 300;
	var x=(window.screen.availWidth - w)/2;
	var y=(window.screen.availHeight- h)/2;
	var Win=window.open('/photos_voiture.html?num='+num+'&i='+i,'aide','scrollbars=yes,resizable=yes,width='+w+',height='+h+',screenX='+x+',screenY='+y+',top='+y+',left='+x+'');

	if (Win.opener == null) {
		Win.opener = window;
	}
		Win.focus();
}*/


function verif_newsletter(newsletter){

	var reg = new RegExp("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$");
	fin = true;
	
	if ((!reg.test(newsletter.mail.value)) || (newsletter.mail.value == "")){
 		document.newsletter.mail.style.backgroundColor = "#FFFFCC";
		document.getElementById('news').style.display="block";
		newsletter.mail.focus();
		fin = false;
	}else{
		document.newsletter.mail.style.backgroundColor = "#FFFFFF";
	}

	 return fin;
}

function numerique(variable){
	var rege = new RegExp("^[0-9]*$","g");
  	if (!rege.test(variable)) return false;
	else return true;
}

//- Vérification de la validité de l'adresse E-Mail:
function emailCheck (EM) {return((EM.indexOf("@")>1)&&(EM.lastIndexOf(".")>EM.indexOf("@"))&&(EM.length-EM.indexOf("@")>1)&&(EM.indexOf(" ")==-1)&&(EM.length-EM.lastIndexOf(".")>2)&&(EM.length-EM.lastIndexOf(".")<5));}

function verif_perso(Formulaire){
	var fin = true;
	var reg = new RegExp("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$");
	var Blanc = "#FFFFFF"; var Rouge = "#FaD8D8"; var Jaune = "#FFFFCC";

	if (!(emailCheck(document.Formulaire.mail.value))){
		document.Formulaire.mail.style.backgroundColor = Jaune;
		document.Formulaire.mail.focus();
		document.getElementById('div_mail').style.display="block";
		fin = false;
	}else{
		document.Formulaire.mail.style.backgroundColor = Blanc;
		document.getElementById('div_mail').style.display="none";
	}
	
	/*if (!(numerique(document.Formulaire.telephone.value)) || (document.Formulaire.telephone.value.length<8)){
		document.Formulaire.telephone.style.backgroundColor = Jaune;
		document.Formulaire.telephone.focus();
		document.getElementById('div_tel').style.display="block";
		fin = false;
	}else{
		document.Formulaire.telephone.style.backgroundColor = Blanc;
		document.getElementById('div_tel').style.display="none";
	}*/

	/*if (document.Formulaire.prenom.value.length<2){
		document.Formulaire.prenom.style.backgroundColor = Jaune;
		document.Formulaire.prenom.focus();
		document.getElementById('div_prenom').style.display="block";
		fin = false;
	}else{
		document.Formulaire.prenom.style.backgroundColor = Blanc;
		document.getElementById('div_prenom').style.display="none";
	}*/

	if (document.Formulaire.nom.value.length<2){
		document.Formulaire.nom.style.backgroundColor = Jaune;
		document.Formulaire.nom.focus();
		document.getElementById('div_nom').style.display="block";
		fin = false;
	}else{
		document.Formulaire.nom.style.backgroundColor = Blanc;
		document.getElementById('div_nom').style.display="none";
	}

	return fin;
}

function verif_ami(ami){
	fin = true;

	if (ami.monnom.value == ""){
 		document.ami.monnom.style.backgroundColor = "#FFFFCC";
		ami.monnom.focus();
		fin = false;
	}else document.ami.monnom.style.backgroundColor = "#FFFFFF";

	if (ami.mail.value == ""){
 		document.ami.mail.style.backgroundColor = "#FFFFCC";
		ami.mail.focus();
		fin = false;
	}else document.ami.mail.style.backgroundColor = "#FFFFFF";
	
	if (ami.nom.value == ""){
 		document.ami.nom.style.backgroundColor = "#FFFFCC";
		ami.nom.focus();
		fin = false;
	}else document.ami.nom.style.backgroundColor = "#FFFFFF";

	return fin;
}

 function change_photo(photo){
    document.getElementById("GPhoto").innerHTML = "<img src=" + photo + " alt='grande taille' border='0' class='photo'/>";
}

function incription_pro(){
	fin = true;
	
	if(!emailCheck(document.pro.email.value)){
 		document.pro.email.style.backgroundColor = "#FFFFCC";
		document.pro.email.focus();
		fin = false;
	}else document.pro.email.style.backgroundColor = "#FFFFFF";

	if(document.pro.tel.value.length<2){
 		document.pro.tel.style.backgroundColor = "#FFFFCC";
		document.pro.tel.focus();
		fin = false;
	}else document.pro.tel.style.backgroundColor = "#FFFFFF";

	if(document.pro.ville.value.length<2){
 		document.pro.ville.style.backgroundColor = "#FFFFCC";
		document.pro.ville.focus();
		fin = false;
	}else document.pro.ville.style.backgroundColor = "#FFFFFF";

	if(document.pro.cp.value.length<2){
 		document.pro.cp.style.backgroundColor = "#FFFFCC";
		document.pro.cp.focus();
		fin = false;
	}else document.pro.cp.style.backgroundColor = "#FFFFFF";

	if(document.pro.adresse.value.length<2){
 		document.pro.adresse.style.backgroundColor = "#FFFFCC";
		document.pro.adresse.focus();
		fin = false;
	}else document.pro.adresse.style.backgroundColor = "#FFFFFF";

	if(document.pro.rcs.value.length<2){
 		document.pro.rcs.style.backgroundColor = "#FFFFCC";
		document.pro.rcs.focus();
		fin = false;
	}else document.pro.rcs.style.backgroundColor = "#FFFFFF";

	if(document.pro.nom_r.value.length<2){
 		document.pro.nom_r.style.backgroundColor = "#FFFFCC";
		document.pro.nom_r.focus();
		fin = false;
	}else document.pro.nom_r.style.backgroundColor = "#FFFFFF";

	if(document.pro.nom_s.value.length<2&&document.pro.nom_g.value.length<2){
 		document.pro.nom_g.style.backgroundColor = "#FFFFCC";
 		document.pro.nom_s.style.backgroundColor = "#FFFFCC";
		document.pro.nom_g.focus();
		fin = false;
	}else{
		document.pro.nom_g.style.backgroundColor = "#FFFFFF";
		document.pro.nom_s.style.backgroundColor = "#FFFFFF";
	}

	return fin;
}

function reservation(id){
	HTTP_Verif('http://www.6car.fr/pro/pro-reservation.html?id='+id);
	document.getElementById('reserv').innerHTML='Le véhicule est reservé pour 24h !';
}

function HTTP_Verif(Fichier){
    var xhr = null;

    if(window.XMLHttpRequest){ // Firefox et autres
        xhr = new XMLHttpRequest();
    }else if(window.ActiveXObject){ // Internet Explorer
        try {
            xhr = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }else{ // XMLHttpRequest non supporté par le navigateur
        alert("Erreur : votre navigateur ne supporte pas l'Ajax !");
        xhr = false;
    }

    if(xhr!=null){
        xhr.open("GET", Fichier+"&date="+escape((new Date()).getTime()), false);
        xhr.send(null);
        if(xhr.readyState == 4 && xhr.status < 400 ){
            return(xhr.responseText);
        }
    }

    return false;
}
