var epcoChoixPrix="2";

function InitForm()
{
	document.formu.txtBTitle.disabled = false;
	document.formu.txtBLastName.disabled = false;
	document.formu.txtBFirstName.disabled = false;
	document.formu.txtBAddr1.disabled = false;
	document.formu.txtBAddr2.disabled = false;
	document.formu.txtBPostbox.disabled = false;
	document.formu.txtBCountry.disabled = false;
	document.formu.txtBZipCode.disabled = false;
	document.formu.txtBCity.disabled = false;
	document.formu.txtBTel.disabled = false;
	document.formu.txtBFax.disabled = false;
	document.formu.txtBEmail.disabled = false;
	document.formu.epcoJ_DdN.disabled = false;
	document.formu.epcoM_DdN.disabled = false;
	document.formu.epcoA_DdN.disabled = false;
	document.formu.epcoTaille.disabled = false;
	document.formu.epcoPoids.disabled = false;
	document.formu.epcoExtraInfo.disabled = false;
	document.formu.epcoArtDesc.disabled = false;
	document.formu.epcoArtQuant.disabled = false;
	document.formu.epcoVidQuant.disabled = false;
	document.formu.epcoCondGen.disabled = false;
	document.formu.bouton.disabled = false;

	epcoChoixPrix="2";
	epcoLeysin="0";
	calculateFullForm();
	SetFocus();
	document.formu.epco_label.value = "";
	document.formu.epco_label.size = 1;
}

function MM_preloadImages()
{
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}};
  InitForm();
}

function ChangeChoix(valeur)
{

	epcoChoixPrix = Number(valeur);
	calculateFullForm();
}

function calculateFullForm()
{
	document.formu.epcoArtQuant.value = NoSpace (document.formu.epcoArtQuant.value);
	if(String (document.formu.epcoArtQuant.value) != String(parseInt (document.formu.epcoArtQuant.value))) {
		switch (document.formu.txtShopPara.value) {
		case 'Session=EPCE' :
			{
			alert("Sorry, it's forbiden to jump with people cut in small pieces ...");
			break;
			}
		default :
			{
			alert("Désolé, nous ne pouvons pas faire sauter des personnes coupées en petits morceaux ...");
			}
		}
		document.formu.epcoArtQuant.value = 1;
		void document.formu.epcoArtQuant.focus();
	} else {
		if(document.formu.epcoArtQuant.value > 9) {
		switch (document.formu.txtShopPara.value) {
			case 'Session=EPCE' :
				{
				alert("For this quantity, please contact our office at info@epco.aero ... you would receive some discount !");
				break;
				}
			default :
				{
				alert("Pour de telle quantité, merci de prendre contact directement avec notre secrétariat à l'adresse info@epco.aero ... vous pourez bénéficier d'un rabais !");
				}
			}
			document.formu.epcoArtQuant.value = 1;
			void document.formu.epcoArtQuant.focus();
		}
	}

	document.formu.epcoVidQuant.value = NoSpace (document.formu.epcoVidQuant.value);
	if(String (document.formu.epcoVidQuant.value) != String(parseInt (document.formu.epcoVidQuant.value))) {
		switch (document.formu.txtShopPara.value) {
		case 'Session=EPCE' :
			{
			alert("Sorry, it's forbiden to jump with people cut in small pieces ...");
			break;
			}
		default :
			{
			alert("Désolé, nous ne pouvons pas faire sauter des personnes coupées en petits morceaux ...");
			}
		}
		document.formu.epcoVidQuant.value = 0;
		void document.formu.epcoVidQuant.focus();
	} else {
		if(document.formu.epcoVidQuant.value > document.formu.epcoArtQuant.value) {
		switch (document.formu.txtShopPara.value) {
			case 'Session=EPCE' :
				{
				alert("Sorry, we can't picture more people than the ''jumping number'' !");
				break;
				}
			default :
				{
				alert("Décolé, nous ne pouvons pas filmer plus de personnes que le nombre de ''sauteurs'' !");
				}
			}
			document.formu.epcoVidQuant.value = 0;
			void document.formu.epcoArtQuant.focus();
		}
	}
// alert("epcoLeysin : " + epcoLeysin);

	if((ChercheMot(document.formu.epcoArtDesc.value,"Leysin") > 0) && (epcoLeysin == "0"))
	{
		epcoLeysin = "1";
		switch (document.formu.txtShopPara.value) {
		case 'Session=EPCE' :
			{
			alert("CAREFULL !!! Jumps at Leysin would be from chopper and cost an extra 120.- CHF !");
			break;
			}
		default :
			{
			alert("ATTENTION !!! Les sauts à Leysin se font d'hélicoptère et le prix est majoré de 120.- !");
			}
		}
	}
	else
	{
		if(ChercheMot(document.formu.epcoArtDesc.value,"Leysin") == 0)
		{
			epcoLeysin = "0";
		}
	}


	if(Number(epcoChoixPrix)<2)
	{
	  document.formu.epcoArtPrice.value = "   100.00";
	  document.formu.epcoArtNr.value="  Inscr";
	  var sExpression = "(document.formu.epcoArtQuant.value * 100) ";
	}
	else
	{
	  if(epcoLeysin == "0")
	  {
// alert("ZERO");
		document.formu.epcoArtPrice.value = "   430.00";
		document.formu.epcoArtNr.value=" Tandem";
		var sExpression = "(document.formu.epcoArtQuant.value * 430) ";
	  }
	  else
	  {
		document.formu.epcoArtPrice.value = "   550.00";
		document.formu.epcoArtNr.value=" Tandem";
		var sExpression = "(document.formu.epcoArtQuant.value * 550) ";
	  }
	}
	
	document.formu.epcoArtPriceTot.value = MiseEnForme (eval(sExpression), 8);

	document.formu.epcoVidPrice.value = "   120.00";
	var sExpression2 = "(document.formu.epcoVidQuant.value * 120) ";
	document.formu.epcoVidPriceTot.value = MiseEnForme (eval(sExpression2), 8);

	var sExpression3 = sExpression + "+ " + sExpression2;
	document.formu.epcoPriceTotal.value = MiseEnForme (eval(sExpression3), 8)
}

function SetFocus()
{
	void document.formu.txtBTitle.focus();
}

function ChercheMot (S, M)
{
// alert ("S : *" + S + "*, M : *" + M + "*");
	var Resulta = 0;
	var j;
	var i;
	var Re = "";

	if(M.length > 0)
	{
		for(i = M.length; i <= S.length;i++)
		{
			j = i - M.length;
			Re = S.slice(j,i);
// alert ("I : " + i + " ; slice : " + Re);
			if((Resulta == 0) && (Re == M))
			{
				Resulta = j + 1;
			}
		}
	}
	return Resulta;
}


function ChercheCar (S, c)
{

// alert ("S : *" + S + "*, c : *" + c + "*");
	var Resulta = 0;
	var j;
	var i;
	var Ca = "";

	for(i = 1; i <= S.length;i++)
	{
		j = i - 1;
		Ca = S.slice(j,i);
// alert ("I : " + i + " ; slice : " + Ca);

		if((Resulta == 0) && (Ca == c))
		{
			Resulta = i;
		}	
	}
	return Resulta;
}

function AjoutZero (n, x)
{
	var S = String (n);
	while(S.length < x)
	{
		S = "0" + S;
	}
	return S.slice(0,x);
}

function AjoutBlanc (S, x)
{
	while(S.length < x)
	{
		S = " " + S;
	}
	return S.slice(0,x);
}

function RemplisBlanc (S, x)
{
	while(S.length < x)
	{
		S = S + " ";
	}
	return S.slice(0,x);
}

function Droite (S, x)
{
	var R = "";
	if(S.length > x)
	{
		R = S.slice (S.length - x)
	} else {
		R = S;
	}
	return R;
}

function MiseEnForme (n, m)
{
	var Entier = parseInt(n);
	var Frac = parseInt(100 * (n - Entier) + 0.25);
	if (Entier > 1000)
	{
		var Millier = parseInt (Entier / 1000);
		var Reste   = parseInt (Entier - (1000 * Millier));
		var SReste  = AjoutZero (Reste, 3);
		var SEntier = String (Millier) + "'" + SReste;
	}
	else
	{
		var SEntier = String (Entier);
	}
	return AjoutBlanc (SEntier + "." + AjoutZero(Frac, 2), m);
}

function empty (S)
{
	if (NoSpace(S) == "") {
		return true;
	} else {
		return false;
	}
}

function NoSpace (S)
{
	while((S.length > 0) && (S.slice(0,1) == " ")) {
		S = S.slice(1);
	}
	return S;
}

function NoString (S)
{
	var i;

	i = S.search(/\'/);

	if (i > 0)
	{
		S = S.substr(0,i) + S.slice(i+1);
	}
	var Entier = parseInt(S);
	var Frac = parseInt (100 * (S - Entier));
	var S1 = Entier + "." + Frac;
	return S1;
}

function test_sortie()
{
    var epcoOK = parseFloat(1);
    if(! document.formu.epcoCondGen.checked)
    {
	switch (document.formu.txtShopPara.value) {
	case 'Session=EPCE' :
		{
		alert("You should accept the general conditions !");
		break;
		}
	default :
		{
		alert("Vous devez accepter les conditions générales !");
		}
	}
    }
    else
    {

	if((document.formu.txtBLastName.value == "") ||
	   (document.formu.txtBZipCode.value  == "") ||
	   (document.formu.txtBCity.value     == "") ||
	   (document.formu.txtBEmail.value    == "")   )
	{
		switch (document.formu.txtShopPara.value) {
		case 'Session=EPCE' :
			{
			alert("Some mandatory field are not filed !");
			break;
			}
		default :
			{
			alert("Certains champs marqués d'une * ne sont pas remplis !");
			}
		}
	}
	else
	{
	    if(document.formu.epcoPriceTotal.value == 0)
	    {
		switch (document.formu.txtShopPara.value) {
		case 'Session=EPCE' :
			{
			alert("You should order something before validate !");
			break;
			}
		default :
			{
			alert("Vous devez commander quelque chose avant de valider !");
			}
		}
	    }
	    else
	    {
		if(document.formu.epcoArtDesc.value.slice(0,6) == "Choisi")
		{
		switch (document.formu.txtShopPara.value) {
			case 'Session=EPCE' :
				{
				alert("You should chose a date before ordering !");
				break;
				}
			default :
				{
				alert("Vous devez choisir une date avant de valider !");
				}
			}
		}
		else
		{
			d = new Date();
			document.formu.orderID.value   = AjoutZero (d.getHours(), 2) + AjoutZero (d.getMinutes(), 2) + AjoutZero (d.getSeconds(), 2) + AjoutZero (d.getDate(), 2) + "N";
			document.formu.orderID.value  += AjoutZero (document.formu.epcoArtQuant.value, 1) + AjoutZero (document.formu.epcoVidQuant.value, 1);
			if (document.formu.epcoArtPrice.value == 90)
			{
				document.formu.orderID.value += "0";
			} else {
				document.formu.orderID.value += "1";
			}
			var tempo = ChercheCar (document.formu.epcoArtDesc.value, " ");
			if (tempo > 4)
			{
				document.formu.orderID.value  += "Autr";
			} else {
				var Reste = document.formu.epcoArtDesc.value.slice (0, tempo-1);
				document.formu.orderID.value += AjoutZero (Reste, 2);
				Reste = document.formu.epcoArtDesc.value.slice (tempo);
				tempo = ChercheCar (Reste, " ");
				Reste = Reste.slice (0, tempo-1);
				switch (Reste) {
					case 'janvier' :
						{
						document.formu.orderID.value  += "01";
						break;
						}
					case 'février' :
						{
						document.formu.orderID.value  += "02";
						break;
						}
					case 'mars' :
						{
						document.formu.orderID.value  += "03";
						break;
						}
					case 'avril' :
						{
						document.formu.orderID.value  += "04";
						break;
						}
					case 'mai' :
						{
						document.formu.orderID.value  += "05";
						break;
						}
					case 'juin' :
						{
						document.formu.orderID.value  += "06";
						break;
						}
					case 'juillet' :
						{
						document.formu.orderID.value  += "07";
						break;
						}
					case 'août' :
						{
						document.formu.orderID.value  += "08";
						break;
						}
					case 'septembre' :
						{
						document.formu.orderID.value  += "09";
						break;
						}
					case 'octobre' :
						{
						document.formu.orderID.value  += "10";
						break;
						}
					case 'novembre' :
						{
						document.formu.orderID.value  += "11";
						break;
						}
					default :
						{
						document.formu.orderID.value  += "12";
						break;
						}
				}
			}

			if (empty(document.formu.epcoExtraInfo.value)) {
				document.formu.orderID.value += "0";
			} else {
				document.formu.orderID.value += "1";
			}
// alert (document.formu.orderID.value);
			document.formu.epcoArtQuant.value     = AjoutBlanc (document.formu.epcoArtQuant.value, 3);
			document.formu.epcoVidQuant.value     = AjoutBlanc (document.formu.epcoVidQuant.value, 3);
			var epcoArtDesc                       = RemplisBlanc (document.formu.epcoArtDesc.value, 38);
			document.formu.amount.value           = 100 * NoString (document.formu.epcoPriceTotal.value);
// alert (document.formu.amount.value);
			document.formu.DtxtOrderTotal.value   = document.formu.epcoPriceTotal.value;
			document.formu.DepcoArtPriceTot.value = document.formu.epcoArtPriceTot.value;
			document.formu.DepcoVidPriceTot.value = document.formu.epcoVidPriceTot.value;
			document.formu.epcoDdN.value          = document.formu.epcoJ_DdN.value + "/" + document.formu.epcoM_DdN.value + "/" + document.formu.epcoA_DdN.value;

			document.formu.CN.value = document.formu.txtBFirstName.value + " " + document.formu.txtBLastName.value;
			document.formu.EMAIL.value = document.formu.txtBEmail.value;
			document.formu.ownerZIP.value = document.formu.txtBZipCode.value;
			document.formu.owneraddress.value = document.formu.txtBAddr1.value;
			document.formu.ownercty.value = document.formu.txtBCountry.value;
			document.formu.ownertown.value = document.formu.txtBCity.value;
			document.formu.ownertelno.value = document.formu.txtBTel.value;

			document.mail.AKsubject.value = "Commande on-line, Shop EPCO - transaction " + document.formu.orderID.value;
			if (document.formu.txtBTitle.value != "Madame") {
				document.mail.AKmessage.value = "Le client suivant :\n";
			} else {
				document.mail.AKmessage.value = "La cliente suivante :\n";
			}
			if (document.formu.txtShopPara.value == "Session=EPCE") {
				document.mail.AKmessage.value += "A REMPLIS LE FORMULAIRE EN ANGLAIS\n";
			}
			document.mail.AKmessage.value += "\n";
			document.mail.AKmessage.value += document.formu.txtBLastName.value + " " + document.formu.txtBFirstName.value + "\n";
			if (!empty(document.formu.txtBAddr1.value)) document.mail.AKmessage.value += document.formu.txtBAddr1.value + "\n";
			if (!empty(document.formu.txtBAddr2.value)) document.mail.AKmessage.value += document.formu.txtBAddr2.value + "\n";
			if (!empty(document.formu.txtBPostbox.value)) document.mail.AKmessage.value += "Boite postale : " + document.formu.txtBPostbox.value + "\n";
			if (document.formu.txtBCountry.value != "CH") document.mail.AKmessage.value += document.formu.txtBCountry.value + "-";
			document.mail.AKmessage.value += document.formu.txtBZipCode.value + " " + document.formu.txtBCity.value + "\n\n";
			if (!empty(document.formu.txtBTel.value)) document.mail.AKmessage.value += "Tél.  : " + document.formu.txtBTel.value + "\n";
			if (!empty(document.formu.txtBFax.value)) document.mail.AKmessage.value += "Fax   : " + document.formu.txtBFax.value + "\n";
			document.mail.AKmessage.value += "Email : " + document.formu.txtBEmail.value + "\n";

			if (!empty(document.formu.epcoDdN.value)) document.mail.AKmessage.value += "Date de naissance : " + document.formu.epcoDdN.value + "\n";
			if (!empty(document.formu.epcoTaille.value)) document.mail.AKmessage.value += "Taille, poids : " + document.formu.epcoTaille.value + " cm   " + document.formu.epcoPoids.value +" kg\n";
			if (!empty(document.formu.epcoExtraInfo.value)) document.mail.AKmessage.value += "\nRemarques :\n" + document.formu.epcoExtraInfo.value + "\n";
			document.mail.AKmessage.value += "\nA commandé :\n\n";
			document.mail.AKmessage.value += "Qte Article Date de saut                              P.U.      Total\n";
			document.mail.AKmessage.value += "--- ------- -------------------------------------- --------- ---------\n";
			document.mail.AKmessage.value += document.formu.epcoArtQuant.value + " ";
			document.mail.AKmessage.value += document.formu.epcoArtNr.value + " ";
			document.mail.AKmessage.value += epcoArtDesc + " ";
			document.mail.AKmessage.value += document.formu.epcoArtPrice.value + "  ";
			document.mail.AKmessage.value += document.formu.epcoArtPriceTot.value + "\n";

			if (document.formu.epcoVidQuant.value > 0)
			{
				document.mail.AKmessage.value += document.formu.epcoVidQuant.value + "  Vidéo                                         ";
				document.mail.AKmessage.value += document.formu.epcoVidPrice.value + "  ";
				document.mail.AKmessage.value += document.formu.epcoVidPriceTot.value + "\n";
			}

			document.mail.AKmessage.value += "                                                             ---------\n";
			document.mail.AKmessage.value += "                                            TOTAL à payer :   " + document.formu.DtxtOrderTotal.value;
			document.mail.AKmessage.value += "\n\nDès réception de la confirmation de YellowPay, merci de lui confirmer cette inscription ...\n";
			document.mail.AKmailto.value ="info@epco.aero";

// alert (document.mail.AKmessage.value);

			document.mail.submit();
			var AKRien = 3000;
			while (AKRien > 0) {
				AKRien -= 1;
				defaultStatus = "Wait : " + AKRien;
				}
			defaultStatus = "";
			document.formu.action="https://e-payment.postfinance.ch/ncol/prod/orderstandard.asp";
			document.formu.submit();
		}
	    }
	}
    }
}

