function defautValue(cas,val,defaut) { var valeur; if(cas == 'focus' && val == defaut) valeur = ''; else if(cas == 'blur' && val == '') valeur = defaut; else valeur = val; return valeur; } function calcul(champ,qte,pu) { var total; var field = document.getElementById('calcul_'+champ); if(isNaN(parseFloat(qte)) ) qte = 0; if( qte >= 0 || qte == '') { if(pu == 'pack') pu = parseFloat(getCheckedValue(document.forms["Devis"].elements["pack"])); total = qte * pu; field.value = total; calculerTotal(); } } function calculerTotal() { var total_devis = 0; var champs = ['surfaceMaison','surfaceGarage','terrasseCouverte','terrasseNonCouverte','cloture']; var prix = ['pack','valeur','valeur','valeur']; var options = ['toitureMultipentes','doucheItalienne','wcSuspendu','enduitTaloche','voletsRoulants','climGainable']; for (var i in champs) { if(prix[i] == 'pack') { if(document.getElementById('optimum').checked == true) var pu = document.getElementById('optimum').value; if(document.getElementById('family').checked == true) var pu = document.getElementById('family').value; if(document.getElementById('eco').checked == true) var pu = document.getElementById('eco').value; } else {var pu = document.getElementById('pu_'+champs[i]).value;} var valeur = document.getElementById('qte_'+champs[i]).value; if(valeur != '' && !isNaN(parseFloat(valeur)*parseFloat(pu)) ) { var tot = parseFloat(valeur)*parseFloat(pu); document.getElementById('calcul_'+champs[i]).value = tot; total_devis += tot; } } if(document.getElementById('optimum').checked != true) { var aPr = document.getElementsByTagName("span"); var iPr = aPr.length; while(iPr-- > 0) if(aPr[iPr].className == 'inclus') aPr[iPr].className = 'invisible'; var aPr = document.getElementsByTagName("div"); var iPr = aPr.length; while(iPr-- > 0) if(aPr[iPr].className == 'optGauche' || aPr[iPr].className == 'optMilieu' || aPr[iPr].className == 'optDroite') aPr[iPr].style.backgroundColor = 'transparent'; /* --------------------------------- OPTIONS (uniquement en mode ECO) -------------------------------------------------- */ for (var i in options) { if(document.getElementById(options[i]).checked == true) { var plus = document.getElementById(options[i]).value; if(!isNaN(parseFloat(plus)) ) { if(options[i]=='climGainable') { total_devis += parseFloat(plus)*parseFloat(document.Devis.qte_surfaceMaison.value); document.getElementById('calcul_'+options[i]).value = parseFloat(plus)*parseFloat(document.Devis.qte_surfaceMaison.value); } else total_devis += parseFloat(plus); } } } } else { var aPr = document.getElementsByTagName("span"); var iPr = aPr.length; while(iPr-- > 0) if(aPr[iPr].className == 'invisible') aPr[iPr].className = 'inclus'; var aPr = document.getElementsByTagName("div"); var iPr = aPr.length; while(iPr-- > 0) if(aPr[iPr].className == 'optGauche' || aPr[iPr].className == 'optMilieu' || aPr[iPr].className == 'optDroite') aPr[iPr].style.fontColor= '#000000'; for (var i in options) { if(document.getElementById(options[i]).checked == true) { if(options[i]=='climGainable') document.getElementById('calcul_'+options[i]).value = 0; } } } /* ------------------------------------------------------- PISCINE ------------------------------------------------------------ */ if(isNaN(parseFloat(document.getElementById('largPiscine').value) * parseFloat(document.getElementById('longPiscine').value) * parseFloat(document.getElementById('profPiscine').value))) { document.getElementById('calcul_piscine').value = 0; } else { var qte = parseFloat(document.getElementById('largPiscine').value) * parseFloat(document.getElementById('longPiscine').value) * parseFloat(document.getElementById('profPiscine').value); var val = document.getElementById('piscine').value; var tot_piscine = qte * val; document.getElementById('calcul_piscine').value = tot_piscine; total_devis += tot_piscine; } document.getElementById('total_devis').value = total_devis; } function getCheckedValue(radioObj) { if(!radioObj) return ""; var radioLength = radioObj.length; if(radioLength == undefined) if(radioObj.checked) return radioObj.value; else return ""; for(var i = 0; i < radioLength; i++) { if(radioObj[i].checked) { return radioObj[i].value; } } return ""; } function checkMail(adresse){ var place = adresse.indexOf("@",1); var point = adresse.indexOf(".",place+1); if ((place > -1)&&(adresse.length >2)&&(point > 1)) return(true); else return(false); } function checkDevis(){ var adresse = document.Devis.email.value; var nom = document.Devis.nom.value; var telephone = document.Devis.telephone.value; var portable = document.Devis.portable.value; var reponse = ''; if(nom == '') reponse += 'Veuillez renseigner votre nom \n'; if(telephone == '' && portable == '') reponse += 'Veuillez indiquer un numero de téléphone \n'; if(!checkMail(adresse)) reponse += 'Veuillez indiquer une adresse mail valide \n'; if(reponse != '') alert(reponse); else document.Devis.submit(); } var checkboxHeight = "17"; var radioHeight = "17"; var selectWidth = "190"; document.write(''); var Custom = { init: function() { var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active; for(a = 0; a < inputs.length; a++) { if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") { span[a] = document.createElement("span"); span[a].className = inputs[a].type; if(inputs[a].checked == true) { if(inputs[a].type == "checkbox") { position = "0 -" + (checkboxHeight*2) + "px"; span[a].style.backgroundPosition = position; } else { position = "0 -" + (radioHeight*2) + "px"; span[a].style.backgroundPosition = position; } } inputs[a].parentNode.insertBefore(span[a], inputs[a]); inputs[a].onchange = Custom.clear; if(!inputs[a].getAttribute("disabled")) { span[a].onmousedown = Custom.pushed; span[a].onmouseup = Custom.check; } else { span[a].className = span[a].className += " disabled"; } } } inputs = document.getElementsByTagName("select"); for(a = 0; a < inputs.length; a++) { if(inputs[a].className == "styled") { option = inputs[a].getElementsByTagName("option"); active = option[0].childNodes[0].nodeValue; textnode = document.createTextNode(active); for(b = 0; b < option.length; b++) { if(option[b].selected == true) { textnode = document.createTextNode(option[b].childNodes[0].nodeValue); } } span[a] = document.createElement("span"); span[a].className = "select"; span[a].id = "select" + inputs[a].name; span[a].appendChild(textnode); inputs[a].parentNode.insertBefore(span[a], inputs[a]); if(!inputs[a].getAttribute("disabled")) { inputs[a].onchange = Custom.choose; } else { inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled"; } } } document.onmouseup = Custom.clear; }, pushed: function() { element = this.nextSibling; if(element.checked == true && element.type == "checkbox") { calculerTotal(); this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px"; } else if(element.checked == true && element.type == "radio") { calculerTotal(); this.style.backgroundPosition = "0 -" + radioHeight*3 + "px"; } else if(element.checked != true && element.type == "checkbox") { calculerTotal(); this.style.backgroundPosition = "0 -" + checkboxHeight + "px"; } else { calculerTotal(); this.style.backgroundPosition = "0 -" + radioHeight + "px"; } }, check: function() { element = this.nextSibling; if(element.checked == true && element.type == "checkbox") { this.style.backgroundPosition = "0 0"; element.checked = false; } else { if(element.type == "checkbox") { this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px"; } else { this.style.backgroundPosition = "0 -" + radioHeight*2 + "px"; group = this.nextSibling.name; inputs = document.getElementsByTagName("input"); for(a = 0; a < inputs.length; a++) { if(inputs[a].name == group && inputs[a] != this.nextSibling) { inputs[a].previousSibling.style.backgroundPosition = "0 0"; } } } element.checked = true; } }, clear: function() { inputs = document.getElementsByTagName("input"); for(var b = 0; b < inputs.length; b++) { if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") { inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px"; calculerTotal(); } else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") { inputs[b].previousSibling.style.backgroundPosition = "0 0"; } else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") { inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px"; //if(inputs[b].name =='pack') calculerTotal();//calcul('surfaceMaison',document.Devis.qte_surfaceMaison.value,inputs[b].value); } else if(inputs[b].type == "radio" && inputs[b].className == "styled") { inputs[b].previousSibling.style.backgroundPosition = "0 0"; } } }, choose: function() { option = this.getElementsByTagName("option"); for(d = 0; d < option.length; d++) { if(option[d].selected == true) { document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue; } } } } window.onload = Custom.init;