function GetCities(county, elem_id) {
    var name = '';
    switch (elem_id) {
        case 'da_city' : name = 'da_city_id';
                        break;
        case 'pj_city' : name = 'pj_city_id';
                        break;
        case 'pf_city' :
        default        : name = 'pf_city_id';
    }

    $('#'+elem_id).load("index.php?__ajax=AjaxCities", {county_id : county, s_name : name}, function() {
                    $("#"+elem_id+" select")[0].focus();
                });
}

function ShowHideOtherCounty(hide, show_id, show) {

    $(hide).parent().css("display", "none");

    if (show == true) {
        $("#"+show_id+"_other_city").css("display", "block");
        $("#"+show_id+"_other_city_check").val(true);
    }
    else {
        $("#"+show_id+"_main_city").css("display", "block");
        $("#"+show_id+"_other_city_check").val(false);
    }
}

function ChangePerson(type) {

    if (type == 'pf') {
        $("input[name='person']").val('f');
    }
    else {
        $("input[name='person']").val('j');
    }
}

jQuery(document).ready(function() {
    if ($("#prod_tabs")[0]) {
        $("#prod_tabs p").click(function() {
            if ($(this).hasClass('tab_inactive')) {
                $("#prod_tabs p").addClass("tab_inactive");
                $(this).removeClass("tab_inactive");
                $("#prod_content > div").css("display", "none");
                $("#"+$(this).attr("activate")).css("display", "block");
            }
        });

        var tabs = $("#prod_tabs p");
        var left = 30;
        $(tabs[0]).css('left', left+'px');
        for (var i = 1; i < tabs.length; i++) {
            left += $(tabs[i-1]).width() - 7;
            $(tabs[i]).css('left', left+'px');
        }
    }
});

jQuery(document).ready(function () {
    if (jQuery("#prod_tabs") && self.document.location.hash == "#comments")
    {
        $("#prod_tabs p[activate='prod_comments']").click();
    }
});

var timer = 0;
jQuery(window).load(function() {
    if ($("#homepage")[0]) {
        $("#image1").css({'background-image': "url('"+images[0].src+"')", 'background-repeat': "no-repeat"});
        $("#image1").height($(document).height());
        $("#image2").height($(document).height());

        timer = setTimeout("slide()", 6000);
    }
});

function slide() {
    if (pos < (images.length - 1))
        pos++;
    else
        pos = 0;

    go_to(pos);
}

function go_to(position) {
    var new_bg = images[position].src;
    if ($("#image2").css("display") == "none") {
        $("#image2").css('background', "url('"+new_bg+"') no-repeat center 150px");
        $("#image1").fadeOut(1000);
        $("#image2").fadeIn(1000);
    }
    else {
        $("#image1").css('background', "url('"+new_bg+"') no-repeat center 150px");
        $("#image2").fadeOut(1000);
        $("#image1").fadeIn(1000);
    }

    $(".slide_btns a").removeClass("selected");
    $($(".slide_btns a")[position]).addClass("selected");

    pos = position;
    clearTimeout(timer);
    timer = setTimeout("slide()", 6000);
}

jQuery(document).ready(function () {
    if ($("#csl")[0]) {
        var as = $("#csl a");
        $(as[0]).css("display", "inline");

        window.setInterval("commercialSlide()", 4000);
    }
});

function commercialSlide() {
    var as = $("#csl a");
    for (var i = 0; i < as.length; i++)
        if ($(as[i]).css("display") != "none") {
            $(as[i]).fadeOut(500);
            if (i == (as.length - 1)) {
                $(as[0]).fadeIn(500);
            }
            else
               $(as[i+1]).fadeIn(500);

            break;
        }
}

jQuery(document).ready(function() {
    $("a#single_image").fancybox();

    $("a.inline").fancybox({
        'hideOnContentClick': true
    });

    $("a[rel=gallery]").fancybox({
        'transitionIn'    :    'elastic',
        'transitionOut'   :    'elastic',
        'speedIn'         :    600,
        'speedOut'        :    200,
        'overlayShow'     :    true,
        'titlePosition'   :    'inside'
    });
});

function ShowHideDA(elem) {
    if ($(elem).children("input")[0].checked)
        $('.da_details').css({display: 'none'});
    else
        $('.da_details').css({display: 'block'});
}

jQuery(document).ready(function() {
    if ($(".menu_categs")[0]) {
        $(".sub_parent").hover(
                function () {
                    $(this).find(".menu_categs").css('display', 'block');
                },
                function () {
                    $(this).find(".menu_categs").css('display', 'none');
                });
    }
});

/*jQuery(document).ready(function() {
    if ($("input[name='qs']")[0]) {
        $("input[name='qs']").focus(function () {
            $("#do_search_holder").css("display", "block");
        });
        $("input[name='qs']").blur(function (e) {
//            alert(e);
//            $("#do_search_holder").css("display", "none");
        });
    }
});*/

function ChangePage(url, disease) {
    if (disease > 0)
        document.location.href = base_href + url+"/sd:"+disease;
    else
        document.location.href = base_href + url;
}

jQuery(document).ready(function() {
    if ($(".promo_holder")[0]) {
        $(".promo_holder a").hover(
                function () {
                    $($($(this).parent()).children(".input_label")[0]).css("display", "block");
                },
                function () {
                    $($($(this).parent()).children(".input_label")[0]).css("display", "none");
                });
    }
});

function CAPage(page) {
    var selected = $(".page").index($(".active"));

    if (page == "prev") {
        if (selected == 0)
            return ;
        $($(".page")[selected-1]).fadeIn().addClass("active");
        $($(".page")[selected]).fadeOut().removeClass("active");
        selected--;
    }
    else if (page == "next") {
        if (selected == 3)
            return ;
        $($(".page")[selected+1]).addClass("active").fadeIn();
        $($(".page")[selected]).removeClass("active").fadeOut();
        selected++;
    }
    else if (page != selected) {
        $($(".page")[page]).addClass("active").fadeIn();
        $($(".page")[selected]).removeClass("active").fadeOut();
        selected = page;
    }

    $(".paginator span").removeClass("selected");
    $($(".paginator span")[selected]).addClass("selected");
}

$(document).ready(function() {
    if ($("#tv_icon")[0]) {
        $("#tv_icon").hover(function () {
            $(this).attr("src", $(this).attr("src").replace(".png", "2.png"));
        },
        function () {
            $(this).attr("src", $(this).attr("src").replace("2.png", ".png"));
        });
    }
});

$(document).ready(function() {
    if ($(".ptitle")[0]) {
        var max = 0;
        $(".ptitle").each(function () {
            if (max < $(this).height())
                max = $(this).height();
        });
        $(".ptitle").each(function () {
            if (max > $(this).height())
                $(this).height(max);
        });
    }

    if ($(".ptitle_top")[0]) {
        var max = 0;
        $(".ptitle_top").each(function () {
            if (max < $(this).height())
                max = $(this).height();
        });
        $(".ptitle_top").each(function () {
            if (max > $(this).height())
                $(this).height(max);
        });
    }
});

$(document).ready(function () {
    if ($("#left_promos")[0]) {
        if ($(".content_left")[0]) {
            var filled = $(".content_left").height();
        }
        else
            var filled = $(".right_wide").height();

        var height = ($(".content_wrapper").height() - filled + 50);
        $("#left_promos").load("index.php?__ajax=AjaxLeftPromos", {nr : height / 540});
    }
});

function FocusInput(elem) {
    var def_value = $(elem).attr("default");
    if (elem.value == def_value) {
        elem.value = "";
        if ($(elem).hasClass("password")) {
            elem.type = "password";
        }
    }
}
function BlurInput(elem) {
    var def_value = $(elem).attr("default");
    if (elem.value.length == 0) {
        elem.value = def_value;
        if ($(elem).hasClass("password"))
            elem.type = "text";
    }
}

$(document).ready(function() {
    if ($(".floating_categs")[0]) {
        $(".floating_categs").hover(
            function () {
                $(this).animate({left: '0px'}, 'fast');
            },
            function () {
                $(this).animate({left: '-160px'}, 'fast');
            });
    }
});

$(document).ready(function() {
    if ($(".pds_list")[0]) {
        $(".product").filter(":even").each(function() {
            var next = $(this).next('.product');
            if ($(next)[0] && $(this).height() != $(next).height()) {
                var max = Math.max($(this).height(), $(next).height()) - 10;
                $(this).find(".prod_center").height(max);
                $(next).find(".prod_center").height(max);
            }
        });
    }
});
