function setCookie (name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function changeVal(objV, str)
{

    if(objV.value == '')
        objV.value = str;
}

function ajax_po() {
    $(".fields input[name='phone'],.fields input[name='companyName'],.fields input[name='namefamiliya'],.fields input[name='Email'],.fields input[name='addressResource'],.fields textarea").focus();
    var options = {
        beforeSubmit: showRequest,
        success: showResponse,
        timeout: 0
    };
    $('#formzvk').attr({
        'action':$(".frmcuract").val()
    });
    $('#formzvk').ajaxSubmit(options);
}
function showRequest(formData, jqForm, options) {
    return true;
}

function showResponse(responseText, statusText)  {
    if (responseText.indexOf('следующие ошибки') + 1) {
        jAlert(responseText);
    } else {
        jQuery('#formzvk').slideToggle('slow');
        jAlertB(responseText);
    }

}


jQuery(document).ready(function() {
    if (document.getElementById('mycarouselB'))
        jQuery('#mycarouselB').jcarousel({
            scroll: 1
        });
    jQuery(".bottomBorder").find("table").find("tr:last").attr({
        'class':'last'
    });
    //horiz_main_menu
    $(".vertical_main_menu > ul > li").hover(function() {	//On hover...
        $(this).addClass("hove");
    //$(this).find("ul:first").show('slow');
    } , function() { //On hover out...
        $(this).removeClass("hove");
    //$(this).find("ul:first").hide('slow');
    });

    $(".pubmfile input").change(function() {
        //$(this).parent(".listZ").find('input').change();
        $(this).parent(".pubmfile").parent(".listZ").find("span").html($(this).attr('value'));
    });

    $(".pubm").click(function() {
        //alert();
        if ($(this).parent(".listZ").find('ul').css("display")=='none') {
            $.each( $(".listZ") , function () {
                if ($(this).attr('id')=='nc') {
                    imagehide = 'numberclumber';
                } else if ($(this).attr('id')=='mc') {
                    imagehide = 'mecclumber';
                } else if ($(this).attr('id')=='fileZ'){
                    imagehide = 'filefield';
                } else {
                    if($(this).hasClass('error')) {
                        imagehide = 'textfield_error';
                    } else {
                        imagehide = 'textfield';
                    }
                }
                $(this).css({
                    "background":"url('../images/"+imagehide+".png') no-repeat"
                }).find("ul").hide("slow");

            });

            $(this).parent(".listZ").find('ul').show("fast");
            if ($(this).parent(".listZ").attr('id')=='nc') {
                image = 'listnoact-nc';
            } else if ($(this).parent(".listZ").attr('id')=='mc') {
                image = 'listnoact-mc';
            } else {
                if($(this).parent(".listZ").hasClass('error')) {
                    image = 'listnoact_error';
                } else {
                    image = 'listnoact';
                }
            }
            $(this).parent('.listZ').css({
                "background":"url('../images/"+image+".png') no-repeat "
            });
        } else {
            $(this).parent(".listZ").find('ul').hide("slow");
            if ($(this).parent(".listZ").attr('id')=='nc') {
                imageB = 'numberclumber';
            } else if ($(this).parent(".listZ").attr('id')=='mc') {
                imageB = 'mecclumber';
            } else {
                imageB = 'textfield';
            }
            $(this).parent('.listZ').css({
                "background":"url('../images/"+imageB+".png') no-repeat"
            });
        }
    });
    $(".listZ a").click(function() {
        $(this).parent("li").parent("ul").parent(".listZ").find("span").html($(this).html());
        nnm = $(this).parent("li").parent("ul").parent(".listZ").find("span").attr('class');
        $("input[name='"+nnm+"']").val($(this).html());
        $(this).parent("li").parent("ul").parent(".listZ").find('ul').hide("slow");
        if ($(this).parent("li").parent("ul").parent(".listZ").attr('id')=='nc') {
            imageС = 'numberclumber';
        } else if ($(this).parent("li").parent("ul").parent(".listZ").attr('id')=='mc') {
            imageС = 'mecclumber';
        } else {
            imageС = 'textfield';
        }
        $(this).parent("li").parent("ul").parent('.listZ').css({
            "background":"url('../images/"+imageС+".png') no-repeat"
        });
        return false;
    });
    $(".fields input, .fields textarea").click(function() {
        $.each( $(".listZ") , function () {
            if ($(this).attr('id')=='nc') {
                imagehide = 'numberclumber';
            } else if ($(this).attr('id')=='mc') {
                imagehide = 'mecclumber';
            } else if ($(this).attr('id')=='fileZ'){
                imagehide = 'filefield';
            } else {
                imagehide = 'textfield';
            }
            $(this).css({
                "background":"url('../images/"+imagehide+".png') no-repeat"
            }).find("ul").hide("slow");

        });
    });
    $(".fields span").click(function() {
        if ($(this).parent(".listZ").find('ul').css("display")=='none') {

            $.each( $(".listZ") , function () {
                if ($(this).attr('id')=='nc') {
                    imagehide = 'numberclumber';
                } else if ($(this).attr('id')=='mc') {
                    imagehide = 'mecclumber';
                } else if ($(this).attr('id')=='fileZ'){
                    imagehide = 'filefield';
                } else {
                    if($(this).hasClass('error')) {
                        imagehide = 'textfield_error';
                    } else {
                        imagehide = 'textfield';
                    }
                }
                $(this).css({
                    "background":"url('../images/"+imagehide+".png') no-repeat"
                }).find("ul").hide("slow");

            });

            $(this).parent(".listZ").find('ul').show("fast");
            if ($(this).parent(".listZ").attr('id')=='nc') {
                image = 'listnoact-nc';
            } else if ($(this).parent(".listZ").attr('id')=='mc') {
                image = 'listnoact-mc';
            } else {
                if($(this).parent(".listZ").hasClass('error')) {
                    image = 'listnoact_error';
                } else {
                    image = 'listnoact';
                }
            }
            $(this).parent('.listZ').css({
                "background":"url('../images/"+image+".png') no-repeat"
            });
        } else {
            $(this).parent(".listZ").find('ul').hide("slow");
            if ($(this).parent(".listZ").attr('id')=='nc') {
                imageB = 'numberclumber';
            } else if ($(this).parent(".listZ").attr('id')=='mc') {
                imageB = 'mecclumber';
            } else if ($(this).parent(".listZ").attr('id')=='fileZ') {
                imageB = 'filefield';
            } else {
                if($(this).parent('.listZ')) {
                    imageB = 'textfield_error';
                } else {
                    imageB = 'textfield';
                }
            }
            $(this).parent('.listZ').css({
                "background":"url('../images/"+imageB+".png') no-repeat"
            });
        }
    });
    $(".fields").hover(function() {

        },function() {
            $.each( $(".listZ") , function () {
                if ($(this).attr('id')=='nc') {
                    imagehide = 'numberclumber';
                } else if ($(this).attr('id')=='mc') {
                    imagehide = 'mecclumber';
                } else if ($(this).attr('id')=='fileZ'){
                    imagehide = 'filefield';
                } else {
                    if($(this).hasClass('error')) {
                        imagehide = 'textfield_error';
                    } else {
                        imagehide = 'textfield';
                    }
                }
                $(this).css({
                    "background":"url('../images/"+imagehide+".png') no-repeat"
                }).find("ul").hide("slow");

            });
        });
    //$(".fields input[name='companyName']").jQueryInputHints({
    //			hintText  : 'Название компании',
    //            hintClass : 'search_hinted'
    //});
    //$(".fields input[name='namefamiliya']").jQueryInputHints({
    //			hintText  : 'Ваше имя',
    //           hintClass : 'search_hinted'
    //});
    //$(".fields input[name='phone']").jQueryInputHints({
    //			hintText  : 'Телефон',
    //           hintClass : 'search_hinted'
    //});
    //$(".fields input[name='Email']").jQueryInputHints({
    //			hintText  : 'E-mail',
    //            hintClass : 'search_hinted'
    //});
    //$(".fields input[name='addressResource']").jQueryInputHints({
    //			hintText  : 'Адрес продвигаемого ресурса',
    //            hintClass : 'search_hinted'
    //});
    $(".fields input[name='phone']").mask("+7(999)999-99-99");
    x=1;
    timer = setInterval(function() {
        x = x + 1;
        show_tab_times(this, 'tab'+x);
        if (x>4) {
            x=0;
        }
    }, 9000);
    checkbe();
    $(".lavaLamp > ul").lavaLamp({
        fx: "easeinout",
        speed: 700,
        homeTop:-100,
        homeLeft:0,
        homeHeight:20,
        homeWidth:600
    });
    $(".lavaLamp ul ul").css({
        'display':'none'
    });
    $(".activateReview a").click(function() {
        if ($(this).parent(".activateReview").next().css('display')=='none') {
            $(this).parent('.activateReview').css({
                "background":"url(images/arrowUpB.png) no-repeat 9px 10px"
            });
            $(this).parent(".activateReview").next().show('fast');
            $(this).html("свернуть промо блок");
            setCookie('promoBlock', 1, "", "/");

            timer = setInterval(function() {
                x = x + 1;
                show_tab_times(this, 'tab'+x);
                if (x>4) {
                    x=0;
                }
            }, 9000);

        } else {
            $(this).parent('.activateReview').css({
                "background":"url(images/arrowDownB.png) no-repeat 9px 10px"
            });
            $(this).parent(".activateReview").next().hide('slow');
            $(this).html("показать промо блок");
            setCookie('promoBlock', 0, "", "/");
            clearInterval(timer);
        }
    });
    if ($(".toggleShowReview").css('display')=='none') {
        clearInterval(timer);
        $('.activateReview').css({
            "background":"url(images/arrowDownB.png) no-repeat 9px 10px"
        });
        $(".activateReview a").html('показать промо блок');
    }
});
