﻿$(function () {
    //initializeFancyBox();
    //initializeMbContainers();
    initializeShoppingCart();
    searchElement();

    initializeRegister();
    initializeOrganizationInfoType();
});

function initializeRegister() {
    function switchRegistrationType() {
        var value = $("input[name=RegistrationType]:radio:checked");
        if (value == "Person") {
            $(".register.view fieldset:gt(0)").attr("style", "display: none;");
            $(".register.view fieldset:eq(3)").removeAttr("style");
        }
        else {
            $(".register.view fieldset").removeAttr("style");
        }
    }
    $(".register.view fieldset:gt(0)").attr("style", "display: none;");
    switchRegistrationType();
    $("input[name=RegistrationType]:radio").click(switchRegistrationType());
}

function initializeOrganizationInfoType() {
    function switchRegistrationType() {
        $(".register.view fieldset.OrganizationInfo > p").attr("style", "display: none;");
        var value = $("input[name=OrganizationInfoType]:radio:checked").val()

        if (value == "Form") {
            $(".register.view  fieldset.OrganizationInfo > p:lt(12)").removeAttr("style");
        } else if (value == "Document") {
            $(".register.view fieldset.OrganizationInfo > p:last").removeAttr("style");
        }
    }
    switchRegistrationType();
    $("input[name=OrganizationInfoType]:radio").click(switchRegistrationType);
}

function searchElement() {
    var searchField = $("#Query");
    if (!searchField.val()) 
    {
        searchField.addClass("off").val("Найти");
    }    
    searchField
        .focus(function () {
            if ($(this).hasClass("off")) {
                $(this).removeClass("off").val("")
            }
        })
        .blur(function () {
            if (!$(this).val().replace(/\s+/g, '')) {
                $(this).addClass("off").val("Найти")
            }
        });
}


function initializeShoppingCart() {
    $(".shopping-cart").shoppingCart({ buttonSelector: ".product input[type=button]" });
}

function liveInternetCounter() {
    document.write(
        "<a href='http://www.liveinternet.ru/click' "
        + "target=_blank><img src='http://counter.yadro.ru/hit?t52.6;r"
        + escape(document.referrer)
        + ((typeof (screen) == "undefined") ? "" : ";s"
        + screen.width
        + "*"
        + screen.height
        + "*"
        + (screen.colorDepth ? screen.colorDepth : screen.pixelDepth))
        + ";u"
        + escape(document.URL)
        + ";" + Math.random()
        + "' alt='' title='LiveInternet: показано число просмотров и посетителей за 24 часа' "
        + "border='0' width='88' height='31'><\/a>")
}
