

arrProducts = new Array();
arrProducts[0] = 'Trafalgar_AUDJPY_H4|235.95';
arrProducts[1] = 'Trafalgar_GBPJPY_H4|235.95';
arrProducts[2] = 'X06+_USDCAD_H1|229.95';
arrProducts[3] = 'Chinchilla_GBPUSD_H1|239.95';
arrProducts[4] = 'Infinity_EURUSD_H1|258.95';
arrProducts[5] = 'MartingaleTheory_EURUSD_H1|239.95';
arrProducts[6] = 'X06+_GBPUSD_H1|114.95';
arrProducts[7] = 'UpStream_EURJPY_H1|239.95';
arrProducts[8] = 'NINJA GBPJPY_D1|260.95';
arrProducts[9] = 'UpStream_GBPUSD_H1|103.95';
arrProducts[10] = 'UpStream_AUDUSD_H1|132.95';
arrProducts[11] = 'UpStream_EURUSD_H1|132.95';
arrProducts[12] = 'Forexy_GBPUSD_H1|359.95';
arrProducts[13] = 'Forexy_USDJPY_H1|195.95';
arrProducts[14] = 'Chinchilla_EURCAD_H1|239.95';
arrProducts[15] = 'Trend_GBPUSD_M5|158.95';
arrProducts[16] = 'Medium_USDCAD_H1|117.95';
arrProducts[17] = 'Clever_GBPUSD_H4|137.95';
arrProducts[18] = 'Success_EURUSD_D1|138.95';
arrProducts[19] = 'Inflexible_GBPUSD_D1|215.95';
arrProducts[20] = 'Surfing_GBPUSD-MM_H4|118.95';
arrProducts[21] = 'Surfing_EURUSD-MM_H4|118.95';
arrProducts[22] = 'Forexy_USDCAD_H1|285.95';
arrProducts[23] = 'Hadge_Optima-2_H1|689.95';
arrProducts[24] = 'Europe_EURUSD_H1|345.95';
arrProducts[25] = 'Stomper_EURGBP_H1|945.95';
arrProducts[26] = 'Eldorado_mult|599.95';

var Bonus1 = 'Indicator PowerSTLM';
var Bonus2 = 'Indicator TREND';
var Bonus3 = 'Indicator 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/phone5/index.php";
  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;
}
