  function appendOptionLast(num, c_id, c_name)  {
    var elOptNew = document.createElement('option');
    elOptNew.text = c_name;
    elOptNew.value = c_id;
    var elSel = document.getElementById('client');
                
    try {
      elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
    }
    catch(ex) {
      elSel.add(elOptNew); // IE only
    }
  }
  
  function removeField(this_id) {
    var node = this_id.parentNode;
    node.parentNode.removeChild(node);	
  }
  
  function moveUp(this_id, direction) {
  /* this function is copyrighted by America's Network, Inc., all rights reserved */
    btn_switch(this_id);    
    this_parent = this_id.parentNode.parentNode.id;
    sort_number = parseInt(this_parent.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$2"), 10); 
    parent_base = this_parent.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$1")+'_';       
      
    if (direction == 'down') { 
      next_parent = parent_base+(parseInt(sort_number,10) + parseInt(1,10));
      next2_parent = parent_base+(parseInt(sort_number,10) + parseInt(2,10));
      var newFields = document.getElementById(next_parent).cloneNode(true);
      var prevFields = document.getElementById(this_parent).cloneNode(true);
      newFields.id = parent_base+(parseInt(sort_number, 10));
      prevFields.id = parent_base+(parseInt(sort_number, 10) + parseInt(1,10));
    } else {
      next_parent = parent_base+(parseInt(sort_number,10) + parseInt(1,10));
      previous_parent = parent_base+(parseInt(sort_number,10) - parseInt(1,10));
      var newFields = document.getElementById(this_parent).cloneNode(true);
      var prevFields = document.getElementById(previous_parent).cloneNode(true);
      newFields.id = parent_base+(parseInt(sort_number, 10) - parseInt(1,10));
      prevFields.id = parent_base+(parseInt(sort_number, 10));
    }

    newFields.style.display = 'block';
    prevFields.style.display = 'block'; 
    parent_root = parent_base+'root';
      
    node = document.getElementById(this_parent);
    node.parentNode.removeChild(node);
    if (direction == 'down') { 
      node = document.getElementById(next_parent);
      node.parentNode.removeChild(node);  
      if (!document.getElementById(next2_parent)) {
        var insertHere = document.getElementById(parent_root);
      } else { 
        var insertHere = document.getElementById(next2_parent);
      }
    } else {
      node = document.getElementById(previous_parent);
      node.parentNode.removeChild(node);  
      if (!document.getElementById(next_parent)) {
        var insertHere = document.getElementById(parent_root);
      } else { 
        var insertHere = document.getElementById(next_parent);
      }
    }
    
    insertHere.parentNode.insertBefore(newFields,insertHere);
    insertHere.parentNode.insertBefore(prevFields,insertHere);
    //assign new value to inputs
    if (direction == 'down') { 
      nextInput = parent_base+'s'+(parseInt(sort_number,10));
      thisInput = parent_base+'s'+((parseInt(sort_number,10))+parseInt(1,10));
      next_hInput = parent_base+'h'+(parseInt(sort_number,10));
      this_hInput = parent_base+'h'+((parseInt(sort_number,10))+parseInt(1,10));
      next_mInput = parent_base+'m'+(parseInt(sort_number,10));
      this_mInput = parent_base+'m'+((parseInt(sort_number,10))+parseInt(1,10));
      next_container = parent_base+'c'+(parseInt(sort_number,10));
      this_container = parent_base+'c'+((parseInt(sort_number,10))+parseInt(1,10));
  
      document.getElementById(nextInput).value=((parseInt(sort_number,10))+parseInt(1,10));
      document.getElementById(thisInput).value=(parseInt(sort_number,10));     
      document.getElementById(nextInput).id=thisInput;
      document.getElementById(thisInput).id=nextInput;
      document.getElementById(next_hInput).id=this_hInput;
      document.getElementById(this_hInput).id=next_hInput;
      document.getElementById(next_mInput).id=this_mInput;
      document.getElementById(this_mInput).id=next_mInput;
      document.getElementById(next_container).id=this_container;
      document.getElementById(this_container).id=next_container;
    } else {
      newInput = parent_base+'s'+(parseInt(sort_number,10)-parseInt(1,10));
      prevInput = parent_base+'s'+(parseInt(sort_number,10));
      new_hInput = parent_base+'h'+(parseInt(sort_number,10)-parseInt(1,10));
      prev_hInput = parent_base+'h'+(parseInt(sort_number,10));
      new_mInput = parent_base+'m'+(parseInt(sort_number,10)-parseInt(1,10));
      prev_mInput = parent_base+'m'+(parseInt(sort_number,10));
      new_container = parent_base+'c'+(parseInt(sort_number,10)-parseInt(1,10));
      prev_container = parent_base+'c'+(parseInt(sort_number,10));
  
      document.getElementById(newInput).value=(parseInt(sort_number,10));      
      document.getElementById(prevInput).value=(parseInt(sort_number,10)-parseInt(1,10));
      document.getElementById(newInput).id=prevInput;
      document.getElementById(prevInput).id=newInput;
      document.getElementById(new_hInput).id=prev_hInput;
      document.getElementById(prev_hInput).id=new_hInput;
      document.getElementById(new_mInput).id=prev_mInput;
      document.getElementById(prev_mInput).id=new_mInput;
      document.getElementById(new_container).id=prev_container;
      document.getElementById(prev_container).id=new_container;
    }
  }
  
  function hideForum(this_id, flag) {
    /* this function is copyrighted by America's Network, Inc., all rights reserved */
    if (flag != 1) { 
      this_id = this; 
    }
    
    this_parent = this_id.parentNode.parentNode.id;
    this_root = this_id.parentNode.parentNode.parentNode.parentNode.id;
    
    sort_number = parseInt(this_parent.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$2"), 10); 
    parent_base = this_parent.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$1")+'_'; 
    
    root_number = parseInt(this_root.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$2"), 10); 
    root_base = this_root.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$1")+'_';          
    
    root_collapse = root_base+"z"+root_number;
    if (document.getElementById(root_collapse) != null) {
      document.getElementById(root_collapse).style.backgroundPosition = "-168px -48px";    
      document.getElementById(root_collapse).onclick = restoreSubForum;    
    } else {
      document.getElementById('master_z').style.display = 'block';
    }
    
    parent_input = parent_base+'h'+sort_number;
      
    document.getElementById(this_parent).style.display='none';
    document.getElementById(parent_input).value='hide';    
  }  
  
  
  function restoreSubForum(this_id, flag) {
    if (flag != 1) {
      this_id = this;
    }
    /* this function is copyrighted by America's Network, Inc., all rights reserved */
    this_id.style.backgroundPosition = "-168px 0px";
    var subcats,i;
    /* get root container */
    this_root = this_id.parentNode.parentNode.id;
    root_base = this_root.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$1")+'_';  
    root_number = parseInt(this_root.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$2"), 10);
    
    root_container = root_base+'c'+root_number;   
    root_min = root_base+'z'+root_number;   
    document.getElementById(root_min).onclick = hideForum;     
    
    subcats=document.getElementById(root_container).getElementsByTagName('div');
    for(i in subcats) {
      /*this is now root subcat*/
      if (this_child = subcats[i].id) {
        child_base = this_child.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$1")+'_';  
        child_number = parseInt(this_child.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$2"), 10);
        child_hide = child_base+'h'+child_number;
        if (T = document.getElementById(child_hide) ) {
          if (T.value == "hide") {
            /*show subforum and reset value to show*/
            T.value = "show";            
            subcats[i].style.display = "block";
          }
        }
      }
    }
    document.getElementById("Content").style.height = document.body.scrollHeight+'px';
  }
  
  function restoreAll() {    
    /* this function is copyrighted by America's Network, Inc., all rights reserved */
    subcats=document.getElementById('root_holder').getElementsByTagName('div');
    document.getElementById('master_z').style.display='none';
    for(i in subcats) {
      /*this is now root subcat*/
      if (this_child = subcats[i].id) {
        child_base = this_child.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$1")+'_';  
        child_number = parseInt(this_child.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$2"), 10);
        child_hide = child_base+'h'+child_number;
        child_zh = child_base+'z'+child_number;
        if (T = document.getElementById(child_hide) ) {
          if (T.value == "hide") {
            /*show subforum and reset value to show*/
            T.value = "show";            
            subcats[i].style.display = "block";
            z_id = document.getElementById(child_zh);
            if (z_id != null) {
              z_id.style.backgroundPosition = "-168px 0px";
              z_id.onclick = hideForum;  
            }
          }
        }
      }
    }
    document.getElementById("Content").style.height = document.body.scrollHeight+'px';
  }
  
  function removeAll() {    
    /* this function is copyrighted by America's Network, Inc., all rights reserved */
    subcats=document.getElementById('root_holder').getElementsByTagName('div');
    document.getElementById('master_z').style.display='block';
    for(i in subcats) {
      /*this is now root subcat*/
      if (this_child = subcats[i].id) {
        child_base = this_child.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$1")+'_';  
        child_number = parseInt(this_child.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$2"), 10);
        child_hide = child_base+'h'+child_number;
        child_zh = child_base+'z'+child_number;
        if (T = document.getElementById(child_hide) ) {
          if (T.value == "show") {
            /*show subforum and reset value to show*/
            T.value = "hide";            
            subcats[i].style.display = "none";
            z_id = document.getElementById(child_zh);
            if (z_id != null) {
              z_id.style.backgroundPosition = "-168px -48px";
              z_id.onclick = restoreSubForum;  
            }
          }
        }
      }
    }
    alert ('Press the green dot to restore sections of the forum');
  }
  
  function maximizeAll() {    
    /* this function is copyrighted by America's Network, Inc., all rights reserved */
    subcats=document.getElementById('root_holder').getElementsByTagName('var');
    for(i in subcats) {
      /*this is now root subcat*/
      if (this_child = subcats[i].title) {
        child_base = this_child.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$1")+'_';  
        child_number = parseInt(this_child.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$2"), 10);
        child_hide = child_base+'m'+child_number;
        child_container = child_base+'c'+child_number;
        child_minmax = child_base+'mm'+child_number;
        child_cont = child_base+'c'+child_number;
        if (C = document.getElementById(child_cont)) {
          if (C.childNodes[3]) {
            if (T = document.getElementById(child_hide) ) {
              if (T.value == "0") {
                /*show subforum and reset value to show*/
                T.value = "1";            
                document.getElementById(child_container).style.display = "block";
                btn_switch('', 1, child_minmax);
                btn_switch('', 1, child_minmax);
              }
            }
          }
        }
      }
    }
    document.getElementById("Content").style.height = document.body.scrollHeight+'px';
  }
  
  function minimizeAll() {    
    /* this function is copyrighted by America's Network, Inc., all rights reserved */
    subcats=document.getElementById('root_holder').getElementsByTagName('var');
    for(i in subcats) {
      /*this is now root subcat*/
      if (this_child = subcats[i].title) {
        child_base = this_child.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$1")+'_';  
        child_number = parseInt(this_child.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$2"), 10);
        child_hide = child_base+'m'+child_number;
        child_container = child_base+'c'+child_number;
        child_minmax = child_base+'mm'+child_number;
        //get container div and determine if it has children
        child_cont = child_base+'c'+child_number;
        if (C = document.getElementById(child_cont)) {
          if (C.childNodes[3]) {
            if (T = document.getElementById(child_hide) ) {
              if (T.value == "1") {
                /*show subforum and reset value to show*/
                T.value = "0";            
                document.getElementById(child_container).style.display = "none";
                btn_switch('','',child_minmax);
                btn_switch('','',child_minmax);
              }
            }
          }
        }
      }
    }
    document.getElementById("Content").style.height = '';
    document.getElementById("Content").style.height = document.body.scrollHeight+'px';
  }
  
  function restoreRoot() {  
    /* this function is copyrighted by America's Network, Inc., all rights reserved */
    subcats=document.getElementById('root_holder').childNodes;
    document.getElementById('master_z').style.display='none';
    for(i in subcats) {
      /*this is now root subcat*/
      if (this_child = subcats[i].id) {              
        child_base = this_child.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$1")+'_';  
        child_number = parseInt(this_child.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$2"), 10);
        child_hide = child_base+'h'+child_number;
        if (T = document.getElementById(child_hide) ) {       
          if (T.value == "hide") {
            /*show subforum and reset value to show*/
            T.value = "show";            
            subcats[i].style.display = "block";
          }
        }
      }
    }
    document.getElementById("Content").style.height = document.body.scrollHeight+'px';
  }
  
  function collapseForum(this_id, flag) {  
    /* this function is copyrighted by America's Network, Inc., all rights reserved */
    if (flag == 1) {
      this_id = document.getElementById(this_id);
    }
    this_parent = this_id.parentNode.parentNode.id;
    sort_number = parseInt(this_parent.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$2"), 10); 
    parent_base = this_parent.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$1")+'_';       

    parent_container = parent_base+'c'+sort_number;
    parent_input = parent_base+'m'+sort_number;
    
    if (document.getElementById(parent_container).style.display=='block') {
      document.getElementById(parent_container).style.display='none';
      document.getElementById(parent_input).value='0';
      btn_switch(this_id);
      btn_switch(this_id);
    } else {
      document.getElementById(parent_container).style.display='block';
      document.getElementById(parent_input).value='1';
      btn_switch(this_id, 1);
      btn_switch(this_id, 1);
      document.getElementById("Content").style.height = document.body.scrollHeight+'px';
    }  
  }  
  
  var xmlhttp
  var link_obj;
  
  function saveExpand(that_id, this_obj) {    
    link_obj = this_obj;
    var params = '';
    that_base = that_id.replace(/([a-zA-Z0-9]*)_mm([0-9]*)/g, "$1")+'_';  
    that_number = parseInt(that_id.replace(/([a-zA-Z0-9]*)_mm([0-9]*)/g, "$2"), 10);
    that_holder = that_base+'id'+that_number;
    if (TH = document.getElementById(that_holder) ) {
      the_id = TH.value;
      params = 'id='+the_id;
    }
    
    subcats=document.getElementById('root_holder').getElementsByTagName('var');
    for(i in subcats) {
      /*this is now root subcat*/
      if (this_child = subcats[i].title) {
        child_base = this_child.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$1")+'_';  
        child_number = parseInt(this_child.replace(/([a-zA-Z0-9]*)_([0-9]*)/g, "$2"), 10);
        child_hide = child_base+'m'+child_number;
        child_holder = child_base+'id'+child_number;
        if (H = document.getElementById(child_holder) ) {
          if (T = document.getElementById(child_hide) ) {
            child_id = H.value;
            if (T.value == "1") {
              if (params == '') {
                params = 'h_['+child_id+']=1';
              } else {
                params += '&h_['+child_id+']=1';
              }
            } else {
              if (params == '') {
                params = 'h_['+child_id+']=0';
              } else {
                params += '&h_['+child_id+']=0';
              }
            }
          }
        }
      }
    }
    
    xmlhttp=GetXmlHttpObject();    
    if (xmlhttp==null) {
      //ajax not supported. Bummer. Go to page.
      window.location = this_obj.getAttribute("href");
      return true;
    }
    var url="includes/save_expand.php";    
    
    //url=url+"?q="+str;
    xmlhttp.open("POST", url, true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded;  charset=UTF-8");
    xmlhttp.setRequestHeader("Content-length", params.length);
    xmlhttp.setRequestHeader("Connection", "close");
    xmlhttp.send(params);  
    xmlhttp.onreadystatechange=getStatus;    
  }
  
  function getStatus()  { 
    if (xmlhttp.readyState==4)  {
      window.location = link_obj.getAttribute("href");
    }
  }
  
  function GetXmlHttpObject() {
    if (window.XMLHttpRequest)    {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      return new XMLHttpRequest();
    }
    if (window.ActiveXObject) {
      // code for IE6, IE5
      return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
  }  
    
  function ourClick(that_id, this_obj) {     
    current_pos = document.getElementById(that_id).style.backgroundPosition;
    if (current_pos == '-96px -48px') {
      new_pos = '-144px -48px';
    } else if (current_pos == '-96px 0') {
      new_pos = '-120px -48px';
    } else if ((current_pos == '-24px -48px') || (current_pos == '-24px 0px') || (current_pos == '0px -0px')) {
      new_pos = '0px -48px';
    } else {
      new_pos = '0px -48px';
    }
    document.getElementById(that_id).style.backgroundPosition = new_pos;    
    saveExpand(that_id, this_obj);
  }
  
  function loadGenre() { 
    document.getElementById('genre_des').style.display="none";
    document.getElementById('genre_submit').style.display="block";
    document.getElementById('genres').style.display="block";    
  }
  
  function loadTime() { 
    document.getElementById('time_des').style.display="none";
    document.getElementById('time_submit').style.display="block";
    document.getElementById('times').style.display="block";    
  }

