// JavaScript Document
function eraseval(obj, val)
{
	if(obj.value == val)
		obj.value = '';
	else
		obj.style.color = '#999999';
}
function restoreval(obj, val)
{
	if(obj.value == '')
		obj.value = val;
	else
		obj.style.color = '#000000';
}

// FONCTIONS
function verif_oblig(input, defaut)
{
	if(document.getElementById(input).value == '' || document.getElementById(input).value == defaut)
	{
		document.getElementById(input).style.color = '#FF0000';
		return 1;
	} else {
		document.getElementById(input).style.color = '#000000';
	}
}
function verif_cp(input)
{
	if(document.getElementById(input).value != '')
	{
		var reg_cp = /^\d{5}$/;
		if(reg_cp.test(document.getElementById(input).value))
			document.getElementById(input).style.color = '#000000';
		else
		{
			document.getElementById(input).style.color = '#FF0000';
			alert('Code postal incorrect !');
			return false;
		}
	}
}
function verif_tel(input)
{
	if(document.getElementById(input).value != '')
	{
		var tel = document.getElementById(input).value;
		tel = tel.replace(/ /g,"");
		tel = tel.replace(/\-/g,"");
		tel = tel.replace(/\./g,"");
		var reg_tel = /^\d{10}$/;
		if(reg_tel.test(tel))
			document.getElementById(input).style.color = '#000000';
		else
		{
			document.getElementById(input).style.color = '#FF0000';
			alert('Numéro de téléphone incorrect !');
			return false;
		}
	}
}
function verif_mail(input)
{
	if(document.getElementById(input).value != '')
	{
		var mail = document.getElementById(input).value;
		mail = mail.replace(/ /g,"");
		var reg_mail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
		if(reg_mail.test(mail))
			document.getElementById(input).style.color = '#000000';
		else
		{
			document.getElementById(input).style.color = '#FF0000';
			alert('Adresse mail incorrect !');
			return false;
		}
	}
}
function verif_date(input)
{
	if(document.getElementById(input).value != '')
	{
		var date = document.getElementById(input).value;
		var reg_date = RegExp("^[0-9]{2}[/]{1}[0-9]{2}[/]{1}[0-9]{4}$","g");
		if(reg_date.test(date))
			document.getElementById(input).style.color = '#000000';
		else
		{
			document.getElementById(input).style.color = '#FF0000';
			alert('Date invalide !');
			return false;
		}
	}
}
function verif_float(input)
{
	if(document.getElementById(input).value != '')
	{
		var valeur = document.getElementById(input).value;
		valeur = valeur.replace(',','.');
		if(isNaN(valeur))
		{
			document.getElementById(input).style.color = '#FF0000';
			alert('Doit-être un nombre !');
			return false;
		}
		else
			document.getElementById(input).style.color = '#000000';
	}
}

// VERIF CHAMPS
function envoi_infos()
{
	//Champs obligatoires
	var zeroun = 0;
	zeroun = verif_oblig('Infos_Formation','');
	zeroun = verif_oblig('Infos_Nom','Nom');
	zeroun = verif_oblig('Infos_Prenom','Prénom');
	zeroun = verif_oblig('Infos_Adresse','Adresse');
	zeroun = verif_oblig('Infos_CP','Code Postal');
	zeroun = verif_oblig('Infos_Ville','Ville');
	zeroun = verif_oblig('Infos_Tel','Téléphone');
	zeroun = verif_oblig('Infos_Mail','Mail');
	zeroun = verif_oblig('Infos_Situation','');
	zeroun = verif_oblig('Infos_Financement','');
	
	if(zeroun == 1)
	{
		alert('Veuillez remplir tous les champs obligatoires !');
		return false;
	}
	
	//Différents tests
	if(verif_cp('Infos_CP') == false) return false;
	if(verif_tel('Infos_Tel') == false) return false;
	if(verif_tel('Infos_Tel2') == false) return false;
	if(verif_mail('Infos_Mail') == false) return false;

	//Si tous les tests sont OK
	return true;
}

function envoi_insc()
{
	//Champs obligatoires
	var zeroun = 0;
	zeroun = verif_oblig('Insc_Nom','Nom');
	zeroun = verif_oblig('Insc_Prenom','Prénom');
	zeroun = verif_oblig('Insc_Adresse','Adresse');
	zeroun = verif_oblig('Insc_CP','00000');
	zeroun = verif_oblig('Insc_Ville','Ville');
	zeroun = verif_oblig('Insc_Tel','00 00 00 00 00');
	zeroun = verif_oblig('Insc_Mail','mail@domaine.fr');
	zeroun = verif_oblig('Insc_DateNaissance','jj/mm/aaaa');
	zeroun = verif_oblig('Insc_LieuNaissance','Ville');
	zeroun = verif_oblig('Insc_Login','Login');
	zeroun = verif_oblig('Insc_Pass','Mot de passe');
	
	if(zeroun == 1)
	{
		alert('Veuillez remplir tous les champs obligatoires !');
		return false;
	}
	
	//Différents tests
	if(verif_date('Insc_DateNaissance') == false) return false;
	if(verif_cp('Insc_CP') == false) return false;
	if(verif_tel('Insc_Tel') == false) return false;
	if(verif_tel('Insc_Tel2') == false) return false;
	if(verif_mail('Insc_Mail') == false) return false;

	//Si tous les tests sont OK
	return true;
}

function envoi_insc2()
{
	//Champs obligatoires
	var zeroun = 0;
	zeroun = verif_oblig('ID_Statut','');
	zeroun = verif_oblig('ID_Mobilite','');
	zeroun = verif_oblig('Insc_AutresCentres','');
	zeroun = verif_oblig('Insc_DirectStagiaires','');
	zeroun = verif_oblig('Insc_Vehicule','');
	zeroun = verif_oblig('Insc_Pretention','euros brut');
	zeroun = verif_oblig('Insc_Xp','an(s)');
	
	if(zeroun == 1)
	{
		alert('Veuillez remplir tous les champs obligatoires !');
		return false;
	}
	
	//Différents tests
	if(verif_float('Insc_Pretention') == false) return false;
	if(verif_float('Insc_Xp') == false) return false;

	//Si tous les tests sont OK
	return true;
}

function verif_commercial()
{
	//Champs obligatoires
	var zeroun = 0;
	zeroun = verif_oblig('Recrute_Nom','Nom');
	zeroun = verif_oblig('Recrute_Prenom','Prénom');
	zeroun = verif_oblig('Recrute_Adresse','Adresse');
	zeroun = verif_oblig('Recrute_CP','Code Postal');
	zeroun = verif_oblig('Recrute_Ville','Ville');
	zeroun = verif_oblig('Recrute_Tel','Téléphone');
	zeroun = verif_oblig('Recrute_Mail','Mail');
	zeroun = verif_oblig('Recrute_Situation','');
	zeroun = verif_oblig('Recrute_Departements','Mes départements (ex : 33,64,16...)');
	
	if(zeroun == 1)
	{
		alert('Veuillez remplir tous les champs obligatoires !');
		return false;
	}
	
	//Différents tests
	if(verif_cp('Recrute_CP') == false) return false;
	if(verif_tel('Recrute_Tel') == false) return false;
	if(verif_mail('Recrute_Mail') == false) return false;
	
	if(document.getElementById('Recrute_Situation').value == 'Autre')
	{
		if(document.getElementById('Recrute_Commentaire').value == 'Commentaire')
		{
			alert('Veuillez nous préciser dans le champ \'Commentaire\' votre situation actuelle !');
			return false;
		} else {
			return confirm('Avez-vous pensez à nous préciser votre situation actuelle dans le champ \'Commentaire\' ?');
		}
	}

	//Si tous les tests sont OK
	return true;
}


// VERIF CHAMPS
function envoi_camp()
{
	//Champs obligatoires
	var zeroun = 0;
	zeroun = verif_oblig('Camp_Societe','Société');
	zeroun = verif_oblig('Camp_Contact','Contact');
	zeroun = verif_oblig('Camp_Tel','00 00 00 00 00');
	zeroun = verif_oblig('Camp_Mail','mail@domaine.ext');
	zeroun = verif_oblig('Camp_Message','Message');
	
	if(zeroun == 1)
	{
		alert('Veuillez remplir tous les champs obligatoires !');
		return false;
	}
	
	if(verif_tel('Camp_Tel') == false) return false;
	if(verif_mail('Camp_Mail') == false) return false;

	if(document.getElementById('Camp_CP').value != '00000' || document.getElementById('Camp_CP').value != '')
	{
		if(verif_cp('Camp_CP') == false) return false;
	}
		
	//Si tous les tests sont OK
	return true;
}
