﻿var popup;
var selDpt = null;
var is_ie = ( /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent) );  
var is_ie5 = ( is_ie && /msie 5\.0/i.test(navigator.userAgent) ); 
var is_ie7up = ( is_ie && parseFloat(navigator.userAgent.replace(/.*msie ([0-9]+).*/i, "$1" )) >= 7 ); 

function clickButton(e, buttonid){ 
  if(navigator.appName.indexOf("Netscape")>(-1)){ 
    if (e.keyCode == 13){ 
      simuleClic (buttonid)
      return false;
    } 
  } else if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
    if (event.keyCode == 13){ 
      simuleClic (buttonid);
      return false;
    } 
  } else { 
    if (event.keyCode == 13){ 
      return false;
    } 
  } 
}

function simuleClic(buttonid) {
    var bt = document.getElementById(buttonid); 

    if (typeof bt == 'object') {
        if (navigator.appName.indexOf("Netscape") > (-1)) {
            // FireFox
            // ajout de l'URL au onClick
            bt.setAttribute('onclick', decodeURIComponent(bt.href));
            // levée de l'évènement click
            var eClick = document.createEvent("MouseEvents");
            eClick.initEvent("click", true, true);
            bt.dispatchEvent(eClick);
        }
        else if (navigator.appName.indexOf("Microsoft Internet Explorer") > (-1)) {
            bt.click();
        }
    }
}

function rechercheRapide(){
	var li1 = document.getElementById("liRechRapide");
	li1.className = "rechRapide active";
	var li2 = document.getElementById("liRechComplete");
	li2.className = "rechComplete";
	var div = document.getElementById("divRechComplete");
	div.style.display = "none";	
	if (is_ie && !is_ie7up) {
		if (selDpt!=null){
			selDpt.style.visibility = 'visible'; 
		}
	}
}

function rechercheComplete(){
	var li1 = document.getElementById("liRechRapide");
	li1.className = "rechRapide";
	var li2 = document.getElementById("liRechComplete");
	li2.className = "rechComplete active";
	var div = document.getElementById("divRechComplete");
	div.style.display = "block";	
	if (is_ie && !is_ie7up) {
		if (selDpt!=null){
			selDpt.style.visibility = 'hidden'; 
		}
	}
}

function oubliEmail(){
	var div = document.getElementById("divOubliEmail");
	div.style.display = "block";	
	afficheVoile(div);
}

function fermerOubliEmail(){
	var div = document.getElementById("divOubliEmail");
	var fond = document.getElementById("voile");
	div.style.display = "none";
	fond.style.display = "none";	
}

function afficheVoile(divPopup){
	popup = divPopup
	fond = document.getElementById("voile");
	if (is_ie && !is_ie7up) {
		window.onscroll = updatePositionPopup;
		window.onresize = updatePositionPopup;
		updatePositionPopup();
	}	
	fond.style.display = "block";
}

function updatePositionPopup(){
	var fond = document.getElementById("voile");
	fond.style.top = document.documentElement.scrollTop;
	if (popup!=null){
		popup.style.top = document.documentElement.scrollTop + 60; 	
	}
}

// Fonction à appeler pour afficher les messages d'erreurs
function validateForm(summary){
	if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false){ 
		// Traitement du message
		errorMessage(summary);
		return false;
	}
	return true;
}

function errorMessage(summary){
	var divSummary = document.getElementById(summary);
	afficherMessageBox("Erreur", divSummary.innerHTML);
	divSummary.style.display = "none";
}

// Cache tous les select de la page
function hideSelect(){  
	oSelects = document.getElementsByTagName('SELECT');
	if (oSelects.length > 0) { 
		for (i = 0; i < oSelects.length; i++) {
			oSelects[i].style.visibility = 'hidden'; 
		} 
	}
}

// Affiche tous les select de la page
function showSelect(){  
	oSelects = document.getElementsByTagName('SELECT');
	if (oSelects.length > 0) { 
		for (i = 0; i < oSelects.length; i++) {
			oSelects[i].style.visibility = 'visible'; 
		} 
	}
}

function codeCandidat(candidatId, candidatureId, pseudo){
	var div = document.getElementById("divCode");
	div.style.display = "block";
	document.getElementById("sMembreCode").innerHTML = pseudo;
	document.getElementById("hCandidatId").value = candidatId;
	document.getElementById("hPretendantId").value = "";
	document.getElementById("hCandidatureId").value = candidatureId;
	afficheVoile(div);
}

function codePretendant(pretendantId, candidatureId, pseudo){
	var div = document.getElementById("divCode");
	div.style.display = "block";	
	document.getElementById("sMembreCode").innerHTML = pseudo;
	document.getElementById("hCandidatId").value = "";
	document.getElementById("hPretendantId").value = pretendantId;
	document.getElementById("hCandidatureId").value = candidatureId;
	afficheVoile(div);
}

function fermerCode(){
	var div = document.getElementById("divCode");
	var fond = document.getElementById("voile");
	div.style.display = "none";
	fond.style.display = "none";	
}

function reloadPage(){
	window.location = document.URL;
}
