// JavaScript Document
function whatsLeft(whichOne,max,showRemaining)
	{
	/*
	"whichOne"
	This is the id of the text input or textarea that you want to limit
	DO NOT SPECIFY THE ID! Just use 'this' as in sample code below.
	Add this event handler code to the input/textarea to trigger this function:
		onkeyup="whatsLeft(this,'6000','msgChars');"

	"max" 
	This is the max number of characters that can be entered
	
	"showRemaining"
	This is the id of the textfield where the remaining number of characters should be shown
	Make sure your
	To display remaining chars, use this sample snippet:
		<span style="color:#999999; font-size:9px;">
			chars left: 
			<input name="msgChars" type="text" id="msgChars" value="6000" size="3" disabled="disabled" onfocus="self.blur()" style="font-size:9.5px; width:30px; color:#999999;" />
		</span>
	
	*/
	
	//alert("start limitChar");
	var theValue = whichOne.value
	var current = theValue.length;
	//alert("current: " + current);
	document.getElementById(showRemaining).innerHTML=max-current;
	if(current>max)
		{
			//alert("red");
		whichOne.style.color="red"; 
		theValue = theValue.substring(0,max);
		whichOne.value=theValue;
		} else {
			//alert("normal");
		whichOne.style.color="black"; 
		}
	}
function showWhatsLeftIf(whichOne,max,showMaxHere,divToShow,showWhenThisMany)
	{
	var theValue = whichOne.value
	var current = theValue.length;
	$("#"+showMaxHere).val(max-current);
	//document.getElementById(showMaxHere).value=max-current;
	if((current+showWhenThisMany)>=max)
		{
		//document.getElementById(divToShow).style.visibility="visible";	
		document.getElementById(divToShow).style.fontSize="10px";	
		document.getElementById(divToShow).style.color="red";	
		document.getElementById(divToShow).style.fontWeight="bold";	
		$("#"+showMaxHere).css("color","#FF0000");
		//document.getElementById(showMaxHere).style.color="#FF0000";	
		} else {
		//document.getElementById(divToShow).style.visibility="hidden";	
		document.getElementById(divToShow).style.fontSize="9px";	
		document.getElementById(divToShow).style.color="black";	
		document.getElementById(divToShow).style.fontWeight="normal";	
		$("#"+showMaxHere).css("color","black");
		//document.getElementById(showMaxHere).style.color="black";	
		}
	if(current>=max)
		{
		whichOne.style.color="red"; 
		theValue = theValue.substring(0,max-1);
		whichOne.value=theValue;
		} else {
		whichOne.style.color="black"; 
		}
	}