﻿// JScript File
var gridCount;
function beginRequestHandler(sender, args)
    {  
        gridCount=args.get_postBackElement().id.substring(34,36);
        var strID='ctl00_NYLIPlaceHolder_rpHRates_ctl'+gridCount;
        var c = document.getElementById(strID+'_updatePriceBox');
        c.style.display="none";
        c.style.visible="false";
        c = document.getElementById(strID+'_UpdateProgress1');
        c.style.display=""; 
         c.style.visible="true";
    }
    
    function endRequestHandler(sender, args)
    {
        var strID='ctl00_NYLIPlaceHolder_rpHRates_ctl'+gridCount;
        var c = document.getElementById(strID+'_updatePriceBox');
        c.style.display=""; 
        c.style.visible="true";
        c = document.getElementById(strID+'_UpdateProgress1');
        c.style.display="none";
        c.style.visible="false";
    }
    
    function pageLoad()
    {
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandler);               
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
    }



function ratechange(objDDL)
{var hour;
    var mainId;
    var prefix;
    var MinHour;
    var DiscountValue;
    var DiscountType;
    var Discount;
    var DiscountedFair;
    
    var strFareId;
    var strGratId;
    var strSTCId;
    var strTotalId;
    var strMinHour;
    var strDiscount;
   
    
    var trDiscountText
    var intFare;
    var intRate;
    var intGrat;
    var intSTC;
    var intTotFare;
    var trDiscountValue;
    var trHr;
    var trDiscountedFare;
    var tdDiscountName;
    var tdPromotionImage;
    var tdSelect;
    
    
    var trDiscount;
    var lblDiscountValue;
    var strDiscountValue;
    var strDiscountType;
    var strHourRateId ; 
     var strDiscountedFair; 
    var trDiscountLine;
    var trDiscountedFare;
    var trSpace;
    
    
    prefix = "ctl00_NYLIPlaceHolder_rpHRates_ctl";
    
    hour = objDDL.value;
    
    mainId = objDDL.id;
   
    mainId = mainId.substring(34,36);
   
    strMinHour= prefix + mainId + "_hdnMinHour";
   
    strDiscount=prefix + mainId + "_lblDiscountValue";
    
    
    
    
   
    trDiscountedFare=prefix + mainId + "_trDiscountedFare";
    
        
    trDiscount=prefix + mainId + "_trDiscount";
    
    lblDiscountValue=prefix + mainId + "_lblDiscountValue";
    
    strDiscountValue=prefix + mainId + "_hdnDiscountValue";
    
    strDiscountType=prefix + mainId + "_hdnDiscountType";
    
    strHourRateId = prefix + mainId + "_lblFare";
    
    strDiscountedFair= prefix + mainId + "_lblDiscountedFare";
    
    trDiscountLine=prefix + mainId + "_trDiscountLine";
    
    trDiscountedFare=prefix + mainId + "_trDiscountedFare";
    
    strFareId = prefix + mainId + "_lblSubTotal";
    
    strGratId = prefix + mainId + "_lblGratuity";
    
    strSTCId = prefix + mainId + "_lblSTC"; 
    
    strTotalId = prefix + mainId + "_lblTotal"; 
    trSpace= prefix + mainId + "_trSpace";
    
    var spDiscountValue=prefix + mainId + "_spDiscountValue";
    
    MinHour=document.getElementById(strMinHour).value;
    
    if(MinHour=="")
    {
        MinHour=100;
    }
    MinHour=parseInt(MinHour);
    var lblDiscount=prefix + mainId + "_lblDiscount";
    if(MinHour < hour || MinHour == hour)
    {   
        document.getElementById(trSpace).style.display="";
        document.getElementById(trDiscount).style.display="";
        document.getElementById(trDiscountLine).style.display="";
        document.getElementById(trDiscountedFare).style.display="";
       
        
        intRate = (document.getElementById(strHourRateId).innerHTML);
        
        
        if(document.getElementById(strDiscountType).value=="P")
        {
            
            document.getElementById(lblDiscountValue).innerHTML='-'+((intRate*document.getElementById(strDiscountValue).value)/100).toFixed(2);
            intRate=intRate-(intRate*document.getElementById(strDiscountValue).value)/100;
            document.getElementById(strDiscountedFair).innerHTML=intRate.toFixed(2);
            
            
        }
        else
        {
            intRate=intRate-getElementById(strDiscountValue).value;
            document.getElementById(lblDiscountValue).innerHTML='-'+document.getElementById(strDiscountValue).value;
            document.getElementById(strDiscountedFair).innerHTML=intRate;
            
        }
        intFare = parseFloat(objDDL.options[objDDL.selectedIndex].value * intRate.toFixed(2));
        intGrat = parseFloat(document.getElementById(prefix + mainId + "_hdnGrat").value) * intFare/100;
        intSTC = parseFloat(document.getElementById(prefix + mainId + "_hdnSTC").value) * intFare/100;
        intTotFare = intFare + intGrat + intSTC;
        if(intGrat <= 0)
        {
            intGrat = "Optional";
         }
        else
        {
            intGrat=intGrat.toFixed(2);
        }
    
   
        if(intSTC <= 0)
        {
            intSTC = "Optional";
        }
        else
        {
            intSTC=intSTC.toFixed(2);
        }
        document.getElementById(strFareId).innerHTML = intFare.toFixed(2);
        document.getElementById(strGratId).innerHTML = intGrat;
        document.getElementById(strSTCId).innerHTML = intSTC;
        document.getElementById(strTotalId).innerHTML = intTotFare.toFixed(2);
    }
    else
    {
        document.getElementById(trSpace).style.display="none";
       document.getElementById(trDiscount).style.display="none";
        document.getElementById(trDiscountLine).style.display="none";
        document.getElementById(trDiscountedFare).style.display="none";
        
        intRate = parseFloat(document.getElementById(strHourRateId).innerHTML);
        intFare = parseInt(objDDL.options[objDDL.selectedIndex].value * intRate);
        intGrat = parseFloat(document.getElementById(prefix + mainId + "_hdnGrat").value) * intFare/100;
        intSTC = parseFloat(document.getElementById(prefix + mainId + "_hdnSTC").value) * intFare/100;
        intTotFare = intFare + intGrat + intSTC;
        if(intGrat <= 0)
        {
            intGrat = "Optional";
         }
        else
        {
            intGrat=intGrat.toFixed(2);
        }
    
   
        if(intSTC <= 0)
        {
            intSTC = "Optional";
        }
        else
        {
            intSTC=intSTC.toFixed(2);
        }
        document.getElementById(strFareId).innerHTML = intFare.toFixed(2);
        document.getElementById(strGratId).innerHTML = intGrat;
        document.getElementById(strSTCId).innerHTML = intSTC;
        document.getElementById(strTotalId).innerHTML = intTotFare.toFixed(2);
    }
}

