var auto_calculate = 1;
var copy_sh = 0;
var copy_opening_price = 0;
var copy_bin_price = 0;
var use_prefilled = 0;
var ebay_giving_works_override = 0.00;

var get_params = window.top.location.search.substring(1).toLowerCase();

if (get_params.indexOf("insertion=") != -1) { var insertion_override = amt(get_value("insertion")); }
if (get_params.indexOf("ppp=") != -1) { var ppp = amt(get_value("ppp")); }
if (get_params.indexOf("ppf=") != -1) { var ppf = amt(get_value("ppf")); }
if (get_params.indexOf("copysh=") != -1) { copy_sh = amt(get_value("copysh")); }
if (get_params.indexOf("copy_sh=") != -1) { copy_sh = amt(get_value("copy_sh")); }
if (get_params.indexOf("copy_opening_price=") != -1) { copy_opening_price = amt(get_value("copy_opening_price")); }
if (get_params.indexOf("copy_opening=") != -1) { copy_opening_price = amt(get_value("copy_opening")); }
if (get_params.indexOf("copy_bin_price=") != -1) { copy_bin_price = amt(get_value("copy_bin_price")); }
if (get_params.indexOf("copy_bin=") != -1) { copy_bin_price = amt(get_value("copy_bin")); }
if (get_params.indexOf("copybin=") != -1) { copy_bin_price = amt(get_value("copybin")); }
if (get_params.indexOf("auto=") != -1) { auto_calculate = amt(get_value("auto")); }
if (get_params.indexOf("prefilled=") != -1) { use_prefilled = amt(get_value("prefilled")); }
if (get_params.indexOf("qty_listed=") != -1) { var qty_listed = amt(get_value("qty_listed")); }
if (get_params.indexOf("qty_sold=") != -1) { var qty_sold = amt(get_value("qty_sold")); }
if (get_params.indexOf("qty_shipped=") != -1) { var qty_shipped = amt(get_value("qty_shipped")); }

if ((get_params.indexOf("store=") != -1) || (get_params.indexOf("stores_level=") != -1)) {
 var store_param_first_letter = (get_params.indexOf("stores_level=") != -1) ? get_value("stores_level").substring(0,1) : get_value("store").substring(0,1);
 if (store_param_first_letter == "b") { var store_level = "basic"; }
 else if (store_param_first_letter == "p") { var store_level = "premium"; }
 else if (store_param_first_letter == "f") { var store_level = "premium"; }
 else if (store_param_first_letter == "a") { var store_level = "anchor"; }
 else if (store_param_first_letter == "n") { var store_level = "none"; }
}

if ((get_params.indexOf("category=") != -1) || (get_params.indexOf("cat=") != -1)) {
 var category_param = (get_params.indexOf("cat=") != -1) ? get_value("cat") : get_value("category");
 var category_param_first_letter = category_param.substring(0,1);
 if (category_param_first_letter == "m") { var category_choice = "media"; } // media
 else if (category_param == "computers") { var category_choice = "tech"; } // computers
 else if (category_param == "business") { var category_choice = "industrial"; } // industrial
 else if (category_param_first_letter == "i") { var category_choice = "industrial"; } // industrial
 else if (category_param_first_letter == "d") { var category_choice = "media"; } // dvds
 else if (category_param_first_letter == "b") { var category_choice = "media"; } // books
 else if (category_param_first_letter == "v") { var category_choice = "media"; } // video games
 else if (category_param_first_letter == "a") { var category_choice = "acc"; } // accessories
 else if (category_param_first_letter == "c") { var category_choice = "acc"; } // clothing
 else if (category_param_first_letter == "s") { var category_choice = "acc"; } // shoes
 else if (category_param_first_letter == "e") { var category_choice = "tech"; } // electronics
 else if (category_param_first_letter == "t") { var category_choice = "tech"; } // technology
 else if (category_param_first_letter == "o") { var category_choice = "other"; } // other
}

if ((get_params.indexOf("powerseller=") != -1) || (get_params.indexOf("powerseller_level=") != -1) || (get_params.indexOf("ps=") != -1)) {
 var powerseller_param_first_letter = (get_params.indexOf("powerseller_level=") != -1) ? get_value("powerseller_level").substring(0,1) : (get_params.indexOf("powerseller=") != -1) ? get_value("powerseller").substring(0,1) : get_value("ps").substring(0,1);
 if (powerseller_param_first_letter == "t") { var powerseller_choice = "top"; }
 else if (powerseller_param_first_letter == "s") { var powerseller_choice = "standard"; }
 else if (powerseller_param_first_letter == "n") { var powerseller_choice = "none"; }
}

if ((get_params.indexOf("payment=") != -1) || (get_params.indexOf("payment_type=") != -1)) {
 var payment_param = (get_params.indexOf("payment=") != -1) ? get_value("payment") : get_value("payment_type");
 var payment_param_first_letter = payment_param.substring(0,1);
 if (payment_param_first_letter == "n") { var payment_choice = "none"; }
 else if (payment_param_first_letter == "m") { var payment_choice = "micro"; }
 else if (payment_param == "cross_tier_4") { var payment_choice = "cross_tier_4"; }
 else if (payment_param == "cross_tier_3") { var payment_choice = "cross_tier_3"; }
 else if (payment_param == "cross_tier_2") { var payment_choice = "cross_tier_2"; }
 else if (payment_param == "dom_tier_4") { var payment_choice = "dom_tier_4"; }
 else if (payment_param == "dom_tier_3") { var payment_choice = "dom_tier_3"; }
 else if (payment_param == "dom_tier_2") { var payment_choice = "dom_tier_2"; }
 else if (payment_param_first_letter == "c") { var payment_choice = "cross"; }
 else if (payment_param_first_letter == "d") { var payment_choice = "dom"; }
}

if ((get_params.indexOf("fvf=") != -1) || (get_params.indexOf("fvf_discount=") != -1)) {
 var fvf_discount_override = (get_params.indexOf("fvf=") != -1) ? amt(get_value("fvf")) : amt(get_value("fvf_discount"));
 fvf_discount_override = Math.round(fvf_discount_override/100*1000)/1000;
}

if ((get_params.indexOf("egw=") != -1) || (get_params.indexOf("ebay_giving_works=") != -1)) {
 ebay_giving_works_override = (get_params.indexOf("egw=") != -1) ? amt(get_value("egw")) : amt(get_value("ebay_giving_works"));
 ebay_giving_works_override = Math.round(ebay_giving_works_override/100*1000)/1000;
}

function get_value(param) {
 var param = param + "=";
 var to_return = "";
 if (get_params.length > 0) {
  begin = get_params.indexOf(param);
  if (begin != -1) {
   begin += param.length;
   end = get_params.indexOf("&",begin);
   if (end == -1) { end = get_params.length; }
   to_return = unescape(get_params.substring(begin,end));
  }
 }
 return to_return;
}

if (window.addEventListener) { window.addEventListener("load", calc_onload, false); }
else if (window.attachEvent) { window.attachEvent("onload", calc_onload); }

function calc_onload() {
 if (window.addEventListener) {
  document.getElementById('qty_listed').addEventListener("keypress", qty_onkey, false);
  document.getElementById('qty_sold').addEventListener("keypress", qty_onkey, false);
  document.getElementById('qty_shipped').addEventListener("keypress", qty_onkey, false);
  document.getElementById('qty_listed').addEventListener("keyup", qty_listed_onkeyup, false);
  document.getElementById('qty_sold').addEventListener("keyup", qty_sold_onkeyup, false);
 }
 else if (window.attachEvent) {
  document.getElementById('qty_listed').attachEvent("onkeydown", qty_onkey);
  document.getElementById('qty_sold').attachEvent("onkeydown", qty_onkey);
  document.getElementById('qty_shipped').attachEvent("onkeydown", qty_onkey);
  document.getElementById('qty_listed').attachEvent("onkeyup", qty_listed_onkeyup);
  document.getElementById('qty_sold').attachEvent("onkeyup", qty_sold_onkeyup);
 }
 show_calculate_button(auto_calculate);
 if (typeof store_level != "undefined") { document.getElementById('store_level').value = store_level; showtab('reverse'); sync_lu_prices(); }
 if (typeof category_choice != "undefined") { document.getElementById('category').value = category_choice; }
 if (typeof powerseller_choice != "undefined") { document.getElementById('powerseller_discount').value = powerseller_choice; }
 if (typeof payment_choice != "undefined") { document.getElementById('payment_type').value = payment_choice; }
 if (typeof use_prefilled != "undefined") { if ((use_prefilled==0) || (use_prefilled==1)) { document.getElementById('prefilled').value = use_prefilled; } }
 if (typeof ebay_giving_works_override != "undefined") { if (Math.round((ebay_giving_works_override*100)%5*100)/100 == 0) { document.getElementById('egw').value = ebay_giving_works_override.toFixed(2); } }
 if (typeof copy_sh != "undefined") { if ((copy_sh==0) || (copy_sh==1)) { document.getElementById('copy_sh_choice').value = copy_sh; } }
 if (typeof copy_opening_price != "undefined") { if ((copy_opening_price==0) || (copy_opening_price==1)) { document.getElementById('copy_opening_price_choice').value = copy_opening_price; } }
 if (typeof copy_bin_price != "undefined") { if ((copy_bin_price==0) || (copy_bin_price==1)) { document.getElementById('copy_bin_price_choice').value = copy_bin_price; } }
 if (typeof auto_calculate != "undefined") { if ((auto_calculate==0) || (auto_calculate==1)) { document.getElementById('auto').value = auto_calculate; } }
 if (typeof qty_listed != "undefined") { if (qty_listed > 0) { document.getElementById('qty_listed').value = qty_listed; } }
 if (typeof qty_sold != "undefined") { if (qty_sold > 0) { document.getElementById('qty_sold').value = qty_sold; } }
 if (typeof qty_shipped != "undefined") { if (qty_shipped > 0) { document.getElementById('qty_shipped').value = qty_shipped; } }
}

function amt(input) {
 if (typeof input == "undefined") { var input = ''; }
 input = input.toString();
 var output = 0;
 if (input.length > 0) {
  var c='',d=false;
  for (var i=0;i<input.length;i++) {
   c = input.substr(i,1);
   if ((c=='0')||(c=='1')||(c=='2')||(c=='3')||(c=='4')||(c=='5')||(c=='6')||(c=='7')||(c=='8')||(c=='9')) { output = output + c; }
   else if ((c=='.')&&(d==false)) { output = output + c; d = true; }
  }
 }
 return parseFloat(output);
}

function buy_it_now_price_onkeyup() {
 if (copy_bin_price == 1) {
  document.getElementById('opening_price').value = document.getElementById('buy_it_now_price').value;
  document.getElementById('closing_price').value = document.getElementById('buy_it_now_price').value;
 }
}

function opening_price_onkeyup() {
 if (copy_opening_price == 1) {
  document.getElementById('closing_price').value = document.getElementById('opening_price').value;
 }
 update_isv_fee();
}

function sh_charged_onkeyup() {
 if (copy_sh == 1) {
  document.getElementById('cost_of_postage').value = document.getElementById('sh_charged').value;
 }
}

function qty_onkey(e) {
 if (typeof e == "undefined") { e = window.event; }
 if (e.keyCode) { var keycode = e.keyCode; }
 else if (e.which) { var keycode = e.which; }
 else { var keycode = e.charCode; }
 var this_one = (typeof e.srcElement == "undefined") ? this : e.srcElement;
 if (keycode == 38) { this_one.value = amt(this_one.value) + 1; }
 else if (keycode == 40) { this_one.value = amt(this_one.value) - 1; }
 if (this_one.id == 'qty_listed') { document.getElementById('qty_sold').value = document.getElementById('qty_shipped').value = this_one.value; }
 else if (this_one.id == 'qty_sold') { document.getElementById('qty_shipped').value = this_one.value; }
 if (auto_calculate == 1) { calculate_fees(); }
}

function qty_listed_onkeyup(e) {
 if (typeof e == "undefined") { e = window.event; }
 var this_one = (typeof e.srcElement == "undefined") ? this : e.srcElement;
 document.getElementById('qty_sold').value = document.getElementById('qty_shipped').value = this_one.value;
 if (auto_calculate == 1) { calculate_fees(); }
}

function qty_sold_onkeyup(e) {
 if (typeof e == "undefined") { e = window.event; }
 var this_one = (typeof e.srcElement == "undefined") ? this : e.srcElement;
 document.getElementById('qty_shipped').value = this_one.value;
 if (auto_calculate == 1) { calculate_fees(); }
}

function show_fees_breakdown(show_it) {
 if (show_it == 1) {
  document.getElementById('calculator_div').style.display = 'none';
  document.getElementById('fees_breakdown_div').style.display = 'block';
 }
 else {
  document.getElementById('fees_breakdown_div').style.display = 'none';
  document.getElementById('calculator_div').style.display = 'block';
 }
}

function show_calculate_button(auto_calc) {
 if (auto_calc == 0) { document.getElementById('calculate_button').style.display = "block"; }
 else { document.getElementById('calculate_button').style.display = "none"; }
 auto_calculate = auto_calc;
 var f = document.getElementById('calc_form'); 
 for (var i=0; i<f.elements.length; i++) {
  if (f.elements[i].type == 'text') {
   if (auto_calculate == 1) {
    if (window.addEventListener) { f.elements[i].addEventListener("keyup", calculate_fees, false);  }
    else if (window.attachEvent) { f.elements[i].attachEvent("onkeyup", calculate_fees); }
   }
   else {
    if (window.addEventListener) { f.elements[i].removeEventListener("keyup", calculate_fees, false);  }
    else if (window.attachEvent) { f.elements[i].detachEvent("onkeyup", calculate_fees); }   
   }
  }
  else if ((f.elements[i].type == 'radio') || (f.elements[i].type == 'checkbox')) {
   if (auto_calculate == 1) {
    if (window.addEventListener) { f.elements[i].addEventListener("click", calculate_fees, false); }
    else if (window.attachEvent) { f.elements[i].attachEvent("onclick", calculate_fees); }
   }
   else {
    if (window.addEventListener) { f.elements[i].removeEventListener("click", calculate_fees, false); }
    else if (window.attachEvent) { f.elements[i].detachEvent("onclick", calculate_fees); }   
   }
  }
  else if (f.elements[i].type == 'select-one') {
   if (auto_calculate == 1) {
    if (window.addEventListener) { f.elements[i].addEventListener("change", calculate_fees, false); f.elements[i].addEventListener("keyup", calculate_fees, false); }
    else if (window.attachEvent) { f.elements[i].attachEvent("onchange", calculate_fees); f.elements[i].attachEvent("onkeyup", calculate_fees); }
   }
   else {
    if (window.addEventListener) { f.elements[i].removeEventListener("change", calculate_fees, false); f.elements[i].removeEventListener("keyup", calculate_fees, false); }
    else if (window.attachEvent) { f.elements[i].detachEvent("onchange", calculate_fees); f.elements[i].detachEvent("onkeyup", calculate_fees); }
   }
  }
 }
}

function showtab(which_tab) {
 if (which_tab == 'options') {
  document.getElementById('reverse_table').style.display = 'none';
  document.getElementById('lu_table').style.display = 'none';
  document.getElementById('options_table').style.display = 'block';
 }
 else if (which_tab == 'listing_upgrades') {
  document.getElementById('reverse_table').style.display = 'none';
  document.getElementById('options_table').style.display = 'none';
  document.getElementById('lu_table').style.display = 'block';
 }
 else if (which_tab == 'reverse') {
  document.getElementById('options_table').style.display = 'none';
  document.getElementById('lu_table').style.display = 'none';
  document.getElementById('reverse_table').style.display = 'block';
 }
}

function subtotal_lu_prices() {
 var subtotal = 0.00;
 subtotal += (document.getElementById('ten_day_auction').checked) ? amt(document.getElementById('ten_day_auction_price').value) : 0.00;
 subtotal += (document.getElementById('value_pack').checked) ? amt(document.getElementById('value_pack_price').value) : 0.00;
 subtotal += (document.getElementById('gallery_plus').checked) ? amt(document.getElementById('gallery_plus_price').value) : 0.00;
 subtotal += (document.getElementById('listing_designer').checked) ? amt(document.getElementById('listing_designer_price').value) : 0.00;
 subtotal += (document.getElementById('subtitle').checked) ? amt(document.getElementById('subtitle_price').value) : 0.00;
 subtotal += (document.getElementById('bold').checked) ? amt(document.getElementById('bold_price').value) : 0.00;
 subtotal += (document.getElementById('featured_first').checked) ? amt(document.getElementById('featured_first_price').value) : 0.00;
 subtotal += (document.getElementById('international_site_visibility').checked) ? amt(document.getElementById('international_site_visibility_price').value) : 0.00;
 subtotal *= (document.getElementById('two_categories').checked) ? 2 : 1;
 subtotal += (document.getElementById('thirty_day_fixed').checked) ? amt(document.getElementById('thirty_day_fixed_price').value) : 0.00; 
 subtotal += (document.getElementById('scheduled_listing').checked) ? amt(document.getElementById('scheduled_listing_price').value) : 0.00;
 subtotal += (document.getElementById('add_images').checked) ? amt(document.getElementById('add_images_price').value) : 0.00;
 subtotal += (document.getElementById('pic_pack_16').checked) ? amt(document.getElementById('pic_pack_16_price').value) : 0.00;
 subtotal += (document.getElementById('pic_pack_712').checked) ? amt(document.getElementById('pic_pack_712_price').value) : 0.00;
 subtotal += amt(document.getElementById('custom_1_price').value);
 document.getElementById('total_lu_fees').value = "$" + subtotal.toFixed(2);
}

function sync_lu_prices() {
 var is_30_day = document.getElementById('thirty_day_fixed').checked;
 var is_store = (document.getElementById('store_level').value == 'none') ? false : true;
 document.getElementById('value_pack_price').value = (is_30_day) ? '$2.00' : '$0.65';
 document.getElementById('gallery_plus_price').value = (is_30_day) ? '$1.00' : '$0.35';
 document.getElementById('listing_designer_price').value = (is_30_day) ? '$0.30' : '$0.10';
 document.getElementById('subtitle_price').value = (is_30_day) ? '$1.50' : '$0.50';
 document.getElementById('bold_price').value = (is_30_day) ? '$4.00' : '$2.00';
 document.getElementById('scheduled_listing_price').value = (is_30_day) ? '$0.10' : '$0.10';
 document.getElementById('featured_first_price').value = (is_30_day) ? '$74.95' : '$24.95';
 update_isv_fee();
 update_add_picture_fee();
 document.getElementById('pic_pack_16_price').value = (is_store) ? '$0.00' : '$0.75';
 document.getElementById('pic_pack_712_price').value = (is_store) ? '$0.00' : '$1.00';
}

function update_isv_fee() {
 var opening_price = amt(document.getElementById('opening_price').value);
 var is_auction = (opening_price > 0) ? true : false;
 if ((is_auction) && (opening_price >= 50)) { document.getElementById('international_site_visibility_price').value = '$0.40'; }
 else if ((is_auction) && (opening_price >= 10)) { document.getElementById('international_site_visibility_price').value = '$0.20'; }
 else if ((is_auction) && (opening_price >= 0.01)) { document.getElementById('international_site_visibility_price').value = '$0.10'; }
 else { document.getElementById('international_site_visibility_price').value = '$0.50'; }
}

function update_add_picture_fee() {
 var is_store = (document.getElementById('store_level').value == 'none') ? false : true;
 var num_pics = amt(document.getElementById('num_add_images').value);
 document.getElementById('add_images_price').value = (is_store) ? '$0.00' : '$' + (Math.round((0.15*num_pics)*100)/100).toFixed(2);
}

function value_pack_checked() {
 if (document.getElementById('value_pack').checked) {
  document.getElementById('gallery_plus_price').value = '$0.00';
  document.getElementById('listing_designer_price').value = '$0.00';
  document.getElementById('subtitle_price').value = '$0.00';
  document.getElementById('gallery_plus').checked = true;
  document.getElementById('listing_designer').checked = true;
  document.getElementById('subtitle').checked = true;
//  document.getElementById('gallery_plus').disabled = true;
//  document.getElementById('listing_designer').disabled = true;
//  document.getElementById('subtitle').disabled = true;
 }
 else {
  document.getElementById('gallery_plus').checked = false;
  document.getElementById('listing_designer').checked = false;
  document.getElementById('subtitle').checked = false;
//  document.getElementById('gallery_plus').disabled = false;
//  document.getElementById('listing_designer').disabled = false;
//  document.getElementById('subtitle').disabled = false;
  sync_lu_prices();
 }
}

function save_options() {
 if (window.confirm("When you click OK the page will reload. If you bookmark the resulting page that loads these options will be loaded by default the next time you use the calculator.")) {
  var payment_type = document.getElementById('payment_type').value;
  var paypal_percent = '0';
  var paypal_fixed = '0';
  if (payment_type == "dom") { paypal_percent = '2.9'; paypal_fixed = '0.30'; }
  else if (payment_type == "cross") { paypal_percent = '3.9'; paypal_fixed = '0.30'; }
  else if (payment_type == "dom_tier_2") { paypal_percent = '2.5'; paypal_fixed = '0.30'; }
  else if (payment_type == "cross_tier_2") { paypal_percent = '3.5'; paypal_fixed = '0.30'; }
  else if (payment_type == "dom_tier_3") { paypal_percent = '2.2'; paypal_fixed = '0.30'; }
  else if (payment_type == "cross_tier_3") { paypal_percent = '3.2'; paypal_fixed = '0.30'; }
  else if (payment_type == "dom_tier_4") { paypal_percent = '1.9'; paypal_fixed = '0.30'; }
  else if (payment_type == "cross_tier_4") { paypal_percent = '2.9'; paypal_fixed = '0.30'; }
  else if (payment_type == "micro") { paypal_percent = '5'; paypal_fixed = '0.05'; }
  else if (payment_type == "none") { paypal_percent = '0'; paypal_fixed = '0'; }
  var egw_amount = amt(document.getElementById('egw').value) * 100;
  window.top.location.search = "?cat=" + document.getElementById('category').value + "&store=" + document.getElementById('store_level').value + "&ps=" + document.getElementById('powerseller_discount').value + "&ppp=" + paypal_percent + "&ppf=" + paypal_fixed + "&payment=" + document.getElementById('payment_type').value + "&prefilled=" + document.getElementById('prefilled').value + "&egw=" + egw_amount + "&copy_bin=" + document.getElementById('copy_bin_price_choice').value + "&copy_opening=" + document.getElementById('copy_opening_price_choice').value + "&copy_sh=" + document.getElementById('copy_sh_choice').value + "&auto=" + document.getElementById('auto').value + "&qty_listed=" + document.getElementById('qty_listed').value + "&qty_sold=" + document.getElementById('qty_sold').value + "&qty_shipped=" + document.getElementById('qty_shipped').value;
 }
}

function reset_options() {
 document.getElementById('category').selectedIndex = 0;
 document.getElementById('store_level').selectedIndex = 0;
 document.getElementById('powerseller_discount').selectedIndex = 0;
 document.getElementById('payment_type').selectedIndex = 2;
 document.getElementById('prefilled').selectedIndex = 0;
 document.getElementById('egw').selectedIndex = 0;
 document.getElementById('copy_bin_price_choice').selectedIndex = 0;
 document.getElementById('copy_opening_price_choice').selectedIndex = 0;
 document.getElementById('copy_sh_choice').selectedIndex = 0;
 document.getElementById('auto').selectedIndex = 1;
 document.getElementById('qty_listed').value = '1';
 document.getElementById('qty_sold').value = '1';
 document.getElementById('qty_shipped').value = '1';
 sync_lu_prices();
 if (auto_calculate == 1) { calculate_fees(); }
}

function reset_boxes() {
 document.getElementById('auction_insertion_fee').innerHTML = "0.00";
 document.getElementById('auction_reserve_fee').innerHTML = "0.00";
 document.getElementById('auction_bin_fee').innerHTML = "0.00";
 document.getElementById('auction_lu_fees').innerHTML = "0.00";
 document.getElementById('auction_fvf').innerHTML = "0.00";
 document.getElementById('auction_ebay_fees').innerHTML = "0.00";
 document.getElementById('auction_paypal_fees').innerHTML = "0.00";
 document.getElementById('auction_total_fees').innerHTML = "0.00";
 document.getElementById('auction_total_profit').innerHTML = "0.00";
 document.getElementById('fixed_insertion_fee').innerHTML = "0.00";
 document.getElementById('fixed_lu_fees').innerHTML = "0.00";
 document.getElementById('fixed_fvf').innerHTML = "0.00";
 document.getElementById('fixed_ebay_fees').innerHTML = "0.00";
 document.getElementById('fixed_paypal_fees').innerHTML = "0.00";
 document.getElementById('fixed_total_fees').innerHTML = "0.00";
 document.getElementById('fixed_total_profit').innerHTML = "0.00"; 
 document.getElementById('buy_it_now_price').value = '';
 document.getElementById('opening_price').value = '';
 document.getElementById('closing_price').value = '';
 document.getElementById('reserve_price').value = '';
 document.getElementById('sh_charged').value = '';
 document.getElementById('cost_of_postage').value = '';
 document.getElementById('cost_to_acquire').value = '';
 document.getElementById('total_ebay_fees').value = '';
 document.getElementById('total_paypal_fees').value = '';
 document.getElementById('total_profit').value = '';
 document.getElementById('total_profit').style.color = '#000000';
 
 document.getElementById('profit_loss_div').style.backgroundImage = "url('bg_textbox_green.gif')";
 //document.getElementById('profit_dollar_sign_svg').setAttribute('fill','#000000');
 //if (document.getElementById('profit_dollar_sign_vml')) { document.getElementById('profit_dollar_sign_vml').style.color = '#000000'; }
 
 document.getElementById('fixed_total_profit').style.color = '#000000';
 document.getElementById('fixed_profit_dollar_sign').style.color = '#000000';
 document.getElementById('auction_total_profit').style.color = '#000000';
 document.getElementById('auction_profit_dollar_sign').style.color = '#000000';
 
 document.getElementById('thirty_day_fixed').checked = false;
 document.getElementById('ten_day_auction').checked = false;
 document.getElementById('value_pack').checked = false;
 document.getElementById('gallery_plus').checked = false;
 document.getElementById('listing_designer').checked = false;
 document.getElementById('subtitle').checked = false;
 document.getElementById('bold').checked = false;
 document.getElementById('scheduled_listing').checked = false;
 document.getElementById('featured_first').checked = false;
 document.getElementById('international_site_visibility').checked = false;
 document.getElementById('add_images').checked = false;
 document.getElementById('pic_pack_16').checked = false;
 document.getElementById('pic_pack_712').checked = false;
 document.getElementById('two_categories').checked = false;
 document.getElementById('num_add_images').value = '1';
 document.getElementById('total_lu_fees').value = '$0.00';
 sync_lu_prices();
 
 document.getElementById('desired_net_profit').value = '';
 document.getElementById('new_price').value = '';
 document.getElementById('new_sh').value = '';
 
 //document.getElementById('break_even').style.display = 'none';
 
 //document.getElementById('buy_it_now_price').focus();
}

function calculate_fees() {

 var bin_price = amt(document.getElementById('buy_it_now_price').value);
 var opening_price = amt(document.getElementById('opening_price').value);
 var closing_price = amt(document.getElementById('closing_price').value);
 var reserve_price = amt(document.getElementById('reserve_price').value);
 var sh_charged = amt(document.getElementById('sh_charged').value);
 var cost_of_postage = amt(document.getElementById('cost_of_postage').value);
 var cost_to_acquire = amt(document.getElementById('cost_to_acquire').value);
 var qty_listed = amt(document.getElementById('qty_listed').value);
 var qty_sold = amt(document.getElementById('qty_sold').value);
 var qty_shipped = amt(document.getElementById('qty_shipped').value);
 
 var opening_value = (reserve_price > opening_price) ? reserve_price : opening_price;
 var fixed_value = (bin_price > 0) ? bin_price : closing_price;
 
 //document.getElementById('break_even').style.display = (cost_to_acquire > 0) ? 'block' : 'none';
 
 var store_level = document.getElementById('store_level').value; /* none | basic | premium | anchor */
 var category = document.getElementById('category').value; /* media | acc | tech | other | industrial */
 var powerseller_level = document.getElementById('powerseller_discount').value; /* none | standard | top */
 var payment_type = document.getElementById('payment_type').value; /* dom | cross | micro | none */

 // ------------------------------------------------------------------------------------------------------------- // 
 // PayPal Fees
 // ------------------------------------------------------------------------------------------------------------- //
 var paypal_percent = 0.00;
 var paypal_fixed = 0.00;
 if (payment_type == "dom") { paypal_percent = 0.029; paypal_fixed = 0.30; }
 else if (payment_type == "cross") { paypal_percent = 0.039; paypal_fixed = 0.30; }
 else if (payment_type == "dom_tier_2") { paypal_percent = 0.025; paypal_fixed = 0.30; }
 else if (payment_type == "cross_tier_2") { paypal_percent = 0.035; paypal_fixed = 0.30; }
 else if (payment_type == "dom_tier_3") { paypal_percent = 0.022; paypal_fixed = 0.30; }
 else if (payment_type == "cross_tier_3") { paypal_percent = 0.032; paypal_fixed = 0.30; }
 else if (payment_type == "dom_tier_4") { paypal_percent = 0.019; paypal_fixed = 0.30; }
 else if (payment_type == "cross_tier_4") { paypal_percent = 0.029; paypal_fixed = 0.30; }
 else if (payment_type == "micro") { paypal_percent = 0.05; paypal_fixed = 0.05; }
 else if (payment_type == "none") { paypal_percent = 0.00; paypal_fixed = 0.00; }

 // ------------------------------------------------------------------------------------------------------------- //
 // check GET parameters
 // ------------------------------------------------------------------------------------------------------------- //
 if (typeof ppp != "undefined") {
  if (ppp.toString().length > 0) {
   var new_ppp = ppp;
   //if (payment_type == "cross") { new_ppp = ppp + 1; }
   paypal_percent = Math.round(new_ppp/100*1000)/1000;
  }
 }
 if (typeof ppf != "undefined") {
  if (ppf.toString().length > 0) { paypal_fixed = Math.round(ppf*100)/100; }
 }

 // ------------------------------------------------------------------------------------------------------------- // 
 // Determine Final Value Fee Discount
 // ------------------------------------------------------------------------------------------------------------- //
 var fvf_discount = 0.00;
 if (powerseller_level == "top") { fvf_discount = 0.20; }
 else if (powerseller_level == "standard") { fvf_discount = 0.05; }
 if (typeof fvf_discount_override != "undefined") { fvf_discount = fvf_discount_override; }
 
 var fixed_fvf_1 = 0.12;
 var fixed_fvf_2 = 0.06;
 var fixed_fvf_3 = 0.02;
 
 if (category == "tech") { fixed_fvf_1 = 0.08; fixed_fvf_2 = 0.05; fixed_fvf_3 = 0.02; }
 else if (category == "acc") { fixed_fvf_1 = 0.12; fixed_fvf_2 = 0.09; fixed_fvf_3 = 0.02; }
 else if (category == "media") { fixed_fvf_1 = 0.15; fixed_fvf_2 = 0.05; fixed_fvf_3 = 0.02; }
 else if (category == "other") { fixed_fvf_1 = 0.12; fixed_fvf_2 = 0.06; fixed_fvf_3 = 0.02; }
 
 var auction_fvf_1 = 0.0875;
 var auction_fvf_2 = 0.04;
 var auction_fvf_3 = 0.02;
 
 if (store_level=="none") { auction_fvf_1 = 0.09; auction_fvf_2 = 0.09; auction_fvf_3 = 0.09; }
 
 var industrial_fvf = 0.01;

 // ------------------------------------------------------------------------------------------------------------- //  
 // Determine Listing Upgrade Fees
 // ------------------------------------------------------------------------------------------------------------- //
 var lu_fees = amt(document.getElementById('total_lu_fees').value);

 // ------------------------------------------------------------------------------------------------------------- // 
 // Multiply Listing Upgrade Fees by Qty Listed
 // ------------------------------------------------------------------------------------------------------------- //
 lu_fees *= qty_listed;
 lu_fees = Math.round(lu_fees*100)/100;

 // ------------------------------------------------------------------------------------------------------------- //  
 // Determine Auction Style Insertion Fee
 // ------------------------------------------------------------------------------------------------------------- //
 var auction_insertion_fee = 0.00;
 var auction_insertion_fee_giving_works_credit = 0.00;
 if ((store_level=="anchor") || (store_level=="premium") || (store_level=="basic")) {
  if (opening_value >= 200) { auction_insertion_fee = 2.00; }
  else if (opening_value >= 50) { auction_insertion_fee = 1.00; }
  else if (opening_value >= 25) { auction_insertion_fee = 0.75; }
  else if (opening_value >= 10) { auction_insertion_fee = 0.50; }
  else if (opening_value >= 1) { auction_insertion_fee = 0.25; }
  else if (opening_value >= 0.01) { auction_insertion_fee = 0.10; }
 }
 else {
  if (opening_value >= 200) { auction_insertion_fee = 2.00; }
  else if (opening_value >= 50) { auction_insertion_fee = 1.00; }
  else if (opening_value >= 25) { auction_insertion_fee = 0.75; }
  else if (opening_value >= 10) { auction_insertion_fee = 0.50; }
  else if (opening_value >= 1) { auction_insertion_fee = 0.25; }
  else if (opening_value >= 0.01) {
   if (reserve_price > 0) { auction_insertion_fee = 0.10; }
   else { auction_insertion_fee = 0.00; }
  }
 }
 if (category == "industrial") { auction_insertion_fee = 20.00; }
 
 if ((auction_insertion_fee > 0) && (typeof ebay_giving_works_override != "undefined")) {
  auction_insertion_fee_giving_works_credit = auction_insertion_fee * ebay_giving_works_override;
  auction_insertion_fee_giving_works_credit = Math.round(auction_insertion_fee_giving_works_credit*100)/100;
  auction_insertion_fee = auction_insertion_fee - auction_insertion_fee_giving_works_credit; 
 }
 
 if (typeof insertion_override != "undefined") { auction_insertion_fee = insertion_override; }
 
 // ------------------------------------------------------------------------------------------------------------- //
 // 2 categories
 // ------------------------------------------------------------------------------------------------------------- //
 auction_insertion_fee *= (document.getElementById('two_categories').checked) ? 2 : 1;
 
 // ------------------------------------------------------------------------------------------------------------- // 
 // Multiply Insertion Fee by Qty Listed
 // ------------------------------------------------------------------------------------------------------------- //
 document.getElementById('auction_insertion_times').innerHTML = (qty_listed > 1) ? '($'+ auction_insertion_fee.toFixed(2) + ' x ' + qty_listed + ')' : '';
 auction_insertion_fee *= qty_listed;
 auction_insertion_fee = Math.round(auction_insertion_fee*100)/100;

 // ------------------------------------------------------------------------------------------------------------- // 
 // Determine Auction Style Reserve Fee
 // ------------------------------------------------------------------------------------------------------------- //
 var auction_reserve_fee = 0.00;
 if (reserve_price >= 200) {
  auction_reserve_fee = 0.01 * reserve_price;
  auction_reserve_fee = Math.round(auction_reserve_fee*100)/100;
  if (auction_reserve_fee > 50) { auction_reserve_fee = 50.00; }
 }
 else if (reserve_price >= 0.01) {
  auction_reserve_fee = 2.00;
 }
 if ((reserve_price > 0) && (category == "industrial")) { auction_reserve_fee = 5.00; }

 // ------------------------------------------------------------------------------------------------------------- // 
 // Multiply Reserve Fee by Qty Listed
 // ------------------------------------------------------------------------------------------------------------- //
 auction_reserve_fee *= qty_listed;
 auction_reserve_fee = Math.round(auction_reserve_fee*100)/100;

 // ------------------------------------------------------------------------------------------------------------- // 
 // Determine Auction Style Buy It Now Fee
 // ------------------------------------------------------------------------------------------------------------- //
 var auction_bin_fee = 0.00;
 if (bin_price >= 50) { auction_bin_fee = 0.25; }
 else if (bin_price >= 25) { auction_bin_fee = 0.20; }
 else if (bin_price >= 10) { auction_bin_fee = 0.10; }
 else if (bin_price >= 0.99) { auction_bin_fee = 0.05; }
 if (opening_value == 0) { auction_bin_fee = 0.00; }

 // ------------------------------------------------------------------------------------------------------------- // 
 // Multiply BIN Fee by Qty Listed
 // ------------------------------------------------------------------------------------------------------------- //
 auction_bin_fee *= qty_listed;
 auction_bin_fee = Math.round(auction_bin_fee*100)/100;

 // ------------------------------------------------------------------------------------------------------------- //  
 // Determine Auction Style Final Value Fees
 // ------------------------------------------------------------------------------------------------------------- //
 var auction_fvf = 0.00;
 var auction_fvf_giving_works_credit = 0.00;
 if ((store_level=="anchor") || (store_level=="premium") || (store_level=="basic")) {
  if (closing_price > 1000) { auction_fvf = ((closing_price-1000) * auction_fvf_3) + (950 * auction_fvf_2) + (50 * auction_fvf_1); }
  else if (closing_price > 50) { auction_fvf = ((closing_price-50) * auction_fvf_2) + (50 * auction_fvf_1); }
  else { auction_fvf = (closing_price * auction_fvf_1); }
 }
 else {
  auction_fvf = (auction_fvf_1 * closing_price);
  if (auction_fvf > 50) { auction_fvf = 50.00; }
 }
 if (category == "industrial") { auction_fvf = closing_price * industrial_fvf; if(auction_fvf>250){auction_fvf=250;} }
 auction_fvf = Math.round(auction_fvf*100)/100;
 
 if ((auction_fvf > 0) && (typeof ebay_giving_works_override != "undefined")) {
  auction_fvf_giving_works_credit = auction_fvf * ebay_giving_works_override;
  auction_fvf_giving_works_credit = Math.round(auction_fvf_giving_works_credit*100)/100;
 }

 // ------------------------------------------------------------------------------------------------------------- // 
 // Determine Auction Style Powerseller Discount
 // ------------------------------------------------------------------------------------------------------------- //
 var auction_powerseller_discount = 0.00;
 auction_powerseller_discount = auction_fvf * fvf_discount;
 auction_powerseller_discount = Math.round(auction_powerseller_discount*100)/100;
 auction_fvf = auction_fvf - auction_powerseller_discount - auction_fvf_giving_works_credit;
 auction_fvf = Math.round(auction_fvf*100)/100;

 // ------------------------------------------------------------------------------------------------------------- // 
 // Multiply FVF by Qty Sold
 // ------------------------------------------------------------------------------------------------------------- //
 document.getElementById('auction_fvf_times').innerHTML = (qty_sold > 1) ? '($'+ auction_fvf.toFixed(2) + ' x ' + qty_sold + ')' : '';
 auction_fvf *= qty_sold;
 auction_fvf = Math.round(auction_fvf*100)/100;

 // ------------------------------------------------------------------------------------------------------------- // 
 // Determine Auction Style PayPal Fees
 // ------------------------------------------------------------------------------------------------------------- //
 var auction_paypal_fees = 0.00;
 auction_paypal_fees = ((closing_price*((qty_shipped==1)?qty_sold:1)) + sh_charged) * paypal_percent + paypal_fixed;
 auction_paypal_fees = Math.round(auction_paypal_fees*100)/100;
 if (closing_price == 0) { auction_paypal_fees = 0.00; }

 // ------------------------------------------------------------------------------------------------------------- // 
 // Multiply PayPal Fee by Qty Shipped
 // ------------------------------------------------------------------------------------------------------------- //
 document.getElementById('auction_paypal_times').innerHTML = (qty_shipped > 1) ? '($'+ auction_paypal_fees.toFixed(2) + ' x ' + qty_shipped + ')' : '';
 auction_paypal_fees *= qty_shipped;
 auction_paypal_fees = Math.round(auction_paypal_fees*100)/100;

 // ------------------------------------------------------------------------------------------------------------- // 
 // Determine Total Auction Style Fees
 // ------------------------------------------------------------------------------------------------------------- //
 var auction_total_fees = 0.00;
 var auction_total_ebay_fees = 0.00;
 auction_total_ebay_fees = auction_insertion_fee + auction_reserve_fee + auction_bin_fee + lu_fees + auction_fvf; auction_total_ebay_fees = Math.round(auction_total_ebay_fees*100)/100;
 auction_total_fees = auction_total_ebay_fees + auction_paypal_fees;
 auction_total_fees = Math.round(auction_total_fees*100)/100;
 
 // ------------------------------------------------------------------------------------------------------------- //
 // Determine Total Auction Style Profit
 // ------------------------------------------------------------------------------------------------------------- //
 var auction_total_profit = 0.00;
 var auction_amount_donated = 0.00;
 if (typeof ebay_giving_works_override != "undefined") {
  auction_amount_donated = closing_price * ebay_giving_works_override;
  auction_amount_donated = Math.round(auction_amount_donated*100)/100;
 }
 auction_total_profit = (closing_price*qty_sold) + (sh_charged*qty_shipped) - (auction_amount_donated*qty_sold) - (cost_of_postage*qty_shipped) - (cost_to_acquire*qty_sold) - auction_total_fees;
 auction_total_profit = Math.round(auction_total_profit*100)/100;
 if (auction_total_fees == 0) { auction_total_profit = 0; }

 // ------------------------------------------------------------------------------------------------------------- // 
 // Determine Fixed Price Insertion Fee
 // ------------------------------------------------------------------------------------------------------------- //
 var fixed_insertion_fee = 0.00;
 var fixed_insertion_fee_reverse = 0.00;
 var fixed_insertion_fee_giving_works_credit = 0.00;
 if (store_level == "anchor") { fixed_insertion_fee = 0.03; }
 else if (store_level == "premium") { fixed_insertion_fee = 0.05; }
 else if (store_level == "basic") { fixed_insertion_fee = 0.20; }
 else if (store_level == "none") { fixed_insertion_fee = 0.50; }
 if (typeof use_prefilled != "undefined") {
  if ((use_prefilled == 1) && (category == "media") && (fixed_insertion_fee > 0.05)) {
   fixed_insertion_fee = 0.05;
  }
 }
 if (category == "industrial") { fixed_insertion_fee = 20.00; }

 if ((fixed_insertion_fee > 0) && (typeof ebay_giving_works_override != "undefined")) {
  fixed_insertion_fee_giving_works_credit = fixed_insertion_fee * ebay_giving_works_override;
  fixed_insertion_fee_giving_works_credit = Math.round(fixed_insertion_fee_giving_works_credit*100)/100;
  fixed_insertion_fee = fixed_insertion_fee - fixed_insertion_fee_giving_works_credit;
 }
 
 // ------------------------------------------------------------------------------------------------------------- //
 // 2 categories
 // ------------------------------------------------------------------------------------------------------------- //
 fixed_insertion_fee *= (document.getElementById('two_categories').checked) ? 2 : 1;
 fixed_insertion_fee_reverse = fixed_insertion_fee;
 
 // ------------------------------------------------------------------------------------------------------------- //
 // Multiply Insertion Fee by Qty Listed
 // ------------------------------------------------------------------------------------------------------------- //
 if (fixed_value == 0) { fixed_insertion_fee = 0.00; }
 document.getElementById('fixed_insertion_times').innerHTML = (qty_listed > 1) ? '($'+ fixed_insertion_fee.toFixed(2) + ' x ' + qty_listed + ')' : '';
 fixed_insertion_fee *= qty_listed;
 fixed_insertion_fee = Math.round(fixed_insertion_fee*100)/100;
 
 // ------------------------------------------------------------------------------------------------------------- // 
 // Determine Fixed Price Final Value Fees
 // ------------------------------------------------------------------------------------------------------------- //
 var fixed_fvf = 0.00;
 var fixed_fvf_giving_works_credit = 0.00;
 if (fixed_value > 1000) { fixed_fvf = ((fixed_value-1000) * fixed_fvf_3) + (950 * fixed_fvf_2) + (50 * fixed_fvf_1); }
 else if (fixed_value > 50) { fixed_fvf = ((fixed_value-50) * fixed_fvf_2) + (50 * fixed_fvf_1); }
 else { fixed_fvf = (fixed_value * fixed_fvf_1); }
 if (category == "industrial") { fixed_fvf = fixed_value * industrial_fvf; if(fixed_fvf>250){fixed_fvf=250;} }
 fixed_fvf = Math.round(fixed_fvf*100)/100;
 
 if ((fixed_fvf > 0) && (typeof ebay_giving_works_override != "undefined")) {
  fixed_fvf_giving_works_credit = fixed_fvf * ebay_giving_works_override;
  fixed_fvf_giving_works_credit = Math.round(fixed_fvf_giving_works_credit*100)/100;
 }
 
 // ------------------------------------------------------------------------------------------------------------- //
 // Determine Fixed Price Powerseller Discount
 // ------------------------------------------------------------------------------------------------------------- //
 var fixed_powerseller_discount = 0.00;
 fixed_powerseller_discount = fixed_fvf * fvf_discount;
 fixed_powerseller_discount = Math.round(fixed_powerseller_discount*100)/100;
 fixed_fvf = fixed_fvf - fixed_powerseller_discount - fixed_fvf_giving_works_credit;
 fixed_fvf = Math.round(fixed_fvf*100)/100;

 // ------------------------------------------------------------------------------------------------------------- // 
 // Multiply FVF by Qty Sold
 // ------------------------------------------------------------------------------------------------------------- //
 document.getElementById('fixed_fvf_times').innerHTML = (qty_sold > 1) ? '($'+ fixed_fvf.toFixed(2) + ' x ' + qty_sold + ')' : '';
 fixed_fvf *= qty_sold;
 fixed_fvf = Math.round(fixed_fvf*100)/100;
 
 // ------------------------------------------------------------------------------------------------------------- //
 // Determine Fixed Price PayPal Fees
 // ------------------------------------------------------------------------------------------------------------- //
 var fixed_paypal_fees = 0.00;
 fixed_paypal_fees = ((fixed_value*((qty_shipped==1)?qty_sold:1)) + sh_charged) * paypal_percent + paypal_fixed;
 fixed_paypal_fees = Math.round(fixed_paypal_fees*100)/100;
 if (fixed_value == 0) { fixed_paypal_fees = 0.00; }

 // ------------------------------------------------------------------------------------------------------------- // 
 // Multiply PayPal Fee by Qty Shipped
 // ------------------------------------------------------------------------------------------------------------- //
 document.getElementById('fixed_paypal_times').innerHTML = (qty_shipped > 1) ? '($'+ fixed_paypal_fees.toFixed(2) + ' x ' + qty_shipped + ')' : '';
 fixed_paypal_fees *= qty_shipped;
 fixed_paypal_fees = Math.round(fixed_paypal_fees*100)/100;
 
 // ------------------------------------------------------------------------------------------------------------- //
 // Determine Total Fixed Price Fees
 // ------------------------------------------------------------------------------------------------------------- //
 var fixed_total_fees = 0.00;
 var fixed_total_ebay_fees = 0.00;
 fixed_total_ebay_fees = fixed_insertion_fee + lu_fees + fixed_fvf; fixed_total_ebay_fees = Math.round(fixed_total_ebay_fees*100)/100;
 fixed_total_fees =  fixed_total_ebay_fees + fixed_paypal_fees;
 fixed_total_fees = Math.round(fixed_total_fees*100)/100;
 
 // ------------------------------------------------------------------------------------------------------------- //
 // Determine Total Fixed Price Profit
 // ------------------------------------------------------------------------------------------------------------- //
 var fixed_total_profit = 0.00;
 var fixed_amount_donated = 0.00;
 if (typeof ebay_giving_works_override != "undefined") {
  fixed_amount_donated = fixed_value * ebay_giving_works_override;
  fixed_amount_donated = Math.round(fixed_amount_donated*100)/100;
 }
 fixed_total_profit = (fixed_value*qty_sold) + (sh_charged*qty_shipped) - (fixed_amount_donated*qty_sold) - (cost_of_postage*qty_shipped) - (cost_to_acquire*qty_sold) - fixed_total_fees;
 fixed_total_profit = Math.round(fixed_total_profit*100)/100;
 if (fixed_total_fees == 0) { fixed_total_profit = 0; }
 
 // ------------------------------------------------------------------------------------------------------------- //
 // Print results to screen
 // ------------------------------------------------------------------------------------------------------------- //
 document.getElementById('auction_insertion_fee').innerHTML = auction_insertion_fee.toFixed(2);
 document.getElementById('auction_reserve_fee').innerHTML = auction_reserve_fee.toFixed(2);
 document.getElementById('auction_bin_fee').innerHTML = auction_bin_fee.toFixed(2);
 document.getElementById('auction_lu_fees').innerHTML = lu_fees.toFixed(2);
 document.getElementById('auction_fvf').innerHTML = auction_fvf.toFixed(2);
 document.getElementById('auction_ebay_fees').innerHTML = auction_total_ebay_fees.toFixed(2);
 document.getElementById('auction_paypal_fees').innerHTML = auction_paypal_fees.toFixed(2);
 document.getElementById('auction_total_fees').innerHTML = auction_total_fees.toFixed(2);
 document.getElementById('auction_total_profit').innerHTML = auction_total_profit.toFixed(2);
 document.getElementById('fixed_insertion_fee').innerHTML = fixed_insertion_fee.toFixed(2);
 document.getElementById('fixed_lu_fees').innerHTML = lu_fees.toFixed(2);
 document.getElementById('fixed_fvf').innerHTML = fixed_fvf.toFixed(2);
 document.getElementById('fixed_ebay_fees').innerHTML = fixed_total_ebay_fees.toFixed(2);
 document.getElementById('fixed_paypal_fees').innerHTML = fixed_paypal_fees.toFixed(2);
 document.getElementById('fixed_total_fees').innerHTML = fixed_total_fees.toFixed(2);
 document.getElementById('fixed_total_profit').innerHTML = fixed_total_profit.toFixed(2);
 
 // ------------------------------------------------------------------------------------------------------------- //
 // determine which format to show
 // ------------------------------------------------------------------------------------------------------------- //
 var total_ebay_fees_to_use = 0.00;
 var total_paypal_fees_to_use = 0.00;
 var total_profit_to_use = 0.00;
 
 if (opening_price > 0) {
  total_ebay_fees_to_use = auction_total_ebay_fees;
  total_paypal_fees_to_use = auction_paypal_fees;
  total_profit_to_use = auction_total_profit;
 }
 else {
  total_ebay_fees_to_use = fixed_total_ebay_fees;
  total_paypal_fees_to_use = fixed_paypal_fees;
  total_profit_to_use = fixed_total_profit;
 }
 if (total_ebay_fees_to_use == 0) { total_ebay_fees_to_use = 0.00; }
 if (total_paypal_fees_to_use == 0) { total_paypal_fees_to_use = 0.00; }
 if (total_profit_to_use == 0) { total_profit_to_use = 0.00; }

 // ------------------------------------------------------------------------------------------------------------- //
 // color total profit red
 // ------------------------------------------------------------------------------------------------------------- //
 if (total_profit_to_use < 0) {
  document.getElementById('total_profit').style.color = '#FF0000';
  document.getElementById('profit_loss_div').style.backgroundImage = "url('bg_textbox_green_red.gif')";
  //document.getElementById('profit_dollar_sign_svg').setAttribute('fill','#FF0000');
  //if (document.getElementById('profit_dollar_sign_vml')) { document.getElementById('profit_dollar_sign_vml').style.color = '#FF0000'; }
 }
 else {
  document.getElementById('total_profit').style.color = '#000000';
  document.getElementById('profit_loss_div').style.backgroundImage = "url('bg_textbox_green.gif')";
  //document.getElementById('profit_dollar_sign_svg').setAttribute('fill','#000000');
  //if (document.getElementById('profit_dollar_sign_vml')) { document.getElementById('profit_dollar_sign_vml').style.color = '#000000'; }
 }
 
 // ------------------------------------------------------------------------------------------------------------- //
 // color fixed price profit red
 // ------------------------------------------------------------------------------------------------------------- //
 if (fixed_total_profit < 0) {
  document.getElementById('fixed_total_profit').style.color = '#FF0000';
  document.getElementById('fixed_profit_dollar_sign').style.color = '#FF0000';
 }
 else {
  document.getElementById('fixed_total_profit').style.color = '#000000';
  document.getElementById('fixed_profit_dollar_sign').style.color = '#000000';
 }
 
 // ------------------------------------------------------------------------------------------------------------- //
 // color auction style profit red
 // ------------------------------------------------------------------------------------------------------------- //
 if (auction_total_profit < 0) {
  document.getElementById('auction_total_profit').style.color = '#FF0000';
  document.getElementById('auction_profit_dollar_sign').style.color = '#FF0000';
 }
 else {
  document.getElementById('auction_total_profit').style.color = '#000000';
  document.getElementById('auction_profit_dollar_sign').style.color = '#000000';
 } 

 document.getElementById('total_ebay_fees').value = total_ebay_fees_to_use.toFixed(2);
 document.getElementById('total_paypal_fees').value = total_paypal_fees_to_use.toFixed(2);
 document.getElementById('total_profit').value = total_profit_to_use.toFixed(2);
 
 // ------------------------------------------------------------------------------------------------------------- //
 // Reverse calculate price
 // ------------------------------------------------------------------------------------------------------------- //
 var desired_net_profit = amt(document.getElementById('desired_net_profit').value);
 var fixed_fvf_1_to_use = fixed_fvf_1 * (1 - fvf_discount - ebay_giving_works_override);
 var fixed_fvf_2_to_use = fixed_fvf_2 * (1 - fvf_discount - ebay_giving_works_override);
 var fixed_fvf_3_to_use = fixed_fvf_3 * (1 - fvf_discount - ebay_giving_works_override);
 fixed_fvf_1_to_use = Math.round(fixed_fvf_1_to_use*10000)/10000;
 fixed_fvf_2_to_use = Math.round(fixed_fvf_2_to_use*10000)/10000;
 fixed_fvf_3_to_use = Math.round(fixed_fvf_3_to_use*10000)/10000;

 // $0.01 - $50.00
 var other1_price = (desired_net_profit - (sh_charged - cost_of_postage - cost_to_acquire - fixed_insertion_fee_reverse - lu_fees - 0 + (0*fixed_fvf_1_to_use) - paypal_fixed - (paypal_percent * sh_charged))) / (1 - fixed_fvf_1_to_use - paypal_percent - ebay_giving_works_override);
 var other1_insertion = fixed_insertion_fee_reverse + lu_fees;
 var other1_fvf = (other1_price>1000) ? ((other1_price-1000)*fixed_fvf_3_to_use)+(950*fixed_fvf_2_to_use)+(50*fixed_fvf_1_to_use) : (other1_price>50) ? ((other1_price-50)*fixed_fvf_2_to_use)+(50*fixed_fvf_1_to_use) : (other1_price*fixed_fvf_1_to_use);
 other1_fvf = Math.round(other1_fvf*100)/100;
 var other1_profit = other1_price + sh_charged - cost_of_postage - cost_to_acquire - other1_insertion - other1_fvf - (Math.round(ebay_giving_works_override*other1_price*100)/100) - (Math.round(((other1_price+sh_charged)*paypal_percent+paypal_fixed)*100)/100);
 
 // $50.01 - $1,000.00
 var other2_price = (desired_net_profit - (sh_charged - cost_of_postage - cost_to_acquire - fixed_insertion_fee_reverse - lu_fees - (50*fixed_fvf_1_to_use) + (50*fixed_fvf_2_to_use) - paypal_fixed - (paypal_percent*sh_charged))) / (1 - fixed_fvf_2_to_use - paypal_percent - ebay_giving_works_override);
 var other2_insertion = fixed_insertion_fee_reverse + lu_fees;
 var other2_fvf = (other2_price>1000) ? ((other2_price-1000)*fixed_fvf_3_to_use)+(950*fixed_fvf_2_to_use)+(50*fixed_fvf_1_to_use) : (other2_price>50) ? ((other2_price-50)*fixed_fvf_2_to_use)+(50*fixed_fvf_1_to_use) : (other2_price*fixed_fvf_1_to_use);
 other2_fvf = Math.round(other2_fvf*100)/100;
 var other2_profit = other2_price + sh_charged - cost_of_postage - cost_to_acquire - other2_insertion - other2_fvf - (Math.round(ebay_giving_works_override*other2_price*100)/100) - (Math.round(((other2_price+sh_charged)*paypal_percent+paypal_fixed)*100)/100);

 // $1,000.01+
 var other3_price = (desired_net_profit - (sh_charged - cost_of_postage - cost_to_acquire - fixed_insertion_fee_reverse - lu_fees - (50*fixed_fvf_1_to_use) - (950*fixed_fvf_2_to_use) + (1000*fixed_fvf_3_to_use) - paypal_fixed - (paypal_percent*sh_charged))) / (1 - fixed_fvf_3_to_use - paypal_percent - ebay_giving_works_override);
 var other3_insertion = fixed_insertion_fee_reverse + lu_fees;
 var other3_fvf = (other3_price>1000) ? ((other3_price-1000)*fixed_fvf_3_to_use)+(950*fixed_fvf_2_to_use)+(50*fixed_fvf_1_to_use) : (other3_price>50) ? ((other3_price-50)*fixed_fvf_2_to_use)+(50*fixed_fvf_1_to_use) : (other3_price*fixed_fvf_1_to_use);
 other3_fvf = Math.round(other3_fvf*100)/100;
 var other3_profit = other3_price + sh_charged - cost_of_postage - cost_to_acquire - other3_insertion - other3_fvf - (Math.round(ebay_giving_works_override*other3_price*100)/100) - (Math.round(((other3_price+sh_charged)*paypal_percent+paypal_fixed)*100)/100);

 var other_profit1diff = Math.round(Math.abs(other1_profit-desired_net_profit)*100)/100;
 var other_profit2diff = Math.round(Math.abs(other2_profit-desired_net_profit)*100)/100;
 var other_profit3diff = Math.round(Math.abs(other3_profit-desired_net_profit)*100)/100;
 
 var tweak = 0.00;
 var reverse_price = 0.00;
 if (other_profit1diff == Math.min(other_profit1diff,other_profit2diff,other_profit3diff)) {
  tweak = desired_net_profit - other1_profit;
  reverse_price = other1_price + tweak;
 }
 else if (other_profit2diff == Math.min(other_profit1diff,other_profit2diff,other_profit3diff)) {
  tweak = desired_net_profit - other2_profit;
  reverse_price = other2_price + tweak;
 }
 else if (other_profit3diff == Math.min(other_profit1diff,other_profit2diff,other_profit3diff)) {
  tweak = desired_net_profit - other3_profit;
  reverse_price = other3_price + tweak;
 }
 reverse_price = Math.round(reverse_price*100)/100;
 document.getElementById('new_price').value = reverse_price.toFixed(2);
 
 // ------------------------------------------------------------------------------------------------------------- //
 // Reverse calculate S&H
 // ------------------------------------------------------------------------------------------------------------- //
 var new_sh = 0.00;
 if (fixed_value > 0) {
  new_sh = (desired_net_profit + cost_to_acquire + cost_of_postage + total_ebay_fees_to_use - fixed_value + paypal_fixed + (fixed_value * paypal_percent)) / (1 - paypal_percent);
  new_sh = Math.round(new_sh*100)/100;
 }
 if (new_sh == 0) { new_sh = 0.00; }
 if (new_sh < 0) { document.getElementById('new_sh').value = '---'; }
 else { document.getElementById('new_sh').value = new_sh.toFixed(2); }
 
 // ------------------------------------------------------------------------------------------------------------- //
 // Determine break even price for Auction Style
 // ------------------------------------------------------------------------------------------------------------- //
 var auction_fvf_1_to_use = auction_fvf_1 * (1 - fvf_discount - ebay_giving_works_override);
 var auction_fvf_2_to_use = auction_fvf_2 * (1 - fvf_discount - ebay_giving_works_override);
 var auction_fvf_3_to_use = auction_fvf_3 * (1 - fvf_discount - ebay_giving_works_override);
 auction_fvf_1_to_use = Math.round(auction_fvf_1_to_use*10000)/10000;
 auction_fvf_2_to_use = Math.round(auction_fvf_2_to_use*10000)/10000;
 auction_fvf_3_to_use = Math.round(auction_fvf_3_to_use*10000)/10000;
 
 // $0.01 - $50.00
 var auction1_price = (0.00 - (sh_charged - cost_of_postage - cost_to_acquire - auction_insertion_fee - auction_reserve_fee - auction_bin_fee - lu_fees - 0 + (0 * auction_fvf_1_to_use) - paypal_fixed - (paypal_percent * sh_charged))) / (1 - auction_fvf_1_to_use - paypal_percent - ebay_giving_works_override);
 var auction1_insertion = auction_insertion_fee + auction_reserve_fee + auction_bin_fee + lu_fees;
 var auction1_fvf = (auction1_price>1000) ? ((auction1_price-1000)*auction_fvf_3_to_use)+(950*auction_fvf_2_to_use)+(50*auction_fvf_1_to_use) : (auction1_price>50) ? ((auction1_price-50)*auction_fvf_2_to_use)+(50*auction_fvf_1_to_use) : (auction1_price*auction_fvf_1_to_use);
 auction1_fvf = Math.round(auction1_fvf*100)/100;
 var auction1_profit = auction1_price + sh_charged - cost_of_postage - cost_to_acquire - auction1_insertion - auction1_fvf - (Math.round(ebay_giving_works_override*auction1_price*100)/100) - (Math.round(((auction1_price+sh_charged)*paypal_percent+paypal_fixed)*100)/100);
 
 // $50.01 - $1,000
 var auction2_price = (0.00 - (sh_charged - cost_of_postage - cost_to_acquire - auction_insertion_fee - auction_reserve_fee - auction_bin_fee - lu_fees - (50 * auction_fvf_1_to_use) + (50 * auction_fvf_2_to_use) - paypal_fixed - (paypal_percent * sh_charged))) / (1 - auction_fvf_2_to_use - paypal_percent - ebay_giving_works_override);
 var auction2_insertion = auction_insertion_fee + auction_reserve_fee + auction_bin_fee + lu_fees;
 var auction2_fvf = (auction2_price>1000) ? ((auction2_price-1000)*auction_fvf_3_to_use)+(950*auction_fvf_2_to_use)+(50*auction_fvf_1_to_use) : (auction2_price>50) ? ((auction2_price-50)*auction_fvf_2_to_use)+(50*auction_fvf_1_to_use) : (auction2_price*auction_fvf_1_to_use);
 auction2_fvf = Math.round(auction2_fvf*100)/100;
 var auction2_profit = auction2_price + sh_charged - cost_of_postage - cost_to_acquire - auction2_insertion - auction2_fvf - (Math.round(ebay_giving_works_override*auction2_price*100)/100) - (Math.round(((auction2_price+sh_charged)*paypal_percent+paypal_fixed)*100)/100);

 // $1,000.01 or more
 var auction3_price = (0.00 - (sh_charged - cost_of_postage - cost_to_acquire - auction_insertion_fee - auction_reserve_fee - auction_bin_fee - lu_fees - (50 * auction_fvf_1_to_use) - (950 * auction_fvf_2_to_use) + (1000 * auction_fvf_3_to_use) - paypal_fixed - (paypal_percent * sh_charged))) / (1 - auction_fvf_3_to_use - paypal_percent - ebay_giving_works_override);
 var auction3_insertion = auction_insertion_fee + auction_reserve_fee + auction_bin_fee + lu_fees;
 var auction3_fvf = (auction3_price>1000) ? ((auction3_price-1000)*auction_fvf_3_to_use)+(950*auction_fvf_2_to_use)+(50*auction_fvf_1_to_use) : (auction3_price>50) ? ((auction3_price-50)*auction_fvf_2_to_use)+(50*auction_fvf_1_to_use) : (auction3_price*auction_fvf_1_to_use);
 auction3_fvf = Math.round(auction3_fvf*100)/100;
 var auction3_profit = auction3_price + sh_charged - cost_of_postage - cost_to_acquire - auction3_insertion - auction3_fvf - (Math.round(ebay_giving_works_override*auction3_price*100)/100) - (Math.round(((auction3_price+sh_charged)*paypal_percent+paypal_fixed)*100)/100);
 
 // $555.57 or more (with max FVF)
 var auction4_price = (0.00 - (sh_charged - cost_of_postage - cost_to_acquire - auction_insertion_fee - auction_reserve_fee - auction_bin_fee - lu_fees - (50.00 * (1 - fvf_discount - ebay_giving_works_override)) - paypal_fixed - (paypal_percent * sh_charged))) / (1 - paypal_percent - ebay_giving_works_override);
 var auction4_insertion = auction_insertion_fee + auction_reserve_fee + auction_bin_fee + lu_fees;
 var auction4_fvf = (auction4_price * auction_fvf_1 > 50.00) ? 50.00 : (auction4_price * auction_fvf_1);
 auction4_fvf *= (1 - fvf_discount - ebay_giving_works_override);
 auction4_fvf = Math.round(auction4_fvf*100)/100;
 var auction4_profit = auction4_price + sh_charged - cost_of_postage - cost_to_acquire - auction4_insertion - auction4_fvf - (Math.round(ebay_giving_works_override*auction4_price*100)/100) - (Math.round(((auction4_price+sh_charged)*paypal_percent+paypal_fixed)*100)/100);
 
 var auction_profit1diff = Math.round(Math.abs(auction1_profit-0.00)*100)/100;
 var auction_profit2diff = Math.round(Math.abs(auction2_profit-0.00)*100)/100;
 var auction_profit3diff = Math.round(Math.abs(auction3_profit-0.00)*100)/100;
 var auction_profit4diff = Math.round(Math.abs(auction4_profit-0.00)*100)/100;
 
 var auction_tweak = 0.00;
 var auction_reverse_price = 0.00;
 if ((store_level == "none") && (auction_profit4diff == Math.min(auction_profit1diff,auction_profit2diff,auction_profit3diff,auction_profit4diff))) {
  auction_tweak = 0.00 - auction4_profit;
  auction_reverse_price = auction4_price + auction_tweak;
 }
 else if (auction_profit3diff == Math.min(auction_profit1diff,auction_profit2diff,auction_profit3diff)) {
  auction_tweak = 0.00 - auction3_profit;
  auction_reverse_price = auction3_price + auction_tweak;
 }
 else if (auction_profit2diff == Math.min(auction_profit1diff,auction_profit2diff,auction_profit3diff)) {
  auction_tweak = 0.00 - auction2_profit;
  auction_reverse_price = auction2_price + auction_tweak;
 }
 else if (auction_profit1diff == Math.min(auction_profit1diff,auction_profit2diff,auction_profit3diff)) {
  auction_tweak = 0.00 - auction1_profit;
  auction_reverse_price = auction1_price + auction_tweak;
 }
 auction_reverse_price = Math.round(auction_reverse_price*100)/100;
 document.getElementById('auction_break_even').innerHTML = "$" + auction_reverse_price.toFixed(2);
 
 // ------------------------------------------------------------------------------------------------------------- //
 // Determine break even price for Fixed Price
 // ------------------------------------------------------------------------------------------------------------- //
 // $0.01 - $50.00
 other1_price = (0.00 - (sh_charged - cost_of_postage - cost_to_acquire - fixed_insertion_fee_reverse - lu_fees - 0 + (0*fixed_fvf_1_to_use) - paypal_fixed - (paypal_percent * sh_charged))) / (1 - fixed_fvf_1_to_use - paypal_percent - ebay_giving_works_override);
 other1_insertion = fixed_insertion_fee_reverse + lu_fees;
 other1_fvf = (other1_price>1000) ? ((other1_price-1000)*fixed_fvf_3_to_use)+(950*fixed_fvf_2_to_use)+(50*fixed_fvf_1_to_use) : (other1_price>50) ? ((other1_price-50)*fixed_fvf_2_to_use)+(50*fixed_fvf_1_to_use) : (other1_price*fixed_fvf_1_to_use);
 other1_fvf = Math.round(other1_fvf*100)/100;
 other1_profit = other1_price + sh_charged - cost_of_postage - cost_to_acquire - other1_insertion - other1_fvf - (Math.round(ebay_giving_works_override*other1_price*100)/100) - (Math.round(((other1_price+sh_charged)*paypal_percent+paypal_fixed)*100)/100);
 
 // $50.01 - $1,000.00
 other2_price = (0.00 - (sh_charged - cost_of_postage - cost_to_acquire - fixed_insertion_fee_reverse - lu_fees - (50*fixed_fvf_1_to_use) + (50*fixed_fvf_2_to_use) - paypal_fixed - (paypal_percent*sh_charged))) / (1 - fixed_fvf_2_to_use - paypal_percent - ebay_giving_works_override);
 other2_insertion = fixed_insertion_fee_reverse + lu_fees;
 other2_fvf = (other2_price>1000) ? ((other2_price-1000)*fixed_fvf_3_to_use)+(950*fixed_fvf_2_to_use)+(50*fixed_fvf_1_to_use) : (other2_price>50) ? ((other2_price-50)*fixed_fvf_2_to_use)+(50*fixed_fvf_1_to_use) : (other2_price*fixed_fvf_1_to_use);
 other2_fvf = Math.round(other2_fvf*100)/100;
 other2_profit = other2_price + sh_charged - cost_of_postage - cost_to_acquire - other2_insertion - other2_fvf - (Math.round(ebay_giving_works_override*other2_price*100)/100) - (Math.round(((other2_price+sh_charged)*paypal_percent+paypal_fixed)*100)/100);

 // $1,000.01+
 other3_price = (0.00 - (sh_charged - cost_of_postage - cost_to_acquire - fixed_insertion_fee_reverse - lu_fees - (50*fixed_fvf_1_to_use) - (950*fixed_fvf_2_to_use) + (1000*fixed_fvf_3_to_use) - paypal_fixed - (paypal_percent*sh_charged))) / (1 - fixed_fvf_3_to_use - paypal_percent - ebay_giving_works_override);
 other3_insertion = fixed_insertion_fee_reverse + lu_fees;
 other3_fvf = (other3_price>1000) ? ((other3_price-1000)*fixed_fvf_3_to_use)+(950*fixed_fvf_2_to_use)+(50*fixed_fvf_1_to_use) : (other3_price>50) ? ((other3_price-50)*fixed_fvf_2_to_use)+(50*fixed_fvf_1_to_use) : (other3_price*fixed_fvf_1_to_use);
 other3_fvf = Math.round(other3_fvf*100)/100;
 other3_profit = other3_price + sh_charged - cost_of_postage - cost_to_acquire - other3_insertion - other3_fvf - (Math.round(ebay_giving_works_override*other3_price*100)/100) - (Math.round(((other3_price+sh_charged)*paypal_percent+paypal_fixed)*100)/100);

 other_profit1diff = Math.round(Math.abs(other1_profit-0.00)*100)/100;
 other_profit2diff = Math.round(Math.abs(other2_profit-0.00)*100)/100;
 other_profit3diff = Math.round(Math.abs(other3_profit-0.00)*100)/100;
 
 tweak = 0.00;
 reverse_price = 0.00;
 if (other_profit1diff == Math.min(other_profit1diff,other_profit2diff,other_profit3diff)) {
  tweak = 0.00 - other1_profit;
  reverse_price = other1_price + tweak;
 }
 else if (other_profit2diff == Math.min(other_profit1diff,other_profit2diff,other_profit3diff)) {
  tweak = 0.00 - other2_profit;
  reverse_price = other2_price + tweak;
 }
 else if (other_profit3diff == Math.min(other_profit1diff,other_profit2diff,other_profit3diff)) {
  tweak = 0.00 - other3_profit;
  reverse_price = other3_price + tweak;
 }
 reverse_price = Math.round(reverse_price*100)/100;
 document.getElementById('fixed_break_even').innerHTML = "$" + reverse_price.toFixed(2);

}
