﻿var DTD = {
    is_iOS: function () {
        return (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i)) ? true : false;
    },
    isMac: function () {
        return navigator.appVersion.match(/Mac/i) ? true : false;
    },
    isWindows: function () {
        return navigator.appVersion.match(/Windows/i) ? true : false;
    },
    format_for_iOS: function () {
        if (DTD.is_iOS()) {
            $('div#mainWrap').css("padding-left", "30px");
            var windowWidth = $(window).width();
            var footerBackWidth = windowWidth > 1042 ? windowWidth : 1042;
            $("#footerBack").css("width", footerBackWidth + "px");

            var userNavBarWidth = windowWidth > 1042 ? windowWidth : 1042;
            $("#userNavBar").css("width", userNavBarWidth + "px");
        }
    },
    format_for_Mac: function () {
        if (DTD.isMac() && !DTD.is_iOS()) {
            $("div#findBox input").width(270);
            $("div#signUpBox input").width(240);
            $("div#createFormRightOverlay").height(323);
        }
    },
    resizeUserNavBar: function () {
        $("div#userNavBar").width(function () {
            if (!DTD.is_iOS()) {
                if ($(window).width() <= $("div#mainWrap").width()) {
                    $("div#userNavBar").css("padding-right", "10px");
                    $("div#footerBack").width($("div#mainWrap").width());
                    $("div#footerBack").css("padding-right", "10px");
                    return ($("div#mainWrap").width());
                } else {
                    $("div#userNavBar").css("padding-right", "0");
                    $("div#footerBack").width("100%");
                    $("div#footerBack").css("padding-right", "0");
                    return "100%";
                }
            }
        });
    },
    setupSignupBox: function () {
        $("#<%=txtSignUp.ClientID%>").keydown(function (e) {
            if (e.keyCode == 13)
                $("#<%=cmdSignUp.ClientID%>").click();
        });
    },
    setupOptionFlyOut: function () {
        $("div.sOptionFlyOutOverlay").attr("id", "optionFlyOutOverlay");
        $("div.sOptionFlyOut").attr("id", "optionFlyOut");

        $("div#optionFlyOutOverlay").click(function () {
            hideOptionFlyOut();
        });

        $("div#closeButtonContainer").click(function () {
            hideOptionFlyOut();
        });
    },
    setupToolTips: function () {
        //Get empty textboxes
        var emptyTextBoxes = $('input:text').filter(function () {
            return $(this).attr("title") != "" && !$(this).hasClass("excludeWatermark");
        });

        //Loop them
        emptyTextBoxes.each(function () {
            //Set focus
            $(this).focus(function () {
                if ($(this).val() == $(this).attr("title")) {
                    $(this).val("");
                    $(this).removeClass("instructions");
                }
            });

            //Set blur
            $(this).blur(function () {
                if ($(this).val() == "") {
                    $(this).val($(this).attr("title"));
                    $(this).addClass("instructions");
                }
            });

            //Initialize
            if ($(this).val() == "" || $(this).val() == $(this).attr("title")) {
                $(this).val($(this).attr("title"));
                $(this).addClass("instructions");
            }
        });
    }
};
