function Trim(TRIM_VALUE)
{
	if(TRIM_VALUE.length < 1)
	{
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE=="")
	{
		return "";
	}
	else
	{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0)
	{
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

	} //End While
	return strTemp;

} //End Function

function LTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
	{
		return"";
	}
		var v_length = VALUE.length;
		var strTemp = "";

		var iTemp = 0;

	while(iTemp < v_length)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function

/********************************************************
*	Counts the characters currently entered into a form field
*
*	@author      Ava Hristova
*	@version     1.00
********************************************************/

charCount = 1;
maxCharCount = 2000;

function displayRemLength(fieldName) {


	remField = document.getElementById(fieldName);
	remField.innerHTML = (maxCharCount - charCount > 0) ? maxCharCount - charCount : 0;
}

function evalEntryLength(curField, maxLimit, discardXtra, errClass, normalClass) {
	maxCharCount = maxLimit;
	var fieldLength = getCharCount(curField);
	
	if (fieldLength > maxLimit) {
           alert('Text Exceeds');
		if (errClass != "") {
		
			curField.className = errClass;
		}
		if (discardXtra) {
			showAllowedLength(curField, maxLimit);
			
		}
	} else if (normalClass != "") {
		curField.className = normalClass;
		
	}
}

function getCharCount(curField) {
	charCount = curField.value.length;
	
	return charCount;
}

function showAllowedLength(curField, maxLimit) {
	curField.value = curField.value.substr(0, maxLimit);
	window.status = curField.value;
}


function getfocus()
{
window.document.getElementById("hp-chr-cnt").style.display= 'inline'
}

//Email validate    
	function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}
   function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}
    function isNumberKey(evt)
			{
				var charCode = (evt.which) ? evt.which : event.keyCode
				if (charCode > 31 && (charCode < 48 || charCode > 57))
					return false;
				return true;
			}
