var dy = {
    cuctl: {},
    body: {

        helper: 0,
        click: function () {
            if (dy.body.helper == 0) {
                all('.items', function (at) { if (!def(at.classList)) return; at.classList.add('hdn'); at.classList.remove('f'); });
            }

            dy.body.helper = 0;
        },
        keyUp: function (event) {

            if (event.keyCode == 27) {
                if (dy.body.helper == 0) {
                    all('.items', function (at) { if (!def(at.classList)) return; at.classList.add('hdn'); at.classList.remove('f'); });
                }

                dy.body.helper = 0;
            }

            var f = document.activeElement;
            var typ = f.getAttribute('typeof');
            if (!def(typ)) {
                var p = par(f, 0, 3, 'block');
                typ = p.getAttribute('typeof')
            }

            switch (typ) {
                case 'checkbox': break;
                case 'textbox': dy.textbox.change(f); break;
                case 'button': break;
                case 'select': break;
                case 'item': case 'load': break;
            }

            if (event.keyCode == 13) {


                switch (typ) {
                    case 'checkbox': dy.checkBox.enter(f); break;
                    case 'textbox': dy.textbox.enter(f); break;
                    case 'button': dy.button.enter(f); break;
                    case 'select': dy.select.enter(f); break;
                    case 'item': case 'load': dy.item.enter(f); break;
                }
            }

            if (event.keyCode == 32) { // space

                switch (typ) {
                    case 'checkbox': break;
                    case 'textbox': break;
                    case 'button': break;
                    case 'select': dy.select.enter(f); break;
                    case 'item': case 'load': dy.item.enter(f); break;
                }
            }

            if (event.keyCode == 38) { // up

                switch (typ) {
                    case 'checkbox': break;
                    case 'textbox': break;
                    case 'button': break;
                    case 'select': dy.select.up(f); break;
                    case 'item': case 'load': break;
                }
            }

            if (event.keyCode == 40) { // down

                switch (typ) {
                    case 'checkbox': break;
                    case 'textbox': break;
                    case 'button': break;
                    case 'select': dy.select.enter(f); break;
                    case 'item': case 'load': break;
                }
            }
        },

        ihelper: 0,
        iclick: function (ev, th, fun, p) {
            if (dy.body.ihelper == 0) {
                if (def(fun)) {
                    dy.body.ihelper = 1;
                    setTimeout(function () { dy.body.ihelper = 0; }, 500);
                    fun(ev, th, p);
                }
            }
        }

    },
    textbox: {
        initValue: function (ctl) {
            var change = js(ctl.getAttribute('fn'));
            if (def(change)) return change(first('input[type=text]', null, ctl), { value: false });

            if (def(change)) change(ctl, { value: false });

            return false;
        },

        change: function (ctl) {

            var change = js(first('input[type=text]', null, par(ctl, 0, 5, 'block')).getAttribute('fn'));
            if (def(change)) return change(first('input[type=text]', null, par(ctl, 0, 5, 'block')), { type: 'keyup' });

            return false;
        },
        value: function (ctl) {
            return first('input[type=text]', null, ctl).value;
        },
        enter: function (block) {
            first('input[type=text]', null, block).focus();
        }
    },
    button: {
        initValue: function (ctl) {
            var change = js(ctl.getAttribute('fn'));
            if (def(change)) return change(first('input[type=button]', null, ctl), { value: false });

            return true;
        },
        submit: function (ctl) {
            var change = js(ctl.getAttribute('fn'));
            if (def(change)) return change(first('input[type=submit]', null, ctl), { value: false });

            return true;
        },
        valid: function (ctl) {
            var change = js(ctl.getAttribute('fn'));
            if (def(change)) return change(first('input[type=submit]', null, ctl), { type: 'valid' });

            return true;
        },
        enter: function (block) {
            dy.button.initValue(block);
        }
    },
    checkBox: {
        initValue: function (ctl) {
            var change = js(ctl.getAttribute('fn'));
            first('.dy-on', function (at) {

                if (at.attributes['class'].value.indexOf('op0') != -1) {
                    first('input[type=hidden]', function (at) { at.value = 'True'; }, ctl);
                    first('.dy-off', function (at) { at.classList._add('op0'); }, ctl);
                    first('.dy-on', function (at) { at.classList.remove('op0'); }, ctl);
                    get(ctl).classList._add('cnavy');
                    get(ctl).classList._add('c-hnavy');
                    get(ctl).classList.remove('csmoke');
                    get(ctl).classList.remove('c-hgray');
                    if (def(change)) change(first('input[type=hidden]', null, ctl), { value: true });
                }
                else {
                    first('input[type=hidden]', function (at) { at.value = 'False'; }, ctl);
                    first('.dy-off', function (at) { at.classList.remove('op0'); }, ctl);
                    first('.dy-on', function (at) { at.classList._add('op0'); }, ctl);
                    get(ctl).classList._add('csmoke');
                    get(ctl).classList._add('c-hgray');
                    get(ctl).classList.remove('cnavy');
                    get(ctl).classList.remove('c-hnavy');
                    if (def(change)) change(first('input[type=hidden]', null, ctl), { value: false });
                }

            }, ctl);



            return false;
        },
        value: function (ctl) {
            return first('input[type=hidden]', null, ctl).value;
        },
        enter: function (block) {
            dy.checkBox.initValue(first('.im', null, block));
        }
    },
    select: {
        click: function (ctl, load) {

            dy.body.helper = 1;
            all('.items', function (iat) {

                if (!def(iat.classList)) return;
                iat.classList.add('hdn'); iat.classList.remove('f');

            }, function () {
                first('.items', null, ctl).classList.toggle('hdn');
                first('.items', null, ctl).classList.toggle('f');

                if (load && first('.items div', null, ctl) == null) {
                    var sel = first('.selected', null, ctl);

                    var loadFn = js(sel.getAttribute("live"));
                    if (def(loadFn)) {

                        first('.waitico', null, ctl).classList.add('hdn');
                        first('.wait', null, ctl).classList.remove('hdn');

                        loadFn(sel, 0);
                    }
                }

                try { first('div[typeof=item]', null, ctl).focus(); } catch (e) { }

            });

        },
        show: function (sel) {
            sel.classList.remove('hdn'); sel.classList.add('f');
        },
        enter: function (block) {
            dy.select.click(block);
        },
        up: function (ctl) {
            first('.items', null, ctl).classList.add('hdn'); first('.items', null, ctl).classList.remove('f');
        },
        setItem: function (bl, text, value) {
            var sel = first('.selected', null, bl);
            var el = document.createElement("div");
            var el2 = document.createElement("div");
            var empty = first('.it', null, bl);
            //el.innerHTML = (((empty != null && sel.getAttribute("multi") == "true") || sel.getAttribute("multi") != "true") ? (item.classList.contains('gnarrow') ? "<img src='/images/shapes/gnarrow.svg' class='w-01 h-01' />" : "")
            //    + (item.classList.contains('gparrow') ? "<img src='/images/shapes/gparrow.svg' class='w-01 h-01' />" : "")
            //    + (item.classList.contains('gsep') ? "<img src='/images/shapes/gsep.svg' class='w-01 h-01' />" : "")
            //    + (item.classList.contains('gcomma') ? "<img src='/images/shapes/gcomma.svg' class='w-01 h-01' />" : "") : "");

            el2.innerHTML =
                text;

            if (sel.getAttribute("rico") != "true")
                el2.innerHTML += "<img src='/images/shapes/gclose.svg' class=' op1 op-h5 w-01 h-01 rad-50 c-hred' onclick=' dy.select.removeItem(this.parentNode);' />";


            el.setAttribute("val", value);
            el.setAttribute("class", 'it f-center fl f-r m-0005 ');
            el2.setAttribute("class", 'p-00125   f-center fl f-r mr-0005');
            // el.setAttribute("ondblclick", "  dy.select.removeItem(this);");
            el.appendChild(el2);
            if (first('div[val="' + value + '"]', null, bl) == null) {
                if (sel.getAttribute("edit") == "true") {
                    first('input[type=text]', null, sel).value = el.innerText;
                    setTimeout(function () { first('.items', null, sel.parentNode).classList.add('hdn'); first('.items', null, sel.parentNode).classList.remove('f'); }, 50);
                }
                else {
                    if (sel.getAttribute("multi") != "true") {

                        var el1 = first('.it', null, sel);
                        if (def(el1)) sel.removeChild(el1);

                        dy.select.clear(sel);

                        setTimeout(function () { first('.items', null, sel.parentNode).classList.add('hdn'); first('.items', null, sel.parentNode).classList.remove('f'); }, 50);
                    }
                    sel.appendChild(el);
                    bl.focus();
                }
            }

            dy.select.getValue(bl);

        },
        addItem: function (sel, item, nav, lnav) {

            var el = document.createElement("div");
            var el2 = document.createElement("div");
            var empty = first('.it', null, sel);
            //el.innerHTML = (((empty != null && sel.getAttribute("multi") == "true") || sel.getAttribute("multi") != "true") ? (item.classList.contains('gnarrow') ? "<img src='/images/shapes/gnarrow.svg' class='w-01 h-01' />" : "")
            //    + (item.classList.contains('gparrow') ? "<img src='/images/shapes/gparrow.svg' class='w-01 h-01' />" : "")
            //    + (item.classList.contains('gsep') ? "<img src='/images/shapes/gsep.svg' class='w-01 h-01' />" : "")
            //    + (item.classList.contains('gcomma') ? "<img src='/images/shapes/gcomma.svg' class='w-01 h-01' />" : "") : "");

            el2.innerHTML =
                item.innerHTML;

            if (sel.getAttribute("rico") != "true")
                el2.innerHTML += (((nav == null && sel.getAttribute("multi") != "true") || sel.getAttribute("multi") == "true") ? "<img src='/images/shapes/gclose.svg' class=' op1 op-h5 w-01 h-01 rad-50 c-hred' onclick=' dy.select.removeItem(this.parentNode);' />" : "");

            el.setAttribute("val", item.getAttribute("val"));
            el.setAttribute("class", 'it f-center fl f-r m-0005 ');
            el2.setAttribute("class", 'p-00125   f-center fl f-r mr-0005');
            // el.setAttribute("ondblclick", "  dy.select.removeItem(this);");
            el.appendChild(el2);

            var at = par(sel, 0, 3, 'block');
            if (at != null) {
                if (first('div[val="' + item.getAttribute("val") + '"]', null, sel) == null) {
                    if (sel.getAttribute("edit") == "true") {
                        first('input[type=text]', null, sel).value = el.innerText;

                        setTimeout(function () { first('.items', null, sel.parentNode).classList.add('hdn'); first('.items', null, sel.parentNode).classList.remove('f'); }, 50);
                    }
                    else {
                        if (sel.getAttribute("multi") != "true" && !nav) {

                            var el1 = first('.it', null, sel);
                            if (def(el1) && !def(lnav)) sel.removeChild(el1);

                            dy.select.clear(sel);

                            setTimeout(function () { first('.items', null, sel.parentNode).classList.add('hdn'); first('.items', null, sel.parentNode).classList.remove('f'); }, 50);
                        }
                        sel.appendChild(el);
                        at.focus();
                    }
                }

                dy.select.getValue(at);


                var change = js(at.getAttribute('fn'));
                if (def(change)) { change(sel, { type: 'addItem', value: first('input[type=hidden]', null, at).value }); }


            }

            var change = js(sel.getAttribute('fn'));
            if (def(change)) { change(sel, { type: 'addItem' }); }

        },
        removeItem: function (item) {
            item.setAttribute("val", "");
            var bl = par(item, 0, 3, 'block');
            dy.select.getValue(bl, function () {
                item.parentNode.removeChild(item);
                first('.items', null, bl).classList.add('hdn'); first('.items', null, bl).classList.remove('f');

                var change = js(bl.getAttribute('fn'));
                if (def(change)) { change(bl, { type: 'removeItem' }); }

            });

            var change = js((first('.selected', null, bl)).getAttribute('fn'));
            if (def(change)) { change(first('.selected', null, bl), { type: 'removeItem' }); }

        },

        clear: function (th) {
            var bl = par(th, 0, 4, 'block');
            if (!def(bl)) return;
            all('.selected .it', function (at) {
                at.parentNode.removeChild(at);

            }, function () {
                dy.select.getValue(bl);


                var change = js(bl.getAttribute('fn'));
                if (def(change)) { change(bl, { type: 'clear' }); }

            }, null, bl);


        },
        bind: function (block, data) {
            first('.items', null, block).innerHTML = data;
            first('.waitico', null, block).classList.remove('hdn');
            first('.wait', null, block).classList.add('hdn');
            //first('.items', null, block).setAttribute("disabled", "");
            //first('.items', null, block).removeAttribute("disabled");
            //first('.items', null, block).classList.remove("op3");

            dy.select.show(first('.items', null, block));
        },
        getValue: function (block, end) {
            var isMulti = first('.selected', null, block).getAttribute("multi") == "true";
            var s = "";
            if (isMulti) s = "[";
            all('.selected > .it', function (at) {
                if (isMulti)
                    s += at.getAttribute("val") + ",";
                else
                    s = at.getAttribute("val");

            }, function () {

                var lbl = first('.lbl', null, block);
                if (def(lbl)) {
                    if (isMulti) {
                        s = (s.replaceAll(",,", ",") + ",").replace(",,", "") + "]";

                        if (s == "[]" || s == "[,]")
                            lbl.classList.remove('hdn');
                        else

                            lbl.classList.add('hdn');
                    }
                    else {
                        if (s == "")
                            lbl.classList.remove('hdn');
                        else
                            lbl.classList.add('hdn');

                        first('input[type=hidden]', null, block).value = s;
                    }
                }

                if (def(end)) end();
            }, null, block);

        }
    },
    item: {
        click: function (ctl) {
            //load if is have sub Items
            if (ctl.getAttribute("typeof") == "load") {
                dy.item.load(ctl);

            }
            else
                dy.item.select(ctl);
        },
        select: function (item) {
            var at = par(item, 0, 3, 'items');
            if (at != null) {
                dy.select.addItem(first('.selected', null, at.parentNode), item, null, item.classList.contains('nav'));
            }
        },
        load: function (item) {
            var at = par(item, 0, 3, 'items');



            var sel = first('.selected', null, at.parentNode);
            if (at != null) {
                if (item.classList.contains('nav')) {
                    // dy.select.addItem(sel, item, true);
                }
                var loadFn = js(sel.getAttribute("live"));

                if (def(loadFn)) loadFn(sel, item.getAttribute("val"));

                first('.waitico', null, at.parentNode).classList.add('hdn');
                first('.wait', null, at.parentNode).classList.remove('hdn');

                first('.items', null, at.parentNode).innerHTML += '<div class="ab t-00 l-00 r-00 b-00 ctrblack z10">&nbsp;</div>';

            }
        },
        enter: function (item) {
            dy.item.click(item);
        }
    },
    upload: {
        embeds: [],
        state: 'ready',
        change: function (evt, th, ftp, key, size, ext) {
            ctl = evt.currentTarget;
            var change = js(ctl.getAttribute('fn'));
            var service = ctl.getAttribute('srv');
            dy.cuctl = ctl;
            change = def(change, function (a, b) { });

            if (service == "") { dy.upload.state = 'ready'; change(ctl, { data: evt }); return; }
            if (dy.upload.state != 'ready') {
                if (confirm('another upload in progress .please wait and cancel this confirm to finish and try again. or you can cancel ?')) {
                    dy.upload.state = 'ready';
                };
            }
            else {
                dy.upload.state = 'start';
                try {
                    if (def(ftp) && ftp) {
                        dy.upload.ftp(evt, change, key, size);
                    }
                    else
                        dy.upload.xhr(evt, change);
                }
                catch (e) {
                    alert(e.message);
                    dy.upload.state = 'ready';
                }
            }
        },
        xhr: function (evt, change) {
            ctl = evt.currentTarget;
            var rd = new FileReader();
            _tid = 0;
            embeds = [];

            var files = evt.currentTarget.files;
            dy.upload.state = 'reading';
            new th_for(files,
                function (tid, it) {
                    _tid = tid;
                    var imageType = /image.*/;
                    var musicType = "audio/mp3";

                    if (it.item.type.match(imageType)) {

                        rd.onload = function (ev) {

                            var im = document.createElement("img");
                            im.src = ev.target.result;
                            im.setAttribute("class", "h-02 p-0025 m-0025  ");
                            dy.upload.embeds.push({ url: ev.target.result, data: null });

                            n_1(dy.upload.embeds).data = it.item;
                            th_e(_tid);

                            change(evt.currentTarget, { type: 'reading', image: im });

                        }
                        rd.readAsDataURL(it.item);
                    }
                    else if (it.item.type == musicType) {

                        rd.onload = function (ev) {

                            var im = document.createElement("audio");
                            im.src = ev.target.result;
                            im.setAttribute("class", "h-02 p-0025 m-0025  ");
                            dy.upload.embeds.push({ url: ev.target.result, data: null });

                            n_1(dy.upload.embeds).data = it.item;
                            th_e(_tid);

                            change(evt.currentTarget, { type: 'reading', image: im });

                        }
                        rd.readAsDataURL(it.item);
                    }
                    else {

                        rd.onload = function (ev) {

                            var im = document.createElement("div");
                            im.innerHTML = kb(ev.target.result.length);
                            im.setAttribute("class", "h-02 w-02 p-0025 m-0025 ");
                            dy.upload.embeds.push({ url: ev.target.result, data: null });

                            n_1(dy.upload.embeds).data = it.item;
                            th_e(_tid);
                            change(evt.currentTarget, { type: 'reading', file: im });

                        }

                        rd.readAsDataURL(it.item);
                    }

                },
                function () {
                    dy.upload.state = 'sending';

                    // xhr req
                    var service = ctl.getAttribute('srv');

                    service = change(ctl, { type: 'url_prepare', data: service });

                    prop.request.postFile(service, function (d) {
                        change(ctl, { type: 'ready', data: d });

                        dy.upload.embeds = new Array();
                        dy.upload.state = 'ready';
                        ctl.title = "100%";
                        first('.progress', null, ctl.parentNode).style.width = "100%";

                        setTimeout(function () {
                            first('.progress', null, ctl.parentNode).style.width = "0%";
                        }, 500);

                    }, { file: dy.upload.embeds, data: {}, progress: function (p) { first('.progress', null, ctl.parentNode).style.width = p + "%"; ctl.title = p + "%"; } });
                }).start();
        },
        ftp: function (evt, change, key, size, ext) {
            ctl = evt.currentTarget;

            var rd = new FileReader();
            _tid = 0;
            embeds = [];

            var files = evt.currentTarget.files;
            dy.upload.state = 'reading';
            new th_for(files,
                function (tid, it) {
                    _tid = tid;

                    rd.onload = function (ev) {

                        var markup, result, n, aByte, byteStr;

                        dy.upload.embeds.push({ url: ev.target.result, data: rd.result });

                        th_e(_tid);
                        change(evt.currentTarget, { type: 'reading' });
                    }

                    rd.readAsBinaryString(it.item);
                },
                function () {
                    dy.upload.state = 'sending';

                    // xhr req
                    var service = ctl.getAttribute('srv');

                    service = change(ctl, { type: 'url_prepare', data: service });
                    var len = dy.upload.embeds[0].data.length;
                    var index = 0;
                    var step = 1;
                    var eof = false;
                    function partUp() {
                        step++;
                        if (eof) return;
                        var ad = "";

                        for (var i = 0; i <= size; i++) {
                            if (i != size && len > index + i) {

                                aByte = dy.upload.embeds[0].data.charCodeAt(index + i);
                                var s = aByte.toString(16);
                                if (s.length == 0) s = "00";
                                else if (s.length == 1) s = "0" + s;
                                if (s.length == 2) ad += s;

                            } else if (i == size) {
                                dy.xhr.upload({
                                    url: '/api/ftp/1', type: 'post',
                                    data: { key: key, Data: ad },
                                    success: function (d) {
                                        first('.progress', null, dy.cuctl.parentNode).style.width = Math.floor(index * 100 / len) + "%"; dy.cuctl.title = Math.floor(index * 100 / len) + "%";
                                        index += d.valueOf() * 1;
                                        if (index < len) {
                                            requestAnimationFrame(partUp);
                                        }
                                        else {
                                            console.log('done.');
                                            dy.xhr.upload({
                                                url: '/api/ftp/1', type: 'post',
                                                data: { key: key, Done: true, Extension: ext },
                                                success: function (d) {

                                                    change(ctl, { type: 'ready', data: d });

                                                    dy.upload.embeds = new Array();
                                                    dy.upload.state = 'ready';
                                                    ctl.title = "100%";
                                                    first('.progress', null, ctl.parentNode).style.width = "100%";

                                                    setTimeout(function () {
                                                        first('.progress', null, ctl.parentNode).style.width = "0%";
                                                    }, 500);

                                                },
                                                error: function () {
                                                    alert('upload is failed . try Again');
                                                    dy.upload.embeds = new Array();
                                                    dy.upload.state = 'ready';
                                                    ctl.title = "100%";
                                                    first('.progress', null, ctl.parentNode).style.width = "100%";

                                                    setTimeout(function () {
                                                        first('.progress', null, ctl.parentNode).style.width = "0%";
                                                    }, 500);
                                                }
                                            });

                                        }
                                    },
                                    error: function () {
                                        alert('try Again');

                                        dy.upload.embeds = new Array();
                                        dy.upload.state = 'ready';
                                        ctl.title = "100%";
                                        first('.progress', null, ctl.parentNode).style.width = "100%";

                                        setTimeout(function () {
                                            first('.progress', null, ctl.parentNode).style.width = "0%";
                                        }, 500);
                                    }
                                });

                            }
                        }
                    }
                    change(ctl, { type: 'url_prepare', data: service });
                    partUp();

                }).start();
        }
    },
    node: {
        click: function (val, root) {
        }
    },
    leaf: {
        click: function (val, root) {
        }
    },
    wait: {
        start: function (ctl, a) {
            switch (a) {
                case 'begin': {
                    first(' .wait', function (at) { at.classList.remove('hdn'); }, ctl)
                    first(' .waitico', function (at) { at.classList._add('hdn'); }, ctl)
                    break;
                }
                case 'end': {
                    first(' .waitico', function (at) { at.classList.remove('hdn'); }, ctl)
                    first(' .wait', function (at) { at.classList._add('hdn'); }, ctl)
                    first(' .wwait', function (at) { at.classList._add('hdn'); }, ctl)
                    first(' .rwait', function (at) { at.classList._add('hdn'); }, ctl)
                    break;
                }

                case 'error': {
                    first(' .rwait', function (at) { at.classList.remove('hdn'); }, ctl)
                    first(' .wait', function (at) { at.classList._add('hdn'); }, ctl)
                    break;
                }
                case 'success': {
                    first(' .wwait', function (at) { at.classList.remove('hdn'); }, ctl)
                    first(' .wait', function (at) { at.classList._add('hdn'); }, ctl)
                    break;
                }
            }
        }

    },
    xhr: {
        download: function (op) {

            op = def(op, {});
            op.type = def(op.type, 'Get');
            op.url = def(op.url, '/');
            op.success = def(op.success, function (data) { alert(data); });
            op.error = def(op.error, function (data) { alert(data.responseText); });
            op.end = def(op.end, function () { });
            op.begin = def(op.begin, function () { });

            function processData(data) {
                op.success(data);
            }

            function handler() {
                op.subProgress = def(op.subProgress, function (p) { });
                op.subProgress(this);
                if (this.readyState == this.DONE) {
                    if (this.status == 200) {
                        // success!
                        processData(this.responseText);
                    }
                    else {
                        op.error(this);
                    }
                    op.end();
                }
            }

            try {
                op.begin();
                var client = new XMLHttpRequest();
                client.onreadystatechange = handler;
                client.open(op.type, op.url);
                client.send();
                client.onprogress = function (pe) {
                    if (pe.lengthComputable) {
                        op.progress = def(op.progress, function (p) { });
                        op.progress(pe.loaded * 100. / pe.total);
                    }
                }
            } catch (e) { op.error(e); op.end(); }

        },
        upload: function (op) {
            op = def(op, {});
            op.type = def(op.type, 'POST');
            op.url = def(op.url, '/');
            op.success = def(op.success, function (data) { alert(data); });
            op.error = def(op.error, function (data) { alert(data.responseText); });
            op.end = def(op.end, function () { });
            op.begin = def(op.begin, function () { });

            function processData(data) {
                op.success(data);
            }

            function handler() {
                if (this.readyState == this.DONE) {
                    if (this.status == 200) {
                        // success!
                        processData(this.responseText);
                    }
                    else {
                        op.error(this);
                    }
                    op.end();
                }
            }

            try {
                op.begin();
                var client = new XMLHttpRequest();
                client.onreadystatechange = handler;
                if ("withCredentials" in client) {
                    client.open(op.type, op.url, true);
                    client.upload.onprogress = function (pe) {
                        if (pe.lengthComputable) {
                            op.progress = def(op.progress, function (p) { });
                            op.progress(pe.loaded * 100. / pe.total);
                        }
                    }

                } else if (typeof XDomainRequest != "undefined") {

                    // Otherwise, check if XDomainRequest.
                    // XDomainRequest only exists in IE, and is IE's way of making CORS requests.
                    client = new XDomainRequest();
                    client.onreadystatechange = handler;

                    client.open(op.type, op.url);
                    client.upload.onprogress = function (pe) {
                        if (pe.lengthComputable) {
                            op.progress = def(op.progress, function (p) { });
                            op.progress(pe.loaded * 100. / pe.total);
                        }
                    }
                }

                if (def(op.file)) {
                    var data = new FormData();
                    _for(op.file, function (at, i) {
                        data.append("file" + i, at.data);

                    }, function () {
                        client.setRequestHeader("content", JSON.stringify(op.data));
                        client.send(data);
                        client.upload.onprogress = function (pe) {
                            if (pe.lengthComputable) {
                                op.progress = def(op.progress, function (p) { });
                                op.progress(pe.loaded * 100. / pe.total);
                            }
                        }
                    });
                }
                else {
                    client.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
                    client.send((def(op.data, false) ? JSON.stringify(op.data) : ''));
                    client.onprogress = function (pe) {
                        if (pe.lengthComputable) {
                            op.progress = def(op.progress, function (p) { });
                            op.progress(pe.loaded * 100. / pe.total);
                        }
                    }
                }
            } catch (e) { op.error(e); op.end(); }
        },
        ftp: function (op) {

        }
    },
    xobj: {
        save: function (op, sel, res) {
            var data = "{";
            var rpl = function (val) {
                return val.replace(/"/, '__dqt__')
                    .replace(/,/g, '__com__')
                    .replace(/;/g, '__sem__')
                    .replace(/'/g, '__qt__')
                    .replace(/{/g, '__aqs__')
                    .replace(/}/g, '__aqe__')
                    .replace(/\//g, '__esl__')
                    .replace(/\\/g, '__bsl__')
                    .replace(/>/g, '__ts__')
                    .replace(/</g, '__te__');
            }
            data = all(sel, function (it) {
                if (it.tagName.toString().toLocaleLowerCase() == 'input') {
                    data += it.id + ":" + rpl(it.value) + ",";
                }
                else if (it.tagName.toString().toLocaleLowerCase() == 'div') {
                    data += it.id + ":" + rpl(it.innerHTML) + ",";
                }
                else if (it.tagName.toString().toLocaleLowerCase() == 'img' && it.attributes['value']) {
                    data += it.parentNode.id.replace('c_', '') + ":" + rpl(it.attributes['value'].value) + ",";
                }
                else if (it.tagName.toString().toLocaleLowerCase() == 'audio' && it.attributes['value']) {
                    data += it.parentNode.id.replace('c_', '') + ":" + rpl(it.attributes['value'].value) + ",";
                }
                else if (it.tagName.toString().toLocaleLowerCase() == 'video' && it.attributes['value']) {
                    data += it.parentNode.id.replace('c_', '') + ":" + rpl(it.attributes['value'].value) + ",";
                }
                else if (it.tagName.toString().toLocaleLowerCase() == 'textarea') {
                    data += it.id + ":" + rpl(it.value) + ",";
                }

            }, function () {
                return data;
            })

            data = all(sel + 's', function (it) {
                if (it.tagName.toString().toLocaleLowerCase() == 'input') {
                    data += it.id + ":list[" + rpl(it.value) + "],";
                }
                else if (it.tagName.toString().toLocaleLowerCase() == 'div') {
                    data += it.id + ":list[" + rpl(it.innerHTML) + "],";
                }
                else if (it.tagName.toString().toLocaleLowerCase() == 'textarea') {
                    data += it.id + ":list[" + rpl(it.value) + "],";
                }

            }, function () {
                return data + "clientDate:" + new Date().getTime() + "}";
            })
            dy.xobj.set({
                data: data,
                Priorities: op.pr,
                Cat: op.cat,
                Custom: op.Custom,
                id: op.id,
                success: function (d) { res(d); },
                error: function (d) { alert('error ' + d); },
                warning: function (d) { }
            });
        },
        set: function (op) {
            // validate
            op = def(op, {});
            op.data = def(op.data, '{clientDate:' + new Date().getTime() + '}');
            op.id = def(op.id, 0);
            op.success = def(op.success, function (d) { });
            op.warning = def(op.warning, function (d) { });
            op.error = def(op.error, function (d) { });

            if (def(op.validate)) {
                var valid = op.validate();
                if (valid) {
                    op.data = valid;
                }
                else return false;
            }
            var cmp = null;
            if (def(op.Custom)) {
                cmp = op.Custom;
                op.Partition = 1000;
            }
            //xhr
            dy.xhr.upload({
                url: '/api/submitad/1',
                type: 'post',
                data: { ObjId: op.id, SecKey: op.SecKey, Cat: op.Cat, Data: op.data, Partition: op.Partition, Priorities: op.Priorities, CustomPartition: cmp },
                success: function (d) {
                    if (d.indexOf("success") != 0) {
                        op.success(d.replace('success', '').replace(/"/g, ''));
                    }
                    else op.warning(d);
                },
                error: function (d) {
                    op.error(d);
                }
            });

        },
        cat: function (name, parent, op) {
            // validate
            op = def(op, {});
            op.data = def(op.data, '{clientDate:' + new Date().getTime() + '}');
            op.id = def(op.id, 0);
            op.success = def(op.success, function (d) { });
            op.warning = def(op.warning, function (d) { });
            op.error = def(op.error, function (d) { });

            if (def(op.validate)) {
                var valid = op.validate();
                if (valid) {
                    op.data = valid;
                }
                else return false;
            }
            var cmp = null;
            if (def(op.Custom)) {
                cmp = op.Custom;
                op.Partition = 1000;
            }
            //xhr
            dy.xhr.upload({
                url: '/api/submitad/1',
                type: 'post',

                data: { ObjId: op.id, cat: name, catParent: parent, Data: op.data, Partition: '7', Priorities: op.Priorities, CustomPartition: cmp },
                success: function (d) {
                    if (d.indexOf("success") != 0) {
                        op.success(d.replace('success', '').replace(/"/g, ''));
                    }
                    else op.warning(d);
                },
                error: function (d) {
                    op.error(d);
                }
            });

        },
        catEdit: function (name, id, op) {
            // validate
            op = def(op, {});
            op.data = def(op.data, '{clientDate:' + new Date().getTime() + '}');
            op.id = def(op.id, 0);
            op.success = def(op.success, function (d) { });
            op.warning = def(op.warning, function (d) { });
            op.error = def(op.error, function (d) { });

            if (def(op.validate)) {
                var valid = op.validate();
                if (valid) {
                    op.data = valid;
                }
                else return false;
            }
            var cmp = null;
            if (def(op.Custom)) {
                cmp = op.Custom;
                op.Partition = 1000;
            }
            //xhr
            dy.xhr.upload({
                url: '/api/submitad/5',
                type: 'post',
                data: { ObjId: 0, catTerm: id, catEdit: name },
                success: function (d) {
                    if (d.indexOf("success") != 0) {
                        op.success(d.replace('success', '').replace(/"/g, ''));
                    }
                    else op.warning(d);
                },
                error: function (d) {
                    op.error(d);
                }
            });

        },
        clr: function (op) {
            // validate
            op = def(op, {});
            op.data = def(op.data, '{}');
            op.id = def(op.id, 0);
            op.success = def(op.success, function (d) { });
            op.warning = def(op.warning, function (d) { });
            op.error = def(op.error, function (d) { });


            dy.xhr.upload({
                url: '/api/submitad/2',
                type: 'post',
                data: { ObjId: op.id, Data: op.data },
                success: function (d) {
                    if (d.indexOf("success") != 0) {
                        op.success(d.replace('success', '').replace(/"/g, ''));
                    }
                    else op.warning(d);
                },
                error: function (d) {
                    op.error(d);
                }
            });

        },
        act: function (op, SecKey) {
            // validate  
            //xhr
            if (document.cookie.indexOf("SCKEUser01") != -1) { // member activity
                dy.xhr.upload({
                    url: '/api/submitad/1',
                    type: 'post',
                    success: function (d) { console.log(d) }, error: function () { },
                    data: { ObjId: -1, SecKey: SecKey, Append: true, Data: '{Key:' + op + '}' }
                });
            }
            else { // client activity

            }
        },
        hideAll: function (prt) {

            dy.xhr.upload({
                url: '/api/submitad/4',
                type: 'post',
                data: { ObjId: 0, Data: '{}', Partition: prt },
                success: function (d) {
                    if (d.indexOf("success") != 0) {
                        op.success(d.replace('success', '').replace(/"/g, ''));
                    }
                    else op.warning(d);
                },
                error: function (d) {
                    op.error(d);
                }
            });
        }
    }
    ,
    editor: {
        open: function (ctl) {
            eval(' function sf(val) {  localStorage.' + ctl.id + "EDT" + ' = val;  }');
            sf(ctl.innerHTML);
            var win = window.open("/Editor.html?" + ctl.id + "EDT", "_blank");
            win.onunload = function () {
                var str = eval(' localStorage.' + ctl.id + "EDT" + ';');

                ctl.innerHTML = str;
            }

        }
    },
    submit: {
        comment: function (form, par, part, fun) {

            var subject = first('input[type="text"]', null, form).value;
            var txt = first('textarea', null, form).value;

            dy.xhr.upload({
                url: '/api/submit/48D7B3E2-A626-4E3F-B545-2104A1357FF3',
                type: 'post',
                data: {
                    Part: part, Parent: par, Data: '{ "Text":"' + txt + '","Subject":"' + subject + '","show":false }'
                },
                success: function (d) {
                    fun(d);
                }
            });

        },
        log: function (form, par, part, fun) {

            var subject = first('input[type="text"]', null, form).value;

            dy.xhr.upload({
                url: '/api/submit/48D7B3E2-A626-4E3F-B545-2104A1357FF3',
                type: 'post',
                data: {
                    Part: part, Parent: par, Data: '{ "Subject":"' + _rpl(window.navigator.appVersion.toString() + ' <hr/> ' + (new Date())) + '", "Text":"' + subject + '","show":true }'
                },
                success: function (d) {
                    fun(d);
                }
            });

        }
    }
}

var _rpl = function (val) {
    if (!val || val.trim() == "") return "";
    return val.replace('"', '').replace(/"/g, '__dqt__')
        .replace(/,/g, '__com__')
        .replace(/\n/g, '__sln__')
        .replace(/\r/g, '__slr__')
        .replace(/\t/g, '__slt__')
        .replace(/;/g, '__sem__')
        .replace(/'/g, '__qt__')
        .replace(/{/g, '__aqs__')
        .replace(/}/g, '__aqe__')
        .replace(/\//g, '__esl__')
        .replace(/\\/g, '__bsl__')
        .replace(/>/g, '__ts__')
        .replace(/</g, '__te__');
}

function initUtilities() {
    return {
        getParent: function (selector, p, level) {
            if (level == null || level == undefined) level = 5;

            if ($(selector, $(p).parent()).length == 0 && level > 0) {
                return GetParent(selector, $(p).parent(), level - 1)
            }

            return $(selector, $(p).parent());
        },
        isDef: function (o) {
            return o != null || o != undefined;
        },
        byId: function (id) {
            return document.getElementById(id);
        },
        getTick: function (d) {
            if (!U.isDef(d)) { d = new Date(); }

            return d.getYear() * 12 * 31 * 24 * 60 * 60 * 1000 + d.getMonth() * 31 * 24 * 60 * 60 * 1000 + d.getDay() * 24 * 60 * 60 * 1000 + d.getHours() * 60 * 60 * 1000 + d.getMinutes() * 60 * 1000 + d.getSeconds() * 1000 + d.getMilliseconds();
        },
        attachFunction: function (oldFun, newFun) {
            var f = oldFun;
            return function (p1, p2, p3, p4, p5, p6, p7, p8, p9, p0) {
                if (U.isDef(f)) {
                    f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p0);
                }
                newFun(p1, p2, p3, p4, p5, p6, p7, p8, p9, p0);
            };
        },
        event: {

            def: function (ctl, live, fun, param) {

                if (live == "mousedown") $(ctl)[0].onmousedown = U.attachFunction($(ctl)[0].onmousedown, fun);
                if (live == "mousemove") $(ctl)[0].onmousemove = U.attachFunction($(ctl)[0].onmousemove, fun);
                if (live == "mouseover") $(ctl)[0].onmouseover = U.attachFunction($(ctl)[0].onmouseover, fun);
                if (live == "dblclick") $(ctl)[0].ondblclick = U.attachFunction($(ctl)[0].ondblclick, fun);
                if (live == "mouseout") $(ctl)[0].onmouseout = U.attachFunction($(ctl)[0].onmouseout, fun);
                if (live == "keypress") $(ctl)[0].onkeypress = U.attachFunction($(ctl)[0].onkeypress, fun);
                if (live == "mouseup") $(ctl)[0].onmouseup = U.attachFunction($(ctl)[0].onmouseup, fun);
                if (live == "keydown") $(ctl)[0].onkeydown = U.attachFunction($(ctl)[0].onkeydown, fun);

                if (live == "scroll") $(ctl)[0].onscroll = U.attachFunction($(ctl)[0].onscroll, fun);
                if (live == "unload") $(ctl)[0].onunload = U.attachFunction($(ctl)[0].onunload, fun);
                if (live == "change") $(ctl)[0].onchange = U.attachFunction($(ctl)[0].onchange, fun);
                if (live == "select") $(ctl)[0].onselect = U.attachFunction($(ctl)[0].onselect, fun);
                if (live == "submit") $(ctl)[0].onsubmit = U.attachFunction($(ctl)[0].onsubmit, fun);
                if (live == "keyup") $(ctl)[0].onkeyup = U.attachFunction($(ctl)[0].onkeyup, fun);
                if (live == "abort") $(ctl)[0].onabort = U.attachFunction($(ctl)[0].onabort, fun);
                if (live == "error") $(ctl)[0].onerror = U.attachFunction($(ctl)[0].onerror, fun);
                if (live == "click") $(ctl)[0].onclick = U.attachFunction($(ctl)[0].onclick, fun);
                if (live == "focus") $(ctl)[0].onfocus = U.attachFunction($(ctl)[0].onfocus, fun);
                if (live == "reset") $(ctl)[0].onreset = U.attachFunction($(ctl)[0].onreset, fun);
                if (live == "blur") $(ctl)[0].onblur = U.attachFunction($(ctl)[0].onblur, fun);
                if (live == "load") $(ctl)[0].onload = U.attachFunction($(ctl)[0].onload, fun);

                if (live == "focusin") $(ctl).focusin(fun);
                if (live == "focusout") $(ctl).focusout(fun);
                if (live == "resize") $(document).on(ctl, 'resize', fun);

                try {
                    if (live == "drop") $(ctl)[0].odrop = U.attachFunction($(ctl)[0].ondrop, fun);
                    if (live == "dragover") $(ctl)[0].ondragover = U.attachFunction($(ctl)[0].ondragover, fun);
                    if (live == "dragstart") $(ctl)[0].ondragstart = U.attachFunction($(ctl)[0].ondragstart, fun);
                    if (live == "dragend") $(ctl)[0].ondragend = U.attachFunction($(ctl)[0].ondragend, fun);


                }
                catch (e) { }


            },
            click: function (ct, fun) { U.event.def(ct, "click", fun); },
            dblclick: function (ct, fun) { U.event.def(ct, "dblclick", fun); },
            mousedown: function (ct, fun) { U.event.def(ct, "mousedown", fun); },
            mousemove: function (ct, fun) { U.event.def(ct, "mousemove", fun); },
            mouseover: function (ct, fun) { U.event.def(ct, "mouseover", fun); },
            mouseout: function (ct, fun) { U.event.def(ct, "mouseout", fun); },
            mouseup: function (ct, fun) { U.event.def(ct, "mouseup", fun); },
            keydown: function (ct, fun) { U.event.def(ct, "keydown", fun); },
            keypress: function (ct, fun) { U.event.def(ct, "keypress", fun); },
            keyup: function (ct, fun) { U.event.def(ct, "keyup", fun); },
            abort: function (ct, fun) { U.event.def(ct, "abort", fun); },
            error: function (ct, fun) { U.event.def(ct, "error", fun); },
            load: function (ct, fun) { U.event.def(ct, "load", fun); },
            resize: function (ct, fun) { U.event.def(ct, "resize", fun); },
            scroll: function (ct, fun) { U.event.def(ct, "scroll", fun); },
            unload: function (ct, fun) { U.event.def(ct, "unload", fun); },
            blur: function (ct, fun) { U.event.def(ct, "blur", fun); },
            change: function (ct, fun) { U.event.def(ct, "change", fun); },
            focus: function (ct, fun) { U.event.def(ct, "focus", fun); },
            reset: function (ct, fun) { U.event.def(ct, "reset", fun); },
            select: function (ct, fun) { U.event.def(ct, "select", fun); },
            submit: function (ct, fun) { U.event.def(ct, "submit", fun); },
            focusin: function (ct, fun) { U.event.def(ct, "focusin", fun); },
            focusout: function (ct, fun) { U.event.def(ct, "focusout", fun); },
            ///
            drop: function (ct, fun) { U.event.def(ct, "drop", fun); },
            dragover: function (ct, fun) { U.event.def(ct, "dragover", fun); },
            dragstart: function (ct, fun) { U.event.def(ct, "dragstart", fun); },
            dragend: function (ct, fun) { U.event.def(ct, "dragend", fun); }

        },
        hover: function (ctl, count, fun, key) {
            var i = 0;
            var ich = 0;
            var c = 0;
            function timeCheck(ct1) {
                c = 0;
                var tkey = (key == undefined || key == null ? 'key1' : key);
                timers.removeKey(tkey);
                timers.set({
                    delay: 10,
                    interval: 1,
                    key: tkey,
                    tick: function (index, action) {
                        c++;

                        if (c >= count && i == 1)
                            fun(ct1);

                        if (c >= count) timers.remove(action);
                    }
                });

                timers.doActionByName(tkey);
            }

            $(ctl).each(function () {

                var ct = $(this.toString())[0];
                U.event.mouseover(ct, function (ev1) {
                    i = 1;

                    timeCheck(ct);
                });
                U.event.mouseout(ct, function (ev1) {
                    if (ich == 0) { i = 0; }
                });

                $('*', ct).each(function () {
                    U.event.mouseover(ct, function (ev1) {
                        ich = 1;
                    });
                    U.event.mouseout(ct, function (ev1) {
                        ich = 0;
                    });
                });
            });

        },
        hout: function (ctl, count, fun, key) {

            var i = 0;
            var ich = 0;
            var c = 0;
            function timeCheck(ct1) {
                c = 0;
                var tkey = (key == undefined || key == null ? 'key2' : key);
                timers.removeKey(tkey);
                timers.set({
                    delay: 10,
                    interval: 1,
                    key: tkey,
                    tick: function (index, action) {
                        c++;
                        // document.title = i + " " + ich + " " + c;
                        if (c >= count && i == 1)
                            fun(ct1);

                        if (c >= count) timers.remove(action);
                    }
                });

                timers.doActionByName(tkey);
            }

            $(ctl).each(function () {
                var ct = $(this.toString())[0];

                U.event.mouseover(ct, function (ev1) {
                    //document.title = i + " " + ich + " " + c;
                    i = 0;
                });
                U.event.mouseout(ct, function (ev1) {
                    // document.title = i + " " + ich + " " + c;
                    i = 1;
                });

                $('*', ct).each(function () {
                    U.event.mouseover(ct, function (ev1) { //document.title = i + " " + ich + " " + c; 
                        ich = 1;
                    });
                    U.event.mouseout(ct, function (ev1) {
                        ich = 0;
                        if (i == 1) {
                            timeCheck(ct);
                        }
                    });
                });
            });
        },
        hout_i: function (ctl, count, fun, key) {

            var i = 0;

            var ich = 0, ihc = 0;
            var c = 0;
            var k = 0;
            function timeChecki(ct1) {
                c = 0;
                var tkey = (key == undefined || key == null ? 'key2' : key);
                timers.removeKey(tkey);
                //document.title = tkey;
                timers.set({
                    delay: 10,
                    interval: 1,
                    key: tkey,
                    tick: function (index, action) {
                        c++;

                        if (c >= count && i == 0)
                            fun(ct1);

                        if (c >= count) timers.remove(action);
                    }
                });

                timers.doActionByName(tkey);
            }

            $(ctl).each(function () {
                var ct = $(this.toString())[0];
                k++;
                U.event.mouseover(ct, function (ev1) {
                    ich++;
                    i = 1;
                    //document.title = i + " " + ich + " " + ihc + " " + k;

                });
                U.event.mouseout(ct, function (ev1) {
                    ihc++;
                    timeChecki(ct);
                    i = 0;
                    //document.title = i + " " + ich + " " + ihc + " " + k;

                });


            });
        },
        deselect: function () {
            try {
                var sel;
                if (document.selection && document.selection.empty) {
                    document.selection.empty();
                } else if (window.getSelection) {
                    sel = window.getSelection();
                    if (sel && sel.removeAllRanges)
                        sel.removeAllRanges();
                }
            } catch (e) { }
        },
        move: function (ctl, d, s, pos, tick, end) {
            try {
                id = 'k' + $(ctl).attr('id');
                var tKey = "M_Y_" + id;

                timers.removeKey(tKey);
                timers.set({
                    delay: 1,
                    interval: 40,
                    key: tKey,
                    tick: function (index, action) {
                        try {
                            var o = pos();
                            var a = Math.round((o - d) / Math.abs(o - d));
                            if (isNaN(a)) a = 1;
                            var n = (o - a * (Math.abs(o - d) / (s + 1)));
                            //  if (isNaN(n) || isNan(d)) timers.remove(action);
                            if (Math.abs(n - d) < 1 || tick(n)) {
                                tick(d);
                                end(d);
                                timers.remove(action);
                            }
                        } catch (e) { }
                    }
                });

                timers.doActionByName(tKey);
            } catch (e) { }
        },
        getCssValue: function (val) {
            return val.replace('px', '').replace('%', '').replace(/ /g, '').valueOf() * 1.0;
        },
        getLastCtlFromSelector: function (selector, ctl) {
            var selector_ctl = null;
            if (selector == null) {
                $(ctl).each(function () { selector_ctl = this; });
            }
            else if (ctl == null || ctl == undefined) {
                $(selector).each(function () { selector_ctl = this; });
            }
            else {
                $(selector, ctl).each(function () { selector_ctl = this; });
            }
            return selector_ctl;
        },
        keepData: function (pid, ctl, value, fun) {
            try {
                if (ctl == null) return;
                if (value != undefined && value == null) value = "";
                if (ctl.id == undefined) {
                    ctl = U.getLastCtlFromSelector('#' + pid, ctl);
                }

                if (value == undefined) {
                    var val_Temp;
                    val_Temp = window.eval('val_Temp = localStorage.OrderTempData_' + pid + '_' + ctl.id + ';');
                    $('#' + pid + ' #' + ctl.id).val(val_Temp);

                    if (fun != null && fun != undefined) {
                        fun(pid, ctl);
                    }
                }
                else
                    window.eval('localStorage.OrderTempData_' + pid + '_' + ctl.id + ' = "' + value + '";');
            }
            catch (e) {
            }
        }


    };
}
var utilities = initUtilities();
var U = utilities;



function initChart() {
    return {
        width: 1000,
        height: 450,
        min: 50,
        css: 'chart',
        list: new Array(),
        generate: function (container) {
            $(container).html("<div id='tabCharts' style='display:inline-block;position:relative;width:" + chart.width + "px;text-align:left;background-color:#fff;' ></div><div id='mainCharts'></div>");
        },
        add: function (key, ms, detail, container, tabContainer) {
            if (ms == undefined || ms == null) {
                // generate Convas
                if ((container == undefined || container == null) && $('#mainCharts').length > 0)
                    container = document.getElementById('mainCharts');
                if (container == undefined || container == null)
                    container = document.body;

                if ((tabContainer == undefined || tabContainer == null) && $('#tabCharts').length > 0)
                    tabContainer = document.getElementById('tabCharts');
                if (tabContainer != undefined && tabContainer != null)
                    $(tabContainer).append("<input type='button' style='border:solid 2px  none;background-color:#fff;color:#000;padding:5px;margin-left:5px;' id='chart_tab_" + key + "' value='" + key + "' onclick=\"$('.chart').hide();$('#tabCharts input').css('border-bottom-color','#fff'); $('#chart_cnt_" + key + "').show();$(this).css('border-bottom-color','#00a2ff');\" />");

                $(container).append('<div class="chart"  id="chart_cnt_' + key + '"  style="display:inline-block;position:relative;width:' + chart.width + ';height:' + chart.height + ';" class="' + chart.css + '"><canvas id="chart_' + key + '" width="' + chart.width + '" height="' + chart.height + '" >This browser or document mode doesn\'t support canvas</canvas></div>');
                $('#chart_tab_' + key).click();
                chart.list[key] = { key: key, values: new Array() };
            }
            else {
                chart.list[key].values[chart.list[key].values.length] = { ms: ms, detail: detail };
            }
        },
        draw: function (key) {
            var pts = new Array();
            $('#chart_' + key).mousemove(function () {

            });
            var step = 0;
            var h = 0;
            var max = 0;
            if (chart.list[key].values != null && chart.list[key].values.length > 0) {
                step = ($('#chart_cnt_' + key).width() - (100)) / (chart.list[key].values.length - 1);
                h = ($('#chart_cnt_' + key).height() - 70);
                max = chart.min * 10000;

                chart.list[key].values.forEach(function (value) {
                    if (max < value.ms)
                        max = value.ms;
                });

                var j = 0;
                var pss = new Array();
                chart.list[key].values.forEach(function (value, index, ar) {
                    var y = h - ((h - 20) * value.ms / max);
                    var x = 50 + j * step;

                    pss[j] = { x: x, y: y }; j++;
                });

                var i = 0;
                pss.forEach(function (value, index, ar) {
                    var lpp = 0.90;
                    var b = i - 1;
                    if (b < 0) { b = 0; lpp = 0; }
                    var a = i + 1;
                    if (a >= pss.length) { a = pss.length - 1; lpp = 0; }

                    pts[i] = Bz.cjRoundedPoint(pss[i].x, pss[i].y, pss[b].x, pss[b].y, pss[a].x, pss[a].y, lpp); i++;

                    if (i > 0) {
                        try {
                            $('#chart_cnt_' + key).append(
                                '<div class="chartDb" style="z-index:10;top:' + (pss[i - 1].y - 22) + 'px;left:' + (pss[i - 1].x + 3) + 'px;">' + chart.list[key].values[index].detail + '</div>'
                            );
                        } catch (e) { }
                    }

                });
            }

            $('#chart_cnt_' + key).append(
                '<div class="chartDb" style="z-index:2; top:' + (chart.height - 33) + 'px;left:' + (40) + 'px;direction:ltr"> key:' + key + ' x : profiler Points  y: time (s.ms)   <span style=\"color:#ddd\">displayed timespan refers to previous action.</span> </div>'
            );

            beziers.set('chart_' + key, pts, null, null, max / 10000);


        }
    };
}
var chart = initChart();

//       Beziers : Bz  ...................................................................................................................

function initBeziers() {
    return {
        array: new Array(),
        cjPoint: function (px, py, alphaLeft, leftWieght, alphaRight, rightWieght) {

            alphaRight = (-alphaRight) * Math.PI / 180.0;
            alphaLeft = (-alphaLeft) * Math.PI / 180.0;

            var cjpt = { pt: { x: px, y: py }, cjRight: { x: px, y: py }, cjLeft: { x: px, y: py } };

            if (rightWieght > 0) {
                cjpt.cjRight.x += Math.round(rightWieght * Math.cos(alphaRight)).toString().replace(".0", "").valueOf() * 1;
                cjpt.cjRight.y += Math.round(rightWieght * Math.sin(alphaRight)).toString().replace(".0", "").valueOf() * 1;

            }
            if (leftWieght > 0) {
                cjpt.cjLeft.x += Math.round(leftWieght * Math.cos(alphaLeft)).toString().replace(".0", "").valueOf() * -1;
                cjpt.cjLeft.y += Math.round(leftWieght * Math.sin(alphaLeft)).toString().replace(".0", "").valueOf() * -1;
            }

            return cjpt;

        },
        cjRoundedPoint: function (px, py, lx, ly, rx, ry, lpp) {

            if (!U.isDef(lpp)) lpp = 1.0;
            var alpha = 0;
            if (rx - lx == 0) alpha = 90;
            else {
                alpha = -1 * Math.atan((ry - ly) / (rx - lx));
                alpha = alpha * 180 / Math.PI;
            }
            var wight = lpp * (Math.sqrt((ry - ly) * (ry - ly) + (rx - lx) * (rx - lx)) / 2.5);
            var lw = Math.sqrt((py - ly) * (py - ly) + (px - lx) * (px - lx));
            var rw = Math.sqrt((ry - py) * (ry - py) + (rx - px) * (rx - px));

            return Bz.cjPoint(px, py, alpha, lw * wight / (lw + rw), alpha, rw * wight / (lw + rw));

        },
        set: function (id, conjunctionPoints, closed, style, min) {

            if (!U.isDef(min)) min = 50;
            min = Math.round(min);

            var canvas = document.getElementById(id);
            if (canvas != null && canvas.getContext) {

                var ctx = canvas.getContext('2d');
                ctx.save();
                ctx.fillStyle = 'rgba(255,255,255,1)';

                ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);

                ctx.beginPath();
                ctx.strokeStyle = 'rgba(100,100,100,0.2)';
                for (var i = 0; i < conjunctionPoints.length; i++) {


                    var sp = conjunctionPoints[i];
                    var ep = conjunctionPoints[i];

                    if (i == 0) {
                        if (closed)
                            sp = conjunctionPoints[conjunctionPoints.length - 1];
                    }
                    else {
                        sp = conjunctionPoints[i - 1];
                        if (closed)
                            sp = conjunctionPoints[i - 1];
                    }
                    ctx.lineWidth = 5;

                    ctx.moveTo(sp.pt.x, sp.pt.y);

                    ctx.bezierCurveTo(sp.cjRight.x, sp.cjRight.y,
                        ep.cjLeft.x, ep.cjLeft.y,
                        ep.pt.x, ep.pt.y);

                    //ctx.stroke();
                    //ctx.beginPath();
                    //ctx.moveTo(ep.cjRight.x, ep.cjRight.y);
                    //ctx.lineTo(ep.cjLeft.x, ep.cjLeft.y);

                }

                ctx.stroke();

                ctx.beginPath();
                ctx.strokeStyle = 'rgba(255,255,255,1)';
                ctx.lineWidth = 3;
                for (var i = 0; i < conjunctionPoints.length; i++) {

                    var sp = conjunctionPoints[i];
                    var ep = conjunctionPoints[i];
                    ctx.stroke();
                    ctx.beginPath();
                    ctx.arc(ep.pt.x, ep.pt.y, 5, 0, 2 * Math.PI, true);
                    ctx.stroke();

                }

                ctx.stroke();


                ctx.beginPath();
                ctx.strokeStyle = 'rgba(0,0,0,0.4)';
                ctx.lineWidth = 3;
                for (var i = 0; i < conjunctionPoints.length; i++) {

                    var sp = conjunctionPoints[i];
                    var ep = conjunctionPoints[i];
                    ctx.stroke();
                    ctx.beginPath();
                    ctx.arc(ep.pt.x, ep.pt.y, 2, 0, 2 * Math.PI, true);
                    ctx.stroke();

                }

                ctx.stroke();

                ctx.beginPath();
                ctx.strokeStyle = 'rgba(0,0,0,1.0)';
                ctx.lineWidth = 1;
                for (var i = 0; i < conjunctionPoints.length; i++) {

                    var sp = conjunctionPoints[i];
                    var ep = conjunctionPoints[i];
                    ctx.stroke();
                    ctx.beginPath();
                    ctx.arc(ep.pt.x, ep.pt.y, 2, 0, 2 * Math.PI, true);
                    ctx.stroke();

                }

                ctx.stroke();


                ctx.beginPath();
                ctx.lineWidth = 1;
                ctx.strokeStyle = 'rgba(120,120,120,0.5)';
                ctx.moveTo(20, 20);
                ctx.lineTo(22, 20);
                ctx.lineTo(20, 15);
                ctx.lineTo(18, 20);
                ctx.lineTo(20, 20);
                ctx.lineTo(20, chart.height - 20);
                ctx.stroke();
                ctx.beginPath();
                ctx.lineWidth = 1;
                ctx.strokeStyle = 'rgba(120,120,120,0.5)';
                ctx.moveTo(10, chart.height - 40);
                ctx.lineTo(chart.width - 20, chart.height - 40);
                ctx.lineTo(chart.width - 20, chart.height - 42);
                ctx.lineTo(chart.width - 15, chart.height - 40);
                ctx.lineTo(chart.width - 20, chart.height - 38);
                ctx.lineTo(chart.width - 20, chart.height - 40);

                ctx.stroke();
                ctx.beginPath();
                ctx.lineWidth = 30;
                ctx.strokeStyle = 'rgba(200,200,200,0.1)';
                ctx.moveTo(35, 20);
                ctx.lineTo(35, chart.height - 20);
                ctx.stroke();
                ctx.beginPath();
                ctx.lineWidth = 30;
                ctx.strokeStyle = 'rgba(200,200,200,0.1)';
                ctx.moveTo(10, chart.height - 55);
                ctx.lineTo(chart.width - 20, chart.height - 55);
                ctx.stroke();
                ctx.fillStyle = 'rgba(200,200,200,1)';
                ctx.font = "14px Arial";
                ctx.fillText("top : " + Math.floor(min / 1000) + "' " + (min % 1000) + " ms", 60, 20);
                ctx.restore();

            }
        }
    };
}
var beziers = initBeziers();
var Bz = beziers;

var msgString = '';
var msgIden = 0;
function HideLoadingAuto() {
    msgIden++;
    alert("test");
    msgString = "$('.msgBoxshow').css('display', 'none');";
    var s1 = "if(msgIden == " + msgIden + "){window.eval(msgString);}"
    setTimeout(function () { window.eval(s1); }, 4000);
}

function CancelHideLoading() {
    msgString = '';
}

function overColor(th) {
    all('.ih-color', function (ita) { ita.style.backgroundColor = th.style.backgroundColor; })

}

function selectColor(th) {
    replacestext("#[main]", "span", ["style=color:" + th.style.backgroundColor + ";"]);
}

function cachedo() {
    if (cacheRedo[currentItem] == null)
        cacheRedo[currentItem] = [];

    alert(window.clipboardData.types[0]);

    cacheRedo[currentItem].push(first(currentItem).innerHTML);
}

function selectFont(th) {

    replacestext("#[main]", "span", ["class=" + th.value.toString().toLocaleLowerCase().replace(/ /g, '')]);

    cachedo();
}

function cacheundo(pop) {
    if (cacheRedo[currentItem + "undo"] == null)
        cacheRedo[currentItem + "undo"] = [];

    cacheRedo[currentItem + "undo"].push(pop);
}

function bold(a) {

    if (a == 1)
        replacestext("#[main]", "span", ["class=normal"]);
    else if (a == 2)
        replacestext("#[main]", "span", ["class=bold"]);


    cachedo();
}

function ltr(a) {

    if (a == 1)
        replacestext("#[main]", "span", ["dir=ltr", "class=ltr"]);
    else if (a == 2)
        replacestext("#[main]", "span", ["dir=rtl", "class=rtl"]);

    cachedo();
}

function ialign(a) {

    if (a == 1)
        replacestext("#[main]", "p", ["class=al-l"]);
    else if (a == 2)
        replacestext("#[main]", "p", ["class=al-c"]);
    else if (a == 3)
        replacestext("#[main]", "p", ["class=al-r"]);
    else if (a == 4)
        replacestext("#[main]", "p", ["class=al-j"]);

    cachedo();
}

var cacheRedo = [];
currentItem = '#test1';
function ed_redo(a) {
    if (a == 1) {
        var pop = cacheRedo[currentItem].pop();
        if (pop == undefined) return;
        first(currentItem).innerHTML = pop;
        cacheundo(pop);
    }
    else if (a == 2) {
        var pop = cacheRedo[currentItem + "undo"].pop();
        if (pop == undefined) return;

        first(currentItem).innerHTML = pop;
        cachedo(pop);
    }
}
function ed_size(a) {
    if (a == 1)
        replacestext("#[main]", "span", ["class=sl"]);
    else if (a == 2)
        replacestext("#[main]", "span", ["class=ss"]);
    cachedo();
}
function ed_top(a) {
    if (a == 1)
        replacestext("#[main]", "span", ["class=rt  t-n00125"]);
    else if (a == 2)
        replacestext("#[main]", "span", ["class=rt  t-00125"]);
    cachedo();
}
function replacestext(replacementText, tag, atts) {
    var sel, range;
    if (window.getSelection) {
        sel = window.getSelection();
        if (sel.rangeCount) {
            range = sel.getRangeAt(0);
            var s = sel.toString();
            s = (s.replace(/\n\r/g, '__br__').replace(/\r\n/g, '__br__').replace(/\n/g, '__br__'));
            console.log(s);
            replacementText = replacementText.replace('#[main]', s);
            range.deleteContents();
            var ds = document.createElement(tag);
            for (var i in atts) {
                var is = atts[i];
                if (is.indexOf('=') != -1) {
                    ds.setAttribute(is.split("=")[0], is.split("=")[1]);
                }
            }
            ds.textContent = replacementText;
            range.insertNode(ds);
            first(currentItem).innerHTML = first(currentItem).innerHTML.replace(/__br__/g, '<br/>');
        }
    } else if (document.selection && document.selection.createRange) {
        range = document.selection.createRange();
        range.text = replacementText;
    }
}

function showPlayerFrame(th, op) {

    if (op.newTab != undefined || op.newTab != null) {
        window.open('/musicPlayer.html#' + op.music + '!!' + op.color + '' + (op.back ? '!' + op.back : ''), "blank");
    } else {
        first('.head', function (at) { at.classList.add('op2'); }, th.parentNode.parentNode);
        th.parentNode.classList.remove('sub-f');
        th.parentNode.classList.add('op2');
        th.parentNode.classList.add('op-h5');

        th.parentNode.innerHTML = '<iframe src="/musicPlayer.html#' + op.music + '!!' + op.color + '' + (op.back ? '!' + op.back : '') + '" scrolling="no" frameborder="0" class="w-full h-full" ></iframe>';
    }

}


var m_move = function (th, event, fun) {
    var val = Math.floor(100. * (th.offsetWidth - abs(event.clientX - (th.offsetLeft +
        th.parentNode.offsetLeft +
        th.parentNode.parentNode.offsetLeft +
        th.parentNode.parentNode.parentNode.offsetLeft +
        th.parentNode.parentNode.parentNode.parentNode.offsetLeft +
        th.parentNode.parentNode.parentNode.parentNode.parentNode.offsetLeft +
        th.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.offsetLeft +
        th.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.offsetLeft +
        th.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.offsetLeft +
        th.parentNode.parentNode.parentNode.parentNode.parentNode.
            parentNode.parentNode.parentNode.parentNode.offsetLeft +
        th.parentNode.parentNode.parentNode.parentNode.parentNode.
            parentNode.parentNode.parentNode.parentNode.parentNode.offsetLeft +
        th.parentNode.parentNode.parentNode.parentNode.parentNode.
        parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.offsetLeft +

         9))) / th.offsetWidth);


    th.querySelector('.wy').style.width = val + '%';

    if (fun) fun(1, val * 1.0);

    var p = val;

    var fl = th.attributes['step'].value * 1.;

    val = Math.floor((1. / fl) * ((val / 100.0) * (th.attributes['max'].value * 1. -
        th.attributes['min'].value * 1.) + (th.attributes['min'].value * 1.))) * fl;

    th.title = val + ' ' + th.attributes['ps'].value;
    if (val.toString().indexOf('00000001') != -1) { val = val.toString().replace('00000001', '') * 1.0; }
    if (val.toString().indexOf('00000002') != -1) { val = val.toString().replace('00000002', '') * 1.0; }
    if (val.toString().indexOf('00000003') != -1) { val = val.toString().replace('00000003', '') * 1.0; }
    if (val.toString().indexOf('00000004') != -1) { val = val.toString().replace('00000004', '') * 1.0; }
    if (val.toString().indexOf('00000005') != -1) { val = val.toString().replace('00000005', '') * 1.0; }
    if (val.toString().indexOf('00000006') != -1) { val = val.toString().replace('00000006', '') * 1.0; }
    if (val.toString().indexOf('00000007') != -1) { val = val.toString().replace('00000007', '') * 1.0; }
    if (val.toString().indexOf('00000008') != -1) { val = val.toString().replace('00000008', '') * 1.0; }
    if (val.toString().indexOf('00000009') != -1) { val = val.toString().replace('00000009', '') * 1.0; }

    th.querySelector('.temp').innerHTML = " (" + (val) + ")";


    m_val = { p: p, v: val, ps: th.attributes['ps'].value };
    if (th.attributes['fun'] && th.attributes['fun'].value)
        window.eval(th.attributes['fun'].value + "(" + val + ")")
}
var m_click = function (th, fun) {
    th.parentNode.querySelector('.back').style.width = m_val.p + '%';
    th.parentNode.querySelector('.wy').style.width = '0%';
    th.parentNode.querySelector('.temp').innerHTML = ' ';
    th.parentNode.querySelector('.mn-val').innerHTML = m_val.v;

    if (fun) fun(2, m_val.v * 1.0);


    th.parentNode.querySelector('.result').innerHTML = m_val.v + ' ' + m_val.ps;
}

var wind = function (op) {
    op = def(op, {});
    this.start = def(op.start, this.start);
    this.live = def(op.live, this.live);
    this.end = def(op.end, this.end);
    this.steps = def(op.steps, this.steps);
    this.fx = def(op.fx, this.fx);
    this.fun = def(op.fun, this.fun);
    this.interval = def(op.interval, this.interval);
    this.last = def(op.last, this.last);
};
wind.prototype = {
    start: 0,
    live: 0,
    end: 0,
    steps: 100,
    interval: 10,
    fx: function (x) {
        return x;
    },
    paused: true,
    last: function (v) { },
    fun: function (v) { },
    go: function (v) {

        var x = (this.end - this.start);
        var y = this.fx(this.live);
        this.start = this.start + x * y / this.steps;
        this.end = v;
        this.live = 0;
        if (this.paused) {

            this.request(this);
        }

    },
    request: function (th) {

        if (th.live + 1 > th.steps) {
            th.last(th.end);
            th.paused = true;
            th.live = 0;
            th.start = th.end;
        }
        else {
            th.paused = false;
            var x = (th.end - th.start);
            th.live++;
            var y = th.fx(th.live);
            y = x * y / th.steps;

            this.fun(th.start + y);

            setTimeout(function () { th.request(th); }, th.interval);
        }
    }
};

var control = {
    slider: function (n, t, mn, mx, step, def, ps, ccs, fu , root) {
        var p = 100.0 * min(1., max(0., def / (mx - mn)));
        return `<div><div class="ctll ns `+root+`" ps="` + ps + `" min="` + mn + `" max="` + mx + `" step="` + step + `"
         onmouseleave=" this.querySelector('.wy').style.width = '0%' ;this.parentNode.querySelector('.temp').innerHTML =  ' ' ;  "
         onmouseup="m_click(this,`+ fu + `);" onmousemove="m_move(this,event,` + fu + `)" >
        <div class="back ab" style="width:`+ floor(p) + `%;"></div>
        <div class="wy ab" style="background-color:#000 !important;opacity:0.2"></div>
        <div dir="rtl" style="background-color:transparent !important;color:#000;" class='ab w-full f f-r  f-nw f-jb f-ac f-cc'>
        <div dir="rtl" class='f-center  w-mn-04 w-mx-04 w-04 f-i11'  > `+ t + ` </div>
        <div dir="rtl" class='f-center `+ ccs + ` result' style='font-weight:700;'> ` + def + ' ' + ps + ` </div>
        <div dir="rtl" class='f-center `+ ccs + ` w-mn-02 w-mx-02 w-02 f-i11 temp' style='color:#222;padding-left:5px;'></div>
        <div class='`+ n + ` f-center ` + ccs + ` w-mn-02 w-mx-02 w-02 f-i11 mn-val' style='display:none;'></div>
        </div><div style="background-color:transparent !important;width:100%;cursor:pointer !important;">&nbsp;</div></div></div>`;
    },
    colorPicker: function (ttl, css, fu) {
        return `<div class='p-0005'>
                <div class='mt-00125 m-0005' onclick='`+ fu + `'>` + ttl + `</div>
                <div dir='rtl' class='ba-i-01 owf c-b-iwgray cwhite rad-03 mb-00125'><input type='text' placeholder:'`+ ttl + `' class='w-full p-0005 m-0005 ba-i-01 c-b-itrans ctrans' ></div></div>`;
    },
    text: function (ttl, css, fu,css2,css3,cssttl,val,chg) {
        return `<div class='p-0005 `+css+`'>
                <div class='mt-00125 m-0005 `+ cssttl+`' onclick='`+ fu + `'>` + ttl + `</div>
                <div dir='rtl' class='  `+ css2 +` rad-03 mb-00125'><input type='text' placeholder:'`+ ttl + `' class='w-full p-0005 m-0005 ba-i-01 c-b-itrans ctrans `+css3+`'  value='`+val+`' onkeyup='`+chg+`' /></div></div>`;
    },
    imgUpload: function (ttl, css, fu) {
        return `<div class='p-0005'>
                <div class='mt-00125 m-0005' onclick='`+ fu + `'>` + ttl + `</div>
                <div dir='rtl' class='ba-i-01 owf c-b-iwgray cwhite rad-03 mb-00125'>
                </div></div>`;
    },
    multiSelect: function (ind,ttl, css, fu) {
        return `<div class='rt p-0005  ` + css +`' >
                <div class='mt-00125 m-0005' onclick='first(".sub",null,this.parentNode).classList.toggle("hdn-i");`+ fu + `(this.parentNode);' >` + ttl + `</div>
                <div dir='rtl' id='mat_`+ind+`' class='items h-01 rad-03 mb-00125 f f-r f-w f-as f-cs f-js '>
                 
                </div>
                <div dir='rtl' class='sub hdn-i ba-i-01 c-b-iblack ab w-full h-mn-02 cwgray rad-02 l-00 t-00 z09'>
                   <div class='f f-r f-w f-as f-cs f-js m-0025'>
                    
                   </div>
                    <div class='ab z10 l-n00125 t-n00125 w-01 h-01 rad-50 cblack c-twhite f-center fs-04' onclick='first(".sub",null,this.parentNode.parentNode).classList.add("hdn-i");`+ fu + `' >×</div>
                </div> 
          </div>`;
    },
    multiSelectItem: function (id, ttl, ccs, fu) {
        return `<div id='ind_` + id + `' class='m-0005  pl-0025 pr-0025 fs-03 f-center f-r rad-05 
            cgray2 `+ ccs + ` c-hblack c-twhite' onclick='if(this.parentNode.className.indexOf("items")!=-1) return; this.classList.toggle("c-inavy");` + fu + `(this);'><div>` + ttl + `</div>
            <div class='clshd mr-0025 fs-05 rad-50 c-twite c-t-hred  bb' onclick='reMat("ind_` + id + `");try{this.parentNode.remove();}catch(e){}'>×</div></div>`;
    },
    imgUploader: function (id, ttl, css, fu, end) {

        setTimeout(end, 300);
        return `<div id='`+id+`' class="imgUploader_`+id+` w-full op0 rt  f f-r f-js m-00125 f-ac f-cc  bb fs-05"  >
            <img title='`+ ttl + `' class="core ba-i-02 c-b-icgray c-b-i-hblack  w-03 h-03 rad-05"  src="/images/add.svg" onload="var thi = this;
            setTimeout(function(){first('.iwait',null,thi.parentNode).classList.add('hdn-i');`+ fu +`(thi)},500);"/>
            <div class="ab t-00 l-00 h-full fs-00 ctrco16 rad-05" style="width:0%"></div>
            <div class="ab iwait  t-00 z10 l-00 h-full f-center fs-00 ctrblack rad-05 hdn-i" style="width:100%">
            <img src='/images/WAT.svg' class='w-02 h-02 animated rotating'/>
            </div> 
             <div class='m-0005 f f-c f-ac f-cc f-jc'>
                <img src='/images/wth.png' class='ba-i-02 c-b-itrgray c-b-i-hnavy rad-50 w-005 h-005' 
          onclick='first(".core",null,this.parentNode.parentNode).src = this.src;' />
                <img src='/images/blc.jpg' class='ba-i-02 c-b-itrgray c-b-i-hnavy rad-50 w-005 h-005' 
            onclick='first(".core",null,this.parentNode.parentNode).src = this.src;' />
                <img src='/images/map.jpg' class='ba-i-02 c-b-itrgray c-b-i-hnavy rad-50 w-005 h-005' 
            onclick='first(".core",null,this.parentNode.parentNode).src = this.src;' />
                  <img src='/images/map2.jpg' class='ba-i-02 c-b-itrgray c-b-i-hnavy rad-50 w-005 h-005' 
            onclick='first(".core",null,this.parentNode.parentNode).src = this.src;' />
                <img src='/images/add.svg' class='ba-i-02 c-b-itrgray c-b-i-hnavy rad-50 w-005 h-005' />
            </div>
        </div>`;
      
    }
};