/* START IfYouSki.Engine.Resources.ControlTemplates.Frontend.tools.scrollable-1.1.2.min.js */
/*
* tools.scrollable 1.1.2 - Scroll your HTML with eye candy.
* 
* Copyright (c) 2009 Tero Piirainen
* http://flowplayer.org/tools/scrollable.html
*
* Dual licensed under MIT and GPL 2+ licenses
* http://www.opensource.org/licenses
*
* Launch  : March 2008
* Date: ${date}
* Revision: ${revision} 
*/
(function() {
    var jQuery = $telerik.$;
    (function(b) { b.tools = b.tools || {}; b.tools.scrollable = { version: "1.1.2", conf: { size: 5, vertical: false, speed: 400, keyboard: true, keyboardSteps: null, disabledClass: "disabled", hoverClass: null, clickable: true, activeClass: "active", easing: "swing", loop: false, items: ".items", item: null, prev: ".prev", next: ".next", prevPage: ".prevPage", nextPage: ".nextPage", api: false} }; var c; function a(o, m) { var r = this, p = b(this), d = !m.vertical, e = o.children(), k = 0, i; if (!c) { c = r } b.each(m, function(s, t) { if (b.isFunction(t)) { p.bind(s, t) } }); if (e.length > 1) { e = b(m.items, o) } function l(t) { var s = b(t); return m.globalNav ? s : o.parent().find(t) } o.data("finder", l); var f = l(m.prev), h = l(m.next), g = l(m.prevPage), n = l(m.nextPage); b.extend(r, { getIndex: function() { return k }, getClickIndex: function() { var s = r.getItems(); return s.index(s.filter("." + m.activeClass)) }, getConf: function() { return m }, getSize: function() { return r.getItems().size() }, getPageAmount: function() { return Math.ceil(this.getSize() / m.size) }, getPageIndex: function() { return Math.ceil(k / m.size) }, getNaviButtons: function() { return f.add(h).add(g).add(n) }, getRoot: function() { return o }, getItemWrap: function() { return e }, getItems: function() { return e.children(m.item) }, getVisibleItems: function() { return r.getItems().slice(k, k + m.size) }, seekTo: function(s, w, t) { if (s < 0) { s = 0 } if (k === s) { return r } if (b.isFunction(w)) { t = w } if (s > r.getSize() - m.size) { return m.loop ? r.begin() : this.end() } var u = r.getItems().eq(s); if (!u.length) { return r } var v = b.Event("onBeforeSeek"); p.trigger(v, [s]); if (v.isDefaultPrevented()) { return r } if (w === undefined || b.isFunction(w)) { w = m.speed } function x() { if (t) { t.call(r, s) } p.trigger("onSeek", [s]) } if (d) { e.animate({ left: -u.position().left }, w, m.easing, x) } else { e.animate({ top: -u.position().top }, w, m.easing, x) } c = r; k = s; v = b.Event("onStart"); p.trigger(v, [s]); if (v.isDefaultPrevented()) { return r } f.add(g).toggleClass(m.disabledClass, s === 0); h.add(n).toggleClass(m.disabledClass, s >= r.getSize() - m.size); return r }, move: function(u, t, s) { i = u > 0; return this.seekTo(k + u, t, s) }, next: function(t, s) { return this.move(1, t, s) }, prev: function(t, s) { return this.move(-1, t, s) }, movePage: function(w, v, u) { i = w > 0; var s = m.size * w; var t = k % m.size; if (t > 0) { s += (w > 0 ? -t : m.size - t) } return this.move(s, v, u) }, prevPage: function(t, s) { return this.movePage(-1, t, s) }, nextPage: function(t, s) { return this.movePage(1, t, s) }, setPage: function(t, u, s) { return this.seekTo(t * m.size, u, s) }, begin: function(t, s) { i = false; return this.seekTo(0, t, s) }, end: function(t, s) { i = true; var u = this.getSize() - m.size; return u > 0 ? this.seekTo(u, t, s) : r }, reload: function() { p.trigger("onReload"); return r }, focus: function() { c = r; return r }, click: function(u) { var v = r.getItems().eq(u), s = m.activeClass, t = m.size; if (u < 0 || u >= r.getSize()) { return r } if (t == 1) { if (m.loop) { return r.next() } if (u === 0 || u == r.getSize() - 1) { i = (i === undefined) ? true : !i } return i === false ? r.prev() : r.next() } if (t == 2) { if (u == k) { u-- } r.getItems().removeClass(s); v.addClass(s); return r.seekTo(u, time, fn) } if (!v.hasClass(s)) { r.getItems().removeClass(s); v.addClass(s); var x = Math.floor(t / 2); var w = u - x; if (w > r.getSize() - t) { w = r.getSize() - t } if (w !== u) { return r.seekTo(w) } } return r }, bind: function(s, t) { p.bind(s, t); return r }, unbind: function(s) { p.unbind(s); return r } }); b.each("onBeforeSeek,onStart,onSeek,onReload".split(","), function(s, t) { r[t] = function(u) { return r.bind(t, u) } }); f.addClass(m.disabledClass).click(function() { r.prev() }); h.click(function() { r.next() }); n.click(function() { r.nextPage() }); if (r.getSize() < m.size) { h.add(n).addClass(m.disabledClass) } g.addClass(m.disabledClass).click(function() { r.prevPage() }); var j = m.hoverClass, q = "keydown." + Math.random().toString().substring(10); r.onReload(function() { if (j) { r.getItems().hover(function() { b(this).addClass(j) }, function() { b(this).removeClass(j) }) } if (m.clickable) { r.getItems().each(function(s) { b(this).unbind("click.scrollable").bind("click.scrollable", function(t) { if (b(t.target).is("a")) { return } return r.click(s) }) }) } if (m.keyboard) { b(document).unbind(q).bind(q, function(t) { if (t.altKey || t.ctrlKey) { return } if (m.keyboard != "static" && c != r) { return } var u = m.keyboardSteps; if (d && (t.keyCode == 37 || t.keyCode == 39)) { r.move(t.keyCode == 37 ? -u : u); return t.preventDefault() } if (!d && (t.keyCode == 38 || t.keyCode == 40)) { r.move(t.keyCode == 38 ? -u : u); return t.preventDefault() } return true }) } else { b(document).unbind(q) } }); r.reload() } b.fn.scrollable = function(d) { var e = this.eq(typeof d == "number" ? d : 0).data("scrollable"); if (e) { return e } var f = b.extend({}, b.tools.scrollable.conf); d = b.extend(f, d); d.keyboardSteps = d.keyboardSteps || d.size; this.each(function() { e = new a(b(this), d); b(this).data("scrollable", e) }); return d.api ? e : this } })(jQuery);
})();
/* END IfYouSki.Engine.Resources.ControlTemplates.Frontend.tools.scrollable-1.1.2.min.js */
/* START IfYouSki.Engine.Resources.ControlTemplates.Frontend.jquery.tmpl.js */
/*
* jQuery Templating Plugin
*   NOTE: Created for demonstration purposes.
* Copyright 2010, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
*/
(function() {
    var jQuery = $telerik.$;
    // Override the DOM manipulation function
    var oldManip = jQuery.fn.domManip, tCtxAtt = "_tmplctx", filterAll = "[" + tCtxAtt + "]", itm, ob,
		htmlExpr = /^[^<]*(<[\w\W]+>)[^>]*$/, newCtxs = {}, topCtx = newCtx({ key: 0 }), ctxKey = 0;

    function newCtx(options, parentCtx, fn, data) {
        // Returns a template context for a new instance of a template. 
        // The content field is a hierarchical array of strings and nested contexts (to be  
        // removed and replaced by nodes field of dom elements, once inserted in DOM).
        var newCtx = {
            index: -1,
            data: data || null,
            tmpl: null,
            parent: parentCtx || null,
            nodes: [],
            update: update,
            remove: remove
        };
        if (options) {
            jQuery.extend(newCtx, options, { nodes: [], parent: parentCtx });
        }
        if (fn) {
            // Build the hierarchical content to be used during insertion into DOM
            newCtx.tmpl = fn;
            newCtx.content = newCtx.tmpl(jQuery, newCtx);
            // Add to dictionary of new contexts for this domManip operation
            newCtx.key = ++ctxKey;
            // Keep track of contexts created during this domManip.
            newCtxs[ctxKey] = newCtx;
        }
        return newCtx;

        function update(context) {
            context = context ? jQuery.extend(this, context) : this;
            var nodes = context.nodes;
            jQuery(nodes[0]).before(context);
            jQuery(nodes).remove();
            return this;
        }
        function remove() {
            jQuery(this.nodes).remove();
            return this;
        }
    }

    jQuery.fn.extend({
        tmpl: function() {
            // Used to get template context of first wrapped DOM element
            return jQuery.tmpl(this[0]);
        },

        // This will allow us to do: .append( "template", dataObject )
        domManip: function(args, table, callback) {
            // This appears to be a bug in the appendTo, etc. implementation
            // it should be doing .call() instead of .apply(). See #6227
            var ctxs, parentCtx, cloneIndex = -1, dmArgs = jQuery.makeArray(arguments);
            if (args.length > 1 && args[0].nodeType) {
                dmArgs[0] = [jQuery.makeArray(args)];
            }
            else if (args.length >= 2 && typeof args[1] === "object" && !args[1].nodeType) {
                // args[1] is data, for a template. Eval template to obtain fragment to clone and insert
                parentCtx = args[3] || topCtx;
                dmArgs[0] = [jQuery.tmpl(args[0], parentCtx, args[1], args[2], true)];
            }
            else if (args.length === 1 && typeof args[0] === "object" && !args[0].nodeType && !(args[0] instanceof jQuery)) {
                // args[0] is template context (already inserted in DOM) to be refreshed
                parentCtx = args[0];
                newCtxs[parentCtx.key] = parentCtx;
                dmArgs[0] = [jQuery.tmpl(parentCtx)];
                dmArgs[1] = parentCtx.data;
            }
            if (parentCtx) {
                dmArgs[2] = tmplCallback;
            }

            oldManip.apply(this, dmArgs);

            cloneIndex = -1;

            // Call onRendered for each inserted template instance. 
            ctxs = newCtxs;
            newCtxs = {};
            for (itm in ctxs) {
                ob = ctxs[itm]; // Could test for hasOwnProperty...
                if (ob.rendered) {
                    ob.rendered(ob);
                }
            }
            return this;

            function tmplCallback(fragClone) {
                // Called by oldManip when $.template has been used to create content. 
                // Provides cloned fragment ready for fixup prior to and after insertion into DOM 
                var i, l, ctx, key, keySuffix, parent,

				content = jQuery(fragClone.nodeType === 11 ? fragClone.childNodes : fragClone);
                cloneIndex++;
                keySuffix = "_" + cloneIndex;

                // Return fragment to original caller (e.g. append) for DOM insertion
                callback.call(this, fragClone);

                // Fragment has been inserted:- Add inserted nodes to context. Replace inserted element annotations by jQuery.data. 
                content.find(filterAll).add(content.filter(filterAll)).each(function() {
                    key = jQuery.attr(this, tCtxAtt);
                    if (!jQuery(this.parentNode).closest("[" + tCtxAtt + "=" + key + "]").length) {
                        parent = ctx = newCtxs[key];
                        if (cloneIndex) {
                            key = key + keySuffix;
                            newCtxs[key] = newCtxs[key] || newCtx(ctx, newCtxs[ctx.parent.key + keySuffix] || ctx.parent, true);
                        }
                        parentNodeCtx = jQuery.attr(this.parentNode, tCtxAtt) || 0;
                        while (parent && parent.key != parentNodeCtx) {
                            parent.nodes.push(this);
                            parent = parent.parent;
                        }
                        jQuery.data(this, "tmplCtx", ctx);
                    }
                }).removeAttr(tCtxAtt);

                delete parentCtx.content;
            }
        }
    });

    jQuery.extend({
        tmpl: function(tmpl, parentCtx, data, options, domFrag) {
            var fn, targetCtx;
            if (arguments.length === 1) {
                // Generate a reusable function that will serve as a template
                // generator (and which will be cached).
                if ((typeof tmpl === "string") && !htmlExpr.test(tmpl)) {
                    // it is a selector
                    tmpl = jQuery(tmpl)[0];
                }
                else if (tmpl instanceof jQuery) {
                    // This is an HTML string being passed directly in. 
                    // Assume the user doesn't want it cached. 
                    // They can stick it in jQuery.templates to cache it.
                    tmpl = tmpl.get(0);
                }
                if (tmpl.nodeType) {
                    // Return template context for an element, unless element is a script block template declaration.
                    if (jQuery.attr(tmpl, "type") !== "text/html") {
                        while (tmpl && !(tmplCtx = jQuery.data(tmpl, "tmplCtx")) && (tmpl = tmpl.parentNode)) { }
                        return tmplCtx || topCtx;
                    }
                } else {
                    // Render an updated template context, already associated with DOM.
                    targetCtx = tmpl;
                    tmpl = tmpl.tmpl;
                }
            }
            if (!tmpl) {
                return topCtx;
            }
            // If arguments.length > 1 render template against data, and return fragments ready for DOM insertion.
            if (typeof tmpl === "string") {
                // Use a pre-defined template, if available
                fn = jQuery.templates[tmpl];
                if (!fn) {
                    fn = tmplFn(jQuery(tmpl)[0].innerHTML);
                }
            } else if (typeof tmpl === "function") {
                fn = tmpl;
            } else if (tmpl.nodeType) {
                // If this is a template block, cache
                fn = jQuery.data(tmpl, "tmpl") || jQuery.data(tmpl, "tmpl", tmplFn(tmpl.innerHTML));
            }
            if (!fn) {
                return []; //Could throw...
            }
            if (targetCtx) {
                // The context is already associated with DOM - this is a refresh.
                targetCtx.tmpl = fn;
                targetCtx.nodes = [];
                targetCtx.content = targetCtx.tmpl(jQuery, targetCtx);
                return build(targetCtx);
            }

            data = data || (parentCtx ? parentCtx.data : null);
            if (!data) {
                return fn;
            }
            if (typeof data === "function") {
                data = data.call(parentCtx.data || {}, parentCtx);
            }
            parentCtx.content = jQuery.isArray(data) ?
				jQuery.map(data, function(dataItem) {
				    return newCtx(options, parentCtx, fn, dataItem);
				}) :
				[newCtx(options, parentCtx, fn, data)];

            return domFrag ? build(parentCtx) : parentCtx.content;

            function build(ctx, parent) {
                // Convert hierarchical content into flat string array 
                // and finally return array of fragments ready for DOM insertion
                var frag, ret = jQuery.map(ctx.content, function(item) {
                    return (typeof item === "string") ?
                    // Insert context annotations, to be converted to jQuery.data( "tmplCtx" ) when elems are inserted into DOM.
						item.replace(/(<\w+)([^>]*)/g, "$1 " + tCtxAtt + "=\"" + ctx.key + "\" $2") :
                    // This is a child template context. Build nested template.
						build(item, ctx);
                });
                if (parent) {
                    // nested template
                    return ret;
                }
                // top-level template
                ret = ret.join("");

                // Support templates which have initial or final text nodes
                ret.replace(/^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/, function(all, before, middle, after) {
                    frag = jQuery(middle).get();
                    if (!!before) frag.unshift(document.createTextNode(before));
                    if (!!after) frag.push(document.createTextNode(after));
                });
                return frag ? frag : document.createTextNode(ret);
            }

            function tmplFn(markup) {
                return new Function("jQuery", "$ctx",
					"var $=jQuery,_=[],$data=$ctx.data;" +

                // Introduce the data as local variables using with(){}
					"with($data){_.push('" +

                // Convert the template into pure JavaScript
					markup
						.replace(/([\\'])/g, "\\$1")
						.replace(/[\r\t\n]/g, " ")
						.replace(/\${([^}]*)}/g, "{{= $1}}")
						.replace(/{{(\/?)(\w+|.)(?:\(((?:.(?!}}))*?)?\))?(?:\s+(.*?)?)?(\((.*?)\))?}}/g,
						function(all, slash, type, fnargs, target, parens, args) {
						    function unescape(args) {
						        return args ? args.replace(/\\'/g, "'").replace(/\\\\/g, "\\") : null;
						    }
						    var cmd = jQuery.tmplTags[type], def, expr;
						    if (!cmd) {
						        throw "Template command not found: " + type;
						    }
						    def = cmd._default || [];
						    if (target) {
						        target = unescape(target);
						        args = args ? ("," + unescape(args) + ")") : (parens ? ")" : "");
						        expr = args ? ("(" + target + ").call($ctx" + args) : target;
						    } else {
						        expr = def["$1"] || "null";
						    }
						    fnargs = unescape(fnargs);
						    return "');" +
								cmd[slash ? "suffix" : "prefix"]
									.split("$defined_1").join("typeof(" + target + ")!=='undefined'")
									.split("$1").join(expr)
									.split("$2").join(fnargs ?
										fnargs.replace(/\s*([^\(]+)\s*(\((.*?)\))?/g, function(all, name, parens, params) {
										    params = params ? ("," + params + ")") : (parens ? ")" : "");
										    return params ? ("(" + name + ").call($ctx" + params) : all;
										})
										: (def["$2"] || "")
									) +
								"_.push('";
						}) +
					"');}return _;"
				);
            }
        },

        // You can stick pre-built template functions here
        templates: {},
        /*
        * For example, someone could do:
        *   jQuery.templates.foo = jQuery.tmpl("some long templating string");
        *   $("#test").append("foo", data);
        */

        tmplTags: {
            "tmpl": {
                _default: { $2: "null" },
                prefix: "if($defined_1){_=_.concat($.tmpl($1,$ctx,$2));}"
            },
            "each": {
                _default: { $2: "$index, $value" },
                prefix: "if($defined_1){$.each($1,function($2){with(this){",
                suffix: "}});}"
            },
            "if": {
                prefix: "if(($defined_1) && $1){",
                suffix: "}"
            },
            "else": {
                prefix: "}else{"
            },
            "html": {
                prefix: "if($defined_1){_.push($1);}"
            },
            "=": {
                _default: { $1: "$data" },
                prefix: "if($defined_1){_.push($.encode($1));}"
            }
        },
        encode: function(text) {
            // This should probably do HTML encoding replacing < > & and' and " by corresponding entities.
            return text != null ? document.createTextNode(text.toString()).nodeValue : "";
        }
    });
})();

/* END IfYouSki.Engine.Resources.ControlTemplates.Frontend.jquery.tmpl.js */
/* START IfYouSki.Engine.Resources.ControlTemplates.Frontend.SearchForm.js */
/// <reference name="MicrosoftAjax.js" />
/// <reference name="Telerik.Web.UI.Common.Core.js" assembly="Telerik.Web.UI" />
/// <reference name="Telerik.Web.UI.Common.jQuery.js" assembly="Telerik.Web.UI" />
/// <reference name="Telerik.Web.UI.Common.jQueryInclude.js" assembly="Telerik.Web.UI" />
/// <reference name="Telerik.Web.UI.Calendar.RadCalendarCommonScript.js" assembly="Telerik.Web.UI" />
/// <reference name="Telerik.Web.UI.Calendar.RadCalendarScript.js" assembly="Telerik.Web.UI" />
/// <reference name="Telerik.Web.UI.Calendar.RadDatePicker.js" assembly="Telerik.Web.UI" />
/// <reference name="IfYouSki.Engine.Resources.ControlTemplates.Frontend.tools.scrollable-1.1.2.min.js" assembly="IfYouSki.Engine" />
/// <reference name="IfYouSki.Engine.Resources.ControlTemplates.Frontend.jquery.tmpl.js" assembly="IfYouSki.Engine" />

/***************************************************************************
SearchForm Control
****************************************************************************/

Type.registerNamespace("IfYouSki.Engine.WebControls");

(function() {

    var $ = $telerik.$;
    var $I = IfYouSki.Engine.WebControls;


    $I.Months = function() { };
    $I.Months.prototype =
             {
                 jan: 1, feb: 2, mar: 3, apr: 4, may: 5, jun: 6,
                 jul: 7, aug: 8, sep: 9, oct: 10, nov: 11, dec: 12
             }
    $I.Months.registerEnum("IfYouSki.Engine.WebControls.Months");


    $I.SearchForm = function(element) {
        //module level variables
        this._whenDayCombo;
        this._whenMonthCombo;
        this._popupButtonId;
        this._calendarPosition;
        this._calendarPopup;
        this._resortComboId;
        this._countryComboId;
        this._countryId;
        this._resortValuesId;
        this._budgetSliderId;
        this._tooltipId;
        this._toggleAdvancedSearchId;
        this._advancedSearchModeId;
        this._isSliding;
        this._budgetIsLoaded = false;
        this._formIsLoaded = false;

        //Calling the base class constructor  
        $I.SearchForm.initializeBase(this, [element]);
    }

    $I.SearchForm.prototype = {
        //Getter for formIsLoaded Property
        get_formIsLoaded: function() {
            return this._formIsLoaded;
        },
        //setter for formIsLoaded Property
        set_formIsLoaded: function(value) {
            this._formIsLoaded = value;
        },
        //Getter for budgetIsLoaded Property
        get_budgetIsLoaded: function() {
            return this._budgetIsLoaded;
        },
        //setter for budgetIsLoaded Property
        set_budgetIsLoaded: function(value) {
            this._budgetIsLoaded = value;
        },
        //Getter for isSliding Property
        get_isSliding: function() {
            return this._isSliding;
        },
        //setter for isSliding Property
        set_isSliding: function(value) {
            this._isSliding = value;
        },
        //Getter for budgetSliderId Property
        get_budgetSliderId: function() {
            return this._budgetSliderId;
        },
        //setter for budgetSliderId Property
        set_budgetSliderId: function(value) {
            this._budgetSliderId = value;
        },
        //Getter for tooltipId Property
        get_tooltipId: function() {
            return this._tooltipId;
        },
        //setter for tooltipId Property
        set_tooltipId: function(value) {
            this._tooltipId = value;
        },
        //Getter for toggleAdvancedSearchId Property
        get_toggleAdvancedSearchId: function() {
            return this._toggleAdvancedSearchId;
        },
        //setter for toggleAdvancedSearchId Property
        set_toggleAdvancedSearchId: function(value) {
            this._toggleAdvancedSearchId = value;
        },
        //Getter for advancedSearchModeId Property
        get_advancedSearchModeId: function() {
            return this._advancedSearchModeId;
        },
        //setter for advancedSearchModeId Property
        set_advancedSearchModeId: function(value) {
            this._advancedSearchModeId = value;
        },
        //Getter for whenDayCombo Property 
        get_whenDayCombo: function() {
            return this._whenDayCombo;
        },
        //setter for whenDayCombo Property
        set_whenDayCombo: function(value) {
            this._whenDayCombo = value;
        },

        //Getter for whenMonthCombo Property
        get_whenMonthCombo: function() {
            return this._whenMonthCombo;
        },
        //setter for whenMonthCombo Property
        set_whenMonthCombo: function(value) {
            this._whenMonthCombo = value;
        },

        //Getter for popupButtonId Property
        get_popupButtonId: function() {
            return this._popupButtonId;
        },
        //setter for popupButtonId Property
        set_popupButtonId: function(value) {
            this._popupButtonId = value;
        },

        //Getter for calendarPosition Property
        get_calendarPosition: function() {
            return this._calendarPosition;
        },
        //setter for calendarPosition Property
        set_calendarPosition: function(value) {
            this._calendarPosition = value;
        },

        //Getter for calendarPopup Property
        get_calendarPopup: function() {
            return this._calendarPopup;
        },
        //setter for calendarPopup Property
        set_calendarPopup: function(value) {
            this._calendarPopup = value;
        },
        //Getter for countryComboId Property
        get_countryComboId: function() {
            return this._countryComboId;
        },
        //setter for countryComboId Property
        set_countryComboId: function(value) {
            this._countryComboId = value;
        },
        //Getter for resortComboId Property
        get_resortComboId: function() {
            return this._resortComboId;
        },
        //setter for resortComboId Property
        set_resortComboId: function(value) {
            this._resortComboId = value;
        },
        //Getter for country Id Property
        get_countryId: function() {
            return this._countryId;
        },
        //setter for country Id Property
        set_countryId: function(value) {
            this._countryId = value;
        },
        //Getter for resort hidden values ID Property
        get_resortValuesId: function() {
            return this._resortValuesId;
        },
        //setter for resort hidden values ID Property
        set_resortValuesId: function(value) {
            this._resortValuesId = value;
        },

        popUpCalendar: function(evt, args) {
            var searchForm = args.sender;

            var popup = $("#" + searchForm.get_calendarPopup());
            var buttonPosition = $(this).position();

            //we need to show before calculatng
            popup.fadeIn('fast');

            var navigation = popup.find(".navigation");

            //find the calendars and count them
            var calendars = popup.find(".items div");
            var firstCalendar = $(":first", calendars);
            var count = (calendars.size() > 3 ? 3 : calendars.size());

            //hide the navigation if there are no calendars
            if (count <= 2)
                navigation.hide();
            else
                navigation.show();

            //get the calculated height of a single calendar
            var width = firstCalendar.outerWidth() * count;
            var height = firstCalendar.outerHeight(true) + (count <= 2 ? 0 : navigation.outerHeight(true));

            //change the position of the picker
            var x = buttonPosition.left;
            if (searchForm.get_calendarPosition() == "BottomLeft")
                x = x - width;

            //position the container
            popup.css({
                position: "absolute",
                marginLeft: 0,
                marginTop: 0,
                top: buttonPosition.top,
                left: x,
                width: width,
                height: height,
                overflow: "hidden"
            });

            var scrollable = popup.find(".scrollable");
            scrollable.css({
                width: width,
                height: firstCalendar.outerHeight(true)
            })
        .scrollable({
            size: 3
        });


            //stop clicks on the popup from bubbling up
            $(popup).click(function(clickEvt) {
                stopPropagation(clickEvt);
            });

            //click to cancel the popup
            $telerik.cancelRawEvent(evt);
            $('html').bind('click.' + searchForm.get_calendarPopup(), function() {
                searchForm.hidePopUp();
                return false;
            });
        },

        hidePopUp: function() {
            var popup = $("#" + this.get_calendarPopup());
            popup.css("");
            popup.fadeOut('fast');

            //remove the click block
            $('html').unbind('click.' + this.get_calendarPopup())
        },

        _calendar_dateSelecting: function(sender, eventArgs) {
            //get the popup
            var popup = $("#" + this.get_calendarPopup());

            //close the popup    
            this.hidePopUp();

            //cancel the click
            eventArgs.set_cancel(true);

            //get the date and format it
            var date = eventArgs.get_renderDay().get_date();
            var dfi = sender.DateTimeFormatInfo;
            var monthYear = dfi.FormatDate(date, "MMM yy");
            var day = date[2];

            //set the when day combo
            var comboItem = $find(this.get_whenDayCombo()).findItemByValue(day);
            if (comboItem != null)
                comboItem.select();

            //set the when day combo
            comboItem = $find(this.get_whenMonthCombo()).findItemByText(monthYear);
            if (comboItem != null)
                comboItem.select();
        },
        _countryCombo_OnClientSelectedIndexChanged: function(combo, eventArgs) {
            if (!this.get_formIsLoaded()) {
                var resortCombo = $find(this.get_resortComboId());
                if (resortCombo != null) {
                    this._resortCombo_OnClientDropDownOpening(resortCombo);
                    this._generateComboText(resortCombo);
                }
            }
        },
        _resortCombo_OnClientDropDownOpening: function(combo, eventArgs) {
            var countryCombo = $find(this.get_countryComboId());

            //hook up Any click
            var thisControl = this;
            $(".rcbHeader input:checkbox", combo.get_dropDownElement()).click(function() {
                search_toggleChecks(this);
                thisControl.getSelectedValues(combo);
            });

            //try the select if the combo is on the page
            if (countryCombo) {
                var countryId = countryCombo.get_value();

                var items = combo.get_items();
                for (var i = 0, ii = items.get_count(); i < ii; i++) {
                    var thisItem = items.getItem(i);
                    //only show if the country id matches or if the country is set to any and don't hide the "Any" item                    
                    if (thisItem.get_attributes().getAttribute("CountryId") == countryId || countryId == "Any" || thisItem.get_value() == "Any") {
                        thisItem.show();
                    }
                    else {
                        thisItem.hide();
                        $("input:checked", thisItem.get_element()).removeAttr("checked");
                    }
                }
            }
            this.getSelectedValues(combo);
        },
        _monthCombo_OnClientSelectedIndexChanging: function(combo, eventArgs) {
            var dayCombo = $find(this.get_whenDayCombo());
            if (dayCombo) {
                if (dayCombo.get_items().get_count() > 0) {

                    //convert the string into useful numbers
                    var monthYear = eventArgs.get_item().get_text();
                    var monthName = monthYear.substring(0, 3);
                    var shortYear = parseInt("20" + monthYear.substring(4));
                    var month = eval("IfYouSki.Engine.WebControls.Months." + monthName.toLowerCase());

                    //get the last day of the month                                        
                    var dd = new Date(shortYear, month, 0);
                    var daysInMonth = dd.getDate();

                    var items = dayCombo.get_items();
                    for (i = 0; i < items.get_count(); i++) {

                        //only show if that day if it exists in that month
                        if (items.getItem(i).get_value() <= daysInMonth || items.getItem(i).get_value() == "Any")
                            items.getItem(i).show();
                        else
                            items.getItem(i).hide();
                    }

                    //if the day selected is out of range then select the last valid day
                    if (dayCombo.get_value() > daysInMonth) {
                        dayCombo.findItemByValue(daysInMonth).select();
                    }

                }
            }
        },
        _resortCombo_OnItemRequesting: function(combo, eventArgs) {
            var context = eventArgs.get_context();
            context["CountryId"] = this.get_countryId();
        },
        _resortCombo_OnClientDropDownClosing: function(combo, eventArgs) {
            this._generateComboText(combo);
        },
        _resortCombo_OnItemRequested: function(combo, eventArgs) {
            var hiddenValues = $("#" + this.get_resortValuesId());

            if (hiddenValues.val().length > 0) {
                var values = hiddenValues.val().split(',');
                for (i = 0; i < values.length; i++) {
                    var item = combo.findItemByValue(values[i]);
                    if (item != null)
                        $(":checkbox", item.get_element()).attr("checked", "checked");
                }
            }

            this._generateComboText(combo, hiddenValues);

            checkboxCombos_SetMouseout(combo, eventArgs);

        },
        _resortCombo_OnItemDataBound: function(combo, eventArgs) {
            var thisControl = this;
            var item = eventArgs.get_item();
            var dataItem = eventArgs.get_dataItem();

            //bind template, and block clicks from closing dropdown
            $(item.get_element())
                .html("")
                .append("#check-template", dataItem)
                .click(function(clickEvt) {
                    stopPropagation(clickEvt);
                })
                .find("input").click(function() {
                    //get the hidden values input
                    var hiddenValues = $("#" + thisControl.get_resortValuesId());
                    var checkbox = $(this);
                    if (checkbox.is(":checked"))
                        hiddenValues.val(hiddenValues.val() + checkbox.val() + ",");
                    else
                        hiddenValues.val(thisControl.removeListValue(hiddenValues.val(), checkbox.val()));
                });
        },
        removeListValue: function(list, value, separator) {
            separator = separator || ",";
            var values = list.split(",");
            for (var i = 0; i < values.length; i++) {
                if (values[i] == value) {
                    values.splice(i, 1);
                    return values.join(",");
                }
            }
            return list;
        },
        getSelectedValues: function(combo) {
            var items = combo.get_items();
            var resortList = "";
            for (i = 0; i < items.get_count(); i++) {
                var thisItem = items.getItem(i);
                if (thisItem.get_visible() && $("input:checked", thisItem.get_element()).length == 1) {
                    resortList += thisItem.get_value() + ",";
                }
            }
            $("#" + this.get_resortValuesId()).val(resortList);
        },
        _budget_OnClientValueChanging: function(sender, args) {
            if (!this.get_isSliding()) return;

            var tooltip = $find(this.get_tooltipId());
            resetBudgetToolTip(tooltip);

            var toolTip = args.get_newValue();
            if (toolTip == sender.get_maximumValue())
                toolTip = "greater than &pound;" + toolTip;
            else if (toolTip == sender.get_minimumValue())
                toolTip = "less than &pound;" + toolTip;
            else
                toolTip = "&pound;" + toolTip;

            tooltip.set_text(toolTip);
        },
        _budget_OnClientSlideStart: function(sender, args) {
            this.set_isSliding(true);

            var tooltip = $find(this.get_tooltipId());
            showBudgetToolTip(tooltip, sender);
        },

        _budget_OnClientSlideEnd: function(sender, args) {
            this.set_isSliding(false); ;

            var tooltip = $find(this.get_tooltipId());
            tooltip.hide();
        },

        toggleAdvancedSearch: function() {
            var advancedSearch = $('#' + this.get_id() + ' .advanced-search');

            var moreLink = $("#" + this.get_toggleAdvancedSearchId());
            var advancedSearchExpanded = $("#" + this.get_advancedSearchModeId());
            var expanded = (advancedSearchExpanded.val() == "true");

            if (!expanded) {
                advancedSearch.removeClass("hidden");
                moreLink.addClass("less");
                this.budgetLoad();

                moreLink.html("Less search options");
                advancedSearchExpanded.val(true);
            } else {
                moreLink.removeClass("less");
                advancedSearch.addClass("hidden");
                moreLink.html("More search options");
                advancedSearchExpanded.val(false);
            }

        },
        budgetLoad: function() {
            if (this.get_budgetIsLoaded()) return;

            var slider = $find(this.get_budgetSliderId());
            var items = slider.get_items();

            for (var i = 0, ii = items.length; i < ii; i++) {
                var prepend = "&pound;";
                if (i == 0)
                    prepend = "&lt;" + prepend
                if (i == items.length - 1)
                    prepend = "&gt;" + prepend

                var item = $("span", items[i].get_element());
                if (item.length > 0)
                    item.html(prepend + item.html());
            }
            this.set_budgetIsLoaded(true);
        },
        _generateComboText: function(combo, hiddenValues) {
            if (hiddenValues == null)
                hiddenValues = $("#" + this.get_resortValuesId());
            if (hiddenValues.val().length == 0)
                combo.set_text("Any");
            else {
                var checkAll = $(".rcbHeader input:checkbox", combo.get_dropDownElement());
                var allSelected = (hiddenValues.val().split(',').length - 1 == combo.get_items().get_count());
                if (allSelected)
                    checkAll.attr("checked", "checked");
                checkAll.siblings("label[for=" + checkAll.attr("id") + "]").html(allSelected ? "Deselect All" : "Select All");
                combo.set_text("Resorts selected");
            }
        }
        ,

        initialize: function() {
            $I.SearchForm.callBaseMethod(this, 'initialize');

            this.set_isSliding(false);

            //add the popup click event
            var thisControl = this;
            var _popupClick = Function.createCallback(this.popUpCalendar, { sender: this });
            $addHandler($get(this._popupButtonId), 'click', _popupClick);

            //find all the calendars and set them to the calendar click event
            $("#" + thisControl.get_calendarPopup() + " table.RadCalendar").each(function() {
                var element = $find(this.id);
                if (element && Telerik.Web.UI.RadCalendar && element instanceof Telerik.Web.UI.RadCalendar) {
                    // it is a calendar so add an anonymous function to encapsulate with this object
                    element.add_dateSelecting(function(sender, eventArgs) {
                        thisControl._calendar_dateSelecting(sender, eventArgs);
                    });
                }
            });

            //set up the selected index
            var countryCombo = $find(this.get_countryComboId());
            if (countryCombo) {
                // build combo on server
                if (countryCombo.get_webServiceSettings().get_path())
                    countryCombo.requestItems("Any", false);

                countryCombo.add_selectedIndexChanged(function(combo, eventArgs) {
                    thisControl._countryCombo_OnClientSelectedIndexChanged(combo, eventArgs);
                });
            }

            //set up the drop down handler
            var resortCombo = $find(this.get_resortComboId());
            if (resortCombo) {
                resortCombo.add_dropDownOpening(function(combo, eventArgs) {
                    thisControl._resortCombo_OnClientDropDownOpening(combo, eventArgs);
                });
                resortCombo.add_itemsRequesting(function(combo, eventArgs) {
                    thisControl._resortCombo_OnItemRequesting(combo, eventArgs);
                });

                resortCombo.add_itemsRequested(function(combo, eventArgs) {
                    thisControl._resortCombo_OnItemRequested(combo, eventArgs);
                });

                resortCombo.add_itemDataBound(function(combo, eventArgs) {
                    thisControl._resortCombo_OnItemDataBound(combo, eventArgs);
                });

                resortCombo.add_itemDataBound(function(combo, eventArgs) {
                    thisControl._resortCombo_OnItemDataBound(combo, eventArgs);
                });

                resortCombo.add_dropDownClosing(function(combo, eventArgs) {
                    thisControl._resortCombo_OnClientDropDownClosing(combo, eventArgs);
                });

                // build combo on server
                if (resortCombo.get_webServiceSettings().get_path())
                    resortCombo.requestItems("Any", false);
            }

            //set up the month combo change
            var monthCombo = $find(this.get_whenMonthCombo());
            monthCombo.add_selectedIndexChanging(function(sender, eventArgs) {
                thisControl._monthCombo_OnClientSelectedIndexChanging(sender, eventArgs);
            });

            //set up the budget slider
            var budgetSlider = $find(this.get_budgetSliderId());
            if (budgetSlider) {
                budgetSlider.add_slideEnd(function(slider, eventArgs) {
                    thisControl._budget_OnClientSlideEnd(slider, eventArgs);
                });
                budgetSlider.add_slideStart(function(slider, eventArgs) {
                    thisControl._budget_OnClientSlideStart(slider, eventArgs);
                });
                budgetSlider.add_valueChanging(function(slider, eventArgs) {
                    thisControl._budget_OnClientValueChanging(slider, eventArgs);
                });
            }

            //hook up the advanced search
            var advancedSearchExpanded = $("#" + this.get_advancedSearchModeId());
            if (advancedSearchExpanded.size() != 0 && budgetSlider) {

                var moreLink = $("#" + this.get_toggleAdvancedSearchId());
                moreLink.click(function() {
                    thisControl.toggleAdvancedSearch();
                });

                var expanded = (advancedSearchExpanded.val() == "true");
                if (expanded) {
                    advancedSearchExpanded.val(false);
                    thisControl.toggleAdvancedSearch();
                }
            }

            //control to indicate all has loaded
            thisControl.set_formIsLoaded(true);
        },
        dispose: function() {

            //clear event handlers
            $clearHandlers($get(this._popupButtonId));

            //Add custom dispose actions here
            $I.SearchForm.callBaseMethod(this, 'dispose');
        }
    }

    $I.SearchForm.registerClass('IfYouSki.Engine.WebControls.SearchForm', Sys.UI.Control);

})();

/***************************************************************************
Other functions
****************************************************************************/

function stopPropagation(e) {
    e = e || event; /* get IE event ( not passed ) */
    e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
}

(function($) {
    $(document).ready(function() {
        //move the calendar
        var popup = $("div.popup-calendar");
        $(document.body).append(popup);
    });
})($telerik.$);


/***************************************************************************
Combo box event handlers
***************************************************************************/
function searchCombos_ItemsRequested(combo, eventArgs) {
    if (combo.get_items().get_count() > 0) {
        var selectedValue = combo.get_value();
        var selectedText = combo.get_text();

        //pre-select the first item or the item whos value was already set
        var item = combo.findItemByValue(selectedValue);
        if (item != null) {
            item.select();
            combo.set_text(item.get_text());
        } else {
            item = combo.findItemByText(selectedText);
            combo.set_text(selectedText);
            item.select();
        }
    }
}

function searchCombos_ItemsRequestFailed(combo, eventArgs) {
    if (console == typeof (undefined)) {
        console.info(eventArgs.get_errorMessage());
    }
    alert("There was a problem loading the search form options, please try again later");
    eventArgs.set_cancel(true);
}

function searchCombos_OnItemDataBound(sender, eventArgs) {
    var item = eventArgs.get_item();
    var dataItem = eventArgs.get_dataItem();
    var countryId = dataItem.CountryId;
    item.get_attributes().setAttribute("CountryId", countryId);
}

function checkboxCombos_SetMouseout(sender, eventArgs) {
    (function($) {
        $(sender.get_dropDownElement()).bind("mouseleave", function() {
            sender.hideDropDown();
        });
    })($telerik.$);
}

function checkboxCombos_OnLoad(sender, eventArgs) {
    (function($) {
        var items = sender.get_items();
        for (var i = 0, ii = items.get_count(); i < ii; i++) {
            var item = items.getItem(i);
            $(item.get_element()).click(function(clkevt) {
                stopPropagation(clkevt);
            });
        }

        var selectedCount = $(".rcbList input:checked", sender.get_dropDownElement()).length;
        if (selectedCount == 0 || allSelected)
            sender.set_text("Any");

        else {
            var checkAll = $(".rcbHeader input:checkbox", sender.get_dropDownElement());
            var allSelected = (selectedCount == sender.get_items().get_count());
            if (allSelected)
                checkAll.attr("checked", "checked");
            checkAll.siblings("label[for=" + checkAll.attr("id") + "]").html(allSelected ? "Deselect All" : "Select All");
            sender.set_text("Multiple selected");
        }

        checkboxCombos_SetMouseout(sender, eventArgs);

    })($telerik.$);
}

function checkboxCombos_Closing(sender, eventArgs) {
    (function($) {
        var selectedCount = $(".rcbList input:checked", sender.get_dropDownElement()).length;
        if (selectedCount == 0 || allSelected)
            sender.set_text("Any");
        else {
            var allSelected = (selectedCount == sender.get_items().get_count());
            if (allSelected)
                $(".rcbHeader input:checkbox", sender.get_dropDownElement()).attr("checked", "checked");
            sender.set_text("Multiple selected");
        }
    })($telerik.$);
}

function search_toggleChecks(check) {
    (function($) {
        var checkAll = $(check);
        var isChecked = checkAll.is(":checked");
        var checboxes = checkAll.closest("div.RadComboBoxDropDown").find(".rcbList input:checkbox").each(function() {
            if (isChecked)
                $(this).attr("checked", "checked");
            else
                $(this).removeAttr("checked");
        });
        checkAll.siblings("label[for=" + checkAll.attr("id") + "]").html(isChecked ? "Deselect All" : "Select All");

    })($telerik.$);
}

function showBudgetToolTip(tooltip, slider) {
    var activeHandle = slider.get_activeHandle();
    if (!activeHandle) return;

    tooltip.set_targetControl(activeHandle);
    resetBudgetToolTip(tooltip);
}

function resetBudgetToolTip(tooltip) {
    if (!tooltip.isVisible())
        tooltip.show();
    else
        tooltip.updateLocation();
}


/* END IfYouSki.Engine.Resources.ControlTemplates.Frontend.SearchForm.js */
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();
(function() {var fn = function() {if(!$get('ctl00_ctl00_RadScriptManager1_TSM')) return; $get('ctl00_ctl00_RadScriptManager1_TSM').value += ';;IfYouSki.Engine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null:en-US:51b37367-5be4-4614-a672-b4fb23516d61:2b4ebc49:fd7a73c0:5a0eb5f0';Sys.Application.remove_load(fn);};Sys.Application.add_load(fn);})();
