if(!Array.prototype.without)
{
    Array.prototype.without = function() {
        var result = [], i = 0, length = this.length, length_ = arguments.length;
        while (i < length) {
            var I = this[i++], k = length_;
            while (k-- && arguments[k] !== I);
            if (k < 0) result[result.length] = I;
        }
        return result;
    };
}

function screenHeight(){
    return $.browser.opera? window.innerHeight : $(window).height();
}

function screenWidth(){
    return $.browser.opera? window.innerWidth : $(window).width();
}

function microtime(get_as_float) {     
    var now = new Date().getTime() / 1000;  
    var s = parseInt(now);  
   
    return (get_as_float) ? now : (Math.round((now - s) * 1000) / 1000) + ' ' + s;  
}  

function contentSize() {
    var w, h;
    w = (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth);
    h = (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight);
    return {
        w:w,
        h:h
    };
}
if(!Array.prototype.remove)
{
    Array.prototype.remove = function(from, to) {
        this.splice(from, !to || 1 - from + to +
            ((to < 0 || -1) && !(to < 0 ^ from > -1)) * this.length);
        return this.length;
    };
}

function htmlspecialchars_encode(html, quote_style) 
{
    html = html.replace(/&/g, "&amp;");
    html = html.replace(/</g, "&lt;");
    html = html.replace(/>/g, "&gt;");
    html = html.replace(/"/g, "&quot;");
    return html;
}

function htmlspecialchars_decode(string, quote_style)
{
    string = string.toString();
    string = string.replace('/&amp;/g', '&');
    string = string.replace('/&lt;/g', '&lt;');
    string = string.replace(/&gt;/g, '&gt;');
    if (quote_style == 'ENT_QUOTES') {
        string = string.replace('/&quot;/g', '"');
        string = string.replace('/&#039;/g', '\'');
    }else if (quote_style != 'ENT_NOQUOTES') {
        string = string.replace('/&quot;/g', '"');
    }
    return string;
}

function getRequestObject()
{
    var req = null;
    if (typeof XMLHttpRequest != "undefined")
        req = new XMLHttpRequest();
    if (!req && typeof ActiveXObject != "undefined")
    {
        try
        {
            req=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                req=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e2)
            {
                try {
                    req=new ActiveXObject("Msxml2.XMLHTTP.4.0");
                }
                catch (e3)
                {
                    req=null;
                }
            }
        }
    }
    if(!req && window.createRequest)
        req = window.createRequest();
			
    return req;
}

var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

var DarkBlock = {

    // private property
    dark_back : "darkframe",
	
    dark_win : "darkwin",
	
    dback : null,
	
    dwin : null,
	
    dlink : null,
	
    dtext : null,
	
    dwidth: 800,
	
    dheight: 550,

    Init: function (linktext) {
        var container = document.getElementById('wrp').parentNode;
        if(this.dback)
        {
            return false;
        }
        else
        {
            this.dlink=document.createElement('a');
            this.dtext=document.createElement('div');
            this.dlink.onclick= function()
            {
                DarkBlock.Hide();
            }
            this.dlink.innerHTML=linktext;
            this.dlink.style.position='absolute';
            this.dlink.style.right="10px";
            this.dlink.style.top="5px";
            this.dlink.href="javascript:void(null);";
            this.dback=document.createElement('div');
            this.dwin =document.createElement('div');
            this.dwin.appendChild(this.dtext);
            this.dwin.appendChild(this.dlink);
            this.dback.style.display='none';
            this.dwin.style.display='none';
            this.dback.style.position='fixed';
            this.dwin.style.position='absolute';
            this.dback.style.zIndex=15000;
            this.dwin.style.zIndex=15001;
            this.dback.style.opacity=0.8;
            this.dwin.style.padding="30px";
            this.dwin.style.backgroundColor="#fff";
            this.dback.href="javascript:void(null);";

            this.dback.onclick= function()
            {
            //DarkBlock.Hide();
            }
            container.appendChild(this.dback);
            container.appendChild(this.dwin);
			
        }
    },
	
    Resize: function (w, h){
        this.dwidth=w;
        this.dheight=h;
    },
	
    Show: function(value) {
        this.dback.style.width=document.body.scrollWidth+"px";
        this.dback.style.height=document.body.scrollHeight+"px";
        this.dback.style.top="0px";
        this.dback.style.left="0px";
        this.dback.style.backgroundColor="#000";
        this.dback.style.display="";
        this.dwin.style.display="";
        this.dwin.style.height=this.dheight+"px";
        this.dwin.style.width=this.dwidth+"px";
        this.dwin.style.top="40px";
        this.dwin.style.left=(Math.round(($(window).width()-this.dwidth)/2)-30)+"px";
        this.dtext.style.height="100%";
        this.dtext.style.overflow="auto";
        this.dtext.innerHTML=value;
        var scripts = this.dtext.getElementsByTagName('script');
        if(scripts.length>0)
        {
            var loaderList = [];
            for(var scr_ic=0; scr_ic<scripts.length; scr_ic++)
            {
                if(scripts[scr_ic].getAttribute('type')=='text/javascript')
                {
                    if(scripts[scr_ic].getAttribute('src'))
                    {
                        loaderList.push({
                            name: scripts[scr_ic].getAttribute('src'),
                            useeval : false
                        });
                    }
                    else
                    {
                        loaderList.push({
                            name: scripts[scr_ic].textContent ? scripts[scr_ic].textContent : scripts[scr_ic].text,
                            useeval : true
                        });
                    }
                }
            }
            if(loaderList.length>0) (new ScriptLoader(loaderList)).run();
        }
        $.scrollTo(DarkBlock.dwin, 400);
    },
	
    Hide: function() {
        DarkBlock.dwin.style.display='none';
        DarkBlock.dback.style.display='none';
    }
}

function OpenLetterForm(code, closeText)
{
    DarkBlock.Init(closeText);
    DarkBlock.Show('Acheache!');
}

function GETparams()
{
    var get = new String(window.location);
    x = get.indexOf('?');
    f = get.indexOf('#');
    if(x!=-1)
    {
        var l = get.length;
        if(f!=-1) l=(l>f?f:l);
        get = get.substr(x+1, l-x-1);
        pairs = get.split('&');
        var list = new Array(pairs.length);
        for(i=0; i<pairs.length; i++)
        {
            var itm=pairs[i].split('=');
            itm[0] = unescape(itm[0]);
            itm[1] = unescape(itm[1]);
            if(itm[0].substr(itm[0].length-2, 2)=='[]')
            {
                itm[0]=itm[0].replace('[]','');
                if(list[itm[0]])
                {
                    if(typeof(list[itm[0]]) != 'object')
                    {
                        var oldVal = list[itm[0]];
                        list[itm[0]]=new Array();
                        list[itm[0]].push(oldVal);
                    }
                }
                else
                {
                    list[itm[0]] = new Array();
                }
                list[itm[0]].push(itm[1]);
            }
            else
            {
                list[itm[0]]=itm[1];
            }
        }
        return list;
		
    }
    else return null;
	
}

function GETparam(name)
{
    var lst=GETparams();
    if(lst)
    {
        try
        {
            return lst[name];
        }
        catch(ex)
        {
            return '';
        }
    }
    else
    {
        return '';
    }
}

function toggle()
{
    for(i=0; i<arguments.length; i++)
    {
        document.getElementById(arguments[i]).style.display=(document.getElementById(arguments[i]).style.display=='none'?'':'none');
    }
    return !(document.getElementById(arguments[arguments.length-1]).style.display=='none');
}

function DialogForm(xhr_ss, notifierObj) {
    this.xhr = getRequestObject();
    this.xhr_sside = xhr_ss;
    this.cmd = null;
    this.params = null;
    this.ntcObj = notifierObj; 
}

DialogForm.prototype.cmd = null;
DialogForm.prototype.params = null;
DialogForm.prototype.xhr = null;
DialogForm.prototype.xhr_sside = '';

DialogForm.prototype.GetForm = function(cmd, params)
{
    this.cmd = cmd;
    this.params = params;
    var req = this.CreateRequest(this.cmd, params);
    if(req) req = '<root>' + req + '</root>';
    this.Request(this.xhr_sside, "POST", req);
};

DialogForm.prototype.CreateRequest = function(cmdName, paramObj)
{
    var reqString = '';
    for(var key in paramObj)
    {
        if(key) {
            if(key.length>0) {
                if(encodeURIComponent(paramObj[key])==paramObj[key]) {
                    reqString += '<p n="' + key + '" v="' + paramObj[key] + '" />';
                } else {
                    reqString += '<p n="' + key + '"><![CDATA[' + Base64.encode(paramObj[key]) + ']]></p>';
                }
            }
        }
    }
    reqString = '<c n="' + cmdName + '">' + reqString + '</c>';
    return reqString;
};

DialogForm.prototype.Request = function(url, type, request, extraHeaders)
{
    if(type != "POST") type = "GET";
    if(request.length==0) request=null;
    this.xhr.open(type, url, true);
    this.xhr.DialogForm = this;
    this.xhr.onreadystatechange = this.ProcessRequest;
    if(request && type=="POST")
    {
        this.xhr.setRequestHeader("Content-type", "text/xml");
    }
    if(extraHeaders)
    {
        for(var key in extraHeaders)
        {
            this.xhr.setRequestHeader(key, extraHeaders[key]);
        }
    }
    this.xhr.send(request);
};

DialogForm.prototype.ProcessRequest = function()
{
    if(this.readyState!=4) return;
    if(this.status==200)
    {
        this.DialogForm.ParseData(this.responseXML);
    } else {
        if(this.DialogForm.ntcObj) {
            this.DialogForm.ntcObj.append('clntc'+MD5_hexhash(microtime(true)), this.status + ': ' + document.ttrLang.Text("XHR_error_occurred"), false);
        }
    }
};

DialogForm.prototype.ParseData = function(dataXML)
{
    var cmdResponse = null;
    var cmdList = dataXML.getElementsByTagName('c');
    for(var i=0; i<cmdList.length && cmdResponse == null; i++)
    {
        if(cmdList[i].getAttribute('n')==this.cmd) cmdResponse = cmdList[i];
    }

    if(cmdResponse)
    {

        var type = cmdResponse.getAttribute('t');
        if(type=='xhr')
        {

        }
        else if(type=='pst')
        {
            DarkBlock.Init(Base64.decode(cmdResponse.getElementsByTagName('dbl')[0].firstChild.nodeValue));
            DarkBlock.Show(Base64.decode(cmdResponse.getElementsByTagName('f')[0].firstChild.nodeValue));
        }
        else
        {
            alert('XML format error');
        }

        var scripts = cmdResponse.getElementsByTagName('script');
        if(scripts.length>0)
        {
            var loaderList = [];
            for(var scr_ic=0; scr_ic<scripts.length; scr_ic++)
            {
                if(scripts[scr_ic].getAttribute('type')=='text/javascript')
                {
                    if(scripts[scr_ic].getAttribute('src'))
                    {
                        loaderList.push({
                            name: scripts[scr_ic].getAttribute('src'),
                            useeval : false
                        });
                    }
                    else
                    {
                        loaderList.push({
                            name: scripts[scr_ic].textContent ? scripts[scr_ic].textContent : scripts[scr_ic].text,
                            useeval : true,
                            context: cmdResponse
                        });
                    }
                }
            }
            if(loaderList.length>0) (new ScriptLoader(loaderList)).run();
        }

        var redir = cmdResponse.getElementsByTagName('rdr');
        if(redir.length>0)
            if(redir[0].firstChild)
                if(redir[0].firstChild.nodeValue)
                {
                    document.location.href = Base64.decode(redir[0].firstChild.nodeValue);
                    return;
                }
        var refresh = cmdResponse.getElementsByTagName('rfr');
        if(refresh.length>0) {
            document.location = document.location.href;
            return;
        }

        var rreq = cmdResponse.getElementsByTagName('rreq');
        if(rreq.length>0)
            if(rreq[0].firstChild)
            {
                var reCmdNode = rreq[0];
                var nCmd = reCmdNode.getElementsByTagName('c')[0];
                var oParams = {};
                var nParams = nCmd.getElementsByTagName('p')
                for(var i=0; i<nParams.length; i++)
                {
                    oParams[nParams[i].getAttribute('n')]=nParams[i].getAttribute('v');
                }
                this.GetForm(nCmd.getAttribute('n'), oParams);
                return;
            }
        var announce = cmdResponse.getElementsByTagName('ann');
        if(announce.length>0)
            if(announce[0].firstChild)
                if(announce[0].firstChild.nodeValue)
                {
                    alert(Base64.decode(announce[0].firstChild.nodeValue));
                    return;
                }
    }
};

function CreateMSXMLDocumentObject () {
    if (typeof (ActiveXObject) != "undefined") {
        var progIDs = [
        "Msxml2.DOMDocument.6.0",
        "Msxml2.DOMDocument.5.0",
        "Msxml2.DOMDocument.4.0",
        "Msxml2.DOMDocument.3.0",
        "MSXML2.DOMDocument",
        "MSXML.DOMDocument"
        ];
        for (var i = 0; i < progIDs.length; i++) {
            try {
                return new ActiveXObject(progIDs[i]);
            } catch(e) {};
        }
    }
    return null;
}

function CreateXMLDocumentObject (rootName) {
    if (rootName == null)
        rootName = "";
    var xmlDoc = null;
    //Firefox, Opera, Safari and Google Chrome
    if (document.implementation.createDocument) {
        xmlDoc = document.implementation.createDocument ("", rootName, null);
    }
    else {
        // Internet Explorer
        xmlDoc = CreateMSXMLDocumentObject ();
        if (rootName != "") {
            var rootNode = xmlDoc.createElement (rootName);
            xmlDoc.appendChild (rootNode);
        }
    }
    return xmlDoc;
}

function CreateXMLDocumentObjectFromString(xmlString) {
    if (rootName == null)
        rootName = "";
    var xmlDoc = null;
    //Firefox, Opera, Safari and Google Chrome
    if (document.implementation.createDocument) {
        xmlDoc = (new DOMParser).parseFromString(xmlString, 'text/xml');
    }
    else {
        // Internet Explorer
        xmlDoc = CreateMSXMLDocumentObject ();
        xmlDoc.loadXML(xmlString);
    }
    return xmlDoc;

}

var Queue = function () {
    this.members = [];
};
Queue.prototype = {
    add: function (f, params, context) {
        if (f instanceof Function) {
            this.members.push([f, params, context]);
        }
    },
    autoIterate: function () {
        while(this.members.length > 0) {
            this.stepIterate();
        }
    },
    stepIterate: function() {
        var triplet = this.members.shift();
        var func = triplet[0];
        var context = triplet[2];
        var params = triplet[1];
        func.apply(context ? context : this, params ? params : []);
    },

    clear: function () {
        this.members = [];
    }
};

var ScriptLoader = function (modules) {
    this.modules = modules.slice();
    this.queue = new Queue();
    this._init();
};

ScriptLoader.prototype = {
    run: function () {
        // test for header ready
        var head = document.getElementsByTagName("head");
        if (head.length > 0) {
            this.queue.autoIterate();
        }else {
            setTimeout(arguments.callee, 500);
        }
    },

    _init: function () {
        var i, me = this;
        for (i = 0; i < me.modules.length; i++) {
            (function (name, useEval, context) {
                me.queue.add(function () {
                    if(useEval)
                    {
                        if(context)
                        {
                            (function(){
                                eval(name);
                            }).apply(context, []);
                        }
                        else
                        {
                            eval(name);
                        }
                    }
                    else
                    {
                        var head, script;
                        head = document.getElementsByTagName("head");
                        if (head.length > 0) {
                            head = head[0];
                            script = document.createElement("script");
                            script.src = name;
                            script.type = "text/javascript";
                            script.onload = script.onreadystatechange = function () {
                                if ((!this.readyState || this.readyState == "loaded" || this.readyState == "complete") ) {
                                    script.onload = script.onreadystatechange = null;
                                    head.removeChild(script);
                                }
                            };
                            head.appendChild(script);
                        }
                    }
                }, null, context);
            })(me.modules[i].name, me.modules[i].useeval, me.modules[i].context);
        }
    }
};

function PresenceMaintainer(url, presence_key, timeout) {
    this.xurl = Base64.decode(url);
    this.timer = null;
    this.XHR = getRequestObject;
    this.key = Base64.decode(presence_key);
    this.timeout = timeout>0 ? timeout : 60000;
}

PresenceMaintainer.prototype.request = function(){
    var xreq = this.XHR();
    var request = '<r><c n="prsnMntnr" k="' + this.key + '" /></r>';
    xreq.owner = this;
    xreq.open("POST", this.xurl, true);
    xreq.onreadystatechange = this.parseResponse;
    xreq.setRequestHeader("Content-type", "text/xml");
    xreq.send(request);
};

PresenceMaintainer.prototype.parseResponse = function(){
    if(this.readyState!=4) return;
    if(this.status!=200) return;
    var xDoc = this.responseXML;
    var cList = xDoc.getElementsByTagName('c');
    for(var ci=0; ci<cList.length; ci++)
    {
        if(cList[ci].getAttribute('n')=='prsnMntnr' && cList[ci].getAttribute('st')==1)
        {
            this.owner.launch();
            return;
        }
    }
    this.timer = null;
};

PresenceMaintainer.prototype.launch = function(){
    var pmr = this;
    this.timer = window.setTimeout(function(){
        pmr.request();
    }, this.timeout);
};

function loadFilterTimeTable(page, type, archvd)
{
    $.scrollTo($('#ttLessons').parent(), 400);
    while(document.getElementById('ttLessons').childNodes.length>0)
    {
        document.getElementById('ttLessons').removeChild(document.getElementById('ttLessons').firstChild);
    }
    var df = new DialogForm(xrUrl, notifier);
    df.GetForm('ttFlt', {
        t: type,
        arch: (archvd == true ? "1" : "0"),
        p: page
    });
    $('#paginator').hide();
    $('#paginator_pages').hide();
    $('#ttLessons').addClass('loading');

}

function fillTimeTable(listXML)
{
    $('#paginator').show();
    $('#paginator_pages').show();
    $('#ttLessons').removeClass('loading');
    var lessons = listXML.getElementsByTagName('lsn');
    $('.ttfltblock td').removeClass('curr');
    $('.ttfltblock td.'+listXML.getAttribute('t')).addClass('curr');
    if(listXML.getAttribute('tp')>1)
    {
        document.getElementById('paginator').style.display='';
        while(document.getElementById('paginator').firstChild) document.getElementById('paginator').removeChild(document.getElementById('paginator').firstChild);
        document.getElementById('paginator_pages').style.display='';
        document.getElementById('ttTotalPages').innerHTML = listXML.getAttribute('tp');
        var arch = listXML.getAttribute('a')==1 ? true : false;
        var pgn = new Paginator('paginator', listXML.getAttribute('tp'), 10, listXML.getAttribute('p'), ttrUrl+'timetable.php?'+(listXML.getAttribute('a')==1?'arch=1&':'')+'p=', true);
        pgn.pageOnclick = function()
        {
            loadFilterTimeTable(arguments[0], listXML.getAttribute('t'), arch, ttrUrl + 'xreq.php');
            return false;
        }
        pgn.Launch();
    }
    else
    {
        document.getElementById('paginator').style.display='none';
        document.getElementById('paginator_pages').style.display='none';

    }
    if(lessons.length>0)
    {
        for(var i=0; i<lessons.length; i++)
        {
            AddMeetingToList(lessons[i], document.getElementById('ttLessons'), listXML.getAttribute('a')==1);
        }
    }
    else if(listXML.getAttribute('a')==1)
    {
        document.getElementById('ttLessons').innerHTML=document.ttrLang.Text('you_have_no_history_meetings');
    }
    else if(listXML.getAttribute('a')==0)
    {
        document.getElementById('ttLessons').innerHTML=document.ttrLang.Text('you_have_no_planned_meetings');
    }
}

function AddMeetingToList(lsnXML, listElement, arch)
{
    var wrp = document.createElement('div');
    var uN = lsnXML.getElementsByTagName('u')[0];
    wrp.id = 'ttmtg'+lsnXML.getAttribute('id');
    $(wrp).addClass('ttmtg');
    if(lsnXML.getAttribute('mrkd')==1) $(wrp).addClass('mrklsn');
    var infpart = document.createElement('div');
    var datepart = document.createElement('div');
    var auxpart = document.createElement('div');
    var dsprt = document.createElement('div');
    $(dsprt).addClass('clear');
    $(infpart).addClass('inf');
    $(datepart).addClass('date');
    $(auxpart).addClass('menu');
    wrp.appendChild(infpart);
    wrp.appendChild(datepart);
    wrp.appendChild(auxpart);
    wrp.appendChild(dsprt);
    var mtglink = document.createElement('a');
        var ava = document.createElement('a');
        $(ava).addClass('ava');
        $(ava).addClass('tooltip');
        var avaimg = document.createElement('img');
        var avaNode = (lsnXML.getElementsByTagName('opp').length>0 ? lsnXML.getElementsByTagName('opp')[0] : uN);
        avaimg.src=avaNode.getAttribute('ava');
        ava.href=ttrUrl+'users/'+avaNode.getAttribute('n');
        ava.appendChild(avaimg);
        var avatooltip = document.createElement('span');
        var avatooltipsmall = document.createElement('small');
        avatooltip.innerHTML = Base64.decode(avaNode.firstChild.nodeValue);
        avatooltip.appendChild(avatooltipsmall);
        ava.appendChild(avatooltip);
        infpart.appendChild(ava);

        mtglink.href= ttrUrl+'meetings/'+lsnXML.getAttribute('id');
        mtglink.innerHTML = Base64.decode(lsnXML.getElementsByTagName('n')[0].firstChild.nodeValue);
        mtglink.title=Base64.decode(uN.firstChild.nodeValue) + ': ' + mtglink.innerHTML;
        if(mtglink.innerHTML.length>40)
          mtglink.innerHTML=mtglink.innerHTML.substr(0, 40) + '…';
        $(mtglink).addClass('tooltip');
        // var mtgtooltip = document.createElement('span');
        // var mtgtooltipsmall = document.createElement('small');
        // mtgtooltip.innerHTML = Base64.decode(uN.firstChild.nodeValue);
        // mtgtooltip.appendChild(mtgtooltipsmall);
        // mtglink.appendChild(mtgtooltip);
        infpart.appendChild(mtglink);

        var mhp_lnk = document.createElement('a');
        mhp_lnk.innerHTML = Base64.decode(avaNode.firstChild.nodeValue);
        mhp_lnk.href=ttrUrl+'users/'+avaNode.getAttribute('n');
        $(mhp_lnk).addClass('ulnk');

        infpart.appendChild(mhp_lnk);

    var dday = document.createElement('div');
    var dtime = document.createElement('div');
    $(dday).addClass('day');
    $(dtime).addClass('time');
    dday.innerHTML = lsnXML.getAttribute('dd');
    dtime.innerHTML = lsnXML.getAttribute('dt');
    datepart.appendChild(dday);
    datepart.appendChild(dtime);
    var ittl = document.createElement('span');
    $(ittl).addClass('ittl');
    ittl.innerHTML+=Base64.decode(lsnXML.getElementsByTagName('ititle')[0].firstChild.nodeValue);
    auxpart.appendChild(ittl);
    var mml = document.createElement('p');
    auxpart.appendChild(mml);
    mml.className='item_menu_line';
    if(lsnXML.getAttribute('st')>=0 && !arch)
    {
        if(lsnXML.getAttribute('st')==0)
        {
            if(lsnXML.getAttribute('we')==1)
            {
                var mml_mte = document.createElement('a');
                mml_mte.href=ttrUrl+'timetable_edit.php?t=mtg&id=' + lsnXML.getAttribute('id');
                mml_mte.innerHTML = document.ttrLang.Text('meeting_edit');
                mml.appendChild(mml_mte);
                mml.appendChild(document.createTextNode(' '));
            }
            if(lsnXML.getAttribute('wc')==1)
            {
                var mml_mcf = document.createElement('a');
                mml_mcf.href=ttrUrl+'timetable_edit.php?t=cfm&id='+lsnXML.getAttribute('id');
                mml_mcf.innerHTML=document.ttrLang.Text('meeting_confirm');
                mml.appendChild(mml_mcf);
                mml.appendChild(document.createTextNode(' '));
            }
        }
        else if(lsnXML.getAttribute('st')==1)
        {
            if(lsnXML.getAttribute('up')==1)
            {
                var mml_mbp = document.createElement('a');
                mml_mbp.onclick=(function(mId){return function(){
                    (new DialogForm(xrUrl, notifier)).GetForm('mpayment', {
                        mtg_id: mId,
                        rd:'timetable'
                    });
                    return false;
                };})(lsnXML.getAttribute('id'));

                mml_mbp.href=ttrUrl+'meeting_buy.php?id='+lsnXML.getAttribute('id');
                mml_mbp.innerHTML = document.ttrLang.Text('pay_it_link');
                mml.appendChild(mml_mbp);
                mml.appendChild(document.createTextNode(' '));
            }
            else
            {
                var mml_mrl = document.createElement('a');
                mml_mrl.href=ttrUrl+'meeting.php?wb='+lsnXML.getAttribute('wbn')+'&id='+lsnXML.getAttribute('id');
                mml_mrl.innerHTML = document.ttrLang.Text('goto_platform');
                mml.appendChild(mml_mrl);
                mml.appendChild(document.createTextNode(' '));
            }
        }
        var mml_mcl = document.createElement('a');
        mml_mcl.href = ttrUrl+'meeting_cancel.php?id=' + lsnXML.getAttribute('id');
        mml_mcl.onclick = (function (mId, cId) {return function(){
            (new DialogForm(xrUrl, notifier)).GetForm('m_cancel', {
                mtg: mId,
                mtgCntrId: cId,
                xrq: 'msrv'
            });
            return false;
        };})(lsnXML.getAttribute('id'), 'ttmtg' + lsnXML.getAttribute('id'));

        mml_mcl.innerHTML = document.ttrLang.Text('meeting_cancel');
        mml.appendChild(mml_mcl);
    }
    listElement.appendChild(wrp);
}

function Lng()
{
    this.list = Array();
    this.groups = Array();
}

Lng.prototype.Load = function()
{
    var req = '';
    for(var i=0; i<this.groups.length; i++)
        req += '<p n="lgn" v="' + this.groups[i] + '" />';
    req = '<c n="ttrLng">' + req + '</c>';
    req = '<root>' + req + '</root>';
    var xhr = getRequestObject();
    xhr.open("POST", ttrUrl+"xreq.php", false);
    xhr.setRequestHeader("Content-type", "text/xml");
    xhr.send(req);
    var xdoc = xhr.responseXML;
    if(xdoc)
    {
        var labels = xdoc.getElementsByTagName('lbl');
        for(var ilbl=0; ilbl<labels.length; ilbl++)
        {
            var lblFound = false;
            for(var j=0; j<this.list.length; j++)
            {
                if(this.list[j].name==labels[ilbl].getAttribute('n'))
                {
                    lblFound = true;
                    this.list[j].value = Base64.decode(labels[ilbl].firstChild.nodeValue);
                    break;
                }
            }
            if(!lblFound)
            {
                this.Add(labels[ilbl].getAttribute('n'), Base64.decode(labels[ilbl].firstChild.nodeValue));
            }
        }
    }
}

Lng.prototype.AddGroups = function()
{
    for(var i=0; i<arguments.length; i++)
    {
        this.groups.push(arguments[i]);
    }
}

Lng.prototype.RemoveGroups = function()
{
    for(var i=0; i<arguments.length; i++)
        for(var j=0; j<this.groups.length; j++)
            if(this.groups[j]==arguments[i]){
                this.groups.pop(this.groups[j]);
                break;
            }
}



Lng.prototype.Text = function(lbl)
{
    var found = lbl;
    for(var i=0; i<this.list.length; i++)
    {
        if(this.list[i].name==lbl)
        {
            found = this.list[i].value;
            break;
        }
    }
    return found;
}

Lng.prototype.Add = function(n, v)
{
    if(this.Text(n)==n && n!=v)
    {
        this.list.push({
            name: n,
            value: v
        });
    }
}

Lng.prototype.Add64 = function(n64, v64)
{
    this.Add(Base64.decode(n64), Base64.decode(v64));
}

function InitLng(id)
{
    document.ttrLang = new Lng(id);
}

function showServices(host, url)
{
    this.host = host;
    if(!url) url = '';
    this.reqUrl = this.host + url;
}

showServices.prototype.User = function (nick, id)
{
    var container = $('#'+id)[0];
    if(!container.listLoaded)
    {
        $(container).hide();
        $(container).addClass('loading');
        $(container).slideDown('fast');
        (new DialogForm(this.reqUrl, notifier)).GetForm('usrSrvList', {
            usr: nick,
            usbid : id
        });
    }
    else
    {
        var clrLnk = $(container).parent().children('.bstats:first').children('.srvlstbtn:first').children('a:first');
        clrLnk[0].innerHTML=document.ttrLang.Text('close_userservices_list');
        clrLnk[0].href="javascript:void(0);";
        clrLnk[0].onclick = (function(container, nick){
            return function(){
                $(container).slideUp('slow');
                this.innerHTML = document.ttrLang.Text('load_user_services');
                this.onclick = (function(unick){
                    return function(){
                        UServLoader.User(unick, container.id);
                        return false;
                    };
                })(nick);
            };
        })(container, nick);
    }
    $('#'+id).slideDown('slow');
}

showServices.prototype.Show = function (srvList, nodeId)
{
    var container = $('#'+nodeId)[0];
    container.listLoaded = true;
    $(container).hide();
    $(container).removeClass('loading');
    with(container) while(childNodes.length>0) removeChild(firstChild);
    if(!$(container).hasClass('usr_short_srvlist')) $(container).addClass('usr_short_srvlist');
    with(srvList.getElementsByTagName('webinars')[0])
    {
        var wbns = getElementsByTagName('itm');
        var wbnCount = getAttribute('count');
        }
    with(srvList.getElementsByTagName('lessons')[0])
    {
        var lsns = getElementsByTagName('itm');
        var lsnCount = getAttribute('count');
        }
    if(lsnCount>0)
    {
        var lsnCntr = document.createElement('div');
        var lsnHdr = document.createElement('h3');
        lsnHdr.innerHTML = document.ttrLang.Text('user_services_lessons_header') + ' (' + lsnCount + ')';
        lsnCntr.appendChild(lsnHdr);
        for(var i=0; i<lsns.length; i++)
        {
            var wcntr = document.createElement('div');
            $(wcntr).addClass('lsn');
            $(wcntr).addClass('item');
            var pname = document.createElement('p');
            var pprice = document.createElement('p');
            var pbtmLine = document.createElement('div');
            pbtmLine.className = 'btmLine';
            pprice.className='price';
            pprice.innerHTML = document.ttrLang.Text('service_price') + ': ' + lsns[i].getAttribute('price') + ' ' + lsns[i].getAttribute('curr');
            $(pname).addClass('sname');
            var srvLnk = document.createElement('a');
            srvLnk.href=this.host+'services/'+lsns[i].getAttribute('id')+'_'+lsns[i].getAttribute('tsname');
            srvLnk.innerHTML = Base64.decode(lsns[i].getElementsByTagName('subj')[0].firstChild.nodeValue) + ': ' + Base64.decode(lsns[i].getElementsByTagName('name')[0].firstChild.nodeValue);
            pname.appendChild(srvLnk);
            var pdesc = document.createElement('div');
            pdesc.innerHTML = Base64.decode(lsns[i].getElementsByTagName('dsc')[0].firstChild.nodeValue);
            var aord = document.createElement('a');
            aord.href=this.host+ 'users/' + srvList.getAttribute('usr') + '/request/service/'+lsns[i].getAttribute('id');
            aord.className='srv_ord_lnk';
            aord.onclick = (function(srv_id){
                return function(){
                    debugger;
                    (new DialogForm(xrUrl, notifier)).GetForm('sauth', {
                        srv_id: srv_id,
                        ssi: 1,
                        wrfr: 0
                    });
                    return false;
                };

            })(lsns[i].getAttribute('id'));
            aord.innerHTML=document.ttrLang.Text('service_signin');
            wcntr.appendChild(pname);
            wcntr.appendChild(pdesc);
            pbtmLine.appendChild(pprice);
            pbtmLine.appendChild(aord);
            wcntr.appendChild(pbtmLine);
            lsnCntr.appendChild(wcntr);
        }
    }
    if(wbnCount>0)
    {
        var wbnCntr = document.createElement('div');
        var wbnHdr = document.createElement('h3');
        wbnHdr.innerHTML = document.ttrLang.Text('user_services_webinars_header') + ' (' + wbnCount + ')';
        wbnCntr.appendChild(wbnHdr);
        for(var i=0; i<wbns.length; i++)
        {
            var wcntr = document.createElement('div');
            $(wcntr).addClass('wbn');
            $(wcntr).addClass('item');
            var pname = document.createElement('p');
            $(pname).addClass('sname');
            var pprice = document.createElement('p');
            var pbtmLine = document.createElement('div');
            pbtmLine.className = 'btmLine';
            pprice.className='price';
            pprice.innerHTML = document.ttrLang.Text('service_price') + ': ' + (wbns[i].getAttribute('price') + ' ' + wbns[i].getAttribute('curr'));
            var srvLnk = document.createElement('a');
            srvLnk.href=this.host+'services/'+wbns[i].getAttribute('id')+'_'+wbns[i].getAttribute('tsname');
            srvLnk.innerHTML = Base64.decode(wbns[i].getElementsByTagName('subj')[0].firstChild.nodeValue) + ': ' + Base64.decode(wbns[i].getElementsByTagName('name')[0].firstChild.nodeValue);
            pname.appendChild(srvLnk);
            var pdesc = document.createElement('div');
            pdesc.innerHTML = Base64.decode(wbns[i].getElementsByTagName('dsc')[0].firstChild.nodeValue);
            if(wbns[i].getAttribute('inst')>0 && 0) // #664  ссылка "Принять участие"
            {
                var aord = document.createElement('a');
                aord.className='srv_ord_lnk';
                aord.href=this.host+'services/'+wbns[i].getAttribute('id')+'_'+wbns[i].getAttribute('tsname');
                aord.onclick = (function(wbn_id, srv_id){
                    return function(){
                        debugger;
                        (new DialogForm(xrUrl, notifier)).GetForm('sauth', {
                            srv_id: srv_id,
                            wbn_id: wbn_id,
                            ssi: 1,
                            wrfr: 0
                        });
                        return false;
                    };

                })(wbns[i].getAttribute('inst'), wbns[i].getAttribute('id'));
                aord.innerHTML=document.ttrLang.Text('webinar_signin');
                pbtmLine.appendChild(aord);
            }
            wcntr.appendChild(pname);
            wcntr.appendChild(pdesc);
            pbtmLine.appendChild(pprice);
            wcntr.appendChild(pbtmLine);
            wbnCntr.appendChild(wcntr);
        }
    }
    if(!wbnCount>0 && ! lsnCount>0)
    {
        container.innerHTML+=document.ttrLang.Text('user_has_no_services_yet');
    }
    else
    {
        if(lsnCount>0)
        {
            container.appendChild(lsnCntr);
        }
        if(wbnCount>0)
        {
            container.appendChild(wbnCntr);
        }
        $(container).slideDown('slow');

        var clrLnk = $(container).parent().children('.bstats:first').children('.srvlstbtn:first').children('a:first');
        clrLnk[0].innerHTML=document.ttrLang.Text('close_userservices_list');
        clrLnk[0].href="javascript:void(0);";
        clrLnk[0].onclick = (function(container, nick){
            return function(){
                $(container).slideUp('slow');
                this.innerHTML = document.ttrLang.Text('load_user_services');
                this.onclick = (function(unick){
                    return function(){
                        UServLoader.User(unick, container.id);
                        return false;
                    };
                })(nick);
            };
        })(container, srvList.getAttribute('usr'));
    }
    $(container).slideDown('slow');
}

function langListStatus(status)
{
    if(status)
    {
        $('#lngchs')[0].isOpened = true;
        if($('#lngchs')[0].timerHide)
        {
            clearTimeout($('#lngchs')[0].timerHide);
            $('#lngchs')[0].timerHide=null;
        }
        $('#lngchs').first().addClass('brdr');
    }
    else
    {
        $('#lngchs')[0].isOpened = false;
        $('#lngchs')[0].timerHide = setTimeout(function(){
            if($('#lngchs')[0].isOpened == false){
                $('#lngchs')[0].timerHide = null;
                $('#lngchs').first().removeClass('brdr');
            }
        }, 1000);
    }
}

function initAuthForm(loginPhrase, passwordPhrase)
{
    $('#usrLogin:first').val(loginPhrase).addClass('dflt').bind({
        focus : function(){
            if(this.value==loginPhrase) this.value='';
            if($(this).hasClass('dflt')) $(this).removeClass('dflt');
        },
        blur : function(){
            if(this.value=='')
            {
                $(this).addClass('dflt');
                this.value=loginPhrase;
            }
            else if(this.value==loginPhrase)
            {
                $(this).addClass('dflt');
            }
        }
    });
    $('#usrPassword:first').val(passwordPhrase);
    $('#usrPassword:first').addClass('dflt');
    $('#usrPassword:first').bind({
        focus : function(){
            if(this.value==passwordPhrase) this.value='';
            if($(this).hasClass('dflt')) $(this).removeClass('dflt');
        },
        blur : function(){
            if(this.value=='')
            {
                $(this).addClass('dflt');
                this.value=passwordPhrase;
            }
            else if(this.value==passwordPhrase)
            {
                $(this).addClass('dflt');
            }
        }
    });
    $("#userUnauthd:first .login:first").bind({
        click: function(){
            if($(this).hasClass('tabbed'))
            {
                $(this).removeClass('tabbed');
                $('#authForm:first').hide();
            }
            else
            {
                $(this).addClass('tabbed');
                $('#authForm:first').show();
            }
            return false;
        }
    });

}

function getMPWebinars(type)
{
    $('#mpwbnlst .item').remove();
    $('#mpwbnlst').addClass('loading');
    (new DialogForm(xrUrl, notifier)).GetForm('mpwblst', {
        t: type
    });
}
function fillMPWebinars(xml)
{
    var container = $('#mpwbnlst')[0];
    $('#mpwbnlst').removeClass('loading');
    var list = xml.getElementsByTagName('srv');
    if(xml.getAttribute('t')=='n')
    {
        $('#advmainpage #mpwbls').removeClass('selected');
        $('#advmainpage #mpwbln').addClass('selected');
    }
    else if(xml.getAttribute('t')=='s')
    {
        $('#advmainpage #mpwbln').removeClass('selected');
        $('#advmainpage #mpwbls').addClass('selected');
    }
    for(var i=0; i<list.length; i++)
    {
        var srv = list[i];
        var icntr = document.createElement('div');
        icntr.className='item';
        var srva = document.createElement('a');
        var srvspan = document.createElement('span');
        var srvb = document.createElement('b');
        srva.innerHTML= Base64.decode(srv.firstChild.nodeValue);
        srva.href = ttrUrl+'services/'+srv.getAttribute('id')+'_'+srv.getAttribute('tsname');
        srvspan.innerHTML = srv.getAttribute('date');
        srvb.innerHTML = srv.getAttribute('time');
        icntr.appendChild(srva);
        icntr.appendChild(srvspan);
        icntr.appendChild(srvb);
        container.appendChild(icntr);
    }
}

function fav(itm, type, status, bid)
{
    (new DialogForm(xrUrl, notifier)).GetForm('fav', {
        i: itm,
        t: type,
        st: status,
        bid: bid
    });
    return false;
}

function wauth(id, wr)
{
    wr = wr || true;
    (new DialogForm(xrUrl, notifier)).GetForm('wauth', {
        wbn_id: id,
        wrfr : wr
    });
    return false;
}

function setPrvMsgDirection(type)
{
    (new DialogForm(xrUrl, notifier)).GetForm('pmsDir', {
        srt: type
    });
    return false;
}

function Notices(container_id)
{
    this.container = $('#'+container_id);
    this.container.owner = this;
    this.Notices = new Array();
}

Notices.prototype.init = function()
{
    (new DialogForm(xrUrl, notifier)).GetForm('chNtc', {});
}

Notices.prototype.parse = function(xml)
{
    var ntcList = xml.getElementsByTagName('ntc');
    for(var nti=0; nti<ntcList.length; nti++)
    {
        this.append(ntcList[nti].getAttribute('id'), Base64.decode(ntcList[nti].firstChild.nodeValue), ntcList[nti].getAttribute('ahide')==1);
    }
}

Notices.prototype.noticeItem = function(id, HTML, autohide)
{
    return {
        ID: id,
        html: HTML,
        autohide: autohide
    };
}

Notices.prototype.append = function(id, messageHTML,autohide)
{
    this.Notices.push(this.noticeItem(id, messageHTML, autohide));
    this.redraw([id]);
};

Notices.prototype.redraw = function(slidelist)
{
    while(this.container[0].firstChild) this.container[0].removeChild(this.container[0].firstChild);
    var itm = null;
    var withSlide = false;
    var slditr = null;
    for(var ni=0; ni<this.Notices.length; ni++)
    {
        withSlide = false;
        for(slditr=0; slditr<slidelist.length; slditr++)
        {
            if(slidelist[slditr]==this.Notices[ni].ID) {
                withSlide=true;
                break
            }
        }
        itm = this.NoticeElement(this.Notices[ni]);
        this.container[0].appendChild(itm);
        if(withSlide)
        {
            $(itm).slideDown();
        }
        else
        {
            $(itm).show();
        }
        if(this.Notices[ni].autohide)
        {
            itm.timer = setTimeout((function(id){
                return function(){
                    notifier.remove(id);
                };

            })(this.Notices[ni].ID), 10000);
        }
    }
};

Notices.prototype.NoticeElement = function (notice)
{
    var elem = document.createElement('div');
    var elemO = $(elem);
    elemO.addClass('notice');
    elem.id = 'ntc'+notice.ID;
    var closeButton = document.createElement('div');
    var msgSpan = document.createElement('span');
    $(closeButton).addClass('xbutt');
    closeButton.onclick = (function(id){
        return function(){
            notifier.remove(id);
            return false;
        };

    })(notice.ID);
    elem.appendChild(closeButton);
    elemO.hide();
    msgSpan.innerHTML = notice.html;
    elem.appendChild(msgSpan);
    return elem;
}

Notices.prototype.checkNotice = function(id)
{
    var ret = false;
    for(var ni=0; ni<this.Notices.length; ni++)
    {
        if(this.Notices[ni].ID==id)
        {
            ret = true;
            break;
        }
    }
    return ret;
}

Notices.prototype.remove = function(id)
{
    try {
        $('#ntc'+id).addClass('dsbl');
        $('#ntc'+id+' .xbutt').hide();
        if($('#ntc'+id)[0].timer) {
            clearTimeout($('#ntc'+id)[0].timer);
            $('#ntc'+id)[0].timer=null;
        }
        if(parseInt(id)==id) {
            (new DialogForm(xrUrl, notifier)).GetForm('ntcOff', {
                n: id
            });
        } else {
            this.hideLine(id);
        }
    } catch (exception) { 
    
    }
};

Notices.prototype.hideLine = function(id) {
    $('#ntc' + id).slideUp('slow', function() {$('#ntc' + id).remove();});
    for(var i=0; i<this.Notices.length; i++) {
        if(this.Notices[i].ID==id) {
            this.Notices.remove(i, i+1);
            break;
        }
    }
}

function manSrvSList(containerID, type) {
    this.containerID = containerID;
    this.type = type;
    $('#' + this.containerID)[0].managerObj = this;
}

manSrvSList.prototype.getServices = function(offset)
{
    $('#'+this.containerID).addClass('loading');
    (new DialogForm(xrUrl, notifier)).GetForm('mngsrvlist', {
        ofst: offset,
        cntrID: this.containerID,
        t: this.type
        });
};

manSrvSList.prototype.getWebinars = function(service_id, offset, wbn_wmtg)
{
    if(!wbn_wmtg>0) wbn_wmtg=0;
    (new DialogForm(xrUrl, notifier)).GetForm('mngsrvwlist', {
        ofst: offset,
        sId: service_id,
        cntrID: this.containerID,
        wwmtg: wbn_wmtg
        });
};

manSrvSList.prototype.getMeetings = function(webinar_id, offset)
{
    (new DialogForm(xrUrl, notifier)).GetForm('mngsrvmlist', {
        wId: webinar_id,
        ofst: offset,
        cntrID: this.containerID
        });
};

manSrvSList.prototype.parseServices = function(xmlData)
{
    $('#'+this.containerID+':first').removeClass('loading');
    var offset = xmlData.getAttribute('ofst');
    if(offset==0) $('#'+this.containerID+':first').children().remove();
    var items = xmlData.getElementsByTagName('srv');
    if($('#'+this.containerID+':first .counterLine').length>0) $('#'+this.containerID+':first .counterLine').remove();
    if(xmlData.getAttribute('ttl')>0) {
        for(var ictr=0; ictr<items.length; ictr++)
        {
            var srv = items[ictr];
            var srvContainer = document.createElement('div');
            $(srvContainer).addClass('srv').hide();
            var srvDescrip = document.createElement('div');
            $(srvDescrip).addClass('description');
            var serviceLink = document.createElement('a');
            serviceLink.innerHTML = Base64.decode(srv.getElementsByTagName('n')[0].firstChild.nodeValue);
            serviceLink.href = ttrUrl + 'services/' + srv.getAttribute('id') + '_' + srv.getAttribute('tsname');
            var subjSpan = document.createElement('b');
            subjSpan.innerHTML = Base64.decode(srv.getElementsByTagName('sbj')[0].firstChild.nodeValue) + ': ';
            srvDescrip.appendChild(subjSpan);
            srvDescrip.appendChild(serviceLink);
            srvContainer.appendChild(srvDescrip);
            var mnglinks = document.createElement('div');
            $(mnglinks).addClass('mnglinks');
            srvContainer.appendChild(mnglinks);
            var edLink = document.createElement('a');
            var wlstLink = document.createElement('a');
            edLink.innerHTML = document.ttrLang.Text('service_edit');
            edLink.href = ttrUrl + 'service_edit.php?id=' + srv.getAttribute('id') + '&act=edit';
            wlstLink.innerHTML = document.ttrLang.Text( srv.getAttribute('t')=='w' ? 'show_webinars_list_wbn' : 'show_webinars_list_ind' );
            wlstLink.id = 'srvtgll' + srv.getAttribute('id');
            wlstLink.ttrSrvType = srv.getAttribute('t');
            wlstLink.href="javascript:void(0);";
            srvContainer.id = 'srv' + srv.getAttribute('id');
            wlstLink.onclick = (function(manager, s_id) {
                return function(){
                    manager.getWebinars(s_id, 0);
                };

            })(this, srv.getAttribute('id'));
            mnglinks.appendChild(edLink);
            mnglinks.appendChild(wlstLink);
            if(srv.getAttribute('size')>1)
            {
                var ptcpLimitLine = document.createElement('p');
                var ptcpLimitAmount = document.createElement('b');
                ptcpLimitAmount.innerHTML = srv.getAttribute('size');
                ptcpLimitLine.appendChild(document.createTextNode(document.ttrLang.Text('service_participant_limit') + ': '));
                ptcpLimitLine.appendChild(ptcpLimitAmount);
                srvContainer.appendChild(ptcpLimitLine);
            }
            var priceLine = document.createElement('p');
            var priceValue = document.createElement('b');
            $(priceValue).addClass('red');
            priceValue.innerHTML = Base64.decode(srv.getElementsByTagName('prc')[0].firstChild.nodeValue);
            priceLine.appendChild(document.createTextNode(document.ttrLang.Text('service_price') + ': '));
            priceLine.appendChild(priceValue);
            srvContainer.appendChild(priceLine);
            $('#' + this.containerID)[0].appendChild(srvContainer);
            $(srvContainer).slideDown();
        }
        var shownAmount = $('#'+this.containerID+':first .srv').length;
        if(shownAmount<xmlData.getAttribute('ttl'))
        {
            var counterLine;
            if(!$('#'+this.containerID+':first .counterLine').length>0)
            {
                counterLine = document.createElement('div');
                $(counterLine).addClass('counterLine');
                $('#' + this.containerID)[0].appendChild(counterLine);
            }
            else
            {
                counterLine = $('#'+this.containerID+':first .counterLine')[0];
            }
            $(counterLine).children().remove();
            var shownValueLine = document.createElement('p');
            var shownValueAmount = document.createElement('b');
            var shownTotalAmount = document.createElement('b');
            shownTotalAmount.innerHTML = xmlData.getAttribute('ttl');
            shownValueAmount.innerHTML = '1 - ' + shownAmount;
            shownValueLine.appendChild(document.createTextNode(document.ttrLang.Text('service_shown_amount') + ': '));
            shownValueLine.appendChild(shownValueAmount);
            shownValueLine.appendChild(document.createTextNode(' ' + document.ttrLang.Text('service_shown_amount_of') + ' '));
            shownValueLine.appendChild(shownTotalAmount);
            counterLine.appendChild(shownValueLine);
            var showMoreLine = document.createElement('p');
            var showMoreLink = document.createElement('a');
            showMoreLink.href='javascript:void(0);';
            showMoreLink.innerHTML = document.ttrLang.Text('myservices_show_more');
            showMoreLine.appendChild(showMoreLink);
            showMoreLink.onclick = (function(offset, cId, type){
                return function(){
                    (new DialogForm(xrUrl, notifier)).GetForm('mngsrvlist', {
                        ofst: offset,
                        cntrID: cId,
                        t: type
                    });
                };

            })(shownAmount, this.containerID, this.type);
            counterLine.appendChild(showMoreLine);
        }
        else
        {
            $('#'+this.containerID+':first .counterLine').remove();
        }
    } else {
        $('#'+this.containerID+':first')[0].appendChild(document.createTextNode(document.ttrLang.Text('no_such_services')));
    }
};

manSrvSList.prototype.parseWebinars = function(xmlData)
{
    var service_id = xmlData.getAttribute('sId');
    var list = xmlData.getElementsByTagName('wbn');
    var serviceContainer = $('#srv'+service_id+':first')[0];
    var offset = xmlData.getAttribute('ofst');
    var wbnsContainer;
    if(!$(serviceContainer).children('.wbnlist').length>0)
    {
        wbnsContainer = document.createElement('div');
        wbnsContainer.id='wlst' + service_id;
        $(wbnsContainer).addClass('wbnlist');
        serviceContainer.appendChild(wbnsContainer);
    } else {
        wbnsContainer = $(serviceContainer).children('.wbnlist')[0];
    }
    if(offset==0)
    {
        $(wbnsContainer).children().remove();
        if(!$(serviceContainer).children('.snifc').length>0 && xmlData.getAttribute('t')=='w')
        {
            var newInstForm = document.createElement('div');
            $(newInstForm).addClass('snifc').addClass('wbn');
            newInstForm.id = 'nifc';
            $(newInstForm).hide();
            wbnsContainer.appendChild(newInstForm);
            newInstForm.appendChild(document.createTextNode(document.ttrLang.Text('myservices_new_instance_from')));
            var nifInp = document.createElement('input');
            var nifLink = document.createElement('a');
            nifLink.href='javascript:void(0);';
            nifLink.innerHTML = document.ttrLang.Text('myservices_new_instance_add');
            nifInp.type='text';
            var curDate = new Date();
            nifInp.value = curDate.getFullYear() + '-' + (curDate.getMonth() < 9 ? '0' : '') + (curDate.getMonth()+1) + '-' + (curDate.getDate() < 10 ? '0' : '') + curDate.getDate() + ' ' + (curDate.getHours() < 10 ? '0' : '') + curDate.getHours() + ':' + (curDate.getMinutes() < 10 ? '0' : '') + curDate.getMinutes();
            nifInp.id='srvni' + service_id;
            $(nifInp).datetime({
                userLang : ttrLangCode,
                yearRange: (new Date()).getFullYear() + ':' + ((new Date()).getFullYear()+3),
                americanMode: false});
            nifLink.onclick = (function(sId, cId) {
                return function(){
                    (new DialogForm(xrUrl, notifier)).GetForm('nins', {sId: sId, cntrID: cId, dt: $('#srvni'+sId).val()});
                    return false;
                };
            })(service_id, this.containerID);
            newInstForm.appendChild(nifInp);
            newInstForm.appendChild(nifLink);
            $(newInstForm).slideDown();
        }
    }
    $(wbnsContainer).show();
    $('#srvtgll'+service_id)[0].onclick=(function(s_id, wbnlContainer, mngr){
        return function(){
            $('#srvtgll'+s_id)[0].innerHTML = document.ttrLang.Text($('#srvtgll'+s_id)[0].ttrSrvType=='w' ? 'show_webinars_list_wbn' : 'show_webinars_list_ind');
            $('#srvtgll'+s_id)[0].onclick = (function(manager, srv_id) {
                return function(){
                    manager.getWebinars(srv_id, 0);
                };

            })(mngr, s_id);
            $(wbnlContainer).slideUp();
        };
    })(service_id, wbnsContainer, this);
    $('#srvtgll'+service_id)[0].innerHTML = document.ttrLang.Text($('#srvtgll'+service_id)[0].ttrSrvType=='w' ? 'hide_webinars_list_wbn' : 'hide_webinars_list_ind');
    for(var ictr=0; ictr<list.length; ictr++) {
        var wbn = list[ictr];
        var webinar_id = wbn.getAttribute('id');
        var wContainer = document.createElement('div');
        wContainer.id = 'wbn' + webinar_id;
        $(wContainer).addClass('wbn').hide();
        var wprice = document.createElement('div');
        $(wprice).addClass('price');
        var wpriceValue = document.createElement('b');
        $(wpriceValue).addClass('red');
        wpriceValue.innerHTML = Base64.decode(wbn.getElementsByTagName('prc')[0].firstChild.nodeValue);
        wprice.appendChild(document.createTextNode(document.ttrLang.Text(wbn.getAttribute('t')=='w' ? 'myservices_curwbn_price' : 'myservices_curind_price') + ': '));
        wprice.appendChild(wpriceValue);
        wContainer.appendChild(wprice);
        var wMngLinks = document.createElement('div');
        $(wMngLinks).addClass('wmngl');
        var wedLink = document.createElement('a');
        wedLink.innerHTML = document.ttrLang.Text('myservices_webinar_edit');
        wedLink.href = 'javascript:void(0);';
        wedLink.onclick = (function(wId){
            return function(){
                (new DialogForm(xrUrl, notifier)).GetForm('wedit', {wbn_id: wId, act: 'edit'});
            };

        })(webinar_id);
        wMngLinks.appendChild(wedLink);

        var wrmLink = document.createElement('a');
        wrmLink.innerHTML = document.ttrLang.Text('myservices_webinar_remove');
        wrmLink.href = 'javascript:void(0);';
        wrmLink.onclick = (function(wId){
            return function(){
                (new DialogForm(xrUrl, notifier)).GetForm('wedit', {wbn_id: wId, act: 'rmv'});
            };

        })(webinar_id);
        wMngLinks.appendChild(wrmLink);

        wContainer.appendChild(wMngLinks);
        var wsContainer;
        if(wbn.getAttribute('t')=='i') {
            $(wContainer).addClass('ind');
            var ava = document.createElement('img');
            var avaLink = document.createElement('a');
            var wbndesc = document.createElement('div');
            var wdsprt = document.createElement('div');
            $(wdsprt).addClass('clear');
            $(wbndesc).addClass('wbndesc');
            $(avaLink).addClass('ava');
            wContainer.appendChild(avaLink);
            avaLink.appendChild(ava);
            wContainer.appendChild(wbndesc);
            wContainer.appendChild(wdsprt);
            var opLink = document.createElement('a');
            $(opLink).addClass('oppLink');
            ava.src=wbn.getElementsByTagName('op')[0].getAttribute('ava');
            avaLink.href=ttrUrl + 'users/' + wbn.getElementsByTagName('op')[0].getAttribute('id');
            opLink.href=ttrUrl + 'users/' + wbn.getElementsByTagName('op')[0].getAttribute('id');
            opLink.innerHTML = Base64.decode(wbn.getElementsByTagName('op')[0].firstChild.nodeValue);
            wbndesc.appendChild(opLink);
            wsContainer = wbndesc;
        } else {
            var wTitle = document.createElement('b');
            wTitle.innerHTML = wbn.getAttribute('dStart') + (wbn.getAttribute('dFin') ? ' - ' + wbn.getAttribute('dFin') : '');
            wContainer.appendChild(wTitle);
            wsContainer = wContainer;
        }
        var mtgListTitle = document.createElement('a');
        var mtgListTtlContainer = document.createElement('p');
        mtgListTtlContainer.appendChild(mtgListTitle);
        mtgListTitle.innerHTML = document.ttrLang.Text('myservices_curwebinar_meetingslist_title') + ':';
        mtgListTitle.href="javascript:void(0);";
        mtgListTitle.id="wmtgsttl" + webinar_id;
        mtgListTitle.onclick = (function (o, w_id){return function(){o.getMeetings(w_id, 0);return false;};})(this, webinar_id);
        wsContainer.appendChild(mtgListTtlContainer);
        var mtgListContainer = document.createElement('div');
        $(mtgListContainer).addClass('mtglist').hide()[0].id = 'mtgl' + webinar_id;
        wsContainer.appendChild(mtgListContainer);
        wbnsContainer.appendChild(wContainer);
        $(wContainer).slideDown();
    }
    var shownAmount = $(wbnsContainer).children('.wbn').length - (xmlData.getAttribute('t')=='w' ? 1 : 0);
    var totalAmount = xmlData.getAttribute('ttl');
    if(list.length==0 && offset==0 && xmlData.getAttribute('t')=='i')
    {
        var nowbnsLabel = document.createElement('div');
        $(nowbnsLabel).addClass('nowbnsLbl').addClass('wbn');
        nowbnsLabel.innerHTML = document.ttrLang.Text(xmlData.getAttribute('t')=='w' ? 'myservices_no_webinars_in_service' : 'myservices_no_individs_in_service');
        wbnsContainer.appendChild(nowbnsLabel);
    }
    if(totalAmount>0 && shownAmount<totalAmount) {
        var shownextwbnLinkcntr;
        var shownextwbnLink;
        var shownValueLine;
        if($(wbnsContainer).children('.wbnshownext').length==0) {
            shownextwbnLinkcntr = document.createElement('div');
            shownextwbnLink = document.createElement('a');
            shownextwbnLink.href='javascript:void(0);';
            $(shownextwbnLinkcntr).addClass('wbnshownext');
            shownValueLine = document.createElement('p');
            shownextwbnLinkcntr.appendChild(shownValueLine);
            shownextwbnLinkcntr.appendChild(shownextwbnLink);
            wbnsContainer.appendChild(shownextwbnLinkcntr);
            shownextwbnLink.innerHTML = document.ttrLang.Text('myservices_show_next_webinars');
        } else {
            shownextwbnLinkcntr = $(wbnsContainer).children('.wbnshownext:first')[0];
            shownextwbnLink = $(shownextwbnLinkcntr).children('a')[0];
            shownValueLine = $(shownextwbnLinkcntr).children('p')[0];
            while(shownValueLine.childNodes.length>0) shownValueLine.removeChild(shownValueLine.firstChild);
            wbnsContainer.appendChild(shownextwbnLinkcntr);
        }
        var shownValueAmount = document.createElement('b');
        var shownTotalAmount = document.createElement('b');
        shownTotalAmount.innerHTML = totalAmount;
        shownValueAmount.innerHTML = '1 - ' + shownAmount;
        shownValueLine.appendChild(document.createTextNode(document.ttrLang.Text('myservices_webinars_shown_amount') + ': '));
        shownValueLine.appendChild(shownValueAmount);
        shownValueLine.appendChild(document.createTextNode(' ' + document.ttrLang.Text('myservices_webinars_shown_amount_of') + ' '));
        shownValueLine.appendChild(shownTotalAmount);
        shownextwbnLink.onclick = (function(ob, s_id, ofst){
            return function(){
                ob.getWebinars(s_id, ofst)
                return false;
            };

        })(this, service_id, shownAmount);
    } else if(totalAmount>0 && shownAmount==totalAmount) {
        $(wbnsContainer).children('.wbnshownext:first').slideUp('normal', function() {$(wbnsContainer).children('.wbnshownext:first').remove();});
    }
};

manSrvSList.prototype.parseMeetings = function(xmlData)
{
    var webinar_id = xmlData.getAttribute('wId');
    var mlContainer = $('#mtgl' + webinar_id + ':first')[0];
    $(mlContainer).show();
    var items = xmlData.getElementsByTagName('mtg');
    var offset = xmlData.getAttribute('ofst');
    var totalAmount = xmlData.getAttribute('ttl');
    if(offset==0) 
    {
        var mtglttl = $('#wmtgsttl'+webinar_id)[0];
        mtglttl.onclick = (function(o, w_id) {
            return function(){
                $('#mtgl' + w_id + ':first').slideUp();
                this.onclick = (function(ob, wbn_id){return function(){ob.getMeetings(wbn_id, 0);return false;};})(o, w_id);
                return false;
            };
        }
        )(this, webinar_id);
        $(mlContainer).children().remove();
        var mtgForm = document.createElement('div');
        $(mtgForm).addClass('mtgform').hide();
        mlContainer.appendChild(mtgForm);
        var mtgfInp = document.createElement('input');
        var mtgfLink = document.createElement('a');
        mtgfInp.type = 'text';
        var curDate = new Date();
        mtgfInp.value = curDate.getFullYear() + '-' + (curDate.getMonth() < 9 ? '0' : '') + (curDate.getMonth()+1) + '-' + (curDate.getDate() < 10 ? '0' : '') + curDate.getDate() + ' ' + (curDate.getHours() < 10 ? '0' : '') + curDate.getHours() + ':' + (curDate.getMinutes() < 10 ? '0' : '') + curDate.getMinutes();
        mtgfInp.id = 'mtgfd' + webinar_id;
        $(mtgfInp).datetime({
            userLang : ttrLangCode,
            yearRange: (new Date()).getFullYear() + ':' + ((new Date()).getFullYear()+3),
            americanMode: false});
        mtgfLink.innerHTML = document.ttrLang.Text('myservices_add_meeting');
        mtgfLink.onclick = (function(wId, cntId){
            return function(){
                var date = $('#mtgfd'+wId).val();
                (new DialogForm(xrUrl, notifier)).GetForm('pnwm', {cntrID: cntId, wbn: wId, dt: date})
            };
        })(webinar_id, this.containerID);
        mtgfLink.href='javascript:void(0);';
        mtgForm.appendChild(document.createTextNode(document.ttrLang.Text('myservices_new_meeting')));
        mtgForm.appendChild(mtgfInp);
        mtgForm.appendChild(mtgfLink);
        $(mtgForm).slideDown();
    }
    for(var ictr=0; ictr<items.length; ictr++)
    {
        var mtg = items[ictr];
        var mContainer = document.createElement('div');
        var mtgCancelLink = document.createElement('a');
        mtgCancelLink.innerHTML = document.ttrLang.Text('myservices_cancel_meeting');
        mtgCancelLink.href = 'javascript:void(0);';
        mtgCancelLink.onclick = (function(mId, cId){
            return function(){
                (new DialogForm(xrUrl, notifier)).GetForm('m_cancel', {mtg: mId, xrq: 'msrv', cntrID: cId});
                return false;
            };

        })(mtg.getAttribute('id'), this.containerID);
        $(mContainer).addClass('mtg').hide();
        mContainer.appendChild(document.createTextNode(mtg.getAttribute('date')));
        if(mtg.getAttribute('old') != 1) mContainer.appendChild(mtgCancelLink);
        mlContainer.appendChild(mContainer);
        $(mContainer).slideDown();
    }
    var shownAmount = $(mlContainer).children('.mtg').length;
    if(shownAmount<totalAmount) {
        var shownextmtgLinkcntr;
        var shownextmtgLink;
        if($(mlContainer).children('.mtgshownext').length==0) {
            shownextmtgLinkcntr = document.createElement('div');
            shownextmtgLink = document.createElement('a');
            $(shownextmtgLinkcntr).addClass('mtgshownext');
            shownextmtgLinkcntr.appendChild(shownextmtgLink);
            mlContainer.appendChild(shownextmtgLinkcntr);
            shownextmtgLink.innerHTML = document.ttrLang.Text('myservices_show_next_meetings');
        } else {
            shownextmtgLinkcntr = $(mlContainer).children('.mtgshownext:first')[0];
            shownextmtgLink = $(shownextmtgLinkcntr).children('a')[0];
            mlContainer.appendChild(shownextmtgLinkcntr);
        }
        shownextmtgLink.href='javascript:void(0);';
        shownextmtgLink.onclick = (function(o, w_id, offst){
            return function(){
                o.getMeetings(w_id, offst);
                return false;
            };

        })(this, webinar_id, shownAmount);
    } else {
        $(mlContainer).children('.mtgshownext').slideUp('normal', function(){$(mlContainer).children('.mtgshownext').remove();});
    }
};

function SubmitXHRForm(form, cmd) {
    var formParams = $(form).serializeArray();
    var params = {};
    var i;
    for(i=0; i<formParams.length; i++) {
        params[formParams[i].name] = formParams[i].value;
    }
    (new DialogForm(xrUrl, notifier)).GetForm(cmd, params);
    return false;
}

function fhCheckScroll() {
    $('.famousheads #carousel:first')[0].disableScrolling = false;
    if($('.famousheads #carousel:first').scrollLeft()==0) {
        $('.famousheads #fhlarr:first span').addClass('d');
    } else {
        $('.famousheads #fhlarr:first span').removeClass('d');
    }
    if($('.famousheads #carousel:first').attr('scrollWidth')-961<=$('.famousheads #carousel:first').scrollLeft()) {
        $('.famousheads #fhrarr:first span').addClass('d');
    } else {
        $('.famousheads #fhrarr:first span').removeClass('d');
    }
}

function facebook(link, text) {
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(link)+'&t='+encodeURIComponent(text),'sharer','toolbar=0,status=0,width=626,height=436');
    return false;
}

function vkontakte(link, text, lan) {
    if(!lan) lan = 'ru';
    window.open('http://vkontakte.ru/share.php?url='+encodeURIComponent(link)+'&title='+encodeURIComponent(text)+'&image=http://tutorion.ru/images/logo_' + lan + '.png','sharer','toolbar=0,status=0,width=626,height=436');
    return false;
}

