
//function used to update quantities if the run type is changed after the packaging type has been chosen
function update_quantity(passed){
  var update_variable;
  var route;

  if(document.getElementById('m_order_packaging_jewel_box').checked){
    update_variable = document.getElementById('m_order_packaging_jewel_box').value;
  }
  else if(document.getElementById('m_order_packaging_wallet').checked){
    update_variable = document.getElementById('m_order_packaging_wallet').value;
  }
  else if(document.getElementById('m_order_packaging_digi').checked){
    update_variable = document.getElementById('m_order_packaging_digi').value;
  }  
  if(document.getElementById('m_order_run').value == ''){
    route = 'none';
  }
  else{
    route = document.getElementById('m_order_run').value;
  }
  new Ajax.Updater('quant', '/manufacturing/quantity_option/' + route + '/' + update_variable + '/' + passed , {onComplete:function(){}, asynchronous:true, evalScripts:true});
}

//turn barcode options on and off
function barcode(){
  if(document.getElementById('m_order_upc').value.length == 12){  
    Element.show('generate_bc');
  }
  else{
    Element.hide('generate_bc');  
  }
}

function topspine(value){
  //alert('barcode');
  
  if(value == 'high run 10-day'){
    document.getElementById('xtopspine').style.display = '';
  }
  else{
    document.getElementById('xtopspine').style.display = 'none';
  }
}

function showOtherAmount_jb(){
  if(document.getElementById('quantity_jb').value == 'other amount'){
    document.getElementById('alt_quantity_jb').style.display = '';
    document.getElementById('alt_qlabel_jb').style.display = '';  
  }
  else{
    document.getElementById('alt_quantity_jb').style.display = 'none';
    document.getElementById('alt_qlabel_jb').style.display = 'none';
  }
}

function showOtherAmount_w(){
  if(document.getElementById('quantity_w').value == 'other amount'){
    document.getElementById('alt_quantity_w').style.display = '';
    document.getElementById('alt_qlabel_w').style.display = '';  
  }
  else{
    document.getElementById('alt_quantity_w').style.display = 'none';
    document.getElementById('alt_qlabel_w').style.display = 'none';
  }
}

function showOtherAmount_d(){
  if(document.getElementById('quantity_d').value == 'other amount'){
    document.getElementById('alt_quantity_d').style.display = '';
    document.getElementById('alt_qlabel_d').style.display = '';  
  }
  else{
    document.getElementById('alt_quantity_d').style.display = 'none';
    document.getElementById('alt_qlabel_d').style.display = 'none';
  }
}

function checkAddress(){
  if (document.getElementById('address_check').checked){
    sameShipping();
  }
  else{
    sameShippingOff();
  }
}

function sameShipping(){
  document.getElementById('manufacturing_order_shipping_name').value = document.getElementById('manufacturing_order_customer_name').value;
  document.getElementById('manufacturing_order_shipping_name').readOnly = true;
  document.getElementById('manufacturing_order_shipping_address').value = document.getElementById('manufacturing_order_address').value;
  document.getElementById('manufacturing_order_shipping_address').readOnly = true;
  document.getElementById('manufacturing_order_shipping_address2').value = document.getElementById('manufacturing_order_address2').value;
  document.getElementById('manufacturing_order_shipping_address2').readOnly = true;
  document.getElementById('manufacturing_order_shipping_address3').value = document.getElementById('manufacturing_order_address3').value;
  document.getElementById('manufacturing_order_shipping_address3').readOnly = true;
  document.getElementById('manufacturing_order_shipping_city').value = document.getElementById('manufacturing_order_city').value;
  document.getElementById('manufacturing_order_shipping_city').readOnly = true;
  document.getElementById('manufacturing_order_shipping_state').value = document.getElementById('manufacturing_order_state').value;
  document.getElementById('manufacturing_order_shipping_state').readOnly = true;
  document.getElementById('manufacturing_order_shipping_zip').value = document.getElementById('manufacturing_order_zip').value;
  document.getElementById('manufacturing_order_shipping_zip').readOnly = true;
}

function sameShippingOff(){
  document.getElementById('manufacturing_order_shipping_name').value = '';
  document.getElementById('manufacturing_order_shipping_name').readOnly = false;
  document.getElementById('manufacturing_order_shipping_address').value = '';
  document.getElementById('manufacturing_order_shipping_address').readOnly = false;
  document.getElementById('manufacturing_order_shipping_address2').value = '';
  document.getElementById('manufacturing_order_shipping_address2').readOnly = false;
  document.getElementById('manufacturing_order_shipping_address3').value = '';
  document.getElementById('manufacturing_order_shipping_address3').readOnly = false;
  document.getElementById('manufacturing_order_shipping_city').value = '';
  document.getElementById('manufacturing_order_shipping_city').readOnly = false;
  document.getElementById('manufacturing_order_shipping_state').value = '';
  document.getElementById('manufacturing_order_shipping_state').readOnly = false;
  document.getElementById('manufacturing_order_shipping_zip').value = '';
  document.getElementById('manufacturing_order_shipping_zip').readOnly = false;
}
