// filtrage recherche

function uncheck2(i) {
    if (i == 1) {
        if (document.getElementById("PrimeCasseStandard").checked)
            document.getElementById("PrimeCasseStandard").checked = false;
        else
            document.getElementById("PrimeCasseStandard").checked = true;
        if (document.theForm.PrimeCasseStandard != null) {
            if (document.theForm.PrimeCasseStandard.checked && document.theForm.PrimeCasseSpecifique != null) {
                document.theForm.PrimeCasseSpecifique.checked = false;
            }
        }
    }

    if (i == 2) {
        if (document.getElementById("PrimeCasseSpecifique").checked)
            document.getElementById("PrimeCasseSpecifique").checked = false;
        else
            document.getElementById("PrimeCasseSpecifique").checked = true;
        if (document.theForm.PrimeCasseSpecifique != null) {
            if (document.theForm.PrimeCasseSpecifique.checked && document.theForm.PrimeCasseStandard != null) {
                document.theForm.PrimeCasseStandard.checked = false;
            }
        }
    }

    document.theForm.submit();
}
function updateCheckAvance2(c) {
    if (document.getElementById(c).checked)
        document.getElementById(c).checked = false;
    else
        document.getElementById(c).checked = true;
    updateAvance2();
}
function updateAvance2() {
    var Portes = "", Carbu = "", Boite = "";

    for (i = 1; i < 30; i++) {
        if (eval("document.theForm.CheckPortes" + i)) {
            if (eval("document.theForm.CheckPortes" + i + ".checked")) {
                if (Portes != "")
                    Portes += ",";
                Portes += eval("document.theForm.IdPortes" + i + ".value");
            }
        }
    }

    for (i = 1; i < 30; i++) {
        if (eval("document.theForm.CheckCarbu" + i)) {
            if (eval("document.theForm.CheckCarbu" + i + ".checked")) {
                if (Carbu != "")
                    Carbu += ",";
                Carbu += eval("document.theForm.IdCarbu" + i + ".value");
            }
        }
    }

    for (i = 1; i < 30; i++) {
        if (eval("document.theForm.CheckBoite" + i)) {
            if (eval("document.theForm.CheckBoite" + i + ".checked")) {
                if (Boite != "")
                    Boite += ",";
                Boite += eval("document.theForm.IdBoite" + i + ".value");
            }
        }
    }

    document.theForm.Portes.value = Portes;
    document.theForm.Carbu.value = Carbu;
    document.theForm.Boite.value = Boite;

    document.theForm.submit();
} 

// recherche avancee

function checkAllMarquesAvance() {
    if (document.theForm.AllMarques.checked)
        check = true;
    else
        check = false;
    for (i = 1; i < 30; i++) {
        if (eval("document.theForm.CheckMarque" + i)) {
            eval("document.theForm.CheckMarque" + i + ".checked=" + check);
        }
    }
    updateAvance();
}
function updateCheckAvance(c) {
    if (document.getElementById(c).checked)
        document.getElementById(c).checked = false;
    else
        document.getElementById(c).checked = true;
    updateAvance();
}
function resetAvance() {
    document.theForm.BudgetMini.value = "";
    document.theForm.BudgetMaxi.value = "";
    frames['AvanceCheck'].location.href = "avancecheck.asp";
    frames['AvanceCompte'].location.href = "avancecompte.asp";
}
function updateAvance() {
    var Marque = "", Carosserie = "", Portes = "", Carbu = "", Boite = "";

    for (i = 1; i < 30; i++) {
        if (eval("document.theForm.CheckMarque" + i)) {
            if (eval("document.theForm.CheckMarque" + i + ".checked")) {
                if (Marque != "")
                    Marque += ",";
                Marque += eval("document.theForm.IdMarque" + i + ".value");
            }
        }
    }

    for (i = 1; i < 30; i++) {
        if (eval("document.theForm.CheckCarosserie" + i)) {
            if (eval("document.theForm.CheckCarosserie" + i + ".checked")) {
                if (Carosserie != "")
                    Carosserie += ",";
                Carosserie += eval("document.theForm.IdCarosserie" + i + ".value");
            }
        }
    }

    for (i = 1; i < 30; i++) {
        if (eval("document.theForm.CheckPortes" + i)) {
            if (eval("document.theForm.CheckPortes" + i + ".checked")) {
                if (Portes != "")
                    Portes += ",";
                Portes += eval("document.theForm.IdPortes" + i + ".value");
            }
        }
    }

    for (i = 1; i < 30; i++) {
        if (eval("document.theForm.CheckCarbu" + i)) {
            if (eval("document.theForm.CheckCarbu" + i + ".checked")) {
                if (Carbu != "")
                    Carbu += ",";
                Carbu += eval("document.theForm.IdCarbu" + i + ".value");
            }
        }
    }

    for (i = 1; i < 30; i++) {
        if (eval("document.theForm.CheckBoite" + i)) {
            if (eval("document.theForm.CheckBoite" + i + ".checked")) {
                if (Boite != "")
                    Boite += ",";
                Boite += eval("document.theForm.IdBoite" + i + ".value");
            }
        }
    }

    window.parent.document.theForm.Marque.value = Marque;
    window.parent.document.theForm.Carosserie.value = Carosserie;
    window.parent.document.theForm.Portes.value = Portes;
    window.parent.document.theForm.Carbu.value = Carbu;
    window.parent.document.theForm.Boite.value = Boite;

    BudgetMini = window.parent.document.theForm.BudgetMini.value;
    BudgetMaxi = window.parent.document.theForm.BudgetMaxi.value;

    location.href = "avancecheck.asp?Marque=" + Marque + "&Carosserie=" + Carosserie + "&Portes=" + Portes + "&Carbu=" + Carbu + "&Boite=" + Boite + "&BudgetMini=" + BudgetMini + "&BudgetMaxi=" + BudgetMaxi + "&AllMarques=" + document.theForm.AllMarques.checked;
    window.parent.document.getElementById('AvanceCompte').src = "avancecompte.asp?Marque=" + Marque + "&Carosserie=" + Carosserie + "&Portes=" + Portes + "&Carbu=" + Carbu + "&Boite=" + Boite + "&BudgetMini=" + BudgetMini + "&BudgetMaxi=" + BudgetMaxi;
} 

// recherche rapide

function updateModeleRapide() {
    idx = document.theForm.Marque.options.selectedIndex;
    Marque = document.theForm.Marque.options[idx].value;
    document.getElementById('RapideModele').src = "rapidemodele.asp?Marque=" + Marque;
    document.getElementById('RapideCarbu').src = "rapidecarbu.asp?Marque=" + Marque;
}
function updateCarbuRapide(Marque) {
    idx = document.theForm.Modele.options.selectedIndex;
    Modele = document.theForm.Modele.options[idx].value;

    window.parent.document.theForm.Modele.value = Modele;
    window.parent.document.getElementById('RapideCarbu').src = "rapidecarbu.asp?Marque=" + Marque + "&Model=" + Modele;

    window.parent.document.getElementById('RapideCarbu').src = "rapidecarbu.asp?Marque=" + Marque + "&Model=" + Modele;
}
function updateCarbu2Rapide() {
    idx = document.theForm.Carbu.options.selectedIndex;
    Carbu = document.theForm.Carbu.options[idx].value;

    window.parent.document.theForm.Carbu.value = Carbu;
}
function submitRapide() {
    idx = document.theForm.Marque.options.selectedIndex;
    if (idx == 0) {
        alert("Veuillez sélectionner une marque.");
        return false;
    } else {
        return true;
    }
}

// comparaison

function CompareOnglet(o) {
    if (document.getElementById('ongletequipements') != null) {
        if (o == "equipements") {
            document.getElementById('equipements').style.display = "block";
            document.getElementById('ongletequipements').src = "images/bt-equip-on.png";
        } else {
            document.getElementById('equipements').style.display = "none";
            document.getElementById('ongletequipements').src = "images/bt-equip-off.png";
        }
    }
    if (o == "options") {
        document.getElementById('options').style.display = "block";
        document.getElementById('ongletoptions').src = "images/bt-options-on.png";
    } else {
        document.getElementById('options').style.display = "none";
        document.getElementById('ongletoptions').src = "images/bt-options-off.png";
    }
    if (o == "fichetech") {
        document.getElementById('fichetech').style.display = "block";
        document.getElementById('ongletfichetech').src = "images/bt-fiche-on.png";
    } else {
        document.getElementById('fichetech').style.display = "none";
        document.getElementById('ongletfichetech').src = "images/bt-fiche-off.png";
    }
}

// formulaire

function FieldCheck(){
	var Flag = 0;
	if(document.theForm.Prenom.value == ""){
		document.theForm.Prenom.style.backgroundColor = "#E40402";
		document.getElementById("Prenom1").style.color = "#E40402";
		Flag = 1;
	}
	if(document.theForm.Nom.value == ""){
		document.theForm.Nom.style.backgroundColor = "#E40402";
		document.getElementById("Nom1").style.color = "#E40402";
		Flag = 1;
	}
	if (document.theForm.TelFixe.value == "") {
		document.theForm.TelFixe.style.backgroundColor = "#E40402";
		document.getElementById("TelFixe1").style.color = "#E40402";
		Flag = 1;
	}
	if (document.theForm.CodePostal.value == "") {
		document.theForm.CodePostal.style.backgroundColor = "#E40402";
		document.getElementById("CodePostal1").style.color = "#E40402";
		Flag = 1;
	}
	if (document.theForm.Email.value == "" || document.theForm.Email.value.indexOf("@") < 0) {
		document.theForm.Email.style.backgroundColor = "#E40402";
		document.getElementById("Email1").style.color = "#E40402";
		Flag = 1;
	}
	if (document.theForm.Email2.value == "" || document.theForm.Email2.value.indexOf("@") < 0) {
		document.theForm.Email2.style.backgroundColor = "#E40402";
		document.getElementById("Email21").style.color = "#E40402";
		Flag = 1;
	}
	if (document.theForm.Email.value != document.theForm.Email2.value) {
	    document.theForm.Email.style.backgroundColor = "#E40402";
		document.theForm.Email2.style.backgroundColor = "#E40402";
		document.getElementById("Email1").style.color = "#E40402";
		document.getElementById("Email21").style.color= "#E40402";
		Flag = 1;
    }

    if (Flag == 0) {
        document.theForm.action = 'demandeauto2.asp';
        //document.theForm.submit();
		return true;
	}else{
		AfficherPop('poperreur');
		//alert("Merci de compléter ou de corriger les champs indiqués en rouge");
		return false;
	}
}	

function ClearFieldNom(){
	document.theForm.Nom.style.backgroundColor = "#FFFFFF";
	document.getElementById("Nom1").style.color = "#000000";	
	ShowEtape2();
}
function ClearFieldPrenom(){
	document.theForm.Prenom.style.backgroundColor = "#FFFFFF";
	document.getElementById("Prenom1").style.color = "#000000";		
	ShowEtape2();
}
function ClearFieldTelFixe(){
	document.theForm.TelFixe.style.backgroundColor = "#FFFFFF";
	document.getElementById("TelFixe1").style.color = "#000000";	
	ShowEtape2();
}
function ClearFieldTelPortable(){
	document.theForm.TelPortable.style.backgroundColor = "#FFFFFF";
	document.getElementById("TelPortable1").style.color = "#000000";		
	ShowEtape2();
}
function ClearFieldTelBureau(){
	document.theForm.TelBureau.style.backgroundColor = "#FFFFFF";
	document.getElementById("TelBureau1").style.color = "#000000";	
	ShowEtape2();
}
function ClearFieldCodePostal(){
	document.theForm.CodePostal.style.backgroundColor = "#FFFFFF";
	document.getElementById("CodePostal1").style.color = "#000000";		
	ShowEtape2();
}
function ClearFieldEmail(){
	document.theForm.Email.style.backgroundColor = "#FFFFFF";
	document.getElementById("Email1").style.color = "#000000";		
	ShowEtape2();
}
function ClearFieldEmail2(){
	document.theForm.Email2.style.backgroundColor = "#FFFFFF";
	document.getElementById("Email21").style.color = "#000000";		
	ShowEtape2();
}
function ShowEtape2(){
	document.getElementById("tableetape1devis").style.borderBottom  = "0";		
	document.getElementById("etape2devis").style.display = "block";	
}
function ShowEtape3() {
    document.getElementById("tableetape2devis").style.borderBottom = "0";
    document.getElementById("etape3devis").style.display = "block";
}

// options

function FormOnglet(Id,o) {
    if (o == "equipements") {
        document.getElementById('ongletequipements').src = "images/bt-equip2-on.png";
		frames['paneau'].location.href = 'displayautoequip.asp?Id=' + Id;
    } else {
        document.getElementById('ongletequipements').src = "images/bt-equip2-off.png";
    }
    if (o == "options") {
        document.getElementById('ongletoptions').src = "images/bt-options2-on.png";
		frames['paneau'].location.href = 'displayautopt.asp?Id=' + Id;
    } else {
        document.getElementById('ongletoptions').src = "images/bt-options2-off.png";
    }
    if (o == "fichetech") {
        document.getElementById('ongletfichetech').src = "images/bt-fiche2-on.png";
		frames['paneau'].location.href = 'displayautotech.asp?Id=' + Id;
    } else {
        document.getElementById('ongletfichetech').src = "images/bt-fiche2-off.png";
    }
	ScrollSmall ();
}

function CouleurdeFond(e) {
	document.getElementById(e).style.background = "#DBDEED";
}
function CouleurdeFondBlanc(e) {
	document.getElementById(e).style.background = "#FFFFFF";
}

function updateFormCoul(Id)
{
	cptidcoul = document.theForm.cptidcoul.value;
	for (i=1; i<=cptidcoul; i++) {
		if (i != Id)
			eval("document.theForm.check"+i+".checked = false");
	}
}

function updateFormInter(Id)
{
	cptidinterdeb = document.theForm.cptidinterdeb.value;
	cptidinterfin = document.theForm.cptidinterfin.value;
	for (i=cptidinterdeb; i<=cptidinterfin; i++) {
		if (i != Id)
			eval("document.theForm.check"+i+".checked = false");
	}
}

function updateMainForm()
{
	n = 1;
	url = "";

	for (i=1; i<200; i++) {
		if (eval("document.theForm.check"+i) != null) {
			if (eval("document.theForm.check"+i+".value") != "") {
				url += "&id" + n + "=" + eval("document.theForm.id"+i+".value");
				n++;
			}
		}
		else
			break;
	}

	frames['choixoption'].UpdateOptPrix ();
}

function uncheck (i)
{
	if (i==1) {
		if (document.theForm.PrimeCasseStandard != null) {
			if (document.theForm.PrimeCasseStandard.checked && document.theForm.PrimeCasseSpecifique != null) {
				document.theForm.PrimeCasseSpecifique.checked = false;
			}
		}
	}

	if (i==2) {
		if (document.theForm.PrimeCasseSpecifique != null) {
			if (document.theForm.PrimeCasseSpecifique.checked && document.theForm.PrimeCasseStandard != null) {
				document.theForm.PrimeCasseStandard.checked = false;
			}
		}
	}
}

function updateForm()
{
	n = 1;
	url = "";

	for (i=1; i<200; i++) {
		if (eval("document.theForm.check"+i) != null) {
			if (eval("document.theForm.check"+i+".checked")) {
				eval ("window.parent.document.theForm.check"+i+".value = '1'");
				url += "&id" + n + "=" + eval("document.theForm.id"+i+".value");
				n++;
			}
			else
				eval ("window.parent.document.theForm.check"+i+".value = ''");
		}
		else
			break;
	}

	window.parent.frames['choixoption'].UpdateOptPrix ();
}
function CheckOption()
{
	for (i=1; i<200; i++) {
		if (eval("window.parent.document.theForm.check"+i) != null) {
			if (eval("window.parent.document.theForm.check"+i+".value") != "") {
				eval ("document.theForm.check"+i+".checked = 1");
			}
			else
				eval ("document.theForm.check"+i+".checked = 0");
		}
		else
			break;
	}
}

function CheckPrime () {
	if (document.theForm.PrimeCasseSpecifique != null) {
		document.theForm.PrimeCasseSpecifique.checked = document.theForm.PrimeCasseStandard.checked;
	}
}

function UpdatePrix (Total, FraisMiseEnRoute, Co2, MakeDesc, PrimeNegocieeMontant, PrimeCasseStandard, PrimeCasseSpecifique, PrimeCasseMontant) {
	url = "displayautoprix.asp?Total=" + Total + "&FraisMiseEnRoute=" + FraisMiseEnRoute + "&Co2=" + Co2 + "&MakeDesc=" + MakeDesc + "&PrimeNegocieeMontant=" + PrimeNegocieeMontant + "&PrimeCasseStandard=" + PrimeCasseStandard + "&PrimeCasseSpecifique=" + PrimeCasseSpecifique + "&PrimeCasseMontant=" + PrimeCasseMontant;
	window.parent.frames['prix'].location.href = url;
}
function AdjustOption (iframeWindow, maxHeight) {
	height = iframeWindow.document.body.scrollHeight;
	if (height<80)
		height = 80;
	if (height>maxHeight)
		height = maxHeight;
	document.getElementById ('choixoption').height = height;
}
function AdjustPaneau (iframeWindow, maxHeight) {
	height = iframeWindow.document.body.scrollHeight;
	if (height>maxHeight)
		height = maxHeight;
	document.getElementById ('paneau').height = height;
}
function AdjustPrix (iframeWindow, maxHeight) {
	height = iframeWindow.document.body.scrollHeight;
//	if (height>maxHeight)
//		height = maxHeight;
	document.getElementById ('prix').height = height;
}

function OngletOption (Id) {
	document.getElementById('options-ul').style.backgroundImage='url(img/bt-3choix1.jpg)';
	frames['paneau'].location.href = 'displayautopt.asp?Id=' + Id;
	ScrollSmall ();
}
function OngletEquip (Id) {
	document.getElementById('options-ul').style.backgroundImage='url(img/bt-3choix2.jpg)';
	frames['paneau'].location.href = 'displayautoequip.asp?Id=' + Id;
	ScrollSmall ();
}
function OngletTech (Id) {
	document.getElementById('options-ul').style.backgroundImage='url(img/bt-3choix3.jpg)';
	frames['paneau'].location.href = 'displayautotech.asp?Id=' + Id;
	ScrollSmall ();
}

function ScrollBig () {
	document.getElementById('paneau').height = document.getElementById('paneau').contentWindow.document.body.scrollHeight;
	document.getElementById('ScrollBig').style.display		= "none";
	document.getElementById('ScrollSmall').style.display	= "block";
}
function ScrollSmall () {
	height = document.getElementById('paneau').contentWindow.document.body.scrollHeight;
	if (height>550)
		height = 550;
	document.getElementById('paneau').height = height;
	document.getElementById('ScrollBig').style.display		= "block";
	document.getElementById('ScrollSmall').style.display	= "none";
}

function HoverInfos (msg) {
	overlib (msg, CENTER, WIDTH,250, CELLPAD,5,15, FGCOLOR,'#FEFECC', TEXTSIZE,'11px', BORDER,1);
}
function HoverOptions (msg) {
	overlib (msg, LEFT, ABOVE, WIDTH,250, CELLPAD,5,15, FGCOLOR,'#FEFECC', TEXTSIZE,'11px', BORDER,1);
}
function HoverFrance (msg) {
	overlib (msg, LEFT, ABOVE, WIDTH,250, CELLPAD,5,15, FGCOLOR,'#FEFECC', TEXTSIZE,'11px', BORDER,1);
}

// fiche véhicule

function showMenu(m, s) {
    document.getElementById(m).style.display = s;
}
function cacheMenu(m) {
    tempo = setTimeout("cache_calque('" + m + "')", 400)
}
function stopTempo() {
    if (tempo != null)
        clearTimeout(tempo);
}
function cache_calque(m) {
    showMenu(m, 'none');
    clearTimeout(tempo);
}						