/*Creating circular scroller icons at runtime*/
var arSelectors_NR = new Array();
var arSelectors_TT = new Array();
var arSelectors_RA = new Array();
var arSelectors_HL = new Array();
var arSelectors_DS = new Array();
/*Creating circular scroller icons at runtime*/
$(function () {

    // Preload images
    $('body').append('<div style="position:absolute;top:-99999999px;"><img src="'+varImagePath+'"/img/search-button-on.gif" /><img src="'+varImagePath+'"/img/button-save-on.gif" /><img src="'+varImagePath+'"/img/button-cancel-on.gif" /><img src="'+varImagePath+'"/img/button-edit-account-on.gif" /><img src="'+varImagePath+'"/img/button-save2-on.gif" /></div>');

    $('#search-field .field').click(function () {
        $(this).val('');
        $(this).css('color', '#000000');
    });

    //Fixed for Send button hover and visited effect done on April 21,2011
    $('#contactUsSubmitBtn').mouseover(function () {
        $(this).attr('src', varImagePath + '/img/button-send2-on.png');
    }).mouseout(function () {
        $(this).attr('src', varImagePath + '/img/button-send2.png');
    });

    //Fixed for Save button hover and visited effect done on April 21,2011
    $('#contactUsSubmitBtnSave').mouseover(function () {
        $(this).attr('src', varImagePath + '/img/button-save2-on.png');
    }).mouseout(function () {
        $(this).attr('src', varImagePath + '/img/button-save2.png');
    });




    //Fixed for Register button hover and visited effect done on May 3,2011
    $('#btnRegister').mouseover(function () {
        $(this).attr('src', varImagePath + '/img/button-register-on.png');
    }).mouseout(function () {
        $(this).attr('src', varImagePath + '/img/button-register.png');
    });

    $('#search-field .button').mouseover(function () {
        $(this).attr('src', varImagePath + '/img/search-button-on.gif');
    }).mouseout(function () {
        $(this).attr('src', varImagePath + '/img/search-button.gif');
    });

    /*Fix for avoid flickering on Home button in Create Account,Edit Account,Contact Us page*/
    $('#btncancel').mouseover(function () {
        $(this).attr('src', varImagePath + '/img/button-cancel-on.png');
    }).mouseout(function () {
        $(this).attr('src', varImagePath + '/img/button-cancel.png');
    });
    $('#buttonedit').mouseover(function () {
        $(this).attr('src', varImagePath + '/img/button-edit-account-on.png');
    }).mouseout(function () {
        $(this).attr('src', varImagePath + '/img/button-edit-account.png');
    });
    /*Fix for avoid flickering on Home button in Create Account,Edit Account,Contact Us page*/
    $('.button-buy').mouseover(function () {
        $(this).attr('src', varImagePath + '/img/buy-0-on.png');
    }).mouseout(function () {
        $(this).attr('src', varImagePath + '/img/buy-0.png');
    });

    $('.button-rent').mouseover(function () {
        $(this).attr('src', varImagePath + '/img/rent-0-on.png');
    }).mouseout(function () {
        $(this).attr('src', varImagePath + '/img/rent-0.png');
    });

    $('.button-watch-trailer').mouseover(function () {
        $(this).attr('src', varImagePath + '/img/button-watch-trailer-on.png');
    }).mouseout(function () {
        $(this).attr('src', varImagePath + '/img/button-watch-trailer.png');
    });

    $('#anchWatchPromo').mouseover(function () {
        $(this).attr('src', varImagePath + '/img/button-watch-movie-on.png');
    }).mouseout(function () {
        $(this).attr('src', varImagePath + '/img/button-watch-movie.png');
    });

    $(".device-select").jCarouselLite({
        btnNext: ".device-select-right",
        btnPrev: ".device-select-left",
        /*afterEnd: function (a) {
        $('.compatible-devices .button-save').css('display', 'block');
        },*/
        visible: 1
    });

    if ($(".jc-top-10")) {
        setCircularScrollers(ttCount, 'scrl_top10'); /*Creating circular scroller icons at runtime*/
        $(".jc-top-10").jCarouselLite({
            btnNext: ".jc-top-10-right",
            btnPrev: ".jc-top-10-left",
            visible: ttCount < 6 ? ttCount : 6,
            scroll: ttCount < 6 ? ttCount : 6,
            circular: true, /*Fix for issue#AT-728 done on April 22, 2011*/
            afterEnd: function (a) {
                hoverPackShot();
                $('.jc-top-10-right').show();
                $('.jc-top-10-left').show();
                var psID = $(a[0]).attr("class");
                var newIndex = 1;
                if (psID != null) {
                    var prts = psID.split('-');
                    psID = parseInt(prts[1]);
                    newIndex = Math.round((psID - 1) / 6) + 1;
                }
                //$("a[class*='top-10-'] img").attr('src', 'acetrax/samsungrevamp/img/scroll-icon.png');
                $("a[class*='top-10-'] img").each(function () { $(this).attr('src', varImagePath + '/img/scroll-icon.png') });
                $('.top-10-' + newIndex + ' img').attr('src', varImagePath + '/img/scroll-icon-on.png');
                if (newIndex > 1) {
                    if (Math.ceil(ttCount / 6) == newIndex) {
                        $('.jc-top-10-right').hide();
                    }
                }
                else if (newIndex == 1)
                    $('.jc-top-10-left').hide();
            },
            btnGo: arSelectors_TT
            /*[".top-10-1", "", "", "", "", "",
            ".top-10-2", "", "", "", "", "",
            ".top-10-3", "", "", "", "", "",
            ".top-10-4", "", "", "", "", "",
            ".top-10-5", "", "", "", "", "",
            ".top-10-6", "", "", "", "", ""]*/
        });
    };

    if ($(".jc-recently-added")) {
        setCircularScrollers(raCount, 'scrl_recentlyadded'); /*Creating circular scroller icons at runtime*/
        $(".jc-recently-added").jCarouselLite({
            btnNext: ".jc-recently-added-right",
            btnPrev: ".jc-recently-added-left",
            visible: raCount < 6 ? raCount : 6,
            scroll: raCount < 6 ? raCount : 6,
            circular: true,
            afterEnd: function (a) {
                hoverPackShot();
                $('.jc-recently-added-right').show();
                $('.jc-recently-added-left').show();
                var psID = $(a[0]).attr("class");
                var newIndex = 1;
                if (psID != null) {
                    var prts = psID.split('-');
                    psID = parseInt(prts[1]);
                    var newIndex = Math.round((psID - 1) / 6) + 1;
                }
                //$("a[class*='recently-added-'] img").attr('src', 'acetrax/samsungrevamp/img/scroll-icon.png');
                $("a[class*='recently-added-'] img").each(function () { $(this).attr('src', varImagePath + '/img/scroll-icon.png') });
                $('.recently-added-' + newIndex + ' img').attr('src', varImagePath + '/img/scroll-icon-on.png');
                if (newIndex > 1) {
                    if (Math.ceil(raCount / 6) == newIndex) {
                        $('.jc-recently-added-right').hide();
                    }
                }
                else if (newIndex == 1)
                    $('.jc-recently-added-left').hide();
            },
            btnGo: arSelectors_RA
            /*[".recently-added-1", "", "", "", "", "",
            ".recently-added-2", "", "", "", "", "",
            ".recently-added-3", "", "", "", "", "",
            ".recently-added-4", "", "", "", "", "",
            ".recently-added-5", "", "", "", "", "",
            ".recently-added-6", "", "", "", "", ""]*/
        });
    };

    if ($("#download")) {
        $("#download").jCarouselLite({
            btnNext: ".jc-download-right",
            btnPrev: ".jc-download-left",
            visible: 1,
            scroll: 1,
            circular: true,
            afterEnd: function (a) {
                $('.jc-download-left').show();
                $('.jc-download-right').show();
                var psID = $(a[0]).attr("id");
                var newIndex = 1;
                if (psID != null) {
                    var prts = psID.split('-');
                    psID = parseInt(prts[1]);
                    var newIndex = Math.round((psID - 1) / 1) + 1;
                }
                 $("a[class*='new-releases-'] img").each(function () { $(this).attr('src', varImagePath + '/img/scroll-icon.png'); });
        $('.new-releases-' + newIndex + ' img').attr('src', varImagePath + '/img/scroll-icon-on.png');
        if (newIndex == 4)
        $('.jc-download-right').hide();
        else if (newIndex == 1)
        $('.jc-download-left').hide();
        },
        btnGo:
        [".new-releases-1", "", "", "",
        ".new-releases-2", "", "", "",
        ".new-releases-3", "", "", "",
        ".new-releases-4", "", "", ""]
        });
    };


    if ($(".jc-new-releases")) {
        setCircularScrollers(naCount, 'scrl_newrelease'); /*Creating circular scroller icons at runtime*/
        $(".jc-new-releases").jCarouselLite({
            btnNext: ".jc-new-releases-right",
            btnPrev: ".jc-new-releases-left",
            visible: naCount < 6 ? naCount : 6,
            scroll: naCount < 6 ? naCount : 6,
            circular: true,
            afterEnd: function (a) {
                hoverPackShot();
                $('.jc-new-releases-right').show();
                $('.jc-new-releases-left').show();
                var psID = $(a[0]).attr("class");
                var newIndex = 1;
                if (psID != null) {
                    var prts = psID.split('-');
                    psID = parseInt(prts[1]);
                    var newIndex = Math.round((psID - 1) / 6) + 1;
                }
                //$("a[class*='new-releases-'] img").attr('src', 'acetrax/samsungrevamp/img/scroll-icon.png');
                $("a[class*='new-releases-'] img").each(function () { $(this).attr('src', varImagePath + '/img/scroll-icon.png'); });
                $('.new-releases-' + newIndex + ' img').attr('src', varImagePath + '/img/scroll-icon-on.png');
                if (newIndex > 1) {
                    if (Math.ceil(naCount / 6) == newIndex) {
                        $('.jc-new-releases-right').hide();
                    }
                }
                else if (newIndex == 1)
                    $('.jc-new-releases-left').hide();
            },
            btnGo: arSelectors_NR
            /*[".new-releases-1", "", "", "", "", "",
            ".new-releases-2", "", "", "", "", "",
            ".new-releases-3", "", "", "", "", "",
            ".new-releases-4", "", "", "", "", "",
            ".new-releases-5", "", "", "", "", "",
            ".new-releases-6", "", "", "", "", ""]*/
        });
    };



    /* vouchers amount, when user points near the vouchers link display in the left panel */
    $('#voucher-balance-link').mouseover(function () {
        //Changed for Mouse over popup on Vouchers.
        getYourVouchersOnLink();
        var xml = varxml;
        if ($(xml).find('voucher').length > 0) {
            $('#voucher-balance-float').css('display', 'block');
        }
        else {
            $('#voucher-balance-float').css('display', 'none');
        }
    }).mouseout(function () {
        $(".voucher_exmp_boxLink table").empty();
        $('#voucher-balance-float').css('display', 'none');
    });
    $('#voucher-balance-float').mouseover(function () {
        $('#voucher-balance-float').css('display', 'block');
    }).mouseout(function () {
        $('#voucher-balance-float').css('display', 'none');
    });

    $('#account-balance-link').mouseover(function () {
        $('#account-balance-float').css('display', 'block');
    }).mouseout(function () {
        $('#account-balance-float').css('display', 'none');
    });
    $('#account-balance-float').mouseover(function () {
        $('#account-balance-float').css('display', 'block');
    }).mouseout(function () {
        $('#account-balance-float').css('display', 'none');
    });

    $('.pack-shot').mouseover(function () {
        $('img', this).css('visibility', 'visible');
        $('.movie-hover-summary', this).css('visibility', 'visible');
    }).mouseout(function () {
        $('img', this).css('visibility', 'hidden');
        $('.movie-hover-summary', this).css('visibility', 'hidden');
    });

    $('.packshot').mouseover(function () {
        $('img', this).css({ border: '3px solid #f2b619' });
    }).mouseout(function () {
        $('img', this).css({ border: '0px' });
    });

    $('.film-details-inner .checkbox').mouseover(function () {
        //$('.movie-hover-synopsis',this).css('visibility','visible');


        if ($('.movie-hover-synopsis', this).length) {

            var x = $(this).offset().left + 90;
            var y = $(this).offset().top - 18;
            $('#movie-synopsis-main-middle').html($('.movie-hover-synopsis', this).html());
            $('#movie-synopsis-main').css('display', 'block');
            $('#movie-synopsis-main').css('left', x + 'px');
            $('#movie-synopsis-main').css('top', y + 'px');
        }

    }).mouseout(function () {
        //$('.movie-hover-synopsis',this).css('visibility','hidden');
        $('#movie-synopsis-main').css('display', 'none');
    });

    $('#movie-synopsis-main').mouseover(function () {
        $('#movie-synopsis-main').css('display', 'block');
    }).mouseout(function () {
        //$('.movie-hover-synopsis',this).css('visibility','hidden');
        $('#movie-synopsis-main').css('display', 'none');
    });


    $(".dropdown dt a").click(function () {
        $(".dropdown dd ul").toggle();
        return false;
    });

    $(document).bind('click', function (e) {
        var $clicked = $(e.target);
        if (!$clicked.parents().hasClass("dropdown"))
            $(".dropdown dd ul").hide();
    });

    $(".dropdown dd ul li a").click(function () {
        var text = $(this).html();
        $(".dropdown dt a").html(text);
        $(".dropdown dd ul").hide();

        var source = $("#source");
        source.val($(this).find("span.value").html())
    });


    $(".dropdown2 dt a").click(function () {
        $(".dropdown2 dd ul").toggle();
        return false;
    });

    $(document).bind('click', function (e) {
        var $clicked = $(e.target);
        if (!$clicked.parents().hasClass("dropdown2"))
            $(".dropdown2 dd ul").hide();
    });

    $(".dropdown2 dd ul li a").click(function () {
        var text = $(this).html();
        $(".dropdown2 dt a").html(text);
        $(".dropdown2 dd ul").hide();

        var source = $("#source");
        source.val($(this).find("span.value").html())
    });

    $(".dropdown-mobile dd ul li a").click(function () {
        var text = $(this).html();
        var par = $(this).parent().parent().parent().parent();
        $(".dropdown-mobile dt a", par).html(text);
        $(".dropdown-mobile dd ul", par).hide();
        return false;
    });

    $(".dropdown-mobile dt a").click(function () {
        var par = $(this).parent().parent();
        $("dd ul").hide();
        $("dd ul", par).slideToggle('fast');
        return false;
    });

    $(document).bind('click', function (e) {
        var $clicked = $(e.target);
        if (!$clicked.parents().hasClass("dropdown-mobile"))
            $(".dropdown-mobile dd ul").hide();
        //return false;
    });

    $(".dropdown-related dd ul li a").click(function () {
        var text = $(this).html();
        var par = $(this).parent().parent().parent().parent();
        $(".dropdown-related dt a", par).html(text);
        $(".dropdown-related dd ul", par).hide();
        return false;
    });

    $(".dropdown-related dt a").click(function () {
        var par = $(this).parent().parent();
        $("dd ul").hide();
        $("dd ul", par).slideToggle('fast');
        return false;
    });

    $(document).bind('click', function (e) {
        var $clicked = $(e.target);
        if (!$clicked.parents().hasClass("dropdown-related"))
            $(".dropdown-related dd ul").hide();
        //return false;
    });

});



function hoverPackShot() {

    $('.pack-shot').mouseover(function () {
        $('img', this).css('visibility', 'visible');
    }).mouseout(function () {
        $('img', this).css('visibility', 'hidden');
    });

};

// ******************************* TOPUP CREDIT ******************************* //

function getTopupCredit() {
    i = 0;
    var total_balance = 0;
    var mycurrency = "";
    var placeHolderName = ".topupCredit"
    $(placeHolderName).empty();
    $(placeHolderName).fadeOut("fast");
    if (varxml == null) {
        $.ajax({
            type: "POST",
            async: false,
            url: "GetUserVouchers.aspx?filterByCurrency=true",
            dataType: "xml",
            data: { allvouchers: 1 },
            success: function (xml) {
                varxml = xml;
                mycurrency = $(xml).find('UserPaymentMethods').attr('currency');
                if (mycurrency == undefined)
                    mycurrency = "GBP";
                $(xml).find('voucher').each(function () {
                    var contentId = $(this).find('contentId').text();
                    var currency = $(this).find('currency').text();
                    var expirationDate = $(this).find('expirationDate').text();
                    var expirationDateFormated = new Date(expirationDate).format(DEFAULT_DATE_FORMAT)
                    var reference = $(this).find('reference').text();
                    var value = $(this).find('value').text();
                    // convert to number
                    value = parseFloat(value) ? parseFloat(value).toFixed(2) : "0.00";
                    var state = $(this).find('state').text();
                    var type = $(this).find('type').text();
                    if (type == "") { type = "ALL"; }
                    var isTopUp = $(this).find('is_topup').text();
                    value = value.replace(",", ".");
                    if (state == "new") {
                        if (isTopUp.toLowerCase() == 'true') {
                            total_balance += parseFloat(value);
                        }
                    }

                    i = i + 1;
                });

                $(placeHolderName).append(convertToCurrencySymbol(mycurrency, total_balance.toFixed(2)) + "");
                $(placeHolderName).fadeIn("slow");
            }
        });
    }
    else {
        mycurrency = $(varxml).find('UserPaymentMethods').attr('currency');
        if (mycurrency == undefined)
            mycurrency = "GBP";
        $(varxml).find('voucher').each(function () {
            var contentId = $(this).find('contentId').text();
            var currency = $(this).find('currency').text();
            var expirationDate = $(this).find('expirationDate').text();
            var expirationDateFormated = new Date(expirationDate).format(DEFAULT_DATE_FORMAT)
            var reference = $(this).find('reference').text();
            var value = $(this).find('value').text();
            // convert to number
            value = parseFloat(value) ? parseFloat(value).toFixed(2) : "0.00";
            var state = $(this).find('state').text();
            var type = $(this).find('type').text();
            if (type == "") { type = "ALL"; }
            var isTopUp = $(this).find('is_topup').text();
            value = value.replace(",", ".");
            if (state == "new") {
                if (isTopUp.toLowerCase() == 'true') {
                    total_balance += parseFloat(value);
                }
            }

            i = i + 1;
        });

        $(placeHolderName).append(convertToCurrencySymbol(mycurrency, total_balance.toFixed(2)) + "");
        $(placeHolderName).fadeIn("slow");
    }

}


//// ******************************* TOPUP CREDIT ******************************* //

// ******************************* /CREATE ACCOUNT ******************************* //

function validateUserAccount() {

    firstname = $("input[name=fname]").val();

    lastname = $("input[name=lname]").val();

    username = $("input[name=username]").val();

    password = $("input[name=pw1]").val();

	// Not required as directly checkig the value as conditions
    //genderVal = $("input[id=gender-male]:checked").val();
    
	/* Code updated - on Oct 12, 2011, genderVal contains 'undefined' and 'on' value to pass Mr/Ms to Samsung API so need to change conditions, verified with Create user dummy HTML page */
    /* Issue: Wrong message display after click on submit on create account screen */
    if ($("input[id=gender-male]:checked").val() == "on")
        genderVal = "Mr.";
    else if ($("input[id=gender-female]:checked").val() == "on")
        genderVal = "Ms.";

    sMonth = parseInt($("select[id$=months] :selected").text());

    if (sMonth < 10) {
        selectedMonth = '0' + $("select[id$=months] :selected").text();
    }
    else if (sMonth >= 10) {
        selectedMonth = $("select[id$=months] :selected").text();
    }

    selectedYear = parseInt($("select[id$=years] :selected").text());

    sDay = parseInt($("select[id$=days] :selected").text());

    if (sDay < 10) {
        selectedDay = '0' + $("select[id$=days] :selected").text();
    }
    else if (sDay >= 10) {
        selectedDay = $("select[id$=days] :selected").text();
    }
	
    news = $("input[name=newsletter]:checked").val();
	/* Code updated - on Oct 12, 2011, news contains 'undefined' and 'on' value to pass Y/N to Samsung API so need to add conditions (Y and N as default), verified with Create user dummy HTML page */
	/* Issue: Samsung revamp: Create account is giving error of "emailAgreement" when user selects newsletter option; otherwise it works fine (reported by Ankur Goel in production release)*/
    if (news == "on") {
        news = "Y";
    }
	else {
		news = "N";
	}


    if ($("#language").text() == "English") {
        countryCode = "GBR";
    }
    else if ($("#language").text() == "Italian") {
        countryCode = "ITA";
    }
    else {
        countryCode = "GBR";
    }


    $.ajax({
        url: "CreateSamsungUser.aspx",
        type: "POST",
        data: { firstName: firstname, lastName: lastname, countryCode: countryCode, password: password, genderCode: genderVal, birthMonth: selectedMonth, birthYear: selectedYear, birthDate: selectedDay, emailAgreement: news, emailID: username },

        success: function (resp) {


            if (resp == undefined) {
                resp = "100";
            }
            /*Fix for HTTP-404 error in case of samsung user creation api failed*/
            if ($(resp, top.document).find('span#page_type').length > 0) {
                if ($(resp, top.document).find('span#page_type').html() == 'GeneralError')
                    resp = 'Error';
            }
            /*Fix for HTTP-404 error in case of samsung user creation api failed*/

            //            showModalPopup('Generic.aspx?type=AccountSuccess&returnVal=' + resp + '&refreshcache=1', 'frameId_AccountSuccess', '645', '330', '', this);
            showModalPopup('Generic.aspx?type=AccountSuccess&returnVal=' + resp, 'frameId_AccountSuccess', '645', '330', '', this);
        },
        error: function () {
            alert("Error");
            // enableClick(isto);
        },
        complete: function () {
            //alert("Terminado");
        }
    });
}


// ******************************* /CREATE ACCOUNT ******************************* //

// ******************************* EDIT ACCOUNT ******************************* //

function validateEditSamsungAccount() {

    //username = $("#user_name").html();
    var countryCode;
    pwd = $("input[name=pw1]").val();

    email = $("input[name=mail1]").val();


    if ($("#language").text() == "English") {
        countryCode = "GBR";
    }
    else if ($("#language").text() == "Italian") {
        countryCode = "ITA";
    }
    else {
        countryCode = "GBR";
    }



    $.ajax({
        url: "UpdateSamsungUser.aspx",
        type: "POST",
        data: { countryCode: countryCode, emailID: email, password: pwd },
        success: function (resp) {
            if (resp == undefined) {
                resp = "100";
            }

            //            showModalPopup('Generic.aspx?type=AccountEditSuccess&returnVal=' + resp + '&refreshcache=1', 'frameId_SignIn', '645', '330', '', this);
            showModalPopup('Generic.aspx?type=AccountEditSuccess&returnVal=' + resp, 'frameId_SignIn', '645', '330', '', this);
        },
        error: function () {
            alert("Error");
            // enableClick(isto);
        },
        complete: function () {
            //alert("Terminado");
        }
    });
}

// ******************************* /EDIT ACCOUNT ******************************* //


//********************************getDetailsVouchers Start*********************//
function getVoucherDetails() {
    type = "";
    if (varxml == null) {
        $.ajax({
            type: "GET",
            async: false,
            url: "GetUserVouchers.aspx?filterByCurrency=true",
            dataType: "xml",
            success: function (xml) {
                varxml = xml;
                $(".radio-checkbox").empty();
                $(".voucher-checkboxes").empty();
                var topUpVoucher;
                var voucherName;
                var topUpValue;
                var topUpCurrency;
                var ctr_TopUp = 0;
                var ctr_Voucher = 0; /*Change as per Pietro's requirement*/
                $('.radio-checkbox').append('<input id="radio_paypal" type="radio" name="option" value="paypal"/>PayPal<!--&nbsp;<input type="radio" name="option" value="candb"/>ClickandBuy--><br/>');
                $(xml).find('voucher').each(function () {
                    var type = $(this).find('type').text();
                    if (type == "") { type = "ALL" }

                    var contentId = $(this).find('contentId').text();
                    var currency = $(this).find('currency').text();
                    var expirationDate = $(this).find('expirationDate').text();
                    var expirationDateFormated = new Date(expirationDate).format(DEFAULT_DATE_FORMAT);
                    var reference = $(this).find('reference').text();
                    var value = $(this).find('value').text();
                    var isTopUp = $(this).find('is_topup').text();
                    arVoucher[reference] = contentId;
                    var checkboxid = reference;
                    //var voucherName = varVoucher_voucher;
                    if (isTopUp.toLowerCase() == 'true') {
                        //topUpVoucher = reference;
                        ctr_TopUp = ctr_TopUp + 1; /*Changed as per Pietro's requirement*/
                        topUpValue = value;
                        topUpCurrency = currency;
                        if (parseFloat(topUpValue) > 0) {
                            $('#radio_paypal').get(0).checked = false;
                            if (ctr_TopUp == 1) {
                                topUpVoucher = 'Top-Up';
                                $('.radio-checkbox').append('<input id="' + checkboxid + '" type="radio" name="option" checked="true" value="topup"/><span id="voucher_name">' + topUpVoucher + ' ' + '</span><span id="span-topupamount" title="' + topUpValue + '">' + convertToCurrencySymbol(topUpCurrency, topUpValue) + '</span>');
                            }
                        }
                        else {
                            topUpVoucher = 'Top-Up' + ctr_TopUp;
                            $('#radio_paypal').get(0).checked = true;
                            $('.radio-checkbox').append('<input id="' + checkboxid + '" type="radio" name="option" value="topup"/><span id="voucher_name">' + topUpVoucher + ' ' + '</span><span id="span-topupamount" title="' + topUpValue + '">' +
							convertToCurrencySymbol(topUpCurrency, topUpValue) + '</span>');
                        }
                        topUpVoucher = '';
                        topUpValue = '';
                        topUpCurrency = '';
                    }
                    //if (((selectedType == "rent") && ((type == "ALL") || (type == "VOD"))) || ((selectedType == "buy") && (type == "ALL"))) {
                    else if ((((type == "ALL") || (type == "VOD"))) || (type == "ALL")) {
                        //Force round vouchers value
                        value = value.replace(',', '.');
                        value = parseFloat(value).toFixed(2);
                        ctr_Voucher = ctr_Voucher + 1;
                        voucherName = 'Voucher' + ctr_Voucher;
                        //Hide vouchers with value = 0
                        if (value > 0) {
                            value = value.replace('.', ',');
                            /*$(".voucher-checkboxes").append('<p><input id="' + checkboxid + '" type="radio" name="option" value="voucher"/><b><span id="voucher_name">' + reference + '</span></b><br/><span id="voucher-valuewithcurrency">' + convertToCurrencySymbol(currency, value) + '</span><span>&nbsp;</span> expires<span>&nbsp;</span><span>' + expirationDateFormated + '</span></p>');*/

                            $(".voucher-checkboxes").append('<p><input id="' + checkboxid + '" type="radio" name="option" value="voucher"/><b><span id="voucher_name">' + voucherName + '</span></b><br/><span id="voucher-valuewithcurrency" title="' + value + '">' + convertToCurrencySymbol(currency, value) + '</span><span>&nbsp;</span> ' + varExpires + '<span>&nbsp;</span><span>' + expirationDateFormated + '</span></p>'); /*Changes done as per Pietros requirement*/
                        }
                    }
                });
            }
        });
    }
    else {
        $(".radio-checkbox").empty();
        $(".voucher-checkboxes").empty();
        var topUpVoucher;
        var voucherName;
        var topUpValue;
        var topUpCurrency;
        var ctr_TopUp = 0;
        var ctr_Voucher = 0; /*Change as per Pietro's requirement*/
        $('.radio-checkbox').append('<input id="radio_paypal" type="radio" name="option" value="paypal"/>PayPal<!--&nbsp;<input type="radio" name="option" value="candb"/>ClickandBuy--><br/>');
        $(varxml).find('voucher').each(function () {
            var type = $(this).find('type').text();
            if (type == "") { type = "ALL" }

            var contentId = $(this).find('contentId').text();
            var currency = $(this).find('currency').text();
            var expirationDate = $(this).find('expirationDate').text();
            var expirationDateFormated = new Date(expirationDate).format(DEFAULT_DATE_FORMAT);
            var reference = $(this).find('reference').text();
            var value = $(this).find('value').text();
            var isTopUp = $(this).find('is_topup').text();
            arVoucher[reference] = contentId;
            var checkboxid = reference;
            //var voucherName = varVoucher_voucher;
            if (isTopUp.toLowerCase() == 'true') {
                //topUpVoucher = reference;
                ctr_TopUp = ctr_TopUp + 1; /*Changed as per Pietro's requirement*/
                topUpValue = value;
                topUpCurrency = currency;
                if (parseFloat(topUpValue) > 0) {
                    $('#radio_paypal').get(0).checked = false;
                    if (ctr_TopUp == 1) {
                        topUpVoucher = 'Top-Up';
                        $('.radio-checkbox').append('<input id="' + checkboxid + '" type="radio" name="option" checked="true" value="topup"/><span id="voucher_name">' + topUpVoucher + ' ' + '</span><span id="span-topupamount" title="' + topUpValue + '">' + convertToCurrencySymbol(topUpCurrency, topUpValue) + '</span>');
                    }
                }
                else {
                    topUpVoucher = 'Top-Up' + ctr_TopUp;
                    $('#radio_paypal').get(0).checked = true;
                    $('.radio-checkbox').append('<input id="' + checkboxid + '" type="radio" name="option" value="topup"/><span id="voucher_name">' + topUpVoucher + ' ' + '</span><span id="span-topupamount" title="' + topUpValue + '">' +
							convertToCurrencySymbol(topUpCurrency, topUpValue) + '</span>');
                }
                topUpVoucher = '';
                topUpValue = '';
                topUpCurrency = '';
            }
            //if (((selectedType == "rent") && ((type == "ALL") || (type == "VOD"))) || ((selectedType == "buy") && (type == "ALL"))) {
            else if ((((type == "ALL") || (type == "VOD"))) || (type == "ALL")) {
                //Force round vouchers value
                value = value.replace(',', '.');
                value = parseFloat(value).toFixed(2);
                ctr_Voucher = ctr_Voucher + 1;
                voucherName = 'Voucher' + ctr_Voucher;
                //Hide vouchers with value = 0
                if (value > 0) {
                    value = value.replace('.', ',');
                    /*$(".voucher-checkboxes").append('<p><input id="' + checkboxid + '" type="radio" name="option" value="voucher"/><b><span id="voucher_name">' + reference + '</span></b><br/><span id="voucher-valuewithcurrency">' + convertToCurrencySymbol(currency, value) + '</span><span>&nbsp;</span> expires<span>&nbsp;</span><span>' + expirationDateFormated + '</span></p>');*/

                    $(".voucher-checkboxes").append('<p><input id="' + checkboxid + '" type="radio" name="option" value="voucher"/><b><span id="voucher_name">' + voucherName + '</span></b><br/><span id="voucher-valuewithcurrency" title="' + value + '">' + convertToCurrencySymbol(currency, value) + '</span><span>&nbsp;</span> ' + varExpires + '<span>&nbsp;</span><span>' + expirationDateFormated + '</span></p>'); /*Changes done as per Pietros requirement*/
                }
            }
        });
    }
}



//********************************getDetailsVouchers End***********************//

function showBox() {
    $('.radio-checkbox').show();
    $('.voucher-checkboxes').show();
    $('#dv_terms_detail').show();
}

function handleBuyRentProcess(offerContentId, evt, p, offerVal) {
    var dv_error_msg;
    var chkTermsAndConditions;
    var offer = $.trim(offerVal);    
    var voucherContentId;
    var panel;

	var totalprice = 0;
    var arPurchaseContentOfferId = new Array();
    /*Check for episodes selection exists then buy episodes else buy complete season*/
    /*Reterive the price value from the offer associated @prive value*/
    if (arEpisodePurchaseOfferID.length > 0) {
        for (var i = 0; i < arEpisodePurchaseOfferID.length; i++) {
            arPurchaseContentOfferId.push(arEpisodePurchaseOfferID[i]);
        }
        totalprice = parseFloat(arPurchase['EpisodePrice']);
    }
    else {
        arPurchaseContentOfferId.push(offerContentId);
        //if (lang == "Italian") {
        //    totalprice = parseFloat(arPurchase[offer].substring(0, arPurchase[offer].indexOf(' ') - 1)); 
        // }
        // else
        if (offer == 'buy')
            totalprice = parseFloat(arPurchase['MovieBuyPrice']);
        else
            totalprice = parseFloat(arPurchase['MovieRentPrice']);
    }

    if ((document.getElementById('moviePreviewPanel').style.display == 'none') || (document.getElementById('moviePreviewPanel').style.display == '')) {
        panel = $('#film_form_detail');
        dv_error_msg = $('#dv_error_msg_detail');
        chkTermsAndConditions = $('#chkTermsAndConditions_detail').get(0);
    }
    else if ((document.getElementById('movieDetailPanel').style.display == 'none') || (document.getElementById('movieDetailPanel').style.display == '')) {
        panel = $('#film_form_preview');
        dv_error_msg = $('#dv_error_msg_preview');
        chkTermsAndConditions = $('#chkTermsAndConditions_preview').get(0);
    }
    dv_error_msg.removeAttr('class');
	
    /*if(dv_error_msg.show()){
    dv_error_msg.hide();
    }*/

	
    if (!document.getElementById('userid')) {


		/* --------------OLD code : hanlded within setPageType() function---------------- */		
       /*********** var loc = document.location;
        var pTypeVal = location.pathname.replace('/', '');
        if (loc.href.indexOf('?') != -1 && loc.search != '') {
            if (loc.href.indexOf('&') != -1)
                pTypeVal = pTypeVal + '?' + loc.href.split('?')[1].substring(0, loc.href.indexOf('&'));
            else
                pTypeVal = pTypeVal + '?' + loc.href.split('?')[1];
        }

        var varSearchVal = '';***********/
        /**SamsungRevamp  
        Start**/
        /**********if (detailObject.channelId) {
            if (document.getElementById('hdnSearchString'))
                varSearchVal = document.getElementById('hdnSearchString').value;

            if (varSearchVal != '') {
                if (pTypeVal.indexOf("=") > -1 || pTypeVal.indexOf("&") > -1)// || window.location.search.substring(1).length > 0)
                {
                    if (pTypeVal.indexOf("search=") == -1 || pTypeVal.indexOf("Search=") == -1) {
                        pTypeVal = pTypeVal + "&Search=" + varSearchVal + ',detailObject={"channelId":"' + detailObject.channelId + '","contentId":"' + detailObject.contentId + '",'
            + '"channelName":"' + detailObject.channelName + '"}';
                    }
                }
                else
                    pTypeVal = pTypeVal + "?Search=" + varSearchVal + ',detailObject={"channelId":"' + detailObject.channelId + '","contentId":"' + detailObject.contentId + '",'
            + '"channelName":"' + detailObject.channelName + '"}';

            }
            else {
                pTypeVal = pTypeVal + ',detailObject={"channelId":"' + detailObject.channelId + '","contentId":"' + detailObject.contentId + '",'
            + '"channelName":"' + detailObject.channelName + '"}';
            }
        }*******/
        /**SamsungRevamp
        End**/
        /********showModalPopup('Generic.aspx?type=Login&pType=' + pTypeVal, 'frameId_SignIn', '625', '325', '', this);	**********/	

		
		/* -------------New Code: To show popup without pTypeVal----------------------- */
		showModalPopup('Generic.aspx?type=Login', 'frameId_SignIn', '625', '325', '', this);
    }
	
	
	
    else if (!validateVouchers(totalprice)) {
        /*dv_error_msg.html('Voucher amount is less than cost of movie');
        dv_error_msg.animate({  top: "0px"  }, 2000 ).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);*/
        //close the message box when cross red image is clicked  $("#close_message").click(function()  {     $("#dv_error_msg").fadeOut("slow");  });
        //dv_error_msg.show();
        return;
    }

    else if (!chkTermsAndConditions.checked) {
        dv_error_msg.html(varTermsCondition);
        $('.radio-checkbox').hide();
        $('.voucher-checkboxes').hide();
        $('#dv_terms_detail').hide();
        dv_error_msg.attr('class', 'overlay');
        dv_error_msg.animate({ top: "0px" }, 2000).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(3500);
        window.setTimeout(showBox, '5500');
        //$('.radio-checkbox').show();
        //$('.voucher-checkboxes').show();
        //$('#dv_terms_detail').show();
        //window.setTimeout('myMethod()', 1000);
        return;

    }

    //Go to Payment Gateway	  
    var arRadio = new Array();
    var pageType = $("#page_type").text();
    var lang = $("#language").text();

    for (var ictr = 0; ictr < panel.find('input').length; ictr++) {
        if (panel.find('input').get(ictr).type == 'radio')
            arRadio.push(panel.find('input').get(ictr));
    }

    

    for (ictr = 0; ictr < arRadio.length; ictr++) {
        var tempRadio = arRadio[ictr];
        if (tempRadio.checked) {
            switch (tempRadio.value) {
                case 'paypal':
                    //case 'candb':   
                    processBuyRentPayPalCB(currency, arPurchaseContentOfferId, totalprice);
                    break;
                case 'topup':
                case 'voucher':
                    voucherContentId = arVoucher[tempRadio.id];
                    processBuyRentVouchers(currency, arPurchaseContentOfferId, voucherContentId, totalprice);
                    break;
            }
        }
    }
}


//********************************handleBuyRentProcess End*********************//

//********************************validateVouchers Start***********************//
function validateVouchers(totalprice) {
    var arRadio = new Array();
    var container_first = $('.radio-checkbox');
    var container_second = $('.voucher-checkboxes');
    var dv_error_msg;
    if ((document.getElementById('moviePreviewPanel').style.display == 'none') || (document.getElementById('moviePreviewPanel').style.display == '')) {
        dv_error_msg = $('#dv_error_msg_detail');
    }
    else if ((document.getElementById('movieDetailPanel').style.display == 'none') || (document.getElementById('movieDetailPanel').style.display == '')) {
        dv_error_msg = $('#dv_error_msg_preview');
    }

    var first_radios = container_first.find('input');
    for (var ictr = 0; ictr < first_radios.length; ictr++) {
        if (first_radios[ictr].type == 'radio')
            arRadio.push(first_radios[ictr]);
    }
    var second_radios = container_second.find('input');
    for (ictr = 0; ictr < second_radios.length; ictr++) {
        if (second_radios[ictr].type == 'radio')
            arRadio.push(second_radios[ictr]);
    }
    for (ictr = 0; ictr < arRadio.length; ictr++) {
        var tempRadio = arRadio[ictr];
        var radioParentChildren = '';
        if (tempRadio.checked) {
            var tempval;
            switch (tempRadio.value) {
                case 'topup':
                    radioParentChildren = tempRadio.parentNode.childNodes;
                    for (i = 0; i < radioParentChildren.length; i++) {
                        if (radioParentChildren[i].id == "span-topupamount") {
                            //Changed - As getting the price value through tag title attribute
                            tempval = radioParentChildren[i].title;
                            break;
                        }
                    }

                    //Changed - As getting the price value through tag title attribute
                    if (parseFloat(tempval) < totalprice) {
                        dv_error_msg.html(varVoucherAmount);
                        $('.radio-checkbox').hide();
                        $('.voucher-checkboxes').hide();
                        $('#dv_terms_detail').hide();
                        dv_error_msg.attr('class', 'overlay');
                        dv_error_msg.animate({ top: "0px" }, 2000).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(3500);
                        window.setTimeout(showBox, '5500');
                        //$('.radio-checkbox').show();
                        //$('.voucher-checkboxes').show();
                        //$('#dv_terms_detail').show();
                        return false;
                    }
                    break;
                case 'voucher':
                    radioParentChildren = tempRadio.parentNode.childNodes;
                    for (i = 0; i < radioParentChildren.length; i++) {
                        if (radioParentChildren[i].id == "voucher-valuewithcurrency") {
                            //Changed - As getting the price value through tag title attribute
                            tempval = radioParentChildren[i].title;
                            break;
                        }
                    }

                    if (tempval != '') {                        
                        //Changed - As comparing the price value with only interger value of button
                        if (parseFloat(tempval) < totalprice) {
                            dv_error_msg.html(varVoucherAmount);
                            $('.radio-checkbox').hide();
                            $('.voucher-checkboxes').hide();
                            $('#dv_terms_detail').hide();
                            dv_error_msg.attr('class', 'overlay');
                            dv_error_msg.animate({ top: "0px" }, 2000).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(3500);
                            window.setTimeout(showBox, '5500');
                            //$('.radio-checkbox').show();
                            //$('.voucher-checkboxes').show();
                            //$('#dv_terms_detail').show();
                            return false;
                        }
                    }
                    break;
            }
        }
    }
    return true;
}
//********************************validateVouchers End*************************//

//********************************processBuyRentPayPal Start*********************//
function processBuyRentPayPalCB(currency, offerid, totalprice) {
    $.get('EditCart.aspx?currency=' + currency + '&catalog=A&offerId=' + offerid + '&action=add&resetcart=true',
{},
	function (res) {
	    window.location.href = 'PaymentPP.aspx?currency=' + currency + '&catalog=A&totalprice=' + totalprice;
	}
 );
}
//********************************processBuyRentPayPal End*********************//


//********************************processBuyRentVouchers Start***************//
function processBuyRentVouchers(currency, offerId, voucherid, totalprice) {
    $.get('EditCart.aspx?currency=' + currency + '&catalog=A&offerId=' + offerId + '&action=add&resetcart=true',
{},
	function (res) {
	    window.location.href = 'PaymentVoucher.aspx?currency=' + currency + '&catalog=A&totalprice=' + totalprice + '&voucherId=' + voucherid;
	}
 );
}
//********************************processBuyRentVouchers End*****************//

// ##################### OFFER HELPER ###################

function getYourVouchersOnLink() {
    var flagIf = false;
    var flagElse = false;
    i = 0;
    var total_balance = 0;
    $(".voucher_exmp_boxLink table").empty();
    var mycurrency = "";
    if (varxml == null) {
        $.ajax({
            type: "POST",
            async: false,
            url: "GetUserVouchers.aspx?filterByCurrency=true",
            dataType: "xml",
            data: { allvouchers: 1 },
            success: function (xml) {
                varxml = xml;
                mycurrency = $(xml).find('UserPaymentMethods').attr('currency');
                if (mycurrency == undefined)
                    mycurrency = "GBP";
                $(xml).find('voucher').each(function () {
                    var contentId = $(this).find('contentId').text();
                    var currency = $(this).find('currency').text();
                    var expirationDate = $(this).find('expirationDate').text();
                    var expirationDateFormated = new Date(expirationDate).format(DEFAULT_DATE_FORMAT)
                    var reference = $(this).find('reference').text();
                    var value = $(this).find('value').text();
                    var isTopUp = $(this).find('is_topup').text();
                    // convert to number
                    value = parseFloat(value) ? parseFloat(value).toFixed(2) : "0.00";
                    var state = $(this).find('state').text();
                    var type = $(this).find('type').text();
                    if (type == "") { type = "ALL"; }

                    value = value.replace(",", ".");
                    if (state == "new") {
                        total_balance += parseFloat(value);
                    }


                    if (isTopUp.toLowerCase() != 'true') {
                        if (flagIf != true) {
                            $(".voucher_exmp_boxLink table").append("<tr class='" + state.toLowerCase() + " " + type.toUpperCase() + "'><th>" + varVoucher_amount + " </th><th>" + varVoucher_expires + " </th><th>" + varVoucher_Type + " </th></tr>");
                            flagIf = true;
                        }
                        $(".voucher_exmp_boxLink table").append("<tr class='" + state.toLowerCase() + " " + type.toUpperCase() + "'><td>" + convertToCurrencySymbol(currency, value) + " </td><td>" + expirationDateFormated + " </td><td>" + type + " </td></tr>");
                        //$(".voucher_exmp_box table").append("<tr class='" + state.toLowerCase() + " " + type.toUpperCase() + "'><td>" + varVoucher_voucher + " " + convertToCurrencySymbol(currency, value) + "</td><td>" + varVoucher_expires + " " + expirationDateFormated + "</td><td>" + varVoucher_Type  + " " + type + "</td></tr>");
                    } else {
                        //$(".voucher_exmp_box table").append("<tr class='" + state.toLowerCase() + " " + type.toUpperCase() + "'><td>" + varVoucher_myTopUpCredit + " " + convertToCurrencySymbol(currency, value) + "</td><td>" + varVoucher_expires + " " + expirationDateFormated + "</td><td>" + varVoucher_Type  + " " + type + "</td></tr>");
                        if (flagElse != true) {
                            $(".voucher_exmp_boxLink table").append("<tr class='" + state.toLowerCase() + " " + type.toUpperCase() + "'><th>" + varVoucher_myTopUpCredit + " </th><th>" + varVoucher_expires + " </th><th>" + varVoucher_Type + " </th></tr>");
                            flagElse = true;
                        }
                        $(".voucher_exmp_boxLink table").append("<tr class='" + state.toLowerCase() + " " + type.toUpperCase() + "'><td>" + convertToCurrencySymbol(currency, value) + " </td><td>" + expirationDateFormated + " </td><td>" + type + " </td></tr>");
                    }
                    i = i + 1;
                });

            }
        });
    }
    else {
                mycurrency = $(varxml).find('UserPaymentMethods').attr('currency');
                if (mycurrency == undefined)
                    mycurrency = "GBP";
                $(varxml).find('voucher').each(function () {
                    var contentId = $(this).find('contentId').text();
                    var currency = $(this).find('currency').text();
                    var expirationDate = $(this).find('expirationDate').text();
                    var expirationDateFormated = new Date(expirationDate).format(DEFAULT_DATE_FORMAT)
                    var reference = $(this).find('reference').text();
                    var value = $(this).find('value').text();
                    var isTopUp = $(this).find('is_topup').text();
                    // convert to number
                    value = parseFloat(value) ? parseFloat(value).toFixed(2) : "0.00";
                    var state = $(this).find('state').text();
                    var type = $(this).find('type').text();
                    if (type == "") { type = "ALL"; }

                    value = value.replace(",", ".");
                    if (state == "new") {
                        total_balance += parseFloat(value);
                    }


                    if (isTopUp.toLowerCase() != 'true') {
                        if (flagIf != true) {
                            $(".voucher_exmp_boxLink table").append("<tr class='" + state.toLowerCase() + " " + type.toUpperCase() + "'><th>" + varVoucher_amount + " </th><th>" + varVoucher_expires + " </th><th>" + varVoucher_Type + " </th></tr>");
                            flagIf = true;
                        }
                        $(".voucher_exmp_boxLink table").append("<tr class='" + state.toLowerCase() + " " + type.toUpperCase() + "'><td>" + convertToCurrencySymbol(currency, value) + " </td><td>" + expirationDateFormated + " </td><td>" + type + " </td></tr>");
                        //$(".voucher_exmp_box table").append("<tr class='" + state.toLowerCase() + " " + type.toUpperCase() + "'><td>" + varVoucher_voucher + " " + convertToCurrencySymbol(currency, value) + "</td><td>" + varVoucher_expires + " " + expirationDateFormated + "</td><td>" + varVoucher_Type  + " " + type + "</td></tr>");
                    } else {
                        //$(".voucher_exmp_box table").append("<tr class='" + state.toLowerCase() + " " + type.toUpperCase() + "'><td>" + varVoucher_myTopUpCredit + " " + convertToCurrencySymbol(currency, value) + "</td><td>" + varVoucher_expires + " " + expirationDateFormated + "</td><td>" + varVoucher_Type  + " " + type + "</td></tr>");
                        if (flagElse != true) {
                            $(".voucher_exmp_boxLink table").append("<tr class='" + state.toLowerCase() + " " + type.toUpperCase() + "'><th>" + varVoucher_myTopUpCredit + " </th><th>" + varVoucher_expires + " </th><th>" + varVoucher_Type + " </th></tr>");
                            flagElse = true;
                        }
                        $(".voucher_exmp_boxLink table").append("<tr class='" + state.toLowerCase() + " " + type.toUpperCase() + "'><td>" + convertToCurrencySymbol(currency, value) + " </td><td>" + expirationDateFormated + " </td><td>" + type + " </td></tr>");
                    }
                    i = i + 1;
                });

            }
    }


/*Fix for sorting not working in my movies page*/
function getQuerystring(key, default_) {
    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return default_;
    else
        return qs[1];
}
/*Fix for issue#AT-735 done on April 22, 2011*/
function setColorPreviousNext(current) {
    current.style.color = '#f2b514';
    if (previousLink) {
        previousLink.style.color = '#fff';
    }
}
/*Fix for issue#AT-735 done on April 22, 2011*/
function setMouseoutForHover(current, previous) {
    if (!previous) {
        current.style.color = '#fff';
    }
    else if (current.innerHTML != previous.innerHTML) {
        current.style.color = '#f2b514';
        previous.style.color = '#fff';
    }
    previousLink = current;
}
/*Fix for issue#AT-728 done on April 22, 2011*/
function setCategoryItemsCount(count, contentId) {
    switch (contentId) {
        //new releases      
        case 'NewRelease':
            naCount = count;
            break;
        //top 10      
        case 'Top10':
            ttCount = count;
            break;
        //recently added      
        case 'RecentlyAdded':
            raCount = count;
            break;

        case 'Highlight':
            hlCount = count;
            break;
    }
}

/*Creating circular scroller icons at runtime*/
function setCircularScrollers(movies_count, scrlid) {
    var cntr = Math.ceil(movies_count / 6);
    var classPrefix = '';
    var idPrefix = '';
    var li;
    var a;
    switch (scrlid) {
        case 'scrl_newrelease':
            classPrefix = 'new-releases-';
            break;
        case 'scrl_recentlyadded':
            classPrefix = 'recently-added-';
            break;
        case 'scrl_top10':
            classPrefix = 'top-10-'
            break;
        case 'scrl_highlight':
            classPrefix = 'highlight-';
            break;
    }
    for (var ictr = 0; ictr < cntr; ictr++) {
        li = $('<li/>');
        a = $('<a/>');
        $(a).attr('href', '#');
        $(a).addClass(classPrefix + (ictr + 1));
        if (ictr == 0)
            $(a).html('<img src="' + varImagePath + '/img/scroll-icon-on.png"/>');
        else
            $(a).html('<img src="'+varImagePath+'/img/scroll-icon.png"/>');
        $(li).append(a);
        $('#' + scrlid).append(li);
    }
    setSelectors(cntr, scrlid, movies_count);
}

function setSelectors(cntr, scrlid, item_count) {
    var jctr = 0;
    var ictr = 0;
    var divide_factor = item_count < 6 ? item_count : 6;
    var total_count = cntr * divide_factor;
    var selectorPrefix = '.';
    switch (scrlid) {
        case 'scrl_newrelease':
            selectorPrefix = selectorPrefix + 'new-releases-';
            for (ictr = 0; ictr < total_count; ictr++) {
                if (ictr == 0) {
                    jctr = jctr + 1;
                    arSelectors_NR.push(selectorPrefix + jctr);
                }
                else if (ictr % divide_factor == 0) {
                    jctr = jctr + 1;
                    arSelectors_NR.push(selectorPrefix + jctr);
                }
                else {
                    arSelectors_NR.push("");
                }
            }
            break;
        case 'scrl_recentlyadded':
            selectorPrefix = selectorPrefix + 'recently-added-';
            for (ictr = 0; ictr < total_count; ictr++) {
                if (ictr == 0) {
                    jctr = jctr + 1;
                    arSelectors_RA.push(selectorPrefix + jctr);
                }
                else if (ictr % divide_factor == 0) {
                    jctr = jctr + 1;
                    arSelectors_RA.push(selectorPrefix + jctr);
                }
                else {
                    arSelectors_RA.push("");
                }
            }
            break;
        case 'scrl_top10':
            selectorPrefix = selectorPrefix + 'top-10-';
            for (ictr = 0; ictr < total_count; ictr++) {
                if (ictr == 0) {
                    jctr = jctr + 1;
                    arSelectors_TT.push(selectorPrefix + jctr);
                }
                else if (ictr % divide_factor == 0) {
                    jctr = jctr + 1;
                    arSelectors_TT.push(selectorPrefix + jctr);
                }
                else {
                    arSelectors_TT.push("");
                }
            }
            break;

        case 'scrl_highlight':
            selectorPrefix = '#' + 'anch_highlight_';
            for (ictr = 0; ictr < total_count; ictr++) {
                if (ictr == 0) {
                    jctr = jctr + 1;
                    arSelectors_HL.push(selectorPrefix + jctr);
                }
                else if (ictr % divide_factor == 0) {
                    jctr = jctr + 1;
                    arSelectors_HL.push(selectorPrefix + jctr);
                }
                else {
                    arSelectors_HL.push("");
                }
            }
            break;
    }
}
/*Creating circular scroller icons at runtime*/
