
function ChampNonVide(ChampNom,message,FormNom) {
 if (document.forms[FormNom].elements[ChampNom].value.length < 1) {
  alert(" "+message);
  document.forms[FormNom].elements[ChampNom].focus();
  return true;
 }
}

function ChampNombre(ChampNom,message,FormNom) {
 var val = document.forms[FormNom].elements[ChampNom].value;
 val = val.replace(/,/g,"\.");	
 val = val.replace(" ","");
 document.forms[FormNom].elements[ChampNom].value = val;
 if (isNaN(val)) {
  alert(" "+message);
  document.forms[FormNom].elements[ChampNom].focus();
  return true;
 }
}

function EmailValid (ChampNom,FormNom) {
 var lib = "Votre adresse e-mail n'est pas valide"; 

 adresse = document.forms[FormNom].elements[ChampNom].value;
 var place = adresse.indexOf("@",1);
 var point = adresse.indexOf(".",place+1);
  if ((place > -1)&&(adresse.length >2)&&(point > 1)) {
  return false;
  }
	else {
   alert(lib);
   document.forms[FormNom].elements[ChampNom].focus();
   return true;
  }
}

function validFormContact(FormNom) {

 if (ChampNonVide('nom' ,'Veuillez saisir votre nom', FormNom)) return false; 
 if (EmailValid ('email' , FormNom)) return false;

 if (document.forms[FormNom].c_idAgence.value == 0) {
      alert ("Veuillez sélectionner l\'agence que vous souhaitez contacter");
      document.forms[FormNom].c_idAgence.focus();
	  return false;
 } 
 /*
 if (document.forms[FormNom].numdept.value == 0) {
      alert ("Veuillez sélectionner votre département");
      document.forms[FormNom].numdept.focus();
	  return false;
 } 
 */
}

function validFormNews(FormNom) {

 if (ChampNonVide('nom' ,'Veuillez saisir votre nom', FormNom)) return false; 
 if (EmailValid ('email' , FormNom)) return false;

}


function validFormDevis(FormNom) {

 if (ChampNonVide('nom' ,'Veuillez saisir votre nom', FormNom)) return false; 
 if (EmailValid ('email' , FormNom)) return false;
 

}

function validFinanCetelem(FormNom) {
  if (document.forms[FormNom].marque.value == 0) {
      alert ("Veuillez sélectionner une marque");
      document.forms[FormNom].marque.focus();
	  return false;
   } 
  if (ChampNonVide('prix_vehicule' ,'Veuillez saisir le prix du véhicule', FormNom)) return false; 
  if (ChampNombre('prix_vehicule' ,'Vous devez saisir le prix du véhicule', FormNom)) return false; 
  if (ChampNonVide('puissfisc' ,'Veuillez saisir la puissance fiscale', FormNom)) return false; 
  if (ChampNonVide('km' ,'Veuillez saisir le kilométrage', FormNom)) return false; 
}

function popup(url,w,h) {
 var le = (screen.availWidth - w) /2;
 var he = (screen.availHeight -h) /2;
 win = window.open(url,null,'height='+h+',width='+w+',status=no,toolbar=no,scrollbars=1,menubar=yes,location=no,resizable=yes,left='+le+', top='+he,false);
 win.focus();
}

function chgListeVN(FormNom,ChampNom,message,action) {

  if (message != '') { 
   if (document.forms[FormNom].elements[ChampNom].value == "") {
      alert (" "+message);
      document.forms[FormNom].elements[ChampNom].focus();
	  return false;
   } 
  }
  
 
   document.forms[FormNom].action = action;
   document.forms[FormNom].submit();
   
}

function validSearchVN(FormNom,action) {
 

 if (document.forms[FormNom].marque.value == 0) {
      alert ("Veuillez sélectionner une marque");
      document.forms[FormNom].marque.focus();
	  return false;
   } 
 /* if (document.forms[FormNom].modele.value == 0) {
      alert ("Veuillez sélectionner un modèle");
      document.forms[FormNom].modele.focus();
	  return false;
   } 
   */
   
   document.forms[FormNom].action = action;
  
}



function getXhr(){
               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("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
				   xhr = false; 
				} 
                return xhr;
}
			
			
function coordAgence(url,id){
	
				var xhr = getXhr();
			
				xhr.onreadystatechange = function(){
					
					if(xhr.readyState == 4 && xhr.status == 200){
						document.getElementById(id).innerHTML = xhr.responseText;
						
					}
				}

				
				xhr.open("GET",url,true);
				
				//xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=utf-8');
					
	            xhr.send(null);
				
			
}


function go(FormNom,url) {
   document.forms[FormNom].action = url;
   document.forms[FormNom].submit();
}

function goP(FormNom,url,page) {
   document.forms[FormNom].action = url+'pagenum='+page;
   document.forms[FormNom].submit();
}

function changelist(date1,chpJ){
var eltDate = date1.split(";");
var mois = eltDate[0];
var annee = eltDate[1];

var nbJ = 31;
if (mois==4 || mois==6 || mois==9 || mois==11 ) { nbJ = 30; }
if (mois==2) {
  nbJ = 28;
  if ((annee%4==0&&annee%100!=0)||annee%400==0) {nbJ = 29; }
}
temp = chpJ;
var val= temp.options[temp.selectedIndex].value;

for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null;
for (i=0;i<nbJ;i++){
temp.options[i]=new Option(i+1,i+1);
}
if (val > nbJ) { val = nbJ; }
temp.options[val-1].selected=true;


}

function format(valeur,decimal,separateur) {
// formate un chiffre avec 'decimal' chiffres après la virgule et un separateur
	var deci=Math.round( Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur)))) ; 
	var val=Math.floor(Math.abs(valeur));
	if ((decimal==0)||(deci==Math.pow(10,decimal))) {val=Math.floor(Math.abs(valeur)); deci=0;}
	var val_format=val+"";
	var nb=val_format.length;
	for (var i=1;i<4;i++) {
		if (val>=Math.pow(10,(3*i))) {
			val_format=val_format.substring(0,nb-(3*i))+separateur+val_format.substring(nb-(3*i));
		}
	}
	if (decimal>0) {
		var decim=""; 
		for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
		deci=decim+deci.toString();
		val_format=val_format+"."+deci;
	}
	if (parseFloat(valeur)<0) {val_format="-"+val_format;}
	return val_format;
}


var map = null;
var geocoder = null;
	
    function load() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.removeMapType(G_DEFAULT_MAP_TYPES);
        //map.setCenter(new GLatLng(37.4419, -122.1419), 13);
		geocoder = new GClientGeocoder();
		
        map.addControl(new GLargeMapControl());
 
        var mapControl = new GMapTypeControl();
        map.addControl(mapControl);
		
			
      }
    }
	
	 function showAddress(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert("Impossible de localiser l'adresse :\n\n" + address);
            } else {
              map.setCenter(point, 12);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(address);
            }
          }
        );
      }
    }


