function isString(aValue, iSizeMin, iSizeMax, iNullAllowed)
{
	//get length of string
	iLength = aValue.length;
	//check if null
	if (iLength == 0 && iNullAllowed == 1)
		return true;
	if ( iLength < iSizeMin || iLength > iSizeMax)
		return false;
	return true;
}

function isEmail(aValue, iNullAllowed){

	//get length of string
	iLength = aValue.length;
	//check if null
	if (iLength == 0 && iNullAllowed == 1)
		return true; 
	re = /^[a-zA-Z0-9_.\-]+\@[a-zA-Z0-9_.\-]+\.[a-zA-Z0-9_\-]+$/;
	iSearch = re.exec(aValue);
	if (iSearch == null)
		return false;
		return true;
}


function IsAlphaNumericOblig(aValue,iSize){

	iLength = aValue.length;
	re = /^[^a-zA-Z\_]/;
	iSearch = re.exec(aValue);
	if (iSearch == null || iLength<iSize)
		return true;
	return false;
}

function IsAlphaNumeric(aValue,iSize){

	iLength = aValue.length;
	re = /[^a-zA-Z\_]/;
	iSearch = re.exec(aValue);
	if(iSearch == null)
		return false
		
	if (iLength!=iSize)
		return true;
	return false;
}

function Unselect(ivar){
	if(ivar == 1) {
	   document.form1.AchatInternet[1].checked = false ;
	}
	if(ivar == 0){
	   document.form1.AchatInternet[0].checked = false ;
	}
}

function ValidInsertion(){

	var errormsg = "";
	var errors = 0;
	var test = "Veuillez remplir correctement le champs : ";
	var cpt;
	
	if (isString(document.form1.nom.value, 2, 255, 0) == 0)
	{
		document.form1.nom.className = "erreur";
		if (cpt != 1){
			test = test + " Nom";
		
		}
		errors=1;
		document.form1.nom.focus();
		cpt = 1;
	}

	if (isString(document.form1.prenom.value, 2, 255, 0) == 0){

		document.form1.prenom.className = "erreur";
		if (cpt != 1){
			test = test + "  Prénom";
		}
		errors=1;
		document.form1.prenom.focus();
		cpt = 1;
	}
	
	if (isString(document.form1.societe.value, 2, 255, 0) == 0)
	{
		document.form1.societe.className = "erreur";
		if (cpt != 1){
			test = test + " Societe";
		
		}
		errors=1;
		document.form1.societe.focus();
		cpt = 1;
	}


	if (isEmail(document.form1.mail.value, 0) == 0){

		document.form1.mail.className = "erreur";
		if (cpt != 1){
			test = test + " Votre email";
		}
		errors=1;
		document.form1.mail.focus();
		cpt = 1;
	}

	if (isString(document.form1.adresse.value, 2, 255, 1) == 0){

		document.form1.adresse.className = "erreur";
		if (cpt != 1){
			test = test + " Adresse ";
		}
		errors=1;
		document.form1.adresse.focus();
		cpt = 1;
	}
	
	
	if(document.form1.postal.value != ""){
	iValue = document.form1.postal.value;
	iLength = iValue.length;
	
	if(isNaN(iValue) || iLength != 5){
	    document.form1.postal.className= "erreur";
		if (cpt != 1){
		               test = test + " Code Postal";
		}
	    errors=1;
		  document.form1.postal.focus();
		  cpt = 1;
	 }
   }								   
	
	
	if (isString(document.form1.ville.value, 2, 255, 1) == 0){

		document.form1.ville.className = "erreur";
		if (cpt != 1){
			test = test + " Ville";
		}
		errors=1;
		document.form1.ville.focus();
		cpt = 1;
	}


	if(document.form1.tel.value != ""){
		iValue = document.form1.tel.value;
		iLength = iValue.length;
	
		if(isNaN(iValue) || iLength != 10){
	    	document.form1.tel.className= "erreur";
			if (cpt != 1){
		       test = test + " Telephone";
			}
	    	errors=1;
		  	document.form1.tel.focus();
		  	cpt = 1;
	 	}
   	}	

	if(document.form1.fax.value != ""){
		iValue = document.form1.fax.value;
		iLength = iValue.length;
	
		if(isNaN(iValue) || iLength != 10){
	    	document.form1.fax.className= "erreur";
			if (cpt != 1){
		       test = test + " fax";
			}
	    	errors=1;
		  	document.form1.fax.focus();
		  	cpt = 1;
	 	}
   	}	

	
	var IsChecked = 0;

	for(i = 1; i < 16 ; i++){
	   ivar ="Check_" + i;
	   ivar2 = "document.form1."+ivar+".checked";
	   if(eval(ivar2) == false ) {
		  IsChecked += 1;
	   }
	}
	if(IsChecked == 15 ){
	    if(cpt != 1){
		   test = test + "Vos besoins ? ";
		}
		errors=1;
		cpt=1;
	 }
					
	

	if (errors == 0)
	{
		document.form1.submit();
	}
	else
	{
		alert(test);
		return;
	}											
}
