function showCCFields(which)
  {
  var ccfields = document.getElementById("cc_fields");

  var cvv = document.getElementById("cvv");
  var showfields="";

  switch(which)
    {
    case 'AE':
      showfields = '<input name="cc1" id="cc1" style="width:35px;" maxlength="4" />'+
                   '<input name="cc2" id="cc2" style="width:45px;" maxlength="6" />'+
                   '<input name="cc3" id="cc3" style="width:40px;" maxlength="5" />';
      break;

    case 'Discover':
      showfields = '<input name="cc1" id="cc1" style="width:35px;" maxlength="4" />'+
                   '<input name="cc2" id="cc2" style="width:45px;" maxlength="6" />'+
                   '<input name="cc3" id="cc3" style="width:35px;" maxlength="4" />';
      break;

    case 'Visa':
    case 'MasterCard':
      showfields = '<input name="cc1" id="cc1" style="width:35px;" maxlength="4" />'+
                   '<input name="cc2" id="cc2" style="width:35px;" maxlength="4" />'+
                   '<input name="cc3" id="cc3" style="width:35px;" maxlength="4" />'+
                   '<input name="cc4" id="cc4" style="width:35px;" maxlength="4" />';
      break;

    default: showfields = '<div> Select a card type.</div>';
    }

  ccfields.innerHTML=showfields;

  if(which=="AE" || which=="MasterCard")
    {
    cvv.style.visibility = 'visible';
    document.getElementById("csc").style.visibility = 'visible';
    }
  else
    {
    cvv.style.visibility = 'hidden';
    document.getElementById("csc").style.visibility = 'hidden';
    document.getElementById("csc").value="";
    }
  }

function showInvoice(inv_num)
  {
  var current_invoice = document.getElementById("invoice"+inv_num);
  var next_invoice = document.getElementById("invoice"+(inv_num+1));

  current_invoice.value = trim(current_invoice.value);
  if(current_invoice.value.length > 0)
    next_invoice.disabled = false;
  }

// trims all spaces at the front, end and multiple spaces in the center
function trim(s) {
	s = s.replace(/(^\s*)|(\s*$)/gi,"");
	s = s.replace(/[ ]{2,}/gi," ");
	s = s.replace(/\n /,"\n");
	return s;
}