﻿
    function textCounter(field, countfield, maxlimit)
    {

if (document.getElementById(field).value.length > maxlimit) // if too long...trim it!
{
document.getElementById(field).value = document.getElementById(field).value.substring(0, maxlimit);
}
 document.getElementById(countfield).value = maxlimit - document.getElementById(field).value.length;
    }
    
    //Round off decimal to the precision set
function roundOff(value, precision)
/*
formula to round any number to x decimal points is:
1) Multiple the original number by 10^x (10 to the power of x)
2) Apply Math.round() to the result
3) Divide result by 10^x
*/
{
        precision = parseInt(precision);

        return Math.round(value * Math.pow(10, precision))/Math.pow(10, precision);
}

   //Allow Number and "." only
function numCheck(eventObj, obj) {
	var keyCode
	// Check For Browser Type
if (document.all) { 
	keyCode = eventObj.keyCode
	}
else {
		keyCode = eventObj.which
	}
	var str = obj.value;
	
	if (keyCode == 46) { //Check for only one '.'
		if (str.indexOf(".")>0){
			return false
		}
	}

if (keyCode == 45) { //Check for only one '-'
		if (str.indexOf("-")>0){
			return false
		}
	}

	if((keyCode<48 || keyCode >58)   &&   (keyCode != 46) && (keyCode != 45)) { // Allow only integers and decimal points, -
		return false
	}
	

	if (str.indexOf(".")>0)
	{
	var str_arry = new Array();
	var str_arry = str.split(".");
	
	
	var str_prec = str_arry[1];
	
	if ( str_prec.length > 2) { //3 decimal
		return false;
	}
	}
	return true
}

  
