var Browser = new Object();
var ua = navigator.userAgent.toLowerCase();

var hotelAvailable = 0;

Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument!='undefined');
Browser.isIE      = window.ActiveXObject ? true : false;
Browser.isIE7     = (Browser.isIE && ua.indexOf("msie 7") != -1) ? true : false;
Browser.isFirefox = (ua.indexOf("firefox")!=-1);
Browser.isSafari  = (ua.indexOf("safari")!=-1);
Browser.isOpera   = (typeof window.opera != 'undefined');

try {
    if(typeof $ == "undefined") {
        var $ = function (elementId) {
            return document.getElementById(elementId);
        }
    }
} catch (exception) {
    dispatchException(exception);
}

var Environment = {};
Environment.isDev  = new RegExp("dev").test(window.location.host);
Environment.isLife = Environment.isDev ? false : true;

function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0, length = vars.length; i < length;i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
    }
}

if (!("console" in window) || !("firebug" in console)) {
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group",
                 "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
    window.console = {};
    for (var i = 0, length = names.length; i < length; ++i) {
        window.console[names[i]] = function() {};
    }
};

function dispatchException(e) {
    if (Environment.isDev) {
        if (Browser.isIE) {
            var fields = ["name", "message", "description", "fileName", "lineNumber", "number"];
            var string = "";
            for (key in fields) {
                if (fields[key] in e) {
                    string += fields[key] + ":" + e[fields[key]] + "\n";
                }
            }
            alert(string);
        } else {
            console.error(e);
        }
    }
};

var debugWindow = null;

function showYourself(object) {
    var string = " -- <u>" + typeof(object) + "</u> -- \n";
    for (var param in object) {
        if (typeof(object[param]) == "function") {
            continue;
        }
        string += "<b>"+param+ "</b> : "+ object[param]+"\n";
    }
    try {
        if (debugWindow == null) {
            debugWindow = window.open("", "DEBUG_WND", "width=800, height=600, scrollbars=yes, resizable=yes");
            debugWindow.document.write("<html><body></body></html>");
            debugWindow.document.close();
            debugWindow.onunload = function () {
                debugWindow = null;
            };
        }
        debugWindow.document.body.innerHTML = "<pre><div style='padding:3px;background: #ECECEC;border: 1px solid #C0C0C0'><span style='font-size: 11px;'>"+string+"</span></div></pre>"+debugWindow.document.body.innerHTML;
    } catch (e) {
        dispatchException(e);
    }
};

function elem(name, attrs, style, text) {
    var e = document.createElement(name);
    if (attrs) {
        for (key in attrs) {
            if (key == 'class') {
                e.className = attrs[key];
            } else if (key == 'id') {
                e.id = attrs[key];
            } else {
                e.setAttribute(key, attrs[key]);
            }
        }
    }
    if (style) {
        for (key in style) {
            e.style[key] = style[key];
        }
    };
    if (text) {
        e.appendChild(document.createTextNode(text));
    };
    return e;
};

var namespace = '';

function showTab() {
    $A($$('div[tab=' + $A($$('ul.tabs li.active')).first().removeClassName('active').id + ']')).first().hide();
    $A($$('div[tab=' + this.addClassName('active').id + ']')).first().show();
    
    if (this.id == 'flight') {
        namespace = '';
    } else {
        namespace = this.id + '__';
    }
}
document.observe && document.observe('dom:loaded', function() {
    var allTabCaptions = $$('#tabs li');
    $A(allTabCaptions).each(
        function(element) {
            element.observe('click', showTab);
        }
    );
}
);

function DD_OnClick_Button(containerName) {
    var containerControl = null;
    containerControl = document.getElementById(containerName);
    
    if (containerControl != 'undefined' ) {
        if (ddshowon(containerControl)) { 
            containerControl.style.visibility = "hidden";
            containerControl.style.display = "none";
        }
        else {
            containerControl.style.visibility = "visible";
            containerControl.style.display = "";
        }
    }
}
function DD_OnClick(containerName, valuedd, value) {
    var containerControl = null;
    value_DD_Name = "value_" + containerName;
    value = value || '';
    containerControl = document.getElementById(containerName);
    DDValue = document.getElementById(value_DD_Name);
    if (containerControl != 'undefined' && containerControl != null) {
        if (ddshowon(containerControl)) { 
            DDValue.innerHTML = valuedd;
            DDValue.setAttribute('value', value);
            containerControl.style.visibility = "hidden";
            containerControl.style.display = "none";
        }
        else {
            containerControl.style.visibility = "visible";
            containerControl.style.display = "";
        }
    }
}
function ddshowon(Element) {
    if (Element.style.visibility == "visible") {
        return true;
    }
    return false;
}