﻿$(document).ready(function() {
    $("ul.mainmenu > li.other").removeClass("other").addClass("js-other");
    $("ul.mainmenu > li.js-other").click(function(event) {
        event.stopPropagation();
        if ($(this).find("ul.submenu").css("display") == "block")
            hideMoreItems();
        else {
            $(this).find("ul.submenu").css("display", "block");
            $("body").click(function() { hideMoreItems(); });
        }
    });

    function hideMoreItems() { $("ul.mainmenu ul.submenu").css("display", ""); $("body").unbind("click"); }

    if ($.browser.mozilla) {
        var a = String();
        a = $.browser.version;
        if (a.indexOf("1.8.1") > -1) {
            $("span.btn-box").after("<div class='clear' />");
        }
    }

    $("form.logon-right label:not(.check)").each(function() {
        $(this).addClass("active");
        var input = $("form.logon-right input[name='" + $(this).attr("for") + "']");
        input.addClass("active");
        if (input.val() != "")
        { $(this).css("visibility", "hidden"); }
    });

    function hideLabel(name) { $("label[for='" + name + "']").css("visibility", "hidden"); }
    function showLabel(name) { $("label[for='" + name + "']").css("visibility", "visible"); }
    $("form.logon-right input.text").focus(function() { hideLabel(this.name); });
    $("form.logon-right input.text").blur(function() { if (this.value == "") showLabel(this.name); });
    $("form.logon-right input.text").change(function() { if (this.value == "") showLabel(this.name); else hideLabel(this.name); });
});

function disableButton(buttonId) { $("#" + buttonId).attr("disabled", "disabled").closest("span.btn-box").addClass("disabled"); }
function disableButtonGrey(buttonId) {
    $("#" + buttonId).attr("disabled", "disabled").closest("span.btn-box").addClass("disabled");
    $("#" + buttonId).closest("span.btn-box").addClass("grey"); 
}
function enableButton(buttonId) { $("#" + buttonId).removeAttr("disabled").closest("span.btn-box").removeClass("disabled"); }

function showhide(elemId) {
    if (document.getElementById(elemId).style.visibility == "hidden") {
        document.getElementById(elemId).style.visibility = "visible";
    }
    else document.getElementById(elemId).style.visibility = "hidden";
    return false;
}

function showblock(elemId) {
    if (document.getElementById(elemId).style.display == "none") {
        document.getElementById(elemId).style.display = "block";
    }
    else document.getElementById(elemId).style.display = "none";
}

function hideblock(elemId) {
    document.getElementById(elemId).style.display = "none";
}

function changeimglink(elemId, imgsrc, img1, img2) {
    if (document.getElementById(elemId).style.display == "none") {
        document.getElementById(imgsrc).src = img1;
    }
    else {
        document.getElementById(imgsrc).src = img2;
    }
}

function hideallpopup() {
    $('.btn_register_required').each(function() {
        this.style.visibility = "hidden";
    });
    return false;
}

function hideallcommentform() {
    $('.comment_result').each(function() {
        this.style.visibility = "hidden";
    });
    return false;
}

function ResetPasswordRememberEmail(url) {
    document.getElementById("forgot_link").href = url + "?email=" + document.getElementById("username").value;
}

function LimitText(e, limitArea, limitCount, limitNum) {
    e = e || window.event;
    var target = e.target || e.srcElement;
    var code = e.keyCode ? e.keyCode : (e.which ? e.which : e.charCode)

    switch (code) {
        case 8:
        case 9:
        case 46:
        case 37:
        case 38:
        case 39:
        case 40:
            return true;
    }
    return target.value.length < limitNum;
}

function LimitCount(limitArea, limitCount, limitNum) {
    document.getElementById(limitCount).value = limitNum - document.getElementById(limitArea).value.length;
    if (document.getElementById(limitCount).value < 0) document.getElementById(limitCount).value = 0;
}

function ShowModal(a) {
	window.open(a.href, "termswindow", "toolbar=no,scrollbars=yes,resizable=no,status=no,width=600,height=400,top=50,left=50");
}
