﻿// JScript File
function onDigittxtkeypress(source)
{
var e = window.event;
var code;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
var character = String.fromCharCode(code);
if(source.style.backgroundColor == "#fcffff")//negative float
    if(e.keyCode==45)
        if(source.value != '')
            e.keyCode = 0;
        else;
    else
    {
        var str = source.value;
        if(str.charCodeAt(0)==45)
            if(str.length>1)
                str = str.substring(1, str.length - 1);
            else
                str = "";
        else;
        if(!isValidFloat(str+character))
            e.keyCode = 0;
        else;
    }
else if(source.style.backgroundColor == "#fdffff")//negative correct
    if(e.keyCode==45)
        if(source.value != '')
            e.keyCode = 0;
        else;
    else if(code<48||code>57)
            e.keyCode = 0;
    else;
else if(source.style.backgroundColor == "#feffff")//positive float
    if(!isValidFloat(source.value+character))
        e.keyCode = 0;
    else;
else//positive correct
    if(code<48||code>57)
        e.keyCode = 0;
    else; 
}

function Round(x,y)
{
return Math.round(x*Math.pow(10, y))/Math.pow(10,y);
}

function isValidFloat(a)
{
	var dotCount = 0;
	for(i=0;i<a.length;i++)
	{
	
		if(a.charCodeAt(i)==46)
			dotCount = dotCount + 1;
		if(dotCount == 2)
	        return false;
		if((a.charCodeAt(i)<48||a.charCodeAt(i)>57)&&a.charCodeAt(i)!=46)
			return false;
	}
	return true;
}
