﻿var EvTool = 
{

truer: function()
{
    return true;    
},

falser: function()
{
    return false;
},

nuller: function()
{
    return null;
},

dummy: function()
{
},

getEvObj: function(e)
{
    if (!e) e = window.event;
    return e;
},

focusLater: function(el, select, timeout)
{
    try
    {
        if (!timeout) timeout = 50;
        EvTool.tmpEl = el;
        setTimeout("try{EvTool.tmpEl.focus()}catch(ex){}", timeout);
        if (select) el.select();
    }
    catch (ex)
    {
    }
},

applyMethodLater: function(obj, method, args, timeout)
{
    try
    {
        if (!timeout) timeout = 50;
        if (!args) args = [];
        
        EvTool.tmpObj = obj;
        EvTool.tmpMethod = method;
        EvTool.tmpArgs = args;
        
        setTimeout("EvTool.tmpMethod.apply(EvTool.tmpObj, EvTool.tmpArgs)", timeout);
    }
    catch (ex)
    {
    }
},

getKey: function(e)
{
    var key = null;
    
    if (e = EvTool.getEvObj(e))
    {
        if (e.keyCode) key = e.keyCode;
        else if (e.which) key = e.which;
    }
    
    return key;
},

docPropStacks: [],

// backup <document> handler
// type: <document> handler type ("onclick", "onmouseup", etc)
// (val === newHandler): new <document> handler of type <type>
backupDocProp: function(name, val)
{
    var ps = EvTool.docPropStacks;
    if (!ps[name]) ps[name] = [];
    
    var stack = ps[name];
    
    stack.push(document[name]);
    document[name] = val;
},

restoreDocProp: function(name)
{
    var val = EvTool.docPropStacks[name].pop();
    document[name] = val ? val : null;
    
    return val;
},

testDocProp: function(name)
{
    var stk = EvTool.docPropStacks[name];
    var val = stk[stk.length - 1];
    
    return val;
}

   
};

