function trim()
{
	var a=trim.arguments;
	a[0].value=a[0].value.replace(/(\s*)$/,"");
	a[0].value=a[0].value.replace(/^(\s*)/,"");
}

function fn_chkphone()
{
	var a=fn_chkphone.arguments;
	if(a[0].value.match(/^[\d\s \- \.\( \) \+]{10,20}$/)==null)
	{
		{
		  alert("Please Enter Valid "+a[2]+" Number");
		  return false;
	    }
	}
 return true;
}
function fn_chknum()
{
	var a=fn_chknum.arguments;
	
	if(a[0].value.match(/^[0-9]{5,10}$/)==null)
	{
		{
		  alert("Please Enter Valid "+a[2]+" Number");
		  return false;
	    }
	}
 return true;
}
function fn_chkcurrency()
{
	var a=fn_chkcurrency.arguments;
	if(a[0].value.match(/^[0-9]*\.?\d{1,2}$/)==null)
							
		{
			alert("Please Enter Valid Amount Format");
			return false;
		}
return true;
}
/*function fn_chkphone()
{
 var a=fn_chkphone.arguments;
	 if ((a[0].value.match(/^[0-9]{3}\-[0-9]{3}\-[0-9]{4}$/)==null) && (a[0].value.match(/^[0-9]{3}\x[0-9]{3}\x[0-9]{4}$/)==null) && (a[0].value.match(/^[0-9]{10}$/)==null) )
	   {
		  alert("Please enter valid phone number");
		  return false;
	   }
 return true;
}*/

//Charaters with spaces
function fn_chkchars()
{
 var a=fn_chkchars.arguments;
	 if(a[0].value.match(/^[a-zA-Z\s]*$/)==null)
	  {
		 alert("Please Enter Characters only");
		 return false;
	  }
 return true;
}

//Only charaters
function fn_chkchar()
{
 var a=fn_chkchar.arguments;
	 if(a[0].value.match(/^[a-zA-Z]*$/)==null)
	  {
		 alert("Please Enter Characters only");
		 return false;
	  }
 return true;
}
function fn_chkemail()
{
	 var a=fn_chkemail.arguments;
		  if(a[0].value.match(/^[\w\.=-]+@[\w\.-]+\.[\w\.-]{2,4}$/)==null)
		   {
			alert("Please Enter Valid Email Address");
			return false;
		   }
	 return true;
}

function numbersonly(e)
	{
	var key;
	var keychar;
	
	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
	   return true;
	
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;
	
	// decimal point jump              
	else if (keychar == ".")
	   {
	   //myfield.form.elements[dec].focus();
	   return true;
	   }
	else
	   return false;
	}
function fn_chkdate()
{
	
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year
	a=fn_chkdate.arguments;
	for(i=0; i<(a.length-1); i+=2)
	{
		if ((a[i+1]==0) && (a[i].value.length==0)) return true;

		if ((a[i+1]==1) && (a[i].value.length==0))
		{
			alert("Enter the Date");
			//a[i].focus();
			return false;
		}
		
		var matchArray = a[i].value.match(datePat); // is the format ok?
		if (matchArray == null)
		{
			alert("Date is not in a valid format.")
			//a[i].focus();
			return false;
		}

		month = matchArray[1]; // parse date into variables
		day = matchArray[3];
		year = matchArray[4];

		if (month < 1 || month > 12) 
		{ 
			alert("Month must be between 1 and 12.");
			//a[i].focus();
			return false;
		}

		if (day < 1 || day > 31)
		{
			alert("Day must be between 1 and 31.");
			//a[i].focus();
			return false;
		}

		if ((month==4 || month==6 || month==9 || month==11) && day==31)
		{
			alert("Month "+month+" doesn't have 31 days!")
			//a[i].focus();
			return false;
		}

		if (month == 2) // check for february 29th
		{ 
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day==29 && !isleap))
			{
				alert("February " + year + " doesn't have " + day + " days!");
				//a[i].focus();
				return false;
			 }
		}
	}
	return true;
}