//-------------------------------- Function to count the number of characters in article text typed by user --------------------

function countCharacters_singleversion2()
{
	
	var MAX_LENGTH =700;


	var valueofmessage = document.addanotherversionform.articletext.value;

	var lengthofmessage = document.addanotherversionform.articletext.value.length;
			
	var numberofenterkeys = CountEnterKey2(valueofmessage); 		// javascript treats carriage return as 2 chars but we have to treat is as 1 therefore, no. of carriage returns(1) is subtracted from fulllength(2)

	var actualmessagelength=document.addanotherversionform.actuallength.value;			// will hold actual message length with carriage return counted as 2

	lengthofmessage = lengthofmessage - numberofenterkeys;
	
	if(lengthofmessage > MAX_LENGTH)
	{
		alert("Maximum Length is Reached");
		TruncateExtraText2(actualmessagelength);
	}
	else
	{	
		actualmessagelength = lengthofmessage + numberofenterkeys;
		document.addanotherversionform.actuallength.value = actualmessagelength;
	

	
	var remchar = MAX_LENGTH - lengthofmessage;


	document.addanotherversionform.charcount.value = lengthofmessage;
	document.addanotherversionform.remcharcount.value = remchar;



	
}
		

}

//-------------------- Returns no. of carriage returns in a message / string ----------------------
function CountEnterKey2(message)
{

var len = message.length;	
var counter=0;

for(var i=0;i<len;i++)
	{
		var c= message.charCodeAt(i);
		if(c==13)				// 13 and 10 both values are printed when a carriage return is encountered
		counter++;
		

	}

return counter;

}
//--------------------------------- Trucates extra text entered in message text area -----------------------------

function TruncateExtraText2(actualmessagelength)
{
	var valueofmessage = document.addanotherversionform.articletext.value;

	valueofmessage = valueofmessage.substring(0,actualmessagelength);
	
	document.addanotherversionform.articletext.value = valueofmessage;
	
	
}

