function session_project_change(obj, id)
{
   var selected_value = obj.options[obj.selectedIndex].value;

   if (selected_value == "add_new")
   {
      session_project_display_add_div(id, true);
   }
   else
   {
      session_project_display_add_div(id, false);
   }
}

function session_project_add_value(id)
{
   var value_tag = document.getElementById("session_project_add_" + id);
   if (value_tag)
   {
      // add this value to the corrosponding select box
      var value      = value_tag.value;
      var select_box = document.getElementById("session_project_select_" + id);

      if (!value.length)
      {
          alert("Please enter a non-empty value for this field");
          return false;
      }
      var exists = false;

      // check if the value already exists
      for (var i = 0; i < select_box.length;++i)
      {
         if (select_box.options[i].value == value)
         {
             exists = true;
         }
      }

      // where to insert the option
      var index = select_box.length;


      if (!exists)
      {
         // add the option and set its value, and set it selected
         select_box.options[index] = new Option(value);
         select_box.options[index].value=value;
         select_box.options[index].selected = true;

         // reset add value
         value_tag.value="";

         // and hide it
         var add_tag        = document.getElementById("session_project_add_div_" + id);
         add_tag.style.display="none";
      }
      else
      {
         alert("Value already exists");
      }
   }
}


function session_project_display_add_div(id, display)
{
   var add_tag        = document.getElementById("session_project_add_div_" + id);

   if (display == true)
   {
      add_tag.style.display="inline";
   }
   else
   {
      add_tag.style.display="none";
   }
}
