﻿function jDecline( inDisplay ){
	document.getElementById('decline').style.display = inDisplay;
	document.getElementById('decline').focus();
	scrollTo(0,0);
}/* end jDecline */

function checkWordCount(entryBoxName, counterBoxName, counterLabelName, maxLength, WordCountMode)
{
    try
    {
        var entryBoxObj;
        var counterBoxObj;
        var counterLabelObj;
        
        if (document.getElementById)
        {
            entryBoxObj = document.getElementById(entryBoxName);
            counterBoxObj = document.getElementById(counterBoxName);
            counterLabelObj = document.getElementById(counterLabelName);      
        }
        else if (document.all)
        {
            entryBoxObj = document.all[entryBoxName];
            counterBoxObj = document.all[counterBoxName];
            counterLabelObj = document.all[counterLabelName];   
        }
        
        if (entryBoxObj && counterBoxObj && counterLabelObj)
        {
            var entryText = new String(entryBoxObj.value);
            
            if (WordCountMode)
            {
                var words = entryText.split(/ /);
                var cnt = words.length;

                if ((maxLength-cnt+1) >= 0)
                { 
                    counterBoxObj.value = (maxLength-cnt+1).toString();
                }
                
                if (maxLength - cnt < -1)
                { 
                    var rewriteStr = new String("");
                    for (var i = 0; i < maxLength; i++)
                    {
                        if (i < words.length)
                        {
                            rewriteStr += words[i].toString() + " ";
                        }
                    }
                    entryBoxObj.value = rewriteStr;
                }

                //HIGHLIGHT WORD COUNT AS WARNING TO USER WHEN NEARLY OUT OF WORDS
                if (maxLength - cnt < 5)
                {
                    counterLabelObj.style.background = "#FF3333";
                    counterLabelObj.style.color = "#FFFFFF";
                }
                else
                {
                    counterLabelObj.style.background = "#FFFFFF";
                    counterLabelObj.style.color = "#000000";
                }
                    
            }
            else
            {
                if (maxLength > entryText.length)
                { 
                    counterBoxObj.value = (maxLength - entryText.length);
                } 
                else
                {
                    counterBoxObj.value = 0; 
                    entryBoxObj.value = entryText.substr(0, maxLength);
                }
            }
        }
    }
    catch (err)
    {alert(err);}
}