//function Calculate(TheForm, O1Price, O3Price, D1Price, D3Price)
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));
    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);
    
    // Set the new total of O1
    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);
    
    // Set the new total of O3
    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);
    
    // Set the new total of D1
    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);
      
    // Set the new total of D3
    TheForm.TotalD3.value = "$ " + parseInt(eval(PriceD3 / 100));
    PriceD3 = parseInt(eval(PriceD3 % 100));
    if(PriceD3 < 10)
        TheForm.TotalD3.value += ".0" + parseInt(PriceD3);
    else
        TheForm.TotalD3.value += "." + 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);

    // Set the Total
    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("No product was properly selected for purchase");
        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 BuyElavon(TheForm)
{
    //--------------------
 /*   if(!SomethingToBuy(TheForm.O1,TheForm.O3,TheForm.D1,TheForm.D3))
        return;*/

    if(!SomethingToBuy(TheForm.O1,TheForm.O3,TheForm.D1,TheForm.D3,TheForm.DC))
        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/english/home/Message.php';
  
    var Product = TheForm.O1.value + '-' + TheForm.O3.value + '-' + TheForm.D1.value + '-' + TheForm.D3.value;
//    var Product = TheForm.O1.value + '-' + TheForm.O3.value + '-' + TheForm.D1.value + '-' + TheForm.D3.value + '-' + TheForm.DCs.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=english'+
        '&ssl_card_number=' + TheForm.ssl_card_number.value +
   			'&ssl_cvv2cvc2=' + TheForm.ssl_cvv2cvc2.value +
  			'&ssl_cvv2cvc2_indicator=1' +
  		  '&ssl_exp_date=' + TheForm.ssl_exp_date.value +
    		'&ssl_receipt_apprvl_get_url=http://www.deltacrypt.com/php/CreateAccount2.php?c=Accept' +
    	  '^language=english' +
    		'^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;
}

function BuyElavonOrder(TheForm)
{                                                    
    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/english/home/Message.php';
  
    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=english'+
  		   	'&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/thanks.php' ;
  
    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_cvv2cvc2=' + TheForm.ssl_cvv2cvc2.value +
  		'&ssl_cvv2cvc2_indicator=1' +
    	'&ssl_amount=' + TheForm.ssl_amount.value +
    	'&ssl_invoice_number=' + TheForm.ssl_invoice_number.value +
    	'&ssl_company=' + TheForm.ssl_company.value +
    	'&ssl_email=' + TheForm.ssl_email.value + order_info;
    	//order_info += '&ssl_test_mode=true';
  
    document.location = order_info;
}

function CountryOk(Country)
{
    if(Country.options[Country.selectedIndex].value=="")
    {
        alert('\nPlease select your country.');
        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('\nYou may not download our encryption product from this Country');
        document.location.replace("./index.htm");
    }
    else
        return(true);
  
    return(false);
}

