// getIDfunction to return commonly used getElementById.  If you see getID(id) etc, it is this function.
function getID(id)
{
    return document.getElementById(id)
}

function isset(varname)
{
    if(typeof varname != 'undefined')
    {
        return true;
    }
    else
    {
        return false;
    }
}

function delConf(url, msg)
{
    if (!isset(msg)) {msg = "this record" }
    var conf = confirm('Are you sure you want to delete ' + msg)
    if (conf) { location.href = url }
}

function insertTags(eid, tag, link)
{
    var id = getID(eid)
    var tagend = "</" + tag + ">"
    
    //this is a link
    if (link != null)
    {
        tagstart = '<a href="' + link + '">'
    }
    else
    {
        var tagstart = "<" + tag + ">"
    }
    
    //Most browsers.
    if (id.setSelectionRange)
    {
        id.value = id.value.substring(0, id.selectionStart) + tagstart + id.value.substring(id.selectionStart,id.selectionEnd) + tagend + id.value.substring(id.selectionEnd, id.value.length)
    }
    //The IE version
    else if (document.selection.createRange().text != "")
    {
        var newText = tagstart + document.selection.createRange().text + tagend
        document.selection.createRange().text = newText
    }
    //Works for both, if no text is selected
    else
    {
        id.value += tagstart + tagend
    }

}

function sendLink(id)
{
    if (getID('textBoxLink').style.visibility == 'visible')
    {
        link = getID('textBoxLinkInput').value
        getID('textBoxLink').style.visibility = 'hidden'
    
        insertTags(id, 'a', link)
        getID('textBoxLinkInput').value = ""
        getID(id).focus()
    }
}

function toggleLinkID(eid, anchor)
{
    var id = getID(eid)
    if(id.style.visibility == 'visible') 
    {
        id.style.visibility = 'hidden'
    }
    else
    {
        pos = $('#'+anchor).offset()
        
        id.style.visibility = 'visible'
        
        $('#'+eid).css({ "left": (pos.left + 20) + "px", "top": (pos.top + 80) + "px" });
        getID('textBoxLinkInput').focus()
    }
}

function toggleSessions(sArray, cb)
{   
    var check = getID(cb);
    if (!check.checked)
    {
        for (i=0; i<sArray.length; i++)
        {
            sess=getID(sArray[i]);
            sess.style.display = "none";
        }
    }
    else
    {
        for (i=0; i<sArray.length; i++)
        {
            sess=getID(sArray[i]);
            sess.style.display = "block";
        }
    }
}

