
function delay_CountTextBox(textboxId, outputId, formatString, treatCRasOneChar, maxChars)
{
    setTimeout("skm_CountTextBox('" + textboxId + "','" + outputId + "','" + formatString + "'," + treatCRasOneChar + "," +  maxChars + ");", 500);
}

function skm_CountTextBox(textboxId, outputId, formatString, treatCRasOneChar, maxChars)
{
    var textBox = document.getElementById(textboxId);
    var output = document.getElementById(outputId);
    
    var tbText = textBox.value;
    var totalWords = 0;
    var totalChars = 0;

    // Count the total number of words...    
    var uniformSpaces = tbText.replace(/\s/g, ' ');
    var pieces = uniformSpaces.split(' ');

    for (var i = 0; i < pieces.length; i++)
        if (pieces[i].length > 0)
            totalWords++;

    // limit the number of characters if required
    if (maxChars != 0)
    {
        if (textBox.value.length > maxChars) {
		    textBox.value = textBox.value.substring(0, maxChars);
		    tbText = textBox.value
		}

    }
    if (treatCRasOneChar)
    {        
        var removedExtraChar = tbText.replace('\r\n', '\n');
        totalChars = removedExtraChar.length;
    }
    else   
        totalChars = tbText.length;
    
    
    if (maxChars != 0 && totalChars > ((maxChars/100)*90))
        output.innerHTML = "<font color=red>" + formatString.replace('{0}', totalWords).replace('{1}', totalChars).replace('{2}', maxChars) + "</font>";
    else
        output.innerHTML = formatString.replace('{0}', totalWords).replace('{1}', totalChars).replace('{2}', maxChars);
}


/* Based on script created by: John G. Wang | http://www.csua.berkeley.edu/~jgwang/ */
/* Script online at: http://javascript.internet.com/forms/check-cap-locks.html */
function skm_CheckCapsLock( e, warnId, dispTime ) {
	var myKeyCode = 0;
	var myShiftKey = e.shiftKey;
    
	if ( document.all ) {
    	// Internet Explorer 4+
		myKeyCode = e.keyCode;
	} else if ( document.getElementById ) {
    	// Mozilla / Opera / etc.
		myKeyCode = e.which;
	}
	
	if ((myKeyCode >= 65 && myKeyCode <= 90 ) || (myKeyCode >= 97 && myKeyCode <= 122)) {
		if ( 
    	    // Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
	        ( (myKeyCode >= 65 && myKeyCode <= 90 ) && !myShiftKey )

	        ||

    	    // Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
	        ( (myKeyCode >= 97 && myKeyCode <= 122 ) && myShiftKey )
    	   )
        {
		    skm_ShowCapsWarning(warnId, dispTime);
	    }
	    else {
	        skm_HideCapsWarning(warnId);
	    }
    }
}

function skm_GetWarningElement(warnId)
{
	if ( document.all ) {
    	// Internet Explorer 4+
		return document.all[warnId];
	} else if ( document.getElementById ) {
    	// Mozilla / Opera / etc.
		return document.getElementById(warnId);
	}
}

/* Clearing of timers logic / script based on work by Ben Kittrell
   http://garbageburrito.com/blog/entry/555/slideshow-clearing-all-javascript-timers */
var myTimers = new Array();

function skm_ShowCapsWarning(warnId, dispTime)
{
    var warnElem = skm_GetWarningElement(warnId);
    
    if (warnElem == null)
        return;
    else
    {
        warnElem.style.visibility = 'visible';
        warnElem.style.display = 'inline';
        
        if (dispTime > 0)
            myTimers.push(setTimeout('skm_HideCapsWarning("' + warnId + '");', dispTime));
    }
}

function skm_HideCapsWarning(warnId)
{
    var warnElem = skm_GetWarningElement(warnId);
    
    if (warnElem == null)
        return;
    else
    {
        warnElem.style.visibility = 'hidden';
        warnElem.style.display = 'none';
        
        // Clear all timers
        while (myTimers.length > 0)
            clearTimeout(myTimers.pop());
    }
}