﻿function Mark() {
    this.Index = 0;
    this.AlertCopyMsg = '复制好了，发给我的QQ/MSN好友分享吧！';
    this.AddId = 'AddMark';
    this.ShowId = 'ShowMark';
    this.AddHTML = '<div class="TagNav"><div class="PinIco" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + GlobalConfig.SkinPath + 'Images/PinIco.png\',sizingMethod=\'image\') !important;"></div><div class="InTagCon"><div class="InTagConBg" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + GlobalConfig.SkinPath + 'Images/InTagBg.png\',sizingMethod=\'image\') !important;"></div><div class="InTagDetCon"><h3>标记</h3><table cellpadding="1" cellspacing="0" border="0"><tr><th>标题：</th><td><input id="txtMarkTitle" style="width:228px; border:solid 1px #666" value="" type="text" /></td></tr><tr><th></th><td class="Explain">(<span>※</span>此项为必填项 控制在20字符以内)</td></tr><tr><th>内容：</th><td><textarea id="txtMarkContent" style=" border:solid 1px #666" cols="26"  rows="3"></textarea></td></tr><tr><td colspan="2" align="center"><img id="btnMarkConfirm" src="' + GlobalConfig.SkinPath + 'Images/TagBtn.gif" style="cursor:pointer" alt="确认" /></td></tr></table></div><div id="btnMarkClose" class="CloseWin" onmouseover="this.className=\'CloseBtnOver\'" onmouseout="this.className=\'CloseBtnOut\'" title="关闭"></div></div></div>';

    this.ViewHTML = '<div class="TagNav"><div class="PinIco" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + GlobalConfig.SkinPath + 'Images/PinIco.png\',sizingMethod=\'image\') !important;"></div><div class="ViewTagConMax"><div class="ViewTagConBg" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + GlobalConfig.SkinPath + 'Images/ViewTagBg.png\',sizingMethod=\'image\')!important;"></div><div class="ViewTagDetCon"><h3 id="MarkTitle">{$MarkerTitle}</h3><div class="AutoText" id="MarkContent">{$MarkerContent2}</div><div class="WkButton"><img id="btnMarkDelete" style="cursor:pointer" src="' + GlobalConfig.SkinPath + 'Images/DeleteTag.gif" alt="删除标记" onclick="parent._Mark.Delete(\'{$Id}\')"/>&nbsp;&nbsp;<img id="btnMarkCopy" style="cursor:pointer" src="' + GlobalConfig.SkinPath + 'Images/ToFriend.gif" alt="复制给好友"  onclick="parent._Mark.Copy(\'{$url}\')"/></div></div><div id="MarkMaxMin" class="SwNavOut" onmouseover="this.className=\'SwNavOver\'" onmouseout="this.className=\'SwNavOut\'" title="收缩/展开" onclick="parent._Mark.MaxMin(this)"></div></div></div>'; 
    this.Add = function(x, y, title) {
        vM.MoveTo(x * 1 + vM.GetMapPos(120), y * 1 + vM.GetMapPos(120), true);
        vM.HidePointerTip();
        if (vM.$(this.AddId)) {
            vM.moveEntity(this.AddId, x * 1, y * 1);
            vM.$(this.AddId).style.display = "block";
        } else {
            var addmark = vM.$C('div');
            addmark.id = this.AddId;
            addmark.innerHTML = this.AddHTML;
            vM.appendEntity(addmark, _MarkLayer, false, x, y, 305, 214, 0, 34, false);
        }
        vM.$('txtMarkTitle').value = title;
        vM.$('txtMarkContent').value = '';
        //debugger;
        vM.$('btnMarkConfirm').onclick = this.Show.bind(this, x, y, '', '');
        vM.$('btnMarkClose').onclick = this.Hidden.bind(this);
        _IsBeginSelectMark = false;
    };

    this.Show = function(x, y, title, content) {
        //debugger;
        if (vM.$('txtMarkTitle')) {
            if (vM.$('txtMarkTitle').value.length > 20) {
                alert('标题必须控制在20个字符以内');
                vM.$('txtMarkTitle').focus();
                return;
            } else if (vM.$('txtMarkTitle').value.length < 1) {
                alert('标题必须填写');
                vM.$('txtMarkTitle').focus();
                return;
            }
        }
        if (title.length < 1) {
            if (vM.$('txtMarkTitle')) {
                title = vM.$('txtMarkTitle').value;
            }
        }
        if (content.length < 1) {
            if (vM.$('txtMarkContent')) {
                content = vM.$('txtMarkContent').value.replaceAll('\r\n', '<br />');
            }
        }
        if (vM.$(this.AddId)) {
            vM.$(this.AddId).style.display = 'none';
        }

        var c = new CookieHelper();
        var d = new Date();
        var MarkCookie = c.getCookie('Mark') == null ? '' : c.getCookie('Mark');
        Mark = parseInt(x) + '^' + parseInt(y) + '^' + title + '^' + content + '|';
        d.setMonth(d.getMonth() + 12);
        c.setCookie('Mark', MarkCookie + Mark, d);

        //this.Index++;
        var i = 0;
        i = c.getCookie('Mark').split('|').length - 2; 
        var markId = this.ShowId + i;
        var showmark = vM.$C('div');
        showmark.id = markId;
        showmark.style.display = 'none';
        
        var url='http://' + GlobalConfig.NodeUrl + '/?l=' + GlobalConfig.Language + '&x=' + x + '&y=' + y + '&title=' + escape(title) + '&content=' + escape(content); 

        showmark.innerHTML = this.ViewHTML.replace('{$MarkerTitle}', title).replace('{$MarkerContent2}', content).replace('{$Id}', markId).replace('{$url}', url);
        vM.appendEntity(showmark, _MarkLayer, false, x, y, 305, 132, 0, 34, false);
            
        


        showmark.style.display = 'block';
    };
    this.Delete = function(id) {
    if (vM.$(id)) {
            
            vM.$(id).parentNode.removeChild(vM.$(id));
        }
    };
   
    this.Copy = function(url) {
        fnCopyToClipboard(url, this.AlertCopyMsg);
    };
    this.MaxMin = function(obj) {
       
        if (obj.parentNode.className == 'ViewTagConMax') { 
            obj.parentNode.className = 'ViewTagConMin';
            obj.parentNode.childNodes[0].style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + GlobalConfig.SkinPath + 'Images/ShowTagBg.png\',sizingMethod=\'image\')'
        } else {
        obj.parentNode.className = 'ViewTagConMax';
        obj.parentNode.childNodes[0].style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + GlobalConfig.SkinPath + 'Images/ViewTagBg.png\',sizingMethod=\'image\')'
        }
    };
    this.Begin = function() {
        if (!_IsBeginSelectMark) {
            _IsBeginSelectMark = true;
            var tip = '<div style="height:15px; line-height:15px; border:1px solid #1A70C7; background:#fff; padding:0 4px 0 4px;filter:alpha(opacity=90); opacity:.9; float:left; color:#000; font-size:12px; white-space:nowrap;">单击左键选择标记位置</div>';
            vM.ShowPointerTip(tip);
        }
    };
    this.Hidden = function() {
        vM.$(this.AddId).style.display = "none";
    }
    


    this.ShowAll = function() {
        
        var c = new CookieHelper();
        var aMark = c.getCookie('Mark') == null ? '' : c.getCookie('Mark').split('|');
        if (aMark == 'undefined') return false; 
        
        for (var i = 0; i < aMark.length - 1; i++) {
            var temp = aMark[i].split('^');
            var x = temp[0];
            var y = temp[1];
            var title = temp[2];
            var content = temp[3];
            var url='http://' + GlobalConfig.NodeUrl + '/?l=' + GlobalConfig.Language + '&x=' + x + '&y=' + y + '&title=' + escape(title) + '&content=' + escape(content); 
            var nd = vM.$C('div');
            var markId = this.ShowId + i;
            nd.id = markId;
            nd.innerHTML = this.ViewHTML.replace('{$MarkerTitle}', title).replace('{$MarkerContent2}', content).replace('{$Id}',markId).replace('{$url}',url);
            

          
            vM.appendEntity(nd, _MarkLayer, false, x, y, 305, 132, 0, 34, false);
            nd = null;

        }
        _IsShowAllMark = true;
        
    }
}
Mark.prototype.Clear = function() {
    var c = new CookieHelper();
    var aMark = c.getCookie('Mark') == null ? '' : c.getCookie('Mark');
    for (var i = 0; i < aMark.length; i++) {
        this.Delete(this.ShowId + i);
    }
    _IsShowAllMark = false;
}
Mark.prototype.Hidden = function() { 
    
}
var _Mark = new Mark();
