function formatcurrency(st) {
	st += "";
	var theValue = st;
	var finalString = '';

	if(theValue.length < 4) {
		finalString = theValue;
	}
	else {
		if(theValue.indexOf(".")==-1) {
			theValueEx = "";
		}
		else {
			temp = theValue.split(",");
			theValue=temp[0];
			theValueEx= "." + temp[1];
		}
		var modulus = theValue.length % 3
		var count = 0
		finalString = theValue.substring(0, modulus)
		if((modulus != 0)&&(theValue.length>3)) finalString += ','
		for(i = modulus; i < theValue.length; i++) {
			if(count == 3){ 
				finalString += ',';
				count = 0;
			}
			finalString += theValue.charAt(i);
			count++;
		}
		finalString = finalString + theValueEx;
	}
	
	return finalString;
}

function parseCurrency(st) {
	var creg=/,/gi;
	mystring = new String(st);
	var results = mystring.replace(creg,"");
	return results;
}

function checknumeric(st) {
	if(event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;
	if(event.keyCode == 46) {
		temp = st.indexOf(".");
		if(temp>-1) event.returnValue = false;
	}
	if(event.keyCode == 45) event.returnValue = false;
	if(event.keyCode == 47) event.returnValue = false;
}

function checkinteger(st) {
	if(event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;
}

function checkformatmoney(stform) {
	if((event.keyCode != 37) && (event.keyCode != 39) && (event.keyCode != 9)){
		var results = stform.value;
		results = parseCurrency(results);
		results = formatcurrency(results);
		stform.value = results;
	};
}
