function validateNumber(val) {
	
    var reg = new RegExp("^[0-9]+(\\.[0-9]{0,2})?$");
    if (!reg.test(val)){
        return false;
	}
    return true;
}

function isNumberValid(evt, comp )
{

    var charCode = (evt.which) ? evt.which : event.keyCode;
	if(charCode == 8 ) return true;
	
	// Initialise the variables
	var startPos = comp.selectionStart;
	var endPos = comp.selectionEnd;
	
	if(comp.selectionStart){
		// FF & Chrome
		startPos = comp.selectionStart;
		endPos = comp.selectionEnd;
	}
	else if(document.selection){
		// IE
		comp.focus();
		var sel = document.selection.createRange();
        var selLen = document.selection.createRange().text.length;
        sel.moveStart('character', -comp.value.length);
        startPos =  sel.text.length - selLen;
		endPos = startPos;
	}
	
	var currentVal = comp.value ;
	var newVal;
	if(startPos == endPos && endPos == currentVal.length){
		newVal = currentVal + String.fromCharCode(charCode);
	}
	else{
		newVal = currentVal.substring(0,startPos) + String.fromCharCode(charCode) + currentVal.substring(endPos);
	}
	
	
	if(!validateNumber(newVal)){
		return false;
	}
    return true;
}

function setFocus(){
}

var isWhole_re       = /^\s*\d+\s*$/;
function validatePositiveInteger(val) {
	return String(val).search (isWhole_re) != -1
}

function isPositiveInteger(evt, comp )
{

    var charCode = (evt.which) ? evt.which : event.keyCode;
	if(charCode == 8 ) return true;
	
	// Initialise the variables
	var startPos = comp.selectionStart;
	var endPos = comp.selectionEnd;
	
	if(comp.selectionStart){
		// FF & Chrome
		startPos = comp.selectionStart;
		endPos = comp.selectionEnd;
	}
	else if(document.selection){
		// IE
		comp.focus();
		var sel = document.selection.createRange();
        var selLen = document.selection.createRange().text.length;
        sel.moveStart('character', -comp.value.length);
        startPos =  sel.text.length - selLen;
		endPos = startPos;
	}
	
	var currentVal = comp.value ;
	var newVal;
	if(startPos == endPos && endPos == currentVal.length){
		newVal = currentVal + String.fromCharCode(charCode);
	}
	else{
		newVal = currentVal.substring(0,startPos) + String.fromCharCode(charCode) + currentVal.substring(endPos);
	}
	
	
	if(!validatePositiveInteger(newVal)){
		return false;
	}
    return true;
}
