/* Javascripts utilisés sur le site
 * Mettez l'ensemble de vos fonctions générique javascript ici
 * 
 * La liaison avec les page se fait à l'aide du code ci-dessous :
 * <script type="text/javascript" src="css-js/scripts.js"></script>
 */




/* GESTION PIEDS DE PAGE */
var hauteurFooter;

function setFooter(footerHeight){
	footerHeight = parseInt(footerHeight);
	hauteurFooter = footerHeight;
	hauteurMenu = document.getElementById('colLeft').offsetHeight;
	if(window.innerHeight){
		var maxHeight = window.innerHeight;
	} else {
		var maxHeight = document.body.clientHeight;
	}
	if(maxHeight < hauteurMenu){
		maxHeight = hauteurMenu;
	}

	// récuopération de la hauteur du footer
	var footer = document.getElementById('footer');
	var divHeight = (maxHeight - footerHeight);
	var headerHeight = document.getElementById('header').offsetHeight;
	document.getElementById('container').style.height=divHeight-8+'px';
	document.getElementById('colLeft').style.height=divHeight-headerHeight-16-8+'px';

}
if(!window.innerHeight){
	event.cancelBubble = true;
}
window.onresize = function(){
	setFooter(hauteurFooter);
}

function montre(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
if (d) {d.style.display='block';}
}
function verif_date(input)
{
var regex = new RegExp("[/]");
var date = input.value.split(regex);
var nbJours = new Array('',31,28,31,30,31,30,31,31,30,31,30,31);
var result = true;

if ( date['2']%4 == 0 && date['2']%100 > 0 || date['2']%400 == 0 )
nbJours['2'] = 29;

if( isNaN(date['2']) )
result=false;

if ( isNaN(date['1']) || date['1'] > 12 || date['1'] < 1 )
result=false;

if ( isNaN(date['0']) || date['0'] > nbJours[Math.round(date['1'])] || date['0'] < 1 )
result=false;

if (!result)
{
alert("Format de date invalide jj/mm/aaaa");
}

return result;
}

function VerificationEmail(elm)
{
		
	if (elm.value.indexOf("@em-lyon.com") != "-1" &&
		elm.value.indexOf(".") != "-1" &&
		elm.value != "" && 
		elm.value.substring("0", elm.value.indexOf("@")!=""))
		return true;

	
	return false;
}

function verif_inscription_etudiant()
{
	var msg    = "";
	var retour = true;
	
	if(document.getElementById('nom_etudiant').value=="")
	{
		retour = false;
		msg += "- Veuillez indiquer votre nom\n";
	}
	
	if(document.getElementById('prenom_etudiant').value=="")
	{
		retour = false;
		msg += "- Veuillez indiquer votre prénom\n";
	}
	if(document.getElementById('datenaissance_etudiant') && document.getElementById('datenaissance_etudiant').value!="")
	{
		retour =  verif_date(document.getElementById('datenaissance_etudiant'));
	}
	
	if(document.getElementById('annee_etudiant') && document.getElementById('annee_etudiant').options[document.getElementById('annee_etudiant').selectedIndex].value<=0)
	{
		retour = false;
		msg += "- Veuillez indiquer votre année d'étude\n";
	}
	
	/*if(document.getElementById('email_etudiant').value=="" ||  VerificationEmail(document.getElementById('email_etudiant')) == false)
	{
		retour = false;
		msg += "- Veuillez indiquer une adresse email valide de la forme @em-lyon.com\n";
	}*/
	if(document.getElementById('email_etudiant').value=="")
	{
		retour = false;
		msg += "- Veuillez indiquer une adresse email valide de la forme @em-lyon.com\n";
	}
	
	
	if(document.getElementById('login_etudiant').value.length<4)
	{
		retour = false;
		msg += "- Veuillez indiquer un login comportant au moins 4 caractères\n";
	}
	
	if(document.getElementById('pwd_etudiant').value.length<4)
	{
		retour = false;
		msg += "- Veuillez indiquer un mot de passe comportant au moins 4 caractères\n";
	}

	if(document.getElementById('confirmpwd_etudiant').value=="")
	{
		retour = false;
		msg += "- Veuillez confirmer votre mot de passe\n";
	}

	if(document.getElementById('confirmpwd_etudiant').value!="" &&  document.getElementById('confirmpwd_etudiant').value!="" && document.getElementById('pwd_etudiant').value!=document.getElementById('confirmpwd_etudiant').value)
	{
		retour = false;
		msg += "- La confirmation doit être identique au mot de passe\n";
	}
	
	if(!retour && msg!="" )
		alert(msg);
	
	return retour;
}
function verif_log()
{
	var msg    = "";
	var retour = true;
	
	if(document.getElementById('ident_login_etudiant').value=="")
	{
		retour = false;
		msg += "- Veuillez indiquer votre login\n";
	}
	
	if(document.getElementById('ident_login_etudiant').value=="")
	{
		retour = false;
		msg += "- Veuillez indiquer votre mot de passe\n";
	}
	if(!retour)
		alert(msg);
		
	return retour;
}
function verif_mail()
{
	var msg    = "";
	var retour = true;
	
	if(document.getElementById('email_etudiant').value=="" ||  VerificationEmail(document.getElementById('email_etudiant')) == false)
	{
		retour = false;
		msg += "Veuillez indiquer une adresse email valide de la forme @em-lyon.com\n";
	}
	if(!retour)
		alert(msg);
		
	return retour;
}
function changeCouleurTr()

{
var ligne= new Array()
 ligne=document.getElementsByName('ligne');

for(var j=0;ligne.length;j++)
{

ligne[j].onmouseover=function(){this.className='clair';};

ligne[j].onmouseout=function(){this.className='blanc';};

}

}


function verif_candidature()
{
	var confirmation = true;
	var txt_confirmation="";
	var retour = true;
	
	
	

	if(document.getElementById('commentaire_candidature').value=="")
	{
		txt_confirmation += "Vous n'avez pas indiqué de commentaire\n";
		confirmation = true;
	}
	
	if(document.getElementById('datedispodebut_candidature').value=="")
	{
		txt_confirmation += "Vous n'avez pas indiqué une date de début de disponibilité\n";
		confirmation = true;
	}
	
	if(document.getElementById('datedispofin_candidature').value=="")
	{
		txt_confirmation += "Vous n'avez pas indiqué une date de fin de disponibilité\n";
		confirmation = true;
	}
	if(confirmation)
	{
		
		if(!confirm(txt_confirmation+"\n\nÊtes vous sûr de vouloir valider votre candidature ?"))
		{
			retour = false;
		}
	}
	if(document.getElementById('datedispodebut_candidature').value!="")
		retour =  verif_date(document.getElementById('datedispodebut_candidature'));
		
	if(document.getElementById('datedispofin_candidature').value!="")
		retour = verif_date(document.getElementById('datedispofin_candidature'));
	
	return retour;
}

function verif_mission()
{
	var retour = true;
	var msg    = "";
	
	if(document.getElementById('titre_mission').value=="")
	{
		retour = false;
		msg += "- Veuillez indiquer un titre\n";
	}
	
	if(document.getElementById('client_mission').value=="")
	{
		retour = false;
		msg += "- Veuillez indiquer un client\n";
	}
	if(document.getElementById('chefprojet_mission') && document.getElementById('chefprojet_mission').options[document.getElementById('chefprojet_mission').selectedIndex].value<=0)
	{
		retour = false;
		msg += "- Veuillez indiquer un chef de projet\n";
	}
	
	if(!retour)
		alert(msg);
	
	if(document.getElementById('datedebut_mission').value!="")
		retour = verif_date(document.getElementById('datedebut_mission'));
	
	if(document.getElementById('datefin_mission').value!="")
		retour = verif_date(document.getElementById('datefin_mission'));
		
	if(document.getElementById('datefinpublication_mission').value!="")
		retour = verif_date(document.getElementById('datefinpublication_mission'));
	
	return retour;
}