// $Id$

/**
 * @file
 * Customer-facing JavaScript for UC Variable Price.
 */
Drupal.behaviors.ucVarPriceShowArb = function(context) {
  var varpriceSel = $('#edit-varprice-sel');
  if (varpriceSel.length) {
    // Using drop-down menu
    if (varpriceSel.val() !== 'other') {
      $('#edit-varprice-arb-wrapper:not(.processed)').addClass('processed').hide();
    }
    varpriceSel.change(function() {
      if ($(this).val() === 'other') {
        $('#edit-varprice-arb-wrapper').show('fast');
        $('#edit-varprice-arb').focus();
      }
      else {
        $('#edit-varprice-arb-wrapper').hide('fast');
      }
    });
  }
  else {
    // Using radio buttons
    if ($('input[name="varprice_sel"]:checked').val() !== 'other') {
      $('#edit-varprice-arb-wrapper:not(.processed)').addClass('processed').hide();
    }
    $('input[name="varprice_sel"]').change(function() {
      if ($('input[name="varprice_sel"]:checked').val() === 'other') {
        $('#edit-varprice-arb-wrapper').show('fast');
        $('#edit-varprice-arb').focus();
      }
      else {
        $('#edit-varprice-arb-wrapper').hide('fast');
      }
    });
    
  }
};
Drupal.behaviors.ucVarPriceShowArb = function(context) {
  var varpriceSel = $('#edit-varprice-sel-1');
  if (varpriceSel.length) {
    // Using drop-down menu
    if (varpriceSel.val() !== 'other') {
      $('#edit-varprice-arb-wrapper:not(.processedtwo)').addClass('processedtwo').hide();
    }
    varpriceSel.change(function() {
      if ($(this).val() === 'other') {
        $('#edit-varprice-arb-wrapper').show('fast');
        $('#edit-varprice-arb').focus();
      }
      else {
        $('#edit-varprice-arb-wrapper').hide('fast');
      }
    });
  }
  else {
    // Using radio buttons
    if ($('input[name="varprice_sel"]:checked').val() !== 'other') {
      $('#edit-varprice-arb-wrapper:not(.processedtwo)').addClass('processedtwo').hide();
    }
    $('input[name="varprice_sel"]').change(function() {
      if ($('input[name="varprice_sel"]:checked').val() === 'other') {
        $('#edit-varprice-arb-wrapper').show('fast');
        $('#edit-varprice-arb').focus();
      }
      else {
        $('#edit-varprice-arb-wrapper').hide('fast');
      }
    });
    
  }
};
Drupal.behaviors.ucVarPriceShowArb = function(context) {
  var varpriceSel = $('#edit-varprice-sel-2');
  if (varpriceSel.length) {
    // Using drop-down menu
    if (varpriceSel.val() !== 'other') {
      $('#edit-varprice-arb-1-wrapper:not(.processedthree)').addClass('processedthree').hide();
    }
    varpriceSel.change(function() {
      if ($(this).val() === 'other') {
        $('#edit-varprice-arb-1-wrapper').show('fast');
        $('#edit-varprice-arb-1').focus();
      }
      else {
        $('#edit-varprice-arb-1-wrapper').hide('fast');
      }
    });
  }
  else {
    // Using radio buttons
    if ($('input[name="varprice_sel"]:checked').val() !== 'other') {
      $('#edit-varprice-arb-1-wrapper:not(.processedthree)').addClass('processedthree').hide();
    }
    $('input[name="varprice_sel"]').change(function() {
      if ($('input[name="varprice_sel"]:checked').val() === 'other') {
        $('#edit-varprice-arb-1-wrapper').show('fast');
        $('#edit-varprice-arb-1').focus();
      }
      else {
        $('#edit-varprice-arb-1-wrapper').hide('fast');
      }
    });
    
  }
};
