// JavaScript Document
function trimLeft(s)
{
 var i;
 i=0;
 var n;
 n = s.length;
 while((i<n)&&(s.charAt(i)==' ')) i++;
	s = s.substring(i);
 return(s);
} 

/*
 trimRight
 Remove all spaces at the end of a string
*/
function trimRight(s)
{
 var n;
 n = s.length;
 var i;
 i = s.length-1;
 while((i>=0)&&(s.charAt(i)==' ')) i--;
	s = s.substring(0,i+1);
 return(s);
}

/* 
 trim
 Remove all leading and trailing spaces in a string
*/
function trim(s)
{
 s = trimLeft(s);
 s = trimRight(s);
 return(s);
}  


function checknumber(str)
{
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (anum.test(str))
		testresult=true
	else{
		alert("Please input a valid number!")
		testresult=false
	}
	return (testresult)
}

/////////////////////////////////
function check_form1()
{
	var action = trim(document.getElementById("action1").value);
	var amount = trim(document.getElementById("action1").value);
	if(action == "")
	{
			alert("Please type the action");
			document.getElementById("action1").focus();
			return false;
	}
	if(amount == "")
	{
			alert("Please type the amount");
			document.getElementById("amount1").focus();
			return false;
	}
	else
	{
		return checknumber(amount);
	}
	return true;
}
function check_form2()
{
	var action = trim(document.getElementById("action2").value);
	var amount = trim(document.getElementById("action2").value);
	if(action == "")
	{
			alert("Please type the action");
			document.getElementById("action2").focus();
			return false;
	}
	if(amount == "")
	{
			alert("Please type the amount");
			document.getElementById("amount2").focus();
			return false;
	}
	
	return true;
}
