﻿function monthly()
{
document.spec.p3.value=12;
document.spec.t3.value='M';
document.spec.item_number="Monthly Donation";
}

function quartly()
{
document.spec.p3.value=3;
document.spec.t3.value='M';
document.spec.item_name="Quartly Donation";
}

function yearly()
{
document.spec.p3.value=1;
document.spec.t3.value='Y';
document.spec.item_name ="Yearly Donation";
}

function once()
{
document.spec.p3.value=1;
document.spec.t3.value='D';
document.spec.on0="Just One Time Donation Only";
}







function CalculateMatrimonialTotal()
{

   
var child_amount= parseFloat(document.forms["frm_event"].txt_child_amount.value);


var adult_amount=parseFloat(document.forms["frm_event"].txt_adult_amount.value);
var item3_amount=parseFloat(document.forms["frm_event"].txt_amount_item3.value);
var item2_amount=parseFloat(document.forms["frm_event"].txt_amount_item2.value);


if(isNaN (item2_amount))
{
item2_amount=0;
}

var item2_qty = document.forms["frm_event"].txt_qty_item2.value;
var item3_qty = document.forms["frm_event"].txt_qty_item3.value;
var child_qty = document.forms["frm_event"].txt_child_qty.value;
var adult_qty = document.forms["frm_event"].txt_adult_qty.value;
       
   
    if(IsNumeric(child_qty))
    {
        var ch_am=document.forms["frm_event"].txt_child_calamount.value= round_decimals((child_qty*child_amount),2);
    }
    else
    {
        var ch_am=child_qty=document.forms["frm_event"].txt_child_calamount.value=0.00;
    }      
             
    if(IsNumeric(item3_qty))
    {
       var item3_am=document.forms["frm_event"].txt_total_item3.value= round_decimals((item3_qty*item3_amount),2);
    }
    else
    {
        var item3_am=document.forms["frm_event"].txt_total_item3.value=0.00;
    }

 
    if(IsNumeric(adult_qty))
    {
    var ad_am=document.forms["frm_event"].txt_adult_calamount.value= round_decimals((adult_qty*adult_amount),2);
    }
    else
    {
    var ad_am=adult_qty=document.forms["frm_event"].txt_adult_calamount.value=0.00;
    }   

    if(IsNumeric(item2_qty))
    {
       var item2_am=document.forms["frm_event"].txt_total_item2.value= round_decimals((item2_qty*item2_amount),2);
      
         var total= parseFloat(ch_am)+ parseFloat(ad_am)+parseFloat(item3_am)+parseFloat(item2_am);
            var number=(child_qty)+(" Matrimonial Event ");

            document.forms["frm_event"].txt_total.value = round_decimals(total, 2);
            document.forms["frm_event"].option_amount0.value= round_decimals(total, 2);
            document.forms["frm_event"].on0.value= number;
    }
    else
    {
        var item2_am=item2_qty=document.forms["frm_event"].txt_total_item2.value=0.00;
    }
 }
 




function CalculatAnniversaryTotal()
{

   
var child_amount= parseFloat(document.forms["frm_event"].txt_child_amount.value);


var adult_amount=parseFloat(document.forms["frm_event"].txt_adult_amount.value);
var item3_amount=parseFloat(document.forms["frm_event"].txt_amount_item3.value);
var item2_amount=parseFloat(document.forms["frm_event"].txt_amount_item2.value);


if(isNaN (item2_amount))
{
item2_amount=0;
}

var item2_qty = document.forms["frm_event"].txt_qty_item2.value;
var item3_qty = document.forms["frm_event"].txt_qty_item3.value;
var child_qty = document.forms["frm_event"].txt_child_qty.value;
var adult_qty = document.forms["frm_event"].txt_adult_qty.value;
       
   
    if(IsNumeric(child_qty))
    {
        var ch_am=document.forms["frm_event"].txt_child_calamount.value= round_decimals((child_qty*child_amount),2);
    }
    else
    {
        var ch_am=child_qty=document.forms["frm_event"].txt_child_calamount.value=0.00;
    }      
             
    if(IsNumeric(item3_qty))
    {
       var item3_am=document.forms["frm_event"].txt_total_item3.value= round_decimals((item3_qty*item3_amount),2);
    }
    else
    {
        var item3_am=document.forms["frm_event"].txt_total_item3.value=0.00;
    }

 
    if(IsNumeric(adult_qty))
    {
    var ad_am=document.forms["frm_event"].txt_adult_calamount.value= round_decimals((adult_qty*adult_amount),2);
    }
    else
    {
    var ad_am=adult_qty=document.forms["frm_event"].txt_adult_calamount.value=0.00;
    }   

    if(IsNumeric(item2_qty))
    {
       var item2_am=document.forms["frm_event"].txt_total_item2.value= round_decimals((item2_qty*item2_amount),2);
      
         var total= parseFloat(ch_am)+ parseFloat(ad_am)+parseFloat(item3_am)+parseFloat(item2_am);
            var number=(child_qty)+(" Child Ticket and ")+(adult_qty)+(" Adult Expansion Project Fundraiser Event Ticket ");

            document.forms["frm_event"].txt_total.value = round_decimals(total, 2);
            document.forms["frm_event"].option_amount0.value= round_decimals(total, 2);
            document.forms["frm_event"].on0.value= number;
    }
    else
    {
        var item2_am=item2_qty=document.forms["frm_event"].txt_total_item2.value=0.00;
    }
 }








function CalculatGolfTotal()
{

   
var child_amount= parseFloat(document.forms["frm_event"].txt_child_amount.value);


var adult_amount=parseFloat(document.forms["frm_event"].txt_adult_amount.value);
var item3_amount=parseFloat(document.forms["frm_event"].txt_amount_item3.value);
var item2_amount=parseFloat(document.forms["frm_event"].txt_amount_item2.value);


if(isNaN (item2_amount))
{
item2_amount=0;
}

var item2_qty = document.forms["frm_event"].txt_qty_item2.value;
var item3_qty = document.forms["frm_event"].txt_qty_item3.value;
var child_qty = document.forms["frm_event"].txt_child_qty.value;
var adult_qty = document.forms["frm_event"].txt_adult_qty.value;
       
   
    if(IsNumeric(child_qty))
    {
        var ch_am=document.forms["frm_event"].txt_child_calamount.value= round_decimals((child_qty*child_amount),2);
    }
    else
    {
        var ch_am=child_qty=document.forms["frm_event"].txt_child_calamount.value=0.00;
    }      
             
    if(IsNumeric(item3_qty))
    {
       var item3_am=document.forms["frm_event"].txt_total_item3.value= round_decimals((item3_qty*item3_amount),2);
    }
    else
    {
        var item3_am=document.forms["frm_event"].txt_total_item3.value=0.00;
    }

 
    if(IsNumeric(adult_qty))
    {
    var ad_am=document.forms["frm_event"].txt_adult_calamount.value= round_decimals((adult_qty*adult_amount),2);
    }
    else
    {
    var ad_am=adult_qty=document.forms["frm_event"].txt_adult_calamount.value=0.00;
    }   

    if(IsNumeric(item2_qty))
    {
       var item2_am=document.forms["frm_event"].txt_total_item2.value= round_decimals((item2_qty*item2_amount),2);
      
         var total= parseFloat(ch_am)+ parseFloat(ad_am)+parseFloat(item3_am)+parseFloat(item2_am);
            var number=(child_qty)+(" Golf Events Ticket  ");//+(adult_qty)+(" Tea Sponsor Event Ticket ");

            document.forms["frm_event"].txt_total.value = round_decimals(total, 2);
            document.forms["frm_event"].option_amount0.value= round_decimals(total, 2);
            document.forms["frm_event"].on0.value= number;
    }
    else
    {
        var item2_am=item2_qty=document.forms["frm_event"].txt_total_item2.value=0.00;
    }
 }










function Calculatezakat()
{

   




var zakat_qty = document.forms["frm_event"].txt_zakat_qty.value;
var fitra_qty = document.forms["frm_event"].txt_fitra_qty.value;
       
   
    if(IsNumeric(zakat_qty))
    {
        var zakat=document.forms["frm_event"].txt_zakat_calamount.value= round_decimals((zakat_qty),2);
    }
    else
    {
        var zakat=zakat_qty=document.forms["frm_event"].txt_zakat_calamount.value=0.00;
    }      
             
   
 
    if(IsNumeric(fitra_qty))
    {
    var fitra=document.forms["frm_event"].txt_fitra_calamount.value= round_decimals((fitra_qty),2);
    }
    else
    {
    var fitra=adult_qty=document.forms["frm_event"].txt_fitra_calamount.value=0.00;
    }   

    if(IsNumeric(fitra_qty))
    {
         var total= parseFloat(fitra)+ parseFloat(zakat);
            var number=(child_qty)+(" Brick , ")+(adult_qty)+(" Window, ")+(item3_qty)+(" Door, ")+(item2_qty)+(" Desk");

            document.forms["frm_event"].txt_total.value = round_decimals(total, 2);
            document.forms["frm_event"].option_amount0.value= round_decimals(total, 2);
            document.forms["frm_event"].on0.value= number;
    }
    else
    {
        var item2_am=item2_qty=document.forms["frm_event"].txt_total_item2.value=0.00;
    }
 }


function CalculateTotal()
{

   
var child_amount= parseFloat(document.forms["frm_event"].txt_child_amount.value);


var adult_amount=parseFloat(document.forms["frm_event"].txt_adult_amount.value);
var item3_amount=parseFloat(document.forms["frm_event"].txt_amount_item3.value);
var item2_amount=parseFloat(document.forms["frm_event"].txt_amount_item2.value);


if(isNaN (item2_amount))
{
item2_amount=0;
}

var item2_qty = document.forms["frm_event"].txt_qty_item2.value;
var item3_qty = document.forms["frm_event"].txt_qty_item3.value;
var child_qty = document.forms["frm_event"].txt_child_qty.value;
var adult_qty = document.forms["frm_event"].txt_adult_qty.value;
       
   
    if(IsNumeric(child_qty))
    {
        var ch_am=document.forms["frm_event"].txt_child_calamount.value= round_decimals((child_qty*child_amount),2);
    }
    else
    {
        var ch_am=child_qty=document.forms["frm_event"].txt_child_calamount.value=0.00;
    }      
             
    if(IsNumeric(item3_qty))
    {
       var item3_am=document.forms["frm_event"].txt_total_item3.value= round_decimals((item3_qty*item3_amount),2);
    }
    else
    {
        var item3_am=document.forms["frm_event"].txt_total_item3.value=0.00;
    }

 
    if(IsNumeric(adult_qty))
    {
    var ad_am=document.forms["frm_event"].txt_adult_calamount.value= round_decimals((adult_qty*adult_amount),2);
    }
    else
    {
    var ad_am=adult_qty=document.forms["frm_event"].txt_adult_calamount.value=0.00;
    }   

    if(IsNumeric(item2_qty))
    {
       var item2_am=document.forms["frm_event"].txt_total_item2.value= round_decimals((item2_qty*item2_amount),2);
      
         var total= parseFloat(ch_am)+ parseFloat(ad_am)+parseFloat(item3_am)+parseFloat(item2_am);
            var number=(child_qty)+(" Brick , ")+(adult_qty)+(" Window, ")+(item3_qty)+(" Door, ")+(item2_qty)+(" Desk");

            document.forms["frm_event"].txt_total.value = round_decimals(total, 2);
            document.forms["frm_event"].option_amount0.value= round_decimals(total, 2);
            document.forms["frm_event"].on0.value= number;
    }
    else
    {
        var item2_am=item2_qty=document.forms["frm_event"].txt_total_item2.value=0.00;
    }
 }
 
 
 
 
 
 
function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
   
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
       
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
       
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
   
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
   
    if (pad_total > 0) {
       
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++)
            value_string += "0"
        }
    return value_string
}



function IsNumeric(sText)

{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;
  
   }

