﻿var offers = {
    airporticon: '/images/marker_airport.png',
    offermatch: '/images/market_hotel_exact.png',
    offerclose: '/images/market_hotel.png',
    contentPanelId: null,
    loaderId: null,
    offerType: '', //day, 24plus, residential
    offerRating: '',
    fvd: true, //first view details
    fe: true, //first enquire
    fm: true, //first mail button click
    fmg: true, //first mail go button click
    fs: true, // first search
    viewmode: 'list',
    country: null,

    get_action_viewdetails: function() {
        if (this.fvd == true) {
            this.fvd = false;
            return "FVD";
        } else return "SVD";
    },
    get_action_enquire: function() {
        if (this.fe == true) {
            this.fe = false;
            return "FE";
        } else return "SE";
    },

    get_action_email_click: function() {
        if (this.fm == true) {
            this.fm = false;
            return "FM";
        } else return "SM";
    },

    get_action_mail_submit: function() {
        if (this.fmg == true) {
            this.fmg = false;
            return "FMG";
        } else return "SMG";
    },

    get_action_search: function() {
        if (this.fs == true) {
            this.fs = false;
            return "FS";
        } else return "SS";
    },
    init: function(loaderId, contentPanelId, country, viewmode, offertype, offerrating, max) {
        this.loaderId = loaderId;
        this.contentPanelId = contentPanelId;
        this.country = country;
        this.viewmode = viewmode;
        this.offerType = offertype;
        this.offerRating = offerrating;

        this.maxdelegates = max;
        $('.delegate-range').html("Enter a number between 1 and " + max);

        //        this.airportDistance = def_dist;
        //        this.delegateRate = def_rate;
    },
    arrayContains: function(arr, val) {
        var f = false;
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] == val) {
                f = true;
                break;
            }
        }
        return f;
    },
    arrayRemove: function(arr, val) {
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] == val) {
                arr.splice(i, 1);
                break;
            }
        }
    },
    trackEvent: function(func) {
        try {
            if (pageTracker)
                setTimeout(func, 1000);
        } catch (err) { }
    },
    arrayToString: function(arr, sep) {
        var val = "";
        for (var i = 0; i < arr.length; i++) {
            val += (val.length > 1 ? sep + arr[i] : arr[i]);
        }
        return val;
    },
    selOffType: function(link, val) {
        $(".c_3 a").removeClass("selected");
        $(link).addClass("selected");
        this.offerType = val;
        return false;
    },
    clearRatings: function() {
        for (var i = 0; i < $(".c_4 a img").length; i++) {
            $(".c_4 a img")[i].src = $(".c_4 a img")[i].src.replace('large', 'small');
        }

        $(".c_4 a").removeClass("selected");
        this.offerRating = '';
    },
    hovOutRating: function(link, ratImgId, imgSrc) {
        if (!$(link).hasClass('selected')) {
            $("#" + ratImgId).attr({ src: imgSrc });
        }
    },
    hovRating: function(link, ratImgId, imgSrc) {

        if (!$(link).hasClass('selected')) {
            $("#" + ratImgId).attr({ src: imgSrc });
        }
    },
    selRating: function(link, val, ratImgId, imgSrc) {
        this.clearRatings();
        $("#" + ratImgId).attr({ src: imgSrc.replace('small', 'large') });
        $(link).addClass("selected");
        this.offerRating = val;
        return false;
    },
    offersLoaded: function() {
        $('#' + this.contentPanelId).slideDown();
    },

    /* google map properties and methods */
    mapCenterLat: 53.291489,
    mapCenterLng: -7.800293,
    mapDefaultZoom: 7,
    maxdelegates: 2500,
    map_panel_id: null,
    map_loading_panel_id: null,
    points: [],
    airports: [],
    center: null,
    markersArray: [],

    map: null,
    zoomLevel: 7,
    airportDistance: -1,
    delegateRate: -1,
    currency: 'GBP',
    rate_max: 300,
    dist_max: 100,
    oferdetailspanelId: null, // map view view details panel
    MapInitialize: function() {

        if (this.center == null || (this.center.lat() == 0 && this.center.lng() == 0))
            this.center = new google.maps.LatLng(this.mapCenterLat, this.mapCenterLng);

        var myOptions = {
            zoom: this.mapDefaultZoom,
            center: this.center,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };

        var infowindow = new google.maps.InfoWindow();
        map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

        //display airports
        if (this.airports != null) {

            for (var i = 0; i < this.airports.length; i++) {
                var airport = this.airports[i];
                var myLatLng = new google.maps.LatLng(airport[1], airport[2]);
                var marker = new google.maps.Marker({
                    position: myLatLng,
                    map: map,
                    title: airport[0],
                    zIndex: -1, //airport[3],
                    icon: this.airporticon
                });

                google.maps.event.addListener(marker, 'click', function() {
                    infowindow.content = "<div style='overflow:hidden'>" + this.title + "</div>";
                    infowindow.open(map, this);
                });

            }
        }

        if (this.points != null)
            this.setMarkers(this.points, null); //default image == null


        var bounds = new google.maps.LatLngBounds(this.center, this.center);
        overlay = new USGSOverlay(bounds, '', map);

    },
    hideMapDetailsPanel: function() {
        $('#' + this.oferdetailspanelId).html('');
        $('#' + this.oferdetailspanelId).hide();
    },
    ViewMapOffer: function(link, offerid, country) {

        var bef = null; //"$('#" + loaderId + "').show();";//show map loader
        var aft = null; //"$('#" + loaderId + "').hide();";//hide map loader
        var onSuccess = "$('#" + this.oferdetailspanelId + "').show();offers.initOfferDetailsEffects();";
        var onClose = "offers.hideMapDetailsPanel();" //"$('#" + this.oferdetailspanelId + "').html(''); $('#" + this.oferdetailspanelId + "').hide();";
        var params = "OfferId=" + offerid + "&country=" + country + "&ContentPanelId=" + this.oferdetailspanelId + "&Mode=map&OnClose=" + onClose + "&OnSuccess=" + onSuccess + "&Featured=false";

        hcAjax.call("/Webservices/Offers.asmx/LoadOfferDetails", params, bef, aft, true);

    },
    initMap: function(map_panel_id, map_loading_panel_id, dist_step, dist_max, rate_step, rate_max, currency, def_dist, def_rate, oferdetailspanelId) {

        this.currency = currency;
        this.map_panel_id = map_panel_id;
        this.map_loading_panel_id = map_loading_panel_id;
        this.airportDistance = def_dist;
        this.delegateRate = def_rate;
        this.oferdetailspanelId = oferdetailspanelId;

        offers.MapInitialize();

        $(".slider-max-miles").html(dist_max + " miles");
        $(".slider-min-miles").html("&lt; 5 miles");

        $("#slider_1").slider({
            animate: true,
            step: dist_step,
            min: 5,
            max: dist_max,
            slide: function(event, ui) {
                $("#slider_1_callback").html("(" + ui.value + " miles)");
            },
            change: function(event, ui) {
                if (ui.value == "0")
                    $("#slider_1_callback").html("");
                else $("#slider_1_callback").html("(" + ui.value + " miles)");
            },
            stop: function(event, ui) {
                $("#slider_1_callback").html("(" + ui.value + " miles)");
                offers.loadByDistanceFromAirport(ui.value);
            }
        });

        if (def_dist && def_dist > 0)
            $("#slider_1").slider("value", def_dist);
        else
            $("#slider_1").slider("value", dist_max);

        $(".slider-max-rate").html((currency == "GBP" ? "&pound;" : "&euro;") + rate_max);
        $(".slider-min-rate").html("&lt; " + (currency == "GBP" ? "&pound;" : "&euro;") + "20");

        $("#slider_2").slider({
            animate: true,
            step: rate_step,
            min: 20,
            max: rate_max,
            slide: function(event, ui) {
                $("#slider_2_callback").html("(" + (currency == "GBP" ? "&pound;" : "&euro;") + ui.value + ")");
            },
            change: function(event, ui) {
                if (ui.value == "0")
                    $("#slider_2_callback").html("");
                else $("#slider_2_callback").html("(" + (currency == "GBP" ? "&pound;" : "&euro;") + ui.value + ")");
            },
            stop: function(event, ui) {
                $("#slider_2_callback").html("(" + (currency == "GBP" ? "&pound;" : "&euro;") + ui.value + ")");
                offers.loadByDelegateRate(ui.value);
            }
        });

        if (def_rate && def_rate > 0)
            $("#slider_2").slider("value", def_rate);
        else
            $("#slider_2").slider("value", rate_max);

    },
    setMarkers: function(locations) {
        for (var i = 0; i < locations.length; i++) {
            this.loadMarker(locations[i]);
        }
    },
    loadMarker: function(markerArray) {
        var myLatLng = new google.maps.LatLng(markerArray[2], markerArray[3]);
        var marker = new google.maps.Marker({
            position: myLatLng,
            map: map,
            id: markerArray[0],
            title: markerArray[1],
            zIndex: markerArray[4]
        });
        this.markersArray.push(marker);

        if (markerArray[5] == 'close')
            marker.icon = this.offerclose;
        else
            marker.icon = this.offermatch;

        marker.html = markerArray[6];

        marker.listener = google.maps.event.addListener(marker, 'click', function() {
            map.setCenter(this.position);
            if (map.getZoom() < 8)
                map.setZoom(8);
            overlay.update(this.position, this.html);
        });

    },
    clearMarkers: function() {
        if (this.markersArray) {
            for (i in this.markersArray) {
                this.markersArray[i].setMap(null);
            }
        }
    },
    clearInfoWindows: function() {
        if (this.markersArray) {
            for (i in this.markersArray) {
                this.markersArray[i].infowindow.close();
            }
        }
    },

    applyMapFilter: function(points, center, zoom) {

        overlay.hide();
        if (points.length == 0) {
            this.clearMarkers();

            map.setCenter(new google.maps.LatLng(this.mapCenterLat, this.mapCenterLng));
            map.setZoom(this.mapDefaultZoom);

        }
        else {

            /// 1. loop through all existing markers
            ///    - show the ones in points(new array to show) and hide those not found
            ///    -- show the rest from points
            var hide = true;
            var point = null;

            for (m in this.markersArray) {

                hide = true;

                for (var i = 0; i < points.length; i++) {

                    point = points[i];

                    if (this.markersArray[m].id == point[0]) {

                        if (this.markersArray[m].map == null || this.markersArray[m].icon != this.offermatch) {
                            this.markersArray[m].setMap(null);

                            if (point[5] == 'close')
                                this.markersArray[m].icon = this.offerclose;
                            else
                                this.markersArray[m].icon = this.offermatch;

                            this.markersArray[m].setMap(map);
                        }


                        /*
                        google.maps.event.removeListener(this.markersArray[m].listener);
                        //this.markersArray[m].removeListener(this.markersArray[m].listener);

                        this.markersArray[m].listener = google.maps.event.addListener(this.markersArray[m], 'click', function() {
                        overlay.update(this.position, point[6]);
                        });
                        */
                        this.markersArray[m].html = point[6];

                        points.splice(i, 1);

                        hide = false;
                        break;
                    }

                }

                if (hide)
                    this.markersArray[m].setMap(null);

            }

            this.setMarkers(points);



            if (center && center.lat() != 0 && center.lng() != 0)
                map.setCenter(center);

            //zoom to correct level
            //setTimeout("map.setZoom(" + zoom + ")", 500);

        }


    },
    /*
    showMarker: function(id) {
    for (m in this.markersArray) {
    if (this.markersArray[m].id == id) {

                if (this.markersArray[m].map == null)
    this.markersArray[m].setMap(map);

                break;
    }
    }
    },*/
    loadByDelegateRate: function(rate) {

        this.delegateRate = rate;
        this.hideMapDetailsPanel();
        //load map coordinates
        var bef = "$('#" + this.map_loading_panel_id + "').show();";
        var aft = "$('#" + this.map_loading_panel_id + "').hide();";

        var onSuccess = '';
        var numPeople = $(".delegatesbox").length > 0 ? $(".delegatesbox")[0].value : -1;
        var params = "DelegateRate=" + this.delegateRate + "&ViewMode=" + this.viewmode + "&NumPeople=" + numPeople + "&OfferType=" + this.offerType + "&OfferRating=" + this.offerRating + "&country=" + this.country + "&AirportDist=" + this.airportDistance + "&ContentPanelId=" + this.contentPanelId + "&OnSuccess=" + onSuccess;
        hcAjax.call("/Webservices/Offers.asmx/GetOffers", params, bef, aft, true);


    },

    //loadByDistanceFromAirportCount: 0,
    loadByDistanceFromAirport: function(distance) {

        //        this.loadByDistanceFromAirportCount++;

        //        $('#' + this.map_loading_panel_id).show();
        //        
        //        $('#' + this.map_loading_panel_id).html("" + this.loadByDistanceFromAirportCount);

        this.airportDistance = distance;

        this.hideMapDetailsPanel();

        //load map coordinates
        var bef = "$('#" + this.map_loading_panel_id + "').show();";
        var aft = "$('#" + this.map_loading_panel_id + "').hide();";

        var onSuccess = '';
        var numPeople = $(".delegatesbox").length > 0 ? $(".delegatesbox")[0].value : -1;
        var params = "DelegateRate=" + this.delegateRate + "&ViewMode=" + this.viewmode + "&NumPeople=" + numPeople + "&OfferType=" + this.offerType + "&OfferRating=" + this.offerRating + "&country=" + this.country + "&AirportDist=" + this.airportDistance + "&ContentPanelId=" + this.contentPanelId + "&OnSuccess=" + onSuccess;
        hcAjax.call("/Webservices/Offers.asmx/GetOffers", params, bef, aft, true);


    },

    /* offers calls */
    ResetFilters: function() {

        this.clearRatings();
        $(".c_3 a").removeClass("selected");

        this.offerType = '';
        if (this.viewmode == 'map') {

            //            $("#slider_1").slider("value", "0");
            //            $("#slider_2").slider("value", "0");

            $("#slider_1").slider("value", this.dist_max);
            $("#slider_2").slider("value", this.rate_max);

            this.hideMapDetailsPanel();

            this.airportDistance = -1;
            this.delegateRate = -1;

            $(".delegatesbox")[0].value = "";

            var bef = "$('#" + this.map_loading_panel_id + "').show();";
            var aft = "$('#" + this.map_loading_panel_id + "').hide();map.setZoom(" + this.mapDefaultZoom + ");";

            var params = "DelegateRate=" + this.delegateRate + "&AirportDist=" + this.airportDistance + "&ViewMode=" + this.viewmode + "&NumPeople=-1&OfferType=" + this.offerType + "&OfferRating=" + this.offerRating + "&country=" + this.country + "&ContentPanelId=" + this.contentPanelId + "&OnSuccess=";
            hcAjax.call("/Webservices/Offers.asmx/GetOffers", params, bef, aft, true);

        }
        else {
            var bef = "$('#" + this.contentPanelId + "').hide();offers.showLoader()";
            var aft = "offers.hideLoader()";
            var onSuccess = "offers.initOffersEffects();offers.offersLoaded();";
            var params = "ContentPanelId=" + this.contentPanelId + "&ViewMode=" + this.viewmode + "&country=" + this.country + "&OnSuccess=" + onSuccess;
            hcAjax.call("/Webservices/Offers.asmx/GetRandomResults", params, bef, aft, true);
        }

        this.trackEvent("pageTracker._trackEvent('" + this.get_action_search() + "', 'Reset filters','" + this.country + "')");
        return false;
    },
    getAllOffers: function() {
        var bef = "$('#" + this.contentPanelId + "').hide();offers.showLoader()";
        var aft = "offers.hideLoader()";
        var onSuccess = "offers.initOffersEffects();offers.offersLoaded();";
        var params = "ContentPanelId=" + this.contentPanelId + "&country=" + this.country + "&OnSuccess=" + onSuccess;
        hcAjax.call("/Webservices/Offers.asmx/GetAllOffers", params, bef, aft, true);
        this.trackEvent("pageTracker._trackEvent('" + this.get_action_search() + "', 'Show all','" + this.country + "')");
        return false;
    },
    applyFilter: function() {

        if (this.viewmode == 'map') {
            //load map coordinates
            var bef = "$('#" + this.map_loading_panel_id + "').show();";
            var aft = "$('#" + this.map_loading_panel_id + "').hide();";

            this.hideMapDetailsPanel();

            var onSuccess = '';
            var numPeople = $(".delegatesbox").length > 0 ? $(".delegatesbox")[0].value : -1;
            var params = "DelegateRate=" + this.delegateRate + "&AirportDist=" + this.airportDistance + "&ViewMode=" + this.viewmode + "&NumPeople=" + numPeople + "&OfferType=" + this.offerType + "&OfferRating=" + this.offerRating + "&country=" + this.country + "&ContentPanelId=" + this.contentPanelId + "&OnSuccess=" + onSuccess;
            hcAjax.call("/Webservices/Offers.asmx/GetOffers", params, bef, aft, true);

        }
        else {

            var bef = "$('#" + this.contentPanelId + "').hide();offers.showLoader()";
            var aft = "offers.hideLoader()"; //$('#" + this.contentPanelId + "').show();
            //        var bef = "document.getElementById('" + this.contentPanelId + "').style.visibility = 'hidden';offers.showLoader();";
            //        var aft = " document.getElementById('" + this.contentPanelId + "').style.visibility = 'visible'; offers.hideLoader()";
            var onSuccess = "offers.initOffersEffects();offers.offersLoaded();";
            var numPeople = ($(".delegatesbox").length > 0 ? $(".delegatesbox")[0].value : -1);
            var params = "DelegateRate=" + this.delegateRate + "&AirportDist=" + this.airportDistance + "&ViewMode=" + this.viewmode + "&NumPeople=" + numPeople + "&OfferType=" + this.offerType + "&OfferRating=" + this.offerRating + "&country=" + this.country + "&ContentPanelId=" + this.contentPanelId + "&OnSuccess=" + onSuccess;
            hcAjax.call("/Webservices/Offers.asmx/GetOffers", params, bef, aft, true);
        }
        //this.trackEvent("pageTracker._trackEvent('" + this.get_action_search() + "', 'Apply filter','| " + this.offerType + " | " + numPeople + " | " + this.offerRating + "'," + numPeople + ")");
        return false;
    },
    initOfferDetailsEffects: function(panelId) {


        $(".viewmaplink").click(function() {
            try {
                return top.fbox(this);
            } catch (err) {
                $.fancybox({
                    'href': this.href,
                    'width': 800,
                    'height': 550,
                    'autoScale': false,
                    'type': 'iframe',
                    'hideOnContentClick': false,
                    'callbackOnClose': function() { $("#fancy_content").empty(); },
                    'overlayOpacity': 0.7,
                    'overlayColor': '#000',
                    'titleShow': false
                });
            }
            return false;
        });

        $(".results .details .c_1 .input_field").focus(function() {
            if ($(this).val() == "email address")
                $(this).val("");
        })

        $(".results .details .c_1 .input_field").blur(function() {
            if ($(this).val() == "")
                $(this).val("email address");
        })


    },

    featuredDetailsLoaded: function(offerpanelId, panelId) {
        $('#' + offerpanelId).parent().hide();
        $('#' + panelId).slideDown();

    },
    closeFeaturedDetails: function(panelId) {
        $('.specials').show();
        $('#' + panelId).hide();
    },
    LoadFeaturedDetails: function(offerDetails, matchType, offerId, panelId, linkId, offerpanelId) {
        if (document.getElementById(panelId).innerHTML.length < 10) {
            var bef = "$('#" + linkId + "').addClass('loading');";
            var aft = "$('#" + linkId + "').removeClass('loading');";
            var onSuccess = "offers.featuredDetailsLoaded('" + offerpanelId + "','" + panelId + "');offers.initOfferDetailsEffects('" + panelId + "');";
            var onClose = "return offers.closeFeaturedDetails('" + panelId + "');";
            var params = "OfferId=" + offerId + "&ContentPanelId=" + panelId + "&country=" + this.country + "&Mode=&OnClose=" + onClose + "&OnSuccess=" + onSuccess;
            params += "&Featured=true";
            hcAjax.call("/Webservices/Offers.asmx/LoadOfferDetails", params, bef, aft, true);
            this.trackEvent("pageTracker._trackEvent('" + this.get_action_viewdetails() + "', 'Featured offer(" + matchType + ")', '" + offerDetails + "')");
        }
        else {
            this.featuredDetailsLoaded(offerpanelId, panelId);
        }
        return false;
    },
    offerDetailsLoaded: function(panelId, teaserPanelId) {
        $('#' + teaserPanelId).hide();
        $('#' + panelId).slideDown();
    },
    closeOfferDetails: function(detailspanelid, teaserpanelid) {
        $('#' + teaserpanelid).slideDown(100, function() { $('#' + detailspanelid).hide(200); });
    },
    LoadOfferDetails: function(teaserPanelId, offerDetails, matchType, offerId, panelId, loaderId) {

        if (document.getElementById(panelId).innerHTML.length < 10) {
            var bef = "$('#" + loaderId + "').show();";
            var aft = "$('#" + loaderId + "').hide();";
            var onSuccess = "offers.offerDetailsLoaded('" + panelId + "','" + teaserPanelId + "');offers.initOfferDetailsEffects('" + panelId + "');";
            var onClose = "return offers.closeOfferDetails('" + panelId + "','" + teaserPanelId + "');";
            var params = "OfferId=" + offerId + "&country=" + this.country + "&ContentPanelId=" + panelId + "&Mode=&OnClose=" + onClose + "&OnSuccess=" + onSuccess;
            params += "&Featured=false";
            hcAjax.call("/Webservices/Offers.asmx/LoadOfferDetails", params, bef, aft, true);
            this.trackEvent("pageTracker._trackEvent('" + this.get_action_viewdetails() + "', 'Other offer(" + matchType + ")', '" + offerDetails + "')");
        }
        else {
            this.offerDetailsLoaded(panelId, teaserPanelId);
        }
        return false;
    },
    showPopupEmail: function(offerDetails, popupId, boxid) {

        if ($('#' + popupId).is(':visible')) {
            $('.email-box-sent').slideUp(200, function() { document.getElementById(boxid).value = "email address"; $('.email-box').show(); });
        }
        else
            $('#' + popupId).slideDown();

        this.trackEvent("pageTracker._trackEvent('" + this.get_action_email_click() + "', '" + offerDetails + "','" + this.country + "')");
        return false;
    },
    emailOfferComplete: function(to, boxid) {
        $('#email-box-sent-to').html(to);
        $('.email-box').slideUp(200, function() { $('.email-box-sent').show(); });

        setTimeout("$('.email-box-sent').slideUp(200, function() { document.getElementById('" + boxid + "').value = 'email address'; $('.email-box').show(); });", 5000);

    },
    emailOffer: function(offerDetails, offerId, emailBoxId, loaderId, PopupsPanelId) {

        var bef = "$('#" + loaderId + "').show();";
        var aft = "$('#" + loaderId + "').hide();";
        if (document.getElementById(emailBoxId).value.length == 0) {
            alert('Please enter an email address an try again.');
            document.getElementById(emailBoxId).focus();
        }
        else {
            var onSuccess = "offers.emailOfferComplete('" + document.getElementById(emailBoxId).value + "','" + emailBoxId + "');";
            var params = "OfferId=" + offerId + "&to=" + encodeURI(document.getElementById(emailBoxId).value) + "&country=" + this.country + "&onSuccess=" + onSuccess;
            hcAjax.call("/Webservices/Offers.asmx/EmailOffer", params, bef, aft, true);
            this.trackEvent("pageTracker._trackEvent('" + this.get_action_mail_submit() + "', '" + offerDetails + "','" + this.country + "')");
        }

        return false;
    },
    newsletterSignUp: function(emailBoxId) {
        var bef = "$('#" + emailBoxId + "').attr('disabled', true);";
        var aft = "$('#" + emailBoxId + "').attr('disabled',false);";
        if (document.getElementById(emailBoxId).value.length == 0) {
            alert('Please enter an email address an try again.');
            document.getElementById(emailBoxId).focus();
        }
        else {
            var onSuccess = "document.getElementById('" + emailBoxId + "').value = '';";
            var params = "Email=" + encodeURI(document.getElementById(emailBoxId).value) + "&onSuccess=" + onSuccess;
            hcAjax.call("/Webservices/Offers.asmx/NewsletterSignup", params, bef, aft, true);
        }
        return false;
    },
    showPopupEnquire: function(offerDetails, popupPanelId, popupId) {
        $('#' + popupPanelId + " .popup").hide();
        $('#' + popupId).show();
        this.trackEvent("pageTracker._trackEvent('" + this.get_action_enquire() + "', '" + offerDetails + "','" + this.country + "')");
        return false;
    },
    showLoader: function() {
        $('#' + this.loaderId).show();
    },
    hideLoader: function() {
        $('#' + this.loaderId).hide();
    },
    emailKeyPress: function(ctlId, event) {
        if ((window.event && window.event.keyCode == 13) || (event && event.which == 13)) {
            document.getElementById(ctlId).click();
            return false;
        }
    },
    initOffersEffects: function() {
        $('.results .item .c_3 img').tooltip({
            track: true,
            delay: 0,
            showURL: false,
            showBody: " - ",
            extraClass: "icon",
            fixPNG: true
        });
        $('.results .item .c_4 .theatre, .results .item .c_4 .capacity').tooltip({
            track: true,
            delay: 0,
            showURL: false,
            showBody: " - ",
            extraClass: "tooltip-capacity",
            fixPNG: true
        });

        $(".fancybox, .viewmaplink").click(function() {
            try {
                return top.fbox(this);
            } catch (err) {
                $.fancybox({
                    'href': this.href,
                    'width': 800,
                    'height': 550,
                    'autoScale': false,
                    'type': 'iframe',
                    'hideOnContentClick': false,
                    'callbackOnClose': function() { $("#fancy_content").empty(); },
                    'overlayOpacity': 0.7,
                    'overlayColor': '#000',
                    'titleShow': false
                });
            }
            return false;
        });

        $(".results .details .c_1 .input_field").focus(function() {
            if ($(this).val() == "email address")
                $(this).val("");
        })

        $(".results .details .c_1 .input_field").blur(function() {
            if ($(this).val() == "")
                $(this).val("email address");
        })

    }

}




$(document).ready(function() {

    offers.initOffersEffects();

    $(".int_validation").keypress(function(e) {
        if (this.value.length >= 5)
            return false;
        else {
            var unicode = e.charCode ? e.charCode : e.keyCode
            if (unicode != 8) { //if the key isn't the backspace key (which we should allow)
                if (unicode < 48 || unicode > 57) //if not a number
                    return false; //disable key press
            }
        }
    });
});


function DoSubmitOnEnter(sender, e, defaultbuttonid)
{
  if(e.keyCode == 13)
  {
    var btn = document.getElementById(defaultbuttonid);

     if(btn != null)
    {
       e.cancelBubble = true;
       e.returnValue = false;

        if (e.preventDefault)
       {
           e.preventDefault();
       }

       btn.click();
   }
  }
}

