function trim(str)
{
	var i=0,p = str.length-1;
	while(str.charAt(i)==' ') i++;
	while(str.charAt(p)==' ') p--;
	if(i>p) return '';
	return str.substring(i,p+1);
}
function checkEmail(strng)
{
	var error = "";
	if (strng == "")
		{
		error = "You did not enter an email-address.\n";
		}
	var emailFilter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	if (!(emailFilter.test(strng))) 
		{ 
		error = "Please enter a valid email address.\n";
		}
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	if(strng.match(illegalChars))
		{
		error = "The email address contains illegal characters.\n";
		}
	return error;
}
function checkalphanumeric(alphane)
{
	var str = alphane;
	for(var j=0; j<str.length; j++)
	{
		var alphaa = str.charAt(j);
		var chrcode = alphaa.charCodeAt(0);
		if((chrcode > 47 && chrcode<59) || (chrcode > 64 && chrcode<91) || (chrcode > 96 && chrcode<123) || chrcode==95)
		{
		}
		else
		{
			return false;
		}
	}
	return true;
}
function checkNumeric(strng,errmsgfield) {
	var error = "";
	var illegalChars = /\D/;
	if (illegalChars.test(strng)) {
	   	error = errmsgfield+" is invalid.\n";
	}
	return error;
}
function checkEmailAddress(emailval) 
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailval)){ return true; }
	return false;
}
function checkDateFormat(strngDate)
{
	/* This function will check the date format is (dd/mm/yyyy). If format is not this then it will show error message*/
	// regular expression to match required date format
    
	
	var error = "";
	if (strngDate == "")
	{
		error = "You did not enter date.\n";
	}
	var re = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
	if(!strngDate.match(re))
	{
		error += "The date format is not accepted. Please use the format (dd/mm/yyyy)\n";
	}
    if(strngDate != '')
	{
		if(regs = strngDate.match(re)) 
		{
			if(regs[1] < 1 || regs[1] > 31) 
			{
			  error += "Invalid value for day: " + regs[1] + ".\r\n";
			}
			if(regs[2] < 1 || regs[2] > 12) 
			{
			  error += "Invalid value for month: " + regs[2] + ".\r\n";
			}
			if(regs[3] < 1902 || regs[3] > (new Date()).getFullYear()) 
			{
			  error += "Invalid value for year: " + regs[3] + " - must be between 1902 and " + (new Date()).getFullYear() + ".\r\n";
			}
		} 
    }
	return error;
}