﻿/*
    function disabPresBut(but) 
    {
        but.disabled = true;
        document.getElementById('PressedButton').value = but.name;
    }

    function show(iid) {
        var iidhref = '<%= ConfigurationManager.AppSettings["WmEuServerPreUrl"] %>/Issues/Details?iid=' + iid;
        var MyDiv = document.getElementById('MyDiv');
        MyDiv.style.visibility = "visible";

        var MyFrame = document.getElementById('frameIID');
        MyFrame.setAttribute('src', iidhref);
        return false;
    }
*/

function smartFillerNames(curId, numId, codId) 
{
    var cur = document.getElementById(curId);
    var num = document.getElementById(numId);
    var cod = document.getElementById(codId);

    if (!(cur && cod && num)) return false;

    var val = cur.value;
    var re0 = new RegExp("\\s*\\d{4,30}\\s*");
    var sres0 = val.match(re0);
    if (sres0 == "") return false;
    
    var re = new RegExp("\\s*\\d{4,30}\\s*[ :#*]\\s*\\d{10,99}");
    var sres = val.match(re);
    if (sres == "") return false;

    val = String(sres);
    var i = val.indexOf(":");
        if (i == -1) 
            i = val.indexOf("#");
                if (i == -1) 
                    i = val.indexOf("*");
                        if (i == -1)
                            i = val.indexOf(" ");
                                if (i == -1) 
                                    return false;    

    var n = val.substring(0, i);
    var c = "";
    if (i < val.length)
        c = val.substring(i + 1, val.length);

    num.value = n;
    cod.value = c;

    return true;
}

function smartFiller(curId) {
    return smartFillerNames(curId, 'Number', 'Code');
}

function CopyToClipboard() {
    return CopyToClipboardNames('Number', 'Code');
}

function CopyToClipboardPref(pref) {
    var num = document.getElementById(pref + 'Number');
    var cod = document.getElementById(pref + 'Code');

    copyToClipboardInner(num.value + ' ' + cod.value);
}

function CopyToClipboardNames(numId, codId) {
    var num = document.getElementById(numId);
    var cod = document.getElementById(codId);

    copyToClipboardInner(num.value + ' ' + cod.value);
}

function CopyToClipboardFull(numId, codId, amntId, issId) {
    var num = document.getElementById(numId);
    var cod = document.getElementById(codId);
    var amnt = document.getElementById(amntId);
    var iss = document.getElementById(issId);

    var amntVal = getInnerText(amnt);
    if (!amntVal)
        amntVal = amnt.value;

    copyToClipboardInner(num.value + ' ' + cod.value + ' ' + amntVal + ' ' + getInnerText(iss));
}

function getInnerText(obj) {
    return obj.textContent ? obj.textContent : obj.innerText
}

function copyToClipboardInner(content) {
    if (window.clipboardData && window.clipboardData.setData) {
        window.clipboardData.setData("Text", content);
    }
    else {
        try {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        }
        catch (e) {
            alert('Unfortunately your browser does not have access to clipboard copy function');
            return;
        }

        var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"].getService();
        if (clipboard) {
            clipboard = clipboard.QueryInterface(Components.interfaces.nsIClipboard);
        }

        var transferable = Components.classes["@mozilla.org/widget/transferable;1"].createInstance();
        if (transferable) {
            transferable = transferable.QueryInterface(Components.interfaces.nsITransferable);
        }

        if (clipboard && transferable) {
            // тип передаваемых данных transferable.addDataFlavor("text/unicode"); 
            var textObj = new Object();
            var textObj = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
            if (textObj) {
                textObj.data = content;
                // Упаковываем данные в контейнер 
                transferable.setTransferData("text/unicode", textObj, content.length * 2);
                var clipid = Components.interfaces.nsIClipboard;
                clipboard.setData(transferable, null, clipid.kGlobalClipboard);
            }
        }
        else
            alert('Unfortunately your browser does not have access to clipboard copy function');
    }
}

/*
function CopyToClipboard(numId, codId, amountId, ordertypeId, msgTo)
{
    var num = document.getElementById(numId);
    var cod = document.getElementById(codId);
    var amount = document.getElementById(amountId);
    var type = document.getElementById(ordertypeId);

    var samount = getInnerText(amount);
    var stype = getInnerText(type);
    var curr = "";
    if (stype != "")
    {
        var nDot = stype.indexOf('.');
        if (nDot != -1)
            curr = stype.substring(0, nDot);
    }

    var date = new Date();
    var sdate = getTimeFormatEng(date.getUTCMonth(), 
                                 date.getUTCDate(), 
                                 date.getUTCFullYear(), 
                                 date.getUTCHours(), 
                                 date.getUTCMinutes(), 
                                 date.getUTCSeconds())
    if (cod.value != '')
        if (samount != '')
            copyToClipboardInner(num.value + '*' + cod.value + ", " + samount + " " + curr + " (" + stype + "), " + sdate);
        else    
            copyToClipboardInner(num.value + '*' + cod.value + ', ' + msgTo + " " + stype + ", " + sdate);
}

function CopyToClipboardOld(numId, codId, amountId, ordertypeId)
{
    var num = document.getElementById(numId);
    var cod = document.getElementById(codId);
    var amount = document.getElementById(amountId);
    var type = document.getElementById(ordertypeId);

    var samount = getInnerText(amount);
    var stype = getInnerText(type);
    var curr = "";
    if (stype != "")
    {
        var nDot = stype.indexOf('.');
        if (nDot != -1)
            curr = stype.substring(0, nDot);
    }

    var date = new Date();
    var sdate = getTimeFormatEng(date.getUTCMonth(), 
                                 date.getUTCDate(), 
                                 date.getUTCFullYear(), 
                                 date.getUTCHours(), 
                                 date.getUTCMinutes(), 
                                 date.getUTCSeconds())

    if (cod.value != '')
        if (samount != '')
            copyToClipboardInner(num.value + '*' + cod.value + ", " + samount + " " + curr + " (" + stype + "), " + sdate);
        else    
            copyToClipboardInner(num.value + '*' + cod.value + " (" + stype + "), " + sdate);
}

function getTimeFormatEng(m, d, y, h, min, sec)
{
    var XM = "AM";
    if (h > 12)
    {
        XM = "PM";
        h = h - 12;
    }

    return String(m) + "/" + String(d) + "/" + String(y) + " " +
           String(h) + ":" + String(min) + ":" + String(sec) + " " + XM + " (UTC)";
}

function getInnerText(obj)
{
    return obj.textContent ? obj.textContent : obj.innerText
}

*/


