function change(select, selectedValue)
{
    while (select.firstChild) 
        select.removeChild(select.firstChild);
    
    for(i=0;i<u[selectedValue].length;i++)
    {
        option = document.createElement('option');
        option.setAttribute('value', u[selectedValue][i][0]);
        option.appendChild(document.createTextNode(u[selectedValue][i][1]));
        select.appendChild(option);
    }
    
    if (selectedValue==0) // Cas ou on revient sur tous les univers pour réinitialiser les départements
        envoyerResultat('<%=this.ResolveUrl("/GetDepartements.aspx") %>', 'todo=getAll&idDepartement=<%=idDepartement %>', new maj());
}

function envoyerResultat(destination, parametres, callback)
{
    var xhr_object = null;
    if(window.XMLHttpRequest) xhr_object = new XMLHttpRequest(); 
    else if(window.ActiveXObject) xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	
    xhr_object.onreadystatechange = function() 
    { 
        if(xhr_object.readyState == 4)
         {
              if(xhr_object.status == 200) 
              {
                 callback.invoke(xhr_object.responseText);
              }
              else 
              {
                alert("Mise a jour non effectuee, recommencez svp ! Erreur : "+xhr_object.status);
              }
         }
    }
	
    xhr_object.open("POST", destination, true);
    xhr_object.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
    xhr_object.send(parametres);
}

function StopPub()
{
    var xhr_object = null;
    if(window.XMLHttpRequest) xhr_object = new XMLHttpRequest(); 
    else if(window.ActiveXObject) xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	
    xhr_object.onreadystatechange = function() 
    { 
        if(xhr_object.readyState == 4)
         {
              if(xhr_object.status == 200) 
              {
                 //callback.invoke(xhr_object.responseText);
              }
         }
    }
	
    xhr_object.open("POST", "StopPub.aspx", true);
    xhr_object.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
    xhr_object.send("");
}


String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function maj()
{
    this.invoke = function(message)
    {
        select = document.getElementById('idDepartement');
        while (select.firstChild)
             select.removeChild(select.firstChild);

        var reg2 = new RegExp("[\t]", "g");
        var reg = new RegExp("[\n]", "g");
        departements = message.split(reg);
        
        for (i=0; i<departements.length; i++)
        {
            if (departements[i].trim().length == 0) continue;
            
            option = document.createElement('option');
            
            tmp = departements[i].split(reg2);
            var value = tmp[0];
            var text = tmp[1];
            var sel = tmp[2];
            
            option.setAttribute('value', value);
            if (tmp[2] == 's') option.setAttribute('selected', 'selected');
            option.appendChild(document.createTextNode(text));
            select.appendChild(option);
        }
    }
}

function recherchePossible()
{
    return true;
    univers = document.getElementById("idUnivers").selectedIndex != 0;
    discipline = document.getElementById("idDiscipline").selectedIndex != 0;
    departement = document.getElementById("idDepartement").selectedIndex != 0;

    if ((univers && departement) || discipline) return true;

    alert("Veuillez choisir un critere de recherche supplementaire svp...");
    return false;
}
