﻿// ----------------------------------------------------------------------------------------------------------
//
//	Text Formating v2.00 
//	by Elpidio Pinto - http://www.criativadesign.com
//
//                 .__        __  .__                   .___            .__               
//      ___________|__|____ _/  |_|__|__  _______     __| _/____   _____|__| ____   ____  
//    _/ ___\_  __ \  \__  \\   __\  \  \/ /\__  \   / __ |/ __ \ /  ___/  |/ ___\ /    \ 
//    \  \___|  | \/  |/ __ \|  | |  |\   /  / __ \_/ /_/ \  ___/ \___ \|  / /_/  >   |  \
//     \___  >__|  |__(____  /__| |__| \_/  (____  /\____ |\___  >____  >__\___  /|___|  /
//         \/              \/                    \/      \/    \/     \/  /_____/      \/  bee criativa -->
//
//	Jan 2009
//
//	For more information on this script, email:
//	javascripts@criativadesign.com
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//  
// ----------------------------------------------------------------------------------------------------------

function checkLength(checkObj, maxLength, counterObjId)
{
    if( checkObj)
    {
        var text = checkObj.value;
        var textLength = text.length;
        
        if( textLength > maxLength )
            checkObj.value = text.substring(0, maxLength);
        
        var counterObj = document.getElementById(counterObjId);
        if(counterObj)
            counterObj.innerHTML = maxLength - textLength;
    }
} 


function checkLengthOld(checkObj, maxLength, counterObjId)
{
    if( checkObj)
    {
        var textLength = 0;
        var text = checkObj.value;
        var cnt = 0;

        for(cnt = 0; cnt < text.length; cnt++)
        {
            textLength += (text.substring(cnt,cnt+1) == '<' || text.substring(cnt,cnt+1) == '>') ? 4 : 1;
            
            if( textLength > maxLength )
                break;
        }
        
        if( textLength > maxLength )
        {
            textLength -= (text.substring(cnt,cnt+1) == '<' || text.substring(cnt,cnt+1) == '>') ? 4 : 1;
            checkObj.value = text.substring(0, cnt);
        }
        
        var counterObj = document.getElementById(counterObjId);
        if(counterObj)
            counterObj.innerHTML = maxLength - textLength;
    }
} 