
  /************************************************************\
  *
  *    Skinned Select Box Copyright 2007 Derek Harvey
  *		 www.lotsofcode.com
  *
  *    This file is part of Skinned Select Box .
  *
  *    Skinned Select Boxis free software; you can redistribute it and/or modify
  *    it under the terms of the GNU General Public License as published by
  *    the Free Software Foundation; either version 2 of the License, or
  *    (at your option) any later version.
  *
  *    Skinned Select Box is distributed in the hope that it will be useful,
  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *    GNU General Public License for more details.
  *
  *    You should have received a copy of the GNU General Public License
  *    along with Skinned Select Box; if not, write to the Free Software
  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  \************************************************************/
  
  // DEVELOPER NOTES
  // ===============
  
  // setText() Function for changing the text value of the selected item
  // This is reqired because the opacity for the select box
  // is set to "0", so we will not be able to see the value without this.
  
  // usage: setText(element [string], selectedOption [object])
  // example (applied to select box): 
  //  ->  setText('text1', this); - Uses current object as passing reference
  // example (onloaded): 
  //  ->  setText('text1', document.formName.elementName.selectedIndex); - Uses form element object as passing reference
  var url="http://www.petbusinessworld.co.uk/templates/default/populatecat.inc.php";

  function setText(a, b)
  {
    x = document.getElementById(a);
    if (x){
      //x.innerHTML = b.options[b.selectedIndex].innerHTML;
      var strr = b.options[b.selectedIndex].innerHTML;
      x.innerHTML = strr.substring(0,22);
    }  
    // IF Pager value is changed then resubmit the form
    if (a=="records_per_page_search")
      document.search_form.submit();
  }

  function setAJAXText(a, b)
  {
    
    x = document.getElementById(a);
    //y = document.getElementByName(b);
     
    if (x){
      //x.innerHTML = b.options[b.selectedIndex].innerHTML;
      var strr = b.options[b.selectedIndex].innerHTML;
      x.innerHTML = strr.substring(0,22);
      poupulateSubCat(b.value);
    }  
  }

  function setAJAXText2(b)
  {
      //x.innerHTML = b.options[b.selectedIndex].innerHTML;
      poupulateSubCat(b);
  }
  
  function poupulateSubCat(catid){
      xmlhttpPost(url, catid);
  }
 
  function xmlhttpPost(strURL, catid) {
      var xmlHttpReq = false;
      var self = this;
      // Mozilla/Safari
      if (window.XMLHttpRequest) {
          self.xmlHttpReq = new XMLHttpRequest();
      }
      // IE
      else if (window.ActiveXObject) {
          self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
      }
      self.xmlHttpReq.open('POST', strURL, true);
      self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      self.xmlHttpReq.onreadystatechange = function() {
          if (self.xmlHttpReq.readyState == 4) {
              updatepage(self.xmlHttpReq.responseText);
          }
      }
      self.xmlHttpReq.send(getquerystring(catid));
  }
  
  function getquerystring(catid) {
      //var form = document.forms['search_form'];
      //var word = form.sub_directories_search.value;
      qstr = 'cat=' + escape(catid);  // NOTE: no '?' before querystring
      return qstr;
  }
  
  function updatepage(str){
      document.getElementById("subdirectory").innerHTML = str;
  }

  // AJAX Code
  
  
