﻿/* config */

var debug = true;
var shaded_button_class = 'gtbutton';
var shaded_button_default_bgcolor = '#e47100';
var shaded_button_default_bgcolor_over = '#ab995b';

/* browser detect */

var BrowserDetect = { init: function () { this.browser = this.searchString(this.dataBrowser) || "An unknown browser"; this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version"; this.OS = this.searchString(this.dataOS) || "an unknown OS" }, searchString: function (b) { for (var a = 0; a < b.length; a++) { var c = b[a].string, d = b[a].prop; this.versionSearchString = b[a].versionSearch || b[a].identity; if (c) { if (c.indexOf(b[a].subString) != -1) return b[a].identity } else if (d) return b[a].identity } },
    searchVersion: function (b) { var a = b.indexOf(this.versionSearchString); if (a != -1) return parseFloat(b.substring(a + this.versionSearchString.length + 1)) }, dataBrowser: [{ string: navigator.userAgent, subString: "OmniWeb", versionSearch: "OmniWeb/", identity: "OmniWeb" }, { string: navigator.vendor, subString: "Apple", identity: "Safari" }, { prop: window.opera, identity: "Opera" }, { string: navigator.vendor, subString: "iCab", identity: "iCab" }, { string: navigator.vendor, subString: "KDE", identity: "Konqueror" }, { string: navigator.userAgent,
        subString: "Firefox", identity: "Firefox"
    }, { string: navigator.vendor, subString: "Camino", identity: "Camino" }, { string: navigator.userAgent, subString: "Netscape", identity: "Netscape" }, { string: navigator.userAgent, subString: "MSIE", identity: "Explorer", versionSearch: "MSIE" }, { string: navigator.userAgent, subString: "Gecko", identity: "Mozilla", versionSearch: "rv" }, { string: navigator.userAgent, subString: "Mozilla", identity: "Netscape", versionSearch: "Mozilla"}], dataOS: [{ string: navigator.platform, subString: "Win", identity: "Windows" },
{ string: navigator.platform, subString: "Mac", identity: "Mac" }, { string: navigator.platform, subString: "Linux", identity: "Linux"}]
}; BrowserDetect.init();

/* form functions */

SetSelect = function (frm, selectbox, waarde) {
    if (!frm[selectbox] || !frm[selectbox].options) return;
    for (var i = 0; i < frm[selectbox].options.length; i++) {
        if (frm[selectbox].options[i].value == waarde || frm[selectbox].options[i].value == '0' + waarde) {
            frm[selectbox].options[i].selected = true;
            break;
        };
    };
};

/* country and city dropdown */

SelectCountry = function (country, select_city, show_all_cities) {
    if (country == '') country = 'EMPTY';
    var count = select_city.options.length;
    for (var i = 0; i < count; i++) {
        select_city.options[0] = null;
    };
    select_city.options[0] = new Option('', '');
    select_city.options[0].innerHTML = translate_select_city;
    select_city.options[0].selected = true;
    var index = 1;
    if (show_all_cities == null || show_all_cities != false) {
        select_city.options[1] = new Option('', 'ALL');
        select_city.options[1].innerHTML = translate_all_cities;
        index = 2;
    }
    for (var i = 0; i < cities.length; i++) {
        if (cities[i][0] == country) {
            select_city.options[index] = new Option('', cities[i][1]);
            select_city.options[index].innerHTML = cities[i][2];
            index++;
        };
    };
}; // end selectCountry

SelectCity = function (city, select_country, select_city) {
    if (city == 'ALL') {
        var count = select_city.options.length;
        for (i = 0; i < count; i++) {
            select_city.options[0] = null;
        };
        var index = 0;
        for (var i = 0; i < cities.length; i++) {
            if (cities[i][1] != '') {
                select_city.options[index] = new Option('', cities[i][1]);
                select_city.options[index].innerHTML = cities[i][2];
                index++;
            };
        };
        select_country.options[0].selected = true;
    };
}; // end selectCity

Mod = function (a, b) {
    return a - Math.floor(a / b) * b;
};

IsLeapYear = function (year) {
    return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
};

SetDaysInMonth = function (yyyyMM, ddlDay) {
    var month = yyyyMM.substring(5, 7);
    var year = yyyyMM.substring(0, 4);
    var oldday = ddlDay.selectedIndex;
    switch (month) {
        case '02':
            if (IsLeapYear(year)) {
                /* 29 */
                ddlDay.options[30] = null;
                ddlDay.options[29] = null;
            } else {
                /* 28 */
                ddlDay.options[30] = null;
                ddlDay.options[29] = null;
                ddlDay.options[28] = null;
            }
            break;
        case '04':
            /* 30 */
            if (!ddlDay.options[28]) {
                ddlDay.options[28] = new Option('29', '29');
            }
            if (!ddlDay.options[29]) {
                ddlDay.options[29] = new Option('30', '30');
            }
            ddlDay.options[30] = null;
            break;
        case '06':
            /* 30 */
            if (!ddlDay.options[28]) {
                ddlDay.options[28] = new Option('29', '29');
            }
            if (!ddlDay.options[29]) {
                ddlDay.options[29] = new Option('30', '30');
            }
            ddlDay.options[30] = null;
            break;
        case '09':
            /* 30 */
            if (!ddlDay.options[28]) {
                ddlDay.options[28] = new Option('29', '29');
            }
            if (!ddlDay.options[29]) {
                ddlDay.options[29] = new Option('30', '30');
            }
            ddlDay.options[30] = null;
            break;
        case '11':
            /* 30 */
            if (!ddlDay.options[28]) {
                ddlDay.options[28] = new Option('29', '29');
            }
            if (!ddlDay.options[29]) {
                ddlDay.options[29] = new Option('30', '30');
            }
            ddlDay.options[30] = null;
            break;
        default:
            /* 31 */
            if (!ddlDay.options[28]) {
                ddlDay.options[28] = new Option('29', '29');
            }
            if (!ddlDay.options[29]) {
                ddlDay.options[29] = new Option('30', '30');
            }
            if (!ddlDay.options[30]) {
                ddlDay.options[30] = new Option('31', '31');
            }
    } /* end switch */
    var newday = ddlDay.selectedIndex;
    if (oldday != newday) {
        ddlDay.options[ddlDay.options.length - 1].selected = true;
    };
};

maxLength = function (o, e, len, spn) {
    var span;
    if (spn && (span = document.getElementById(spn))) {
        span.innerHTML = Math.max(len - o.value.length, 0);
    };
    o.value = o.value.substring(0, len);
    return true;
};

/* general functions */

var GT; if (!GT) GT = {};
if (!GT.Utils) GT.Utils = {};

GT.Utils.AddEvent = function (o, ename, fn) {
    if (typeof (fn) == 'function') {
        if (window.addEventListener)
            window.addEventListener(ename, fn, false);
        else if (window.attachEvent)
            window.attachEvent('on' + ename, fn, false);
        else if (document.getElementById)
            eval('window.on' + ename) = fn;
        else
            fn();
    }
};

QueryString = function (qs) {
    var r = '', s = window.location.search.substring(1), v = s.split('&');
    for (var i = 0; i < v.length; i++) {
        var nv = v[i].split('=');
        if (nv && nv[0].toLowerCase() == qs.toLowerCase()) { r = nv[1]; delete nv; break; }
        delete nv;
    }
    delete v;
    return r;
};

GetCookie = function (name) {
    var r = null;
    if (document.cookie.length > 0) {
        var offset = document.cookie.indexOf(name + '=');
        if (offset != -1) {
            offset += name.length + 1;
            var end = document.cookie.indexOf(";", offset);
            if (end == -1) end = document.cookie.length;
            r = unescape(document.cookie.substring(offset, end));
        }
    }
    return r;
};

SetCookie = function (name, value, lifetime_minutes, path) {
    if (typeof name != 'undefined') {
        var cookie = name + '=' + escape(value);
        if (lifetime_minutes != null) {
            var today = new Date();
            var expires = new Date(today.getTime() + lifetime_minutes * 1000 * 60);
            cookie += '; expires=' + expires.toGMTString();
        }
        if (path != null) {
            cookie += '; path=' + path;
        }
        document.cookie = cookie;
    }
};

jsEscape = function (text) {
    var s = text;
    if (text && typeof text == 'string')
        s = text;
    else if (text && text.toString)
        s = text.toString();
    else if (text)
        s = (typeof text).toString();
    else
        s = 'undefined';
    return s.replace(/\'/g, '\\\'');
};

getURL = getUrl = function (url, target) {
    if (url != '') {
        if (url.substring(0, 11) == 'javascript:') {
            return (eval(url.substring(11)));
        } else {
            try {
                if (navigator.userAgent && navigator.userAgent.toLowerCase().indexOf('firefox') > -1 && parseInt(jQuery.browser.version, 10) >= 5) {
                    // link.click is broken in FF5
                    document.location.href = url;
                } else {
                    var link = document.createElement('a');
                    if (link.setAttribute) {
                        link.setAttribute('href', url);
                        link.setAttribute('target', (target || '_top'));
                    } else {
                        link.href = url;
                        link.target = (target || '_top');
                    }
                    document.body.appendChild(link);
                    link.click();
                }
            } catch (e) {
                document.location.href = url;
            }
        }
    }
};

selectLanguage = SelectLanguage = function (o) {
    getURL(o.options[o.selectedIndex].value);
};

getScrollOffset = GetScrollOffset = function () {
    var x, y;
    if (self.pageYOffset) // all except Explorer
    {
        x = self.pageXOffset;
        y = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop)
    // Explorer 6 Strict
    {
        x = document.documentElement.scrollLeft;
        y = document.documentElement.scrollTop;
    }
    else if (document.body) // all other Explorers
    {
        x = document.body.scrollLeft;
        y = document.body.scrollTop;
    }
    return new Array(x, y);
};

getKeyCode = GetKeyCode = function (e) {
    var keycode;
    if (e == null) { // ie
        keycode = event.keyCode;
    } else { // mozilla
        keycode = e.which;
    }
    return keycode;
};

getKey = GetKey = function (e) {
    return String.fromCharCode(getKeyCode(e));
};

showElement = ShowElement = function (id) {
    var element = document.getElementById(id);
    if (element) {
        if (!element.style) element.style = new Object();
        element.style.display = 'block';
    }
};

hideElement = HideElement = function (id) {
    var element = document.getElementById(id);
    if (element) {
        if (!element.style) element.style = new Object();
        element.style.display = 'none';
    }
};

toggleElement = ToggleElement = function (id) {
    var element = document.getElementById(id);
    if (element) {
        if (!element.style) element.style = new Object();
        if (element.style.display == 'none')
            element.style.display = 'block';
        else
            element.style.display = 'none';
    }
};

if (!Array.prototype.push) {
    Array.prototype.push = function () {
        for (var i = 0; i < arguments.length; i++) {
            this[this.length] = arguments[i];
        }
        return this.length;
    }
}

if (!String.prototype.trim) {
    String.prototype.trim = function () {
        return this.replace(/^\s*/, "").replace(/\s*$/, "");
    }
}

init_shaded_buttons = function () {
    var input_elements = document.getElementsByTagName('INPUT');
    for (var i = 0; i < input_elements.length; i++) {
        var btn = input_elements[i];
        if (shaded_button_class != '' && btn.className && btn.className == shaded_button_class) {
            btn.onmouseover = function () { try { this.style.background = (eval('btn_bgcolor_over_' + this.id) || shaded_button_default_bgcolor); } catch (ex) { } };
            btn.onmouseout = function () { try { this.style.background = (eval('btn_bgcolor_' + this.id) || shaded_button_default_bgcolor_over); } catch (ex) { } };
            btn.onfocus = btn.onmouseover;
            btn.onblur = btn.onmouseout;
        }
    }
};

/* firefox error console */
var console; if (!console) console = {};
if (BrowserDetect && BrowserDetect.browser == 'Firefox') {
    console.do_log = function (text) {
        throw text;
    }
    console.log = function (text) {
        if (debug) window.setTimeout("console.do_log('" + jsEscape(text).replace(/\n/g, '') + "')", 1);
    }
} else {
    console.log = function (text) {
        if (debug) window.status = text;
    }
}

/* this will stop image flickering in IE6 when elements with images are moved */
try {
    if (document.execCommand)
        document.execCommand("BackgroundImageCache", false, true);
} catch (e) { };

/* load */
$(document).ready(function () {
    init_shaded_buttons();
    $("a[rel=lytebox]").fancybox({ 'titleShow': true });
    // GA tracking of email links
    $('A[href^="mailto:"]').click(function () { _gaq.push(['_trackPageview', '/mailto/' + escape($(this).attr('href').substring(7))]); });
    // booking comments
    $("FORM[name='bookingform3'] TEXTAREA#CLRemarks").keyup(function () {
        $(this).val($(this).val().substr(0, 100));
        $("FORM[name='bookingform3'] SPAN#charsleft").html(Math.max(100 - $(this).val().length, 0).toString());
    });
});

