var InMenu, Langue = false;

var OtherLang;
var FN = document.location.href;

if (FN.indexOf("_EN.php") != -1)
   FN = "index_EN.html";
else if (FN.indexOf(".html") == -1)
   FN="index.html";
else
   FN = FN.substring(FN.lastIndexOf("/") + 1);

if (FN.search("_EN.html") != -1)
{
   OtherLang = FN.substr(0, FN.lastIndexOf(".") - 3);
   OtherLang = OtherLang + ".html";
   Langue = true;
}
else
   OtherLang = FN.substr(0, FN.lastIndexOf(".")) + "_EN.html";

var Suff = (Langue) ? "_EN" : "";
var IE = (navigator.appName == "Microsoft Internet Explorer");

function Prop(Obj, ObjName, UseAlert) 
{
   var Res = ""
   for (var t in Obj)
   {
	if (String(Obj[t]).indexOf("function") == -1)
         Res += ObjName + "." + t + " = " + Obj[t];
      if (UseAlert)
         Res += "\n";
      else
         Res += "<BR>";
   }
   if (window.clipboardData)
      window.clipboardData.setData("Text", Res);

   if (UseAlert)
      alert(Res);
   
   return Res;
}

function VariableEnv()
{
   var Value = '<!--#echo var="REDIRECT_STATUS"-->';
   document.write("Erreur " + Value);
}

function GetURLParam(Param)
{
   Page = window.location.href;
   Liste = Page.split(new RegExp(Param + "=", "g"));
   Find = "";

   if (Liste.length != 1)
   {
      Find = Liste[1].split(new RegExp("&", "g"));
      if (Find.length != 1)
         Find = Find[0];
   }
   return Find;
}

var X1, X2, Pos, MsgID = Math.round(Math.random() * 10) % 2;
var Msg = new Array(2);

function CheckEmail(Str) 
{
   var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
   var emailPat = /^(.+)@(.+)$/;
   var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
   var validChars = "\[^\\s" + specialChars + "\]";
   var quotedUser = "(\"[^\"]*\")";
   var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
   var atom = validChars + '+';
   var word = "(" + atom + "|" + quotedUser + ")";
   var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
   var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$");
   var matchArray = Str.match(emailPat);

   if (!matchArray) 
   {
      alert("Adresse de « Courrier Électronique » invalide !");
      return false;
   }
   var user = matchArray[1];
   var domain = matchArray[2];

   for (i = 0; i < user.length; i++) 
      if (user.charCodeAt(i) > 127) 
      {
         alert("Adresse de « Courrier Électronique » invalide !");
         return false;
      }

   for (i = 0; i < domain.length; i++)
      if (domain.charCodeAt(i) > 127) 
      {
         alert("Adresse de « Courrier Électronique » invalide !");
         return false;
      }

   if (!user.match(userPat)) 
   {
      alert("Adresse de « Courrier Électronique » invalide !");
      return false;
   }
   var IPArray = domain.match(ipDomainPat);
   if (IPArray) 
   {
      for (i = 1; i <= 4; i++) 
      {
         if (IPArray[i] > 255) 
         {
            alert("Adresse de « Courrier Électronique » invalide !");
            return false;
         }
      }
      return true;
   }
   var atomPat = new RegExp("^" + atom + "$");
   var domArr = domain.split(".");
   var len = domArr.length;
   for (i = 0; i < len; i++) 
      if (domArr[i].search(atomPat) == -1) 
      {
         alert("Adresse de « Courrier Électronique » invalide !");
         return false;
      }

   if (domArr[domArr.length - 1].length != 2 && domArr[domArr.length - 1].search(knownDomsPat) == -1)
   {
      alert("Adresse de « Courrier Électronique » invalide !");
      return false;
   }
   if (len < 2) 
   {
      alert("Adresse de « Courrier Électronique » invalide !");
      return false;
   }
   return true;
}

function OP(Value)
{
	document.forms.namedItem('Formulaire').elements.namedItem('OP').value = Value;
	document.forms.namedItem('Formulaire').submit();
}

function LOG(Value, Form)
{
	Obj = (!Form) ? document.forms.namedItem('Formulaire') :	document.forms.namedItem('FormFacture');
	
	if (Value == 5)
	{
		Obj.elements.namedItem('LOG').value = Value;
		Obj.submit();
	}	
	else if (Validation())
	{
		Obj.action = 'Facture/index.php';
		Obj.elements.namedItem('LOG').value = Value;
		Obj.submit();
	}
}

function Validation()
{
   if (document.Formulaire.Nom && document.Formulaire.Nom.value == "")
   {
		alert("Vous devez spécifier une « Personne à Contacter » !");
		document.Formulaire.Nom.focus();
		return false;
   }
   if (document.Formulaire.Courrier && document.Formulaire.Courrier.value == "")
   {
		alert("Vous devez spécifier un « Courrier Électronique » !");
		document.Formulaire.Courrier.focus();
		return false;
   }
   else if (document.Formulaire.Courrier && document.Formulaire.Courrier.value != "123" && !CheckEmail(document.Formulaire.Courrier.value))
   {
		document.Formulaire.Courrier.focus();
		return false;
   }
   if (document.Formulaire.Password && document.Formulaire.Password.value == "")
   {
		alert("Vous devez spécifier un « Mot de Passe » !");
		document.Formulaire.Password.focus();
		return false;
   }
   if (document.Formulaire.Commentaire && document.Formulaire.Commentaire.value == "")
   {
		alert("Vous devez spécifier un « Commentaire » !");
		document.Formulaire.Commentaire.focus();
	   return false;
   }
   if (document.Formulaire.xxxCompany && document.Formulaire.xxxCompany.value == "")
   {
      alert("Vous devez spécifier un « Nom de Compagnie » !");
		document.Formulaire.xxxCompany.focus();
		return false;
   }
   if (document.Formulaire.xxxAddress && document.Formulaire.xxxAddress.value == "")
   {
      alert("Vous devez spécifier une « Adresse Civic » !");
		document.Formulaire.xxxAddress.focus();
		return false;
   }
   if (document.Formulaire.xxxCity && document.Formulaire.xxxCity.value == "")
   {
      alert("Vous devez spécifier une « Ville » !");
		document.Formulaire.xxxCity.focus();
		return false;
   }
   if (document.Formulaire.xxxPostal && document.Formulaire.xxxPostal.value == "")
   {
      alert("Vous devez spécifier un « Code Postal » !");
		document.Formulaire.xxxPostal.focus();
		return false;
   }
   if (document.Formulaire.xxxName && document.Formulaire.xxxName.value == "")
   {
      alert("Vous devez spécifier un « Nom sur la Carte » !");
		document.Formulaire.xxxName.focus();
		return false;
   }
   if (document.Formulaire.xxxEmail && document.Formulaire.xxxEmail.value == "")
   {
      alert("Vous devez spécifier un « Courrier Électronique » !");
		document.Formulaire.xxxEmail.focus();
		return false;
   }
   else if (document.Formulaire.xxxEmail && !CheckEmail(document.Formulaire.xxxEmail.value))
   {
		document.Formulaire.xxxEmail.focus();
		return false;
   }

   if (document.Formulaire.xxxPhone && document.Formulaire.xxxPhone.value == "")
   {
      alert("Vous devez spécifier un « Numéro de Téléphone » !");
		document.Formulaire.xxxPhone.focus();
		return false;
   }
   return true;
}

function ValidationAchat()
{
   if (document.FormAchat.xxxCompany && document.FormAchat.xxxCompany.value == "")
   {
      alert("Vous devez spécifier un « Nom de Compagnie » !");
		document.FormAchat.xxxCompany.focus();
		return false;
   }
   if (document.FormAchat.xxxAddress && document.FormAchat.xxxAddress.value == "")
   {
      alert("Vous devez spécifier une « Adresse Civic » !");
		document.FormAchat.xxxAddress.focus();
		return false;
   }
   if (document.FormAchat.xxxCity && document.FormAchat.xxxCity.value == "")
   {
      alert("Vous devez spécifier une « Ville » !");
		document.FormAchat.xxxCity.focus();
		return false;
   }
   if (document.FormAchat.xxxPostal && document.FormAchat.xxxPostal.value == "")
   {
      alert("Vous devez spécifier un « Code Postal » !");
		document.FormAchat.xxxPostal.focus();
		return false;
   }
   if (document.FormAchat.xxxName && document.FormAchat.xxxName.value == "")
   {
      alert("Vous devez spécifier un « Nom sur la Carte » !");
		document.FormAchat.xxxName.focus();
		return false;
   }
   if (document.FormAchat.xxxEmail && document.FormAchat.xxxEmail.value == "")
   {
      alert("Vous devez spécifier un « Courrier Électronique » !");
		document.FormAchat.xxxEmail.focus();
		return false;
   }
   else if (document.FormAchat.xxxEmail && !CheckEmail(document.FormAchat.xxxEmail.value))
   {
		document.FormAchat.xxxEmail.focus();
		return false;
   }

   if (document.FormAchat.xxxPhone && document.FormAchat.xxxPhone.value == "")
   {
      alert("Vous devez spécifier un « Numéro de Téléphone » !");
		document.FormAchat.xxxPhone.focus();
		return false;
   }
   x = screen.width - 12;
   if (x > 840)
	x = 840;

   y = screen.height - 80;
   if (y > 880)
       y = 880;

   return true;
}

function ShowDivNav(Show, Image)
{
	W = document.body.clientWidth + 40;	// 40 = Ajustement pour MARGIN dans body.style 
	H = document.body.clientHeight + 40; 

	Obj = document.getElementById("DivImgMask");
	Obj.width = W + 100;
	Obj.height = H + 100;
	
	Obj = document.getElementById("DivNavMask");
	Obj.style.visibility = (Show) ? "visible" : "hidden";
	

	Obj = document.getElementById("DivImg");
	Obj.src = Image;

	Obj = document.getElementById("DivNav");
	Obj.style.left = (W - 773) / 2; 
	Obj.style.top = (H - 581) / 2;
	Obj.style.visibility = (Show) ? "visible" : "hidden";
	
	Obj = document.getElementById('MainTable');
	Obj.disabled = Show;
}

