/*these two scripts run when the user mouses out of an input area*/

function verifiermail(mail) {
      if ((mail.indexOf("@")>=0)&&(mail.indexOf(".")>=0)) {
         return true 
      } else {
        
         return false
      }
   }



function getLabelForId(id) {
 var label, labels = document.getElementsByTagName('label');
 for (var i = 0; (label = labels[i]); i++) {
   if (label.htmlFor == id) {
     return label;
   }
 }
 return false;
}
function checkRequired(id) {
 var formfield = document.getElementById(id);
 var label = getLabelForId(id);
 blurDown(id);
 if (formfield.value.length == 0) {
    label.className = 'problem';
 }  else {
    label.className = 'completed';
 }
}
function checkRequiredSelect(id) {
	var formfield = document.getElementById(id);
	var label = getLabelForId(id);
	if (formfield.options[0].selected == true){
 	label.className = 'problem';
 	} else{
		label.className = 'completed';
		}
}

/*this 2 functions set the border style of the input area on the form for fields OFF/ON position*/
function blurDown(id){
	var formfield = document.getElementById(id);
	formfield.className = 'inputoff';
	}
function blurUp(id){
	var formfield = document.getElementById(id);
	formfield.className = 'inputon';
	}

/*  */
/*validation script - on submit button*/
function validate_fields(form)
{
	if ( form.nom.value == "" ) {
		alert("Entrez votre nom svp.");
		form.nom.focus();
		return false; }

	if ( form.prenom.value == "" ) {
		alert("Entrez votre prénom svp.");
		form.prenom.focus();
		return false; }

	if ( form.fonction.value == "" ) {
		alert("Entrez votre fonction svp.");
		form.fonction.focus();
		return false; }

	if ( form.email.value == "" ) {
		alert("Entrez votre email svp.");
		form.email.focus();
		return false; }
		
	if ( verifiermail(form.email.value) == false ) {
		alert("Entrez un email valide svp.");
		form.email.focus();
		return false; }

	if ( form.tel.value == "" ) {
		alert("Entrez votre numéro de téléphone svp.");
		form.tel.focus();
		return false; }

	if ( form.adresse1.value == "" ) {
		alert("Entrez votre adresse svp.");
		form.adresse1.focus();
		return false; }

    if ( form.ville.value == "" ) {
		alert("Entrez votre ville svp.");
		form.ville.focus();
		return false; }



	if ( form.cp.value == "" ) {
		alert("Entrez votre code postal svp.");
		form.cp.focus();
		return false; }



	if ( form.societe.value == "" ) {
		alert("Entrez le nom de votre société svp.");
		form.societe.focus();
	    return false; }
		
	if ( form.customer.value == "" ) {
		alert("Remplissez le champ utilisateur svp.");
		form.customer.focus();
		return false; }
		
	if ( form.news_UGS.value == "" ) {
		alert("Précisez si vous souhaitez recvoir des informations de la part d'UGS svp.");
		form.news_UGS.focus();
		return false; }

	return true;
}