
/* Currency Exchange Rates */
exchange_rate_USD = 1.0;
exchange_rate_CAD = 1.069;
exchange_rate_JPY = 91.249;
exchange_rate_GBP = 0.612;
exchange_rate_EUR = 0.676;
exchange_rate_AUD = 1.146;
exchange_rate_NZD = 1.389;
exchange_rate_HKD = 7.75;
exchange_rate_SGD = 1.412;
exchange_rate_CHF = 1.022;
exchange_rate_SEK = 6.815;
exchange_rate_NOK = 5.819;
exchange_rate_DKK = 5.03;
exchange_rate_PLN = 2.811;
exchange_rate_HUF = 183.655;
exchange_rate_CZK = 17.02;

/* PayPal Fixed Fees */
paypal_fixed_fee_same_USD = paypal_fixed_fee_different_USD = 0.30;
paypal_fixed_fee_same_CAD = paypal_fixed_fee_different_CAD = 0.30;
paypal_fixed_fee_same_JPY = paypal_fixed_fee_different_JPY = 40;
paypal_fixed_fee_same_GBP = paypal_fixed_fee_different_GBP = 0.20;
paypal_fixed_fee_same_EUR = paypal_fixed_fee_different_EUR = 0.35;
paypal_fixed_fee_same_FR_EUR = 0.25; // France, French Guiana, Guadeloupe, Martinique, Reunion (EUR)
paypal_fixed_fee_same_AUD = 0.30; paypal_fixed_fee_different_AUD = 0.40;
paypal_fixed_fee_same_NZD = paypal_fixed_fee_different_NZD = 0.45;
paypal_fixed_fee_same_HKD = paypal_fixed_fee_different_HKD = 2.35;
paypal_fixed_fee_same_SGD = paypal_fixed_fee_different_SGD = 0.50;
paypal_fixed_fee_same_CHF = paypal_fixed_fee_different_CHF = 0.55;
paypal_fixed_fee_same_SEK = paypal_fixed_fee_different_SEK = 3.25;
paypal_fixed_fee_same_NOK = paypal_fixed_fee_different_NOK = 2.80;
paypal_fixed_fee_same_DKK = paypal_fixed_fee_different_DKK = 2.60;
paypal_fixed_fee_same_PLN = paypal_fixed_fee_different_PLN = 1.35;
paypal_fixed_fee_same_HUF = paypal_fixed_fee_different_HUF = 90;
paypal_fixed_fee_same_CZK = paypal_fixed_fee_different_CZK = 10.00;

/* PayPal Maximum eCheck Fees */
var paypal_max_echeck_fee_USD = 5.00;
var paypal_max_echeck_fee_CAD = 7.50;
var paypal_max_echeck_fee_JPY = 650;
var paypal_max_echeck_fee_GBP = 3.50;
var paypal_max_echeck_fee_EUR = 5.00;
var paypal_max_echeck_fee_AUD = 7.50;
var paypal_max_echeck_fee_NZD = 7.50;
var paypal_max_echeck_fee_HKD = 38.00;
var paypal_max_echeck_fee_SGD = 8.00;
var paypal_max_echeck_fee_CHF = 6.50;
var paypal_max_echeck_fee_SEK = 40.00;
var paypal_max_echeck_fee_NOK = 33.00;
var paypal_max_echeck_fee_DKK = 30.00;
var paypal_max_echeck_fee_PLN = 16.00;
var paypal_max_echeck_fee_HUF = 1000;
var paypal_max_echeck_fee_CZK = 120.00;

var old_paypal_percentage = '2.9-3.9'.split("-")[0];
var old_paypal_fixed_fee = paypal_fixed_fee_same_USD;

/* Element Variables */
var source_country_dropdown, source_currency_dropdown, dest_country_dropdown, dest_currency_dropdown;
var monthly_sales_volume_dropdown = new Array(17);
var paypal_percentage_textbox, paypal_fixed_fee_textbox;
var currency_exchange_rate_textbox, currency_exchange_rate_dropdown, micropayments_checkbox;
var personal_account_checkbox, include_cc_fee_checkbox, echeck_payment_checkbox;
var if_a_person_sends_you_textbox, your_pp_fees_would_be_textbox, and_you_would_receive_textbox;
var to_receive_textbox, a_person_would_textbox, convert_from_textbox, convert_from_dropdown;
var convert_to_textbox, convert_to_dropdown, pp_calc_clear, pp_calc_calculate, rpp_calc_clear, rpp_calc_calculate;
var conv_currency_clear, conv_currency_convert;
var i,f;

if (window.addEventListener) { window.addEventListener("load", window_onload, false); }
else if (window.attachEvent) { window.attachEvent("onload", window_onload); }

function window_onload() {

 document.forms['close_button_form'].elements['close_button'].onclick = close_paypal_steps_clicked;
 document.forms['reverse_close_button_form'].elements['reverse_close_button'].onclick = close_reverse_paypal_steps_clicked;

 f = document.forms['ppcalc_form'];
 source_country_dropdown = f.elements['source_country'];
 source_currency_dropdown = f.elements['source_currency'];
 dest_country_dropdown = f.elements['destination_country'];
 dest_currency_dropdown = f.elements['destination_currency'];
 monthly_sales_volume_dropdown[0] = f.elements['monthly_sales_volume_USD'];
 monthly_sales_volume_dropdown[1] = f.elements['monthly_sales_volume_CAD'];
 monthly_sales_volume_dropdown[2] = f.elements['monthly_sales_volume_JPY'];
 monthly_sales_volume_dropdown[3] = f.elements['monthly_sales_volume_GBP'];
 monthly_sales_volume_dropdown[4] = f.elements['monthly_sales_volume_EUR'];
 monthly_sales_volume_dropdown[5] = f.elements['monthly_sales_volume_AUD'];
 monthly_sales_volume_dropdown[6] = f.elements['monthly_sales_volume_NZD'];
 monthly_sales_volume_dropdown[7] = f.elements['monthly_sales_volume_HKD'];
 monthly_sales_volume_dropdown[8] = f.elements['monthly_sales_volume_SGD'];
 monthly_sales_volume_dropdown[9] = f.elements['monthly_sales_volume_CHF'];
 monthly_sales_volume_dropdown[10] = f.elements['monthly_sales_volume_SEK'];
 monthly_sales_volume_dropdown[11] = f.elements['monthly_sales_volume_NOK'];
 monthly_sales_volume_dropdown[12] = f.elements['monthly_sales_volume_DKK'];
 monthly_sales_volume_dropdown[13] = f.elements['monthly_sales_volume_PLN'];
 monthly_sales_volume_dropdown[14] = f.elements['monthly_sales_volume_HUF'];
 monthly_sales_volume_dropdown[15] = f.elements['monthly_sales_volume_CZK'];
 monthly_sales_volume_dropdown[16] = f.elements['monthly_sales_volume_DE'];
 paypal_percentage_textbox = f.elements['paypal_fee_percentage'];
 paypal_fixed_fee_textbox = f.elements['paypal_fixed_fee'];
 currency_exchange_rate_textbox = f.elements['one_usd_equals'];
 currency_exchange_rate_dropdown = f.elements['currency_exchange_dropdown'];
 micropayments_checkbox = f.elements['digital_goods_rate'];
 personal_account_checkbox = f.elements['personal_account_cc_rate'];
 include_cc_fee_checkbox = f.elements['include_cc_fee'];
 echeck_payment_checkbox = f.elements['echeck_payment'];
 if_a_person_sends_you_textbox = f.elements['PPCalcInput1'];
 your_pp_fees_would_be_textbox = f.elements['PPCalcInput2'];
 and_you_would_receive_textbox = f.elements['PPCalcInput3'];
 to_receive_textbox = f.elements['RPPCalcInput1'];
 a_person_would_textbox = f.elements['RPPCalcInput2'];
 convert_from_textbox = f.elements['CCCalcInput1'];
 convert_from_dropdown = f.elements['convert_from_currency'];
 convert_to_textbox = f.elements['CCCalcInput2'];
 convert_to_dropdown = f.elements['convert_to_currency'];
 pp_calc_clear = f.elements['paypal_calculator_clear'];
 pp_calc_calculate = f.elements['paypal_calculator_calculate'];
 rpp_calc_clear = f.elements['reverse_paypal_calculator_clear'];
 rpp_calc_calculate = f.elements['reverse_paypal_calculator_calculate'];
 conv_currency_clear = f.elements['currency_converter_clear'];
 conv_currency_convert = f.elements['currency_converter_convert'];

 currency_exchange_rate_textbox.value = exchange_rate_CAD;

 for (i=0;i<monthly_sales_volume_dropdown.length;i++) {
  monthly_sales_volume_dropdown[i].onchange = monthly_sales_volume_changed;
  monthly_sales_volume_dropdown[i].onkeyup = monthly_sales_volume_changed;
 }

 // onblur
 currency_exchange_rate_textbox.onblur = exchange_rate_box_lost_focus;

 // onchange
 source_country_dropdown.onchange = country_changed;
 source_currency_dropdown.onchange = currency_changed;
 dest_country_dropdown.onchange = country_changed;
 dest_currency_dropdown.onchange = currency_changed;
 convert_from_dropdown.onchange = currency_converter_currency_changed;
 convert_to_dropdown.onchange = currency_converter_currency_changed;
 currency_exchange_rate_dropdown.onchange = currency_exchange_rates_dropdown_onchange;

 // onkeyup
 source_country_dropdown.onkeyup = country_changed;
 source_currency_dropdown.onkeyup = currency_changed;
 dest_country_dropdown.onkeyup = country_changed;
 dest_currency_dropdown.onkeyup = currency_changed;
 convert_from_dropdown.onkeyup = currency_converter_currency_changed;
 convert_to_dropdown.onkeyup = currency_converter_currency_changed;
 currency_exchange_rate_dropdown.onkeyup = currency_exchange_rates_dropdown_onchange;

 // onkeypress
 paypal_percentage_textbox.onkeypress = textbox_onkeypress;
 paypal_fixed_fee_textbox.onkeypress = textbox_onkeypress;
 currency_exchange_rate_textbox.onkeypress = textbox_onkeypress;
 if_a_person_sends_you_textbox.onkeypress = textbox_onkeypress;
 to_receive_textbox.onkeypress = textbox_onkeypress;
 convert_from_textbox.onkeypress = textbox_onkeypress;

 // onclick
 pp_calc_clear.onclick = paypal_calculator_clear_clicked;
 rpp_calc_clear.onclick = reverse_paypal_calculator_clear_clicked;
 conv_currency_clear.onclick = currency_converter_clear_clicked;

 pp_calc_calculate.onclick = PPCalculate;
 rpp_calc_calculate.onclick = RPPCalculate;
 conv_currency_convert.onclick = currency_converter_convert_clicked;

 micropayments_checkbox.onclick = use_digital_goods_rate_clicked;
 personal_account_checkbox.onclick = use_personal_account_cc_rate_clicked;
 include_cc_fee_checkbox.onclick = include_cc_fee_clicked;

 document.getElementById('fees_breakdown_link_1').onclick = show_paypal_fees_breakdown;
 document.getElementById('fees_breakdown_link_2').onclick = show_reverse_paypal_fees_breakdown;

 monthly_sales_volume_changed();
 if_a_person_sends_you_textbox.focus();
}

/* Validation Functions */
/* -------------------------------------------------------------------------------------------- */
function zkwbvpsh(){
 return true;
 /*
 var r = false;
 if (window.location.href.toLowerCase().indexOf('ppcalc') != -1) { r=true; }
 return r;
 */
}
/* -------------------------------------------------------------------------------------------- */


function get_max_echeck_fee() {
 eval("var max_fee = paypal_max_echeck_fee_" + dest_currency_dropdown.value);
 return max_fee;
}

function get_currency_symbol(currency_word) {
 var to_return = '';
 switch (currency_word) {
  case 'USD': case 'CAD': case 'AUD': case 'NZD': case 'HKD': case 'SGD': to_return = '$'; break;
  case 'GBP': to_return = '&pound;'; break;
  case 'EUR': to_return = '&euro;'; break;
  case 'JPY': to_return = '&yen;'; break;
  case 'CHF': case 'SEK': case 'NOK': case 'DKK': case 'PLN': case 'HUF': case 'CZK': to_return = ''; break;
  default: to_return = '';
 }
 return to_return;
}

function is_european_union(country) {
 var to_return = false;
 switch (country) {
  case 'LU': case 'IE': case 'DK': case 'AT': case 'FI': case 'BE': case 'NL': case 'GB': case 'DE': case 'SE': case 'FR':
  case 'IT': case 'ES': case 'GR': case 'SI': case 'CY': case 'MT': case 'PT': case 'CZ': case 'EE': case 'HU': case 'SK':
  case 'LT': case 'LV': case 'PL': case 'BG': case 'RO':
  case 'AD': case 'GF': case 'GP': case 'MQ': case 'YT': case 'RE': case 'PM':
   to_return = true; break;
  default:
   to_return = false;
 }
 return to_return;
}

function is_euro_domestic() {
 var to_return = false;
 if ((source_currency_dropdown.value == 'EUR') && (dest_currency_dropdown.value == 'EUR')) {
  if ((is_european_union(source_country_dropdown.value) == true) && (is_european_union(dest_country_dropdown.value) == true)) {
   to_return = true;
  }
 }
 return to_return;
}

function currency_exchange_rates_dropdown_onchange() {
 eval("currency_exchange_rate_textbox.value = exchange_rate_" + currency_exchange_rate_dropdown.value);
}

function exchange_rate_box_lost_focus() {
 this.style.backgroundColor = '#FFFFFF';
 eval("exchange_rate_" + currency_exchange_rate_dropdown.value + " = get_float(currency_exchange_rate_textbox.value)");
}

function paypal_calculator_clear_clicked() {
 if_a_person_sends_you_textbox.value = '';
 your_pp_fees_would_be_textbox.value = '';
 and_you_would_receive_textbox.value = '';
 your_pp_fees_would_be_textbox.style.backgroundColor = '#E6E6E6';
 and_you_would_receive_textbox.style.backgroundColor = '#E6E6E6';
 document.getElementById('breakdown_icon').style.left = '-3000px';  // hide fees breakdown
 document.getElementById('breakdown_icon').style.top = '-3000px';
 document.getElementById('fees_breakdown_link_1').style.left = '-3000px';
 document.getElementById('fees_breakdown_link_1').style.top = '-3000px';
 if_a_person_sends_you_textbox.focus();
}

function reverse_paypal_calculator_clear_clicked() {
 to_receive_textbox.value = '';
 a_person_would_textbox.value = '';
 a_person_would_textbox.style.backgroundColor = '#E6E6E6';
 document.getElementById('reverse_breakdown_icon').style.left = '-3000px';  // hide reverse fees breakdown
 document.getElementById('reverse_breakdown_icon').style.top = '-3000px';
 document.getElementById('fees_breakdown_link_2').style.left = '-3000px';
 document.getElementById('fees_breakdown_link_2').style.top = '-3000px';
 to_receive_textbox.focus();
}

function currency_converter_clear_clicked() {
 convert_from_textbox.value = '';
 convert_to_textbox.value = '';
 convert_to_textbox.style.backgroundColor = '#E6E6E6';
 convert_from_textbox.focus();
}

function currency_converter_convert_clicked() {
 var amount_to_convert = get_float(convert_from_textbox.value);
 var converted_amount = 0.00;
 if (amount_to_convert == 0) { convert_from_textbox.value = '0.00'; }
 if (convert_from_dropdown.selectedIndex == convert_to_dropdown.selectedIndex) {
  convert_to_textbox.value = amount_to_convert.toFixed(2);
 }
 else {
  converted_amount = convert_currency(amount_to_convert, convert_from_dropdown.value, convert_to_dropdown.value);
  convert_to_textbox.value = converted_amount.toFixed(2);
 }
 convert_to_textbox.style.backgroundColor = '#FFFFCF'; // #D8FFD8 or #FFFFCF
}

function use_digital_goods_rate_clicked() {
 if (micropayments_checkbox.checked == true) {
  old_paypal_percentage = paypal_percentage_textbox.value;
  old_paypal_fixed_fee = paypal_fixed_fee_textbox.value;
  paypal_percentage_textbox.value = '5.0';
  paypal_fixed_fee_textbox.value = '0.05';
 }
 else {
  paypal_percentage_textbox.value = old_paypal_percentage;
  paypal_fixed_fee_textbox.value = old_paypal_fixed_fee;
 }
}

function include_cc_fee_clicked() {
 if (include_cc_fee_checkbox.checked == true) {
  old_paypal_percentage = paypal_percentage_textbox.value;
  paypal_percentage_textbox.value = (get_float(old_paypal_percentage) + 2.5).toFixed(1);
 }
 else {
  paypal_percentage_textbox.value = old_paypal_percentage;
  monthly_sales_volume_changed();
 }
}

function find_personal_account_cc_rate(original_percentage) {
  var the_new_percentage = '3.4';
  if (is_european_union(dest_country_dropdown.value) == true) { the_new_percentage = '5.4'; }
  else if (dest_country_dropdown.value == 'US') { the_new_percentage = '4.9'; }
  else if (dest_country_dropdown.value == 'CA') { the_new_percentage = '4.9'; }
  else { the_new_percentage = '5.4'; }
  if ((source_country_dropdown.value == 'US') && (dest_country_dropdown.value == 'CA')) {}
  else if ((is_european_union(source_country_dropdown.value) == true) && (is_european_union(dest_country_dropdown.value) == true)) {}
  else if ((source_country_dropdown.value == 'IE') && (dest_country_dropdown.value == 'IE')) { the_new_percentage = '5.4'; }
  else if ((source_country_dropdown.value == 'AU') && (dest_country_dropdown.value == 'AU')) { the_new_percentage = '3.4'; }
  else if ((source_country_dropdown.value != 'AU') && (dest_country_dropdown.value == 'AU')) { the_new_percentage = '4.4'; }
  else if ((source_country_dropdown.value == 'PL') && (dest_country_dropdown.value == 'PL')) { the_new_percentage = '5.4'; }
  else if (dest_country_dropdown.value != source_country_dropdown.value) {
   the_new_percentage = original_percentage + 2;
  }
 return the_new_percentage;
}

function use_personal_account_cc_rate_clicked() {
 if (personal_account_checkbox.checked == true) {
  old_paypal_percentage = paypal_percentage_textbox.value;
  var the_new_percentage = find_personal_account_cc_rate(get_float(old_paypal_percentage));
  paypal_percentage_textbox.value = the_new_percentage;
 }
 else {
  paypal_percentage_textbox.value = old_paypal_percentage;
 }
}

function show_paypal_fees_breakdown() { document.getElementById('paypal_steps').style.display = 'block'; }
function close_paypal_steps_clicked() { document.getElementById('paypal_steps').style.display = 'none'; }

function show_reverse_paypal_fees_breakdown() { document.getElementById('reverse_paypal_steps').style.display = 'block'; }
function close_reverse_paypal_steps_clicked() { document.getElementById('reverse_paypal_steps').style.display = 'none'; }

function currency_converter_currency_changed() {
 document.getElementById('CCCalcInput1_currency_symbol').innerHTML = get_currency_symbol(convert_from_dropdown.value);
 document.getElementById('CCCalcInput2_currency_symbol').innerHTML = get_currency_symbol(convert_to_dropdown.value);
}

function currency_changed() {
 for (i=0;i<monthly_sales_volume_dropdown.length;i++) {
  monthly_sales_volume_dropdown[i].style.display = 'none';
 }
 if (dest_country_dropdown.value == 'DE') {
  monthly_sales_volume_dropdown[16].style.display = 'block';
 }
 else {
  monthly_sales_volume_dropdown[dest_currency_dropdown.selectedIndex].style.display = 'block';
 }

 document.getElementById('paypal_fixed_fee_currency').innerHTML = dest_currency_dropdown.value;
 document.getElementById('PPCalcInput1_currency').innerHTML = source_currency_dropdown.value;
 document.getElementById('PPCalcInput2_currency').innerHTML = dest_currency_dropdown.value;
 document.getElementById('PPCalcInput3_currency').innerHTML = dest_currency_dropdown.value;
 document.getElementById('RPPCalcInput1_currency').innerHTML = dest_currency_dropdown.value;
 document.getElementById('RPPCalcInput2_currency').innerHTML = source_currency_dropdown.value;

 var currency_sign = get_currency_symbol(dest_currency_dropdown.value);
 var src_currency_sign = get_currency_symbol(source_currency_dropdown.value);

 document.getElementById('PPCalcInput1_currency_symbol').innerHTML = src_currency_sign;
 document.getElementById('PPCalcInput2_currency_symbol').innerHTML = currency_sign;
 document.getElementById('PPCalcInput3_currency_symbol').innerHTML = currency_sign;
 document.getElementById('RPPCalcInput1_currency_symbol').innerHTML = currency_sign;
 document.getElementById('RPPCalcInput2_currency_symbol').innerHTML = src_currency_sign;
 document.getElementById('paypal_currency_sign').innerHTML = '% + ' + currency_sign;

 include_cc_fee_checkbox.checked = (source_currency_dropdown.value != dest_currency_dropdown.value) ? true : false;
 include_cc_fee_clicked();
 monthly_sales_volume_changed();
}

function monthly_sales_volume_changed() {
 var monthly_sales_dropdown = monthly_sales_volume_dropdown[dest_currency_dropdown.selectedIndex];
 if (dest_country_dropdown.value == 'DE') { monthly_sales_dropdown = monthly_sales_volume_dropdown[16]; }
  
 var rate_pieces = monthly_sales_dropdown.value.split("-");
 var fee_percent = '0.0';

 // set the paypal fixed fee
 if (micropayments_checkbox.checked == true) {
  paypal_fixed_fee_textbox.value = '0.05';
 }
 else if (((dest_country_dropdown.value == 'FR') || (dest_country_dropdown.value == 'GF') || (dest_country_dropdown.value == 'GP') || (dest_country_dropdown.value == 'MQ') || (dest_country_dropdown.value == 'RE')) && (dest_currency_dropdown.value == 'EUR')) {
  paypal_fixed_fee_textbox.value = paypal_fixed_fee_same_FR_EUR.toFixed(2);
 }
 else if (source_currency_dropdown.value == dest_currency_dropdown.value) {
  eval("paypal_fixed_fee_textbox.value = paypal_fixed_fee_same_" + dest_currency_dropdown.value + ".toFixed(2)");
 }
 else {
  eval("paypal_fixed_fee_textbox.value = paypal_fixed_fee_different_" + dest_currency_dropdown.value + ".toFixed(2)");
 }

 if ((source_country_dropdown.selectedIndex == dest_country_dropdown.selectedIndex) || (is_euro_domestic() == true)) {
  fee_percent = rate_pieces[0];
 }
 else if ((source_country_dropdown.value == 'US') && (dest_country_dropdown.value == 'CA')) {
  fee_percent = rate_pieces[0];
 }
 else {
  fee_percent = rate_pieces[1];
 }

 /********** Special Case for Italy ************/
 if ((source_country_dropdown.value == "IT") && (dest_country_dropdown.value == "IT")) {
  switch (monthly_sales_dropdown.selectedIndex) {
   case 0: fee_percent = '3.4'; break;
   case 1: fee_percent = '2.7'; break;
   case 2: fee_percent = '2.2'; break;
   case 3: fee_percent = '2.2'; break;
   case 4: fee_percent = '1.8'; break;
   default: fee_percent = '3.4';
  }
 }
 /*********************************************/

 /********* Special Case for France ***********/
 else if ((source_country_dropdown.value == "FR") && (dest_country_dropdown.value == "FR")) {
  switch (monthly_sales_dropdown.selectedIndex) {
   case 0: fee_percent = '3.4'; break;
   case 1: fee_percent = '2.0'; break;
   case 2: fee_percent = '1.8'; break;
   case 3: fee_percent = '1.6'; break;
   case 4: fee_percent = '1.4'; break;
   default: fee_percent = '3.4';
  }
 }
 /*******************************************/

 /********* Special Case for Germany (Germany to Germany) ***********/
 else if ((source_country_dropdown.value == "DE") && (dest_country_dropdown.value == "DE")) {
  switch (monthly_sales_dropdown.selectedIndex) {
   case 0: fee_percent = '1.9'; break;
   case 1: fee_percent = '1.7'; break;
   case 2: fee_percent = '1.5'; break;
   case 3: fee_percent = '1.2'; break;
   case 4: fee_percent = '1.2'; break;
   default: fee_percent = '1.9';
  }
 }
 /*******************************************************************/

 /********* Special Case for Germany (Europe to Germany) ***********/
 else if ((is_european_union(source_country_dropdown.value) == true) && (dest_country_dropdown.value == "DE")) {
  switch (monthly_sales_dropdown.selectedIndex) {
   case 0: fee_percent = '1.9'; break;
   case 1: fee_percent = '1.7'; break;
   case 2: fee_percent = '1.5'; break;
   case 3: fee_percent = '1.2'; break;
   case 4: fee_percent = '1.2'; break;
   default: fee_percent = '1.9';
  }
 }
 /*******************************************************************/

 /********* Special Case for Germany (Non Europe to Germany) ***********/
 else if ((is_european_union(source_country_dropdown.value) == false) && (dest_country_dropdown.value == "DE")) {
  switch (monthly_sales_dropdown.selectedIndex) {
   case 0: fee_percent = '3.9'; break;
   case 1: fee_percent = '3.7'; break;
   case 2: fee_percent = '3.5'; break;
   case 3: fee_percent = '3.2'; break;
   case 4: fee_percent = '3.2'; break;
   default: fee_percent = '3.9';
  }
 }
 /*******************************************************************/

 // Add additional percents to fee_percent
 if (include_cc_fee_checkbox.checked == true) { fee_percent = (get_float(fee_percent) + 2.5).toFixed(1); }
 if (personal_account_checkbox.checked == true) { fee_percent = find_personal_account_cc_rate(get_float(fee_percent)); }
 if (micropayments_checkbox.checked == true) { fee_percent = '5.0'; }

 paypal_percentage_textbox.value = fee_percent;

}

function country_changed() {
 var is_source_country = false;
 var the_country_dropdown = dest_country_dropdown;
 var currency_selection = -1;
 if (this.id == 'source_country') { is_source_country = true; the_country_dropdown = source_country_dropdown; }
 switch (the_country_dropdown.value) {
  case 'US': currency_selection = 0; break;  // United States = US Dollar (USD)
  case 'VG': currency_selection = 0; break;  // British Virgin Islands = US Dollar (USD)
  case 'EC': currency_selection = 0; break;  // Ecuador = US Dollar (USD)
  case 'WS': currency_selection = 0; break;  // Samoa = US dollar (USD)
  case 'TC': currency_selection = 0; break;  // Turks and Caicos Islands = US Dollar (USD)
  case 'CA': currency_selection = 1; break;  // Canada = Canadian Dollar (CAD)
  case 'JP': currency_selection = 2; break;  // Japan = Japanese Yen (JPY)
  case 'GB': currency_selection = 3; break;  // United Kingdom = British Pound (GBP)
  case 'AD': currency_selection = 4; break;  // Andorra = Euro (EUR)
  case 'AT': currency_selection = 4; break;  // Austria = Euro (EUR)
  case 'BE': currency_selection = 4; break;  // Belgium = Euro (EUR)
  case 'FI': currency_selection = 4; break;  // Finland = Euro (EUR)
  case 'FR': currency_selection = 4; break;  // France = Euro (EUR)
  case 'GF': currency_selection = 4; break;  // French Guiana = Euro (EUR)
  case 'DE': currency_selection = 4; break;  // Germany = Euro (EUR)
  case 'GR': currency_selection = 4; break;  // Greece = Euro (EUR)
  case 'GP': currency_selection = 4; break;  // Guadeloupe = Euro (EUR)
  case 'IE': currency_selection = 4; break;  // Ireland = Euro (EUR)
  case 'IT': currency_selection = 4; break;  // Italy = Euro (EUR)
  case 'LU': currency_selection = 4; break;  // Luxembourg = Euro (EUR)
  case 'MQ': currency_selection = 4; break;  // Martinique = Euro (EUR)
  case 'YT': currency_selection = 4; break;  // Mayotte = Euro (EUR)
  case 'NL': currency_selection = 4; break;  // Netherlands = Euro (EUR)
  case 'PT': currency_selection = 4; break;  // Portugal = Euro (EUR)
  case 'RE': currency_selection = 4; break;  // Reunion = Euro (EUR)
  case 'SI': currency_selection = 4; break;  // Slovenia = Euro (EUR)
  case 'ES': currency_selection = 4; break;  // Spain = Euro (EUR)
  case 'PM': currency_selection = 4; break;  // St. Pierre and Miquelon = Euro (EUR)
  case 'AU': currency_selection = 5; break;  // Australia = Australian Dollar (AUD)
  case 'NZ': currency_selection = 6; break;  // New Zealand = New Zealand Dollar (NZD)
  case 'PN': currency_selection = 6; break;  // Pitcairn Islands = New Zealand Dollar (NZD)
  case 'HK': currency_selection = 7; break;  // Hong Kong = Hong Kong Dollar (HKD)
  case 'SG': currency_selection = 8; break;  // Singapore = Singapore Dollar (SGD)
  case 'LI': currency_selection = 9; break;  // Liechtenstein = Swiss Franc (CHF)
  case 'CH': currency_selection = 9; break;  // Switzerland = Swiss Franc (CHF)
  case 'SE': currency_selection = 10; break; // Sweden = Swedish Krona (SEK)
  case 'NO': currency_selection = 11; break; // Norway = Norwegian Krone (NOK)
  case 'DK': currency_selection = 12; break; // Denmark = Danish Krone (DKK)
  case 'PL': currency_selection = 13; break; // Poland = Polish Zloty (PLN)
  case 'HU': currency_selection = 14; break; // Hungary = Hungarian Forint (HUF)
  case 'CZ': currency_selection = 15; break; // Czech Republic = Czech Koruna (CZK)
  case 'AI': currency_selection = 0; break; // Anguilla = East Caribbean dollar (XCD)
  case 'AR': currency_selection = 0; break; // Argentina = Argentine Peso (ARS)
  case 'AW': currency_selection = 0; break; // Aruba = Aruban guilder/florin (AWG)
  case 'BS': currency_selection = 0; break; // Bahamas = Bahamian dollar (BSD)
  case 'BH': currency_selection = 0; break; // Bahrain = Bahraini dinar (BHD)
  case 'BB': currency_selection = 0; break; // Barbados = Barbadian dollar (BBD)
  case 'BM': currency_selection = 0; break; // Bermuda = Bermudian dollar (BMD)
  case 'BW': currency_selection = 0; break; // Botswana = Pula (BWP)
  case 'BR': currency_selection = 0; break; // Brazil = Real (BRL)
  case 'BN': currency_selection = 0; break; // Brunei = Bruneian dollar (BND)
  case 'CV': currency_selection = 0; break; // Cape Verde = Cape Verdean Escudo (CVE)
  case 'KY': currency_selection = 0; break; // Cayman Islands = Caymanian dollar (KYD)
  case 'CL': currency_selection = 0; break; // Chile = Chilean Peso (CLP)
  case 'C2': currency_selection = 0; break; // China = Yuan (CNY)
  case 'CR': currency_selection = 0; break; // Costa Rica = Costa Rican Colon (CRC)
  case 'HR': currency_selection = 0; break; // Croatia = Kuna (HRK)
  case 'CY': currency_selection = 0; break; // Cyprus = Cypriot pound (CYP)
  case 'DO': currency_selection = 0; break; // Dominican Republic = Dominican Peso (DOP)
  case 'EE': currency_selection = 0; break; // Estonia = Estonian Kroon (EEK)
  case 'FK': currency_selection = 0; break; // Falkland Islands = Falkland Pound (FKP)
  case 'FJ': currency_selection = 0; break; // Fiji = Fijian dollar (FJD)
  case 'PF': currency_selection = 0; break; // French Polynesia = Comptoirs Francais du Pacifique franc (XPF)
  case 'GI': currency_selection = 0; break; // Gibraltar = Gibraltar Pound (GIP)
  case 'IS': currency_selection = 0; break; // Iceland = Icelandic Krona (ISK)
  case 'IN': currency_selection = 0; break; // India = Indian Rupee (INR)
  case 'ID': currency_selection = 0; break; // Indonesia = Indonesian Rupiah (IDR)
  case 'IL': currency_selection = 0; break; // Israel = New Israeli Shekel (ILS)
  case 'JM': currency_selection = 0; break; // Jamaica = Jamaican dollar (JMD)
  case 'JO': currency_selection = 0; break; // Jordan = Jordanian Dinar (JOD)
  case 'LV': currency_selection = 0; break; // Latvia = Latvian Lat (LVL)
  case 'LT': currency_selection = 0; break; // Lithuania = Litas (LTL)
  case 'MY': currency_selection = 0; break; // Malaysia = Ringgit (MYR)
  case 'MV': currency_selection = 0; break; // Maldives = Rufiyaa (MVR)
  case 'MT': currency_selection = 0; break; // Malta = Maltese Lira (MTL)
  case 'MX': currency_selection = 0; break; // Mexico = Mexican Peso (MXN)
  case 'MS': currency_selection = 0; break; // Montserrat = East Caribbean dollar (XCD)
  case 'NA': currency_selection = 0; break; // Namibia = Namibian Dollar (NAD)
  case 'AN': currency_selection = 0; break; // Netherlands Antilles = Netherlands Antillean Guilder (ANG)
  case 'NC': currency_selection = 0; break; // New Caledonia = Comptoirs Francais du Pacifique franc (XPF)
  case 'PH': currency_selection = 0; break; // Philippines = Philippine Peso (PHP)
  case 'QA': currency_selection = 0; break; // Qatar = Qatari Rial (QAR)
  case 'RU': currency_selection = 0; break; // Russia = Russian Ruble (RUB)
  case 'SK': currency_selection = 0; break; // Slovakia = Slovak Koruna (SKK)
  case 'SB': currency_selection = 0; break; // Solomon Islands = Solomon Islands Dollar (SBD)
  case 'ZA': currency_selection = 0; break; // South Africa = Rand (ZAR)
  case 'KR': currency_selection = 0; break; // South Korea = South Korean Won (KRW)
  case 'SH': currency_selection = 0; break; // St. Helena = Saint Helenian Pound (SHP)
  case 'KN': currency_selection = 0; break; // St. Kitts and Nevis = East Caribbean Dollar (XCD)
  case 'LC': currency_selection = 0; break; // St. Lucia = East Caribbean Dollar (XCD)
  case 'TW': currency_selection = 0; break; // Taiwan = New Taiwan Dollar (TWD)
  case 'TH': currency_selection = 0; break; // Thailand = Baht (THB)
  case 'TG': currency_selection = 0; break; // Togo = Communaute Financiere Africaine Franc (XOF)
  case 'TO': currency_selection = 0; break; // Tonga = Pa'anga (TOP)
  case 'TT': currency_selection = 0; break; // Trinidad and Tobago = Trinidad and Tobago Dollar (TTD)
  case 'TN': currency_selection = 0; break; // Tunisia = Tunisian Dinar (TND)
  case 'TR': currency_selection = 0; break; // Turkey = Turkish Lira (TRY)
  case 'UA': currency_selection = 0; break; // Ukraine = Ukrainian Hryvnia (UAH)
  case 'AE': currency_selection = 0; break; // United Arab Emirates = Emirati Dirham (AED)
  case 'UY': currency_selection = 0; break; // Uruguay = Uruguayan Peso (UYU)
  case 'VE': currency_selection = 0; break; // Venezuela = Bolivar (VEB)
  case 'VN': currency_selection = 0; break; // Vietnam = Dong (VND)
  case 'WF': currency_selection = 0; break; // Wallis and Futuna Islands = CFP Franc (XPF)
  default: currency_selection = -1;
 }
 if (currency_selection >= 0) {
  if (is_source_country == true) { source_currency_dropdown.selectedIndex = currency_selection; }
  else { dest_currency_dropdown.selectedIndex = currency_selection; }
 }
 currency_changed();
 //alert('country changed just finished.');
}

function PPCalculate() {
 var original_paypal_percentage = 0.00;
 var paypal_percentage = 0.00;
 var paypal_fixed_fee = 0.00;
 var amount_sent = 0.00;
 var original_paypal_fees = 0.00;
 var the_paypal_fees = 0.00;
 var amount_after_fees = 0.00;
 var cc_fees = 0.00;
 var max_echeck_fee = get_max_echeck_fee();
 if (if_a_person_sends_you_textbox.value == '') { if_a_person_sends_you_textbox.value = '0.00'; }
 if (paypal_percentage_textbox.value == '') { paypal_percentage_textbox.value = '0.00'; }
 else { paypal_percentage = get_float(paypal_percentage_textbox.value); }
 if (paypal_fixed_fee_textbox.value == '') { paypal_fixed_fee_textbox.value = '0.00'; }
 else { paypal_fixed_fee = get_float(paypal_fixed_fee_textbox.value); }
 original_paypal_percentage = paypal_percentage;
 paypal_percentage = paypal_percentage / 100;
 paypal_percentage = paypal_percentage.toFixed(4);
 amount_sent = get_float(if_a_person_sends_you_textbox.value);
 if (amount_sent == 0) { your_pp_fees_would_be_textbox.value = and_you_would_receive_textbox.value = '0.00'; }
 else {
  if (source_currency_dropdown.value != dest_currency_dropdown.value) {
   amount_sent = convert_currency(amount_sent, source_currency_dropdown.value, dest_currency_dropdown.value);
  }
  original_paypal_fees = amount_sent * paypal_percentage;
  the_paypal_fees = amount_sent * paypal_percentage + paypal_fixed_fee;
  document.getElementById('steps_echeck_maximum').innerHTML = '';

  if (include_cc_fee_checkbox.checked == true) {
   original_paypal_fees = amount_sent * (paypal_percentage - 0.025);
   cc_fees = amount_sent * 0.025;
  }
  if ((echeck_payment_checkbox.checked == true) && (the_paypal_fees > max_echeck_fee)) {
   the_paypal_fees = max_echeck_fee;
   document.getElementById('steps_echeck_maximum').innerHTML = '(eCheck Maximum)';
   if (include_cc_fee_checkbox.checked == true) { the_paypal_fees = max_echeck_fee + cc_fees; }
  }
  if (the_paypal_fees >= amount_sent) { the_paypal_fees = amount_sent; }
  document.forms['ppcalc_form'].elements['PPCalcInput2'].value = the_paypal_fees.toFixed(2);
  the_paypal_fees = get_float(your_pp_fees_would_be_textbox.value);
  amount_after_fees = amount_sent - the_paypal_fees;
  if (amount_after_fees < 0) { amount_after_fees = 0; }
  document.forms['ppcalc_form'].elements['PPCalcInput3'].value = amount_after_fees.toFixed(2);  
 }
 //your_pp_fees_would_be_textbox.style.backgroundColor = '#FFFFCF';
 and_you_would_receive_textbox.style.backgroundColor = '#FFFFCF'; // #D8FFD8 or #FFFFCF

 // set fees breakdown
 document.getElementById('steps_amount_sent_in_source').innerHTML = document.getElementById('steps_amount_sent').innerHTML = get_float(if_a_person_sends_you_textbox.value).toFixed(2);
 document.getElementById('steps_amount_sent_source_currency').innerHTML = document.getElementById('steps_amount_sent_currency').innerHTML = document.getElementById('PPCalcInput1_currency').innerHTML;
 document.getElementById('steps_amount_sent_source_currency_equals').innerHTML = document.getElementById('PPCalcInput1_currency').innerHTML;
 document.getElementById('steps_amount_sent_in_dest').innerHTML = '' + amount_sent.toFixed(2);
 document.getElementById('steps_amount_sent_dest_currency').innerHTML = document.getElementById('PPCalcInput2_currency').innerHTML;
 document.getElementById('steps_amount_sent_dest_currency_equals').innerHTML = document.getElementById('PPCalcInput2_currency').innerHTML;
 document.getElementById('steps_exchange_rate_equals').innerHTML = '' + convert_currency(1, source_currency_dropdown.value, dest_currency_dropdown.value, 0).toFixed(5);
 document.getElementById('steps_currency_conversion_fee_amount').innerHTML = cc_fees.toFixed(2);
 document.getElementById('steps_currency_conversion_fee_currency').innerHTML = document.getElementById('PPCalcInput2_currency').innerHTML;
 document.getElementById('steps_paypal_fees_amount').innerHTML = original_paypal_fees.toFixed(2);
 document.getElementById('steps_paypal_fees_currency').innerHTML = document.getElementById('PPCalcInput2_currency').innerHTML;
 document.getElementById('steps_paypal_fixed_fee_amount').innerHTML = paypal_fixed_fee_textbox.value;
 document.getElementById('steps_paypal_fixed_fee_currency').innerHTML = document.getElementById('paypal_fixed_fee_currency').innerHTML;
 document.getElementById('steps_total_paypal_fees').innerHTML = your_pp_fees_would_be_textbox.value;
 document.getElementById('steps_total_paypal_fees_currency').innerHTML = document.getElementById('PPCalcInput2_currency').innerHTML;
 document.getElementById('steps_after_paypal_fees').innerHTML = and_you_would_receive_textbox.value;
 document.getElementById('steps_after_paypal_fees_currency').innerHTML = document.getElementById('PPCalcInput2_currency').innerHTML;

 if (include_cc_fee_checkbox.checked == true) { document.getElementById('steps_paypal_fee_percent').innerHTML = (original_paypal_percentage*100 - 2.5*100) / 100; }
 else { document.getElementById('steps_paypal_fee_percent').innerHTML = paypal_percentage_textbox.value; }

 if (source_currency_dropdown.value != dest_currency_dropdown.value) {
  document.getElementById('amount_sent_line_conversion').style.display = 'inline';
  document.getElementById('amount_sent_line').style.display = 'none';
 }
 else {
  document.getElementById('amount_sent_line_conversion').style.display = 'none';
  document.getElementById('amount_sent_line').style.display = 'inline';
 }

 if (cc_fees == 0) { document.getElementById('steps_currency_conversion_fee_line').style.display = 'none'; }
 else { document.getElementById('steps_currency_conversion_fee_line').style.display = 'inline'; }

 // show fees breakdown
 document.getElementById('breakdown_icon').style.left = '12px';
 document.getElementById('breakdown_icon').style.top = '96px';
 document.getElementById('fees_breakdown_link_1').style.left = '34px';
 document.getElementById('fees_breakdown_link_1').style.top = '95px';
}

function RPPCalculate() {
 var paypal_percentage = 0.00;
 var original_paypal_percentage = 0.00;
 var original_paypal_fees = 0.00;
 var total_paypal_fees = 0.00;
 var paypal_fixed_fee = 0.00;
 var desired_amount = 0.00;
 var a_person_must_send = 0.00;
 var a_person_must_send_other_currency = 0.00;
 var cc_fees = 0.00;
 var max_echeck_fee = get_max_echeck_fee();
 if (paypal_percentage_textbox.value == '') { paypal_percentage_textbox.value = '0.00'; }
 else { paypal_percentage = get_float(paypal_percentage_textbox.value); }
 if (paypal_fixed_fee_textbox.value == '') { paypal_fixed_fee_textbox.value = '0.00'; }
 else { paypal_fixed_fee = get_float(paypal_fixed_fee_textbox.value); }
 original_paypal_percentage = paypal_percentage;
 paypal_percentage = paypal_percentage / 100;
 paypal_percentage = paypal_percentage.toFixed(4);
 desired_amount = get_float(to_receive_textbox.value);
 if (desired_amount == 0) { a_person_would_textbox.value = '0.00'; }
 else {
  //alert("desired amount is " + desired_amount + "\npaypal_percentage is " + paypal_percentage + "\npaypal_fixed_fee is " + paypal_fixed_fee);
  a_person_must_send = (desired_amount + paypal_fixed_fee) / (1 - paypal_percentage);
  a_person_must_send = get_float(a_person_must_send).toFixed(2);
  if ((echeck_payment_checkbox.checked == true) && ((a_person_must_send-desired_amount) > max_echeck_fee)) {
   a_person_must_send = desired_amount + max_echeck_fee;
   if (include_cc_fee_checkbox.checked == true) { a_person_must_send = a_person_must_send / (1 - 0.025); }
  }
  if (source_currency_dropdown.value != dest_currency_dropdown.value) {
   a_person_must_send = convert_currency(a_person_must_send, dest_currency_dropdown.value, source_currency_dropdown.value, 1);
   a_person_must_send_other_currency = convert_currency(get_float(a_person_must_send), source_currency_dropdown.value, dest_currency_dropdown.value, 1);
  }
  else {
   a_person_must_send_other_currency = a_person_must_send;
  }
  document.forms['ppcalc_form'].elements['RPPCalcInput2'].value = a_person_must_send;
 }
 a_person_would_textbox.style.backgroundColor = '#FFFFCF'; // #D8FFD8 or #FFFFCF

 if (include_cc_fee_checkbox.checked == true) {
  cc_fees = a_person_must_send_other_currency * 0.025;
  original_paypal_fees = a_person_must_send_other_currency * (paypal_percentage - 0.025);
 }
 else {
  original_paypal_fees = a_person_must_send_other_currency * paypal_percentage;
 }

 total_paypal_fees = cc_fees + original_paypal_fees + paypal_fixed_fee;

 // set reverse fees breakdown
 document.getElementById('reverse_steps_amount_sent_in_source').innerHTML = document.getElementById('reverse_steps_amount_sent').innerHTML = a_person_would_textbox.value;
 document.getElementById('reverse_steps_amount_sent_source_currency').innerHTML = document.getElementById('reverse_steps_amount_sent_currency').innerHTML = document.getElementById('RPPCalcInput2_currency').innerHTML;
 document.getElementById('reverse_steps_amount_sent_source_currency_equals').innerHTML = document.getElementById('RPPCalcInput2_currency').innerHTML;
 document.getElementById('reverse_steps_amount_sent_in_dest').innerHTML = '' + a_person_must_send_other_currency;
 document.getElementById('reverse_steps_amount_sent_dest_currency').innerHTML = document.getElementById('RPPCalcInput1_currency').innerHTML;
 document.getElementById('reverse_steps_amount_sent_dest_currency_equals').innerHTML = document.getElementById('RPPCalcInput1_currency').innerHTML;
 document.getElementById('reverse_steps_exchange_rate_equals').innerHTML = '' + convert_currency(1, source_currency_dropdown.value, dest_currency_dropdown.value, 0).toFixed(5);
 document.getElementById('reverse_steps_currency_conversion_fee_amount').innerHTML = cc_fees.toFixed(2);
 document.getElementById('reverse_steps_currency_conversion_fee_currency').innerHTML = document.getElementById('RPPCalcInput1_currency').innerHTML;
 document.getElementById('reverse_steps_paypal_fees_amount').innerHTML = original_paypal_fees.toFixed(2);
 document.getElementById('reverse_steps_paypal_fees_currency').innerHTML = document.getElementById('RPPCalcInput1_currency').innerHTML;
 document.getElementById('reverse_steps_paypal_fixed_fee_amount').innerHTML = paypal_fixed_fee_textbox.value;
 document.getElementById('reverse_steps_paypal_fixed_fee_currency').innerHTML = document.getElementById('paypal_fixed_fee_currency').innerHTML;
 document.getElementById('reverse_steps_total_paypal_fees').innerHTML = total_paypal_fees.toFixed(2);
 document.getElementById('reverse_steps_total_paypal_fees_currency').innerHTML = document.getElementById('RPPCalcInput1_currency').innerHTML;
 document.getElementById('reverse_steps_after_paypal_fees').innerHTML = get_float(a_person_must_send_other_currency - total_paypal_fees).toFixed(2);
 document.getElementById('reverse_steps_after_paypal_fees_currency').innerHTML = document.getElementById('RPPCalcInput1_currency').innerHTML;

 if (include_cc_fee_checkbox.checked == true) {
  document.getElementById('reverse_steps_paypal_fee_percent').innerHTML = (original_paypal_percentage*100 - 2.5*100) / 100;
 }
 else {
  document.getElementById('reverse_steps_paypal_fee_percent').innerHTML = paypal_percentage_textbox.value;
 }

 if (source_currency_dropdown.value != dest_currency_dropdown.value) {
  document.getElementById('reverse_amount_sent_line_conversion').style.display = 'inline';
  document.getElementById('reverse_amount_sent_line').style.display = 'none';
 }
 else {
  document.getElementById('reverse_amount_sent_line_conversion').style.display = 'none';
  document.getElementById('reverse_amount_sent_line').style.display = 'inline';
 }

 if (cc_fees == 0) { document.getElementById('reverse_steps_currency_conversion_fee_line').style.display = 'none'; }
 else { document.getElementById('reverse_steps_currency_conversion_fee_line').style.display = 'inline'; }

 // show reverse fees breakdown
 document.getElementById('reverse_breakdown_icon').style.left = '12px';
 document.getElementById('reverse_breakdown_icon').style.top = '69px';
 document.getElementById('fees_breakdown_link_2').style.left = '34px';
 document.getElementById('fees_breakdown_link_2').style.top = '68px';
}

function convert_currency(amount, src_currency, dest_currency, round_off) {
 if (typeof round_off == "undefined") { round_off = 1; }
 var to_return = 0.00;
 var amount_in_USD = 0.00;
 if (dest_currency == 'USD') { eval("to_return = amount / exchange_rate_" + src_currency); }
 else if (src_currency == 'USD') { eval("to_return = amount * exchange_rate_" + dest_currency); }
 else {
  amount_in_USD = convert_currency(amount, src_currency, 'USD');
  eval("to_return = amount_in_USD * exchange_rate_" + dest_currency);
 }
 if (src_currency == dest_currency) { to_return = amount; }
 if (round_off == 1) { to_return = get_float(to_return.toFixed(2)); }
 else { to_return = get_float(to_return); }
 return to_return;
}

function textbox_onkeypress(e) {
 if (typeof e == "undefined") { e = window.event; }
 var keycode = get_key_code(e);
 var to_return = true;
 switch (keycode) {
  case 8: // backspace
   break; 
  case 13: // enter
   if (this.value == '') { this.value = '0.01'; }
   to_return = false;
   if (this.id == 'PPCalcInput1') { PPCalculate(); }
   else if (this.id == 'RPPCalcInput1') { RPPCalculate(); }
   else if (this.id == 'CCCalcInput1') { currency_converter_convert_clicked(); }
   break;
  case 17: case 86: // CTRL-V
   break;
  case 37: case 39: break; // left arrow, right arrow
  case 38: // up arrow
   if (this.value == '') { this.value = '0.01'; }
   this.value = (get_float(this.value) + 0.5).toFixed(2);
   break;
  case 40: // down arrow
   if (get_float(this.value) >= 0.5) { this.value = (get_float(this.value) - 0.5).toFixed(2); }
   else { this.value = '0.00'; }
   break;
  case 46: // period (.) was pressed
   if (this.value.indexOf(".") != -1) { // there is already a (.) in there
    if (has_selection(this) == false) { to_return = false; } // no good
   }
   break;
  case 48: case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57:
   if ((this.id != 'one_usd_equals') && (this.id != 'paypal_fee_percentage')) {
    if ( this.value.length >= 3) {
     if ( this.value.substr(this.value.length - 3, 1) == '.' ) {
      if (has_selection(this) == false) { to_return = false; } // no good
     }
    }
   }
   break;
  default:
   to_return = false;
 } // end switch
 if ((!e.which) && (keycode == 46)) { to_return = true; } // allow delete
 if ((typeof e.which == "undefined") && (keycode == 46) && (this.value.indexOf(".") != -1) && (has_selection(this) == false)) { to_return = false; }
 e.returnValue = to_return;
 return to_return;
}


