/*
This function is used to trim all leading and trailing spaces in a string.
This function takes a string as input and returns the trimmed string.
At present this function uses substr() method, on the assumption that 
first argument to substr() will never be negative and 
second argument will never be greater than str.length
*/
function trim(str){
	var start= str.length, end = 0, ch, i;
	for(i=0;i<str.length;i++) {
		ch = str.charAt(i);
		if(ch !=' '){
			start = i;
			break;
		}
	}
	for(i=str.length-1;i>=0;i--) {
		ch = str.charAt(i);
		if(ch !=' '){
			end = i;
			break;
		}
	}
	if (start<=end)
		return str.substr(start,end-start+1);
	else
		return "";
}
