function ltrim(str)
{	
	var temp = str;	
	try
	{	
		for(i=0;i<temp.length;i++)
		{
			if(temp.charAt(0) == ' ')
				temp = temp.substring(1);
			else
				break;
		}	
	}
	catch(e){}	
	return temp;	
}

function rtrim(str)
{
	var temp = str;
	try
	{	
		for(i=temp.length-1;i>=0;i--)
		{
			if(temp.charAt(i) == ' ')
				temp = temp.substring(0,i);
			else
				break;
		}	
	}
	catch(e){}	
	return temp;
}

function trim(str)
{
	try
	{
		str = ltrim(str);
		str = rtrim(str);
	}
	catch(e){}
	return str;
}

function validateform(str)
{	
	var sstr = str.split(',')
	var i,j,tstr,errorStr
	errorStr=""
	for (i=0;i<sstr.length;i=i+3)
	{
		var s = eval("document.forms[0]." + sstr[i] + ".value")
		if ((sstr[i+2]=="R" || sstr[i+2]=="RE") && s=="")		
			errorStr = errorStr + "\n" + sstr[i + 1] + " is Required."		
		else if(sstr[i+2]=="RN"  && parseInt(s)==0)		
			errorStr = errorStr + "\n" + sstr[i + 1] + " is Required."
		else if((sstr[i+2]=="E" || sstr[i+2]=="RE") && s!='')
			if (!checkEmail(s))
					errorStr = errorStr + "\n" + sstr[i + 1] + " is not a valid Email Address."				
	}
	if (errorStr!="")
	{
		alert("Please check the following errors :" + errorStr)
		return false
	}
	else
		return true;
}

function checkEmail(strng)
{
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) 
		return false;
	var illegalChars= /[\(\)\<\>\?\,\;\:\\\/\"\[\]\*\+\-\&\%\!\#\$\^\=]/		
	if (strng.match(illegalChars)) 
		return false;
	else
		return true;
}

