// JavaScript Document
function CalcOrder()
{
 Prix_1 = (document.form.Cahier_N1.value * 5.35);
 document.form.Prix_1.value = RoundOff(Prix_1);
 Prix_2 = (document.form.Cahier_N2.value * 7.65);
 document.form.Prix_2.value = RoundOff(Prix_2);
 Prix_3 = (document.form.Cahier_N3.value * 9);
 document.form.Prix_3.value = RoundOff(Prix_3);
 Prix_4 = (document.form.Cahier_N4.value * 9);
 document.form.Prix_4.value = RoundOff(Prix_4);
 Prix_5 = (document.form.Cahier_N5.value * 9);
 document.form.Prix_5.value = RoundOff(Prix_5);
 Prix_6 = (document.form.Cahier_N6.value * 9);
 document.form.Prix_6.value = RoundOff(Prix_6);
 Prix_7 = (document.form.Cahier_N7.value * 9);
 document.form.Prix_7.value = RoundOff(Prix_7);
 ETotal = Prix_1 + Prix_2 + Prix_3 + Prix_4 + Prix_5 + Prix_6 + Prix_7;
	 if (ETotal == 0) {
  document.form.Grand_Total.value = 0;
} 
else {
 if (ETotal <10) {
  document.form.Grand_Total.value = RoundOff(ETotal +2.97);
} 
else {
 if ((ETotal >10)&&(ETotal<27)) {
  document.form.Grand_Total.value = RoundOff(ETotal +3.85);
} 
else {
document.form.Grand_Total.value = RoundOff(ETotal +5.07);
}
}
}
}

function RoundOff(value)
{
    value = "" + value ;//convert value to string
    precision = 2;
 
    var whole = "" + Math.round(value * Math.pow(10, precision));
 
    var decPoint = whole.length - precision;
 
    if (value == "0")
    {
 result = "0";
 }
 else
 {
 if(decPoint != 0)
 {
 result = " " + whole.substring(0, decPoint);
    result += ",";
    result += whole.substring(decPoint, whole.length);
 }
 else
 {
    result = "," + whole;
 }
    }
    return result;
}



function Validation()
{
	CalcOrder();
    valid = true; 
    if (document.form.nom.value.length < 2)
 {
    alert("Merci de taper votre nom.")
    document.form.nom.focus()
    return false;
}
    if (document.form.prenom.value.length < 2)
 {
    alert("Merci de taper votre prenom.")
    document.form.prenom.focus()
    return false;
}
    if (document.form.adresse.value < 5)
 {
    alert("Inscrivez correctement votre adresse pour votre livraison.")
    document.form.adresse.focus()
    return false;
}
    if (document.form.ville.value.length < 2)
 {
    alert("Cette ville est inconnue.")
    document.form.ville.focus()
    return false;
}
var codePostal = document.form.code.value;
	
	function allDigits(str)
{
	return inValidCharSet(str,"0123456789");
}

function inValidCharSet(str,charset)
{
	var result = true;	
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}
	if (!allDigits(codePostal))
	{
	alert("Un code postal est en chiffres !")
	document.form.code.focus()
	return false;
}
if (codePostal.length < 5 )
		{
	alert("Tapez TOUT votre code postal !")
	document.form.code.focus()
	return false;
	}
	if (codePostal.length > 5)
	{
	alert("Il y a trop de chiffres !")
	document.form.code.focus()
	return false;
	}


var mail = document.form.email.value;
var aroba = mail.indexOf("@");
	if (aroba == -1) {
	alert("L'adresse email n'est pas valide...\nUne adresse mail valide est du type \"adresse@domaine.com\"");
	document.form.email.focus()
	return false;
}

    if (valid) 
    {
    alert("Votre demande est bien enregistrée. \nNous vous en remercions et vous confirmerons la dispnibilité.")
    document.form.Submit.disabled = true;
    return true;
}
}



