/**
 * Pop-up an info box for the credit card CVV.
 */
/*function cvv_info_popup() {
  var popup = window.open(Drupal.settings['base_path'] + 'credit/cvv_info', 'CVV_Info', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=480,height=460,left=282,top=122');
}*/

function gotoMain() {
  location.href = '/dashboard';
  return false;
  
}
function selectType(type) {
 
  if (type.value == 0) {
    title = 'Credit Card Number(Optional)';    
  } else {
    title = 'Credit Card Number';    
  }
  var item=document.getElementById('card-caption');
  
  var changeTitle = '<fieldset class=" collapsible"><legend>' + title + '</legend>';
  
  item.innerHtml = title;
  
}

/**
 * Hide or display the enter new credit card form.
 */
function vb_user_toggle_new_card(selection) {
  if (selection == '0') $('div.enter-new-credit-card').show();
  else $('div.enter-new-credit-card').hide();
}

function update_billing_field(field, address_book_path, delivery_path_length) {
  if (copy_box_checked) {
    $('#edit-' + address_book_path + field.id.substring(delivery_path_length)).val($(field).val());
  }
}

/**
 * Apply the selected address to the appropriate fields in the cart form.
 */

function vb_user_apply_address(type, address_str) {
  if (address_str == '0') {
    return;
  }

  eval('var address = ' + address_str + ';');
  var temp = type;
  
  $('#edit-' + temp + '-first-name').val(address.first_name).trigger('change');
  $('#edit-' + temp + '-last-name').val(address.last_name).trigger('change');
  $('#edit-' + temp + '-phone').val(address.phone).trigger('change');
  $('#edit-' + temp + '-company').val(address.company).trigger('change');
  $('#edit-' + temp + '-street1').val(address.street1).trigger('change');
  $('#edit-' + temp + '-street2').val(address.street2).trigger('change');
  $('#edit-' + temp + '-city').val(address.city).trigger('change');
  $('#edit-' + temp + '-postal-code').val(address.postal_code).trigger('change');

  if ($('#edit-' + temp + '-country').val() != address.country) {
    $('#edit-' + temp + '-country').val(address.country);
    try {
      uc_update_zone_select('edit-' + temp + '-country', address.zone);
    }
    catch (err) { }
  }

  $('#edit-' + temp + '-zone').val(address.zone).trigger('change');
}

function vb_user_toggleCompany(type) {
  if (type == 'American Express') {
    document.getElementById('edit-billing-company').disabled = false;
  } else {
    document.getElementById('edit-billing-company').disabled = true;
  }
}



/**
 * When the checkout page loads, if js is enabled, hide the enter new credit card form and setup thickbox pop-ups.
 */
if (Drupal.jsEnabled) {
  $(document).ready(function() {
    $('input[@name="panes[cim][cards]"]:checked').val() == 0 ? $('div.enter-new-credit-card').show() : $('div.enter-new-credit-card').hide();
    $('input[@name="cards"]:checked').val() == 0 ? $('div.enter-new-credit-card').show() : $('div.enter-new-credit-card').hide();    
  })
}

