/**
 * javascript functions for archive search
 * @author    Greg Tammi <greg@pictographics.com>
 * @copyright Copyright 2009+ Pictographics Ltd
 * @since     Feb 10, 2009
 * @internal  All functions are in alphabetical order for ease of finding
 */

/**
 * loads a given subject category into select option list
 * @param       object  target  the target of the select option list
 * @param       integer parent  the parent category to load
 * @param       integer select  the selected item (if any)
 * @since       Feb 10, 2009
 * @internal    had to use low-level $.ajax implementation instead of using the
 *              $.post method because the call needed to be synchronous.
 */
function loadSubjectCategory(target, parent, select) {
  $.ajax({
     async:      false, 
     dataType:   "text",
     type:       "POST", 
     data:       "id=" + parent, 
     url:        "/ajax/loadArchiveSubjects.php", 
     success:    function(data, status) {
       // load JSON information       
       var json = eval('(' + data + ')') ;
       // wipe all options from parent_object select box
       var targ = document.getElementById(target) ;
       targ.options.length = 0 ;
       // create blank option for list
       targ.options[0] = new Option("", "") ;
       for(obj in json) {
         // replace entity constants here
         var desc = json[obj]['description'] ;
         // check if this is the selected option
         var sel = (json[obj]['id'] == select) ? true : false ;       
         var opt = new Option(desc, json[obj]['id'], false, sel) ;
         targ.options[targ.options.length] = opt ;
       }
     },
     error:      function(xhr, status, error) {
     }
  }); 
}