

function checkRegistrationFormStep1(theFrm,fieldsArray){
	var errors = "";
	for (var i=0; i < theFrm.length; i++) 
	{
		var element = theFrm.elements[i];
		for (var j in fieldsArray) {
			//alert(element.name + ' == ' + fieldsArray[j]);
			if (element.name == fieldsArray[j]){
				
				if (element.className.indexOf("text") == -1){
					var elmname = element.name;
					// Radio Button Validation
					if (element.className.indexOf("check") != -1){
						if(element.name == 'type_registration'){
							if(!btn) {
								errors += "Type d'inscription\n";
							}
						}
					} else {
						var btn = valButton(theFrm.type_registration);		
						if (btn == null) {
							alert("Veuillez remplir les champs suivants:\n- Type d'inscription");
							return false;
						}
					}
					
				} else if(!isFilled(element)){
					alert('Veuillez remplir les champs obligatoires');
					return false;
				}
				
				
			}
		}
	}
	
	var person_type = getCheckedValue(theFrm.type_registration);
	if(person_type == 'company_person'){
		// check if OrganisationID is filled in
		if(!isFilled(theFrm.CompanyNumber)){
			alert('Veuillez remplir le num\u00E9ro d\'entreprise.');		
			return false;
		}
		
		var re = /^[0]\d{3}\.\d{3}\.\d{3}$/; 
		if (re.test(theFrm.CompanyNumber.value)==false) {	
			alert('Veuillez remplir le num\u00E9ro d\'entreprise dans le format 0xxx.xxx.xxx');		
			return false;
		}

		/*
		
		
		if(!IsNumeric2(theFrm.CompanyNumber.value)){
			alert('Het ondernemersnummer van uw bedrijf moet numeriek zijn.');		
			return false;
		}*/
	}	
	
	if(errors != ""){
		alert("Veuillez remplir les champs suivants:\n"+errors);	
	} else {
		theFrm.submit();
	}
}

function checkRegistrationFormStep2(theFrm,fieldsArray){
	var errors = "";
	var error1 = false;
	var error2 = false;
	var error3 = false;
	for (var i=0; i < theFrm.length; i++) 
	{
		var element = theFrm.elements[i];
		for (var j in fieldsArray) {
			//alert(element.name + ' == ' + fieldsArray[j]);
			if (element.name == fieldsArray[j]){
				
				if (element.className.indexOf("text") == -1){
					var elmname = element.name;
					//alert(elmname);
					switch(elmname){
						case "OrganisationMemberArcopar":	var btn = valButton(theFrm.OrganisationMemberArcopar);		
															if (btn == null) {
																//errors += "- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: Arcopar lid\n";
																//alert("Volgende verplichte velden werden niet ingevuld:\n- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: Arcopar lid");
																if(error1 == false){
																	error1 = true;
																	errors += "- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: membre Arcopar\n";
																}
																//return false;
															}
															break;
						case "OrganisationMemberACW_MOW":	var btn = valButton(theFrm.OrganisationMemberACW_MOW);	
															if (btn == null) {
																//errors += "- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: ACW-MOW lid\n";
																if(error2 == false){
																	error2 = true;
																	errors += "- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: membre ACW-MOW\n";
																}
																//alert("Volgende verplichte velden werden niet ingevuld:\n- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: ACW-MOW lid");
																//return false;
															}
															break;
						case "OrganisationMemberSociare	":
						case 'OrganisationMemberSociare':	var btn = valButton(theFrm.OrganisationMemberSociare);	
															if (btn == null) {
																//errors += "- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: Sociare lid\n";
																if(error3 == false){
																	error3 = true;
																	errors += "- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: membre Sociare\n";
																}
																//alert("Volgende verplichte velden werden niet ingevuld:\n- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: Sociare lid");
																//return false;
															}
															break;
						//default:	alert('name again: '+elmname);									
					}					
					
					
				} else if(!isFilled(element)){
					switch(element.name) {
						case 'OrganisationName':				errors += "- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: nom d'entreprise\n";
																break;
						case 'OrganisationAddress':				errors += "- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: adresse\n";
																break;	
						case 'OrganisationZipCode':				errors += "- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: code postal\n";
																break;	
						case 'OrganisationCity':				errors += "- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: localit\u00E9\n";
																break;	
						case 'OrganisationCountry':				errors += "- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: pays\n";
																break;	
						case 'OrganisationEmail':				errors += "- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: adresse e-mail\n";
																break;	
						case 'OrganisationTelephone':			errors += "- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: num\u00E9ro de t\u00E9l\u00E9phone\n";
																break;	
						case 'OrganisationFax':					errors += "- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: num\u00E9ro de fax\n";
																break;	
						case 'OrganisationVATNumber':			errors += "- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: num\u00E9ro TVA\n";
																break;	
						case 'OrganisationCompanyNumber':		errors += "- Donn\u00E9es g\u00E9n\u00E9rales d'entreprise: num\u00E9ro d'enntreprise\n";
																break;	
																						
						case 'OrganisationContactTitle':		errors += "- Coordonn\u00E9es: titre\n";
																break;
						case 'OrganisationContactFirstName':	errors += "- Coordonn\u00E9es: pr\u00E9nom\n";
																break;
						case 'OrganisationContactName':			errors += "- Coordonn\u00E9es: nom\n";
																break;
						case 'OrganisationContactFunction':		errors += "- Coordonn\u00E9es: fonction\n";
																break;
						case 'OrganisationContactEmail':		errors += "- Coordonn\u00E9es: adresse e-mail\n";
																break;
						case 'OrganisationContactMobilePhone':	errors += "- Coordonn\u00E9es: gsm\n";
																break;
						case 'OrganisationContactTelephone':	errors += "- Coordonn\u00E9es: num\u00E9ro de t\u00E9l\u00E9phone\n";
																break;
						case 'OrganisationContactFax':			errors += "- Coordonn\u00E9es: num\u00E9ro de fax\n";
																break;
						case 'OrganisationFacturationName':		errors += "- Donn\u00E9es de facturation: nom\n";
																break;
						case 'OrganisationFacturationAddress':	errors += "- Donn\u00E9es de facturation: adresse\n";
																break;
						case 'OrganisationFacturationZipCode':	errors += "- Donn\u00E9es de facturation: code postal\n";
																break;
						case 'OrganisationFacturationCity':		errors += "- Donn\u00E9es de facturation: localit\u00E9\n";
																break;
						case 'OrganisationFacturationCountry':	errors += "- Donn\u00E9es de facturation: pays\n";
																break;
						case 'OrganisationShippingName':		errors += "- Donn\u00E9es de livraison: nom\n";
																break;
						case 'OrganisationShippingAddress':		errors += "- Donn\u00E9es de livraison: adresse\n";
																break;
						case 'OrganisationShippingZipCode':		errors += "- Donn\u00E9es de livraison: code postal\n";
																break;
						case 'OrganisationShippingCity':		errors += "- Donn\u00E9es de livraison: localit\u00E9\n";
																break;
						case 'OrganisationShippingCountry':		errors += "- Donn\u00E9es de livraison: pays\n";
																break;	
				
						default:								alert('Veuillez remplir les champs obligatoires');
																return false;
					}
				} else {
					if(element.name == 'OrganisationContactEmail'){
						hasDot = theFrm.OrganisationContactEmail.value.indexOf(".");
						hasAt = theFrm.OrganisationContactEmail.value.indexOf("@");
						
						if (hasDot == -1 || hasAt == -1)
						{
							alert("L'adresse e-mail n'est pas valable.");
							theFrm.OrganisationContactEmail.focus();
							theFrm.OrganisationContactEmail.select();
							return false;
						}
					}
					if(element.name == 'OrganisationEmail'){
						hasDot = theFrm.OrganisationEmail.value.indexOf(".");
						hasAt = theFrm.OrganisationEmail.value.indexOf("@");
						
						if (hasDot == -1 || hasAt == -1)
						{
							alert("L'adresse e-mail n'est pas valable.");
							theFrm.OrganisationEmail.focus();
							theFrm.OrganisationEmail.select();
							return false;
						}
					}
				}
			}
		}
	}
	
	if(errors != ""){
		alert("Veuillez remplir les champs suivants:\n"+errors);	
	} else {
		theFrm.submit();
	}
}

function checkRegistrationFormStep3(theFrm,fieldsArray){
	var errors = "";
	for (var i=0; i < theFrm.length; i++) 
	{
		var element = theFrm.elements[i];
		for (var j in fieldsArray) {
			//alert(element.name + ' == ' + fieldsArray[j]);
			if (element.name == fieldsArray[j]){
				
				if(!isFilled(element)){
					switch(element.name) {						
						case 'ClientTitle':			errors += "- titre\n";
													break;
						case 'ClientFirstName':		errors += "- pr\u00E9nom\n";
													break;
						case 'ClientName':			errors += "- nom\n";
													break;
						case 'ClientFunction':		errors += "- fonction\n";
													break;
						case 'ClientEmail':			errors += "- e-mail\n";
													break;
						case 'ClientMobilePhone':	errors += "- gsm\n";
													break;
						case 'ClientTelephone':		errors += "- t\u00E9l\u00E9phone\n";
													break;
						case 'ClientFax':			errors += "- fax\n";
													break;
						case 'ClientAddress':		errors += "- adresse\n";
													break;
						case 'ClientZipCode':		errors += "- code postal\n";
													break;
						case 'ClientCity':			errors += "- localit\u00E9\n";
													break;
						case 'ClientCountry':		errors += "- pays\n";
													break;		
						default:					alert('Veuillez remplir les champs obligatoires');
													return false;
					}
				} else {
					if(element.name == 'ClientEmail'){
						hasDot = theFrm.ClientEmail.value.indexOf(".");
						hasAt = theFrm.ClientEmail.value.indexOf("@");
						
						if (hasDot == -1 || hasAt == -1)
						{
							alert("L'adresse e-mail n'est pas valable.");
							theFrm.ClientEmail.focus();
							theFrm.ClientEmail.select();
							return false;
						}
					}
				}
			}
		}
	}
	
	if(errors != ""){
		alert("Veuillez remplir les champs suivants:\n"+errors);	
	} else {
		theFrm.submit();
	}
}



var requiredfields=new Array("");

function isFilled(field)
{
	if (field.value.length < 1)	{
		return false;
	} else {
		return true;
	}
}

function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function copyCompanyAddressToFacturationAddress(theFrm){
	theFrm.OrganisationFacturationName.value = theFrm.OrganisationName.value;
	theFrm.OrganisationFacturationAddress.value = theFrm.OrganisationAddress.value;
	theFrm.OrganisationFacturationZipCode.value = theFrm.OrganisationZipCode.value;
	theFrm.OrganisationFacturationCity.value = theFrm.OrganisationCity.value;
	theFrm.OrganisationFacturationCountry.value = theFrm.OrganisationCountry.value;
	
}
									
function copyCompanyFacturationAddressToShippingAddress(theFrm){
	theFrm.OrganisationShippingName.value = theFrm.OrganisationFacturationName.value;
	theFrm.OrganisationShippingAddress.value = theFrm.OrganisationFacturationAddress.value;
	theFrm.OrganisationShippingZipCode.value = theFrm.OrganisationFacturationZipCode.value;
	theFrm.OrganisationShippingCity.value = theFrm.OrganisationFacturationCity.value;
	theFrm.OrganisationShippingCountry.value = theFrm.OrganisationFacturationCountry.value;
}

function isNumber(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function IsNumeric2(strString){
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;
   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++){
      strChar = strString.charAt(i);
	  if (strValidChars.indexOf(strChar) == -1)  blnResult = false;
         
   }
   return blnResult;
}