function admin_save_inventory()
{
  // Set the backend filename to process
  var filename = 'modules/Admin/inventory/ajax_save_inventory.php';

  // Get the form fields
  var pk_ID = document.getElementById('pk_ID').value;
  var vc_Title = document.getElementById('vc_Title').value;
  var fk_ArtistID = document.getElementById('fk_ArtistID').value;
  var fk_CountryID = document.getElementById('fk_CountryID').value;
  var txt_Description = document.getElementById('txt_Description').value;
  var vc_Tags = document.getElementById('vc_Tags').value;

  var int_Quantity = document.getElementById('int_Quantity').value;
  var int_Limit = document.getElementById('int_Limit').value;
  var fl_Price01 = document.getElementById('fl_Price01').value;
  var fl_Price02 = document.getElementById('fl_Price02').value;
  var fl_Shipping_Domestic01 = document.getElementById('fl_Shipping_Domestic01').value;
  var fl_Shipping_Domestic02 = document.getElementById('fl_Shipping_Domestic02').value;
  var fl_Shipping_Intl01 = document.getElementById('fl_Shipping_Intl01').value;
  var fl_Shipping_Intl02 = document.getElementById('fl_Shipping_Intl02').value;

  var int_DimX = document.getElementById('int_DimX').value;
  var int_DimY = document.getElementById('int_DimY').value;
  var int_DimZ = document.getElementById('int_DimZ').value;
  var int_Weight = document.getElementById('int_Weight').value;

  var vc_FairQURL = document.getElementById('vc_FairQURL').value;


  // Get the inventory type radio selection
  var fk_Inventory_Types = document.getElementsByName('fk_Inventory_TypeID');

  for( i = 0; i < fk_Inventory_Types.length; i++ )
  {
    if( fk_Inventory_Types[i].checked)
      var fk_Inventory_TypeID = fk_Inventory_Types[i].value;
  }

  // Get the checkout type selection
  var bool_FairQ = document.getElementsByName('bool_FairQ');

  for( i = 0; i < bool_FairQ.length; i++ )
  {
    if( bool_FairQ[i].checked)
      var bool_FairQ_TypeID = bool_FairQ[i].value;
  }

  // Format any ampersands with URL friendly characters
  txt_Description = txt_Description.replace( /&/g, '%26' );
  vc_Tags = vc_Tags.replace( /&/g, '%26' );
  vc_FairQURL = vc_FairQURL.replace( /&/g, '%26' );

  // Create the parameter list
  var params = "pk_ID=" + pk_ID + "&vc_Title=" + vc_Title + "&fk_ArtistID=" + fk_ArtistID + "&fk_CountryID=" + fk_CountryID + "&txt_Description=" + txt_Description + "&fk_Inventory_TypeID=" + fk_Inventory_TypeID + "&vc_Tags=" + vc_Tags + "&int_Quantity=" + int_Quantity + "&int_Limit=" + int_Limit + "&fl_Price01=" + fl_Price01 + "&fl_Price02=" + fl_Price02 + "&fl_Shipping_Domestic01=" + fl_Shipping_Domestic01 + "&fl_Shipping_Domestic02=" + fl_Shipping_Domestic02 + "&fl_Shipping_Intl01=" + fl_Shipping_Intl01 + "&fl_Shipping_Intl02="  + fl_Shipping_Intl02 + "&int_DimX=" + int_DimX + "&int_DimY=" + int_DimY + "&int_DimZ=" + int_DimZ + "&int_Weight=" + int_Weight + "&bool_FairQ=" + bool_FairQ_TypeID + "&vc_FairQURL=" + vc_FairQURL;

  // Inform the user that the item is being submitted
  document.getElementById('Submit').value = 'Saving Inventory';

  // Process the AJAX POST request
  AJAX_POST( filename, params );

  // Update the form when the AJAX process finishes
  xmlhttp.onreadystatechange = function()
  {
    if( (xmlhttp.readyState == 4) && (xmlhttp.status == 200) )
    {
      // Toggle the submit button
      toggle_submit( 'Submit', 'Inventory Saved', 'Submit' );
    }
  }

}


function admin_toggle_inventory( pk_ID )
{
  // Set the backend filename to process
  var filename = 'modules/Admin/inventory/ajax_toggle_inventory.php';

  // Get the inventory types
  if( document.getElementById('bool_Active[' + pk_ID +']').checked == true )
    var bool_Active = 1;
  else
    var bool_Active = 0;

  // Create the parameter list
  var params = "pk_ID=" + pk_ID + "&bool_Active=" + bool_Active;

  // Process the AJAX POST request
  AJAX_POST( filename, params );

  // Update the form when the AJAX process finishes
  xmlhttp.onreadystatechange = function()
  {
    if( (xmlhttp.readyState == 4) && (xmlhttp.status == 200) )
    {
    }
  }

}




function admin_delete_inventory( ArtistID, pk_ID )
{
  // Send the confirmation 
  var remove = confirm( "Are you sure you want to delete this item?\n\nThis can not be undone." );

  if( remove == true )
    window.location = "index.php?module=Admin&page=inventory&subpage=delete&ArtistID= " + ArtistID + "&InventoryID=" + pk_ID;

}



function admin_inventory_quantity( pk_ID, op )
{
  // Set the backend filename to process
  var filename = 'modules/Admin/inventory/ajax_inventory_quantity.php';

  // Create the parameter list
  var params = "pk_ID=" + pk_ID + "&op=" + op;

  // Process the AJAX POST request
  AJAX_POST( filename, params );

  // Update the form when the AJAX process finishes
  xmlhttp.onreadystatechange = function()
  {
    if( (xmlhttp.readyState == 4) && (xmlhttp.status == 200) )
    {
      // Format the available as necessary
      if( xmlhttp.responseText == 0 )
        document.getElementById('inventory_available_' + pk_ID).innerHTML = '<em>Sold Out</em>';
      else
        document.getElementById('inventory_available_' + pk_ID).innerHTML = '<b>' + xmlhttp.responseText + '</b> available';
    }
  }

}

