// JavaScript Document

/* ---------------------------  function de carte  ------------------------------*/
function cursusCarte(id,boutton)
{
	hide(document.getElementById("curcusBlock1"));
	hide(document.getElementById("curcusBlock2"));
	show(document.getElementById(id));
	initialiseMenuCarte(document.getElementById("menuCarte1"));
	initialiseMenuCarte(document.getElementById("menuCarte2"));
	selectMenuCarte(document.getElementById(boutton));
}

function initialiseMenuCarte(object)
{
	if(object){
		object.style.borderBottomColor="#b2cb7e";
		object.style.fontWeight="normal";
	}
}

function selectMenuCarte(object)
{
	if(object){
		object.style.borderBottomColor="#FFFFFF";
		object.style.fontWeight="bold";
	}
}

function defaultCoursCarte()
{
    var url = window.location.href;

    if( url.indexOf( "?choix=" ) == -1 )
    {
        window.location = window.location + "?choix=0&niveau=0";
    }
}

function defaultCoursCarteMotsCle()
{
     var url = window.location.href;

    if( ( url.indexOf( "?go2=" ) == -1 ) && ( url.indexOf( "?choix=" ) == -1 ) )
    {
        window.location = window.location + "?choix=0&niveau=1";
    }
}

function submitRechercheMotsCle() 
{
    if(document.getElementById( 'recherche-keyword').value != '' )
        document.getElementById('form_recherche2').submit();
}

/* ---------------------------  function de cursus  ------------------------------*/

function defaultCursus()
{
     var url = window.location.href;

    if( url.indexOf( "?choix=" ) == -1 )
    {
        window.location = window.location + "?choix=0&niveau=0";
    }
}

function cursusAffiche(id,boutton)
{
	hide(document.getElementById("curcusBlock1"));
	hide(document.getElementById("curcusBlock2"));
	show(document.getElementById(id));
	initialiseMenuCursus(document.getElementById("menuCurcus1"));
	initialiseMenuCursus(document.getElementById("menuCurcus2"));
	selectMenu(document.getElementById(boutton));
}

function initialiseMenuCursus(object)
{
	if(object){
		object.style.backgroundColor = "#d8dada";
		object.style.fontWeight="normal";
	}
}

function selectMenu(object)
{
	if(object){
		object.style.backgroundColor = "#FFFFFF";
		object.style.fontWeight="bold";
	}
}

/* ---------------------------  function carte et cursus  ------------------------------*/

function hide(object)
{
	if(object){
		object.style.display="none";
	}
}

function show(object)
{
	if(object){
		object.style.display="block";
	}
}

/**
 * Fonction permettant d'activer ou non le bouton d'inscription à un cours en fonction de si la session
 * sélectionnée est complète ou non
 */
function disableButton()
{
    if(document.getElementById('sessions'))
        monSelect = document.getElementById('sessions');
          
    if (monSelect.options[monSelect.selectedIndex].id == 'complet') {
        if (document.getElementById('boutonInscription')) 
            document.getElementById('boutonInscription').disabled = true;
    }
    else 
    {
        if (document.getElementById('boutonInscription')) 
            document.getElementById('boutonInscription').disabled = false;
    }
}

/**
 * Permet d'afficher la description du premier cours présent dans la liste
 * S'il n'y a pas de cours, alors on efface ce qu'il se trouve dans la div de description
 * 
 * @author djoguet
 */
function showFirstCourseDescription( cours ){
    if (document.getElementById('objectId')) 
        var objectId = document.getElementById('objectId').value;
    
    if (document.getElementById('coursId')) 
        var coursId = document.getElementById('coursId').value;
    
    if (objectId)
        xajax_getDescription('curcusBlock3', objectId, coursId, 1);
    else if(cours)
        xajax_getDescriptionByCourseID('curcusBlock3', cours, 1);
    else
        document.getElementById('curcusBlock3').innerHTML = '';
}

function razAClasses()
{
    var container = document.getElementById( 'listeCours' );
    var mylinks = container.getElementsByTagName( 'a' );

    for (i=0;i<mylinks.length;i++) 
    {

         mylinks[i].className = '';
    }
}

/**
 * Permet de soumettre le formulaire de recherche dans eZ Publish
 * 
 * @author djoguet
 */
function submitSearchForm()
{
    var searchBoxValue = document.getElementById( 'SearchText' ).value.replace(/^\s+|\s+$/g,"");
    //searchBoxValue = searchBoxValue.toUpperCase();
    //if( ( searchBoxValue != '' ) && ( searchBoxValue != 'RECHERCHE' ) )
    document.getElementById( 'search_form' ).submit();
}