$(document).ready(function() {

var msgError = '';

var arrEmptyFields = new Array();

arrEmptyFields['firstname_spec'] = 0;
arrEmptyFields['lastname_spec'] = 0;
arrEmptyFields['position_spec'] = 0;
arrEmptyFields['company_spec'] = 0;
arrEmptyFields['country_spec'] = 0;
arrEmptyFields['email_spec'] = 0;

function checkInputText(idParam, titleParam){
	
	var text = $('#'+idParam).val();
	
	if(text == ''){
		$('#msg-' + idParam).slideDown('normal');
		$('#' + idParam).addClass('error');
		msgError = msgError +  ' - The field "' + titleParam +'" is wrong.\n';
		arrEmptyFields[idParam] = 1;
	}
	else {
		$('#msg-' + idParam).slideUp('fast');
		$('#' + idParam).removeClass('error');
		arrEmptyFields[idParam] = 0;
	}
}

function checkInputMail(idParam, titleParam){
	
	var text = $('#'+idParam).val();
	var regex = /^[a-zA-Z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$/;
	
	if(!text.match(regex)){
		$('#msg-' + idParam).slideDown('normal');
		$('#' + idParam).addClass('error');
		msgError = msgError +  ' - The field "' + titleParam +'" is wrong.\n';
		arrEmptyFields[idParam] = 1;
	}
	else if(text == ''){
		$('#msg-' + idParam).slideDown('normal');
		$('#' + idParam).addClass('error');
		msgError = msgError +  ' - The field "' + titleParam +'" is wrong.\n';
		arrEmptyFields[idParam] = 1;
	}
	else {
		$('#msg-' + idParam).slideUp('fast');
		$('#' + param).removeClass('error');
		arrEmptyFields[idParam] = 0;
	}
}

// Appel de la fonction en blur
	$('#firstname_spec').blur(function() {
		checkInputText('firstname_spec');
	});
	$('#lastname_spec').blur(function() {
		checkInputText('lastname_spec');
	});
	$('#position_spec').blur(function() {
		checkInputText('position_spec');
	});
	$('#company_spec').blur(function() {
		checkInputText('company_spec');
	});
	$('#country_spec').blur(function() {
		checkInputText('country_spec');
	});
	$('#email_spec').blur(function() {
		checkInputMail('email_spec');
	});
		
// Fin de la fonction en blur

// Debut de la fonction pour verif le form
	$('#spect_form').submit(function() {
		
		msgError = '';
		
		checkInputText('firstname_spec','PRENOM / FIRST NAME');
		checkInputText('lastname_spec','NOM / LAST NAME');
		checkInputText('position_spec','POSTE / POSITION');
		checkInputText('company_spec','COMPAGNIE/ COMPANY');
		checkInputText('country_spec','PAYS / COUNTRY');
		checkInputText('email_spec','EMAIL');

		if (arrEmptyFields['firstname_spec'] == 0 && arrEmptyFields['lastname_spec'] == 0 && arrEmptyFields['position_spec'] == 0 && arrEmptyFields['company_spec'] == 0 && arrEmptyFields['country_spec'] == 0 && arrEmptyFields['email_spec'] == 0){
			alert('Your registration has been completed.\n An email will be sent you to confirm.');
			return true;
		}
		else {
			alert(msgError);
			return false;
		}
	});

});
