// Form validations
function formValidation() 
{
	FirstName=trim(document.form1.FirstName.value);
	if (FirstName=="")
	{
		alert("Enter first name");
		document.form1.FirstName.focus();		
		return false;
	}
	else
		if(!isText(FirstName))
		{
			alert("Check first name")
			document.form1.FirstName.focus();
			return false;
		}
		
	LastName=trim(document.form1.LastName.value);
	if(LastName!= "")
	{
		if(!isText(LastName))
		{
			alert("Check last name")
			document.form1.LastName.focus();
			return false;
		}	
	}	
		
	City=trim(document.form1.City.value);
	if(isNumeric(City)&& City!="")	
	{		
		alert("Check city")
		document.form1.City.focus()
		return false;
	}
	
	Tel=trim(document.form1.Tel.value);	
	if ((Tel==null)||(Tel==""))
	{
		alert("Enter telephone ")
		document.form1.Tel.focus()
		return false
	}
	if(!(isTelephoneNumber(Tel))&& Tel!="")	
	{		
		alert("Check telephone")
		document.form1.Tel.focus()
		return false;
	}
	
	Mobile=trim(document.form1.Mobile.value);	
	if(!(isTelephoneNumber(Mobile))&& Mobile!="")	
	{		
		alert("Check Mobile")
		document.form1.Mobile.focus()
		return false;
	}
	
	Email=trim(document.form1.Email.value);
	if (Email=="")
	{
		alert("Enter E-mail ");
		document.form1.Email.focus ();
		return false;
	}
	else
	 {
		if(!isMailid(Email))
		{
			document.form1.Email.focus ();
			return false;
		}
	 }
	
	Message=trim(document.form1.Message.value)
	if(isNumeric(Message)&& Message!="")	
	{		
		alert("Check message")
		document.form1.Message.focus()
		return false;
	}	 	
	document.form1.submit();
	return true;
}		

// Reset the form
function resetForm()
{
	document.form1.reset();			
}

// If the String is text or not
function isText(str)
{
	var i=0;
	while(i<str.length)
	{
		if (str.charAt(i)>='0' && str.charAt(i)<= '9')
			return false;
		i++;
	}
	return true;
}

// If the Phone no is numeric or not excpt somr characters
function isTelephoneNumber(str)
{
	var i=0;
	
	if ((str.charAt(0)=='+') || (str.charAt(i)>='0' && str.charAt(i)<= '9') ) i=1;
	else
		return false;
	while(i<str.length)
	{
		if ((str.charAt(i)>='0' && str.charAt(i)<= '9') || str.charAt(i)==' ' || str.charAt(i)=='-')
			i++;
		else	
			return false;
	}
	return true;
}

// If the Phone no is numeric or not
function isNumeric(str)
{
	var i=0;
	while(i<str.length)
	{
		if (!(str.charAt(i)>='0' && str.charAt(i)<= '9' || str.charAt(i)==' '))
			return false;
		i++;
	}
	return true;
}

// Remove the empty spaces
function trim(String)
{
   if (String == null)
   {   
   	return ("");
   }
   return String.replace(/(^\s+)|(\s+$)/g,"");
}

// Check the E-Mail Id
function isMailid(str) 
{
	var emailPat = /^[\w-\.]+\@[\w\.-]+\.[a-z]{2,4}$/;
	var matchArray = str.match(emailPat);
	if (matchArray == null)
	{
		alert("Invalid E-mail");
		return false;
	}
	return true;
}