var MAX_ENGRAVING_LENGTH = 1000;

function CheckLength( sender, args )
{
	//alert( "In CheckLength" );
	
	// Check the length
	var value = args.Value;	
	if( value.length > MAX_ENGRAVING_LENGTH )
		args.IsValid = false;
	else
		args.IsValid = true;
		
	//alert( args.IsValid );
	
	//alert( "Out of CheckLength" );
}

function ShowLetterCount( str )
{
	var l;
	
	if( null == str || 0 == str.length )
		alert( "You have not yet entered anything." );
	else
		alert( "You have entered " + str.length + " characters." );
}

function CheckLengthMultiple( sender, args )
{
	var itemsInCurPanel = sender.parentNode.childNodes;
	var engravingTextBox = null;
	
	// Find the text area whose ID contains the word "EngravingText"
	for( i = itemsInCurPanel.length - 1; i > -1; i-- )
	{
		var curItem = itemsInCurPanel.item( i );
		if( curItem.getAttribute )
		{
			if( "textarea" == curItem.getAttribute( "type" ) && 
				curItem.getAttribute( "name" ).indexOf( "EngravingText" ) != -1 )
			{
				engravingTextBox = curItem;
			}
		}
	}

	if( null != engravingTextBox )
	{		
		var value = args.Value;
		
		// Get the maximum length set for the current engraving text box
		var maxEngravingLength = parseInt( engravingTextBox.getAttribute( "maxlength" ) );
		//alert( "maxEngravingLength: " + maxEngravingLength );
		if( isNaN( maxEngravingLength ) )
		{
			// Length not set. Use default one.
			maxEngravingLength = MAX_ENGRAVING_LENGTH;
			//alert( "maxEngravingLength is NaN. maxEngravingLength  = " + maxEngravingLength );
		}

		// Validate the length of the current engraving text
		if( value.length > maxEngravingLength )
			args.IsValid = false;
		else
			args.IsValid = true;
	
		//alert( "Valid: " + args.IsValid );
	}
}
