﻿// JScript File

function WordCharacterCount(textField, infoAreaID)
{

    
    
    var wordCount=1;
    var characterLength;
    

    // Counts the spaces and new line characters while ignoring 
    // double spaces, usually one in between each word. 
    if(textField != null && textField.value != null)
    {
        characterLength = textField.value.length;
        //--- get the data from the text field and trim (right and left)
        var data = textField.value.replace(/^\s+|\s+$/g,"");
        for (x=0; x < characterLength; x++) 
        { 
        
            if 
            (
                    (data.charAt(x) == " " && data.charAt(x-1) != " ")
                    || 
                    (data.charAt(x) == "\n" && data.charAt(x-1) != "\n")
            ) 
            {

                   wordCount = wordCount + 1; 

            }

        }  
                         
    }
    
   
    var oInfoArea = window.document.getElementById(infoAreaID);
    if(oInfoArea != null)
    {
        //spnWordCount.innerText = wordcounter;
        oInfoArea.innerText = "Words: " + wordCount + " " + "Characters: " + characterLength;
    }

   

}


