function check(form1)
{
//---------------------------------------------------Validate Company Name.
	/*var formCompany=form1.company.value;*/
	var ValidNameChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz- .";
	/*if(form1.company.value=="")
	{
		alert("Please enter your company name.");
		form1.company.focus();

		return false;
	}
 	 if (!ValidChars(formCompany, ValidNameChars))
 	 {
	    alert("Your Company Name is not valid! Please check.");
	    form1.company.focus();
		 form1.company.select();	
	    return false;
	 }*/
//---------------------------------------------------Validation for Company ends here.

//---------------------------------------------------Validate Contact Person Name
	var formCPerson=form1.name.value;
	if(form1.name.value=="")
	{
		alert("Please enter your name.");
		form1.name.focus();
		return false;
	}
	if (!ValidChars(formCPerson, ValidNameChars))
	{
		alert("This is an invalid name.");
		form1.name.select();	
		form1.name.focus();
		return false;
	}

//---------------------------------------------------Validation of Contact Person Name ends here.
  
//---------------------------------------------------Validation of Optional Designation

//---------------------------------------------------Validation of Optional Designation ends here.


//---------------------------------------------------Validation of E-mail
  var FormEmail = form1.email.value
  ValidEmailChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_@.";

  if (!ValidLength(FormEmail.length, 5))
  {
    alert ("Please enter your valid email address.");
    form1.email.focus();
    return false;
  }
   
  dot = FormEmail.indexOf(".");
  afterdot = FormEmail.charAt(dot +1);
  if (dot == -1 || afterdot == "") 
  {
    alert("Invalid email address.");
    form1.email.focus();
    return false;
  }

  at = FormEmail.indexOf("@");
  afterat = FormEmail.charAt(at +1);
  if (at == -1 || afterat == "")
  {
    alert("Invalid email address.");
    form1.email.focus();
    return false;
  }
  
  if (!ValidChars(FormEmail, ValidEmailChars))
  {
    alert("Invalid email address.");
    form1.email.focus();
    return false;
  }
//---------------------------------------------------Validation of E-mail ends here

	if(form1.phone.value=="")
	{
		alert("Please enter your phone number.");
		form1.phone.focus();
		return false;
	}
	
	if(isChennaiPhoneNumber(form1.phone.value)==false)
	{
	alert("Invalid phone number.");
	form1.phone.select();
	form1.phone.focus();
	return false;
	}//valid US Phone Number

	/*if(form1.fax.value=="")
	{
		alert("Please enter your Fax number.");
		form1.fax.focus();
		return false;
	}*/
	
	if(form1.fax.value.length>0)
	if(isfaxNumber(form1.fax.value)==false)
	{
	alert("Invalid fax number");
	form1.fax.select();
	form1.fax.focus();
	return false;
	}//valid 

	/*if(form1.mobile.value=="")
	{
		alert("Please enter your Mobile number.");
		form1.mobile.focus();
		return false;
	}*/
	
	if(form1.mobile.value.length>0)
	if(isfaxNumber(form1.mobile.value)==false)
	{
	alert("Invalid mobile number");
	form1.mobile.select();
	form1.mobile.focus();
	return false;
	}//valid US Phone Number

	

	
	

	if(form1.details.value=="")
	{
		alert("Please enter your details.");
		form1.details.focus();
		return false;
	}

	
	/*if(isAns(form1.details.value) == false)
	{
		alert("Invalid Details.");
		form1.details.select();
		form1.details.focus();
		return false;
	}//valid name*/
alert("Thank you for your enquiry.");
return true;
}//end check
//---------------------------------------------------This is my addition to the existing bit of code
function ValidChars(CheckStr,chars)
{
  for (i = 0;  i < CheckStr.length;  i++)
  {
    ch = CheckStr.charAt(i);
    for (j = 0;  j < chars.length;  j++)
      if (ch == chars.charAt(j))
        break;
      if (j == chars.length)
        return false;
  }
  return true;
} 

function ValidLength(str,number)
{
  if (str < number)
    return false;
  return true;
}
//---------------------------------------------------Ends here for now!
function isAlphabetic (s)
{ 
	var i;
	if(s.length==0)
	return false;
	for (i = 0; i < s.length; i++)
	{   
		var c = s.charAt(i);
		if (!isLetter(c))
		{
			s.value= " ";
			return false;
		}
	}
// All characters are letters.
return true;
}

function isLetter (c) //user id use
{ 
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isAnsDigit(c)
{
	var as=escape(c);
	var pa="%0D";
	var pb="%0A";
	
	if((as==pa)||(as==pb))
		return true;
	else
		return ((c.search(/^\d/)!=-1) || (c =="'") || (c ==".") || (c =="#")|| (c =="(")|| (c ==")")|| (c ==" :")|| (c ==";")|| (c =="/")|| (c ==" ")) 
}

function isAns(string)
{
	for (var i = 0; i < string.length; i++)
	{
		if ((!isAnsDigit(string.charAt(i))) && (!isLetter(string.charAt(i))))
		return false;
	}
	
return true;
}

function isDigit(c)// user id use
{
return ((c.search(/^\d/)!=-1) || (c =="_")) 
}

function isEmail(string) 
{
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
		return false;
}


function isEmailNext(string) 
{
	var c='.';
	var pos; 
	pos=string.indexOf(c);
	if(string.length > (pos + 2))
	return true;
	else
	return false;
}
function isChennaiPhoneNumber(string)
{
	var phoneNumberDelimiters = "()- ";
	var returnString = "";
	for (var i = 0; i < string.length; i++)
	{   
		var c = string.charAt(i);
		if (phoneNumberDelimiters.indexOf(c)==-1)
		returnString += c;
	}
	if(returnString.length<=4)
	return false;
	for (var j = 0; j < returnString.length; j++)
	{
		if (!isphDigit(returnString.charAt(j)))
		return false;
	}
  
return true;
}
function isphDigit(c)
{
//	alert("is digit");
	return ((c.search(/^\d/)!=-1) || (c =="-") || (c =="(") || (c ==")") ) 
//return (c.search(/^\d/)!=-1 ) 
}
function isfaxNumber(string)
{
	var phoneNumberDelimiters = "()- ";
	var returnString = "";
	for (var i = 0; i < string.length; i++)
	{   
		var c = string.charAt(i);
		if (phoneNumberDelimiters.indexOf(c)==-1)
		returnString += c;
	}
	
	for (var j = 0; j < returnString.length; j++)
	{
		if (!isphDigit(returnString.charAt(j)))
		return false;
	}
  
return true;
}


