arrProducts = new Array();
arrProducts[0] = 'PipsInvader|629.95';
arrProducts[1] = 'NeuralScalpingEA|849.95';
arrProducts[2] = 'Stomper_EURGBP_H1|799.95';
arrProducts[3] = 'IntellectualPro_EURGBP_H1|799.95';
arrProducts[4] = 'SteroID|999.95';
arrProducts[5] = 'NewsTrader|74.95';
arrProducts[6] = 'Chinchilla_GBPUSD_H1|232.95';
arrProducts[7] = 'MartingaleTheory_EURUSD_H1|239.95';
arrProducts[8] = 'UpStream_EURJPY_H1|267.95';
arrProducts[9] = 'UpStream_GBPUSD_H1|100.95';
arrProducts[10] = 'UpStream_AUDUSD_H1|128.95';
arrProducts[11] = 'UpStream_EURUSD_H1|128.95';
arrProducts[12] = 'Forexy_GBPUSD_H1|379.95';
arrProducts[13] = 'Forexy_USDJPY_H1|189.95';
arrProducts[14] = 'Chinchilla_EURCAD_H1|329.95';
arrProducts[15] = 'Trend_GBPUSD_M5|154.95';
arrProducts[16] = 'Medium_USDCAD_H1|114.95';
arrProducts[17] = 'Forexy_USDCAD_H1|277.95';
arrProducts[18] = 'Hadge_Optima-2_H1|516.95';
arrProducts[19] = 'Eldorado_mult|499.95';
arrProducts[20] = 'Condor_GBPJPY|314.96';
arrProducts[21] = 'Trafalgar_AUDJPY_H4|228.95';
arrProducts[22] = 'Trafalgar_GBPJPY_H4|228.95';
arrProducts[23] = 'X06+_USDCAD_H1|223.95';
arrProducts[24] = 'NINJA GBPJPY_D1|260.95';
arrProducts[25] = 'Surfing_GBPUSD-MM_H4|118.95';
arrProducts[26] = 'Surfing_EURUSD-MM_H4|118.95';


var Bonus1 = 'Indicador PowerSTLM';
var Bonus2 = 'Indicador TREND';
var Bonus3 = 'Indicador MACD-Div';
if (window.addEventListener) //DOM method for binding an event
  window.addEventListener("load", load_form, false)
else if (window.attachEvent) //IE exclusive method for binding an event
  window.attachEvent("onload", load_form)
else if (document.getElementById) //support older modern browsers
  window.onload = load_form;
function load_form()
{

  var lb1 = document.getElementById('lbProducts');
  for (i=0; i<arrProducts.length; i++) {
    var item = arrProducts[i].split('|');
    lb1.options[lb1.options.length] = new Option('$'+ item[1] +' ... '+ item[0], i);
  }
}
function order_now() {
  if (!submit_form(document.OrderForm)) return;
  //document.OrderForm.action = "http://it-d.org/phone3/index.php";

  document.OrderForm.action = "https://usd.swreg.org/cgi-bin/s.cgi?s=47339&p=473397SD1EZ&q=1&a=jp";
  document.OrderForm.submit();
}
function exp_add() {
  var lb1 = document.getElementById('lbProducts');
  if (lb1.selectedIndex == -1) {
    alert('No items selected!');
    return;
  }
  var lb2 = document.getElementById('lbMyProducts');
  for (i=0; i<lb2.length; i++) {
    if (lb2.options[i].value == lb1.options[lb1.selectedIndex].value) {
      alert('This item already added!');
      return;
    }
  }
  var opt = lb1.options[lb1.selectedIndex];
  lb2.options[lb2.options.length] = new Option(opt.text, opt.value);
  lb_select_item(lb2, lb2.length-1);
  update_cost();
}
function exp_remove() {
  var lb2 = document.getElementById('lbMyProducts');
  if (lb2.selectedIndex == -1) {
    return;
  }
  var ind = lb2.selectedIndex;
  lb2.remove(ind);
  if (lb2.length == 0) {
    lb_select_item(lb2, -1);
  }
  else {
    if (ind >= lb2.length) ind = lb2.length-1;
    lb_select_item(lb2, ind);
  }
  update_cost();
}
function lb_select_item(obj, ind) {
  setTimeout(function(){ obj.selectedIndex = ind; }, 1);

}
function update_cost() {
  var lb2 = document.getElementById('lbMyProducts');
  var cnt = lb2.length;
  if (cnt == 0) {
    document.getElementById('spMyCost').innerHTML = 'Cost: $0.00';
    return;
  }
  var pcnt = 5*cnt;
  if (cnt == 1) pcnt = 0;
  if (cnt == 2) pcnt = 10;
  if (cnt == 3) pcnt = 15;
  if (cnt == 4) pcnt = 18;
  if (cnt == 5) pcnt = 21;
  if (cnt == 6) pcnt = 23;
  if (cnt == 7) pcnt = 25;
  if (cnt >= 8) pcnt = 25 + 1*(cnt-7);
  var sum = 0.0;
  for (i=0; i<lb2.length; i++) {
    var ind = lb2.options[i].value;
    var item = arrProducts[ind].split('|');
    sum += parseFloat(item[1]);
  }
  sum = Math.round(100*sum)/100;
  var sum2 = sum*(1-pcnt/100);
  sum2 = Math.round(100*sum2)/100;
  document.getElementById('spMyCost').innerHTML = 'Cost: $'+sum+' - '+pcnt+'% = $'+sum2;
  document.getElementById('vp').value = sum2;
  if (Bonus1.length > 0) {
    var txt = '';
    if (cnt >= 3) txt = '+ BONUS: '+Bonus1;
    document.getElementById('spMyBonus1').innerHTML = txt;
    if (txt == '')
      document.getElementById('spMyBonus1').style.display = 'none';
    else
      document.getElementById('spMyBonus1').style.display = 'block';
  }
  if (Bonus2.length > 0) {
    var txt = '';
    if (cnt >= 5) txt = '+ BONUS: '+Bonus2;
    document.getElementById('spMyBonus2').innerHTML = txt;
    if (txt == '')
      document.getElementById('spMyBonus2').style.display = 'none';
    else
      document.getElementById('spMyBonus2').style.display = 'block';
  }
  if (Bonus3.length > 0) {
    var txt = '';
    if (cnt >= 7) txt = '+ BONUS: '+Bonus3;
    document.getElementById('spMyBonus3').innerHTML = txt;
    if (txt == '')
      document.getElementById('spMyBonus3').style.display = 'none';
    else
      document.getElementById('spMyBonus3').style.display = 'block';
  }
}
function get_orders_body() {
  var txt = '';
  var lb2 = document.getElementById('lbMyProducts');
  for (i=0; i<lb2.length; i++) {
    txt += lb2.options[i].text +'\n';
  }
  txt += '\n'+ document.getElementById('spMyCost').innerHTML;
  var txt2 = document.getElementById('spMyBonus1').innerHTML;
  if (txt2.length > 0) txt += '\n'+ txt2;
  txt2 = document.getElementById('spMyBonus2').innerHTML;
  if (txt2.length > 0) txt += '\n'+ txt2;
  txt2 = document.getElementById('spMyBonus3').innerHTML;
  if (txt2.length > 0) txt += '\n'+ txt2;
  document.getElementById('order_body').value = txt;

  txt = '';
  for (i=0; i<lb2.length; i++) {
    var item = arrProducts[lb2.options[i].value].split('|');
    txt += item[0] +'; ';

  }
  txt2 = document.getElementById('spMyBonus1').innerHTML;
  if (txt2.length > 0) txt += txt2 +'; ';
  txt2 = document.getElementById('spMyBonus2').innerHTML;
  if (txt2.length > 0) txt += txt2 +'; ';
  txt2 = document.getElementById('spMyBonus3').innerHTML;
  if (txt2.length > 0) txt += txt2 +'; ';
  document.getElementById('s').value = '47339';
  document.getElementById('p').value = '473397SD1EZ';
  document.getElementById('t').value = txt;

}
function submit_form(form) {
  var lb2 = document.getElementById('lbMyProducts');
  if (lb2.length < 2) {
    alert("Please add 2 or more items.");
    form.order_mail.focus();
    return false;
  }

  if (form.order_mail.value.indexOf('@') == -1) {
    alert("Please enter your email address.");
    form.order_mail.focus();
    return false;
  }
  get_orders_body();
  return true;

}

