function generateID(){
	var theDate = new Date();
	var theMonth = new String(theDate.getMonth() + 1);
	if(theMonth.length==1)theMonth = "0" + theMonth;
	var theDay = new String(theDate.getDate());
	if(theDay.length==1)theDay = "0" + theDay;
	var theYear = new String(theDate.getYear());
	while(theYear.length<4)theYear = "0" + theYear;
		
	with(Math){
		var fieldText = theYear.substr(3,1) + theMonth + theDay + floor(random()*9) + floor(random()*9) + floor(random()*9) + floor(random()*9) + floor(random()*9);
		if(document.contactForm){
			document.contactForm.contactID.value = fieldText;
		}else{
			document.importForm.contactID.value = fieldText;
		}
	}
	var theHTML="&nbsp;&nbsp;&nbsp;<b style='color: #002350; font-size: 1.2em'>" + fieldText + "</b>";
	if(document.layers){
		document.layers['contactIDlayer'].document.open();
		document.layers['contactIDlayer'].document.write(theHTML);
		document.layers['contactIDlayer'].document.close();
	}
	if(document.all){
		document.all['contactIDlayer'].innerHTML = theHTML;
	}
	if(document.getElementById){
		document.getElementById('contactIDlayer').innerHTML = theHTML;
	}
}

function condLength(theRadioButton, field, fieldname, fieldlength, langcode) {
	if (theRadioButton.checked) {
		if(CheckLength(field, fieldname, fieldlength, langcode)){
			return true;
		} else {
			return false;
		}
	}
	return true;
}

function CheckFormat(field,fieldname,langcode,regularExp,humanReadable){
/************************************************
DESCRIPTION: Validates that a string a matches
  a valid regular expression value.
date : (0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/(19|20)[0-9][0-9]
PARAMETERS:
   strValue - String to be tested for validity
   strMatchPattern - String containing a valid
      regular expression match pattern.

RETURNS:
   True if valid, otherwise false.
*************************************************/
var objRegExp = new RegExp(regularExp);

 //check if string matches pattern
 formatOK = objRegExp.test(field.value);
	 if(!formatOK){
		if(langcode == "FR")
          {
            alert("Le champ '" + fieldname + "' doit être conforme au format " + humanReadable + ".");
          }
          else if(langcode == "NL")
          {
            alert(fieldname + " voldoet niet aan het formaat " + humanReadable + ".");
          }
          else if(langcode == "EN")
          {
            alert(fieldname + " has to be in the format " + humanReadable + ".");
          }
          else if(langcode == "DE")
          {
            alert(fieldname + " has to be in the format " + humanReadable + ".");
          }
		field.focus();
     }
	 return formatOK;
}


function CheckAccountNbr(field,fieldname,langcode){
// Bank: last two digits = [first ten digits] mod 97
/*
Een check op een belgische BTW-nummer gaat als volgt:

97 - ((de eerste 7 cijfers) Mod 97) = de twee laatste cijfers

*/
	if(field.value!=""){
		var checksumOK = false;
		var formatOK = false;
		formatOK = CheckFormat(field,fieldname,langcode,'[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9]','XXX-XXXXXXX-XX');
		if(formatOK){
			var firstPart = field.value.substr(0,3);
			var secondPart = field.value.substr(4,7);
			var thirdPart = field.value.substr(12,2);
			var target = thirdPart;
			if (target >= 97){
				target = target - 97;
			}
			var deeltal = firstPart + secondPart;
			var resterend = deeltal % 97;
			if(resterend == target){
				checksumOK = true;
			}else{
				if(langcode == "FR")
					{
					alert(fieldname + " est un numéro incorrect. Veuillez contrôler.");
					}
				else if(langcode == "NL")
					{
					alert(fieldname + " is geen correct nummer. Gelieve dit te controleren.");
					}
				else if(langcode == "EN")
					{
					alert(fieldname + " is an incorrect number. Please check.");
					}
				else if(langcode == "DE")
					{
					alert(fieldname + " is an incorrect number. Please check.");
				}
				field.focus();
			}
		}
		return (formatOK && checksumOK);
	}else{
		return true;
	}
}

function IsNumeric(field,fieldname,langcode){
   var sText = field.value;
   var ValidChars = "0123456789.,";
   var IsNumber=true;
   var Char;
    
   for (i = 0; i < sText.length && IsNumber == true; i++){ 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1){
         IsNumber = false;
      }
   }
   
   if(!IsNumber){
		if(langcode == "FR")
          {
            alert("Le champ '" + fieldname + "' ne doit comporter que des chiffres.");
          }
          else if(langcode == "NL")
          {
            alert(fieldname + " moet bestaan uit cijfers!");
          }
          else if(langcode == "EN")
          {
            alert(fieldname + " has to be a number !");
          }
          else if(langcode == "DE")
          {
            alert(fieldname + " muß eine Zahl sein !");
          }
		field.focus();
	}
   
   return IsNumber;
}

function CheckLength(field,fieldname,fieldlength, langcode){
	if(field.value.length != fieldlength){
		if(langcode == "FR")
          {
            alert(fieldname + " doit comporter " + fieldlength + " caractères !");
          }
          else if(langcode == "NL")
          {
            alert(fieldname + " moet " + fieldlength + " karakters lang zijn!");
          }
          else if(langcode == "EN")
          {
            alert(fieldname + " has to consist of " + fieldlength + " characters !");
          }
          else if(langcode == "DE")
          {
            alert(fieldname + " has to consist of " + fieldlength + " characters !");
          }
		field.focus();
		return false;
	}else{
		return true;
	}
}

function copySenderAddressee(contactForm) {

personalDataFields = new Array();
senderDataFields = new Array();
addresseeDataFields = new Array();

personalDataFields[0] = document.importForm.naam;
personalDataFields[1] = document.importForm.voornaam;
personalDataFields[2] = document.importForm.straat;
personalDataFields[3] = document.importForm.nummer;
personalDataFields[4] = document.importForm.bus;
personalDataFields[5] = document.importForm.postcode;
personalDataFields[6] = document.importForm.plaats;
personalDataFields[7] = document.importForm.land;
personalDataFields[8] = document.importForm.telefoon;
personalDataFields[9] = document.importForm.email;
personalDataFields[10] = document.importForm.rekeningnummer;

senderDataFields[0] = document.importForm.naam_verzender;
senderDataFields[1] = document.importForm.voornaam_verzender;
senderDataFields[2] = document.importForm.straat_verzender;
senderDataFields[3] = document.importForm.nummer_verzender;
senderDataFields[4] = document.importForm.bus_verzender;
senderDataFields[5] = document.importForm.postcode_verzender;
senderDataFields[6] = document.importForm.plaats_verzender;
senderDataFields[7] = document.importForm.land_verzender;
senderDataFields[8] = document.importForm.telefoon_verzender;
senderDataFields[9] = document.importForm.email_verzender;
senderDataFields[10] = document.importForm.rekeningnummer_verzender;

addresseeDataFields[0] = document.importForm.naam_bestemmeling;
addresseeDataFields[1] = document.importForm.voornaam_bestemmeling;
addresseeDataFields[2] = document.importForm.straat_bestemmeling;
addresseeDataFields[3] = document.importForm.nummer_bestemmeling;
addresseeDataFields[4] = document.importForm.bus_bestemmeling;
addresseeDataFields[5] = document.importForm.postcode_bestemmeling;
addresseeDataFields[6] = document.importForm.plaats_bestemmeling;
addresseeDataFields[7] = document.importForm.land_bestemmeling;
addresseeDataFields[8] = document.importForm.telefoon_bestemmeling;
addresseeDataFields[9] = document.importForm.email_bestemmeling;
addresseeDataFields[10] = document.importForm.rekeningnummer_bestemmeling;
	
	if(document.importForm.afzender_bestemmeling[0].checked){

		for(i=0;i<11;++i){
			if(senderDataFields[i] != null && personalDataFields[i] != null){
				senderDataFields[i].value = personalDataFields[i].value;
			}
		}

		for(i=0;i<11;++i){
			if(addresseeDataFields[i] != null && personalDataFields[i] != null){
				if(addresseeDataFields[i].value == personalDataFields[i].value){
					addresseeDataFields[i].value = '';
				}		
			}
		}

	}else if(document.importForm.afzender_bestemmeling[1].checked){

		for(i=0;i<11;++i){
			if(addresseeDataFields[i] != null && personalDataFields[i] != null){
				addresseeDataFields[i].value = personalDataFields[i].value;
			}
		}
			
		for(i=0;i<11;++i){
			if(senderDataFields[i] != null && personalDataFields[i] != null){
				if(senderDataFields[i].value == personalDataFields[i].value){
					senderDataFields[i].value = '';
				}		
			}
		}

	}else if(document.importForm.afzender_bestemmeling[2].checked){

		for(i=0;i<11;++i){
			if(senderDataFields[i] != null && personalDataFields[i] != null){
				if(senderDataFields[i].value == personalDataFields[i].value){
					senderDataFields[i].value = '';
				}		
			}
		}
			
		for(i=0;i<11;++i){
			if(addresseeDataFields[i] != null && personalDataFields[i] != null){
				if(addresseeDataFields[i].value == personalDataFields[i].value){
					addresseeDataFields[i].value = '';
				}		
			}
		}
	}
}



function condOblige(theRadioButton, theField, theFieldDesc, theLang) {
	if (theRadioButton.checked) {
		if(CheckMandatoryField(theField, theFieldDesc, theLang)){
			return true;
		} else {
			return false;
		}
	}
	return true;
}

function condTelephone(field,fieldname,langcode){
	if(field.value){
		var melk=field.value;
		var voorraad=melk.length;
		var tepelHoven = new Array('0','1','2','3','4','5','6','7','8','9','.','/',' ','-','+','(',')');
		var tepelKlemmen = new Array('0','1','2','3','4','5','6','7','8','9');
		var okTepels = 0;
		var lekkereTepels = 0;
		for(i=0; i < voorraad; ++i){
			for(j=0; j < tepelHoven.length; ++j){
				if(melk.charAt(i)==tepelHoven[j]){
					okTepels++;
				}
			}
			for(k=0; k < tepelKlemmen.length; ++k){
				if(melk.charAt(i)==tepelHoven[k]){
					lekkereTepels++;
				}
			}
		}
		if(okTepels==voorraad && lekkereTepels>=9){
			return true;
		}else{
			if(langcode == "FR"){
				alert(fieldname + " doit comprendre au moins 9 chiffres et, mis à part ces chiffres, ne peut comprendre que les caractères suivants ./ -+() !");
			}else if(langcode == "NL"){
				alert(fieldname + " moet minstens negen cijfers bevatten en mag buiten cijfers alleen de karakters ./ -+() bevatten!");
			}else if(langcode == "EN"){
				alert(fieldname + " has to consist of at least 9 digits and only digits and ./ -+() are allowed !");
			}else if(langcode == "DE"){
				alert(fieldname + " muß bestehen aus mindestens 9 Ziffern und nur Ziffern und ./ -+() werden gewährt !");
	  		}                  
			field.focus();
			return false;
		}
	}
	return true;
}

function CheckTelephone(field,fieldname,langcode){
	if(field.value){
		var waarde=field.value;
		var lengte=waarde.length;
		var alleenCijfers = new Array('0','1','2','3','4','5','6','7','8','9');
		var okKarakters = 0;
		if(waarde.charAt(0) == '+'){
			okKarakters = 1;
			for(i=1; i < lengte; ++i){
				for(j=0; j < alleenCijfers.length; ++j){
					if(waarde.charAt(i)==alleenCijfers[j]){
						okKarakters++;
					}
				}
			}
			if(okKarakters==lengte && okKarakters>=11){
				return true;
			}else{
				if(langcode == "FR"){
					alert(fieldname + " doit comprendre au moins 10 chiffres et, mis à part ces chiffres, ne peut comprendre que le caractère suivant +");
				}else if(langcode == "NL"){
					alert(fieldname + " moet minstens tien cijfers bevatten en mag buiten cijfers alleen het karakter + bevatten!");
				}else if(langcode == "EN"){
					alert(fieldname + " has to consist of at least 10 digits and only digits and + are allowed !");
				}else if(langcode == "DE"){
					alert(fieldname + " muß bestehen aus mindestens 10 Ziffern und nur Ziffern und + werden gewährt !");
				}                  
				field.focus();
				return false;
			}
		}else if(waarde.charAt(0) == '0'){
			okKarakters = 1;
			for(i=1; i < lengte; ++i){
				for(j=0; j < alleenCijfers.length; ++j){
					if(waarde.charAt(i)==alleenCijfers[j]){
						okKarakters++;
					}
				}
			}
			if(okKarakters==lengte && okKarakters>=9){
				return true;
			}else{
				if(langcode == "FR"){
					alert(fieldname + " doit comprendre au moins 9 chiffres !");
				}else if(langcode == "NL"){
					alert(fieldname + " moet minstens negen cijfers bevatten!");
				}else if(langcode == "EN"){
					alert(fieldname + " has to consist of at least 9 digits !");
				}else if(langcode == "DE"){
					alert(fieldname + " muß bestehen aus mindestens 9 Ziffern !");
				}                  
				field.focus();
				return false;
			}
		}else{
			if(langcode == "FR"){
				alert(fieldname + " doit avoir le format '099999999' ou '+9999999999'");
			}else if(langcode == "NL"){
				alert(fieldname + " moet in het formaat '099999999' of '+9999999999' zijn");
			}else if(langcode == "EN"){
				alert(fieldname + " has to have the format '099999999' or '+9999999999'");
			}else if(langcode == "DE"){
				alert(fieldname + " muß das Format '099999999' oder '+9999999999' haben");
	  		}                  
			field.focus();
			return false;
		}
	}
	return false;
}

function CheckMandatoryField(field, fieldname, langcode){
        if(field.value == "")
        {
          if(langcode == "FR")
          {
            alert(fieldname + " est obligatoire !");
          }
          else if(langcode == "NL")
          {
            alert(fieldname + " is verplicht !");
          }
          else if(langcode == "EN")
          {
            alert(fieldname + " is mandatory !");
          }
          else if(langcode == "DE")
          {
            alert(fieldname + " is verpflichtet !");
          }                  
		  field.focus();
          return false;
        }
        else 
        {
          return true;
        }
}

function CheckAtLeastOneField(description, field1, field2, field3, langcode){
        if(field1.checked || field2.checked || field3.checked)
        {
          return true;
        }
        else 
        {
          if(langcode == "FR")
          {
            alert(description + " est obligatoire !");
          }
          else if(langcode == "NL")
          {
            alert(description + " is verplicht !");
          }
          else if(langcode == "EN")
          {
            alert(description + " is mandatory !");
          }
          else if(langcode == "DE")
          {
            alert(description + " is verpflichtet !");
          }                  
		  field1.focus();
          return false;
        }
}

function CompleteAtLeastOneField(description, field1, field2, field3, langcode){
        if(field1.value != "" || field2.value != "" || field3.value != "")
        {
          return true;
        }
        else 
        {
          if(langcode == "FR")
          {
            alert(description + " est obligatoire !");
          }
          else if(langcode == "NL")
          {
            alert(description + " is verplicht !");
          }
          else if(langcode == "EN")
          {
            alert(description + " is mandatory !");
          }
          else if(langcode == "DE")
          {
            alert(description + " is verpflichtet !");
          }                  
		  field1.focus();
          return false;
        }
}

function CheckMandatoryRadio(field, fieldname, langcode)
  {
	checked = false;
	for(i = 0 ;i < field.length ; i++)
	{
	  checked |= field[i].checked;
	}
	if(!checked)
	{
	  if(langcode == "FR")
	  {
		alert(fieldname + " est obligatoire !");
	  }
	  else if(langcode == "NL")
	  {
		alert(fieldname + " is verplicht !");
	  }
	  else if(langcode == "EN")
	  {
		alert(fieldname + " is mandatory !");
	  }
	  else if(langcode == "DE")
	  {
		alert(fieldname + " is verpflichtet !");
	  }                 
	field[0].focus();
	return false;
	}
	else 
	{
	  return true;
	}
}

function CheckMandatoryCheckBox(field, fieldname, langcode)
  {
	if(!field.checked)
	{
	  if(langcode == "FR")
	  {
		alert(fieldname + " est obligatoire !");
	  }
	  else if(langcode == "NL")
	  {
		alert(fieldname + " is verplicht !");
	  }
	  else if(langcode == "EN")
	  {
		alert(fieldname + " is mandatory !");
	  }
	  else if(langcode == "DE")
	  {
		alert(fieldname + " is verpflichtet !");
	  }                 
	field.focus();
	return false;
	}
	else 
	{
	  return true;
	}
}

function CheckMandatorySelect(field, fieldname, langcode)
{
	checked = false;
	for(i = 0 ;i < field.length ; i++)
	{
	  if(!field[i].value == '')
	  {
		checked |= field[i].selected;
	  }
	}
	if(!checked)
	{
	  if(langcode == "FR")
	  {
		alert(fieldname + " est obligatoire !");
	  }
	  else if(langcode == "NL")
	  {
		alert(fieldname + " is verplicht !");
	  }
	  else if(langcode == "EN")
	  {
		alert(fieldname + " is mandatory !");
	  }
	  else if(langcode == "DE")
	  {
		alert(fieldname + " ist verpflichtet !");
	  }                    
	  field.focus();
	  return false;
	}
	else 
	{
	  return true;
	}
}

function CheckEmail (field, fieldname, langcode) {
  
  emailStr = field.value;

	/* The following pattern is used to check if the entered e-mail address
	   fits the user@domain format.  It also is used to separate the username
	   from the domain. */
	
	var emailPat=/^(.+)@(.+)$/
	
	/* The following string represents the pattern for matching all special
	   characters.  We don't want to allow special characters in the address. 
	   These characters include ( ) < > @ , ; : \ " . [ ]    */
	
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	
	/* The following string represents the range of characters allowed in a 
	   username or domainname.  It really states which chars aren't allowed. */
	
	var validChars="\[^\\s" + specialChars + "\]"
	
	/* The following pattern represents the range of characters allowed as
	   the first character in a valid username or domain.  I just made it
	   the same as above, but if you want to add a different constraint,
	   you would change it here. */
	
	var firstChars=validChars
	
	/* The following pattern applies if the "user" is a quoted string (in
	   which case, there are no rules about which characters are allowed
	   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	   is a legal e-mail address. */
	
	var quotedUser="(\"[^\"]*\")"
	
	/* The following pattern applies for domains that are IP addresses,
	   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	   e-mail address. NOTE: The square brackets are required. */
	
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	
	/* The following string represents at atom (basically a series of
	   non-special characters.) */
	
	var atom="(" + firstChars + validChars + "*" + ")"
	
	/* The following string represents one word in the typical username.
	   For example, in john.doe@somewhere.com, john and doe are words.
	   Basically, a word is either an atom or quoted string. */
	
	var word="(" + atom + "|" + quotedUser + ")"
	
	// The following pattern describes the structure of the user
	
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	
	/* The following pattern describes the structure of a normal symbolic
	   domain, as opposed to ipDomainPat, shown above. */
	
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	
	
	/* Finally, let's start trying to figure out if the supplied address is
	   valid. */
	
	/* Begin with the course pattern to simply break up user@domain into
	   different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
	  /* Too many/few @'s or something; basically, this address doesn't
		 even fit the general mould of a valid e-mail address. */
	   if (langcode == "FR")
		{
		 alert(fieldname + " n'est pas correcte (@, . et un domaine sont obligatoires)")
		}
		else if (langcode == "NL")
		{
		  alert("Het " + fieldname + " is niet correct. Ieder e-mailadres bevat een '@', minstens één '.' en een domeinnaam.")
		}
		else if (langcode == "EN")
		{
		  alert(fieldname + ": address seems incorrect (check @ and .'s)")
		}        
		
		field.focus();
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	
	// See if "user" is valid 
	if (user.match(userPat)==null) {
		// user is not valid
		if (langcode == "FR")
		{
		  alert(fieldname + ": le nom d'utilisateur n'est pas valable.")
		}
		else if (langcode == "NL")
		{
		  alert("De gebruikersnaam in het " + fieldname + " is niet correct.")
		}
		else if (langcode == "EN")
		{
		  alert(fieldname + ": username doesn't seem to be valid.")
		}        
		
		field.focus();
		return false
	}
	/* if the e-mail address is at an IP address (as opposed to a symbolic
	   host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		for (var i=1;i<=4;i++) {
		  if (IPArray[i]>255) {
		if (langcode == "FR")
		{
		  alert(fieldname + ": l'adresse IP n'est pas valable.")
		}
		else if (langcode == "EN")
		{
		  alert(fieldname + ": destination IP address is invalid!")
		}
		else if (langcode == "NL")
		{
		  alert(fieldname + ": IP adres is ongeldig!")
		}        
			  
		field.focus();
		return false
		  }
		}
		return true
	}
	
	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		if (langcode == "FR")
		{
		  alert(fieldname + ": le domaine n'est pas valable.")
		}
		else if (langcode == "EN")
		{
		  alert(fieldname + ": domain name doesn't seem to be valid.")
		}
		else if (langcode == "NL")
		{
		  alert(fieldname + ": domeinnaam is niet geldig.")
		}        
	
		field.focus();
		return false
	}
	/* domain name seems valid, but now make sure that it ends in a
	   three-letter word (like com, edu, gov) or a two-letter word,
	   representing country (uk, nl).
	   If there's a country code at the end of the address, the full domain
	   must include a hostname and category (e.g. host.co.uk or host.pub.nl).
	   If it ends in a .com or something, make sure there's a hostname.*/
	
	/* Now we need to break up the domain to get a count of how many atoms
	   it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>4) {
	   // the address must end in a two letter or three letter word.
		if (langcode == "FR")
		{
		  alert(fieldname + ": le domaine consiste typiquement de 2, 3 ou 4 lettres.")
		}
		else if (langcode == "EN")
		{
		  alert(fieldname + ": address must end in a four- or three-letter domain, or two letter country.")
		}
		else if (langcode == "NL")
		{
		  alert("Het domein van het e-mail adres moet uit 2, 3 of 4 letters bestaan.")
		}        
	
	   field.focus();
	   return false
	}
	
	
	/* If it just ends in .com, .gov, etc., make sure there's a host name.
	   This case can never actually happen because earlier checks take
	   care of this implicitly, but we'll do it anyway. */
	if (domArr[domArr.length-1].length==3 && len<2) {
		if (langcode == "FR")
		{
		  alert(fieldname + ": pas de hostname!")
		}
		else if (langcode == "EN")
		{
		  alert(fieldname + ": This address is missing a hostname!")
		}
		else if (langcode == "NL")
		{
		   alert(fieldname + ": Dit adres mist een hostname!")
		}        
	
	   field.focus();
	   return false
	}
	// If we've gotten this far, everything should be valid!
	return true;
}

function condLength2(theRadioButton1, theRadioButton2, field, fieldname, fieldlength, langcode) {
	if (theRadioButton1.checked && theRadioButton2.checked) {
		if(CheckLength(field, fieldname, fieldlength, langcode)){
			return true;
		} else {
			return false;
		}
	}
	return true;
}
