

/*** cnvyr.js.gz ***/
var singleTicket = false;
$('div.locSearchContainer').hide();
$('.event_tnc').click(function (e) {
    e.preventDefault();
    $('#event_tnc').modal();});
resetValues();
function resetValues() {
    HideDiscountCodePopup();
    $('#promo_code').val('');
    $("#accrdn_1 .selectpicker,.selectNo").find('option:first-child').prop('selected', true);}
function addFixedHeader() {
    if ($(window).width() <= 768) {
        return false;
    }
    var top = $(document).scrollTop();

    function addClass() {
        $('#event_div').addClass('fixto-fixed');
        $('.event_toggle').css('top', '200px');
    }
    function removeClass() {
        $('#event_div').removeClass('fixto-fixed');
        $('.event_toggle').css('top', '0');
    }
    top = 390 ? addClass() : removeClass();}
if (window.matchMedia('(min-width: 1060px)').matches) {
    //$('#event_div').fixTo('body', {top: 80, zIndex: 99});
    //$('#event_div').fixTo('destroy');
    $('#event_div').stick_in_parent({offset_top: 80});}
$("#datepick").datepicker();
$('html, body').css({
    'overflow': 'auto',
    'height': 'auto'
});
$("#earlyEntry .btn").click(function () {
    var time = 500;
    if ($('.viewEarlyEntryTicket').is(":visible")) {
        $('.viewEarlyEntryTicket').slideUp(time);
        $(this).text('View More');
    } else {
        $('.viewEarlyEntryTicket').slideDown(time);
        $(this).text('View Less');
    }
    return false;
});
$(".cont_main .ticket-desc-loadmore a").click(function(){
    var tckDesc = $(this).parents(".eventCatName").find(".tckdesc");
    tckDesc.find("span").toggle();
    tckDesc.find("i").toggle();
    (tckDesc.find("span").is(":visible")) ? $(this).text('Show Less') : $(this).text('Show More') ;
});
$(".widget-namesection .ticket-desc-loadmore a").click(function(){
    var tckDesc = $(this).parents(".widget-namesection").find(".widget-desc");
    tckDesc.find("span").toggle();
    tckDesc.find("i").toggle();
    (tckDesc.find("span").is(":visible")) ? $(this).text('Show Less') : $(this).text('Show More') ;
});
$("#vipTicket .btn").click(function () {
    var time = 500;
    if ($('.viewVipTicket').is(":visible")) {
        $('.viewVipTicket').slideUp(time);
        $(this).text('View More');
    } else {
        $('.viewVipTicket').slideDown(time);
        $(this).text('View Less');
    }
    return false;
});
$("input[name=isCourier]").on("change",function(){
    calculate();
});
function calculate() {
    var limitSingleTicketType = $('#limitSingleTicketType').val();

    var ticketObj = {};
    var donationObj = {};
    var eventId = $('#eventId').val();
    var referralCode = $('#referralCode').val();
    var pcode = $("#pcode").val();
    var discountCode = $.trim($('#promo_code').val());
    var promoterCode = $("#promoterCode").val();
    var acode = $("#acode").val();
    var widgettheme = $("#widgettheme").val();
    var ticketWidget = $("#ticketWidget").val();
    var isCourier = $("input[name=isCourier]:checked").val();
    var totalSelectedQty = 0;
    if (limitSingleTicketType != 1) {
        var ticketCurrency = '';
        $('.ticket_selector').each(function () {
            if (ticketCurrency != '') {
                return false;
            } else if (((this.type === 'text' && $(this).val() != '') || parseInt($(this).val()))) {
                ticketCurrency = $(this).attr('currencyCode');
            }

        });
        $('.ticket_selector').each(function () {
            if ($(this).attr('currencyCode') != '' && ticketCurrency != '' && $(this).attr('currencyCode') != ticketCurrency) {
                $(this).prop('disabled', true);
            } else {
                $(this).prop('disabled', false);
            }
        });
    }

    $('.ticket_selector').each(function () {
        var ticketIdStr = $(this).attr('id');
        if (this.type === 'text') {
            var amount = ($(this).val() != '') ? $(this).val() : 0;
            if (parseInt(amount) > 0) {
                totalSelectedQty += 1;
                donationObj[ticketIdStr] = amount;
            }
        } else {
            var qty = $(this).val();
            ticketObj[ticketIdStr] = qty;
            totalSelectedQty += parseInt(qty);
        }
    });

    if (totalSelectedQty === 0) {
        alert("Please select ticket quantity");
        $('#promo_code').val('');
        $('#apply_discount_btn').show();
        $('#calucationsDiv').hide();
        return false;
    }
    var inputData = {eventId: eventId};
    if (Object.keys(ticketObj).length) {
        inputData.ticketArray = ticketObj;
    }
    if (Object.keys(donationObj).length) {
        inputData.donateTicketArray = donationObj;
    }
    if ((referralCode) !== '') {
        inputData.referralCode = referralCode;
    }
    if ((pcode) !== '') {
        inputData.pcode = pcode;
    }
    if ((acode) !== '') {
        inputData.acode = acode;
    }
    if ((promoterCode) !== '') {
        inputData.promoterCode = promoterCode;
    }
    if ((discountCode) !== '') {
        inputData.discountCode = discountCode;
    }
    if ((widgettheme) !== '') {
        inputData.widgetTheme = widgettheme;
    }
    if ((ticketWidget) !== '') {
        inputData.ticketWidget = ticketWidget;
    }
    if (typeof (isCourier) !== 'undefined' && isCourier != '') {
        inputData.isCourier = isCourier;
    }


    inputData.isInterNetHandling=1;
    var pageUrl = api_getTicketCalculation;
    var method = 'POST';
    //var call = 'reports';
    var dataFormat = 'JSON';
    function callbackSuccess(calculationObj) {
        if($("#widgettheme").length == 0) {
            var theme=0;
        }else{
            var theme=$('#widgettheme').val();
        }

        if(theme==1){
            var data = calculationObj.response.calculationDetails;
            var otherCurrencyTickets = data.otherCurrencyTickets;

            $(otherCurrencyTickets).each(function (index, value) {
                $('#' + value).attr('disabled', 'disabled');
            });

            if(typeof (calculationObj.response.messages.ticketGrouping) != 'undefined' && calculationObj.response.messages.ticketGrouping.length > 0  ){
                var ticketGroups = calculationObj.response.messages.ticketGrouping;
                for (var i = ticketGroups.length - 1; i >= 0; i--) {
                    $('[data-id="'+ticketGroups[i]+'"]').each(function(){
                        $(this).find(".ticket_selector").each(function(){
                            $(this).val()==0 ? ($(this).addClass('opacity5').attr('disabled', 'disabled'), $(this).prev('.ticketselectioncheckbox').attr('disabled', 'disabled')) : 0;
                        });
                    });
                }
            }


            var currencyCodeStr = data.currencyCode;
            if (data.totalPurchaseAmount > 0) {
                $('.currencyCodeStr').html('(' + currencyCodeStr + ')');
            } else {
                $('.currencyCodeStr').html('');
            }

            $('#discountTbl').hide();
            $('#mediscountTbl').hide();
            $('#bulkDiscountTbl').hide();
            $('#referralDiscountTbl').hide();
            $('#extraChargeTbl').hide();
            if (discountCode != '' && data.totalCodeDiscount == 0 && data.totalCodeCashBack == 0) {
                if(data.disableGlobalOnBulk){
                    alert("You cannot avail two offers at once!");
                } else {
                    alert("Discount code you entered is not applicable to this Ticket Or Exceeded Limit");
                }
				if(data.isCorporateUser){
                    clearDiscount();
                } else {
                	$('#promo_code').removeAttr('readonly');
                	$('#promo_code').focus();
                	$('.calucationsDiv').hide();
                	$('#apply_discount_btn').show();
                }
                //return false;
            }
            if (data.totalCodeDiscount > 0 || data.totalCodeCashBack > 0) {
                if(data.totalCodeDiscount > 0){
                    if(!data.isMeraeventsDiscount){
                        $('#discount_amount').html(data.totalCodeDiscount);
                        $('#discountTbl').show();
                    } else {
                        $('#mediscount_amount').html(data.totalCodeDiscount);
                        $('#mediscountTbl').show();
                    }
                }
                if(data.totalCodeCashBack > 0){
                    $('#cashback_amount').html(data.totalCodeCashBack);
                    $('#cashbackTbl').show();
                }
            } else {
                $('#promo_code').val('');
                $('#promo_code').focus();
                $('#apply_discount_btn').show();
            }
            if (data.totalBulkDiscount > 0) {
                $('#bulkDiscount_amount').html('<span>:</span> '+currencyCodeStr+' '+data.totalBulkDiscount);
                $('#bulkDiscountTbl').show();
            }
            if (data.totalReferralDiscount > 0) {
                $('#referralDiscount_amount').html('<span>:</span> '+currencyCodeStr+' '+data.totalReferralDiscount);
                $('#referralDiscountTbl').show();
            }
            if (data.totalInternetHandlingAmount > 0) {
                $('#totalInternetHandlingAmount').html('<span>:</span> '+currencyCodeStr+' '+data.totalInternetHandlingAmountWithoutGst);
                $('#totalInternetHandlingTbl').show();
            }else{
                $('#totalInternetHandlingAmount').html('<span>:</span>'+0);
            }
            if (typeof data.courierFee != 'undefined' && data.courierFee > 0) {
                $('#courierFeeTbl .courierFee').html(data.courierFeeLabel);
                $('#courierFee_amount').html('<span>:</span> '+currencyCodeStr+' '+data.courierFee);
                $('#courierFeeTbl').show();
            }else{
                $('#courierFeeTbl .courierFee').html(data.courierFeeLabel);
                $('#courierFee_amount').html('<span>:</span>'+0);
                $('#courierFeeTbl').hide();
            }
            if (data.totalInternetHandlingOnlyGstAmount > 0) {
                $('#totalInternetHandlingGstAmount').html('<span>:</span> '+currencyCodeStr+' '+data.totalInternetHandlingOnlyGstAmount);
                $('#totalInternetHandlingGst').show();
            }else{
                $('#totalInternetHandlingGstAmount').html('<span>:</span>'+0);
                $('#totalInternetHandlingGst').hide();
            }
            var tax = '';
            $.each(data.totalTaxDetails, function (key, value) {
                tax += '<div class="col-lg-12 col-md-12 col-sm-12 widget-amountcontainer">';
                tax += '<p class="col-lg-6 col-md-6 col-sm-6 col-xs-6 widget-tleft">' + value.label + '</p>';
                tax += '<p class="col-lg-6 col-md-6 col-sm-6 col-xs-6 widget-tright"><span>:</span>';
                if (value.taxAmount > 0) {
                    tax += currencyCodeStr + ' ' + value.taxAmount + '</p>';
                } else {
                    tax += value.taxAmount + '</p>';
                }

                tax +='</div>';
            });
            $('#taxesDiv').html(tax);

            var extraTxt = '';
            var totalextrachargeamount=0;
            if (data.extraCharge.length > 0) {
                $.each(data.extraCharge, function(extraKey, extraVal){

                    if (extraVal.totalAmount > 0) {
                        extraTxt += '<div class="col-lg-12 col-md-12 col-sm-12 widget-amountcontainer">'+
                            '<p class="col-lg-6 col-md-6 col-sm-6 col-xs-6 widget-tleft">'+extraVal.label+'</p>'+
                            '<p class="col-lg-6 col-md-6 col-sm-6 col-xs-6 widget-tright"><span>:</span>'+currencyCodeStr+' '+extraVal.totalAmountWithoutGst+'</p>'+
                            '</div>';
                        totalextrachargeamount=parseFloat(totalextrachargeamount)+parseFloat(extraVal.totalAmount);
                    }
                });
                $('#extraChargeTbl').html(extraTxt);
                $('#extraChargeTbl').show();
            }
            if(typeof(data.totalInternetHandlingAmount) != "undefined" && data.totalInternetHandlingAmount !== null) {
                if(data.totalInternetHandlingAmount>=0){
                    totalextrachargeamount=parseFloat(totalextrachargeamount)+parseFloat(data.totalInternetHandlingAmount);
                    totalextrachargeamount=totalextrachargeamount.toFixed(2);
                }
            }
            /*if (data.extraCharge.totalAmount > 0) {
             $('#extrachargeLabel').html(data.extraCharge.label + '(' + currencyCodeStr + ')')
             $('#extracharge_amount').html(data.extraCharge.totalAmount);
             $('#extraChargeTbl').show();
             }*/
            if (currencyCodeStr == null) {
                currencyCodeStr='';
            }
            $('#roundOfValue').html('<span>:</span> '+currencyCodeStr+' '+data.roundofvalue);
            $('#total_amount').html('<span>:</span> '+currencyCodeStr+' '+data.totalTicketAmount);
            $('#purchase_total').html('<b><span>:</span> '+currencyCodeStr+' '+data.totalPurchaseAmount+'</b>');
            $('.calucationsDiv').show();
            var checktotalextrachargeamount=totalextrachargeamount;
            totalextrachargeamount='' + currencyCodeStr + ' '+totalextrachargeamount;
            $('#internethandlingtotalamount').html(totalextrachargeamount);
            if (data.totalPurchaseAmount > 0 && checktotalextrachargeamount > 0) {
                $('#handlingfeesbox').show();
                if (data.totalInternetHandlingOnlyGstAmount > 0) {
                    $('#totalInternetHandlingGst').show();
                }else{
                    $('#totalInternetHandlingGst').hide();
                }
                if (data.totalInternetHandlingAmount > 0) {
                    $('#totalInternetHandlingTbl').show();
                }else{
                    $('#totalInternetHandlingTbl').hide();
                }

            }else{
                $('#handlingfeesbox').hide();
                $('#totalInternetHandlingGst').hide();
                $('#totalInternetHandlingTbl').hide();
            }
            $("#dvLoading").hide();
        }else{
            var data = calculationObj.response.calculationDetails;
            var otherCurrencyTickets = data.otherCurrencyTickets;

            $(otherCurrencyTickets).each(function (index, value) {
                $('#' + value).attr('disabled', 'disabled');
            });

            if(typeof (calculationObj.response.messages.ticketGrouping) != 'undefined' && calculationObj.response.messages.ticketGrouping.length > 0  ){
                var ticketGroups = calculationObj.response.messages.ticketGrouping;
                for (var i = ticketGroups.length - 1; i >= 0; i--) {
                    $('[data-id="'+ticketGroups[i]+'"]').each(function(){
                        $(this).find(".ticket_selector").each(function(){
                            $(this).val()==0 ? ($(this).addClass('opacity5').attr('disabled', 'disabled'), $(this).prev('.ticketselectioncheckbox').attr('disabled', 'disabled')) : 0;
                        });
                    });
                }
            }

            var currencyCodeStr = data.currencyCode;
            if (data.totalPurchaseAmount > 0) {
                $('.currencyCodeStr').html('(' + currencyCodeStr + ')');
            } else {
                $('.currencyCodeStr').html('');
            }

            $('#discountTbl').hide();
            $('#mediscountTbl').hide();
            $('#cashbackTbl').hide();
            $('#bulkDiscountTbl').hide();
            $('#referralDiscountTbl').hide();
            $('#extraChargeTbl').hide();
            $('#courierFeeTbl').hide();
            if (discountCode != '' && data.totalCodeDiscount == 0 && data.totalCodeCashBack == 0) {
                if(data.disableGlobalOnBulk){
                    alert("You cannot avail two offers at once!");
                } else {
                    alert("Discount code you entered is not applicable to this Ticket Or Exceeded Limit");
                }
                if(data.isCorporateUser){
                    clearDiscount();
                } else {
                    $('#promo_code').removeAttr('readonly');
                    $('#promo_code').focus();
                    $('#calucationsDiv').hide();
                    $('#apply_discount_btn').show();
                }
            }
            if (data.totalCodeDiscount > 0 || data.totalCodeCashBack > 0) {
                if(data.totalCodeDiscount > 0){
                    if(!data.isMeraeventsDiscount){
                        $('#discount_amount').html(data.totalCodeDiscount);
                        $('#discountTbl').show();
                    } else {
                        $('#mediscount_amount').html(data.totalCodeDiscount);
                        $('#mediscountTbl').show();
                    }
                }
                if(data.totalCodeCashBack > 0){
                    $('#cashback_amount').html(data.totalCodeCashBack);
                    $('#cashbackTbl').show();
                }
            } else {
                $('#promo_code').val('');
                $('#promo_code').focus();
                $('#apply_discount_btn').show();
            }
            if (data.totalBulkDiscount > 0) {
                $('#bulkDiscount_amount').html(data.totalBulkDiscount);
                $('#bulkDiscountTbl').show();
            }
            if (data.totalReferralDiscount > 0) {
                $('#referralDiscount_amount').html(data.totalReferralDiscount);
                $('#referralDiscountTbl').show();
            }
            if (typeof data.courierFee != 'undefined' && data.courierFee > 0) {
                $('#courierFeeTbl .courierFee').html(data.courierFeeLabel);
                $('#courierFee_amount').html(data.courierFee);
                $('#courierFeeTbl').show();
            }
            if (data.totalInternetHandlingAmount > 0) {
                $('#totalInternetHandlingAmount').html(data.totalInternetHandlingAmountWithoutGst);
                $('#totalInternetHandlingTbl').show();
            }else{
                $('#totalInternetHandlingAmount').html(0);
            }
            if (data.totalInternetHandlingOnlyGstAmount > 0) {
                $('#totalInternetHandlingGstAmount').html(data.totalInternetHandlingOnlyGstAmount);
                $('#totalInternetHandlingGst').show();
            }else{
                $('#totalInternetHandlingGstAmount').html(0);
                $('#totalInternetHandlingGst').hide();
            }
            var tax = '';
            var taxLabel = [];
            $.each(data.totalTaxDetails, function (key, value) {
                if ( taxLabel.indexOf(value.label) == -1){
                    taxLabel.push(value.label);
                }

            });
            if(taxLabel.length == 1){
                if(data.totalTaxAmount > 0){
                    tax += '<table width="100%" class="table_cont table_cont_1">' +
                        '<tbody>' +
                        '<tr>' +
                        '<td class="table_left_cont">';
                    tax += taxLabel[0] + '(' + currencyCodeStr + ')</td>';

                    tax += '<td class="table_ryt_cont">' + data.totalTaxAmount + '</td>' +
                        '</tr>' +
                        '</tbody>' +
                        '</table>';
                }
            }else{

                var clickId = [];
                var finaljson = [];
                var originaljson = data.totalTaxDetails;
                $.each(originaljson, function(i, item) {
                    if(clickId.indexOf(originaljson[i].label) === -1){
                        finaljson.push(item);
                        clickId.push(originaljson[i].label);
                    }else{
                        $.each(finaljson, function(j, item1) {
                            if(originaljson[i].label === finaljson[j].label){
                                finalValue = parseFloat(finaljson[j].taxAmount)+parseFloat(originaljson[i].taxAmount);
                                finaljson[j].taxAmount = +finalValue.toFixed(2);
                            }
                        });
                    }
                });

                data.totalTaxDetails = finaljson;

                $.each(data.totalTaxDetails, function (key, value) {
                    tax += '<table width="100%" class="table_cont table_cont_1">' +
                        '<tbody>' +
                        '<tr>' +
                        '<td class="table_left_cont">';
                    if (data.totalPurchaseAmount > 0) {
                        tax += value.label + '(' + currencyCodeStr + ')</td>';
                    } else {
                        tax += value.label + '</td>';
                    }

                    tax += '<td class="table_ryt_cont">' + value.taxAmount + '</td>' +
                        '</tr>' +
                        '</tbody>' +
                        '</table>';
                });
            }

            $('#taxesDiv').html(tax);

            var extraTxt = '';
            var totalextrachargeamount=0;
            if (data.extraCharge.length > 0) {
                $.each(data.extraCharge, function(extraKey, extraVal){

                    if (extraVal.totalAmount > 0) {
                        extraTxt += '<tbody>'+
                            '<tr>'+
                            '<td id="extrachargeLabel" class="table_left_cont">'+extraVal.label+'('+extraVal.currencyCode+')</td>'+
                            '<td class="table_ryt_cont" id="extracharge_amount">'+extraVal.totalAmountWithoutGst+'</td>'+
                            '</tr>'+
                            '</tbody>';
                        totalextrachargeamount=parseFloat(totalextrachargeamount)+parseFloat(extraVal.totalAmount);
                    }
                });
                $('#extraChargeTbl').html(extraTxt);
                $('#extraChargeTbl').show();
            }
            if(typeof(data.totalInternetHandlingAmount) != "undefined" && data.totalInternetHandlingAmount !== null) {
                if(data.totalInternetHandlingAmount>=0){
                    totalextrachargeamount=parseFloat(totalextrachargeamount)+parseFloat(data.totalInternetHandlingAmount);
                    totalextrachargeamount=totalextrachargeamount.toFixed(2);
                }
            }
            $('#internethandlingtotalamount').html(totalextrachargeamount);

            if (data.totalPurchaseAmount > 0 && totalextrachargeamount > 0) {
                $('#handlingfeesbox').show();
                if (data.totalInternetHandlingOnlyGstAmount > 0) {
                    $('#totalInternetHandlingGst').show();
                }else{
                    $('#totalInternetHandlingGst').hide();
                }
                if (data.totalInternetHandlingAmount > 0) {
                    $('#totalInternetHandlingTbl').show();
                }else{
                    $('#totalInternetHandlingTbl').hide();
                }

            }else{
                $('#handlingfeesbox').hide();
                $('#totalInternetHandlingGst').hide();
                $('#totalInternetHandlingTbl').hide();
            }
            /*if (data.extraCharge.totalAmount > 0) {
             $('#extrachargeLabel').html(data.extraCharge.label + '(' + currencyCodeStr + ')')
             $('#extracharge_amount').html(data.extraCharge.totalAmount);
             $('#extraChargeTbl').show();
             }*/
            $('#roundOfValue').html(data.roundofvalue);
            $('#total_amount').html(data.totalTicketAmount);
            $('#purchase_total').html(data.totalPurchaseAmount);
            $('#calucationsDiv').show();
            $("#dvLoading").hide();
        }

    }
    function callbackFailure(result) {
        var data1 = result.responseJSON.response;
        if(typeof data1.calculationDetails!='undefined' && typeof data1.calculationDetails.otherCurrencyTickets!='undefined'){
            var otherCurrencyTickets = data1.calculationDetails.otherCurrencyTickets;

            $(otherCurrencyTickets).each(function (index, value) {
                $('#' + value).attr('disabled', 'disabled');
            });
        }
        alert(data1.messages);
        $("#dvLoading").hide();
        if (typeof data1.calculationDetails != 'undefined') {
            var data = data1.calculationDetails;
            var currencyCodeStr = data.currencyCode;
            if (currencyCodeStr != '') {
                $('.currencyCodeStr').html('(' + currencyCodeStr + ')');
            } else {
                $('.currencyCodeStr').html('');
            }
            $('#mediscountTbl').hide();
            $('#discountTbl').hide();
            $('#cashbackTbl').hide();
            $('#bulkDiscountTbl').hide();
            $('#referralDiscountTbl').hide();
            if (data.totalCodeDiscount > 0) {
                $('#discount_amount').html(data.totalCodeDiscount);
                $('#discountTbl').show();
            } else {
                $('#promo_code').val('');
                $('#apply_discount_btn').show();
                $('#promo_code').focus();
            }
            if (data.totalBulkDiscount > 0) {
                $('#bulkDiscount_amount').html(data.totalBulkDiscount);
                $('#bulkDiscountTbl').show();
            }
            if (data.totalReferralDiscount > 0) {
                $('#referralDiscount_amount').html(data.totalReferralDiscount);
                $('#referralDiscountTbl').show();
            }
            var tax = '';
            $.each(data.totalTaxDetails, function (key, value) {
                tax += '<table width="100%" class="table_cont table_cont_1">' +
                    '<tbody>' +
                    '<tr>' +
                    '<td class="table_left_cont">';
                if (value.taxAmount > 0) {
                    tax += value.label + '(' + currencyCodeStr + ')</td>';
                } else {
                    tax += value.label + '</td>';
                }

                tax += '<td class="table_ryt_cont">' + value.taxAmount + '</td>' +
                    '</tr>' +
                    '</tbody>' +
                    '</table>';
            });
            $('#taxesDiv').html(tax);
            if (data.extraCharge.totalAmount > 0) {
                $('#extrachargeLabel').html(data.extraCharge.label)
                $('#extracharge_amount').html(data.extraCharge.totalAmount);
                $('#extraChargeTbl').show();
            }
            $('#roundOfValue').html(data.roundofvalue);
            $('#total_amount').html(data.totalTicketAmount);
            $('#purchase_total').html(data.totalPurchaseAmount);
        } else {
            $("#dvLoading").show();
            $('#calucationsDiv').hide();
            location.reload(true);
        }
        $('#promo_code').removeAttr('readonly');
    }
    getPageResponse(pageUrl, method, inputData, dataFormat, callbackSuccess, callbackFailure);
}
$(".ticket_selector").on('change', function () {
    $("#dvLoading").show();
    if (this.type == "text" && isNaN(this.value)) {
        alert("Please enter valid amount");
        $('#' + this.id).val('');
        $('#calucationsDiv').hide();
        $("#dvLoading").hide();
        $('.ticket_selector').prop('disabled', false);
        return false;
    } else if (this.type == "text" && parseInt(this.value) <= 0) {
        alert("Please enter amount greater than zero");
        $('#' + this.id).val('');
        $('#calucationsDiv').hide();
        $("#dvLoading").hide();
        $('.ticket_selector').prop('disabled', false);
        return false;
    } else {
        var limitSingleTicketType = $('#limitSingleTicketType').val();

        if (limitSingleTicketType > 0) {

            if ($(this).val() == '0' || $(this).val() == '') {
                $('.ticket_selector').prop('disabled', false);
            } else {
                $('.ticket_selector').prop('disabled', 'disabled');
                //$("input.ticket_selector").val('0');
                $(this).prop('disabled', false);
            }
        } else {
            $('.ticket_selector').prop('disabled', false);
        }
        var totalSelectedQty = 0
        $('.ticket_selector').each(function () {
            // $(this).removeAttr('disabled');
            $(this).removeClass('opacity5').attr('disabled', false);
            $(this).prev('.ticketselectioncheckbox').attr('disabled', false);
            if (this.type === 'text') {
                var amount = ($(this).val() != '') ? $(this).val() : 0;
                if (parseInt(amount) > 0) {
                    totalSelectedQty += 1;
                }
            } else {
                var qty = $(this).val();
                totalSelectedQty += parseInt(qty);
            }
        });

        if (totalSelectedQty == 0) {
            $('#calucationsDiv').hide();
            if($("#widgettheme").length == 0) {
                var theme=0;
            }else{
                var theme=$('#widgettheme').val();
            }
            if(theme==1){
                $('.calucationsDiv').hide();
            }
            HideDiscountCodePopup();
            $('#apply_discount_btn').show();
            $('#total_amount, #purchase_total, .table_ryt_cont').text(0);
            $('#promo_code').val('');
            $('#promo_code').removeAttr('readonly');
            $("#dvLoading").hide();
        } else {
            $('.ticket_selector').blur();
            calculate(this);

        }
    }
});
$("#datepicker").datepicker();
$("#datepicker2").datepicker();
$("#viewMoreEvents").click(function () {
    $(".eventThumbs:first").clone().insertAfter(".eventThumbs:last").hide();
    $(".eventThumbs:last").fadeIn(500);
    return false;
});
$("#viewMoreCat").click(function () {
    if ($(this).attr("aria-expanded") === "false")
        $(this).text("View Less");
    else
        $(this).text("View More");
});
$("#settingsBtn").click(function () {
    if ($("#locationContainer").is(':hidden')) {
        $("#locationContainer").show();
        $("#locationContainer").css('position', 'fixed');
        $("#locationContainer").css('background', '#f5f6f7');
        $(window).off('scroll', onwindowscroll)

    } else {
        $("#locationContainer").hide();
        $("#locationContainer").css('position', 'relative');
        $(window).on('scroll', onwindowscroll)
    }

});
function onwindowscroll() {
    var top = $(document).scrollTop();
    if (top >= 180) {
        $("#locationContainer").hide();
        $("#settingsBtn").show();
    } else {
        $("#settingsBtn").hide();
        $("#locationContainer").show();
    }
}
$(window).on('scroll', onwindowscroll);
$("#scrollnavtoggle").on("click", function () {
    $(this).toggleClass("active");
});
$(window).on('scroll', onwindowscroll);
$(".showMoreTickets").click(function () {
    var idArr = this.id.split('_');
    var tktId = idArr[1];
    if (!($("#show_" + tktId).is(":visible"))) {
        $(this).text('View Less');
        $("#show_" + tktId).show().slideDown();
    } else {
        $("#show_" + tktId).hide();
        $(this).text("View More");

    }
    return false;

});
$("#event_about .btn").click(function () {
    $('#viewMoreDetailss1').toggleClass("aboutdivmore");
    if ($(this).text() == 'View More')
    {
        $(this).text('View Less');
        $('#viewMoreDetailss1').slideDown(time);

    } else if ($(this).text() == 'View Less')
    {
        $(this).text('View More');
        $('#viewMoreDetailss1').slideUp(time);
    }
});
function ShowDiscountCodePopup() {

    var myElem1 = document.getElementById('showdis');
    if (myElem1 === null) {

    } else {
        myElem1.style.display = "none";
    }

    var myElem2 = document.getElementById('hidedis');
    if (myElem2 === null) {

    } else {
        myElem2.style.display = "";
        $('#promo_code').focus();
    }
}
function HideDiscountCodePopup() {

    var myElem1 = document.getElementById('showdis');
    if (myElem1 === null) {

    } else {
        myElem1.style.display = "";
    }

    var myElem2 = document.getElementById('hidedis');
    if (myElem2 === null) {

    } else {
        myElem2.style.display = "none";
    }
}
function clearDiscount() {
    $('#promo_code').val('');
    $('#promo_code').focus();
    $('#promo_code').removeAttr('readonly');
    $('#apply_discount_btn').show();
    $("#dvLoading").show();
    calculate();
}
function applyDiscount() {

    $('#promo_code').removeAttr('readonly');
    if ($.trim($('#promo_code').val()) == '') {
        alert("Please enter valid discount code");
        $('#promo_code').focus();
    } else {
        $('#apply_discount_btn').hide();
        $('#promo_code').attr('readonly', true);
        $("#dvLoading").show();
        calculate();
    }
}
//});

function showhide() {
    var divSignUp = document.getElementById("signUpContainer");
    var divLogin = document.getElementById("loginContainer");
    if (divSignUp.style.display == "none") {
        divSignUp.style.display = "block";
        divLogin.style.display = "none";
    }
    else {
        divSignUp.style.display = "none";
        divLogin.style.display = "block";
    }
}
// adding to order log
function booknow() {
    $("#dvLoading").show();
    var ticketObj = {};
    var donationObj = {};
    var eventId = $('#eventId').val();
    var totalamount = $('#total_amount').html();
    var discountCode = $.trim($('#promo_code').val());
    var referralCode = $('#referralCode').val();
    var pcode = $('#pcode').val();
    var pageType = $('#pageType').val();
    var ticketWidget = $('#ticketWidget').val();
    var addonCount = 0, nonaddonCount = 0;
    var addonArray = [];
    var isCourier = $("input[name=isCourier]:checked").val();
    $('.ticket_selector').each(function () {
        var ticketIdStr = $(this).attr('id');
        if (this.type === 'text') {
            var amount = ($(this).val() != '') ? $(this).val() : 0;
            donationObj[ticketIdStr] = amount;
        } else {
            var qty = $(this).val();
            ticketObj[ticketIdStr] = qty;
        }
        if ($(this).hasClass("addon")) {
            addonCount += isNaN($(this).val()) ? 0 : eval($(this).val());
            addonArray.push(ticketIdStr);
        } else {
            nonaddonCount += (isNaN($(this).val()) || $(this).val() == 'undefined' || $(this).val() == '') ? 0 : eval($(this).val());
        }
    });

    if (addonCount > 0 && nonaddonCount == 0)
    {
        $("#dvLoading").hide();
        alert("Only Add-on tickets are not allowed, Please select atleast one regular ticket");
        return false;
    }
    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    var widgetRedirectUrl = '';
    var ucode = '';
    var acode = '';
    var samepage = '';
    var nobrand = '';
    for (var i = 0; i < sURLVariables.length; i++) {

        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == "widgetRedirectUrl") {
            widgetRedirectUrl = sParameterName[1];
        }
        if (sParameterName[0] == "ucode") {
            ucode = sParameterName[1];
        }
        if (sParameterName[0] == "acode") {
            acode = sParameterName[1];
        }
        if (sParameterName[0] == "samepage") {
            samepage = sParameterName[1];
        }
        if (sParameterName[0] == "nobrand") {
            nobrand = sParameterName[1];
        }
    }


    var meprcode = '';
    var url = (window.location != window.parent.location)
        ? document.referrer
        : document.location;
    meprcode = getParamValueFromUrl('meprcode',url);

    if(meprcode == null || meprcode == ''){}
    else{	ucode = meprcode; 	}


    if (ucode == '') {
        ucode = $('input[name="promoterCode"]').val();
    }
    var redirectionUrl =$('#redirectUrl').val();
    var inputData = {'ticketArray': ticketObj, 'eventId': eventId, 'discountCode': discountCode, 'donateTicketArray': donationObj,'widgetRedirectUrl': widgetRedirectUrl, 'pcode':pcode,'referralCode': referralCode, 'ucode': ucode,'acode': acode, 'pageType': pageType, 'ticketWidget':ticketWidget, 'redirectUrl' : redirectionUrl};
    if (addonArray.length > 0) {
        inputData.addonArray = addonArray;
    }
    if (typeof (isCourier) !== 'undefined' && isCourier != '') {
        inputData.isCourier = isCourier;
    }
    inputData.rcode = $('#rCode').val();
    inputData.isInterNetHandling=1;
    // Calling the Ajax to calculate the total amount of the selcted tickets and quantity
    $.ajax({
        type: "post",
        url: api_bookNow,
        datatype: 'json',
        headers: {'Content-Type': 'application/x-www-form-urlencoded',
            'Authorization': 'bearer ' + client_ajax_call_api_key
        },
        data: inputData,
        success: function (result) {
            //_paq.push(['trackEvent', ,'EventPage', 'Book Now']);
            var widgeturl='';
            var showTitle='';
            var showDateTime='';
            var showDateTime='';
            var wcode='';
            if($("#widgettheme").length == 0) {
                var theme=0;
            }else{
                var theme=$('#widgettheme').val();
                widgeturl +='&theme='+theme;
            }
            if( $('#showTitle').length ){
                widgeturl +='&title='+$('#showTitle').val();
            }
            if( $('#showDateTime').length ){
                widgeturl +='&dateTime='+$('#showDateTime').val();
            }
            if( $('#showLocation').length ){
                widgeturl +='&location='+$('#showLocation').val();
            }
            if( $('#wcode').length ){
                widgeturl +='&wcode='+$('#wcode').val();
            }
            if( $('#widgetThirdPartyUrl').length ){
                widgeturl +='&widgetThirdPartyUrl='+$('#widgetThirdPartyUrl').val();
            }
            if(nobrand!=''){
                widgeturl +='&nobrand=' + nobrand;
            }
            if($('#wcode').length){
                widgeturl +='&redirectUrl=' + redirectionUrl;
            }
            if($('#ticket_option').length){
                widgeturl +='&t=' + $('#ticket_option').val();
            }
            if($('#ticket_option_ids').length){
                widgeturl +='&tid=' + $('#ticket_option_ids').val();
            }
            if($('#directDetails').length){
                widgeturl +='&directDetails=' + $('#directDetails').val();
            }
            if(theme==1){
                // window.location.href = site_url + 'payment/' + eventId + '?orderid=' + result.response.orderId+'&samepage=1'+widgeturl;
                window.parent.location.href = site_url + 'payment/' + eventId + '?orderid=' + result.response.orderId+'&samepage=1'+widgeturl;
            }else{
                var isInIframe = (window.location != window.parent.location) ? true : false;
                if (isInIframe) {
                    if(samepage == null || samepage == ''){
                        window.top.location.href = site_url + 'payment/' + eventId + '?orderid=' + result.response.orderId;
                    }else {
                        window.location.href = site_url + 'payment/' + eventId + '?orderid=' + result.response.orderId +'&samepage=' + samepage +'&nobrand=' + nobrand;
                    }
                } else {
                    window.location.href = site_url + 'payment/' + eventId + '?orderid=' + result.response.orderId;
                }
            }
        },
        done: function () {
            setTimeout(function () {
                $("#dvLoading").hide();
            }, 2000);
        },
        error: function (result) {
            alert(result.responseJSON.response.messages[0]);
            $('#promo_code').removeAttr('readonly');
            $("#dvLoading").hide();
        }
    });
}
function getParamValueFromUrl( name, url ) {
    if (!url) url = location.href;
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( url );
    return results == null ? null : results[1];
}
$(document).ready(function(){
    if($("#copyGlobalCodeButton").length > 0){
        document.getElementById("copyGlobalCodeButton").addEventListener("click", function() {
            copyToClipboard(document.getElementById("affiliate_link"));
        });
    }

    function copyToClipboard(elem) {
        // create hidden text element, if it doesn't already exist
        var targetId = "_hiddenCopyText_";
        var isInput =  elem.tagName === "INPUT" || elem.tagName === "TEXTAREA";
        var origSelectionStart, origSelectionEnd;
        if (isInput) {
            // can just use the original source element for the selection and copy
            target = elem;
            origSelectionStart = elem.selectionStart;
            origSelectionEnd = elem.selectionEnd;
        } else {
            // must use a temporary form element for the selection and copy
            target = document.getElementById(targetId);
            if (!target) {
                var target = document.createElement("textarea");
                target.style.position = "absolute";
                target.style.left = "-9999px";
                target.style.top = "0";
                target.id = targetId;
                document.body.appendChild(target);
            }
            target.textContent = elem.textContent;
        }
        // select the content
        var currentFocus = document.activeElement;
        target.focus();
        target.setSelectionRange(0, target.value.length);

        // copy the selection
        var succeed;
        try {
            succeed = document.execCommand("copy");
        } catch(e) {
            succeed = false;
        }
        // restore original focus
        if (currentFocus && typeof currentFocus.focus === "function") {
            currentFocus.focus();
        }

        if (isInput) {
            // restore prior selection
            elem.setSelectionRange(origSelectionStart, origSelectionEnd);
        } else {
            // clear temporary content
            target.textContent = "";
        }
        return succeed;
    }

    $('.ticketselectioncheckbox').change(function(){
        var ticketid=$(this).attr('ticketid');
        if(this.checked) {
            $('.ticketselectioncheckbox_'+ticketid).val('1').trigger('change');
        }else{
            $('.ticketselectioncheckbox_'+ticketid).val('0').trigger('change');
        }
    });

    // internethandling fee efffects
    $(".handlingfeescontainer").hide();
    $(".handlingfees").click(function(){
        $(".handlingfeescontainer").slideToggle('fast');
        $(this).find('i').toggleClass('icon2-plus icon2-minus');
    });
});

$(function(){
    if (typeof (api_getTinyUrl) != 'undefined' && api_getTinyUrl != 'null') {
        if(api_getTinyUrl.length > 0){
            jQuery.ajax({
                type: "POST",
                url: api_getTinyUrl,
                data:{url:event_url},
                headers: {'Authorization': 'bearer 930332c8a6bf5f0850bd49c1627ced2092631250'},
                dataType: 'json',
                async: true,
                success: function (tinyUrl) {
                    var twUrl = 'http://twitter.com/home?status='+tweet+'...'+tinyUrl.response;
                    $("#twitterShareUrl").attr("href", twUrl);
                }

            });
        }

    }

    /*function to update & fetch event viewcount*/
	if (typeof viewCountUp != 'undefined' && viewCountUp == 1) { 
        jQuery.ajax({
            type: 'POST',
            url: api_updateEventViewCount,
            data:{eventid:eventid},
            headers: {'Authorization': 'bearer 930332c8a6bf5f0850bd49c1627ced2092631250'},
            dataType: 'json',
            async: true,
            success: function (viewcount) {
                $("#eventViewCount").html(viewcount.response);
            }
							
        });
    }
	
        
        if(typeof sDate !== 'undefined' && typeof eDate !== 'undefined'){
            var startDate = Date.convertStringToTime(sDate);
            var endDate = Date.convertStringToTime(eDate);
            // For multi date datepicker
            $('#multiDates-datePickerLeft')
                .datepicker({
                    minDate:startDate,
                    maxDate:endDate,
                    dateFormat:"yy-mm-dd",
                    beforeShowDay: function(date){
                        return DisableSpecificDates(date,enableDates);
                    }
            });
            $('#multiDates-datePickerRight')
                .datepicker({
                    minDate:startDate,
                    maxDate:endDate,
                    dateFormat:"yy-mm-dd",
                    beforeShowDay: function(date){
                        return DisableSpecificDates(date,enableDates);
                    }

            });

            // For anchor tag click
            $('#multiDates-datePickerLeftAnchor').click(function() {
                  $('#multiDates-datePickerLeft').datepicker('show');
                  return false;
            });
            $('#multiDates-datePickerRightAnchor').click(function() {
                  $('#multiDates-datePickerRight').datepicker('show');
                  return false;
            });
            
            $('#multiDates-datePickerLeft,#multiDates-datePickerRight').datepicker('option', 'onSelect', function (selectedDate) {
                if(selectedDate.length > 0){
                    var eventId = multiEventsWithDates.map(function(o) { 
                        var str = o.startDateTime;
                        var datestr = str.split(" ");
                        return datestr[0]; 
                    }).indexOf(selectedDate);
                    var pageType = $('#pageType').val();
                    var url;
                    var selectedEventId = multiEventsWithDates[eventId].id;
                    if(pageType == 'preview'){
                     url = eventurl + '&sub=' + selectedEventId;
                    }else{
                     url = eventurl + '/' + selectedEventId;
                    }
                    if(getParams.length > 1 && pageType != 'preview'){
                      url = url + '?' + getParams;
                    }
                    window.location.href = url;
                }
            });
      
            function DisableSpecificDates(date,enableDays) {
                var dateString = date.getFullYear() + '-' + ('0' + (date.getMonth()+1)).slice(-2) + '-' + ('0' + date.getDate()).slice(-2);
                for (i = 0; i < enableDays.length; i++) {
                    if($.inArray(dateString,enableDays) != -1) {
                        return [true];
                    }
                }
                return [false];
            }

        }
         $('#multidateoption').on('change',function(){
            var value = $('#multidateoption').val();
            var url = ticketWidgetUrl+'&sub='+value;
            window.location.href = url;
        });
        
});
window.onload = function(e){
    if($('.ticket_selector').length ==1){
        if($(".ticket_selector option:eq(1)").val()){
            singleTicket = true;
            $('.ticket_selector').val($(".ticket_selector option:eq(1)").val()).change();
            var ticketWidget = $('#ticketWidget').val();
            if (ticketWidget) {
                var directDetails = $('#directDetails').val();
                if (directDetails == 1) {
                    $('#tickets_tab1').hide();
                    $('#ticket_pane_tab1').hide();
                    booknow();
                }
            }
        }
    }

    var animTime = 300;
    $(document).on('click touch', '.widget-acc-btn-home', function(){
        var contentDiv = $(this).parents('.widget-ticketgroup').find('.widget-acc-content-home');
        if(contentDiv.height() > 0 && contentDiv.is(":visible")){ 
            contentDiv.slideUp(animTime); $('p.selected').removeClass('widget-ac-selected-home');
        }
        else{
            $('p.selected').removeClass('widget-ac-selected-home');
            $(this).children('p').addClass('widget-ac-selected-home');
            $('.widget-acc-content-home').slideUp(animTime);
            contentDiv.addClass('widget-open').slideDown(animTime);        
        }            
    });

    $(document).on('click touch', '.widget-acc-btn', function(){
        var contentDiv = $(this).parents('.widget-ticketgroup').find('.widget-acc-content');         
        if(contentDiv.height() > 0 && contentDiv.is(":visible")){ 
            contentDiv.slideUp(animTime); $('p.selected').removeClass('widget-ac-selected');
        }
        else{
            $('p.selected').removeClass('widget-ac-selected');
            $(this).children('p').addClass('widget-ac-selected');
            $('.widget-acc-content').slideUp(animTime);
            contentDiv.addClass('widget-open').slideDown(animTime);        
        }            
    });
}