
function getFormatedDate()
{ // retourne un string jj/mm/yyyy = valide entre 2000 et 2009
  // car différences entre netscape et ie = ns retourne 101 = > remplacer "101" par "20" + 01 
  var d, s;
  var monthName = new Array("01", "02", "03","04", "05", "06", "07", "08", "09","10", "11", "12");
  var theyear;
  d = new Date();
  theyear = new String(d.getYear());
  s = d.getDate() + "/" + monthName[d.getMonth()] + "/" + "20"; 
  s = s + (theyear.substring(theyear.length-2,theyear.length) );
  return (new String(s));
}

function getindexof(thevalue,a)
{ 
// specifications : a : the anchor array to search in, value the searched value
// returns the index of the searched value in the array.
// exceptions : the value is not there = returns -1
// ------------------------------------------------

    var i = 0;
    for (i = 0; i < a.length; i++) 
    {      if (a[i].name == thevalue ) 
           {         return (i);      
           };   
    };
    return -1;
}

function findelementinarray(thevalue,a)
{ 
// specifications : a : the array to search in, value the searched value
// returns the index of the searched value in the array.
// exceptions : the value is not there = returns -1
// ------------------------------------------------
//alert('inside');
//alert(thevalue);
    var i = 0;
    for (i = 0; i < a.length; i++) 
    {      if (a[i] == thevalue ) 
           {
                   // alert(i + '');
                    return (new Number(i));      
           };
             
    };
//alert('outside');    
    return (-1);

    
}

function getvalueofselectoptionmenu(formname,selectname)
{
// specifications : return value : gets the selected value of a non multiple select option
// pre-rquesits   : the form exists and the select option control has 1 and only 1 selected item
// parameters     : formname : the string name of the form.
//                  selectname : the string name of the non multiple select option control
// exceptions     : the formname doesn't exist, the select option doesn't exist : returns null
//                  the select option is multiple choice : returns the value of the first selected element there is NOERROR - but return value not significative !!

var indexinform = 0;

indexinform = getindexof(selectname,document.forms[formname].elements);

var optioncount = document.forms[formname].elements[indexinform].options.length;
var i = 0;
while( (i < optioncount) && (document.forms[formname].elements[indexinform].options[i].selected == false))
{
  ++i;
};

return (document.forms[formname].elements[indexinform].options[i].value);

}

function setformelementto(formname,elementin,thevalue)
{
//  set the value of the form element to the value.
//  works well with text, hidden elements
//  had some problems with select elements ...
  var indexinform = getindexof(elementin,document.forms[formname].elements);
  if (indexinform!=-1) {
    document.forms[formname].elements[indexinform].value = thevalue;
    return true;
  }
  else {
    return false;
  };
}

function getvaluefromformelement(formname,elementin)
{  
//  gets the value of a given name element in the form
//  both parameters are strings ... 
  var indexinform = getindexof(elementin,document.forms[formname].elements);
  if (indexinform!=-1) {
    return new String(document.forms[formname].elements[indexinform].value);
  }
  else {
    return new String("");
  };
}
function getnumbervaluefromformelement(formname,elementin)
{  
//  gets the value of a given name element in the form
//  both parameters are strings ... 
  var indexinform = getindexof(elementin,document.forms[formname].elements);
  if (indexinform!=-1) {
    return new Number (document.forms[formname].elements[indexinform].value);
  }
  else {
    return Nan;
  };
}

function clickformelement(formname,elemname)
{
// purpose : trigger the click event by programmation on a element in a form
// parameters : 
// + fromname a string representing the name (id) of the form, must exist 
//   in the document
// + elemname a string representing the name (id) in the form, the element 
//   must exist and has a at least a default handler to the click event - 
//   most of forms elements may accept click event. 
  var indexinform = getindexof(elemname,document.forms[formname].elements);
  if (indexinform != -1) {
    document.forms[formname].elements[indexinform].click();
    return true;
  }
  else {
    return false;
  };
}
function initfromform(formname,arrayelems,arrayvalues)
{
// forname    : the name of the source form, 
// arrayelems : an array of strings representing the source elements wanted 
//              (mostly edits)
// arrayvalues: the destination array value. 
// purpose : this function copies the values from the wanted edits elements 
// of a form in a destination array
// return value : a string representing the concatenation of the values
   var l;
   var k;
   var x;
   x = '';
   l = arrayelems.length;
   for (var i = 0;i < l;++i)
   {
      k = getindexof(arrayelems[i],document.forms[formname].elements);
// alert(arrayelems[i] + ": " + "k" + k + ", value read :" + document.forms[formname].elements[k].value);
      arrayvalues[i] = document.forms[formname].elements[k].value;
      
      x = x + arrayvalues[i]; 
   };
   return x;
}

function ValidateForm(com)
{ var nom, prenom, rue, cp, ville, pays;
  nom = document.com.nom.value;
  if (nom == "")
  {
     if (document.com.role.value == "FR")
     {
     alert("Vous devez nous communiquer votre nom!");
     }
     else
     {
     alert("U moet ons uw naam meedelen!");
     };
     document.com.nom.focus();
     return false;
  };
  prenom = document.com.prenom.value;
  if (prenom == "")
  {
     if (document.com.role.value == "FR")
	 {
       alert("Vous devez nous communiquer votre prénom!");
     }
	 else
	 {
	   alert("U moet ons uw voornaam meedelen!");
	 };
     document.com.prenom.focus();
     return false;
  };
  rue = document.com.rue.value;
  cp = document.com.cp.value;
  ville = document.com.ville.value;

  var messageErr;
  if (document.com.role.value == "FR")
  {
    messageErr = "Vous devez nous communiquer votre adresse complète !"
  }
  else
  {
    messageErr = "U moet ons uw volledig adres meedelen!"
  };
  if (rue == "")
  {
     alert(messageErr);
     document.com.rue.focus();
     return false;
  };
  if (cp == "")
  {
     alert(messageErr);
     document.com.cp.focus();
     return false;
  };
  if (ville == "")
  {
     alert(messageErr);
     document.com.ville.focus();
     return false;
  };
  pays = document.com.pays.value;
  if (pays == "")
  {
       if (document.com.role.value == "FR")  
       {   
	          alert("vous devez encoder ou sélectionner votre pays!");
       }
       else

  
	   {
          alert("U moet uw land kiezen of intikken!");
       };
       document.com.pays.focus()
       return false;
  }

      if (document.com.nom.value.length != 0)
		document.com.nom.value = verifyAlpha(document.com.nom.value);
	if (document.com.prenom.value.length != 0)
		document.com.prenom.value = verifyAlpha(document.com.prenom.value);
	if (document.com.rue.value.length != 0)
		document.com.rue.value = verifyAlpha(document.com.rue.value);
	if (document.com.cp.value.length != 0)
		document.com.cp.value = verifyAlpha(document.com.cp.value);
	if (document.com.ville.value.length != 0)
		document.com.ville.value = verifyAlpha(document.com.ville.value);
	if (document.com.pays.value.length != 0)
		document.com.pays.value = verifyAlpha(document.com.pays.value);

  return true;
}
function verifyAlpha(AZ) {
	var CorrChar = new Array();
	var pos = 0;
	
	// De Array CorrChar bevat de ASCII codes van toegelaten karakters. Om chars toe te voegen of te verwijderen moet je enkel 2 lijntjes initialisatie-code bijvoegen

	CorrChar[pos] = 13;
	pos++;
	
	CorrChar[pos] = 32;
	pos++;
	
	for (var l = 44; l < 47; l++){
		CorrChar[pos] = l;
		pos++;
	}
	
	for (var l = 48; l < 58; l++){
		CorrChar[pos] = l;
		pos++;
	}
	
	CorrChar[pos] = 58;
	pos++;
	
	for (var l = 64; l < 91; l++){
		CorrChar[pos] = l;
		pos++;
	}	
	
	for (var l = 95; l < 123; l++){
		CorrChar[pos] = l;
		pos++;
	}
	
	CorrChar[pos] = 224;
	pos++;
		
	CorrChar[pos] = 226;
	pos++;		
		
	CorrChar[pos] = 228;
	pos++;
	
	for (var l = 231; l < 236; l++){
		CorrChar[pos] = l;
		pos++;
	}	

	CorrChar[pos] = 244;
	pos++;
	
	CorrChar[pos] = 246;
	pos++;
	
	CorrChar[pos] = 249;
	pos++;
	
	CorrChar[pos] = 251;
	pos++;
	
	CorrChar[pos] = 255;
	pos++;
	
	var validChar = false;
			
  	if (AZ.length!=0) {
	    for (var i=0; i<AZ.length; i++) {
			bValidChar = false;
			for (var j = 0; j < CorrChar.length; j ++){
				if (AZ.charCodeAt(i) == CorrChar[j]){
					bValidChar = true;
				}
			} 
			if(!bValidChar){
				AZ = AZ.replace(AZ.substring(i,i+1),"");
				i--;
			}
    	}
	}
	return AZ;
}	


