﻿function ShowNHide(control)
{
    try
    {
        var objStyle = $get(control).style;
        
        if (objStyle.display == 'none')
        {
            objStyle.display = 'block';
        }
        else
        {
            objStyle.display = 'none';
        }
    }
    catch (e)
    {
    }
}

function CountCharsForAlerting(alertID, countID, charLimit)
{
    try
    {
        var objAlert = document.getElementById(alertID);
        var objCount = document.getElementById(countID);
        
        if (objAlert.value.length > charLimit)
        {
            objAlert.value = objAlert.value.substring(0, charLimit);
        }
        
        objCount.innerHTML = String(charLimit - objAlert.value.length) + " chars left";
    }
    catch (e)
    {
    }
}

function AddFriendForAlerting(toID, friend)
{
    try
    {
        var objTo = document.getElementById(toID);
        
        if (objTo.value == '')
        {
            objTo.value = friend;
        }
        else
        {
            objTo.value = objTo.value + ", " + friend;
        }
    }
    catch (e)
    {
    }
}

// taken from http://alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript .
function InsertAtCursor(control, text)
{
    var objControl = document.getElementById(control);
    
    if (document.selection)
    {
        objControl.focus();
        var objSelection = document.selection.createRange();
        objSelection.text = text;
    }
    else if (objControl.selectionStart || objControl.selectionStart == 0)
    {
        var intStart = objControl.selectionStart;
        var intEnd = objControl.selectionEnd;
        objControl.value = objControl.value.substring(0, intStart) + text + objControl.value.substring(intEnd, objControl.value.length);
    }
    else
    {
        objControl.value += text;
    }
}

function SkipError()
{
    return true;
}

window.onerror = SkipError;
