function montre(id) 
{
	var d = document.getElementById(id);
	document.getElementById('sous-menu-etudiant').style.display='none';
	document.getElementById('sous-menu-recruteur').style.display='none';
	document.getElementById('sous-menu-blog').style.display='none';
	if(d) 
	{
		d.style.display='block';
	}
}

function active_bouton_inscription()
{
	var d=document.getElementById("boutton_inscription");
}

function enregistreUnBulletin(nom, valeur)
{
	var argv= enregistreUnBulletin.arguments;
	var argc= enregistreUnBulletin.arguments.length;
	var expires=null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=nom+"="+escape(valeur)+
	((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+
	((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}

/* For registration*/

function contratEstAccepte()
{
	
	var bouton=document.getElementById("accept_contrat");
	if(bouton.checked==true)
	{
		return true;
	}
	return false;
	//return true;
}

function checkModificationEtudiant(formulaire)
{
	if(checkInscriptionEtudiantDepartements() && checkInscriptionEtudiantMatiereDominante() && checkInscriptionEtudiantEtablissementScolaire() && checkInscriptionEtudiantMotDePasse() &&  checkInscriptionEtudiantConfirmation() && checkInscriptionEtudiantMail() &&	checkInscriptionEtudiantNom())
	{
		formulaire.submit();
	}
}

function checkInscriptionEtudiant(formulaire)
{
	if(!contratEstAccepte())
	{
		alert("Pour pouvoir valider votre inscription, vous devez lire le \"Contrat d'inscription\" et cocher la case \"J'accepte\".");
		return;
	}
	if(checkInscriptionEtudiantDepartements() && checkInscriptionEtudiantMatiereDominante() && checkInscriptionEtudiantEtablissementScolaire() && checkInscriptionEtudiantConfirmation() && checkInscriptionEtudiantMotDePasse() && checkInscriptionEtudiantMail() && checkInscriptionEtudiantPrenom() &&	checkInscriptionEtudiantNom())
	{
			formulaire.submit();
	}
}

function checkInscriptionRecruteur(formulaire)
{
	if(!contratEstAccepte())
	{
		alert("Pour pouvoir valider votre inscription, vous devez lire le \"Contrat d'inscription\" et cocher la case \"J'accepte\".");
		return;
	}

	if(checkInscriptionEtudiantConfirmation() && checkInscriptionEtudiantMotDePasse() && checkInscriptionEtudiantMail() && checkInscriptionEtudiantPrenom() &&	checkInscriptionEtudiantNom() && checkNumeroTelephone() && checkAdresse() )
	{
		formulaire.submit();
	}
}

function checkNouvelleAnnonce(formulaire)
{
	if(checkTitreAnnonce() && checkDateDebut() && checkNombreDePostes() && checkDescriptifCadre() && checkDescriptifMission() && checkDescriptifConditions() && checkDescriptifProfil() && checkDescriptifContact())
	{
		formulaire.submit();
	}
}

function checkTitreAnnonce()
{
	if(isEmpty("input_titre"))
	{
		alert("Vous n'avez pas entre de titre pour votre annonce.");
		return false;
	}
	return true;
}

function checkDateDebut()
{
	jour=document.getElementById("input_jour").value;
	mois=document.getElementById("input_mois").value;
	annee=document.getElementById("input_annee").value;
	today= new Date();
	theDay=new Date(annee,mois-1,jour);
	if(theDay.getYear()<today.getYear())
	{
		alert("Cette date est deja passee!");
		return false;
	}
	else if (theDay.getYear()>today.getYear())
	{
		return true;
	}
	else
	{
		if(theDay.getMonth()<today.getMonth())
		{
			alert("Cette date est deja passee!");
			return false;
		}
		else if(theDay.getMonth()>today.getMonth())
		{
			return true;
		}
		else
		{
			if(theDay.getDate()<today.getDate())
			{
				alert("Cette date est deja passee!");
				return false;
			}
			else
			{
				return true;
			}
		}
	}
}

function checkNombreDePostes()
{
	if(isEmpty("input_nombre_postes"))
	{
		alert("Vous n'avez pas entre le nombre de postes que vous proposez.");
		return false;
	}
	return true;	
}

function checkDescriptifCadre()
{
	if(isEmpty("input_descriptif_cadre"))
	{
		alert("Vous n'avez pas entre de descriptif pour le cadre: decrivez votre entreprise, votre association...");
		return false;
	}
	return true;	
}

function checkDescriptifMission()
{
	if(isEmpty("input_descriptif_mission"))
	{
		alert("Vous n'avez pas entre de descriptif pour la mission.");
		return false;
	}
	return true;	
}

function checkDescriptifConditions()
{
	if(isEmpty("input_descriptif_conditions"))
	{
		alert("Vous n'avez pas entre de  conditions, entrez le salaire, les horaires...");
		return false;
	}
	return true;	
}

function checkDescriptifProfil()
{
	if(isEmpty("input_descriptif_profil"))
	{
		alert("Vous n'avez pas entre de desciptif pour le profil type.");
		return false;
	}
	return true;	
}

function checkDescriptifContact()
{
	if(isEmpty("input_informations_contact"))
	{
		alert("Vous n'avez pas entre les informations pour postuler.");
		return false;
	}
	return true;	
}

function checkNumeroTelephone()
{
	var content=document.getElementById("input_telephone").value;
	if(!content.length==10)
	{
		alert("Ce numero de telephone n'est pas valide.");
		return false;
	}
	return true;
}

function checkAdresse()
{
	if(isEmpty("input_adresse"))
	{
		alert("Rentrez votre adresse.");
		return false;
	}
	return true;
}

function checkInscriptionEtudiantDepartements()
{
	var content=document.getElementById("input_departements").value;
	var splitted=content.split("-");
	if(content=="")
	{
		alert("Entrez au moins un departement.");
		return false;
	}
	else
	{
		var i=0;
		while(i<splitted.length)
		{
			if(!isDep(splitted[i]))
			{
				alert(splitted[i]+" n'est pas un departement.");
				return false;
			}
			i++;
		}
	}
	return true;
}

function checkMailContact(formulaire)
{
	if(checkSujetMailContact() && checkMessageMailcontact() && checkInscriptionEtudiantPrenom() && checkInscriptionEtudiantNom() && checkInscriptionEtudiantMail())
	{
		formulaire.submit();
	}
}

function checkSujetMailContact()
{
	if(isEmpty("input_sujet"))
	{
		alert("Vous n'avez pas de sujet a votre message.");
		return false;
	}
	return true;
}

function checkMessageMailcontact()
{
	if(isEmpty("input_message"))
	{
		alert("Vous n'avez pas de message pour nous contacter.");
		return false;
	}
	return true;
}

function checkInscriptionEtudiantMatiereDominante()
{
	if(isEmpty("input_matiere_dominante"))
	{
		alert("Vous n'avez pas entre de matiere dominante.");
		return false;
	}
	return true;
}

function checkInscriptionEtudiantEtablissementScolaire()
{
	if(isEmpty("input_etablissement"))
	{
		alert("Vous n'avez pas entre votre etablissement scolaire.");
		return false;
	}
	return true;
}

function checkInscriptionEtudiantConfirmation()
{
	var motDePasse=document.getElementById("input_mot_de_passe").value;
	var confirmation=document.getElementById("input_confirmation").value;
	if(motDePasse!=confirmation)
	{
		alert("Vous avez entre deux mots de passe differents.");
		return false;
	}
	return true;
}

function checkInscriptionEtudiantMotDePasse()
{
	if(isEmpty("input_mot_de_passe"))
	{
		alert("Vous n'avez pas entre votre mot de passe.");
		return false;
	}
	return true;
}

function checkInscriptionEtudiantMail()
{
	if(!VerificationEmail(document.getElementById("input_email").value))
	{
		alert("Cette adresse email n'est pas valide.");
		return false;
	}
	return true;
}

function checkInscriptionEtudiantPrenom()
{
	if(isEmpty("input_prenom"))
	{
		alert("Vous n'avez pas entre votre prenom.");
		return false;
	}
	return true;
}

function checkInscriptionEtudiantNom()
{
	if(isEmpty("input_nom"))
	{
		alert("Vous n'avez pas entre votre nom.");
		return false;
	}
	return true;
}

function isDep(dep)
{
	if(dep=="2a" || dep=="2b")
	{
		return true;
	}
	else if(dep>0 && dep<96)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function isEmpty(idComponent)
{
	var content=document.getElementById(idComponent).value;
	if(leftTrim(content)=="")
	{
		return true;
	}
	return false;
}

function leftTrim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	return sString;
}

function VerificationEmail(email)
{
	if (email.indexOf("@") != "-1" && email.indexOf(".") != "-1" && email!= "" && email.lastIndexOf("@")==email.indexOf("@"))
    return true;
	return false;
}