function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);
(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);


/*************************************************
**  jQuery Masonry version 1.3.2
**  Copyright David DeSandro, licensed MIT
**  http://desandro.com/resources/jquery-masonry
**************************************************/
(function(e){var n=e.event,o;n.special.smartresize={setup:function(){e(this).bind("resize",n.special.smartresize.handler)},teardown:function(){e(this).unbind("resize",n.special.smartresize.handler)},handler:function(j,l){var g=this,d=arguments;j.type="smartresize";o&&clearTimeout(o);o=setTimeout(function(){jQuery.event.handle.apply(g,d)},l==="execAsap"?0:100)}};e.fn.smartresize=function(j){return j?this.bind("smartresize",j):this.trigger("smartresize",["execAsap"])};e.fn.masonry=function(j,l){var g=
{getBricks:function(d,b,a){var c=a.itemSelector===undefined;b.$bricks=a.appendedContent===undefined?c?d.children():d.find(a.itemSelector):c?a.appendedContent:a.appendedContent.filter(a.itemSelector)},placeBrick:function(d,b,a,c,h){b=Math.min.apply(Math,a);for(var i=b+d.outerHeight(true),f=a.length,k=f,m=c.colCount+1-f;f--;)if(a[f]==b)k=f;d.applyStyle({left:c.colW*k+c.posLeft,top:b},e.extend(true,{},h.animationOptions));for(f=0;f<m;f++)c.colY[k+f]=i},setup:function(d,b,a){g.getBricks(d,a,b);if(a.masoned)a.previousData=
d.data("masonry");a.colW=b.columnWidth===undefined?a.masoned?a.previousData.colW:a.$bricks.outerWidth(true):b.columnWidth;a.colCount=Math.floor(d.width()/a.colW);a.colCount=Math.max(a.colCount,1)},arrange:function(d,b,a){var c;if(!a.masoned||b.appendedContent!==undefined)a.$bricks.css("position","absolute");if(a.masoned){a.posTop=a.previousData.posTop;a.posLeft=a.previousData.posLeft}else{d.css("position","relative");var h=e(document.createElement("div"));d.prepend(h);a.posTop=Math.round(h.position().top);
a.posLeft=Math.round(h.position().left);h.remove()}if(a.masoned&&b.appendedContent!==undefined){a.colY=a.previousData.colY;for(c=a.previousData.colCount;c<a.colCount;c++)a.colY[c]=a.posTop}else{a.colY=[];for(c=a.colCount;c--;)a.colY.push(a.posTop)}e.fn.applyStyle=a.masoned&&b.animate?e.fn.animate:e.fn.css;b.singleMode?a.$bricks.each(function(){var i=e(this);g.placeBrick(i,a.colCount,a.colY,a,b)}):a.$bricks.each(function(){var i=e(this),f=Math.ceil(i.outerWidth(true)/a.colW);f=Math.min(f,a.colCount);
if(f===1)g.placeBrick(i,a.colCount,a.colY,a,b);else{var k=a.colCount+1-f,m=[];for(c=0;c<k;c++){var p=a.colY.slice(c,c+f);m[c]=Math.max.apply(Math,p)}g.placeBrick(i,k,m,a,b)}});a.wallH=Math.max.apply(Math,a.colY);d.applyStyle({height:a.wallH-a.posTop},e.extend(true,[],b.animationOptions));a.masoned||setTimeout(function(){d.addClass("masoned")},1);l.call(a.$bricks);d.data("masonry",a)},resize:function(d,b,a){a.masoned=!!d.data("masonry");var c=d.data("masonry").colCount;g.setup(d,b,a);a.colCount!=c&&
g.arrange(d,b,a)}};return this.each(function(){var d=e(this),b={};b.masoned=!!d.data("masonry");var a=b.masoned?d.data("masonry").options:{},c=e.extend({},e.fn.masonry.defaults,a,j),h=a.resizeable;b.options=c.saveOptions?c:a;l=l||function(){};g.getBricks(d,b,c);if(!b.$bricks.length)return this;g.setup(d,c,b);g.arrange(d,c,b);!h&&c.resizeable&&e(window).bind("smartresize.masonry",function(){g.resize(d,c,b)});h&&!c.resizeable&&e(window).unbind("smartresize.masonry")})};e.fn.masonry.defaults={singleMode:false,
columnWidth:undefined,itemSelector:undefined,appendedContent:undefined,saveOptions:true,resizeable:true,animate:false,animationOptions:{}}})(jQuery);

///json

(function($) {
    $.toJSON = function(o) {
        if (typeof (JSON) == 'object' && JSON.stringify)
            return JSON.stringify(o); var type = typeof (o); if (o === null)
            return "null"; if (type == "undefined")
            return undefined; if (type == "number" || type == "boolean")
            return o + ""; if (type == "string")
            return $.quoteString(o); if (type == 'object') {
            if (typeof o.toJSON == "function")
                return $.toJSON(o.toJSON()); if (o.constructor === Date) {
                var month = o.getUTCMonth() + 1; if (month < 10) month = '0' + month; var day = o.getUTCDate(); if (day < 10) day = '0' + day; var year = o.getUTCFullYear(); var hours = o.getUTCHours(); if (hours < 10) hours = '0' + hours; var minutes = o.getUTCMinutes(); if (minutes < 10) minutes = '0' + minutes; var seconds = o.getUTCSeconds(); if (seconds < 10) seconds = '0' + seconds; var milli = o.getUTCMilliseconds(); if (milli < 100) milli = '0' + milli; if (milli < 10) milli = '0' + milli; return '"' + year + '-' + month + '-' + day + 'T' +
hours + ':' + minutes + ':' + seconds + '.' + milli + 'Z"';
            }
            if (o.constructor === Array) {
                var ret = []; for (var i = 0; i < o.length; i++)
                    ret.push($.toJSON(o[i]) || "null"); return "[" + ret.join(",") + "]";
            }
            var pairs = []; for (var k in o) {
                var name; var type = typeof k; if (type == "number")
                    name = '"' + k + '"'; else if (type == "string")
                    name = $.quoteString(k); else
                    continue; if (typeof o[k] == "function")
                    continue; var val = $.toJSON(o[k]); pairs.push(name + ":" + val);
            }
            return "{" + pairs.join(", ") + "}";
        }
    }; $.evalJSON = function(src) {
        if (typeof (JSON) == 'object' && JSON.parse)
            return JSON.parse(src); return eval("(" + src + ")");
    }; $.secureEvalJSON = function(src) {
        if (typeof (JSON) == 'object' && JSON.parse)
            return JSON.parse(src); var filtered = src; filtered = filtered.replace(/\\["\\\/bfnrtu]/g, '@'); filtered = filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'); filtered = filtered.replace(/(?:^|:|,)(?:\s*\[)+/g, ''); if (/^[\],:{}\s]*$/.test(filtered))
            return eval("(" + src + ")"); else
            throw new SyntaxError("Error parsing JSON, source is not valid.");
    }; $.quoteString = function(string) {
        if (string.match(_escapeable)) {
            return '"' + string.replace(_escapeable, function(a)
            { var c = _meta[a]; if (typeof c === 'string') return c; c = a.charCodeAt(); return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16); }) + '"';
        }
        return '"' + string + '"';
    }; var _escapeable = /["\\\x00-\x1f\x7f-\x9f]/g; var _meta = { '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"': '\\"', '\\': '\\\\' };
})(jQuery);

$(function() {

// Вносим textarea value в переменную
	
	var taval = $('#message-form-text').val();
	
	//

	$('#chuser').click(function () {
	$('#user-pics').show();
	$('<div id="ovl"></div>').appendTo('body');
	return false
	})
	
	//
	
	$('#user-pics img').click(function () {
		var picad = $(this).attr('src');
		var altad = $(this).attr('alt');
		var hidden = $('input.hidden')
		hidden.val(altad) ;
		$('.userpic img').remove();
		$('.userpic').append('<img src="' + picad + ' " alt="' + altad + '">');
		$(this).closest('.popup').hide();
	$('#ovl').remove();
	})
	
	//
	
	$('.control').each(function () {
		$(this).attr({
			href: '#message-form-text'
		})
	})
	
	// Скрыть значение value у полей
	
	function hideValue() {
        var elem = jQuery('.change-val');
        if (elem.size() > 0) {
            elem.each(function () {
                var defaultVal = jQuery(this).val();
                jQuery(this).focus(function () {
                    if (jQuery(this).val() == defaultVal) {
                        jQuery(this).val('');
                    }
                }).blur(function () {
                    if (jQuery(this).val() == '') {
                        jQuery(this).val(defaultVal);
                    }
                });
            });
        }
    }
     
    jQuery(document).ready(function () {   
        hideValue();
    });
	
	// Вставка цитаты
	
	$('.comment-item').each(function () {
		var comm = $(this);
		var cText = $('#msg .quot p', this).text();
		$('.control', comm).click(function () {
			$('#message-form-text').val($('#message-form-text').val() + '[quote]' + cText + '[/quote]');
			$('#message-form-text').val($('#message-form-text').val().replace(taval, ''));
		})
	})
	
	
	
	// Вставка тега переноса строки при нажатии Enter
	/*
	var txar = $("#message-form-text");	
	txar.keydown(function(event) {
		if (event.keyCode == '13') {
			txar.val( txar.val() + "<br />");
		}
	});
	*/
	
    $('.cleared').each(function() {
        $(this).attr('def', $(this).val());
    }).focus(function() {
        if ($(this).val() == $(this).attr('def')) $(this).val('');
    }).blur(function() {
        if ($(this).val() == '') $(this).val($(this).attr('def'));
    });

    function getHeight() {
        return document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientHeight : document.body.clientHeight;
    }

    var getHeight = getHeight() - 448;
    if (getHeight < 0) {
        $('#lb').css('top', '100px');
    }

    $('#lb>div.fst').click(function() {
        $('#lb').animate({ "left": "-=12px" }, 200, function() {
            $(this).addClass('style1');
            $('#lb').animate({ "left": "+=227px" }, 500);
        });
    });
    $('#lb>div.lst').click(function(e) {
        if ($(e.target).is('.lst')) {
            $('#lb').animate({ "left": "-=227px" }, 600, function() {
                $(this).removeClass('style1');
                $('#lb').animate({ "left": "+=12px" }, 200);
            });
        }
    });

    function changeCnt() {
        var inp = $('input:radio[name=cnt]:checked').attr('id');
        switch (inp) {
            case 'c_rus':
                $('#map>.map').css('background-position', '0 -203px');
                break
            case 'c_ukr':
                $('#map>.map').css('background-position', '0 -406px');
                break
            case 'c_blr':
                $('#map>.map').css('background-position', '0 -609px');
                break
            default:
                $('#map>.map').removeAttr('style');
                break
        }
    }
    changeCnt();
    $('input:radio[name=cnt]').change(changeCnt);
    $('.c_rus,.c_ukr,.c_blr').mouseenter(function() {
        var clas = $(this).attr('class');
        switch (clas) {
            case 'c_rus':
                $('#map>.map').css('background-position', '0 -203px');
                break
            case 'c_ukr':
                $('#map>.map').css('background-position', '0 -406px');
                break
            case 'c_blr':
                $('#map>.map').css('background-position', '0 -609px');
                break
            default:
                $('#map>.map').removeAttr('style');
                break
        }

    }).mouseleave(changeCnt).click(function(e) {
        $('#' + $(this).attr('class')).attr('checked', 'checked');
        changeCnt();

        if ($(this).is('a') && !$(this).is('[href*=http]')) {
            return false
        }
    });

    $('a.clz,input.iclz').click(function() {
        $(this).closest('.popup').hide();
        $('#ovl').remove();
        return false
    });

//    $('#enterbut').click(function() {

//        $.ajax({
//            type: "POST",
//            url: "/Services/LoginWb.asmx/LoadLogin",
//            data: "{}",
//            contentType: "application/json; charset=utf-8",
//            dataType: "json",
//            success: function(res) { OnLogInUpdated(res.d); }
//        });


//    });

   

//    $('#regbut').click(function() {
//     
//        $('#registerbar').show();
//        $('<div id="ovl"></div>').appendTo('body');
//        return false
//    });
//    
//    $('#adsearch').click(function() {
//        $('#advsearch').show();
//        $('<div id="ovl"></div>').appendTo('body');
//        return false
    //    });

    function getClientHeight() {
        return document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientHeight : document.body.clientHeight;
    }

    $('a.changeRegion').click(function() {
        $('#regionbar').show();
        $('#regionbar div.ww').masonry({ columnWidth: 189 });
        if ($('#regionbar').outerHeight() > getClientHeight()) {
            $('#regionbar').css('position', 'absolute').css('margin-top', '0').css('top', '50px');
        } else {
            $('#regionbar').css('top', '50%').css('position', 'fixed').css('margin-top', -parseInt($('#regionbar').height() / 2) + 'px');
        }

        $('<div id="ovl"></div>').appendTo('body');
        return false
    });
    $('#writeToSeller').click(function() {
        $('#messbar').show();
        $('<div id="ovl"></div>').appendTo('body');
        return false
    });

    $('.validate form').submit(function() {
        $(this).find('span.error').remove();
        var valid = true;
        var $this = $(this);
        $(this).find('input.required').each(function() {
            if ($(this).val().length < 3) {
                valid = false;
                var err = 'Заполните поле';
                if ($(this).prev().is('span')) {
                    var txt = $(this).prev().text();
                    $(this).prev().html(txt + ',<br />' + err);
                } else {
                    $('<span class="error">' + err + '</span>').insertBefore($(this));
                }
            }
        });
        $(this).find('input.confirmpassword').each(function() {
            if ($(this).val() != $this.find('input.password').val()) {
                valid = false;
                var err = 'Пароли не совпадают';
                if ($(this).prev().is('span')) {
                    var txt = $(this).prev().text();
                    $(this).prev().html(txt + ',<br />' + err);
                } else {
                    $('<span class="error">' + err + '</span>').insertBefore($(this));
                }
            }
        });
        $(this).find('input.email').each(function() {
            function isValidEmail(email) {
                email = email.replace(/^\s+|\s+$/g, '');
                return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
            }
            if (!isValidEmail($(this).val())) {
                valid = false;
                var err = 'Email введен не корректно';
                if ($(this).prev().is('span')) {
                    var txt = $(this).prev().text();
                    $(this).prev().html(txt + ',<br />' + err);
                } else {
                    $('<span class="error">' + err + '</span>').insertBefore($(this));
                }
            }
        });

        if (!valid) {
            return false
        }
    });

    $('div.slider').each(function() {
        var max = ($(this).find('td').size()) * 147 - 694 - 82;
        $(this).find('a.gonext').click(function() {
            if ($(this).parent().find('div.sld').scrollLeft() < max) {
                $(this).parent().find('div.sld').scrollTo({ top: 0, left: '+=147px' }, 400);
            }
            return false
        });
        $(this).find('a.goprev').click(function() {
            $(this).parent().find('div.sld').scrollTo({ top: 0, left: '-=147px' }, 400);
            return false
        });
        $(this).find('div.sld').scrollTo({ top: 0, left: '-=206px' }, 100);
    });

    $('div.menuBar > ul > li').hover(
function() {
    var el = $(this).find('a:first');
    if (el.parent().is('li')) { $('<span class="mm1"><span class="mm2"><a href="' + el.attr('href') + '">' + el.text() + '</a></span></span>').insertBefore(el); }
    if ($.browser.msie) {
        $('div.popupMenu').hide();
        el.closest('li').find('>div.popupMenu').show();
    }
},
function() {
    $(this).find('>span.mm1').remove();
    if ($.browser.msie) {
        $(this).find('div.popupMenu').hide();
    }
}
);

    $('a.loc').click(function() {
        $(this).parent().prev().find('span').css({ display: 'block' }).unbind('mouseleave').mouseleave(function() {
            $(this).hide();
        });
        return false
    });

    $('span.vSlider').each(function() {
        var max = ($(this).find('span.sItem').size()) * 93 - 279;
        $(this).find('a.gotop').click(function() {
            if ($(this).parent().find('span.vsld').scrollTop() <= max) {
                $(this).parent().find('span.vsld').scrollTo({ top: '-=93px', left: 0 }, 400);
            }
            return false
        });
        $(this).find('a.gobot').click(function() {
            $(this).parent().find('span.vsld').scrollTo({ top: '+=93px', left: 0 }, 400);
            return false
        });
        $(this).find('span.sItem img').click(function() {
            var URL = $(this).attr('alt');
            $('td.bigImage').empty().append('<img src="' + URL + '" alt="" />');
        });
    });

    $('div.smap').masonry({ columnWidth: 265 });

    $('#forgotbarbutton').click(function() {
        $(this).closest('.in2').find('.clz').click();

        $('#forgotbar').show();
        $('<div id="ovl"></div>').appendTo('body');

        return false
    });

    $('#feedbackbutton').click(function() {

        $.ajax({
            type: "POST",
            url: "/Services/LoginWb.asmx/SendAdminMail",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(res) { OnSendPostAdminMailUpdated(res.d); }
        });


    });

    function OnSendPostAdminMailUpdated(result) {
        $('#DivInsertContent').html(unescape(result));

        $('#feedbackbar').show();
        $('<div id="ovl"></div>').appendTo('body');

        return false
    }

    $('a.upp').click(function() {

        $('#uppbar').show();
        $('<div id="ovl"></div>').appendTo('body');

        return false
    });
    
});


function DoitVip(postId) {

    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/DoVipPost",
        data: $.toJSON({ postId: postId }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnDoitVipUpdated(res.d); }
    });

}

function OnDoitVipUpdated(result) {
    $('#DivInsertContent').html(unescape(result));

    $('#vippop').show();
    $('<div id="ovl"></div>').appendTo('body');

    return false
}


function DoitUP(postId) {

    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/LoadUP",
        data: $.toJSON({ postId: postId }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnDoitUPUpdated(res.d); }
    });

}

function OnDoitUPUpdated(result) {
    $('#DivInsertContent').html(unescape(result));

    $('#uppbar').show();
    $('<div id="ovl"></div>').appendTo('body');

    return false
}

function GoToFilterResult(root, urlresult, spros) {
    var _spros = "";

    if (spros == "true")
        _spros = "&spros=true"

    if (urlresult != null)
        window.location.href = root + "?reg=" + urlresult + _spros;
}

function galleryPhoto(DirOfImg) {

    document.getElementById('zoombig').src = DirOfImg;

}

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 getCookie(name) {
    var cookie = " " + document.cookie;
    var search = " " + name + "=";
    var setStr = null;
    var offset = 0;
    var end = 0;
    if (cookie.length > 0) {
        offset = cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = cookie.indexOf(";", offset)
            if (end == -1) {
                end = cookie.length;
            }
            setStr = unescape(cookie.substring(offset, end));
        }
    }
    return (setStr);
}


function CheckFavarites(idPost) {

    var ListFave = new Array();
    var liststrt = "";

    var classname = document.getElementById('Save_' + idPost).className;
    if (classname == "fv") {
        document.getElementById('Save_' + idPost).className = "fv checked";
        var list = getCookie('SaveFave');

        if (list != null) {
            ListFave = list.split(",");

            for (var i = 0; i < ListFave.length - 1; i++) {
                if (idPost == ListFave[i]) ListFave.splice(i, 1);
            }

            for (var i = 0; i < ListFave.length - 1; i++) {
                liststrt = liststrt + ListFave[i] + ",";
            }

            setCookie('SaveFave', liststrt, "Mon, 01-Jan-2020 00:00:00 GMT", "/");
        }

    }
    else {

        document.getElementById('Save_' + idPost).className = "fv";
        var list = getCookie('SaveFave');
        if (list != null) {
            ListFave = list.split(",");

            for (var i = 0; i < ListFave.length - 1; i++) {
                if (idPost == ListFave[i]) ListFave.splice(i, 1);
            }

            for (var i = 0; i < ListFave.length - 1; i++) {
                liststrt = liststrt + ListFave[i] + ",";
            }

            liststrt = liststrt + idPost + ",";

            setCookie('SaveFave', liststrt, "Mon, 01-Jan-2020 00:00:00 GMT", "/");

        }
        else {
            liststrt = idPost + ",";
            setCookie('SaveFave', liststrt, "Mon, 01-Jan-2020 00:00:00 GMT", "/");
        }

    }

}

function CheckFavaritesPost(idPost) {

    var ListFave = new Array();
    var liststrt = "";

    var classname = document.getElementById('Save_' + idPost).className;
    if (classname == "isfav") {
        document.getElementById('Save_' + idPost).className = "addtofav";
        var list = getCookie('SaveFave');

        if (list != null) {
            ListFave = list.split(",");

            for (var i = 0; i < ListFave.length - 1; i++) {
                if (idPost == ListFave[i]) ListFave.splice(i, 1);
            }

            for (var i = 0; i < ListFave.length - 1; i++) {
                liststrt = liststrt + ListFave[i] + ",";
            }

            setCookie('SaveFave', liststrt, "Mon, 01-Jan-2020 00:00:00 GMT", "/");
        }

    }
    else {

        document.getElementById('Save_' + idPost).className = "isfav";
        var list = getCookie('SaveFave');
        if (list != null) {
            ListFave = list.split(",");

            for (var i = 0; i < ListFave.length - 1; i++) {
                if (idPost == ListFave[i]) ListFave.splice(i, 1);
            }

            for (var i = 0; i < ListFave.length - 1; i++) {
                liststrt = liststrt + ListFave[i] + ",";
            }

            liststrt = liststrt + idPost + ",";

            setCookie('SaveFave', liststrt, "Mon, 01-Jan-2020 00:00:00 GMT", "/");

        }
        else {
            liststrt = idPost + ",";
            setCookie('SaveFave', liststrt, "Mon, 01-Jan-2020 00:00:00 GMT", "/");
        }

    }

}


function CheckFavaritesList(idPost) {

    var ListFave = new Array();
    var liststrt = "";

    var classname = document.getElementById('Save_' + idPost).className;
    if (classname == "fv checked") {
        document.getElementById('Save_' + idPost).className = "fv";
        var list = getCookie('SaveFave');

        if (list != null) {
            ListFave = list.split(",");

            for (var i = 0; i < ListFave.length - 1; i++) {
                if (idPost == ListFave[i]) ListFave.splice(i, 1);
            }

            for (var i = 0; i < ListFave.length - 1; i++) {
                liststrt = liststrt + ListFave[i] + ",";
            }

            setCookie('SaveFave', liststrt, "Mon, 01-Jan-2020 00:00:00 GMT", "/");
        }

    }
    else {

        document.getElementById('Save_' + idPost).className = "fv checked";
        var list = getCookie('SaveFave');
        if (list != null) {
            ListFave = list.split(",");

            for (var i = 0; i < ListFave.length - 1; i++) {
                if (idPost == ListFave[i]) ListFave.splice(i, 1);
            }

            for (var i = 0; i < ListFave.length - 1; i++) {
                liststrt = liststrt + ListFave[i] + ",";
            }

            liststrt = liststrt + idPost + ",";

            setCookie('SaveFave', liststrt, "Mon, 01-Jan-2020 00:00:00 GMT", "/");

        }
        else {
            liststrt = idPost + ",";
            setCookie('SaveFave', liststrt, "Mon, 01-Jan-2020 00:00:00 GMT", "/");
        }

    }

}

function DeleteCookie() {
    setCookie('SaveFave', null, "", "/", "", "");
}


function PromoBlock(orderInList, OrderPromo, divfin) {
    this.orderInList = orderInList;
    this.OrderPromo = OrderPromo;
    this.divfin = divfin;
}

var superruperpromobool = true;
var divpromo = "";
var arraypromoblock = new Array(24);
var orderInListPromo, OrderPromoPromo;

function AddPromoBlock(OrderPromo, postId, orderInList, div) {

    if (superruperpromobool) {
        divpromo = div;
        orderInListPromo = orderInList;
        OrderPromoPromo = OrderPromo;


        var elem = orderInListPromo * 3 - OrderPromoPromo;

        if (arraypromoblock[elem] != null) {
            $('#' + divpromo).html(arraypromoblock[elem].divfin);
        }
        else {

            superruperpromobool = false;
            $('#' + divpromo).html("<div class='loadpromo'><img alt='loading...' src='images/loadingBig.gif'  /><div>");
            $.ajax({
                type: "POST",
                url: "/Services/HomePage.asmx/AddPromoBlock",
                data: $.toJSON({ PostID: postId, orderInList: orderInList }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(res) { OnPromoBlockUpdated(unescape(res.d)); }
            });
        }

    }

}

function OnPromoBlockUpdated(result) {
    if (!superruperpromobool) {
        superruperpromobool = true;
        $('#' + divpromo).html(result);
        var elem = orderInListPromo * 3 - OrderPromoPromo;
        arraypromoblock[elem] = new PromoBlock(orderInListPromo, OrderPromoPromo, result)
    }
}


function SendMessegeAdmin() {

    var Username = $('#FormName').val();
    var UserMail = $('#FormMail').val();
    var SendText = $('#txtSendText').val();
    var FormTema = $('#oFormTema').val();

    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/ValidateMessage",
        data: $.toJSON({ username: Username, mail: UserMail, text: SendText }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnValidateAdminMessageUpdated(res.d, Username, UserMail, FormTema, SendText); }
    });

}

function OnValidateAdminMessageUpdated(result, Username, UserMail, FormTema, SendText) {

    if (result.toString().length == 0) {
        $.ajax({
            type: "POST",
            url: "/Services/LoginWb.asmx/SaveAdminMessage",
            data: $.toJSON({ username: Username, mail: UserMail, text: SendText, IdFormTema: FormTema }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(res) { OnSaveAdminMessageUpdated(res.d); }
        });
    }
    else {

        $('#validMessage').html(unescape(result));
    }
}

function OnSaveAdminMessageUpdated(result) {
    $('#ovl').remove(); $('#DivInsertContent').html(unescape(''));
    $('#DivInsertContent').html(unescape(result));

    $('#infbar').show();
    $('<div id="ovl"></div>').appendTo('body');
}


var Username;
function LoadUser() {

    Username = $('#FormLogin').val();
    var Password = $('#FormPassword').val();

    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/LoadUser",
        data: $.toJSON({ login: Username, password: Password }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnLoadUserInUpdated(res.d); }
    });

}


function OnLoadUserInUpdated(result) {
    if (result == "NoOk") {

        $.ajax({
            type: "POST",
            url: "/Services/LoginWb.asmx/ValidUser",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(res) { ValidUserUpdated(res.d); }
        });
    }
    else {
        $('#ovl').remove(); $('#DivInsertContent').html(unescape(''));
        $('#LoginSetup').html(result);
    }
}

function ValidUserUpdated(result) {

    $('#validuser').html(result);

}

function LoadLoginHeader() {
    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/LoadLoginHeader",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { LoadLoginHeaderUpdated(res.d); }
    });
}


function LoadLoginHeaderUpdated(result) {

    $('#LoginSetup').html(result);

}

function LoadPostSite(IdPost) {
    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/LoadPostSite",
        data: $.toJSON({ IdPost: IdPost}),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { LoadPostSiteUpdated(res.d); }
    });
}


function LoadPostSiteUpdated(result) {

    $('#PostSite').html(result);

}

function onSignOut() {

    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/onSignOut",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnSignOutUpdated(res.d); }
    });

}

function OnSignOutUpdated(result) {
    document.location.href = result;
}



function LoadLogIn() {

    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/LoadLogin",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnLogInUpdated(res.d); }
    });

}

function OnLogInUpdated(result) {
    $('#DivInsertContent').html(unescape(result));

    $('#loginbar').show();
    $('<div id="ovl"></div>').appendTo('body');
    return false
}



function LoadSignup() {

    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/LoadSignup",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnSignupInUpdated(res.d); }
    });

}

function OnSignupInUpdated(result) {
    $('#DivInsertContent').html(unescape(result));

    $('#registerbar').show();
    $('<div id="ovl"></div>').appendTo('body');
    return false
}

function SaveUser() {

    Username = $('#SaveLogin').val();
    var Password1 = $('#SavePassword1').val();
    var Password2 = $('#SavePassword2').val();
    var Mail = $('#SaveMail').val();

    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/IfUserExists",
        data: $.toJSON({ login: Username }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnValidateUpdated(res.d, Password1, Password2, Mail); }
    });

}

function OnValidateUpdated(result, Password1, Password2, Mail) {

    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/IfUserMailExists",
        data: $.toJSON({ mail: Mail }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnValidateUpdatedFin(res.d, result, Password1, Password2, Mail); }
    });

}

function OnValidateUpdatedFin(resultmail, resultuser, Password1, Password2, Mail) {

    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/Validate",
        data: $.toJSON({ exist: resultuser, existmail: resultmail, login: Username, password1: Password1, password2: Password2, mail: Mail }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnExistsUpdated(res.d, Password1, Mail); }
    });

}

function OnExistsUpdated(result, Password1, Mail) {

    if (result.toString().length == 0) {
        $.ajax({
            type: "POST",
            url: "/Services/LoginWb.asmx/SaveUser",
            data: $.toJSON({ login: Username, password: Password1, mail: Mail }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(res) { OnSaveUserUpdated(res.d); }
        });
    }
    else {

        $('#valid').html(unescape(result));
    }
}


function OnSaveUserUpdated(result) {

    $('#ovl').remove(); $('#DivInsertContent').html(unescape(''));
    $('#LoginSetup').html(result);
}

function LoadRecover() {

    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/LoadRecover",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnRecoverInUpdated(res.d); }
    });

}

function OnRecoverInUpdated(result) {
    $('#DivInsertContent').html(unescape(result));

    $('#forgotbar').show();
    $('<div id="ovl"></div>').appendTo('body');
    return false
}

function RecoverUser() {

    var Mail = $('#FormMail').val();

    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/RecoverUser",
        data: $.toJSON({ mail: Mail }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnRecoverUserUpdated(res.d); }
    });

}

function OnRecoverUserUpdated(result) {
    if (result == "NoOk") {

        $.ajax({
            type: "POST",
            url: "/Services/LoginWb.asmx/ValidRecoverUser",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(res) { ValidRecoverUserUpdated(res.d); }
        });
    }
    else {
        $('#ovl').remove(); $('#DivInsertContent').html(unescape(''));
        $('#DivInsertContent').html(unescape(result));

        $('#infbar').show();
        $('<div id="ovl"></div>').appendTo('body');
        return false
    }
}

function ValidRecoverUserUpdated(result) {

    $('#validRecover').html(result);

}


function DeletePost(IdPost) {
    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/DeletePost",
        data: $.toJSON({ idpost: IdPost }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnDeletePostUpdated(res.d); }
    });

}

function OnDeletePostUpdated(result) {
    document.location.href = result;
}

function LoadMessageUp(postId) {

    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/LoadMessageUp",
        data: $.toJSON({ postId: postId }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnLoadMessageUpUpdated(res.d); }
    });

}


function OnLoadMessageUpUpdated(result) {
    if (result) {
        document.location.href = "../account";
    }
    else {
        $.ajax({
            type: "POST",
            url: "/Services/LoginWb.asmx/MessageUpResult",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(res) { OnSaveAdminMessageUpdated(res.d); }
        });
    }
}


function LoadSearsh() {

    $.ajax({
        type: "POST",
        url: "/Services/WebSearch.asmx/LoadSearsh",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnAdviseUpdated(res.d); }
    });

}


function OnAdviseUpdated(result) {
    $('#DivInsertContent').html(unescape(result));

    $('#advsearch').show();
    $('<div id="ovl"></div>').appendTo('body');
    return false
}

function LoadSearchCombo(idStore) {

    if (idStore != 1333) {
        LoadCity(idStore);
        LoadRubric(idStore);
    }
    else {

        $('#ComboCity').html(unescape("<select disabled style='width:170px;' />"));
        $('#ComboRubric').html(unescape("<select disabled style='width:170px;' />"));
    }
}

function LoadCity(idStore) {

    $.ajax({
        type: "POST",
        url: "/Services/WebSearch.asmx/LoadCity",
        data: $.toJSON({ Id: idStore }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnLoadCityUpdated(res.d); }
    });
}

function OnLoadCityUpdated(result) {
    $('#ComboCity').html(unescape(result));
}

function LoadRubric(idStore) {

    $.ajax({
        type: "POST",
        url: "/Services/WebSearch.asmx/LoadRubric",
        data: $.toJSON({ Id: idStore }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnLoadRubricUpdated(res.d); }
    });
}

function OnLoadRubricUpdated(result) {
    $('#ComboRubric').html(unescape(result));
}

function LoadSubRubric(idRubric) {

    $.ajax({
        type: "POST",
        url: "/Services/WebSearch.asmx/LoadSubRubric",
        data: $.toJSON({ Id: idRubric }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnLoadSubRubricUpdated(res.d); }
    });
}

function OnLoadSubRubricUpdated(result) {
    $('#ComboSubRubric').html(unescape(result));
}

function LoadSearchSubRubricCombo(idRubric) {

    if (idRubric != 1555) {
        LoadSubRubric(idRubric);
    }
    else {
        $('#ComboSubRubric').html(unescape("<select disabled style='width:170px;' />"));
    }
}

function AdviceSearch(query, query3, query4, query5, query6) {


    if (query.value == '' & query3.value != 1333 & query4.value == 1444 & query5.value == 1555) {
        // на  хом страны
        $.ajax({
            type: "POST",
            url: "/Services/WebSearch.asmx/GoHome",
            data: $.toJSON({ IdStore: query3.value }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(res) { OnSignOutUpdated(res.d); }
        });

        return false;
    }
    else if (query.value == '' & query3.value != 1333 & query4.value != 1444 & query5.value == 1555) {
        // на  хом страны
        $.ajax({
            type: "POST",
            url: "/Services/WebSearch.asmx/GoHome",
            data: $.toJSON({ IdStore: query3.value }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(res) { OnSignOutUpdated(res.d); }
        });

        return false;
    }
    else if (query.value == '' & query3.value != 1333 & query4.value == 1444 & query5.value != 1555 & query6.value == 1655) {
        // на  рубрику
        $.ajax({
            type: "POST",
            url: "/Services/WebSearch.asmx/GoRubric",
            data: $.toJSON({ IdStore: query3.value, IdRubric: query5.value }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(res) { OnSignOutUpdated(res.d); }
        });

        return false;
    }
    else if (query.value == '' & query3.value != 1333 & query4.value != 1444 & query5.value != 1555 & query6.value == 1655) {
        //        // на  рубрику с городом

        $.ajax({
            type: "POST",
            url: "/Services/WebSearch.asmx/GoRubricCity",
            data: $.toJSON({ IdStore: query3.value, IdRubric: query5.value, IdCity: query4.value }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(res) { OnSignOutUpdated(res.d); }
        });


        return false;
    }
    else if (query.value == '' & query3.value != 1333 & query4.value == 1444 & query5.value != 1555 & query6.value != 1655) {
        // на  субрубрику
        $.ajax({
            type: "POST",
            url: "/Services/WebSearch.asmx/GoSubRubric",
            data: $.toJSON({ IdStore: query3.value, IdRubric: query5.value, IdSubRubric: query6.value }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(res) { OnSignOutUpdated(res.d); }
        });

        return false;
    }
    else if (query.value == '' & query3.value != 1333 & query4.value != 1444 & query5.value != 1555 & query6.value != 1655) {
        //       // на  субрубрику с городом

        $.ajax({
            type: "POST",
            url: "/Services/WebSearch.asmx/GoSubRubricCity",
            data: $.toJSON({ IdStore: query3.value, IdRubric: query5.value, IdCity: query4.value, IdSubRubric: query6.value }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(res) { OnSignOutUpdated(res.d); }
        });

        return false;
    }

}

var PostID;

function SendMessege(_PostID) {

    PostID = _PostID;
    var Username = $('#FormName').val();
    var UserMail = $('#FormMail').val();
    var SendText = $('#txtSendText').val();

    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/ValidateMessage",
        data: $.toJSON({ username: Username, mail: UserMail, text: SendText }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnValidateMessageUpdated(res.d, Username, UserMail, SendText); }
    });

}


function OnValidateMessageUpdated(result, Username, UserMail, SendText) {

    if (result.toString().length == 0) {
        $.ajax({
            type: "POST",
            url: "/Services/LoginWb.asmx/SaveMessage",
            data: $.toJSON({ username: Username, mail: UserMail, text: SendText, postID: PostID }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(res) { OnSaveMessageUpdated(res.d); }
        });
    }
    else {

        $('#validMessage').html(unescape(result));
    }
}

function OnSaveMessageUpdated(result) {
    $('#messbar').closest('.popup').hide();
    $('#ovl').remove(); 
    $('#DivInsertContent').html(unescape(result));
    
    $('#infbar').show();
    $('<div id="ovl"></div>').appendTo('body');
}

function IsLoginOn() {

    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/IsLoginOn",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { IsLoginOnUpdated(res.d); }
    });

}

function IsLoginOnUpdated(result) {
    if (!result)
        LoadLogIn();
}

function MessageBanOn() {

    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/MessageBanOn",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnMessageBanOnUpdated(res.d); }
    });

}

function AllertAtrBanOn() {

    $.ajax({
        type: "POST",
        url: "/Services/LoginWb.asmx/AllertAtrBanOn",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(res) { OnMessageBanOnUpdated(res.d); }
    });

}

function OnMessageBanOnUpdated(result) {

    $('#DivInsertContent').html(unescape(result));

    $('#infbar').show();
    $('<div id="ovl"></div>').appendTo('body');
    return false
}

function openLink(url) {
  var reg = /(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)/;
  if (!reg.test(url) && url.substring(0, 6) != 'skype:') 
      url = 'http://' + url;
 
   window.open(url, '', '');
 
}
