// JavaScript Document

function confirme(param){
document.location.href = param ;
}

function supligne(identifiant){
var confirmation = confirm("Voulez vous vraiment supprimer cet enregistrement ?");
if(confirmation){
document.location.href = "supp_ligne_voiture.php?id="+identifiant ;}
}

function modif(identifiant){
document.location.href = "modifier.php?id="+identifiant ;
}

function Popup(value, left, top){
 eval('open(value, \'\', \'directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,left= ' + left + ',top= ' + top + '\')');
}

function MM_reloadPage(init) { //reloads the window if Nav4 resized
   if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
     document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
   else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
 }
 MM_reloadPage(true);
 function MM_findObj(n, d) { //v4.01
   var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
     d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
   if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
   for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
   if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function CheckFormat(name,id) {
 var format = '.jpeg|.gif|.jpg|.png';
 var file = MM_findObj(name);
 var args = format.split("|");
 var ok = false;
 var arg_list = new String;
    for (i = 0; i < args.length; i++) {
        var valeur = args[i];
        var nom_fic = file.value.substr(file.value.length - valeur.length, valeur.length).toLowerCase();
        arg_list += "*"+valeur+" ";
         if (valeur == nom_fic) {
            ok = true;
			 document.getElementById('erreur').innerHTML = "";
             return ok;
         }
     }
    if (!ok) {
        document.getElementById('erreur').innerHTML = "Format de votre fichier incorrect !<br> Les formats acceptés sont : "+arg_list+"<br> Veuillez séléctionner un autre fichier.";
		document.getElementById(id).value='';
     }
     return ok;
}		

function create_champ(i) {
var i2 = i + 1;
document.getElementById('leschamps3_'+i).innerHTML = '<input type="file" name="fichier_'+i+'" id="file_'+i+'" class="champs3" value="" onChange="CheckFormat(this.name,this.id);">';
document.getElementById('leschamps3_'+i).innerHTML += (i <= 5) ? '<br /><span id="leschamps3_'+i2+'"><a href="javascript:create_champ('+i2+')" class="add_champ" onMouseover="this.style.textDecoration=\'underline\'" onMouseout="this.style.textDecoration=\'none\'"><i>Ajouter plusieurs images</i></a></span>' : '';
}

function supimg(param){
var confirmation = confirm("Voulez vous vraiment supprimer cette image ?") ;
if(confirmation){
document.location.href = param ;}
}

function couleur(obj) {
     obj.style.backgroundColor = "#CFD9F5";
}

function Choix(form) {

if (form=="Appartement" || form=="Maison" || form=="Autres"){
 document.getElementById("ligne1").style.display = "";
 document.getElementById("ligne2").style.display = "";
 
 }else{
 document.getElementById("ligne1").style.display = "none";
 document.getElementById("ligne2").style.display = "none";
} 
}

function check() {

	var msg = "Veuillez saisir : ";
	var i = 0;

if (document.formulaire.marque.value == ""){
	if (i!=0){msg += ", "}
		msg += "la marque";
		i++;
		document.formulaire.marque.style.backgroundColor = "#F3C200";
}
if (document.formulaire.modele.value == ""){
	if (i!=0){msg += ", "}
		msg += "le modèle";
		i++;
		document.formulaire.prix.style.backgroundColor = "#F3C200";
}		
if (document.formulaire.option.value == ""){
	if (i!=0){msg += ", "}
		msg += "les options";
		i++;
		document.formulaire.option.style.backgroundColor = "#F3C200";
}	
if (document.formulaire.teinte.value == ""){
	if (i!=0){msg += ", "}
		msg += "la teinte";
		i++;
		document.formulaire.teinte.style.backgroundColor = "#F3C200";
}
if (document.formulaire.klm.value == ""){
	if (i!=0){msg += ", "}
		msg += "le nombre de kilomètres";
		i++;
		document.formulaire.klm.style.backgroundColor = "#F3C200";
}
if (document.formulaire.prix.value == ""){
	if (i!=0){msg += ", "}
		msg += "le prix";
		i++;
		document.formulaire.prix.style.backgroundColor = "#F3C200";
}
if (document.formulaire.garantie.value == ""){
	if (i!=0){msg += ", "}
		msg += "la garantie";
		i++;
		document.formulaire.garantie.style.backgroundColor = "#F3C200";
}
	if (msg == "Veuillez saisir : ") return(true);
	else	{
		msg += ".";
		alert(msg);
		return(false);
	}

}
