/*
 * Construction d'une adresse mail
 * -------------------------------
 */
function BuildAddress (anchor, name, domain, tld) {
	anchor.href = new String("").concat ('mailto:', name, '@', domain, '.', tld);
	anchor.title = new String("").concat (name, '@', domain, '.', tld);
}

/*
 * Vérification adresse mail
 * -------------------------
 */
function CheckMailAddress (address) {
	addressPattern = /^[a-z0-9_\-\.]+@[a-z0-9_\-]+\.+[a-z]{2,4}$/i;
	return addressPattern.test (address);
}

/*
 * Preload images
 * --------------
 */
function PreloadImages()
{
  if (document.preloadArray == null)
	preloadArray = new Array();
  var i = preloadArray.length;
  for (var j = 0; j < PreloadImages.arguments.length; j++) {
	preloadArray[i] = new Image;
	preloadArray[i++].src = PreloadImages.arguments[j];
  }
}
/*
 * Affichage date de mise à jour du document
 * -----------------------------------------
 */
function LastModifiedDate()
{
  var english = ((new String(window.location).search("English")) != -1);
  var mod = new Date(document.lastModified);

  if (english) {
    var day = new Array ("sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday");
    var month = new Array ("january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december");
    document.writeln(day[mod.getDay()] + ", " + month[mod.getMonth()] + " " + mod.getDate() + ", " + mod.getFullYear() + " " + mod.getHours() + ":" + mod.getMinutes());
  } else {
    var day = new Array ("dimanche", "lundi", "mardi", "mecredi", "jeudi", "vendredi", "samedi");
    var month = new Array ("janvier", "février", "mars", "avril", "mai", "juin", "juillet", "ao&ucirc;t", "septembre", "octobre", "novembre", "décembre");
    document.writeln(day[mod.getDay()] + " " + mod.getDate() + " " + month[mod.getMonth()] + " " + mod.getFullYear() + " " + mod.getHours() + ":" + mod.getMinutes());
  }
}

/*
 *	Validation de la commande
 *	-------------------------
 */
function ValidTheOrder(theChateau) {
	if (document.Order.email.value && !CheckMailAddress(document.Order.email.value)) {
		alert(mOrderBadEmail);
		return false;
	}
	if (!document.Order.name.value || !document.Order.address.value) {
		alert(mOrderNoaddress);
		return false;
	}
	if (eval("document.Order.TotalTTC" + theChateau).value == 0) {
		alert(mOrderEmpty);
		return false;
	}
	document.Order.action.value = "valid";
	document.Order.chateau.value = theChateau;
	document.Order.submit();
}
function ShowOrder(theChateau) {	// A jeter quand l'anglais sera à jour !!
	document.Order.chateau.value = theChateau;
	document.Order.submit();
}

/*
 * Envoi formulaire de contact
 * ---------------------------
 */
function CheckTheForm() {	// Pas utilisé, mais bon, ce serait mieux mais ça entraîne des tas de merde pour le multilingue
	var email = document.MailingForm.email.value;
	var name = document.MailingForm.name.value;
	var address = document.MailingForm.address.value;
	if (email) {
		if (!CheckMailAddress (email)) {
			alert ("Adresse courriel incorrecte " + email + " !");
			return false;
		}
	} else if (!name || !address) {
		alert ("S'il n'y a pas d'adresse courriel, il faut un nom et une adresse !");
		return false;
	}
	return true;
}
function MailTheForm() {
	if (CheckTheForm()) {
		document.MailingForm.submit();
	}
}
function Mailing() {
	document.MailingForm.submit();
}

/*
 * Calculs de la commande
 * ----------------------
 */
function ComputeTheOrder(theChateau) {
	var PriceList = eval(theChateau + "PriceList");
	var TotalTTC = 0;
	var Transport = 27;
	for (var i = 0; PriceList[i] >= 0; i++) {
		QuantityObj = eval("document.Order.Quantity" + theChateau + i/2);
		TotalObj = eval("document.Order.Total" + theChateau + i/2);
//		if (theChateau == "DCVRT")	// Offre découverte, quantité limitée à 1
//				QuantityObj.value = 1;
		TotalObj.value = Math.round(QuantityObj.value * PriceList[i] * 100) / 100;
		TotalTTC += Math.round(QuantityObj.value * PriceList[i] * 100) / 100;
		i++;						// Traitement du franco de port
		if (PriceList[i] && QuantityObj.value >= PriceList[i])
			Transport = 0;
	}
	if (!TotalTTC)
		Transport = 0;
	if (TotalObj = eval("document.Order.Transport" + theChateau)) {
		TotalObj.value = Transport;
		TotalTTC += Transport;
	}
	TotalObj = eval("document.Order.TotalTTC" + theChateau);
	TotalObj.value = TotalTTC;
	TotalObj = eval("document.Order.TotalHT" + theChateau);
	TotalObj.value = Math.round(TotalTTC * 83.6) / 100;
	TotalObj = eval("document.Order.TVA" + theChateau);
	TotalObj.value = Math.round((TotalTTC * 100) - (TotalTTC * 83.6)) / 100;
}

function ResetTheOrder(theChateau) {
	for (i = 0; i < 100; i++) {
		if (!(QuantityObj = eval("document.Order.Quantity" + theChateau + i))) break;
		QuantityObj.value = 0;
	}
	ComputeTheOrder(theChateau);
}

/*
 * Essais, prototypes, tests
 * -------------------------
 */
function PopUpProperties(inobj) {
        op = window.open();
        op.document.open('text/plain');
        for (objprop in inobj) {
        	op.document.write("-***-" + objprop + ' => ' + inobj[objprop] + '\n');
        }
        op.document.close();
op.focus();
}
/*
 * Affichage date commande
 * -----------------------
 */
function OrderDate()
{
/* Le bon de commande est en français !!! */
  var english = false; /*((new String(window.location).search("/EN/")) != -1);*/
  var mod = new Date();

  if (english) {
    var day = new Array ("sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday");
    var month = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    document.writeln(day[mod.getDay()] + ", " + month[mod.getMonth()] + " " + mod.getDate() + ", " + mod.getFullYear());
  } else {
    var day = new Array ("dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi");
    var month = new Array ("janvier", "février", "mars", "avril", "mai", "juin", "juillet", "ao&ucirc;t", "septembre", "octobre", "novembre", "décembre");
    document.writeln(day[mod.getDay()] + " " + mod.getDate() + " " + month[mod.getMonth()] + " " + mod.getFullYear());
  }
}
/*
 * Changements de langue
 * ---------------------
 */
function ToEN() {
	if (location.href.search("/EN/") != -1) {
		return;
	} else {
		location.href = location.href.replace("/FR/", "/EN/");
	}
}
function ToFR() {
	if (location.href.search("/FR/") != -1) {
		return;
	} else {
		location.href = location.href.replace("/EN/", "/FR/");
	}
}
function ToRU() {
		location.href = "../RU/plaquette.htm";
}
function ToCN() {
		location.href = "../CN/plaquette.htm";
}

