﻿/* Function to set the comment text to maximum number of characters allowed.*/
function SetCommentsText(controlObject ,numberofCharactersAllowed)
{
	if( controlObject !=null )
	{
		var value = controlObject.value;
		var x = value.length+1;
		if(x > numberofCharactersAllowed)
		{
			controlObject.value = value.substring(0, numberofCharactersAllowed);
		}
	}
}

function GetControl(controlID)
{
	return document.getElementById(controlID);
}

function validateAndDisplaytextLimit(controlToValidate, numberOfCharAllowed, controlLegend)
{
	if( controlToValidate != null && numberOfCharAllowed != null )
	{
		/* Get the control to be validated */
		var textToBeValidated =  controlToValidate.value;
		/* Check if the length of the current text is greater than the allowed number of characters */
		if( textToBeValidated != null && textToBeValidated.length > numberOfCharAllowed)
		{
			/* Trim down the number of characters present in the control to the allowed number of characters */
			controlToValidate.value = controlToValidate.value.substring(0,numberOfCharAllowed);
			textToBeValidated = controlToValidate.value;
		}		
		if( textToBeValidated != null && controlLegend != null)
		{
			/* Get the length of the current text */
			var currentTextLength = textToBeValidated.length;
			/* Get the number of allowed charters left */
			currentTextLength = numberOfCharAllowed-currentTextLength;
			controlLegend.innerHTML = currentTextLength + "/" + numberOfCharAllowed;
		}
	}
	SetCommentsText(controlToValidate,numberOfCharAllowed);
}

function hideControl(control)
{
    if(control)
    {
       control.className = "hidecontrol";
    }
}

function showControl(control)
{
    if(control)
    {
       control.className  = "showcontrol";
    }
}

function clearTextControl(control)
{
    if(control)
    {
       control.value  = "";
    }
}