
function trim(s) {
	//remove leading spaces and tab
    while ((s.substring(0, 1) == ' ') || (s.substring(0, 1) == '\t')) {
        s = s.substring(1, s.length);
    }
	// remove trailing spaces and tab
    while ((s.substring(s.length - 1, s.length) == ' ') || (s.substring(s.length - 1, s.length) == '\t')) {
    	alert("I am here");
        s = s.substring(0, s.length - 1);
    }
    return s;
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789.";
   	var IsNumber=true;
   	var Char;
 
   	for (i = 0; i < sText.length && IsNumber == true; i++) 
    { 
      	Char = sText.charAt(i); 
      	if (ValidChars.indexOf(Char) == -1) 
        {
         	IsNumber = false;
        }
    }
   	return IsNumber;  
}

function checkClusterParams(form) {
	with(form) {
    	var m_threshold = trim(threshold.value);
    	if (!IsNumeric(m_threshold)) {
        	alert("Please input an invalid value for threshold!");
        	threshold.focus(true);
        	return false;
    	}

    	var m_radius = trim(radius.value);
    	if (!IsNumeric(m_radius)) {
        	alert("Please input an invalid value for radius!");
        	radius.focus(true);
        	return false;
    	}
	}
	return true;
}

