
/**************************************************************************************************
* Function :	fieldValidation
* Description :	Check if the field is fill
* Parameter :	name : The string to validate, name of the field
***************************************************************************************************/
function fieldValidation(field, name){	
	if(field==null || field==""){
		alert("Le champ "+ name + " ne peut ętre vide");
		return false;
	}else{
/*
		for(i=0; i < field.length; i++){
			if(field.charAt(i)=="<"||field.charAt(i)==">"){
				alert("Le champ "+ name +" does not accept character '<' or '>'." );
				return false;
			}
		}
		for(i=0; i < field.length; i++){
			if(field.charAt(i)=="'"||field.charAt(i)=='"'){
				alert("The "+ name +" does not accept character (')or('')." );
				return false;
			}
		}
*/
	}
	//alert(name + " fieldValidation true");
	return true;
}
/**************************************************************************************************
* Function :	emailValidation
* Description :	Check if the field is fill
* Parameter :	name : The number to validate and name of the field
***************************************************************************************************/
function emailValidation(x){	
	var caracterevalide="abcdefghijklmnopqrstuvwxyz1234567890._@";
	var acommercial=x.indexOf("@");
	var point=x.lastIndexOf(".");
	var acommavantpoint=point-acommercial;
	var checkchar;
	var checkcharbool=true;
	var erreur=false;
	for (var i=0; i<=x.length; i++){
		checkchar=caracterevalide.indexOf(x.charAt(i));
		if (checkchar==-1){
			checkcharbool=false;
		}
	}
	if (checkcharbool==false){
		erreur=true;
	}	
	if (acommercial==-1){
		erreur=true;
	}
	if (point==-1){
		erreur=true;
	}
	if (acommavantpoint<0){
		erreur=true;
	}
	if (erreur==false){
		return true;
	}else{
		alert("L'adresse couriel n'est pas valide");
		return false;
	}
}
/**************************************************************************************************
* Function :	nbValidation
* Description :	Check if the field is fill
* Parameter :	name : The number to validate and name of the field
***************************************************************************************************/
function ndValidation(nb, name){	
	if(isNaN(nb)){
		alert(name + " need to be a number");
		return false;
	}
	//alert(name + " nbValidation true");
	return true;
}
/**************************************************************************************************
* Function :	nbMinMaxValidation
* Description :	Check if the field is fill
* Parameter :	name : The number to validate, min, max,  name of the field
***************************************************************************************************/
function nbMinMaxValidation(nb, min, max, name){	
	if(fieldValidation(nb, name)){
		if(ndValidation(nb, name)){
			var checkNumber=parseInt(nb);
			if(checkNumber<=max&&checkNumber>=min){
				//alert(name + " nbMinMaxValidation true");
				return true;
			}else{
				alert(name + " you entered is out of range("+min+" to "+max+")");		
			}
		}
	}
	return false;
}
/**************************************************************************************************
* Function :	isInteger
* Description :	Check if the number is interger
* Parameter :	the number
***************************************************************************************************/
function isInteger(field, name) {
	for (var i=0; i < field.length; i++) {
		if (field.charAt(i)==".") {
			alert(name + " need to be a integer number");
			return false; 
		}
	}
	return true;
}
/**************************************************************************************************
* Function :	Trim functions
* Description :	Returns string with whitespace trimmed
* Parameter :	The string to validate
***************************************************************************************************/
function lTrim(str) {
	for (var i=0; str.charAt(i)==" "; i++);
		return str.substring(i,str.length);
}
function rTrim(str) {
	for (var i=str.length-1; str.charAt(i)==" "; i--);
		return str.substring(0,i+1);
}
function trim(str) {
	return lTrim(rTrim(str));
}
/**************************************************************************************************
* Function :	Trim functions
* Description :	Returns string with whitespace trimmed
* Parameter :	The string to validate
***************************************************************************************************/
function sendMSG(){
	if(confirm('\nĘtes vous sűr de vouloir envoyer ce message?')){
		var sujet = document.form1.topic.value = trim(document.form1.topic.value);
		var nom = document.form1.name.value = trim(document.form1.name.value);
		var couriel = document.form1.email.value = trim(document.form1.email.value);
		var msg = document.form1.msg.value = trim(document.form1.msg.value);
		if(fieldValidation(sujet,"sujet")){
//			if(fieldValidation(nom,"nom")){		
//				if(emailValidation(couriel)){		
					if(fieldValidation(msg,"message")){	
						document.form1.submit();
					}
//				}
//			}
		}
	}
}
/**************************************************************************************************
* Function :	sendQuestion functions
* Description :	Returns string with whitespace trimmed
* Parameter :	The string to validate
***************************************************************************************************/
function sendQuestion(){
	if(confirm('\nĘtes vous sűr de vouloir envoyer cette Question?')){
		var question = document.form1.question.value = trim(document.form1.question.value);
		if(fieldValidation(question,"question")){	
			document.form1.submit();
		}
	}
}

