var is_child = false;

var child_window;

var wndName = 'childpuzzle';

$(document).ready(function ()

{

	var height_ = jQuery.fn.height;
	jQuery.fn.height = function() {
		if ( this[0] == window && jQuery.browser.opera && jQuery.browser.version >= 9.50)
			return window.innerHeight;
		else return height_.apply(this,arguments);
	};

	$('.db-block-more').css('display','none');
	$('.db-go-more').css('display','block');
	$('.db-go-more').click(function(){
		$('.db-go-more').slideUp();
		$('.db-block-more').slideDown();
		return false;
	});

    $('.footer .author a').attr('target', '_blank');

    var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");

    $('#getpuzzle').click(function ()

    {

        is_child = (window.opener != null);

        if (is_child) { }

        else {

            child_window = window.open('/puzzle.php', wndName, 'width=800,height=600');

        }

        return false;

    });

    /* Catalog slider */

    if ($(".catalog-slider-area").length)

    {

        var itemWidth = $(".catalog-slider-item").width() + 80;

        var step = 0;

        $('.catalog-tab').each(function ()

        {

            var areaLength = $('.catalog-slider-item', $(this)).length;

            $(this).find(".catalog-slider-area").width(areaLength * itemWidth);

            if (($(this).find(".catalog-slider-area").width() - $(this).find(".catalog-slider-wrapper").width()) < 45)

            {

                $(this).find(".catalog-slider-back").hide();

                $(this).find(".catalog-slider-next").hide();

            };

            $(this).hide();

        });

        $(".catalog-slider-next").click(function ()

        {

            if (step >= ($(this).parent().find(".catalog-slider-area").width() - $(this).parent().find(".catalog-slider-wrapper").width())) {

                step = 0;

                $(this).parent().find(".catalog-slider-area").animate({

                    left : 0

                });

            }

            else if ((step + itemWidth) > ($(this).parent().find(".catalog-slider-area").width() - $(this).parent().find(".catalog-slider-wrapper").width()))

            {

                step = step + itemWidth;

                $(this).parent().find(".catalog-slider-area").animate(

                {

                    left : "-" + ($(this).parent().find(".catalog-slider-area").width() - $(this).parent().find(".catalog-slider-wrapper").width())

                });

            }

            else

            {

                step = step + itemWidth;

                $(this).parent().find(".catalog-slider-area").animate({

                    left : "-" + step

                });

            };

        });

        $(".catalog-slider-back").click(function ()

        {

            if (step == 0)

            {

                step = $(this).parent().find(".catalog-slider-area").width() - $(this).parent().find(".catalog-slider-wrapper").width();

                $(this).parent().find(".catalog-slider-area").animate({

                    left : "-" + step

                });

            }

            else if (Math.round(step / itemWidth) != (step / itemWidth))

            {

                step = $(this).parent().find(".catalog-slider-area").width() - Math.round($(this).parent().find(".catalog-slider-wrapper").width()  / itemWidth) * itemWidth - itemWidth;

                $(this).parent().find(".catalog-slider-area").animate({

                    left : "-" + step

                });

            }

            else

            {

                step = step - itemWidth;

                $(this).parent().find(".catalog-slider-area").animate({

                    left : "-" + step

                });

            };

        });

    };

    /* Catalog item */

    if ($(".catalog-item").length)

    {

        var tab = "";

        if ($(".catalog-first-tab").length) {

            tab = ".catalog-first-tab";

        }

        else if ($(".catalog-second-tab").length) {

            tab = ".catalog-second-tab";

        };

        var tabObj = $(tab + ":eq(0)");

        if ($(".catalog-item-image.tetrapack", tabObj).length)

        {

            $(".catalog-item-go-to-recipe").show();

            $(".catalog-item-info").addClass("catalog-item-info-tetrapack");

            $(".catalog-item-recipe").hide();

            $(".catalog-item").addClass("bg-tetrapack").css({

                "background-position" : "50% -860px"

            });

            $(".go-to-tetrapack").hide();

            $(".go-to-bottle").show();

            $(".catalog-item-image.bottle").parent().hide();

            $(".side-bottle").parent().removeClass("catalog-item-description-pack-active");

            $(".side-tetrapack").parent().addClass("catalog-item-description-pack-active");

        };

        if ($(".catalog-item-image.bottle", tabObj).length) {

            $(".catalog-item-image.tetrapack").parent().hide();

        };

        if (!$(".catalog-first-tab").length || !$(".catalog-second-tab").length) {

            $(".go-to-tetrapack, .go-to-bottle").hide();

        }

        else

        {

            $(".go-to-bottle, .side-bottle").click(function ()

            {

                $(".catalog-item-go-to-recipe").hide();

                $(".catalog-item-info").removeClass("catalog-item-info-tetrapack");

                $(".catalog-item-recipe").show();

                $(".catalog-item").removeClass("bg-tetrapack").css({

                    "background-position" : "36% 140px"

                });

                $(".go-to-bottle").hide();

                $(".go-to-tetrapack").show();

                $(".catalog-item-image.bottle").parent().show();

                $(".catalog-item-image.tetrapack").parent().hide();

                $(".side-tetrapack").parent().removeClass("catalog-item-description-pack-active");

                $(".side-bottle").parent().addClass("catalog-item-description-pack-active");

                return false;

            });

            $(".go-to-tetrapack, .side-tetrapack").click(function ()

            {

                $(".catalog-item-go-to-recipe").show();

                $(".catalog-item-info").addClass("catalog-item-info-tetrapack");

                $(".catalog-item-recipe").hide();

                $(".catalog-item").addClass("bg-tetrapack").css({

                    "background-position" : "50% -860px"

                });

                $(".go-to-tetrapack").hide();

                $(".go-to-bottle").show();

                $(".catalog-item-image.bottle").parent().hide();

                $(".catalog-item-image.tetrapack").parent().show();

                $(".side-bottle").parent().removeClass("catalog-item-description-pack-active");

                $(".side-tetrapack").parent().addClass("catalog-item-description-pack-active");

                return false;

            });

        };

        if (type_pack == 1) {

            $(".go-to-tetrapack").click();

        };

        if (type_pack == 0) {

            $(".go-to-bottle").click();

        };

    };

	/*==MIK== New Catalog Breed*/
	$(".catalog").parent().parent().find(".breed").css("margin", "240px 0 25px");

    /* Catalog */

    if ($(".catalog").length)

    {

        setEqualHeight($(".catalog-eq"));

        $(".catalog-tab.visible").show();

        $(".catalog-menu").find("li:eq(0)").addClass("active").find("> em").css({

            "background-position" : "100% -35px"

        }).find("> ins").css({

            "background-position" : "0 0"

        });

        $(".catalog-menu ul").delegate("li:not(.active)", "click", function ()

        {

            $(this).addClass("active").siblings().removeClass("active").parents(".catalog-step").find(".catalog-tab").hide().eq($(this).index()).show().parents(".catalog").find(".catalog-intro span").hide().eq($(this).index()).show();

            $(this).find("> em").css({

                "background-position" : "100% -35px"

            }).find("> ins").css({

                "background-position" : "0 0"

            });

            $(this).siblings().find("> em").css({

                "background-position" : "0 -1000px"

            }).find("> ins").css({

                "background-position" : "0 -1000px"

            });

            step = 0;

            $(".catalog-slider-area").animate({

                left : 0

            });

        });

    };

    /* Catalog country */

    if ($(".catalog-country").length) {

        setEqualHeight($(".catalog-country-list > ins"));

    };



    /* About vine */

    if ($(".about-vine").length)

    {

        $(".about-vine-garsia-recipes-info-recipe-full").hide();

        $(".about-vine-garsia-recipes-item").hover( function ()

        {

            $(this).addClass("hover");

            $(this).find(".about-vine-garsia-recipes-info-recipe-full").show();

            $(this).find(".about-vine-garsia-recipes-info").css({

                background : "#fff"

            });

        },

        function ()

        {

            $(this).removeClass("hover");

            $(this).find(".about-vine-garsia-recipes-info-recipe-full").hide();

            $(this).find(".about-vine-garsia-recipes-info").css({

                background : "#fffef2"

            });

        } );

    };

    /* About vine recipes */

    if ($(".about-vine-recipes").length)

    {

        $(".about-vine-recipes-full").hide();

        $(".about-vine-recipes-item").hover( function ()

        {

            $(this).addClass("hover");

            $(this).find(".about-vine-recipes-full").show();

            $(this).find(".about-vine-recipes-info").css({

                background : "#fff"

            });

        },

        function ()

        {

            $(this).removeClass("hover");

            $(this).find(".about-vine-recipes-full").hide();

            $(this).find(".about-vine-recipes-info").css({

                background : "#fffef2"

            });

        } );

    };

    /* About vine master class */

    if ($(".about-vine-master").length)

    {

        $("#slider").easySlider();

        $(".about-vine-master-announce-show-all-slides").toggle( function ()

        {

            $(".about-vine-master-announce-wrap2").css({

                height : "auto"

            });

            $("#slider ul").css({

                width : "auto", "margin-left" : 0

            });

            $("#prevBtn").hide();

            $("#nextBtn").hide();

        },

        function ()

        {

            $(".about-vine-master-announce-wrap2").css({

                height : "450px"

            });

            $("#slider").easySlider();

        } );

    };

    /* About vine master class item */

    if ($(".about-vine-master-item").length)

    {

        if ($(".about-vine-master-item-slides-item").length)

        {

            var photoWidth = $(".about-vine-master-item-slides-item").width();

            $(".about-vine-master-item-slides-item a, .about-vine-master-item-slides-item img").width(photoWidth).height(photoWidth * 0.63).css({

                display : "block"

            });

        };

        setEqualHeight($(".about-vine-master-item-slides > .about-vine-master-item-slides-item"));

        $(".about-vine-master-item-slides-item").hide();

        var i;

        for (i = 0; i <= 2; i++) {

            $(".about-vine-master-item-slides-item:eq(" + i + ")").show();

        };

        $(".about-vine-master-item-show-all-slides").toggle( function ()

        {

            $(".about-vine-master-item-info").animate({

                width : "30%"

            });

            $(".about-vine-master-item-slides").animate({

                width : "68%"

            }).addClass("about-vine-master-item-slides-all").find(".about-vine-master-item-slides-item").show();

            $(this).find("span").replaceWith("<span>Скрыть все слайды</span>");

        },

        function ()

        {

            $(".about-vine-master-item-info").animate({

                width : "60%"

            });

            $(".about-vine-master-item-slides").removeClass("about-vine-master-item-slides-all").animate({

                width : "38%"

            }).find(".about-vine-master-item-slides-item").hide();

            $(this).find("span").replaceWith("<span>Показать все слайды</span>");

            for (i = 0; i <= 2; i++) {

                $(".about-vine-master-item-slides-item:eq(" + i + ")").show();

            };

        } );

    }

    if ($(".company-sidebar").length)

    {

        if ($(".company-sidebar-photos-item").length)

        {

            var photoWidth = $(".company-sidebar-photos-item").width();

            $(".company-sidebar-photos-item a, .company-sidebar-photos-item img").width(photoWidth).height(photoWidth * 0.63).css({

                display : "block"

            });

        };

        var companyPhotosMinHeight = 0;

        var companyPhotosHeight = 0;

        var i = 0;

        $(".company-sidebar-photos-item").each(function ()

        {

            if (i < 3) {

                i++;

                companyPhotosMinHeight = companyPhotosMinHeight + $(this).height() + 11 + 15;

            }

            companyPhotosHeight = companyPhotosHeight + $(this).height() + 11 + 15;

        });

        $(".company-sidebar-photos").css({

            height : companyPhotosMinHeight + "px"

        });

        $(".company-sidebar-photos-show-all-slides").toggle( function ()

        {

            $(".company-sidebar-photos").animate({

                height : companyPhotosHeight + "px"

            });

            $(".company-sidebar-photos").addClass("open");

            $(this).find("span").replaceWith("<span>Скрыть все слайды</span>");

        },

        function ()

        {

            $(".company-sidebar-photos").animate({

                height : companyPhotosMinHeight + "px"

            });

            $(".company-sidebar-photos").removeClass("open");

            $(this).find("span").replaceWith("<span>Показать все слайды</span>");

        } );

    };

    /* Company */

    if ($(".company").length)

    {

        var photosHeight = $(".company-photos ul").height();

        $(".company-photos ul").css({

            height : "112px"

        });

        $(".company-show-all").toggle( function ()

        {

            $(".company-photos ul").animate({

                height : photosHeight + "px"

            });

            $(this).find("span").replaceWith("<span>Скрыть все фото</span>");

        },

        function ()

        {

            $(".company-photos ul").animate({

                height : "112px"

            });

            $(this).find("span").replaceWith("<span>Показать все фото</span>");

        } );

    };

    /* Company partners */

    if ($(".company-partners").length) {

        setEqualHeight($(".company-partners-list li"));

    };

    /* Presentation */

    if ($(".presentation").length)

    {

        var clientHeight = $("body").height() - $(".attention").height() - 20;

        var presCount = $(".presentation-item").length;

        var presItemWidth = 865;

        var presArea = presCount * presItemWidth;

        var presAreaPos = 0;

        $(".presentation, .overlay").css({

            display : "none"

        });

        $(".presentation-start").click(function ()

        {

            $(".presentation, .overlay").css({

                display : "block"

            });

            $(".presentation-area").css({

                left : 0

            });

            return false;

        });

        $(".overlay").css({

            height : clientHeight + "px"

        });

        $(".presentation-close, .overlay, .attention").click(function ()

        {

            $(".presentation, .overlay").css({

                display : "none"

            });

        });

        $(".presentation-begin-link").hide();

        $(".presentation-area").width(presArea);

        function presentationNext()

        {

            if (presAreaPos < presArea - presItemWidth)

            {

                presAreaPos = presAreaPos + presItemWidth;

                $(".presentation-area").animate({

                    left : "-" + presAreaPos + "px"

                });

                if (presAreaPos == presArea - presItemWidth) {

                    $(".presentation-begin-link").show();

                    $(".presentation-next-link").hide();

                };

                return false;

            }

            else

            {

                $(".presentation-area").animate({

                    left : 0

                });

                $(".presentation-begin-link").hide();

                $(".presentation-next-link").show();

                presAreaPos = 0;

                return false;

            };

        };

        function presentationBack()

        {

            if (presAreaPos > 0)

            {

                presAreaPos = presAreaPos - presItemWidth;

                $(".presentation-area").animate({

                    left : "-" + presAreaPos + "px"

                });

                return false;

            }

            else {

                return false;

            };

        };

        $(".presentation-next, .presentation-begin").click(presentationNext);

        $(".presentation-back").click(presentationBack);

    };

    /* Company partners */

    if ($(".client-files-list").length) {

        setEqualHeight($(".client-files-list li"));

    };

    /* Client order */

    /*

    if ($(".form-client-order").length){

        if(badBrowser){

            var indicatorWidth = 126;

        } else {

            var indicatorWidth = ($(".form-client-order-text").parent().width() - 22);

        };

        $(".form-client-order-text").width(indicatorWidth);

        $(".form-client-order").find("textarea").width(indicatorWidth);

    };

    */

    /* Client regions */

    if ($(".client-regions").length)

    {

        setEqualHeight($(".client-regions-list-item li"));

        $(".client-regions-list-item").hide();

        $(".client-regions-list-item:eq(0)").show();

        $(".client-regions-list > ul > li > a").click(function ()

        {

            $(this).parent().parent().find(".client-regions-list-item").slideUp();

            $(this).parent().find(".client-regions-list-item").stop(false, false).fadeIn();

            return false;

        });

        if (badBrowser)

        {

            $(".client-regions-list-item ul").each(function ()

            {

                $(this).find("> li").each(function ()

                {

                    var pos = $(this).index() + 1;

                    var a = pos  / 2;

                    var b = parseInt(pos  / 2);

                    if ((b - a) == 0) {

                        $(this).addClass("break");

                    };

                });

            });

            $(".break").after('<li style=\"background: none; border: none; clear: both; float: none; height: 2px; margin: 0; overflow: hidden; padding: 0; width: 100%;\"></li>');

        };

    };

    /* Consultant */

    if ($(".consultant").length)

    {

        $(".consultant-item .faq-answer").hide();

        $(".consultant-item .faq-quest").click(function ()

        {

            $(".consultant-item .faq-quest").css({

                "font-size" : "18px"

            }).parent().find(".faq-answer").hide();

            $(this).css({

                "font-size" : "21px"

            }).parent().find(".faq-answer").show();

            $('html:not(:animated)').animate({

                scrollTop : $(this).offset().top - 20

            },

            500, "swing");

            return false;

        });

        $(".consultant-item .faq-quest:eq(0)").css({

            "font-size" : "21px"

        }).parent().find(".faq-answer").show();

    };

    function s_keyPress(evt)

    {

        evt = (evt) ? evt : (window.event) ? window.event : "";

        if (evt.keyCode == 13) {

            CheckUserForm();

        }

    }

    var in_pass = document.getElementById('password');

    if (in_pass != null) {

        in_pass.onkeypress = s_keyPress;

    }

    var in_login = document.getElementById('login');

    if (in_login != null) {

        in_login.onkeypress = s_keyPress;

    }

    $('#auto_subm').click(function ()

    {

        CheckUserForm();

    });

    function subs_keyPress(evt)

    {

        evt = (evt) ? evt : (window.event) ? window.event : "";

        if (evt.keyCode == 13) {

            checkSubscribe();

        }

    }

    var in_email = document.getElementById('subscribe_email');

    if (in_email != null) {

        in_email.onkeypress = subs_keyPress;

    }

    $(".catalog-item-response-add .form-client-order").hide();

    if ($(".form-client-order").length)

    {

        $(".add-comment, .catalog-item-response-add a, .newcomm").click(function ()

        {

            if (badBrowser) {

                $(".catalog-item-response-add").css({

                    width : "auto"

                });

            }

            else {

                $(".catalog-item-response-add").css({

                    width : "100%"

                });

            };

            $('.form-client-order').slideDown();

            $('html:not(:animated)').animate({

                scrollTop : $(".form-client-order").offset().top - 100

            },

            500, "swing");

            $(".catalog-item-response-add a").hide();

            return false;

        });

    };

    if ($("#contact_agree").length) {

        $("#contact_agree").css({

            width : "auto"

        }).parent().css({

            margin : "0 0 22px 0"

        });

    };

});

/* Functions */

function setEqualHeight(columns)

{

    var tallestcolumn = 0;

    columns.each(function ()

    {

        currentHeight = $(this).height();

        if (currentHeight > tallestcolumn) {

            tallestcolumn = currentHeight;

        }

		//alert(currentHeight);

    });



    columns.height(tallestcolumn);

}

/* Resize */

$(window).resize(function ()

{

    if ($(".catalog-slider-area").length)

    {

        $('.catalog-tab').each(function ()

        {

            if (($(this).find(".catalog-slider-area").width() - $(this).find(".catalog-slider-wrapper").width()) < 45)

            {

                $(this).find(".catalog-slider-back").hide();

                $(this).find(".catalog-slider-next").hide();

            }

            else

            {

                $(this).find(".catalog-slider-back").show();

                $(this).find(".catalog-slider-next").show();

            };

        });

    };

    if ($(".catalog-country").length)

    {

        $(".catalog-country-list > ins").each(function ()

        {

            $(this).height("auto");

        });

        setEqualHeight($(".catalog-country-list > ins"));

    };

    if ($(".catalog-country-item").length)

    {

        $(".catalog-country-item-list > ins").each(function ()

        {

            $(this).height("auto");

        });

        setEqualHeight($(".catalog-country-item-list > ins"));

    };

    if ($(".about-vine-master-item").length)

    {

        setEqualHeight($(".about-vine-master-item-slides > .about-vine-master-item-slides-item"));

    };

    if ($(".company-sidebar").length)

    {

        $(".company-sidebar-photos-item img").css({

            width : "100%", height : "auto"

        });

        var companyPhotosMinHeight = 0;

        var companyPhotosHeight = 0;

        var i = 0;

        $(".company-sidebar-photos-item").height('auto');

        $(".company-sidebar-photos-item").each(function ()

        {

            if (i < 3) {

                i++;

                companyPhotosMinHeight = companyPhotosMinHeight + $(this).height() + 10 + 15;

            }

            companyPhotosHeight = companyPhotosHeight + $(this).height() + 10 + 15;

        });

        if ($(".company-sidebar-photos").hasClass("open")) {

            $(".company-sidebar-photos").css({

                height : companyPhotosHeight + "px"

            });

        }

        else {

            $(".company-sidebar-photos").css({

                height : companyPhotosMinHeight + "px"

            });

        };

    };

    if ($(".overlay").length)

    {

        var clientHeight = $("body").height() - $(".attention").height() - 20;

        $(".overlay").css({

            height : clientHeight + "px"

        });

    };

    /*

    if ($(".form-client-order").length){

        var indicatorWidth = ($(".form-client-order-text").parent().width() - 22);

        $(".form-client-order-text").width(indicatorWidth);

        $(".form-client-order").find("textarea").width(indicatorWidth);

    };

    */

    if ($("#contact_agree").length) {

        $("#contact_agree").css({

            width : "auto"

        });

    };

});

function spaces(str)

{

    var patt = eval("/[\\s]{" + str.length + "}/");

    return !str.search(patt);

}

function checkCommentsForm() {
    if (spaces($('#user-name').val())) {
        $('#user-name').parent().css('background', 'rgb(255,0,0)');
        return false;
    }
    else {
        $('#user-name').parent().attr('style', '');
    }

	if ($('#user-email').length) {
		var regemail = new RegExp("^[0-9a-z_\.\-]+@[0-9a-z_\-]+\\.[a-z]{2,6}$", 'i');
		if (spaces($('#user-email').val()) || !regemail.test($('#user-email').val())) {
			$('#user-email').parent().css('background', 'rgb(255,0,0)');
			return false;
		}
		else {
			$('#user-email').parent().attr('style', '');
		}
	}

	if ($('#user-phone').length) {
		var regemail = new RegExp("^[\+]{0,1}[0-9 \-]+$", 'i');
		if ($('#user-phone').val() && !regemail.test($('#user-phone').val())) {
			$('#user-phone').parent().css('background', 'rgb(255,0,0)');
			return false;
		}
		else {
			$('#user-phone').parent().attr('style', '');
		}
	}

    if (spaces($('#user-text').val())) {
        $('#user-text').parent().css('background', 'rgb(255,0,0)');
        return false;
    }
    else {
        $('#user-text').parent().attr('style', '');
    }

    $.post('/comments.php', {
        name : $('#user-name').val(),
		email : $('#user-email').val(),
		phone : $('#user-phone').val(),
		text : $('#user-text').val(),
		id : $('#news-id').val(),
		tree_id : $('#tree-id').val()
    },
    function ( data ) {
        $('#user-name').val('');
        $('#user-text').val('');
		$('#user-email').val('');
		$('#user-phone').val('');
        if (data == 1) {
            alert('Комментарий добавлен успешно.');
        }
    } );

    return true;
}

function checkMail(email)

{

    var pat = /^[\w-+\.]+@([\w-]+\.)+[\w-]{2,}$/i;

    if (pat.test(email)) {

        return true;

    }

    else {

        return false;

    }

}

function check_feedback_form()

{

    if ($('#contact_name').val() == '' || $('#contact_name').val() == 'Имя, фамилия') {

        $('#contact_name').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#contact_name').parent().attr('style', '');

    }

    if (!checkMail($('#contact_email').val())) {

        $('#contact_email').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#contact_email').parent().attr('style', '');

    }

    if ($('#contact_message').val() == '' || $('#contact_message').val() == 'Текст вопроса') {

        $('#contact_message').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#contact_message').parent().attr('style', '');

    }

    return true;

}

function checkOrderForm()

{

    if ($('#contact_name').val() == '') {

        $('#contact_name').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#contact_name').parent().attr('style', '');

    }

    if ($('#contact_phone').val() == '') {

        $('#contact_phone').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#contact_phone').parent().attr('style', '');

    }

    if (!checkMail($('#contact_email').val())) {

        $('#contact_email').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#contact_email').parent().attr('style', '');

    }

    return true;

}

function checkRegForm()

{

    if ($('#name_company').val() == '') {

        $('#name_company').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#name_company').parent().attr('style', '');

    }

    if ($('#activity').val() == '') {

        $('#activity').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#activity').parent().attr('style', '');

    }

    if ($('#city').val() == '') {

        $('#city').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#city').parent().attr('style', '');

    }

    if ($('#address').val() == '') {

        $('#address').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#address').parent().attr('style', '');

    }

    if ($('#contact_name').val() == '') {

        $('#contact_name').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#contact_name').parent().attr('style', '');

    }

    if ($('#contact_phone').val() == '') {

        $('#contact_phone').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#contact_phone').parent().attr('style', '');

    }

    if (!checkMail($('#contact_email').val())) {

        $('#contact_email').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#contact_email').parent().attr('style', '');

    }

    if ($('#contact_login').val() == '') {

        $('#contact_login').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#contact_login').parent().attr('style', '');

    }

    if ($('#contact_passw').val() == '') {

        $('#contact_passw').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#contact_passw').parent().attr('style', '');

    }

    if (!($('#contact_agree').is(':checked'))) {

        $('#contact_agree').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#contact_agree').parent().attr('style', 'width:100%');

    }

    if ($('#contact_passw2').val() != $('#contact_passw').val()) {

        alert('Пароли не совпадают');

        return false;

    }

    $.post('/user.php', {

        action : 'check', login : $('#contact_login').val(), email : $('#contact_email').val()

    },

    function ( data )

    {

        checks = data;

        if (data == 1)

        {

            alert('Пользователь с таким email уже существует');

            $('#contact_email').val();

            $('#contact_email').focus();

            return false;

        }

        else if (data == 2)

        {

            alert('Пользователь с таким login уже существует');

            $('#contact_login').val();

            $('#contact_login').focus();

            return false;

        }

        else if (data == 0)

        {

            alert('Благодарим Вас за регистрацию на сайте garsia.by. Менеджер компании GARSIA свяжется с вами в ближайшее время для подтверждения регистрации.');

            document.feedback.submit();

        }

        else {

            document.feedback.submit();

        }

    } );

    return false;

}

function CheckUserForm()

{

    if ($('#login').val() == '' || $('#login').val() == 'имя') {

        $('#login').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#login').parent().attr('style', '');

    }

    if ($('#password').val() == '' || $('#password').val() == 'пароль') {

        $('#password').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#password').parent().attr('style', '');

    }

    $.post('/user.php', {

        action : 'login', name : $('#login').val(), pass : $('#password').val()

    },

    function ( data )

    {

        $('#login').val('имя');

        $('#password').val('пароль');

        if (data == 1)

        {

            location.href = $('#cabinet_url').val();

            /*                if (location.href.indexOf('cooperation') > 0) {                    location.href

            = location.href;                }                else {                    $('#not_log').hide();

                   $('#log').show();                }*/

        }

        else {

            alert('Такого пользователя не существует');

        }

    } );

    return true;

}

function checkSubscribe()

{

    if (!checkMail($('#subscribe_email').val())) {

        $('#subscribe_email').parent().css('background', 'rgb(255,0,0)');

        return false;

    }

    else {

        $('#subscribe_email').parent().attr('style', '');

    }

    $.post('/check_subscribe.php', {

        action : 'check', val : $('#val').val(), email : $('#subscribe_email').val()

    },

    function ( data )

    {

        if (data != '')

        {

            $('#inline_example').html(data);

            $.fn.colorbox({

                width : "50%", inline : true, href : "#inline_example"

            });

        }

    } );

    return true;

}

function userAgreementShow()

{

    $.fn.colorbox({

        width : "50%", inline : true, href : "#user_agreement"

    });

}

function subscribe()

{

    var t1 = 1;

    if ($('#subscribe1').is(':checked') == false) {

        t1 = 0;

    }

    var t2 = 1;

    if ($('#subscribe2').is(':checked') == false) {

        t2 = 0;

    }

    var t3 = 1;

    if ($('#subscribe3').is(':checked') == false) {

        t3 = 0;

    }

    var t4 = 1;

    if ($('#subscribe4').is(':checked') == false) {

        t4 = 0;

    }

    var t5 = 1;

    if ($('#subscribe5').is(':checked') == false) {

        t5 = 0;

    }

    var t6 = 1;

    if ($('#subscribe6').is(':checked') == false) {

        t6 = 0;

    }

    var stype = 1;

    if ($('input[name=subhtml]').filter(':checked').length > 0) {

        stype = $('input[name=subhtml]').filter(':checked').val();

    }

    $.post('/check_subscribe.php',

    {

        action : 'subscribe', val : $('#val').val(), email : $('#subscribe_email').val(), t1 : t1, t2 : t2,

        t3 : t3, t4 : t4, t5 : t5, t6 : t6, stype : stype

    },

    function ( data )

    {

        if (data != '') {

            $.fn.colorbox.close()

        }

    } );

}

function Exit()

{

    $.post('/user.php', {

        action : 'logout', name : $('#login').val(), pass : $('#password').val()

    },

    function ( data )

    {

        location.href = '/';

        /*            if (location.href.indexOf('cooperation') > 0) {                location.href = location.href;

           }            else {                $('#login').val('имя');                $('#password').val('пароль');

               $('#not_log').show();                $('#log').hide();            }*/

    } );

    return true;

}

function feedformval(formid, blockid)

{

    if (!formid || !blockid || !$('#' + formid).length || !$('#' + blockid).length) {

        return;

    }

    $('#' + blockid).append('<input name="ajax" value="" type="hidden" />');

    $(function ()

    {

        var form = $("#" + formid);

        var fio = $('input[name=fio]', form);

        var email = $('input[name=email]', form);

        var answer = $('input[name=answer]', form);

        var msg = $('textarea[name=message]', form);

        var btn = $('input[type=submit]', form);

        if (answer.length > 0 && btn.length == 1)

        {

            btn.attr('disabled', 'disabled').addClass('disabled');

            answer.bind('keyup paste blur change', function ()

            {

                checkFormError(answer, new Array('radio'));

                checkSubmitBtn(btn, new Array(answer));

            });

            form.submit(function ()

            {

                $('#' + formid + ' input:submit').attr('disabled', 'disabled').addClass('disabled');

                $.post( '/voting.php', $( "#" + formid ).serializeArray(), function (data)

                {

                    var form = $( '#' + formid );

                    $( '.valid', form ).removeClass('valid');

                    $( 'label.error', form ).remove();

                    $( '.error', form ).removeClass('error');

                    document.getElementById( formid ).reset();

                    var text = $('page', data).text();

                    if ($("#vote-block").length == 1) {

                        $("#vote-block").remove();

                    }

                    $("#vote-box").append(text);

                });

                return false;

            });

        }

    });

}

function nextVoiting()

{

    $.post( '/voting.php', {

        nextvote : '1'

    },

    function (data)

    {

        var text = $('page', data).text();

        if ($("#vote-block").length == 1) {

            $("#vote-block").remove();

        }

        $("#vote-box").append(text);

    });

    return false;

}

function checkFormError(obj, arr)

{

    var errorFlag = false;

    var errorText = '';

    for (c = 0; c < arr.length; c++)

    {

        if (arr[c] == 'radio' && obj.filter(":checked").val().length < 1) {

            errorFlag = true;

            errorText = 'Поле обязательно для заполнения';

        }

        if (arr[c] == 'required' && obj.val().length < 1) {

            errorFlag = true;

            errorText = 'Поле обязательно для заполнения';

        }

        var regemail = new RegExp("^[0-9a-z_]+@[0-9a-z_^\\.]+\\.[a-z]{2,6}$", 'i');

        if (arr[c] == 'email' && ((obj.val().length < 1) || (!regemail.test(obj.val())))) {

            errorFlag = true;

            errorText = 'Некорректный e-mail';

        }

        if (arr[c] == 'number' && parseInt(obj.val()) != obj.val()) {

            errorFlag = true;

            errorText = 'Введите число';

        }

        if (arr[c].indexOf('min') == 0 && parseInt(obj.val()) < arr[c].substr(3, arr[c].length - 3))

        {

            errorFlag = true;

            errorText = 'Число не меньше <a href="#" onmousedown="pasteErrorValue(this);" onclick="return false;">' + arr[c].substr(3,

            arr[c].length - 3) + '</a>';

        }

        if (arr[c].indexOf('max') == 0 && parseInt(obj.val()) > arr[c].substr(3, arr[c].length - 3))

        {

            errorFlag = true;

            errorText = 'Число не больше <a href="#" onmousedown="pasteErrorValue(this);" onclick="pasteErrorValue(this); return false;">' + arr[c].substr(3,

            arr[c].length - 3) + '</a>';

        }

        if (arr[c].indexOf('file_') == 0)

        {

            errorFlag = false;

            var val = obj.val();

            var extensions = arr[c].split(' ');

            var badExtension = true;

            for (j = 0; j < extensions.length; j++) if (extensions[j].indexOf('file_') == 0)

            {

                var checkExt = extensions[j].substr(5, extensions[j].length - 5);

                var fileExt;

                var posExt = val.lastIndexOf('.');

                if (posExt >= 0) {

                    fileExt = val.substr(posExt + 1, val.length - posExt - 1);

                }

                if (fileExt) {

                    fileExt = fileExt.toLowerCase();

                }

                if (fileExt == checkExt) {

                    badExtension = false;

                }

            }

            if (badExtension) {

                errorFlag = true;

                errorText = 'Выбранный Вами тип файла не поддерживается.';

            }

        }

    }

    if (errorFlag) {

        if (!obj.hasClass('error')) {

            obj.removeClass('valid').addClass('error');

        }

        else { }

    }

    else

    {

        if (!obj.hasClass('valid'))

        {

            obj.removeClass('error').addClass('valid');

            $('label[for=' + obj.attr('name') + ']').remove();

        }

    }

    return errorFlag;

}

function checkSubmitBtn(btn, arr)

{

    var errorFlag = false;

    for (c = 0; c < arr.length; c++) {

        if (!arr[c].hasClass('valid')) {

            errorFlag = true;

        }

    }

    if (!errorFlag) {

        btn.removeAttr('disabled').removeClass('disabled');

    }

    else

    {

        btn.attr('disabled', 'disabled');

        if (!btn.hasClass('disabled')) {

            btn.addClass('disabled');

        }

    }

}

