/**
* get text limit with FF3 compatibility
* author: Mark Gil M. Libres
* on: 8/6/2008
* email: markglibres@yahoo.com
*/
function getTextLimit(taObj)
{
	var maxLen = null;
	var e = null;
	if (window.event) e = window.event; 
	if(e)
	{
		var taObj= e.srcElement? e.srcElement : e.target;
		maxLen = taObj.maxlength;
	}
	/** workaround with firefox 3 */
	if(maxLen == null)
		maxLen = taObj.attributes.getNamedItem("maxlength").value;
	
	return maxLen;
}

/**
* set text limit, with FF3 compatibility
* author: Mark Gil M. Libres
* on: 8/6/2008
* email: markglibres@yahoo.com
*/
function textLimit(taObj,e) {
	
	var	maxLen = getTextLimit(taObj);
	var key=e.keyCode || e.which;
	//alert(key);
	/**
	* exclude delete (46), backspace (8), up (38), down (40), left (37) and right (39) keys
	* 
	*
	*/
	if (taObj.value.length==maxLen && key != 8 && key != 46 && key != 38 && key != 40 && key != 37 && key != 39) return false;
	return true;
	
}

/**
* set text couter, with FF3 compatibility
* author: Mark Gil M. Libres
* on: 8/6/2008
* email: markglibres@yahoo.com
*/
function textCount(taObj,counter) { 
	
	var	maxLen = getTextLimit(taObj);
	var counterContainer = document.getElementById(counter);
	counterContainer.innerHTML = maxLen - taObj.value.length;
	return true;
}

/**
* checks if textbox has the right limit
* author: Mark Gil M. Libres
* on: 12/31/2008
* email: markglibres@yahoo.com
*/
function checkTextLimit(taObj, taName, limitChar)
{
	var obj = taObj;
	var txtLimit = 0;
	
	if(taObj == null)
			obj = document.getElementById(taName);
	
	if(limitChar)
		txtLimit = limitChar;
	else
		txtLimit = getTextLimit(obj,limitChar);
		
	if(obj.innerHTML.length>txtLimit)
	{
		alert('The number of characters should not exceed beyond '+txtLimit);
		obj.focus();
		obj.select();
		return false;
	}
	return true;
}

