function Calculate(TheForm, O1Price, O3Price, D1Price, D3Price, DCPrice)
{
  // Verify the Qty
  var Qty;
  Qty = parseInt(TheForm.O1.value); if(Qty >= 0) TheForm.O1.value = Qty; else TheForm.O1.value = "";
  Qty = parseInt(TheForm.O3.value); if(Qty >= 0) TheForm.O3.value = Qty; else TheForm.O3.value = "";
  Qty = parseInt(TheForm.D1.value); if(Qty >= 0) TheForm.D1.value = Qty; else TheForm.D1.value = "";
  Qty = parseInt(TheForm.D3.value); if(Qty >= 0) TheForm.D3.value = Qty; else TheForm.D3.value = "";
  Qty = parseInt(TheForm.DC.value); if(Qty >= 0) TheForm.DC.value = Qty; else TheForm.DC.value = "";
	
  // Calculate the total
  var PriceO1 = parseInt(eval(TheForm.O1.value * O1Price * 100));
  var PriceO3 = parseInt(eval(TheForm.O3.value * O3Price * 100));
  var PriceD1 = parseInt(eval(TheForm.D1.value * D1Price * 100));
  var PriceD3 = parseInt(eval(TheForm.D3.value * D3Price * 100));
  var PriceDC = parseInt(eval(TheForm.DC.value * DCPrice * 100));
	
  var Price = parseInt(eval(PriceO1 + PriceO3 + PriceD1 + PriceD3 + PriceDC));
  var RealPrice = Price;

  // Set the RealTotal
  TheForm.RealTotal.value = parseInt(eval(RealPrice / 100));
  RealPrice = parseInt(eval(RealPrice % 100));
  if(RealPrice < 10)
    TheForm.RealTotal.value += ".0" + parseInt(RealPrice);
  else
    TheForm.RealTotal.value += "." + parseInt(RealPrice);

  TheForm.TotalO1.value = "$ " + parseInt(eval(PriceO1 / 100));
  PriceO1 = parseInt(eval(PriceO1 % 100));
  if(PriceO1 < 10)
    TheForm.TotalO1.value += ".0" + parseInt(PriceO1);
  else
    TheForm.TotalO1.value += "." + parseInt(PriceO1);

  TheForm.TotalO3.value = "$ " + parseInt(eval(PriceO3 / 100));
  PriceO3 = parseInt(eval(PriceO3 % 100));
  if(PriceO3 < 10)
    TheForm.TotalO3.value += ".0" + parseInt(PriceO3);
  else
    TheForm.TotalO3.value += "." + parseInt(PriceO3);

  TheForm.TotalD1.value = "$ " + parseInt(eval(PriceD1 / 100));
  PriceD1 = parseInt(eval(PriceD1 % 100));
  if(PriceD1 < 10)
    TheForm.TotalD1.value += ".0" + parseInt(PriceD1);
  else
    TheForm.TotalD1.value += "." + parseInt(PriceD1);

  TheForm.TotalD3.value = "$ " + parseInt(eval(PriceD3 / 100));
  PriceD3 = parseInt(eval(PriceD3 % 100));
  if(PriceD3 < 10)
    TheForm.TotalD3.value += ".0" + parseInt(PriceD3);
  else
    TheForm.TotalD3value += "." + parseInt(PriceD3);

  // Set the new total of DC
    TheForm.TotalDC.value = "$ " + parseInt(eval(PriceDC / 100));
    PriceDC = parseInt(eval(PriceDC % 100));
    if(PriceDC < 10)
        TheForm.TotalDC.value += ".0" + parseInt(PriceDC);
    else
        TheForm.TotalDC.value += "." + parseInt(PriceDC);
		
  TheForm.Total.value = "$ " + parseInt(eval(Price / 100));
  Price = parseInt(eval(Price % 100));
  if(Price < 10)
    TheForm.Total.value += ".0" + parseInt(Price);
  else
    TheForm.Total.value += "." + parseInt(Price);
}

function ChangeDesc(Title,Desc)
{
  var PopupTitle = document.getElementById('PopupTitle').firstChild;
  var PopupDesc = document.getElementById('PopupDesc').firstChild;

  PopupTitle.replaceData(0,PopupTitle.nodeValue.length,Title);
  PopupDesc.replaceData(0,PopupDesc.nodeValue.length,Desc);
}

/*function SomethingToBuy(O1,O3,D1,D3)
{
  if(((O1.value == "0") || (O1.value == "")) &&
     ((O3.value == "0") || (O3.value == "")) &&
     ((D1.value == "0") || (D1.value == "")) &&
     ((D3.value == "0") || (D3.value == "")))
  {
    alert("Vous n'avez pas correctement sélectionné de produit pour fins d'achat");
    return(false);
  }

  return(true);
}*/

function SomethingToBuy(O1,O3,D1,D3,DC)
{
    if(((O1.value == "0") || (O1.value == "")) &&
       ((O3.value == "0") || (O3.value == "")) &&
       ((D1.value == "0") || (D1.value == "")) &&
       ((D3.value == "0") || (D3.value == "")) &&
       ((DC.value == "0") || (DC.value == "")))
    {
        alert("No product was properly selected for purchase");
        return(false);
    }

    return(true);
}

function CountryOk(Country)
{
  if(Country.options[Country.selectedIndex].value=="" )
  {
    alert('\nVeuillez indiquer votre pays.');
    Country.focus();
  }
  else if((Country.options[Country.selectedIndex].value == 'afghanistan') || (Country.options[Country.selectedIndex].value == 'iran') || (Country.options[Country.selectedIndex].value == 'cuba') || (Country.options[Country.selectedIndex].value == 'libya') || (Country.options[Country.selectedIndex].value == 'syria') || (Country.options[Country.selectedIndex].value == 'sudan') || (Country.options[Country.selectedIndex].value == 'vietnam') || (Country.options[Country.selectedIndex].value == 'koreanorth')  )
  {
    alert('\nVous ne pouvez télécharger de produit de cryptage de ce pays.');
    document.location.replace("./index.htm");
  }
  else
    return(true);

  return(false);
}

function Buy(TheForm)
{

  if(!SomethingToBuy(TheForm.O1,TheForm.O3,TheForm.D1,TheForm.D3,TheForm.DC))
      return

  if((!CountryOk(TheForm.Country)) || (!NameOk(TheForm.Name)) || (!EmailOk(TheForm.Email,TheForm.Confirmation)))
    return;

  var now = new Date();
  var year = now.getYear() + 1900;
  var day = now.getDay();
  var month = now.getMonth();
  var date_ = now.getDate();
  var whc = Math.random().toString();
  var ww = whc.charAt(5);
  var ww2 = whc.charAt(3);
  var uidd = (year + day + month + date_ + ww + whc + ww2);
  var Product = TheForm.O1.value + '-' + TheForm.O3.value + '-' + TheForm.D1.value + '-' + TheForm.D3.value;
  var Total = TheForm.RealTotal.value;
  var Notify = (TheForm.Notify.checked == true)?"on":"off";

  order_info = 'ThanksURL=http:%2f%2fwww.deltacrypt.com%2fphp%2fCreateAccount2.php%3Fc=Accept%5elanguage=francais%5eaccess_type=purchase%5eemail=' + TheForm.Email.value + '%5ename=' + TheForm.Name.value + '%5ecountry=' + TheForm.Country.value + '%5enotify=' + Notify + '%5eproduct='+ Product + '%5enumber=' + TheForm.ID.value + '&NoThanksURL=http:%2f%2fwww.deltacrypt.com%2fphp%2fCreateAccount2.php%3Faccess_type=purchase%5ec=Declined%5elanguage=francais';
  order_info = order_info.replace(/ /g,"*");
  //order_info = 'https://order.psigate.com/psigatestandard.asp?MerchantID=deltacrypttech&Bname='+ TheForm.Name.value + '&FullTotal=' + Total + '&Oid=' + uidd + '&Email=' + TheForm.Email.value + '&ChargeType=0&' + order_info;
  order_info = 'https://checkout.psigate.com/HTMLPost/HTMLMessenger?StoreKey=DeltacryptusdxQVrfR007639&Bname='+ TheForm.Name.value + '&FullTotal=' + Total + '&Oid=' + uidd + '&Email=' + TheForm.Email.value + '&ChargeType=0&' + order_info;
  document.location=order_info;
//TheForm.Command.value = order_info;
}

function BuyElavon(TheForm)
{                                                    //--------------------
  if(!SomethingToBuy(TheForm.O1,TheForm.O3,TheForm.D1,TheForm.D3))
    return;

  if((!CountryOk(TheForm.ssl_country)) || (!NameOk(TheForm.ssl_first_name)) || (!EmailOk(TheForm.ssl_email,TheForm.Confirmation)) || (!CreditCardNumberOk(TheForm.ssl_card_number)) || (!CreditCardExpDateOk(TheForm.ssl_exp_date)))
    return;

  var now = new Date();
  var year = now.getYear() + 1900;
  var day = now.getDay();
  var month = now.getMonth();
  var date_ = now.getDate();
  var whc = Math.random().toString();
  var ww = whc.charAt(5);
  var ww2 = whc.charAt(3);
  var uidd = (year + day + month + date_ + ww + whc + ww2);
  // Configuration de base
  var BaseParams =  'ssl_show_form=false' +
  				'&ssl_transaction_type=ccsale' +
  				'&ssl_receipt_apprvl_method=REDG' +
  				'&ssl_receipt_decl_method=REDG' +
  				'&ssl_result_format=HTML' +
			  	'&ssl_pin=AT3REQ' +
				'&ssl_user_id=website' +
				'&ssl_merchant_id=513739' +
				'&ssl_error_url=http://www.deltacrypt.com/francais/home/Message.php';

  var Product = TheForm.O1.value + '-' + TheForm.O3.value + '-' + TheForm.D1.value + '-' + TheForm.D3.value;
  var Total = TheForm.RealTotal.value.substr(2);
  var Notify = (TheForm.Notify.checked == true)?"on":"off";

  // Config with parameters
  order_info = '&ssl_receipt_decl_get_url=http://www.deltacrypt.com/php/CreateAccount2.php?language=francais'+
		   	'&ssl_card_number=' + TheForm.ssl_card_number.value +
		   	'&ssl_exp_date=' + TheForm.ssl_exp_date.value +
  			'&ssl_receipt_apprvl_get_url=http://www.deltacrypt.com/php/CreateAccount2.php?c=Accept' +
  	        	'^language=francais' +
  			'^access_type=purchase' +
  			'^email=' + TheForm.ssl_email.value +
  			'^name=' + TheForm.ssl_first_name.value +
  			'^country=' + TheForm.ssl_country.value +
  			'^notify=' + Notify +
  			'^product=' + Product;


  order_info = order_info.replace(/ /g,"*");

  // when the period of test will finish, keep just: order_info += '&ssl_test_mode=false';
    order_info = 'https://www.myvirtualmerchant.com/VirtualMerchant/process.do?' +
  	BaseParams +
  	'&ssl_first_name=' + TheForm.ssl_first_name.value +
  	'&ssl_amount=' + Total +
  	'&ssl_invoice_number=' + uidd +
  	'&ssl_email=' + TheForm.ssl_email.value + order_info;
  	//order_info += '&ssl_test_mode=true';

  document.location = order_info;
}

