

if (! String.prototype.trim) { String.prototype.trim = function() { return this.replace(/^\s+/g, '').replace(/\s+$/g, ''); } ;}

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

function CPoint(x, y) { this.x = this.y = null; this.reshape(x, y); }
CPoint.prototype.reshape = function(x, y) { this.x = x; this.y = y; };
CPoint.prototype.toString = function() { return "CPoint [x = " + this.x + ", y = " + this.y + "]"; };

function CBox(left, top, width, height) { this.left = this.top = this.width = this.height = 0; this.reshape(left, top, width, height); }
CBox.prototype.reshape = function(left, top, width, height) { this.left = left; this.top = top; this.width = width; this.height = height; };
CBox.prototype.toString = function() { return "CBox [left = " + this.left + ", top = " + this.top + ", width = " + this.width + ", height = " + this.height + "]"; };

var CUtils = new function()
{
    this.isIE = navigator.userAgent.indexOf("MSIE") != -1;
    
    this.hideElement = function(element) { element.style.visibility = "hidden"; };
    this.showElement = function(element) { element.style.visibility = "visible"; };
    this.isVisible = function(element) { return element.style.visibility == "visible"; };
    this.isHidden = function(element) { return !this.isVisible(element);};

    this.getMouseXY = function(e)
    {
        if (!e) e = window.event;

        // Calculate pageX/Y if missing and clientX/Y available
        if ( e.pageX == null && e.clientX != null ) {
            var doc = document.documentElement, body = document.body;
            e.pageX = e.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc.clientLeft || 0);
            e.pageY = e.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientTop || 0);
        }

        return new CPoint(e.pageX, e.pageY);
    };

    this.getXYScroll = function()
    {
        var x = 0, y = 0;
        if (typeof( window.pageYOffset ) == 'number')
        {
            //Netscape
            y = window.pageYOffset;
            x = window.pageXOffset;
        } else if (document.body && ( document.body.scrollLeft || document.body.scrollTop ))
        {
            //DOM
            y = document.body.scrollTop;
            x = document.body.scrollLeft;
        } else if (document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ))
        {
            //IE6
            y = document.documentElement.scrollTop;
            x = document.documentElement.scrollLeft;
        }
        return new CPoint(x, y);
    };

    this.moveElement = function(element, left, top) { CUtils.setElementStyle(element, "left:" + left + "px; top:" + top + "px;"); };

    this.getScreenBox = function()
    {
        if (window.innerHeight)
        {
            return new CBox(0, 0, window.innerWidth, window.innerHeight);
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
            return new CBox(0, 0, document.documentElement.clientWidth, document.documentElement.clientHeight);
        }
        else if (document.body && document.body.clientHeight)
        {
            return new CBox(0, 0, document.body.clientWidth, document.body.clientHeight);
        }
        else
        {
            return new CBox(0, 0, 0, 0);
        }
    };

    this.getElementBox = function(element)
    {
        var left = 0, top = 0;
        var width = element.offsetWidth;
        var height = element.offsetHeight;
        while (element)
        {
            left += element.offsetLeft;
            top += element.offsetTop;
            element = element.offsetParent;
        }
        return new CBox(left, top, width, height);
    };

    function camelize(name)
    {
        var splittedName = name.split("-");
        var result = splittedName[0];
        for (var c = 1; c < splittedName.length; c++) result += splittedName[c].substring(0, 1).toUpperCase() + splittedName[c].substring(1);
        return result;
    }

    this.setElementStyle = function(element, css)
    {
        var el = element.style;
        var styles = css.split(";");
        for (var i = 0; i < styles.length; i++)
        {
            var currentStyle = styles[i].split(":");
            currentStyle[0] = currentStyle[0].trim();
            if (currentStyle[0] == "" || ! currentStyle[1]) continue;
            eval("el." + camelize(currentStyle[0]) + " = \"" + currentStyle[1].trim() + "\"");
        }
    };
};

function openWinCentered(loc, winname, widthh, heightt, params)
{
    var tp = Math.ceil((screen.height - heightt) / 2);
    var lf = Math.ceil((screen.width - widthh) / 2);
    if (params.length > 0)
        params = "," + params;

    var win = window.open(loc, winname, "width=" + widthh + ",height=" + heightt + ",top=" + tp + ",left=" + lf + params);
    win.focus();
    return win;
}

function PopupUtil()
{
}

PopupUtil.fitToScreen = function(div, x, y)
{
    x = parseInt(x);
    y = parseInt(y);
    var dBoxHeight = CUtils.getElementBox(div).height ;
    var elementFromPageTop = y - CUtils.getXYScroll().y ;
    var screenBoxHeight = CUtils.getScreenBox().height ;
    var freeSpaceY = screenBoxHeight - elementFromPageTop ;
    var correctionY = 0 ;
    if (freeSpaceY < dBoxHeight)
    {
        correctionY = dBoxHeight - freeSpaceY + 5;
        if (dBoxHeight > screenBoxHeight)
        {
            correctionY = elementFromPageTop;
        }
    }
    CUtils.moveElement(div, x + 5, y + 5 - correctionY);
};

PopupUtil.setContainerCoordinates = function(div, newX, newY)
{
    if (is_nn4)
    {
        div.left = newX;
        div.top = newY;
    }
    else if (is_ie)
    {
        div.style.pixelLeft = newX;
        div.style.pixelTop = newY;
    }
    else
    {
        div.style.left = newX + "px";
        div.style.top = newY + "px";
    }
};

PopupUtil.setPopupPosition = function(div, x, y, minWidth, minHeight)
{
    var docElement = document.documentElement;
    var doesNotFitX = docElement.clientWidth && docElement.clientWidth - x < minWidth;
    if (doesNotFitX)
    {
        x -= minWidth;
    } else
    {
        x += 5;
    }
    var doesNotFitY = CUtils.getScreenBox().height - y < minHeight;
    if (doesNotFitY)
    {
        y -= minHeight;
    }
    var xyScroll = CUtils.getXYScroll();
    x += xyScroll.x;
    y += xyScroll.y;
    PopupUtil.setContainerCoordinates(div, x, y);
};

PopupUtil.correctPopupWidth = function (div, width)
{
    if (CUtils.getElementBox(div).width > width)
    {
        CUtils.setElementStyle(div, "width: " + width + "px");
    }
};

(function()
{
    var UA = navigator.userAgent;
    is_gecko = /gecko/i.test(UA);
    is_opera = /opera/i.test(UA);
    is_mac = /mac_powerpc/i.test(UA);
    is_ie = /msie/i.test(UA) && !is_opera && !is_gecko && !is_mac;
    is_ie5 = is_ie && /msie 5\.[^5]/i.test(UA);
    is_nn4 = document.layers;
})();

function Community()
{
}

Community.i18n = function(text, arg1, arg2)
{
    if (typeof Community.I18N != "undefined" && typeof Community.I18N[text] != "undefined")
        text = Community.I18N[text];

    if (arg1)
    {
        text = text.replace(/(\(1\))/g, arg1);

        if (arg2)
            text = text.replace(/(\(2\))/g, arg2);
    }

    return text;
};


Community.CE = function(type, parent, props, style)
{
    var el = null,i;

    if (document.createElementNS)
        el = document.createElementNS("http://www.w3.org/1999/xhtml", type);
    else
        el = document.createElement(type);

    if (parent)
        parent.appendChild(el);

    if (props)
        for (i in props)
            el[i] = props[i];

    if (style)
        for (i in style)
            el.style[i] = style[i];

    return el;
};

function runStatusBar()
{
    var bar = document.getElementById("fileTransferBar");
    bar.style.display = "block";
}

function submitForm(element)
{
    var parent = element.parentNode;
    while (parent && parent.tagName.toLowerCase() != "form")
        parent = parent.parentNode;

    if (parent)
        parent.submit();

    return false;
}

/* Ajax */

function getHTTPObject()
{
    var http = false;
    //Use IE's ActiveX
    if (typeof ActiveXObject != 'undefined')
    {
        try
        {
            http = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                http = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (E)
            {
                http = false;
            }
        }
    } else if (window.XMLHttpRequest)
    {
        //XMLHttpRequest of Firefox/Mozilla etc
        try
        {
            http = new XMLHttpRequest();
        }
        catch (e)
        {
            http = false;
        }
    }
    return http;
}

var ajaxHTTPObject = getHTTPObject() ;

function sendFeedAjaxRequest(src, photoDiv, doSmilize, x, y)
{
    var h = ajaxHTTPObject ;
    if (h)
    {
        h.open("GET", src, true);
        h.onreadystatechange = function ()
        {
            if (h.readyState == 4)
            {
                if (h.status == 200)
                {
                    var r = h.responseText ;
                    try
                    {
                        var div = Community.CE("div");
                        div.innerHTML = r;
                        var c = div.firstChild; //get response first child
                        if (c != null && c.tagName.toLowerCase() == "div" && c.id == "feedResponse")
                        {
                            var cImgs = c.getElementsByTagName("img") ;
                            if (cImgs != null && cImgs.length > 0)
                            {
                                /* preload personal photo, album cover, group cover */
                                var imgSrc = cImgs[0].src;
                                var tooltipImage = new Image();
                                tooltipImage.src = imgSrc;
                                tooltipImage.onLoad = redrawFeed(photoDiv, x, y, doSmilize, r, false);
                            } else
                            {
                                redrawFeed(photoDiv, x, y, doSmilize, r, true);
                            }
                        }
                        c = null;
                        div = null;
                    } catch(e)
                    {
                    }
                } else
                {
                    //handle error
                }
            }
        };
        h.send(null);
    }
}

function redrawFeed(photoDiv, x, y, doSmilize, res, isMsg)
{
    if (doSmilize)
    {
        res = OneSmile.smilize(res, smilesPath);
    }
    photoDiv.innerHTML = res;
    if (isMsg && doSmilize) {
        /* expand tooltip for comment with formatting */
        CUtils.setElementStyle(photoDiv, "width: 410px");
    } else if(!isMsg) {
        /* tooltip for photos and photoalbums */
        PopupUtil.correctPopupWidth(photoDiv, 150);
    } else {
        /* tooltip for comments, community info... */
        PopupUtil.correctPopupWidth(photoDiv, 410);
    }
    PopupUtil.fitToScreen(photoDiv, x, y);
}

var getFeed = function(sessionId, tooltipType, feedReferenceId, photoDivId, doSmilize, x, y)
{
    var src = "/dk;jsessionid=" + sessionId + "?st.cmd=userGetFeedInfo&tooltipType=" + tooltipType + "&feedReferenceId=" + feedReferenceId ;
    var photoDiv = document.getElementById(photoDivId);
    CUtils.showElement(photoDiv);
    var loadingImage = Community.CE("img", photoDiv);
    loadingImage.src = "/res/default/Images/loading.gif";
    SMenuFeed.showDiv = "1";
    CUtils.moveElement(photoDiv, x, y);
    sendFeedAjaxRequest(src, photoDiv, doSmilize, x, y);
};

function SMenuFriend()
{
}

SMenuFriend.div = null;
SMenuFriend.timer = null;
SMenuFriend.showDiv = 0;
SMenuFriend.overDiv = 0;

SMenuFriend.sessionId = null;
SMenuFriend.userId = null;
SMenuFriend.userName = null;
SMenuFriend.photoId = null;

SMenuFriend.generate = function(parent)
{
    if (!parent)
        return;

    if (SMenuFriend.div)
        return;

    var C = Community;
    SMenuFriend.div = C.CE("div", parent, {id:"shortcutMenuFriend"}, {});
    SMenuFriend.div.onmouseover = function()
    {
        SMenuFriend.overDiv = 1;
    };

    SMenuFriend.div.onmouseout = function()
    {
        SMenuFriend.overDiv = 0;
        setTimeout('closeSMenuFriend()', 500);
    };

    SMenuFriend.userName = C.CE("h4", SMenuFriend.div, {});

    var body = C.CE("ul", SMenuFriend.div, {}, {});

    function gen_menu(body, icon, label, clickHandler)
    {
        var a = C.CE("a", C.CE("li", body, {className:"shortcutMenuItem-" + icon}), {href:"#",innerHTML:C.i18n(label)});
        a.onclick = clickHandler;
    }

    function gen_break(body)
    {
        C.CE("hr", body, {className:"shortcutMenuItemBreak"});
    }

    gen_menu(body, "view", "friend.menu.large-photo", function()
    {
        var url = SMenuFriend.sessionId + "/photobig.php?uid=" + SMenuFriend.photoId;

//        if (SMenuFriend.photoId != "main")
//            url = url + "&st.photoId=" + SMenuFriend.photoId;
        openWinCentered(url, "view" + SMenuFriend.userId, 700, 670, 'location=no,status=no,toolbar=no,menubar=no,resizable=yes,scrollbars=no');
        return false;
    });

    gen_menu(body, "message", "friend.menu.send-msg", function()
    {
        var url = SMenuFriend.sessionId + "/sendmess.php?tid=" + SMenuFriend.userId;

        // dublicate change dimension in TCreateMessageLink class
        openWinCentered(url, "msg" + SMenuFriend.userId, 520, 650, 'location=no,status=no,toolbar=no,menubar=no,resizable=no,scrollbars=no');
        return false;
    });
/*
    gen_menu(body, "messaging", "friend.menu.messaging", function()
    {
        window.location = "/dk;jsessionid=" + SMenuFriend.sessionId +
                  "?st.cmd=friendMessaging&st.friendId=" + SMenuFriend.userId;
        return false;
    });

    gen_menu(body, "altGroupInvite", "friend.menu.altgroup.invite", function()
	{
        window.location = "/dk;jsessionid=" + SMenuFriend.sessionId +
                  "?st.cmd=friendAltGroupInvite&st.friendId=" + SMenuFriend.userId;
        return false;
    });
    
    gen_menu(body, "sendPresent", "friend.menu.presents.send", function()
    {
        window.location = "/dk;jsessionid=" + SMenuFriend.sessionId +
                  "?st.mode=choose&st.cmd=friendSendPresent&st.friendId=" + SMenuFriend.userId;
        return false;
    });
*/
    gen_break(body);

    
    gen_menu(body, "friends", "friend.menu.friends", function()
    {
        window.location = SMenuFriend.sessionId + "/index.php?pr=2&u=" + SMenuFriend.userId;
        return false;
    });

    gen_menu(body, "photo", "friend.menu.photos", function()
    {
        window.location = SMenuFriend.sessionId + "/index.php?pr=4&u=" + SMenuFriend.userId;
        return false;
    });
/*
    gen_menu(body, "photoalbums", "friend.menu.photoalbums", function()
    {
        window.location = "/dk;jsessionid=" + SMenuFriend.sessionId +
                  "?st.cmd=friendPhotoAlbums&st.friendId=" + SMenuFriend.userId;
        return false;
    });

    gen_menu(body, "altGroups", "friend.menu.altgroups", function()
	{
        window.location = "/dk;jsessionid=" + SMenuFriend.sessionId +
                  "?st.cmd=friendAltGroup&st.friendId=" + SMenuFriend.userId;
        return false;
    });
*/
    gen_menu(body, "groups", "friend.menu.groups", function()
    {
        window.location = SMenuFriend.sessionId + "/index.php?pr=3&u=" + SMenuFriend.userId;
        return false;
    });

    gen_menu(body, "forum", "friend.menu.forum", function()
    {
        window.location = SMenuFriend.sessionId + "/index.php?pr=6&u=" + SMenuFriend.userId;
        return false;
    });

    gen_menu(body, "self", "friend.menu.self", function()
    {
        window.location = SMenuFriend.sessionId + "/index.php?pr=5&u=" + SMenuFriend.userId;
        return false;
    });
};

SMenuFriend.popupDiv = function(e, sessionId, userId, userName, photoId)
{
    if (!e)
        e = window.event;

    var x = e.clientX;
    var y = e.clientY;

    SMenuFriend.timer = setTimeout("showSMenuFriend(" + x + "," + y + ",'" + sessionId + "','" + userId + "','" + userName + "','" + photoId + "')", 600);
};

var showSMenuFriend = function(x, y, sessionId, userId, userName, photoId)
{
    SMenuFriend.generate(document.body);
    var div = SMenuFriend.div;

    SMenuFriend.sessionId = sessionId;
    SMenuFriend.userId = userId;
    SMenuFriend.photoId = photoId;
    SMenuFriend.userName.innerHTML = userName;

    PopupUtil.setPopupPosition(div, x, y, 200, 280);

    CUtils.showElement(div);
    SMenuFriend.showDiv = 1;
};

SMenuFriend.hideDiv = function()
{
    if (SMenuFriend.timer)
    {
        clearTimeout(SMenuFriend.timer);
        SMenuFriend.timer = null;
    }

    if (SMenuFriend.showDiv == "1")
    {
        SMenuFriend.overDiv = 0;
        setTimeout('closeSMenuFriend()', 500);
    }
};

var closeSMenuFriend = function()
{
    if (SMenuFriend.overDiv == "0")
    {
        CUtils.hideElement(SMenuFriend.div);
        SMenuFriend.showDiv = 0;
    }
};

function SMenuUOGroup()
{
}

SMenuUOGroup.div=null;
SMenuUOGroup.timer=null;
SMenuUOGroup.showDiv="0";
SMenuUOGroup.overDiv="0";

SMenuUOGroup.sessionId=null;
SMenuUOGroup.groupId=null;
SMenuUOGroup.groupName=null;
SMenuUOGroup.friendId=null;

SMenuUOGroup.image=null;
SMenuUOGroup.onclickLocation=null;

SMenuUOGroup.generate=function(parent)
{
    if (!parent)
        return;

    if (SMenuUOGroup.div == "1" && SMenuUOGroup.showDiv == "1")
        return;

    var C=Community;
    SMenuUOGroup.div=C.CE("div",parent,{id:"shortcutMenuGroup"},{});
    SMenuUOGroup.div.onmouseover=function()
    {
        SMenuUOGroup.overDiv="1";
    };

    SMenuUOGroup.div.onmouseout=function()
    {
        SMenuUOGroup.overDiv="0";
        setTimeout('closeSMenuUOGroup()',500);
    };

    SMenuUOGroup.groupName=C.CE("span",SMenuUOGroup.div,{});

    var body=C.CE("ul",SMenuUOGroup.div,{},{});

	function gen_menu(body,icon,label,clickHandler)
	{
        var a=C.CE("a",C.CE("li",body,{className:"shortcutMenuItem-" + icon}),{href:"javascript:void(0);",innerHTML:C.i18n(label)});
        a.onclick=clickHandler;
    }

    gen_menu(body,"group-main","uogroup.menu.main",function()
    {
        window.location="/dk;jsessionid="+SMenuUOGroup.sessionId+"?st.cmd=altGroupMain&st.groupId="+SMenuUOGroup.groupId;
        return false;
    });

    gen_menu(body,"group-members","uogroup.menu.members",function()
    {
        window.location="/dk;jsessionid="+SMenuUOGroup.sessionId+"?st.cmd=altGroupMembers&st.groupId="+SMenuUOGroup.groupId;
        return false;
    });

    gen_menu(body,"group-albums","uogroup.menu.albums",function()
    {
        window.location="/dk;jsessionid="+SMenuUOGroup.sessionId+"?st.cmd=altGroupPhotos&st.groupId="+SMenuUOGroup.groupId;
        return false;
    });

    gen_menu(body,"group-forum","uogroup.menu.forum",function()
    {
        window.location="/dk;jsessionid="+SMenuUOGroup.sessionId+"?st.cmd=altGroupForum&st.groupId="+SMenuUOGroup.groupId;
        return false;
    });
};

SMenuUOGroup.generateMainPhotoPreview=function(parent)
{
    if (!parent)
        return;

    if (SMenuUOGroup.div == "1" && SMenuUOGroup.showDiv == "1")
        return;

    var C=Community;
    SMenuUOGroup.div=C.CE("div",parent,{id:"shortcutMenuMedal"},{});
    SMenuUOGroup.div.onmouseover=function()
    {
        SMenuUOGroup.overDiv="1";
    };

    SMenuUOGroup.div.onmouseout=function()
    {
        SMenuUOGroup.overDiv="0";
        setTimeout('closeSMenuUOGroup()',500);
    };

    if (!is_mac)
    {
        var a=C.CE("a",SMenuUOGroup.div,{href:"javascript:void(0);"});
        a.onclick=function()
        {
            window.location=SMenuUOGroup.onclickLocation;
            return false;
        };
        SMenuUOGroup.image=C.CE("img",a);
    }
};

SMenuUOGroup.popupDiv=function(e,sessionId,groupId,groupName,friendId)
{
    if (!e) e = window.event;
    var x=e.clientX;
    var y=e.clientY;
    SMenuUOGroup.timer=setTimeout("showSMenuUOGroup("+x+","+y+",'"+sessionId+"','"+groupId+"','"+groupName+"','"+friendId+"')",600);
};

showSMenuUOGroup=function(x,y,sessionId,groupId,groupName,friendId)
{
    SMenuUOGroup.generate(document.body);
    SMenuUOGroup.sessionId=sessionId;
    SMenuUOGroup.groupId=groupId;
    SMenuUOGroup.groupName.innerHTML=groupName;
    SMenuUOGroup.friendId=friendId;
    SMenuUOGroup.render(x,y);
};

SMenuUOGroup.popupPhotoPreviewDiv=function(e,mainPhotoSrc,onclickLocation)
{
    if (!e) e = window.event;
    var x=e.clientX;
    var y=e.clientY;
    SMenuUOGroup.timer=setTimeout("showMainPhotoSMenuUOGroup("+x+","+y+",'"+mainPhotoSrc+"','"+onclickLocation+"')",600);
};

showMainPhotoSMenuUOGroup=function(x,y,mainPhotoSrc,onclickLocation)
{
    SMenuUOGroup.generateMainPhotoPreview(document.body);

    SMenuUOGroup.onclickLocation=onclickLocation;
    SMenuUOGroup.image.src=mainPhotoSrc;

    SMenuUOGroup.render(x,y);
};

SMenuUOGroup.render=function(x,y)
{
    var div=SMenuUOGroup.div;
    PopupUtil.setPopupPosition(div, x, y, 100, 90);
    CUtils.showElement(div);
    SMenuUOGroup.showDiv="1";
};

SMenuUOGroup.hideDiv=function()
{
    if(SMenuUOGroup.timer)
    {
        clearTimeout(SMenuUOGroup.timer);
        SMenuUOGroup.timer=null;
    }
    if(SMenuUOGroup.showDiv=="1")
    {
        SMenuUOGroup.overDiv="0";
        setTimeout('closeSMenuUOGroup()',500);
    }
};

closeSMenuUOGroup=function()
{
    if (SMenuUOGroup.overDiv == "0")
    {
        CUtils.hideElement(SMenuUOGroup.div);
        SMenuUOGroup.showDiv="0";
    }
};

function SMenuFeed()
{
}

SMenuFeed.div = null;
SMenuFeed.timer = null;
SMenuFeed.showDiv = "0";
SMenuFeed.overDiv = "0";

SMenuFeed.render = function(x, y)
{
    var div = SMenuFeed.div;
    CUtils.showElement(div);
    PopupUtil.correctPopupWidth(div, 410);
    PopupUtil.fitToScreen(div, x, y);
    SMenuFeed.showDiv = "1";
};

SMenuFeed.popup = function(e, sessionId, tooltipType, feedReferenceId, doSmilize)
{
    if (typeof ajaxHTTPObject == "boolean") {
        return ;
    }

    var mouseXY = CUtils.getMouseXY(e) ;
    var x = mouseXY.x + 5;
    var y = mouseXY.y;

    doSmilize = doSmilize == "true";

    if (SMenuFeed.timer)
    {
        clearTimeout(SMenuFeed.timer);
        SMenuFeed.timer = null;
    }
    if (SMenuFeed.div != null)
    {
        SMenuFeed.overDiv = "0";
        closeSMenuFeed();
    }

    var popupId = "feed."+ tooltipType + "." + feedReferenceId + ".popup";
    SMenuFeed.div = document.getElementById(popupId) ;
    if (SMenuFeed.div == null) {
        SMenuFeed.div = Community.CE("div", document.body);
        SMenuFeed.div.id = popupId;
        SMenuFeed.div.className = "shortcutFeed";
    }

    if (SMenuFeed.div.innerHTML == "")
    {
        SMenuFeed.sessionId = sessionId;

        SMenuFeed.div.onmouseover = function()
        {
            SMenuFeed.overDiv = "1";
        };

        SMenuFeed.div.onmouseout = function()
        {
            SMenuFeed.overDiv = "0";
            setTimeout('closeSMenuFeed()', 500);
        };

        SMenuFeed.timer = setTimeout("getFeed('" + sessionId + "','" + tooltipType + "','" + feedReferenceId + "', SMenuFeed.div.id, " + doSmilize + ",'" + x + "','" + y + "'); ", 600);
    } else
    {
        SMenuFeed.timer = setTimeout("SMenuFeed.render(" + x + "," + y + ")", 600);
    }
};

SMenuFeed.hide = function()
{
    if (SMenuFeed.timer)
    {
        clearTimeout(SMenuFeed.timer);
        SMenuFeed.timer = null;
    }

    if (SMenuFeed.showDiv == "1")
    {
        SMenuFeed.overDiv = "0";
        setTimeout('closeSMenuFeed()', 500);
    }
};

var closeSMenuFeed = function()
{
    if (SMenuFeed.overDiv == "0")
    {
        CUtils.hideElement(SMenuFeed.div);
        SMenuFeed.timer = null;
        SMenuFeed.showDiv = "0";
        SMenuFeed.overDiv = "0";
    }
};

function SMenuUser()
{
}

SMenuUser.div = null;
SMenuUser.timer = null;
SMenuUser.showDiv = "0";
SMenuUser.overDiv = "0";

SMenuUser.userName = null;
SMenuUser.image = null;
SMenuUser.onclickLocation = null;

SMenuUser.popup = function(e, userId, userName, imageSrc, link)
{
    if (!e) e = window.event;
    var x = e.clientX;
    var y = e.clientY;

    if (SMenuUser.timer)
    {
        clearTimeout(SMenuUser.timer);
        SMenuUser.timer = null;
    }
    if (SMenuUser.div != null)
    {
        SMenuUser.overDiv = "0";
        closeSMenuUser();
    }

    SMenuUser.timer = setTimeout("showSMenuUser(" + x + "," + y + ",'" + userId + "','" + userName + "','" + imageSrc + "','" + link + "')", 600);
};

var showSMenuUser = function(x, y, userId, userName, imageSrc, link)
{
    if (SMenuUser.timer)
    {
        clearTimeout(SMenuUser.timer);
        SMenuUser.timer = null;
    }
    if (SMenuUser.div != null)
    {
        SMenuUser.overDiv = "0";
        closeSMenuUser();
    }
    var popupId = "shortcutUser." + parseInt(userId) + ".popup";
    SMenuUser.div = document.getElementById(popupId) ;
    if (SMenuUser.div == null) {
        var C = Community;
        SMenuUser.div = C.CE("div", document.body);
        SMenuUser.div.id = popupId ;
        SMenuUser.div.className = "shortcutUser";

        SMenuUser.div.onmouseover = function()
        {
            SMenuUser.overDiv = "1";
        };
        SMenuUser.div.onmouseout = function()
        {
            SMenuUser.overDiv = "0";
            setTimeout('closeSMenuUser()', 200);
        };

        if (!is_mac)
        {
            var a = C.CE("a", SMenuUser.div, {href:"javascript:void(0);"});
            a.onclick = function()
            {
                if (SMenuUser.onclickLocation)
                {
                    window.location = SMenuUser.onclickLocation;
                }
                return false;
            };
            SMenuUser.image = C.CE("img", a);
        }
        SMenuUser.userName = C.CE("em", C.CE("p", SMenuUser.div));

        SMenuUser.onclickLocation = link;
        SMenuUser.userName.innerHTML = userName;
        SMenuUser.image.src = imageSrc;
    }

    SMenuUser.render(x, y);
};

SMenuUser.render = function(x, y)
{
    PopupUtil.setPopupPosition(SMenuUser.div, x, y, 160, 160);
    PopupUtil.correctPopupWidth(SMenuUser.div, 150);
    CUtils.showElement(SMenuUser.div);
    SMenuUser.showDiv = "1";
};

SMenuUser.hideDiv = function()
{
    if (SMenuUser.timer)
    {
        clearTimeout(SMenuUser.timer);
        SMenuUser.timer = null;
    }

    if (SMenuUser.showDiv == "1")
    {
        SMenuUser.overDiv = "0";
        setTimeout('closeSMenuUser()', 200);
    }
};

var closeSMenuUser = function()
{
    if (SMenuUser.overDiv == "0")
    {
        CUtils.hideElement(SMenuUser.div);
        SMenuUser.timer = null;
        SMenuUser.overDiv = "0";
        SMenuUser.showDiv = "0";
    }
};

function SMenuGroupUser()
{
}

SMenuGroupUser.div = null;
SMenuGroupUser.timer = null;
SMenuGroupUser.showDiv = "0";
SMenuGroupUser.overDiv = "0";

SMenuGroupUser.userName = null;
SMenuGroupUser.image = null;
SMenuGroupUser.onclickLocation = null;

SMenuGroupUser.additionalLink = null;
SMenuGroupUser.additionalLinkText = null;

SMenuGroupUser.popup = function(e, userId, userName, imageSrc, link, additionalLink, additionalLinkText)
{
    if (!e) e = window.event;
    var x = e.clientX;
    var y = e.clientY;

    if (SMenuGroupUser.timer)
    {
        clearTimeout(SMenuGroupUser.timer);
        SMenuGroupUser.timer = null;
    }
    if (SMenuGroupUser.div != null)
    {
        SMenuGroupUser.overDiv = "0";
        closeSMenuGroupUser();
    }

    SMenuGroupUser.timer = setTimeout("showSMenuGroupUser(" + x + "," + y + ",'" + userId + "','" + userName + "','" + imageSrc + "','" + link + "','" + additionalLink + "','" + additionalLinkText + "')", 600);
};

var showSMenuGroupUser = function(x, y, userId, userName, imageSrc, link, additionalLink, additionalLinkText)
{
    if (SMenuGroupUser.timer)
    {
        clearTimeout(SMenuGroupUser.timer);
        SMenuGroupUser.timer = null;
    }
    if (SMenuGroupUser.div != null)
    {
        SMenuGroupUser.overDiv = "0";
        closeSMenuGroupUser();
    }
    var popupId = "shortcutGroupUser." + userId + ".popup";
    SMenuGroupUser.div = document.getElementById(popupId) ;
    if (SMenuGroupUser.div == null) {
        var C = Community;
        SMenuGroupUser.div = C.CE("div", document.body);
        SMenuGroupUser.div.id = popupId ;
        SMenuGroupUser.div.className = "shortcutGroupUser";

        SMenuGroupUser.div.onmouseover = function()
        {
            SMenuGroupUser.overDiv = "1";
        };
        SMenuGroupUser.div.onmouseout = function()
        {
            SMenuGroupUser.overDiv = "0";
            setTimeout('closeSMenuGroupUser()', 200);
        };

        if (!is_mac)
        {
            var a = C.CE("a", SMenuGroupUser.div, {href:"javascript:void(0);"});
            a.onclick = function()
            {
                if (SMenuGroupUser.onclickLocation)
                {
                    window.location = SMenuGroupUser.onclickLocation;
                }
                return false;
            };
            SMenuGroupUser.image = C.CE("img", a);
        }
        SMenuGroupUser.userName = C.CE("em", C.CE("p", SMenuGroupUser.div));

        SMenuGroupUser.onclickLocation = link;
        SMenuGroupUser.userName.innerHTML = userName;
        SMenuGroupUser.image.src = imageSrc;

        if (!is_mac)
        {
            var addADiv = C.CE("div", SMenuGroupUser.div);
            C.CE("br", addADiv);
            var addA = C.CE("a", addADiv, {href:"javascript:void(0);", className:"feat2"});
            addA.onclick = function()
            {
                if (SMenuGroupUser.additionalLink)
                {
                    window.location = SMenuGroupUser.additionalLink;
                }
                return false;
            };
            addA.appendChild(document.createTextNode(additionalLinkText));
        }

        SMenuGroupUser.additionalLink = additionalLink;
        SMenuGroupUser.additionalLinkText = additionalLinkText;

    }

    SMenuGroupUser.render(x, y);
};

SMenuGroupUser.render = function(x, y)
{
    PopupUtil.setPopupPosition(SMenuGroupUser.div, x, y, 160, 160);
    PopupUtil.correctPopupWidth(SMenuGroupUser.div, 150);
    CUtils.showElement(SMenuGroupUser.div);
    SMenuGroupUser.showDiv = "1";
};

SMenuGroupUser.hideDiv = function()
{
    if (SMenuGroupUser.timer)
    {
        clearTimeout(SMenuGroupUser.timer);
        SMenuGroupUser.timer = null;
    }

    if (SMenuGroupUser.showDiv == "1")
    {
        SMenuGroupUser.overDiv = "0";
        setTimeout('closeSMenuGroupUser()', 200);
    }
};

var closeSMenuGroupUser = function()
{
    if (SMenuGroupUser.overDiv == "0")
    {
        CUtils.hideElement(SMenuGroupUser.div);
        SMenuGroupUser.timer = null;
        SMenuGroupUser.overDiv = "0";
        SMenuGroupUser.showDiv = "0";
    }
};

function SMenuComment()
{
}

SMenuComment.div = null;
SMenuComment.timer = null;
SMenuComment.showDiv = "0";
SMenuComment.overDiv = "0";
SMenuComment.comment = null;

SMenuComment.render = function(x, y)
{
    var div = SMenuComment.div;
    CUtils.showElement(div);
    SMenuComment.showDiv = "1";
    PopupUtil.setPopupPosition(div, x, y, 100, 50);
};

SMenuComment.generateCommentInfo = function(parent)
{
    if (SMenuComment.div)
        return;

    SMenuComment.div = Community.CE("div", parent, {id:"shortcutComment"}, {});
    SMenuComment.div.onmouseover = function()
    {
        SMenuComment.overDiv = "1";
    };

    SMenuComment.div.onmouseout = function()
    {
        SMenuComment.overDiv = "0";
        setTimeout('closeSMenuComment()', 500);
    };

//    SMenuComment.comment = Community.CE("p", SMenuComment.div);
};

SMenuComment.popup = function(e, comment)
{
    if (!e)
        e = window.event;

    var x = e.clientX;
    var y = e.clientY;

    SMenuComment.timer = setTimeout("showSMenuComment(" + x + "," + y + ",'" + comment + "')", 600);
};

SMenuComment.popupPicture = function(e, picture)
{
    if (!e)
        e = window.event;

    var x = e.clientX;
    var y = e.clientY;

    SMenuComment.timer = setTimeout("showSMenuPicture(" + x + "," + y + ",'" + picture + "')", 600);
}

var showSMenuComment = function(x, y, comment)
{
    SMenuComment.generateCommentInfo(document.body);

    if (SMenuComment.comment)
    {
        SMenuComment.div.removeChild(SMenuComment.comment);
        SMenuComment.comment = null;
    }

    SMenuComment.comment = Community.CE("p", SMenuComment.div)
    SMenuComment.comment.innerHTML = comment;
    SMenuComment.render(x, y);
};

var showSMenuPicture = function(x, y, picture)
{
    SMenuComment.generateCommentInfo(document.body);
    
    if (SMenuComment.comment)
    {
        SMenuComment.div.removeChild(SMenuComment.comment);
        SMenuComment.comment = null;
    }
    
    if (CUtils.isIE)
	    SMenuComment.comment = Community.CE("div", SMenuComment.div, {className:"present-thumbnail"}, {filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + picture + ",sizingMethod=crop)", width: "92px", height: "92px" });
	else	    
	    SMenuComment.comment = Community.CE("div", SMenuComment.div, {className:"present-thumbnail"}, {backgroundImage: "url(" + picture + ")", backgroundRepeat: "no-repeat", backgroundPosition: "50% 50%"});

    SMenuComment.render(x, y);	
}

SMenuComment.hideDiv = function()
{
    if (SMenuComment.timer)
    {
        clearTimeout(SMenuComment.timer);
        SMenuComment.timer = null;
    }

    if (SMenuComment.showDiv == "1")
    {
        SMenuComment.overDiv = "0";
        setTimeout('closeSMenuComment()', 500);
    }
};

var closeSMenuComment = function()
{
    if (SMenuComment.overDiv == "0")
    {
        CUtils.hideElement(SMenuComment.div);
        SMenuComment.timer = null;
        SMenuComment.showDiv = "0";
        SMenuComment.overDiv = "0";
    }
};

function Messages()
{
}

var editor = null;

Messages.initEditor=function(textAreaId, lengthCounterId, maxLength, lang, formName)
{
    if (!textAreaId)
        return;
    
    if (typeof(tinymce)=='undefined')
    {
        setTimeout("Messages.initEditor('"+textAreaId+"','"+lengthCounterId+"','"+maxLength+"','"+lang+"','"+formName+"')", 200);
        return false;
    }
    
    try {
		tinyMCE.init({
		    theme : "advanced",
		    mode : "exact",
		    elements: textAreaId,
		    language : lang,
		    plugins : "safari,lengthcounter",
		    lengthCounterElementId : lengthCounterId,
		    lengthCounterMax : maxLength,
		    submitFormName : formName,
			object_resizing : false,
			force_p_newlines : true,
	        convert_fonts_to_spans : false,
	        entities : '160,nbsp',
	        verify_html : true,
            valid_elements : 'strong/b[class|style],-em/-i[class|style],-strike[class|style],-u[class|style],-p[id|style|class|align],br,img[src|border|alt=|title|hspace|vspace|width|height|align],-div[id|class|align|style],-span[style|class|align|color],-pre,-font[face|size|style|id|class|color],-li[class|style],-ol[class|style],-ul[class|style]',
	        invalid_elements : "a",
	        icons : "icons-x",
	        		
			// Theme options
			theme_advanced_buttons1 : "fontselect,fontsizeselect,cut,copy,paste",
			theme_advanced_buttons2 : "bold,italic,underline,strikethrough,|,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,|,undo,redo" ,
			theme_advanced_buttons3 : "",
			theme_advanced_buttons4 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "none",
			theme_advanced_resizing : false,
			theme_advanced_fonts : "Arial=arial,helvetica,sans-serif;Courier New=courier new,courier,monospace;Georgia=georgia,times new roman,times,serif;Tahoma=tahoma,arial,helvetica,sans-serif;Times New Roman=times new roman,times,serif;Verdana=verdana,arial,helvetica,sans-serif;Impact=impact,chicago;Wingdings=wingdings,zapf dingbats",
			theme_advanced_font_sizes : "1,2,3,4"
		});
	} catch (e)	{}

	return false;
}


Messages.changeTextArea=function(form,ev,limit)
{
    ev||(ev=window.event);
    if(ev && ev.keyCode == 13 && (ev.altKey || ev.ctrlKey))
    {
      form.submit();
      return false;
    }

    var msg = form.msg;
    if (msg.value.length > limit)
      msg.value = msg.value.substring(0,limit);

    document.getElementById("fm_len").innerHTML = limit - msg.value.length;
    return false;
}

// ----------------------
// SMILES FUNCTIONALITY

Messages.changeSmiles=function(tagName)
{
    var i,t,tags=document.getElementsByTagName(tagName);
    for(i=0;i<tags.length;i++)
    {
        t=tags[i];
        if(t.className=='msg-area')
        {
            t.innerHTML=OneSmile.smilize(t.innerHTML, smilesPath);
        }
    }
}

Messages.insertSmilesToInput=function(input, abreviation, src)
{
    if(tinyMCE.activeEditor)
    {
        tinyMCE.activeEditor.contentWindow.focus();
        var sel = tinyMCE.activeEditor.selection.getSel();
        var range = tinymce._createRange(sel);

        image = tinymce.getParentElement();
        if (!image || !/^img$/i.test(image.tagName))
        {
            tinyMCE.activeEditor.execCommand("mceInsertContent",true,'&nbsp;<img src="' + src + '" alt="' + abreviation + '" onresizestart="return false;" onresizeend="return false;" />');
        }
        else
        {
            image.src = src;
            image.alt = abreviation;
        }

        if (is_ie)
        {
            range.collapse(false);
            range.select();
        }
        else
        {
	        try {
	            var n = sel.focusNode.nextSibling;
	            if (n && n.nodeType != 1 && n.nextSibling)
	                n = n.nextSibling;
	
	            if (n)
	            {
	                sel.removeAllRanges();
	                range = document.createRange();
	                range.selectNode(n.nextSibling);
	                range.collapse(true);
	                sel.addRange(range);
	            }
	        } catch (e) {}
        }

        tinyMCE.execCommand("mceCountMessageLength");
    }
    else
    {
        if(is_ie)
        {
            if(input.isTextEdit)
            {
                input.focus();
                var sel=document.selection;
                var rng=sel.createRange();
                rng.colapse;
                if((sel.type == "Text" || sel.type == "None") && rng != null)
                {
                    rng.text = abreviation;
                }
            }
            else{
                    input.value += abreviation;
            }
        }
        else
        {
            input.value+=abreviation;
        }

        input.focus();
    }
}

Messages.createSmilesArea=function(parent, input)
{
    if (is_mac)
        return;

	var C=Community,tbody,row,i,str,img,smile,src,firstDiv;
	firstDiv=C.CE("div",parent,{},{position:"relative"});
    tbody=C.CE("tbody",C.CE("table",firstDiv));

	for(i=0;i<52;++i)
	{
        if (i==47)
            continue;

        if(i%17==0 && i<51)
            row=C.CE("tr",tbody);

        smile=OneSmile.smiles[i];
		img=C.CE("img",C.CE("td",row),{src:smilesPath+smile[0],title:smile[1]},{cursor:"pointer"});

        img.onclick=function()
        {
            Messages.insertSmilesToInput(input,this.title,this.src);
        };

		img.onmousedown=function()
		{
			return false;
		};
	}
}

function OneSmile()
{
}

OneSmile.smiles=[
    ['04a.gif',':-)',[/(:|=)[-]?\)/gi]],
    ['06a.gif',':-(',[/(:|=)[-]?\(/gi]],
    ['09a.gif',';-)',[/;[-]?\)/gi]],
    ['11a.gif',':-D',[/(:|=)[-]?(D|d)/gi]],
    ['02.gif',':-@',[/(:|=)[-]?@/gi]],
    ['01.gif','^o)',[/\^o\)/gi]],
    ['03a.gif',':-S',[/(:|=)[-]?(S|s)/gi]],
    ['07a.gif','*-)',[/\*-\)/gi]],
    ['08a.gif',':-|',[/[:=][-]?[|I]/gi]],
    ['10a.gif','8oI',[/8o(I|\|)/gi]],
    ['14a.gif',':-P',[/(:|=)[-]?(P|p)/gi]],
    ['26a.gif',':-$',[/(:|=)[-]?\$/gi]],
    ['27a.gif',':-O',[/(:|=)[-](O|o|0)/gi]],
    ['28a.gif','|-)',[/\|-\)/gi]],
    ['41.gif','(ch)',[/\((C|c)(H|h)\)/gi]],
    ['44a.gif','(lo)',[/\((L|l)(O|o)\)/gi]],
    ['45a.gif','(sr)',[/\((S|s)(R|r)\)/gi]],
    ['46a.gif','|-(',[/\|-\(/gi]],
    ['47a.gif','(H)',[/\((H|h)\)/gi]],
    ['48a.gif','(hu)',[/\((H|h)(U|u)\)/gi]],
    ['49a.gif','(tr)',[/\((T|t)(R|r)\)/gi]],
    ['50a.gif','(md)',[/\((M|m)(D|d)\)/gi]],
    ['51a.gif','(fr)',[/\((F|f)(R|r)\)/gi]],
    ['52a.gif','(dt)',[/\((D|d)(T|t)\)/gi]],
    ['53a.gif','(sc)',[/\((S|s)(C|c)\)/gi]],
    ['12.gif','(Y)',[/\((Y|y)\)/gi]],
    ['15.gif','(N)',[/\((N|n)\)/gi]],
    ['34.gif','(v)',[/\((V|v)\)/gi]],
    ['16.gif','(L)',[/\((L|l)\)/gi]],
    ['17.gif','(U)',[/\((U|u)\)/gi]],
    ['24.gif','(K)',[/\((K|k)\)/gi]],
    ['23.gif','(F)',[/\((F|f)\)/gi]],
    ['32.gif','(*)',[/\(\*\)/gi]],
    ['19.gif','(^)',[/\((\^)\)/gi]],
    ['21.gif','(G)',[/\((G|g)\)/gi]],
    ['25.gif','(B)',[/\((B|b)\)/gi]],
    ['29.gif','(D)',[/\((D|d)\)/gi]],
    ['22.gif','(C)',[/\((C|c)\)/gi]],
    ['30.gif','(pi)',[/\(pi\)/gi]],
    ['33.gif','(pl)',[/\(pl\)/gi]],
    ['36.gif','(ic)',[/\((I|i)(C|c)\)/gi]],
//    ['37.gif','(dc)',[/\((D|d)(C|c)\)/gi]],
    ['baks.gif','($)',[/\(\$\)/gi]],
    ['35.gif','(co)',[/\((C|c)(O|o)\)/gi]],
    ['38.gif','(so)',[/\((S|s)(O|o)\)/gi]],
    ['40.gif','(te)',[/\((T|t)(E|e)\)/gi]],
    ['39.gif','(nt)',[/\((N|n)(T|t)\)/gi]],
    ['18.gif','(I)',[/\((I|i)\)/gi]],
    ['20.gif','(E)',[/\((E|e)\)/gi]],
    ['42.gif','(Z)',[/\((Z|z)\)/gi]],
    ['43.gif','(X)',[/\((X|x)\)/gi]],
    ['31.gif','(S)',[/\((S|s)\)/gi]]
];

OneSmile.smilize=function(str,path)
{
	var i,j,v,regs,tag;

	for(i=this.smiles.length-1;i>=0;--i)
	{
		v=this.smiles[i];
		tag='<img align="middle" src="'+path+v[0]+'" />';

        regs=v[2];
		for(j=regs.length;--j>=0;)
			str=str.replace(regs[j],tag);
	}

    str=str.replace(/&nbsp;<img/gi,'\n<img');

	return str;
};

function selectCheckBoxs(mainbox, boxname)
{
    var elems = mainbox.form.elements;
    var elemnum = elems.length;

    for(i=0; i < elemnum; i++)
      if(elems[i].name.substr(0, boxname.length) == boxname)
        elems[i].checked = mainbox.checked;
}

function SSidebanner()
{
}

SSidebanner.generateFirst = function(parent, targetParamStr, rleurl, sec)
{
    if (!parent)
        return;

	if(typeof(ar_cn)=="undefined") ar_cn=1;
	var ar_link="http://ad.adriver.ru/cgi-bin/erle.cgi?sid=75012" + targetParamStr + "&target=blank&bt=49&pz=0&rleurl=" + rleurl;

	document.write('<div id="ad_ph_'+ar_cn+'_" style="visibility:hidden;height:0px">'
	+ '<iframe id="ar_container_'+ar_cn+'" width=1 height=1 marginwidth=0 marginheight=0 scrolling=no frameborder=0>'
	+ '<\/iframe><\/div>'
	+ '<div style="display:none;margin-bottom:10px" id="ad_ph_'+ar_cn+'"><\/div>');
	(function(num,link){
		function addEvent(e,t,f){
			if (e.addEventListener) e.addEventListener(t, f, false);
			else if (e.attachEvent) e.attachEvent('on'+t, f)
		}
		function removeEvent(e,t,f){
			if (e.removeEventListener) e.removeEventListener(t, f, false);
			else if (e.detachEvent) e.detachEvent('on'+t, f)
		}
	
		var t = 0;
		
		var BannerLoader = {
			
			seconds: sec, //life time for reply repair
			expiration: 0, // 0 - for 'none' or another in minutes
		
			top: 0,
			cm: document.compatMode == "CSS1Compat",
	
			G: function(n){
				if(!this.cookie.match(n))return 0;
				
				var s=this.cookie.indexOf(n);
				var e=this.cookie.indexOf(';',s);
				if(e<0)e=this.cookie.length;
				
				var c = this.cookie.substring(s,e);
				return c.substr(c.indexOf('=')+1)
			},
			
			S: function(s){	
				var z = '';
				if(this.expiration){
					z = new Date();
					z.setMinutes(z.getMinutes()+this.expiration);
					z = ';expires='+z.toGMTString();
				}
				document.cookie='ar_session='+s+';path=/'+z;
				document.cookie='ar_session_exp='+(new Date())+';path=/'+z;
			},
			
			tryGetReply: function(){
				if(t++<100){
					if(document.all&&!window.opera) var win = window.frames['ar_container_'+num].window;
					else if(document.getElementById) var win = document.getElementById('ar_container_'+num).contentWindow;
					
					if (win&&win.name!='ready') setTimeout(arguments.callee, 100);
					else {
						function MakeCookie(){
							var i=0,s="";
							var n = ["CgiHref","ar_bt","ar_siteid","Mirror","bid","sliceid","ar_adid","ar_pz","ar_sz","ar_nid","ar_bn","Path",
									"Comp0","Width","Height","date","Uid","Target","Alt","CompPath","RndNum4NoCash","ar_ntype","ar_tns"];
							for(;i<n.length;i++)s+=escape(n[i]+"='"+win[n[i]]+"';")+"|";
							s += escape("ScriptSrc='"+win.Mirror + win.Path + win.Comp0 + "?" + win.RndNum4NoCash+"';");
							return s
						};
						BannerLoader.S(MakeCookie()); 
					}
				}
			},
			
			getParam: function(s){
				var n = this.repl.split('|');
				for(var i=0;i<n.length;i++) {
					var str = unescape(n[i]);
					if (str.indexOf(s+'=')==0) return str.split('=')[1].replace(/'|"/g,'').replace(/;/g,'');
				}
			},
			
			repairFromReply: function(){
				if(t++<100){
					var doc;
					if(document.all&&!window.opera) doc = window.frames['ar_container_'+num].document;
					else if(document.getElementById) doc = document.getElementById('ar_container_'+num).contentDocument;
				
					if (!doc) setTimeout(arguments.callee, 100);
					else {
						function MakeVars(r){
							var i=0,s="",n=r.split('|');
							for(;i<n.length;i++)s+='var '+unescape(n[i]);
							return s
						};
						var s = 'var ar_bnum='+num+';'+MakeVars(this.repl)
						+'document.write(\"<sc\"+\"ript language=\\"JavaScript\\" type=\\"text/javascript\\" src=\"+ScriptSrc+\"><\\/sc\"+\"ript>\");';
						doc.write('<sc'+'ript language="JavaScript" type="text/javascript">'+s+'<\/sc'+'ript>');
						BannerLoader.S(this.repl);
					}
				}
			},
			
			getDoc: function(){
				if(t++<100){
					var doc;
					if(document.all&&!window.opera) doc = window.frames['ar_container_'+num].document;
					else if(document.getElementById) doc = document.getElementById('ar_container_'+num).contentDocument;
				
					if (!doc) setTimeout(arguments.callee, 100);
					else {
						var RndNum4NoCash = Math.round(Math.random() * 1000000000);
						var s = 'var t=0;var ar_bnum='+num+';'
						+ '(function(){if(t++<100){if(typeof window.ar_tns=="undefined")setTimeout(arguments.callee,100);'
						+ 'else{window.name="ready"}}})();';
						doc.write('<sc'+'ript language="JavaScript" type="text/javascript">'+s+'<\/sc'+'ript>');
						doc.write('<sc'+'ript language="JavaScript" type="text/javascript" src="'+link+'&rnd='+RndNum4NoCash+'"><\/sc'+'ript>');
						t = 0;
						BannerLoader.tryGetReply();
					}
				}
			},
			
			scroll: function(){
				var ch = self.innerHeight || this.cm && document.documentElement.clientHeight || document.body.clientHeight;
				var st  = self.pageYOffset || this.cm && document.documentElement.scrollTop || document.body.scrollTop;
				if (this.top >= st && st + ch >= this.top) {
					removeEvent(window, 'scroll', this.sfunc);
					this.repl = this.G('ar_session');
					this.exp = this.G('ar_session_exp');
					if (this.exp) {
						this.exp = new Date(this.exp);
						this.exp.setSeconds(this.exp.getSeconds()+this.seconds);
						
						if (this.exp>new Date()) {
							this.repairFromReply(); // no request to AdRiver 
						}
						else {
							this.getDoc(); // request to Ardiver
							(new Image).src='http://ad.adriver.ru/cgi-bin/event.cgi?&bid=' + this.getParam('bid')
							+ '&ntype=' + this.getParam('ar_ntype')
							+ '&type=0&rnd=' + Math.round(Math.random()*1000000);
						}
					}
					else {
						this.getDoc(); // request to Ardiver
					}
				}
			},
	
			sfunc: function(){BannerLoader.scroll()},
			
			init: function(){
				this.cookie = document.cookie;
				document.cookie='ar_cookie_accept=1';
				if(document.cookie.indexOf('ar_cookie_accept=1')==-1) return;
				
				var t = this;
				var obj = document.getElementById('ad_ph_'+num + "_");
				if (obj){
					while(obj.offsetParent){t.top += obj.offsetTop; obj = obj.offsetParent}
					addEvent(window, 'scroll', this.sfunc);
					t.scroll();
				}
			}
		};
	
		addEvent(window, 'load', function(){ try {BannerLoader.init() } catch(e) {} });
	})(ar_cn++,ar_link);
}

SSidebanner.generateFirstNew = function(parent, targetParamStr, rleurl, sec)
{
    if (!parent)
        return;

	if (typeof(ar_cn)=="undefined") ar_cn=1;
	var ar_link="http://ad.adriver.ru/cgi-bin/erle.cgi?sid=75012" + targetParamStr + "&bt=49&pz=0";

	document.write('<div id="ad_ph_'+ar_cn+'_" style="visibility:hidden;height:0px;"><iframe id="ar_container_'+ar_cn+'" width=1 height=1 marginwidth=0 marginheight=0 scrolling=no frameborder=0><\/iframe><\/div><div style="display:none;margin-bottom:10px" id="ad_ph_'+ar_cn+'"><\/div>');

	(function(num,link){
		function addEvent(e,t,f){
			if (e.addEventListener) e.addEventListener(t, f, false);
			else if (e.attachEvent) e.attachEvent('on'+t, f)
		}
		function removeEvent(e,t,f){
			if (e.removeEventListener) e.removeEventListener(t, f, false);
			else if (e.detachEvent) e.detachEvent('on'+t, f)
		}
	
		var t = 0;
		
		var BannerLoader = {
			
			ar_keyword: rleurl,
			
			seconds: sec,
			expiration: 0,
			ar_pix: '',
		
			top: 0,
			cm: document.compatMode == "CSS1Compat",
	
			G: function(n){
				if(!this.cookie.match(n))return 0;
				
				var s=this.cookie.indexOf(n);
				var e=this.cookie.indexOf(';',s);
				if(e<0)e=this.cookie.length;
				
				var c = this.cookie.substring(s,e);
				return c.substr(c.indexOf('=')+1)
			},
			
			S: function(n,s){	
				var z = '';
				if(this.expiration){
					z = new Date();
					z.setMinutes(z.getMinutes()+this.expiration);
					z = ';expires='+z.toGMTString();
				}
				document.cookie= n+'='+s+';path=/'+z;
			},
			
			tryGetReply: function(){
				if(t++<100){
					if(document.all&&!window.opera) var win = window.frames['ar_container_'+num].window;
					else if(document.getElementById&&document.getElementById('ar_container_'+num))
						var win = document.getElementById('ar_container_'+num).contentWindow;
					
					if (win&&win.name!='ready') setTimeout(arguments.callee, 300);
					else {
						function MakeCookie(){
							var i=0,s="";
							var n = ["CgiHref","ar_bt","ar_siteid","Mirror","bid","sliceid","ar_adid","ar_pz","ar_sz","ar_nid","ar_bn","Path",
									"Comp0","Width","Height","date","Uid","Target","Alt","CompPath","RndNum4NoCash","ar_ntype","ar_tns"];
							for(;i<n.length;i++)s+=escape(n[i]+"='"+win[n[i]]+"';")+"|";
							s += escape("ScriptSrc='"+win.Mirror + win.Path + win.Comp0 + "?" + win.RndNum4NoCash+"';|");
							return s
						};
						
						BannerLoader.S('ar_sess_pix',win["ar_pix"]);
						BannerLoader.S('ar_sess_seconds',win["ar_expiration"]);
						BannerLoader.S('ar_session',MakeCookie()); 
						BannerLoader.S('ar_session_exp',(new Date()));
					}
				}
			},
			
			getParam: function(s){
				var n = this.repl.split('|');
				for(var i=0;i<n.length;i++) {
					var str = unescape(n[i]);
					if (str.indexOf(s+'=')==0) return str.split('=')[1].replace(/'|"/g,'').replace(/;/g,'');
				}
			},
			
			repairFromReply: function(){
				if(t++<100){
					var doc;
					if(document.all&&!window.opera) doc = window.frames['ar_container_'+num].document;
					else if(document.getElementById) doc = document.getElementById('ar_container_'+num).contentDocument;
				
					if (!doc) setTimeout(arguments.callee, 100);
					else {
						var s = 'var ar_bnum='+num+'; var ar_keyword="'+this.ar_keyword+'";'+unescape(this.repl).replace(/(.+?;)\|/g,'var $1')
						+'document.write(\"<sc\"+\"ript language=\\"JavaScript\\" type=\\"text/javascript\\" src=\"+ScriptSrc+\"><\\/sc\"+\"ript>\");';
						doc.write('<sc'+'ript language="JavaScript" type="text/javascript">'+s+'<\/sc'+'ript>');
					}
				}
			},
			
			getDoc: function(){
				if(t++<100){
					var doc;
					if(document.all&&!window.opera) doc = window.frames['ar_container_'+num].document;
					else if(document.getElementById) doc = document.getElementById('ar_container_'+num).contentDocument;
				
					if (!doc) setTimeout(arguments.callee, 300);
					else {
						var RndNum4NoCash = Math.round(Math.random() * 1000000000);
						var s = 'var t=0;var ar_bnum='+num+'; var ar_keyword="'+this.ar_keyword+'";'
						+ '(function(){if(t++<100){if(typeof window.ar_pix=="undefined")setTimeout(arguments.callee,100);'
						+ 'else{window.name="ready"}}})();';
						doc.write('<sc'+'ript language="JavaScript" type="text/javascript">'+s+'<\/sc'+'ript>');
						doc.write('<sc'+'ript language="JavaScript" type="text/javascript" src="'+link+'&rnd='+RndNum4NoCash+'"><\/sc'+'ript>');
						t = 0;
						BannerLoader.tryGetReply();
					}
				}
			},
			
			scroll: function(){
				var ch = self.innerHeight || this.cm && document.documentElement.clientHeight || document.body.clientHeight;
				var st  = self.pageYOffset || this.cm && document.documentElement.scrollTop || document.body.scrollTop;
				if (this.top >= st && st + ch >= this.top) {
					removeEvent(window, 'scroll', this.sfunc);
					this.repl = this.G('ar_session');
					this.exp = this.G('ar_session_exp');
					//this.seconds = parseInt(this.G('ar_sess_seconds'))||0;
					this.ar_pix = this.G('ar_sess_pix');
					
					if (this.exp) {
						this.exp = new Date(this.exp);
						this.exp.setSeconds(this.exp.getSeconds()+this.seconds);
						
						if (this.exp>new Date()) {
							this.repairFromReply();
						}
						else {
							var src='http://ad.adriver.ru/cgi-bin/event.cgi?bid=' + this.getParam('bid')
							+ '&ntype=' + this.getParam('ar_ntype')
							+ '&sliceid=' + this.getParam('sliceid')
							+ '&ad=' + this.getParam('ar_adid')
							+ '&type=0&rnd=' + Math.round(Math.random()*1000000);
						
							function pix(s){
								if (!s) return;
								var obj = document.getElementById('ad_ph_'+num+'_');
								if(document.createElement){
									var i=document.createElement('img');
									i.style.display='none';i.style.width=i.style.height='0px';
									i.src=s;
									obj.appendChild(i);
								}
								else{obj.innerHTML += '<img src="'+s+'" border=0 width=0 height=0>'}
							}
							
							pix(src);
							pix(this.ar_pix);
							
							var t = this;
							setTimeout(function(){t.getDoc()},1000);
						}
					}
					else {
						this.getDoc();
					}
				}
			},
	
			sfunc: function(){BannerLoader.scroll()},
			
			init: function(){
				this.cookie = document.cookie;
				document.cookie='ar_cookie_accept=1';
				if(document.cookie.indexOf('ar_cookie_accept=1')==-1) return;
				
				var t = this;
				var obj = document.getElementById('ad_ph_'+num+'_');
				if (obj){
					while(obj.offsetParent){t.top += obj.offsetTop; obj = obj.offsetParent}
					addEvent(window, 'scroll', this.sfunc);
					t.scroll();
				}
			}
		};
	
		addEvent(window, 'load', function(){ try {BannerLoader.init()} catch(e) {} });
	})(ar_cn++,ar_link);
}

SSidebanner.generateSecond = function(parent, targetParamStr, rleurl)
{
    if (!parent)
        return;

	document.write('<div id=\"sideadv_banner2\" style=\"display:block;width:240px;height:400px;background-color:#FFF\"></div>');
	
	var SecondBannerLoader = { 
	    loaded: false, top: 0, banner: null, old_handler: window.onscroll, cm : document.compatMode == "CSS1Compat",
	    code: '<iframe src=\"http://ad.adriver.ru/cgi-bin/erle.cgi?'
	        + 'sid=75012' + targetParamStr + '&target=blank&bt=22&pz=0&rleurl=' + rleurl + '&rnd=' + Math.round(Math.random() * 100000000)
	        + '\" frameborder=0 vspace=0 hspace=0 width=240 height=400'
	        + ' marginwidth=0 marginheight=0 scrolling=no><\\/iframe>',
	    scroll: function (){
	        try {
	            if (!this.loaded){
	                var ch = self.innerHeight || this.cm && document.documentElement.clientHeight || document.body.clientHeight;
	                var st  = self.pageYOffset || this.cm && document.documentElement.scrollTop || document.body.scrollTop;
	                if (this.top > st && st + ch > this.top) {this.loaded=true; window.onscroll = this.old_handler; this.banner.innerHTML = this.code }
	                if (this.old_handler) this.old_handler();
	            }
	        }catch(e){};
	    },
	    init: function (id){
	        try {
	            var obj = document.getElementById(id);
	            if (obj){
	                this.top += parseInt(obj.style.height)/2;
	                this.banner = obj;while(obj.offsetParent){this.top += obj.offsetTop; obj = obj.offsetParent}
	                var t = this; window.onscroll = function(){t.scroll()}; this.scroll();
	            }
	        }catch(e){};
	    }
	};
	
	function init_SecondBannerLoader() {
	    try {
	        if (arguments.callee.done) return;
	        arguments.callee.done = true;
	        if (_timer) {
	            clearInterval(_timer);
	            _timer = null;
	        }
	        SecondBannerLoader.init("sideadv_banner2");
	    }catch(e){};
	};
	
	if (document.addEventListener) {
	    document.addEventListener("DOMContentLoaded", init_SecondBannerLoader, false);
	}
	
	/*@cc_on @*/
	/*@if (@_win32)
	    document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	    var script = document.getElementById("__ie_onload");
	    script.onreadystatechange = function() {
	        if (this.readyState == "complete") {
	            init_SecondBannerLoader();
	        }
	    };
	/*@end @*/
	
	if (/WebKit/i.test(navigator.userAgent)) {
	    var _timer = setInterval(function() {
	        if (/loaded|complete/.test(document.readyState)) {
	            init_SecondBannerLoader();
	        }
	    }, 10);
	}
	
	var old_onload_SecondBannerLoader = window.onload;
	window.onload = function() {
        if (old_onload_SecondBannerLoader)
            old_onload_SecondBannerLoader();

	    try
	    {
	        init_SecondBannerLoader();
	    }
	    catch (e)
	    {
        }
	}
}
                                
