function verifier_adresse_email(email){
	var verif = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,4}$/
	if (verif.exec(email) == null){return false;}
	else{return true;}
} 

function verifier_jour(jour){
	if (isNaN(parseInt(jour,10))||(!(jour.length==2))||(!(parseInt(jour,10)>=1))||(!(parseInt(jour,10)<=31))){return false;}
	else{return true;}
}

function verifier_mois(mois){
	if (isNaN(parseInt(mois,10))||(!(mois.length==2))||(!(parseInt(mois,10)>=1))||(!(parseInt(mois,10)<=12))){return false;}
	else{return true;}
}

function verifier_annee(annee){
	var date = new Date();
	if (isNaN(parseInt(annee,10))||(!(annee.length==4))||(!(parseInt(annee,10)>=1900))||(!(parseInt(annee,10)<date.getFullYear()))){return false;}
	else{return true;}
}

function verifier_annee2(annee){
	var date = new Date();
	if (isNaN(parseInt(annee,10))||(!(annee.length==4))||(!(parseInt(annee,10)>=1900))){return false;}
	else{return true;}
}

function champ(input,div){
	if (document.getElementById(input).value != "") {
		document.getElementById(div).innerHTML = "OK";
		document.getElementById(div).style.color = "#40b400";
		document.getElementById(input).style.color = "";
		return true;
	}
	else {
		document.getElementById(div).innerHTML = "";
		return true;
	}
}

function champ_test(input,div,test){
if (test){
	if (document.getElementById(input).value != "") {
		document.getElementById(div).innerHTML = "OK";
		document.getElementById(div).style.color = "#40b400";
		document.getElementById(input).style.color = "";
		return true;
	}
	else {
		document.getElementById(div).innerHTML = "";
		return true;
	}
}
else {
	document.getElementById(div).innerHTML = "X";
	document.getElementById(div).style.color = "#c00000";
	document.getElementById(input).style.color = "#c00000";
	return false;
}
}

function champ_liste(input,div){
	if (document.getElementById(input).value != -1) {
		document.getElementById(div).innerHTML = "OK";
		document.getElementById(div).style.color = "#40b400";
		document.getElementById(input).style.color = "";
		return true;
	}
	else {
		document.getElementById(div).innerHTML = "";
		return true;
	}
}

function champ_obligatoire(input,div,test){
if (test){
	if (document.getElementById(input).value == ""){
		document.getElementById(div).innerHTML = "X";
		document.getElementById(div).style.color = "#c00000";
		document.getElementById(input).style.color = "#c00000";
		return false;
	}
	else {
		document.getElementById(div).innerHTML = "OK";
		document.getElementById(div).style.color = "#40b400";
		document.getElementById(input).style.color = "";
		return true;
	}
}
else {
	document.getElementById(div).innerHTML = "X";
	document.getElementById(div).style.color = "#c00000";
	document.getElementById(input).style.color = "#c00000";
	return false;
}
}

function champ_obligatoire_modele(input,div,test,modele){
if (test){
	if (document.getElementById(input).value == "" || document.getElementById(input).value == modele){
		document.getElementById(div).innerHTML = "X";
		document.getElementById(div).style.color = "#c00000";
		document.getElementById(input).style.color = "#c00000";
		document.getElementById(input).value = modele;
		return false;
	}
	else {
		document.getElementById(div).innerHTML = "OK";
		document.getElementById(div).style.color = "#40b400";
		document.getElementById(input).style.color = "";
		return true;
	}
}
else {
	document.getElementById(div).innerHTML = "X";
	document.getElementById(div).style.color = "#c00000";
	document.getElementById(input).style.color = "#c00000";
	return false;
}
}

function champ_obligatoire_liste(input,div,test){
if (test){
	if (document.getElementById(input).value == -1){
		document.getElementById(div).innerHTML = "X";
		document.getElementById(div).style.color = "#c00000";
		document.getElementById(input).style.color = "#c00000";
		return false;
	}
	else {
		document.getElementById(div).innerHTML = "OK";
		document.getElementById(div).style.color = "#40b400";
		document.getElementById(input).style.color = "";
		return true;
	}
}
else {
	document.getElementById(div).innerHTML = "X";
	document.getElementById(div).style.color = "#c00000";
	document.getElementById(input).style.color = "#c00000";
	return false;
}
}

function champ_obligatoire_liste_programme_baip(input_programme,input_baip,div){
	var id_programme = document.getElementById(input_programme).value;
	var id_baip = document.getElementById(input_baip).value;
	if (id_programme==-1) {
		document.getElementById(div).innerHTML = "X";
		document.getElementById(div).style.color = "#c00000";
		document.getElementById(input_programme).style.color = "#c00000";
		return false;
	}
	else if (id_programme==2 && id_baip==-1) {
		document.getElementById(div).innerHTML = "X";
		document.getElementById(div).style.color = "#c00000";
		document.getElementById(input_baip).style.color = "#c00000";
		return false;
	}
	else {
		document.getElementById(div).innerHTML = "OK";
		document.getElementById(div).style.color = "#40b400";
		document.getElementById(input_programme).style.color = "";
		document.getElementById(input_baip).style.color = "";
		return true;
	}
}

function champ_numerique_jour(input,div,test){
if (test){
	if (!verifier_jour(document.getElementById(input).value)){
		document.getElementById(div).innerHTML = "X";
		document.getElementById(div).style.color = "#c00000";
		document.getElementById(input).style.color = "#c00000";
		return false;
	}
	else {
		document.getElementById(div).innerHTML = "OK";
		document.getElementById(div).style.color = "#40b400";
		document.getElementById(input).style.color = "";
		return true;
	}
}
else {
	document.getElementById(div).innerHTML = "X";
	document.getElementById(div).style.color = "#c00000";
	document.getElementById(input).style.color = "#c00000";
	return false;
}	
}

function champ_numerique_mois(input,div,test){
if (test){
	if (!verifier_mois(document.getElementById(input).value)){
		document.getElementById(div).innerHTML = "X";
		document.getElementById(div).style.color = "#c00000";
		document.getElementById(input).style.color = "#c00000";
		return false;
	}
	else {
		document.getElementById(div).innerHTML = "OK";
		document.getElementById(div).style.color = "#40b400";
		document.getElementById(input).style.color = "";
		return true;
	}
}
else {
   	document.getElementById(div).innerHTML = "X";
	document.getElementById(div).style.color = "#c00000";
	document.getElementById(input).style.color = "#c00000";
	return false;
}
}

function champ_numerique_annee(input,div,test){
if (test){
	if (!verifier_annee(document.getElementById(input).value)){
		document.getElementById(div).innerHTML = "X";
		document.getElementById(div).style.color = "#c00000";
		document.getElementById(input).style.color = "#c00000";
		return false;
	}
	else {
		document.getElementById(div).innerHTML = "OK";
		document.getElementById(div).style.color = "#40b400";
		document.getElementById(input).style.color = "";
		return true;
	}
}
else {
	document.getElementById(div).innerHTML = "X";
	document.getElementById(div).style.color = "#c00000";
	document.getElementById(input).style.color = "#c00000";
	return false;
}
}

function champ_numerique_annee2(input,div,test){
if (test){
	if (!verifier_annee2(document.getElementById(input).value)){
		document.getElementById(div).innerHTML = "X";
		document.getElementById(div).style.color = "#c00000";
		document.getElementById(input).style.color = "#c00000";
		return false;
	}
	else {
		document.getElementById(div).innerHTML = "OK";
		document.getElementById(div).style.color = "#40b400";
		document.getElementById(input).style.color = "";
		return true;
	}
}
else {
	document.getElementById(div).innerHTML = "X";
	document.getElementById(div).style.color = "#c00000";
	document.getElementById(input).style.color = "#c00000";
	return false;
}
}

function champ_numerique_annee_afc(input,div,test){
var input_afc = null;
if (input == "form_annee_afc1")
	input_afc = "form_sponsor_fin_comp";
else if (input == "form_annee_afc2")
	input_afc = "form_afc2";
else if (input == "form_annee_afc3")
	input_afc = "form_afc3";
	
if (test){
	if (document.getElementById(input_afc).value > 0 && !verifier_annee2(document.getElementById(input).value)){
		document.getElementById(div).innerHTML = "X";
		document.getElementById(div).style.color = "#c00000";
		document.getElementById(input).style.color = "#c00000";
		return false;
	}
	else {
		document.getElementById(div).innerHTML = "OK";
		document.getElementById(div).style.color = "#40b400";
		document.getElementById(input).style.color = "";
		return true;
	}
}
else {
	document.getElementById(div).innerHTML = "X";
	document.getElementById(div).style.color = "#c00000";
	document.getElementById(input).style.color = "#c00000";
	return false;
}
}

function champ_email(input,div,test){
if (test){
	if ((!verifier_adresse_email(document.getElementById(input).value)) && (document.getElementById(input).value != "")){
		document.getElementById(div).innerHTML = "X";
		document.getElementById(div).style.color = "#c00000";
		document.getElementById(input).style.color = "#c00000";
		return false;
	}
	else if (document.getElementById(input).value != ""){
		document.getElementById(div).innerHTML = "OK";
		document.getElementById(div).style.color = "#40b400";
		document.getElementById(input).style.color = "";
		return true;
	}
	else {
		document.getElementById(div).innerHTML = "";
		return true;
	}
}
else {
	document.getElementById(div).innerHTML = "X";
	document.getElementById(div).style.color = "#c00000";
	document.getElementById(input).style.color = "#c00000";
	return false;
}
}

function champ_duo(input1,div1,input2,div2,test){
if (test){ 
	if ((document.getElementById(input2).value != "") && (document.getElementById(input1).value != document.getElementById(input2).value)){
		document.getElementById(div1).innerHTML = "X";
		document.getElementById(div1).style.color = "#c00000";
		document.getElementById(input1).style.color = "#c00000";
		document.getElementById(div2).innerHTML = "X";
		document.getElementById(div2).style.color = "#c00000";
		document.getElementById(input2).style.color = "#c00000";
		return false;
	}
	else if (document.getElementById(input1).value != ""){
		document.getElementById(div1).innerHTML = "OK";
		document.getElementById(div1).style.color = "#40b400";
		document.getElementById(input1).style.color = "";
		if (document.getElementById(input2).value != ""){
			document.getElementById(div2).innerHTML = "OK";
			document.getElementById(div2).style.color = "#40b400";
			document.getElementById(input2).style.color = "";
		}
		return true;
	}
	else {
		document.getElementById(div1).innerHTML = "";
		return true;
	}
}
else {
	document.getElementById(div1).innerHTML = "X";
	document.getElementById(div1).style.color = "#c00000";
	document.getElementById(input1).style.color = "#c00000";
	if (document.getElementById(input2).value != ""){
		document.getElementById(div2).innerHTML = "X";
		document.getElementById(div2).style.color = "#c00000";
		document.getElementById(input2).style.color = "#c00000";
	}
	return false;
}
}

function suivant(input1, input2, limite){
  if (document.getElementById(input1).value.length == limite){
   	document.getElementById(input2).focus();
  }
}

function limite(textarea, max, div)
{
	var taille = document.getElementById(textarea).value.length;
	var nbrMots = document.getElementById(textarea).value.split(" ");
	var reste = max - nbrMots.length + 1;
	if(reste < 0)
    {
        document.getElementById(div).innerHTML = "X";
		document.getElementById(div).style.color = "#c00000";
		document.getElementById(textarea).style.color = "#c00000";
		return false;
    }
    else {
    	document.getElementById(div).innerHTML = reste;
		document.getElementById(div).style.color = "#40b400";
		document.getElementById(textarea).style.color = "";
		return true;
	}
}

function limite_min(textarea, min, div)
{
	var taille = document.getElementById(textarea).value.length;
	var nbrMots = document.getElementById(textarea).value.split(" ");
	//var reste = nbrMots.length + 1 - min;
	if(nbrMots.length < min)
    {
        document.getElementById(div).innerHTML = nbrMots.length; //"X";
		document.getElementById(div).style.color = "#c00000";
		document.getElementById(textarea).style.color = "#c00000";
		return false;
    }
    else {
    	document.getElementById(div).innerHTML = nbrMots.length;
		document.getElementById(div).style.color = "#40b400";
		document.getElementById(textarea).style.color = "";
		return true;
	}
}


function cases_check(input,nombre){
	var verif = false;
	for (var i=0; i<nombre; i++){
		if (document.getElementById(input+'_'+i).checked){verif = true;}
	}
	return verif;
}


function cases_obligatoires(input,nombre,div,test){
if (test){
	if (!cases_check(input,nombre)){
		document.getElementById(div).innerHTML = "X";
		document.getElementById(div).style.color = "#c00000";
		for (var i=0; i<nombre; i++){
			document.getElementById(input+'_'+i).style.color = "#c00000";
		}
		return false;
		
	}
	else {
		document.getElementById(div).innerHTML = "OK";
		document.getElementById(div).style.color = "#40b400";
		for (var i=0; i<nombre; i++){
			document.getElementById(input+'_'+i).style.color = "";
		}
		return true;
	}
}
else {
	document.getElementById(div).innerHTML = "X";
	document.getElementById(div).style.color = "#c00000";
	for (var i=0; i<nombre; i++){
			document.getElementById(input+'_'+i).style.color = "#c00000";
	}
	return false;
}
}

function cases(input,nombre,div){
	if (!cases_check(input,nombre)){
		document.getElementById(div).innerHTML = "X";
		document.getElementById(div).style.color = "#c00000";
		for (var i=0; i<nombre; i++){
			document.getElementById(input+'_'+i).style.color = "#c00000";
		}
		return false;
		
	}
	else {
		document.getElementById(div).innerHTML = "";
		return true;
	}
}

function afficheOuCacheMenuBaip(menu_programmes) {
	if (menu_programmes.value == 2)
		document.getElementById("form_baip").style.display = "";
	else
		document.getElementById("form_baip").style.display = "none";
}

function afficheOuCacheChampAutre(checkbox, id_info) {
	if (checkbox.checked) {
		document.getElementById("libelle_" + id_info + "_autre").style.display = "";
		document.getElementById("form_" + id_info + "_autre").style.display = "";
		document.getElementById("form_" + id_info + "_autre").focus();
		document.getElementById("form_" + id_info + "_autre").select();
	}
	else {
		document.getElementById("libelle_" + id_info + "_autre").style.display = "none";
		document.getElementById("form_" + id_info + "_autre").style.display = "none";
	}
}

function testeValeurModele(champ, modele) {
	if (champ.value == modele)
		champ.value = "";
}
