<!--
function Validate()
{
	 // Declaring required variables
	var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()- ";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 8;
	
	function isInteger(s)
	{
		var i;
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		// All characters are numbers.
		return true;
	}
	
	function stripCharsInBag(s, bag)
	{
		var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in bag, append to returnString.
		for (i = 0; i < s.length; i++){   
			var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}
	
	function checkInternationalPhone(strPhone)
	{
		s=stripCharsInBag(strPhone,validWorldPhoneChars);
		return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
	}	
	
	//------------------- Sender firstname -------------------
	if ( document.frmEmail.firstname.value == ""  )
	   {if (!(PrintMesg(document.frmEmail.firstname,"Please enter First Name.")))
	   {return false;}}
	 else  { 
	   if (!SpaceChk(document.frmEmail.firstname))
		{if (!(PrintMesg(document.frmEmail.firstname,"Please enter First Name other than space")))
		{return false;}}
	}
	//------------------- Sender lastname -------------------
	if ( document.frmEmail.lastname.value == ""  )
	   {if (!(PrintMesg(document.frmEmail.lastname,"Please enter Last Name.")))
	   {return false;}}
	 else  { 
	   if (!SpaceChk(document.frmEmail.lastname))
		{if (!(PrintMesg(document.frmEmail.lastname,"Please enter the Last Name other than space")))
		{return false;}}
	}


	//-------------------- phone1----------
	phone1 = document.frmEmail.phone1.value
 	if (phone1  == "")
    {if (!(PrintMesg(document.frmEmail.phone1,"Please enter The Phone No (business hour)")))
	{return false;}}
		
	if (checkInternationalPhone(phone1)==false)
	{
		alert("Please Enter a Valid Phone Number (business hour). Eg. 0242223333");
		phone1="";
		document.frmEmail.phone1.focus();
		return false;
	}
	
	//-------------------- phone2----------
	/*phone2 = document.frmEmail.phone2.value
 	if (phone2  == "")
    {if (!(PrintMesg(document.frmEmail.phone2,"Please enter The Phone No (after hour)")))
	{return false;}}
		
	if (checkInternationalPhone(phone2)==false)
	{
		alert("Please Enter a Valid Phone Number (after hour)");
		phone2="";
		document.frmEmail.phone2.focus();
		return false;
	}
	*/
	//-------------------- email----------
	mail = document.frmEmail.email.value
	if (mail  == "")
	{
		if (!(PrintMesg(document.frmEmail.email,"Please enter From Email address")))
		{	return false;	}
	}
	else { 
		n = mail.indexOf("@")
	   	if (n >= 0)
	   	{ 
			newstr = mail.substring(n)
		 	n= newstr.indexOf(".")
		 	if (n<0)
			{
				if (!(PrintMesg(document.frmEmail.email,"Enter a valid E-mail Address")))
				{	return false;	}
			}
	   	} 
	   	else
		{
			if (!(PrintMesg(document.frmEmail.email,"Enter a valid E-mail Address")))
			{	return false;	}
		}
	}
	
	//---------Address
	/*if ( document.frmEmail.address.value == ""  )
	   {if (!(PrintMesg(document.frmEmail.address,"Please enter Address.")))
	   {return false;}}
	 else  { 
	   if (!SpaceChk(document.frmEmail.address))
		{if (!(PrintMesg(document.frmEmail.address,"Please enter the Address other than space")))
		{return false;}}
	}*/

	//------------------Message -------------------
	if ( document.frmEmail.message.value == ""  )
	   {if (!(PrintMesg(document.frmEmail.message,"Please enter  Message.")))
	   {return false;}}
	 else  { 
	   if (!SpaceChk(document.frmEmail.message))
		{if (!(PrintMesg(document.frmEmail.message,"Please enter the  Message other than space")))
		{return false;}}
	}

	//--------------------------------------
	return true;
}

//prints messages
function PrintMesg(ctrlvar,mesg)
{ alert(mesg); ctrlvar.focus(); return false }

// function to check spaces
function SpaceChk(ctrlvar)
{
   chkstr     = ctrlvar.value
   stlength   = chkstr.length
   spacecount = 0
   if (stlength >0)  {
    for(i=0;i<=stlength;i++)
     if ( chkstr.charAt(i)==" ") { spacecount=spacecount+1  }
    if (stlength == spacecount) { return false }
   return true }
}
//-->
