
function checkout_bind() {

    if ($('.personalValidationSummaryStyle').children().length != 0) {
        $(window).scrollTop(0);
    }

    if ($('input.chemSideTip').length != 0) {

        // hide/display the correct panels on load

        if ($('.displayPersonalDetailsInput').val() == 'False') {
            $('.personalDetailsPanel').hide();
        } else {
            $('.personalDetailsPanel').show();
        }

        if ($('.displayBankDetailsInput').val() == 'False') {
            $('.bankDetailsPanel').hide();
        } else {
            $('.bankDetailsPanel').show();
        }

        $('.remove').remove();

        $('.checkoutPanel').each(function (i) {
            $('div.info_icon_holder div.chemSideTip').each(function (i) {
                var data = $(this);
                var ref = 'ref_' + i;
                data.attr('tip_ref', ref);
                $(this).replaceWith('<span class="tip-trigger" trigger-ref="' + ref + '"></span>');
                data.addClass('remove');
                $('body').prepend(data);
            });
        });

        tip_init();
        checkout_expand();
        tip_error_switch();
        progress_switch();

    }
}

function progress_switch() {

    var progress_bar = $('.checkoutProgress ol');

    if ($('.checkout_complete_tick').is(':visible')) {
        $('li:eq(1)').attr('class', 'prev');
        $('li:eq(2)').attr('class', 'current');

    } else {

        $('li:eq(1)').attr('class', 'current');
        $('li:eq(2)').attr('class', 'next');

    }

}

function tip_error_switch() {

    $('.col label').each(function () {

        var el = $(this);
        var tip_trigger_relation = $('.tip-trigger', el.parents('div.col:eq(0)'));
        var tip_relation = $('div[tip_ref=' + tip_trigger_relation.attr('trigger-ref') + ']');

        if (el.hasClass('errorLabel')) {
            tip_relation.addClass('error');
        } else {
            tip_relation.removeClass('error');
        }

    });

}

function tip_init() {

    // foreach element requiring the tooltip, find out its position and work out where it is to be displayed
    // ( it works out the custom selectbox slightly differently )

    if ($('.checkoutPanel :visible').length != 0) {

        // create a trigger placeholder for the tool tip, and then move the tooltip to the body

        $('a.chemSideTip').each(function (i) {

            var el = $(this);
            var offset;
            var parent;
            var sideOffest = $('.checkoutPanel :visible:first').offset();
            var sideOffsetLeft = sideOffest.left;
            var related_ref;
            var related;
            var top;

            if (el.get(0).tagName.toLowerCase() == 'select') {
                parent = el.parent();
                offset = parent.offset();
            } else {
                offset = el.offset();
            }

            related_ref = $('span.tip-trigger', el.parents('.info_icon_holder:eq(0)')).attr('trigger-ref');
            related = $('div[tip_ref=' + related_ref + ']');

            top = (Number(Number(offset.top) + 30) - Number(related.height()));

            related
                .css({ 'top': top + 'px', 'left': Number(sideOffsetLeft + 60) + 'px' })
                .hide();

            var timer;
            el.bind('click', function () {
                clearTimeout(timer);
                timer = setTimeout(
                function () {
                    if ($.browser.msie && Number($.browser.version.substr(0, 1)) < 9) {
                        related.hide();
                    } else {
                        related.fadeOut(1000);
                    }
                }, 4000);
                related.show();
                return false;
            });

        });

    }

    // if there are some that are not yet loaded into the page ( like displayed on an event ) hide them

    $('div.chemSideTip').hide();

}

function checkout_expand() {

    // allow the correct panels to be opened and closed.
    // open - the current panel to be open from load0000000000000
    // complete - the panel that has previously been verified and completed
    // denied - not yet verified and not alowed to be opened

    $('.checkoutPanelHeader').live('click', function () {

        var el = $(this).next();
        if (!el.hasClass('denied')) {
            if (!el.next().next().hasClass('denied') && (el.next().next().hasClass('checkoutPanel') || el.prev().prev().hasClass('checkoutPanel'))) {
                if (el.hasClass('complete')) {
                    if (el.is(':visible')) {
                        el.slideUp(800, function () {
                            $('.checkout_drop_arrow', el.next()).attr('src', 'images/layout/checkout_drop_arrow2.png');
                            $('.checkout_drop_arrow', el.prev()).attr('src', 'images/layout/checkout_drop_arrow.png');
                            el.next().next().slideDown(800, function () {
                                tip_init();
                            });
                        });
                    } else {
                        $('.checkout_drop_arrow', el.next()).attr('src', 'images/layout/checkout_drop_arrow.png');
                        $('.checkout_drop_arrow', el.prev()).attr('src', 'images/layout/checkout_drop_arrow2.png');
                        el.slideDown(800, function () {
                            tip_init();
                            el.next().next().slideUp(300);
                        });
                    }
                } else if (el.hasClass('open')) {
                    if (el.is(':visible')) {
                        $('.checkout_drop_arrow', el.prev().prev().prev()).attr('src', 'images/layout/checkout_drop_arrow2.png');
                        $('.checkout_drop_arrow', el.prev()).attr('src', 'images/layout/checkout_drop_arrow.png');
                        el.slideUp(800, function () {
                            el.prev().prev().slideDown(800, function () {
                                tip_init();
                            });
                        });
                    } else {
                        $('.checkout_drop_arrow', el.prev().prev().prev()).attr('src', 'images/layout/checkout_drop_arrow.png');
                        $('.checkout_drop_arrow', el.prev()).attr('src', 'images/layout/checkout_drop_arrow2.png');
                        el.slideDown(800, function () {
                            tip_init();
                            el.prev().prev().slideUp(300);
                        });
                    }
                }
            }
        }
        return false;
    });
}

function maskbody() {
    $('#serviceDetail').mask('<img src="../../images/layout/dealBuilder/ajax-loader.gif" width="32" height="32" alt="loading" style="position:relative;z-index:9999999999999;" />');
}


// For IE 7 z-indexing problems, another overlay is added so the master overlay needs to be removed only on this page.
function overlay_manip() {
    if ($.browser.msie && $.browser.version.substr(0, 1) == '7') {
        if ($('.overlayCount').length > 1) {
            $('.overlayCount:eq(0)').remove();
        }
    } else if ($.browser.msie && $.browser.version.substr(0, 1) == '6') {
        if ($('.overlayCount').length > 1) {
            $('.overlayCount:eq(0)').remove();
        }
        var offset = $('#pageContainer').offset();
        $('.overlayCount').css({ 'left': '-' + offset.left + 'px' });
    }
}

$(document).ready(function () {

    $('.newRow, .newGenericOuter').each(function () {
        var r = $(this);
        var m = 0;
        var mbw = 0;
        $('.box-module, .newGenericModule', r).each(function () {
            var bb = Number($(this).css('border-bottom-width').replace('px', '')) + Number($(this).css('border-top-width').replace('px', ''));
            //var pb = ($(this).css('padding-bottom').replace('px', ''));
            // var h = ($(this).height() - pb);
            var h = ($(this).height());
            if (h > m) {
                m = h;
            }
            if (bb > mbw) {
                mbw = bb;
            }
        });
        $('.box-module, .newGenericModule', r).each(function () {
            var bt = Number($(this).css('border-bottom-width').replace('px', '')) + Number($(this).css('border-top-width').replace('px', ''));
            var bc = mbw - bt;
            if ($(this).hasClass('newGenericModule')) {
                $(this).height(Number(m) + Number(bc) + 4);
            } else {
                $(this).height(Number(m) + Number(bc));
            }
        });
    });

    /* This is for the lightboxes on the deal info page */
    $('.lightboxesNoJS').removeClass('lightboxesNoJS'); //remove class so lightboxes are hidden    
    $('#dealInfoLightboxes').appendTo('body'); //move lightbox elements to directly inside body so that they overlay correctly

    //Add to basket lightbox fix
    $('.lightbox4').appendTo('body'); //move lightbox elements to directly inside body so that they overlay correctly
    //lightbox error fix
    $('.lightboxError').appendTo('body'); //move lightbox elements to directly inside body so that they overlay correctly
    //basket update fix
    $('.lightboxUpdatingBasket').appendTo('body'); //move lightbox elements to directly inside body so that they overlay correctly

    //addClass to change css on rollovers
    $(".buttonContainer").addClass('js');

    $('.buttonContainer a').each(function () {
        var linkHasFocus = false;

        $(this).hover(function () {
            var $buttonElements = $(this).closest(".buttonContainer").children();
            jQuery.each($buttonElements, function () {
                if ($.browser.msie) {
                    $(this).css("background-position-y", "-28px");
                }
                else {
                    var position = $(this).css("background-position").replace("px 0px", "px -28px");
                    $(this).css("background-position", position);
                }
            });
        },
        function () {
            if (!linkHasFocus) {
                var $buttonElements = $(this).closest(".buttonContainer").children();
                jQuery.each($buttonElements, function () {
                    if ($.browser.msie) {
                        $(this).css("background-position-y", "0px");
                    }
                    else {
                        var position = $(this).css("background-position").replace("px -28px", "px 0px");
                        $(this).css("background-position", position);
                    }
                });
            }
        });

        $(this).focus(function () {
            var $buttonElements = $(this).closest(".buttonContainer").children();
            jQuery.each($buttonElements, function () {
                if ($.browser.msie) {
                    $(this).css("background-position-y", "-56px");
                }
                else {
                    var position = $(this).css("background-position").replace("px 0px", "px -56px");
                    position = position.replace("px -28px", "px -56px");
                    $(this).css("background-position", position);
                }
            });
            linkHasFocus = true;
            return false;
        }
	    );

        $(this).blur(function () {
            var $buttonElements = $(this).closest(".buttonContainer").children();
            jQuery.each($buttonElements, function () {
                if ($.browser.msie) {
                    $(this).css("background-position-y", "0px");
                }
                else {
                    var position = $(this).css("background-position").replace("px -56px", "px 0px");
                    position = position.replace("px -28px", "px 0px");
                    $(this).css("background-position", position);
                }
            });
            linkHasFocus = false;
        }
	    );


        $(this).click(function () {
            var $buttonElements = $(this).closest(".buttonContainer").children();
            jQuery.each($buttonElements, function () {
                if ($.browser.msie) {
                    $(this).css("background-position-y", "-56px");
                }
                else {
                    var position = $(this).css("background-position").replace("px -28px", "px -56px");
                    $(this).css("background-position", position);
                }
            });
            $(this).blur();
        }
	    );


    });





    $('#Local').click(function () {
        //$('#q').removeClass('fullSearchBar').addClass('halfSearchBarLeft').attr('value','What for');
        //$('#near').removeClass('access').addClass('halfSearchBar').attr('value','Where');
        $('#q').removeClass('fullSearchBar').addClass('halfSearchBarLeft');
        $('#near').removeClass('access').addClass('halfSearchBar');
    });

    $('#Web, #UK').click(function () {
        //$('#q').addClass('fullSearchBar').removeClass('halfSearchBarLeft').attr('value','');
        //$('#near').addClass('access').removeClass('halfSearchBar').attr('value','');
        $('#q').addClass('fullSearchBar').removeClass('halfSearchBarLeft');
        $('#near').addClass('access').removeClass('halfSearchBar');
    });

    $('.promptText').focus(function () {
        if (($(this).val()) == ($(this).attr("title"))) {
            $(this).css("color", "#555555");
            $(this).attr('value', '');
        }
    });
    $('.promptText').blur(function () {
        if (($(this).attr('value')) == '') {
            $(this).css("color", "#cccccc");
            $(this).attr('value', $(this).attr("title"));
        }
    });


    /*$('#q').focus(function()
    {
    if( ($(this).attr('value'))=='What for')
    {
    $(this).css("color","#555555");
    $(this).attr('value','');
    }
    });
    $('#q').blur(function()
    {
    if( ($(this).attr('value'))=='')
    {
    $(this).css("color","#cccccc");
    $(this).attr('value','What for');
    }
    });
    $('#near').focus(function()
    {
    if( ($(this).attr('value'))=='Where')
    {
    $(this).css("color","#555555");
    $(this).attr('value','');
    }
    });
    $('#near').blur(function()
    {
    if( ($(this).attr('value'))=='')
    {
    $(this).css("color","#cccccc");
    $(this).attr('value','Where');
    }
    });*/

    $(".bigbuttonContainer").addClass('js');

    $('.bigbuttonContainer a').each(function () {
        var linkHasFocus = false;

        $(this).hover(function () {
            var $buttonElements = $(this).closest(".bigbuttonContainer").children();
            jQuery.each($buttonElements, function () {
                if ($.browser.msie) {
                    $(this).css("background-position-y", "-50px");
                }
                else {
                    var position = $(this).css("background-position").replace("px 0px", "px -50px");
                    $(this).css("background-position", position);
                }
            });
        },
        function () {
            if (!linkHasFocus) {
                var $buttonElements = $(this).closest(".bigbuttonContainer").children();
                jQuery.each($buttonElements, function () {
                    if ($.browser.msie) {
                        $(this).css("background-position-y", "0px");
                    }
                    else {
                        var position = $(this).css("background-position").replace("px -50px", "px 0px");
                        $(this).css("background-position", position);
                    }
                });
            }
        });

        $(this).focus(function () {
            var $buttonElements = $(this).closest(".bigbuttonContainer").children();
            jQuery.each($buttonElements, function () {
                if ($.browser.msie) {
                    $(this).css("background-position-y", "-100px");
                }
                else {
                    var position = $(this).css("background-position").replace("px 0px", "px -100px");
                    position = position.replace("px -50px", "px -100px");
                    $(this).css("background-position", position);
                }
            });
            linkHasFocus = true;
        }
	    );

        $(this).blur(function () {
            var $buttonElements = $(this).closest(".bigbuttonContainer").children();
            jQuery.each($buttonElements, function () {
                if ($.browser.msie) {
                    $(this).css("background-position-y", "0px");
                }
                else {
                    var position = $(this).css("background-position").replace("px -100px", "px 0px");
                    position = position.replace("px -50px", "px 0px");
                    $(this).css("background-position", position);
                }
            });
            linkHasFocus = false;
        }
	    );


        $(this).click(function () {
            var $buttonElements = $(this).closest(".bigbuttonContainer").children();
            jQuery.each($buttonElements, function () {
                if ($.browser.msie) {
                    $(this).css("background-position-y", "-100px");
                }
                else {
                    var position = $(this).css("background-position").replace("px -50px", "px -100px");
                    $(this).css("background-position", position);
                }
            });
        }
	    );
    });

    $("input.rollover").hover(
		function () {
		    var $imageName = $(this).attr("src");
		    $(this).attr("src", $imageName.replace("_click", ""));
		    $(this).attr("src", $imageName.replace(".jpg", "_roll.jpg"));
		},
		function () {
		    var $imageName = $(this).attr("src");
		    $(this).attr("src", $imageName.replace("_click", ""));
		    $(this).attr("src", $imageName.replace("_roll", ""));
		}
	);
    $("input.rollover").focus(
		function () {
		    var $imageName = $(this).attr("src");
		    $imageName = $imageName.replace("_roll", "");
		    $(this).attr("src", $imageName.replace(".jpg", "_click.jpg"));
		    $(this).blur();
		}
	);
    // for Safari only
    $("input.rollover").click(
		function () {
		    if ($.browser.safari) {
		        var $imageName = $(this).attr("src");
		        $imageName = $imageName.replace("_roll", "");
		        $(this).attr("src", $imageName.replace(".jpg", "_click.jpg"));
		    }
		}
	);

    $("input.rollover").blur(
		function () {
		    var $imageName = $(this).attr("src");
		    $(this).attr("src", $imageName.replace("_click", ""));
		}
	);

    //toggle the display of the header basket
    ToggleHeaderBasket();

    $('.lightbox .closeLightbox a').click(function () {
        $('.lightbox').hide();
        $('.lightbox .lightboxContent .middle').height('auto');
        $('#overlay').hide();
        return false;
    });

    $('.addToBasket').each(function () {

        $(this).focus(function () {
            $(this).addClass('addToBasketClick');
        }
	    );

        $(this).blur(function () {
            $(this).removeClass('addToBasketClick');
        }
	    );

        $(this).click(function () {
            $(this).addClass('addToBasketClick');
        }
	    );
    });

    $('.checkout_btn').each(function () {

        $(this).focus(function () {
            $(this).addClass('checkout_btnClick');
        }
	    );

        $(this).blur(function () {
            $(this).removeClass('checkout_btnClick');
        }
	    );

        $(this).click(function () {
            $(this).addClass('checkout_btnClick');
        }
	    );
    });

    $('.addBtn').each(function () {

        $(this).focus(function () {
            $(this).addClass('addBtnClick');
        }
	    );

        $(this).blur(function () {
            $(this).removeClass('addBtnClick');
        }
	    );

        $(this).click(function () {
            $(this).addClass('addBtnClick');
        }
	    );
    });

    $('.checkOutBtn').each(function () {

        $(this).focus(function () {
            $(this).addClass('checkOutBtnClick');
        }
	    );

        $(this).blur(function () {
            $(this).removeClass('checkOutBtnClick');
        }
	    );

        $(this).click(function () {
            $(this).addClass('checkOutBtnClick');
        }
	    );
    });

    $('.updateBasket_btn').each(function () {

        $(this).focus(function () {
            $(this).addClass('updateBasket_btnClick');
        }
	    );

        $(this).blur(function () {
            $(this).removeClass('updateBasket_btnClick');
        }
	    );

        $(this).click(function () {
            $(this).addClass('updateBasket_btnClick');
        }
	    );
    });

    /*
    $('.simList').each(function(){
    var $biggerSim = 0;
    $('.sim',this).each(function(){
    if( $(this).height() > $biggerSim )
    {
    $biggerSim = $(this).height()
    }
    });
    $('.sim',this).height($biggerSim);
    });
    
    $('.simrow').each(function(){
    var $biggerSim = 0;
    $('.simInfo',this).each(function(){
    if( $(this).height() > $biggerSim )
    {
    $biggerSim = $(this).height()
    }
    });
    $('.simInfo',this).height($biggerSim);
    });
    
    $('.dealsRow').each(function(){
    var $biggerSim = 0;
    $('.info',this).each(function(){
    if( $(this).height() > $biggerSim )
    {
    $biggerSim = $(this).height()
    }
    });
    $('.info',this).height($biggerSim);
    });
    
    $('.largeTabbedContent').each(function(){
    var $biggerSim = 0;
    $('.info',this).each(function(){
    if( $(this).height() > $biggerSim )
    {
    $biggerSim = $(this).height()
    }
    });
    $('.info',this).height($biggerSim);
    });

    */

    /*
    // Item Detail page lightboxes
    $('.handsetPanel .buttonContainer a').attr("href","javascript:void(0);");
    $('.handsetPanel,.handsetPanel .buttonContainer a').click(function()
    {
    showLightBox('lightbox1',469);
    return false;
    });
    $('.tariffPanel .buttonContainer a').attr("href","javascript:void(0);");
    $('.tariffPanel,.tariffPanel .buttonContainer a').click(function()
    {
    showLightBox('lightbox2',469);
    return false;
    });
    $('.giftPanel .buttonContainer a').attr("href","javascript:void(0);");
    $('.giftPanel,.giftPanel .buttonContainer a').click(function()
    {
    if ($(".giftPanel .nogift").length < 1) {
    showLightBox('lightbox3',469);
    return false;
    }
    });
    */

    /* calling card scripting */


    $('#CChomepageCarousel').before('<div class="CCheaderContainer"></div>');

    $('#CChomepageCarousel .header').each(function () {
        $(this).appendTo('.CCheaderContainer');
    });

    $('.callchargecalculator').addClass('calculatordisplay');

    function DisplayCallRates(selectedValue) {
        var landlineRateSelector = '#' + selectedValue + "-L";
        var mobileRateSelector = '#' + selectedValue + "-M";
        var ukTextSelector = '#' + selectedValue;

        $('.landlinerate p:visible').hide();
        $('.mobilerate p:visible').hide();
        $('.uktext p:visible').hide();

        $(landlineRateSelector).show();
        $(mobileRateSelector).show();
        $(ukTextSelector).show();
    }

    $('.landlinerate').children('p').each(
        function () {
            $(this).hide();
        }
    );

    $('.mobilerate').children('p').each(
        function () {
            $(this).hide();
        }
    );

    $('.uktext').children('p').each(
        function () {
            $(this).hide();
        }
    );

    $('.countryselector').change(function () {
        DisplayCallRates($('select.countryselector option:selected').val());
    });

    DisplayCallRates($('select.countryselector option:selected').val());

    if ($('#CChomepageCarousel #homepageCarouselFrames').length != 0) {
        $('#CChomepageCarousel #homepageCarouselFrames').cycle({
            timeout: 0,
            speed: 800,

            pause: true,
            fx: 'scrollHorz',
            next: '#homepageCarouselNext',
            prev: '#homepageCarouselPrev',
            easing: 'easeInOutExpo',
            pager: '.CCheaderContainer',
            pagerAnchorBuilder: function (idx, slide) {
                // return selector string for existing anchor 
                return '.CCheaderContainer h2:eq(' + idx + ') a';
            }

        });
    }
    $('.noJS').removeClass('noJS');

    if ($('#CCtoppanel').length != 0) {
        $('#CCtoppanel').cycle({
            timeout: 5000,
            speed: 800,
            slideExpr: '.frame'
        });
    }

    $('#CCminiCarousel').addClass('JS');



    $('.seealldestinations').addClass('donotseealldestinations');



});


/**
/ THIRD FUNCTION
* getPageScroll() by quirksmode.com
*
* @return Array Return an array with x,y page scroll values.
*/
function ___getPageScroll() {
    var xScroll, yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
        xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
        xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
        xScroll = document.body.scrollLeft;
    }
    arrayPageScroll = new Array(xScroll, yScroll);
    return arrayPageScroll;
}

/**
/ THIRD FUNCTION
* getPageSize() by quirksmode.com
*
* @return Array Return an array with page width, height and window width, height
*/
function ___getPageSize() {
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = window.innerWidth + window.scrollMaxX;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        if (document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        } else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }
    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = xScroll;
    } else {
        pageWidth = windowWidth;
    }
    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
    return arrayPageSize;
}

//args - class of lightbox you want to display, width of content in pixels
function showLightBox(lightBoxID, lightboxWidth) {
    //get height of page and how far down user has scrolled
    lightBoxID = '.' + lightBoxID;
    var arrPageSizes = ___getPageSize();
    var arrPageScroll = ___getPageScroll();
    $('#overlay').show();
    // Calculate top offset for the lightbox and center it	
    $(lightBoxID).css({
        top: arrPageScroll[1] + (arrPageSizes[3] / 10),
        width: (46 + lightboxWidth),
        marginLeft: -(46 + lightboxWidth) / 2
    }).show();
    //set the content width
    $(lightBoxID + ' .middle').css({
        width: lightboxWidth
    });
    //calculate height of content and set borders to this size
    var lightboxHeight = $(lightBoxID + ' .lightboxContent .middle').height();
    $(lightBoxID + ' .lightboxContent .left').height(lightboxHeight);
    $(lightBoxID + ' .lightboxContent .middle').height(lightboxHeight);
    $(lightBoxID + ' .lightboxContent .right').height(lightboxHeight);
}

function hideAllLightBoxes() {

    $('.lightbox').hide();
}

function hideLightBox(lightBoxID) {
    var bIsSomeoneElseUsingOverlay = false;
    var currentClass = "";

    //hide lightbox
    lightBoxID = '.' + lightBoxID;
    $(lightBoxID).hide();

    //PK check to see if another lightbox is using our overlay
    $('.lightbox').each(
        function (e) {
            if ($(this).is(':visible') && ($(this).attr("class") != $(lightBoxID).attr("class"))) {
                bIsSomeoneElseUsingOverlay = true;
                return;
            }
        }
    );

    //only hide overlay if no other lightbox is using it
    if (!bIsSomeoneElseUsingOverlay) {
        $('#overlay').hide();
    }
}

function ToggleHeaderBasket() {
    $('#basketToggle').click(function () {
        if ($('#basketFooter').hasClass('open')) {
            $(this).text('View basket');
        }
        else {
            $(this).text('Hide basket');
        }
        $('#basketContent').slideToggle('normal');
        $('#basketFooter').toggleClass('open');
        return false;
    });
}

function ResetForm() {
    var formClientID = $('form').attr('id');

    document.getElementById(formClientID).reset();
}

//Gets the error information passed from the server into a javascript object (see Error500.ascx control for more details)
function AsyncErrorObject(ajaxErrorObject) {
    var errorObject = new Object();

    if (ajaxErrorObject != null) {
        var errorArray = ajaxErrorObject.message.split("::");

        errorObject.ErrorGroup = errorArray[0];
        errorObject.Title = errorArray[1];
        errorObject.Message = errorArray[2];
        errorObject.MessageType = errorArray[3];
    }

    return errorObject;
}

////Sets the error Title and Message with a default error symbol and red text
//function SetFriendlyErrorText(errorTitleSelector, errorTitleText, errorMessageSelector, errorMessageText) {

//    var errorTitle = jQuery(errorTitleSelector);

//    errorTitle.text(errorTitleText);
//    errorTitle.addClass('errorSymbol');
//    errorTitle.addClass('errorTitleText');
//    jQuery(errorMessageSelector).text(errorMessageText);
//}

//Sets the error Title and Message overloaded with errorType to define additional variable to control text and symbol colour.
function SetFriendlyErrorText(errorTitleSelector, errorTitleText, errorType, errorMessageSelector, errorMessageText) {
    
    var lowerCaseErrorType = errorType.toLowerCase();

    var errorTitle = jQuery(errorTitleSelector);

    errorTitle.text(errorTitleText);
    errorTitle.addClass(lowerCaseErrorType + 'Symbol');
    errorTitle.addClass(lowerCaseErrorType + 'TitleText');
    jQuery(errorMessageSelector).text(errorMessageText);
}

var disableRefreshMask = true;
var contentChange = '0';
var t;
var timing = 'false';

function remove_spaces(txtControl) {
    var txtI = '#' + txtControl
    $(txtI).val($(txtI).val().replace(/ /g, ''));
}

function remove_non_numeric_input(txtControl) {
    var txtI = '#' + txtControl
    var inputTxt = $(txtI).val();
    inputTxt = inputTxt.replace(/[^0-9]/g, '');
    $(txtI).val(inputTxt);
}

function HomePhoneValidate(source, arguments) {

    remove_spaces(source.controltovalidate);
    remove_non_numeric_input(source.controltovalidate);

    arguments.IsValid = true;
}

function OpenNewWindow(url) {
    //    var load = window.open(url, '', 'scrollbars=yes,menubar=yes,height=600,width=800,resizable=yes,toolbar=yes,location=yes,status=yes');
    window.open(url, 'mywindow', 'width=800,height=600,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes, resizable=yes');
}

$(document).ready(function () {

    // THIS IS THE ONLY PIECE OF CODED NEEDED FOR HEIGHT ADJUSTMENTS
    // THIS ONLY ALTERS HEIGHTS TO SMALLER CONTAINERS, NOT CAROUSELS
    var maxHeightOfALLSmallContainers = 0;
    $('div[class!=carouselFrames] .newGenericModule').each(function () {
        var curHeight = $(this).height();
        if (curHeight > maxHeightOfALLSmallContainers) {
            maxHeightOfALLSmallContainers = curHeight;
        }
    });
    $('div[class!=carouselFrames] .newGenericModule').css({ 'height': maxHeightOfALLSmallContainers + 'px' });
    // END

    // THIS IS THE ONLY PIECE OF CODE NEEDED FOR MAIN CAROUSEL HEIGHT ADJUSTMENTS
    var maxHeightOfMainCarouselFrames = 0;
    $('.carouselFrame .newDoubleColThin, .carouselFrame .doubleColMainModule, .carouselFrame .newThreeColThin, .carouselFrame .threeColMainModule, .channelModule').each(function () {
        var curHeight = $(this).height();
        if (curHeight > maxHeightOfMainCarouselFrames) {
            maxHeightOfMainCarouselFrames = curHeight;
        }
    });
    $('.carouselFrame .newDoubleColThin, .carouselFrame .doubleColMainModule, .carouselFrame .newThreeColThin, .carouselFrame .threeColMainModule, .channelModule').css({ 'height': maxHeightOfMainCarouselFrames + 'px' });
    // END

    if ($('#form1').attr('action') == 'where-to-buy.aspx') {
        $('#pageContainer').css({ 'background': 'none' });
    }

    if ($('#homeTab a.selected').length != 0) {
        $('.carouselFrames').css({ 'height': '305px' });
    }

    $('.available-networks-new').each(function () {
        var ob = $(this);
        var contents = $('.available-networks-contents', ob.parents('.box-module'));
        var pos = ob.offset();
        var top = Number(pos.top + 20);
        var left = pos.left;
        ob.hover(function () {
            contents.css({ 'top': top + 'px', 'left': left + 'px' });
            $('body').append(contents);
            contents.show();
        }, function () {
            contents.hide();
        });
    });

    $('select').selectBox();

});

function init_dropdowns() {
    $('select').selectBox();

}



