﻿/* function to load plan price after radio button selected*/
function setPrice(planType, id) {
    //debugger;
    //alert(id);
    var price = $(id).attr("data_price");
    var savings = $(id).attr("data-savings");
    var planID = $(id).val();
    if (planType == Constants.Premium) {
        $("#labelPremiumPrice").html(price);
        $("#labelPremiumSavings").html(savings);
    }
    else if (planType == Constants.Vip) {
        $("#labelVipPrice").html(price);
        $("#labelVipSavings").html(savings);
    }
}
/* function to load plan price after radio button selected*/

/* Function when page gets load select the first radio button */
$(document).ready(function () {
    //debugger;
    var premiumIds = "";
    var vipIds = "";
    $("#subscribeVIPLink").click(function () {
        $('#divLoadImage').show();
        $('#divOverlay').show();
        return checkOption(Constants.Vip);
    });

    $("#subscribePremiumLink").click(function () {
        //debugger;
        $('#divLoadImage').show();
        $('#divOverlay').show();
        return checkOption(Constants.Premium);
    });

    $("input[id*='pid_']").each(function () {
        //debugger;
        $(this).click(function () {
            setPrice($(this).attr("name"), this);
        });
       
        if ($(this).attr("name") == Constants.Premium) {
            premiumIds = premiumIds + "," + $(this).attr("id");
        }

        if ($(this).attr("name") == Constants.Vip) {
            vipIds = vipIds + "," + $(this).attr("id");
        }


    });

    var premiumObject = premiumIds.split(",");
    var selectedPID = premiumObject[1];
    $("#" + selectedPID).attr('checked', true);
    setPrice($("#" + selectedPID).attr("name"), $("#" + selectedPID).attr("id"));
    var vipObject = vipIds.split(",");
    var selectedVID = vipObject[1];
    $("#" + selectedVID).attr('checked', true);
    setPrice($("#" + selectedVID).attr("name"), $("#" + selectedVID).attr("id"));

});
/* Function when page gets load select the first radio button */

/* Function to check if radio is selected or not berfore redirecting to Subscribe */

function checkOption(mode) {
    //debugger;

    // debugger;
    var Count = 0;
    var planID = 0;
    if (mode == Constants.Premium) {
        $("input[id*='pid_']").each(function () {
            if ($(this).attr("name") == Constants.Premium) {
                if (this.checked) {
                    planID = $(this).val();
                    Count++;
                }
            }
        });
    }
    else if (mode == Constants.Vip) {
        $("input[id*='pid_']").each(function () {
            if ($(this).attr("name") == Constants.Vip) {
                if (this.checked) {
                    planID = $(this).val();
                    Count++;
                }
            }
        });
    }

    if (Count == 0) {
        alert("Please select any one of the option to proceed further");
        $('#divLoadImage').hide();
        $('#divOverlay').hide();
        return false;
    }

    var price = 0;
    if (mode == Constants.Premium)
        price = $("#labelPremiumPrice").html();
    else if (mode == Constants.Vip)
        price = $("#labelVipPrice").html();


    var url = "Home/Subscribe" + "?planID=" + planID;
    //alert(url);
    window.location = url;
}
/* Function to check if radio is selected or not berfore redirecting to Subscribe */
