/*-----------------------------------------------------------------------
Created by: PP
Created date:10th March 2006
File description: Contact Us
Special instructions-notes:Java script Validation
Tables used:None
Stored procedures:None
Triggers used:None
-----------------------------------------------------------------------*/

function Validate(theForm)
{
	var errMesg = "";
	var displayMesg = "";
	var Q = ""; // this block determines lifespan of Q
	{
	if (isWhitespace(theForm.first_name.value))
		{
			Q += "  First Name\n";
		}
	else if(!isCharsInBag( theForm.first_name.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' "))
		{
		errMesg += "First Name contains Invalid Characters\n";
		}
	if(theForm.last_name)
		{
	if (isWhitespace(theForm.last_name.value))
		{
			Q += "  Last Name\n";
		}
	else if(!isCharsInBag( theForm.last_name.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' "))
		{
		errMesg += "Last Name contains Invalid Characters\n";
		}
		}
	if (isWhitespace(theForm.company.value))
		{
			Q += "  Company\n";
		}
	if (isWhitespace(theForm.email.value))
		{
			Q += "  E-mail\n";
		}
	else if(echeck(theForm.email.value))
		{
		   errMesg += "Invalid Email Address\n";
		}	
	else if(!isCharsInBag( theForm.email.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@._-"))
		{
			errMesg += "Email Address contains Invalid Characters\n";
		}
	if (isWhitespace(theForm.phone.value))
		{
			Q += "  Phone\n";
		}
	else if(!isCharsInBag( theForm.phone.value, "1234567890- "))
		{
			errMesg += "Phone contains Invalid Characters\n";
		}

		if(theForm.fax)
		{
	if (theForm.fax.value!="" && !isCharsInBag(theForm.phone.value, "1234567890- "))
		{
			errMesg += "Fax contains Invalid Characters\n";
		}
		}
	if (isWhitespace(theForm.address.value))
		{
			Q += "  Address\n";
		}	
	if(theForm.address.value!="" && theForm.address.value.length>500)
		{
			errMesg += "Address should not be greater than 500 characters\n";
		}
	if (isWhitespace(theForm.city.value))
		{
			Q += "  City\n";
		}	
	if (theForm.country.value==0)
		{
			Q += "  Country\n";
		}

	/*if (theForm.country.value==1 && theForm.state.value=="")
		{
			errMesg += "Please select state\n";
		}*/
	if (isWhitespace(theForm.zipcode.value))
		{
			Q += "  Zip/Postal\n";
		}	
	
	if(theForm.inquiry)
	{
	if (isWhitespace(theForm.inquiry.value))
		{
			Q += "  Inquiry\n";
		}	
	if (isWhitespace(theForm.captcha.value))
		{
			Q += "  Security code\n";
		}	

	if(theForm.inquiry.value!="" && theForm.inquiry.value.length>500)
		{
			errMesg += " Inquiry should not be greater than 500 characters\n";
		}
	}

	if(theForm.password)
	{
		if (isWhitespace(theForm.password.value))
		{
			Q += "  Password\n";
		}

		if (theForm.password.value.length < 5 )
		{
			errMesg += "Password must be at least 5 characters.\n";
		}
	}


	if ( Q.length > 0 )
		{
		displayMesg = "Please provide Valid values for\n" + Q ;
		}
	}
 
	if (errMesg == "" && displayMesg == "")
	{
		return true;
	}
	
	else
	{
	
			if(displayMesg!="")
			{
				alert(displayMesg);
				return false;			
			}
			else
			{
				alert(errMesg);
				return false;
			}	
	}
}

