  function CheckNumeric()
  {
     // Get ASCII value of key that user pressed
     var key = window.event.keyCode;

     // Was key that was pressed a numeric character (0-9)?
     if ( (key > 47 && key < 58) || key == 8 )
        return; // if so, do nothing
     else
        window.event.returnValue = null; // otherwise, 
  	                               // discard character
  }

  function expand_category ( cat_id ) {
    var q = document.getElementById("child_" + cat_id);
    q.style.display == "list-item" ? q.style.display = "none" : q.style.display = "list-item";
  }
  
  function getURLVar( urlVarName ) {
    // divide the URL in half at the '?' 
    var urlHalves = decodeURI(window.document.location).split('?');
    var urlVarValue = '';
    if(urlHalves[1]){
      // load all the name/value pairs into an array 
      var urlVars = urlHalves[1].split('&');
      // loop over the list, and find the specified url variable 
      for(var i=0; i<=(urlVars.length); i++){
        if(urlVars[i]){
          // load the name/value pair into an array 
          var urlVarPair = urlVars[i].split('=');
          if (urlVarPair[0] && urlVarPair[0] == urlVarName) {
            // I found a variable that matches, load it's value into the return variable 
            urlVarValue = urlVarPair[1];
          }
        }
      }
    }
    return urlVarValue;   
  }
  
  function expand_current () {
    var q = getURLVar( "cat" );
    if( q && q != "sys" ) {
      if( document.getElementById("child_" + q) ) {
        document.getElementById("child_" + q).style.listStyleType = "none";
        document.getElementById("child_" + q).style.display = "list-item";
      }
      if( document.getElementById("brand_" + q) ) {
        document.getElementById("browse_cat").style.display = "none";
        document.getElementById("browse_brand").style.display = "block";
        
        document.getElementById("radioBrowse_cat").checked = "";
        document.getElementById("radioBrowse_brand").checked = "checked";
        return false;
      }
      if( document.getElementById("child_" + q) ) document.getElementById("child_" + q).style.display = "list-item";
      parentdiv = document.getElementById("cat_" + q).parentNode;
      parentdiv.style.display = "list-item";
      if( parentdiv.parentNode.parentNode.className = "category_child" ) {
        parentdiv.parentNode.parentNode.style.display = "list-item";
      }
    }
  }
  
  function update_build( category, stock, image, qty ) {
    var q = document.getElementById("code_" + category);
    var r = document.getElementById("desc_" + category);
    var s = document.getElementById("price_" + category);
    var t = document.getElementById("item_" + category);
    var u = document.getElementById("catimage_" + category);
    
    var v = document.getElementsByName("radio_" + category);
    var w = document.getElementById("pricedisplay_" + category + "_" + stock);
    var x = document.getElementById("itemqty_" + category);
    
    var subtotal;
    
    if( image == 1 ) {
      u.src = "image.php?q=thumb&id=" + stock;
      u.style.visibility = "visible";
    } else {
      u.style.visibility = "hidden";
    }
    
    subtotal = document.getElementById("stockprice_" + category + "_" + stock).value * qty;
    q.innerHTML = document.getElementById("stockcode_" + category + "_" + stock).innerHTML;
    r.innerHTML = "<strong>" + document.getElementById("stockdesc_" + category + "_" + stock).innerHTML + "</strong>";
    s.innerHTML = "$<strong><a name='price'>" + subtotal.toFixed(2) + "</a></strong>";
    
    if( qty > 0 ) {
      for( i = 0; i < v.length; i++ ) {
        if( v[i].value == stock ) v[i].checked = "checked";
      }
    }
    
    w.innerHTML = "$" + subtotal.toFixed(2);
    
    if( x ) x.value = qty;
    t.value = stock;
    
    update_build_total();
  }
  
  function update_build_price( checkbox, category, stock ) {
    var q = document.getElementById("price_" + stock);
    var r = document.getElementById("stockprice_" + category + "_" + stock);
    
    if( checkbox.checked == true ) {
      if( r ) q.innerHTML = "$<a name='price'>" + r.value + "</a>";
    } else {
      q.innerHTML = "";
      
    }
    
    update_build_total();
  }
  
  function update_build_total() {
    var total = 0;
    var prices = document.getElementsByName("price");
    
    for( var i = 0; i < prices.length; i++ ) {
      if( prices[i].innerHTML ) total = total + parseFloat( prices[i].innerHTML );
    }
    document.getElementById("build_total").innerHTML = "Total: $" + total.toFixed(2);
  }
  
  function expand_kit( category ) {
    var q = document.getElementById("expand_" + category);
    var r = document.getElementsByName("kit_" + category);
    
    if( q.alt == "Expand" ) {
      for( var i = 0; i < r.length; i++ ) {
        r[i].style.display = 'block';
      }
      q.src = "images/system_contract.png";
      q.alt = "Contract";
    } else {
      for( var i = 0; i < r.length; i++ ) {
        r[i].style.display = 'none';
      }
      q.src = "images/system_expand.png";
      q.alt = "Expand";
    }
  }
  
  function load_main() {
    if( getURLVar("cat") != "kits" && getURLVar("q") != "sys" ) {
      expand_current();
    }
    if( getURLVar("q") == "sys" || getURLVar("q") == "kit" ) {
      for( var q = 0; q < document.system_form.elements.length; q++ ) {
        if( document.system_form.elements[q].type == "checkbox" && document.system_form.elements[q].checked == true ) {
          var cat_stock = document.system_form.elements[q].name.substr(10);
          var u = cat_stock.indexOf("_");
          var stock = cat_stock.substr(u + 1);
          
          update_build_price( document.system_form.elements[q], stock );
        }
      }
      update_build_total();
    }
  }
  
  function submit_form( elem, e ) {
    var keycode = (window.event) ? window.event.keyCode : e.which;
    
    if (keycode == 13) {
      document.getElementById("loginenter").value = "1";
      elem.form.submit();
      
      return false;
    }
  }
  
  function change_category_list( type ) {
    if( type == "brand" ) {
      document.getElementById("browse_cat").style.display = "none";
      document.getElementById("browse_brand").style.display = "block";
    } else {
      document.getElementById("browse_cat").style.display = "block";
      document.getElementById("browse_brand").style.display = "none";
    }
  }