// ==================================================================
// - - - - - - - - - - - - D I S C L A I M E R - - - - - - - - - - -
// By accepting this software ("Software"), you ("Customer") agree that
// use of the Software is subject to the following terms and
// conditions:
//
// (i)  the Software is supplied on a strict "AS IS" basis, without
//      warranty of any kind or nature.  DCJ CONSULTING DISCLAIMS ANY
//      AND ALL EXPRESS OR IMPLIED WARRANTIES RELATIVE TO THE SOFTWARE,
//      INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTY OF
//      MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, and
//
// (ii) in no event shall DCJ Consulting be liable to Customer for
//      any damages, whether direct, indirect, special, incidental,
//      consequential or punitive, which in any way arise out of or
//      relate to the Software, and
//
// (iii)DCJ Consulting shall not provide support of any kind for the
//      Software. DCJ Consulting retains title to all portions of the
//      Software and any copies thereof.
//
// Assistance with tailoring/customizing this code can be purchased on
// a time and materials basis from DCJ Consulting.
//
// (c) Copyright DCJ Consulting 2002. All rights reserved.
// ==================================================================
// Written: 2002/04/24 by D.C. Jones, per DCJ Consulting
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Modified: yyyy/mm/dd by ??
// Purpose: ??
// ==================================================================


//Name		:	formValidate
//Programmer:	Dave Jones
//Company	:	DCJ Consulting
//Input		:	Form object upon which to operate
//Output	:	Boolean value indicating whether the function
//				succeeded in its task
//Purpose	:	Ensures that required values are entered prior to
//				submitting the form to LinkPoint
function formValidate(form)
{
	if (form.name.value != "")
	{
		if (form.clinic_name.value != "")
		{
			if (form.address1.value != "")
			{
				if (form.city.value != "")
				{
					if (form.country.value != "")
					{
						if (form.country.value == "US")
						{
							if (form.state.value != "")
							{
								if (form.zip.value != "")
								{
									if (isUSPhoneNumber(stripCharsInBag(form.telephone.value, phoneNumberDelimiters)))
									{
										if (isUSPhoneNumber(stripCharsInBag(form.facsimile.value, phoneNumberDelimiters), true))
										{
											//do nothing
	 									}
	 									else
	 									{
	 										alert("Please enter a valid fax number or leave it blank.");
	 										form.facsimile.focus();
	 										form.facsimile.select();
	 										return false;
	 									}	//end if international fax
	 								}
	 								else
	 								{
	 									alert("Please enter a valid phone number.");
	 									form.telephone.focus();
	 									form.telephone.select();
	 									return false;
	 								}	//end if international phone
								}
								else
								{
									alert("Please enter a valid zip code.");
									form.zip.focus();
									form.zip.select();
									return false;
								}	//end if zip code
							}
							else
							{
									alert("Please enter a valid state.");
									form.state.focus();
									return false;
 							}	//end if state
						}
						else	//if international country
						{
 							if (form.provence.value != "")
 							{
								if (form.zip.value != "")
								{
	 								if (isInternationalPhoneNumber(stripCharsInBag(form.telephone.value, phoneNumberDelimiters)))
	 								{
	 									if (isInternationalPhoneNumber(stripCharsInBag(form.facsimile.value, phoneNumberDelimiters), true))
	 									{
											//do nothing
	 									}
	 									else
	 									{
	 										alert("Please enter a valid fax number or leave it blank.");
	 										form.facsimile.focus();
	 										form.facsimile.select();
	 										return false;
	 									}	//end if international fax
	 								}
	 								else
	 								{
	 									alert("Please enter a valid phone number.");
	 									form.telephone.focus();
	 									form.telephone.select();
	 									return false;
	 								}	//end if international phone
								}
								else
								{
									alert("Please enter a valid postal code or a dash (-) if you do not have one.");
									form.zip.focus();
									form.zip.select();
									return false;
								}	//end if zip code
							}
							else
							{
									alert("Please enter a valid provence.");
									form.provence.focus();
									form.provence.select();
									return false;
 							}	//end if provence
						}	//end if country = "US" or international
						if (checkEmail(form.e_mail, false))
						{
							//if (form.web_addr.value != "")
							//{
								if (form.howheard.value != "")
								{
									form.telephone.value = reformatUSPhone(stripCharsInBag(form.telephone.value, phoneNumberDelimiters))

									if (stripCharsInBag(form.facsimile.value, phoneNumberDelimiters) != "")
									{
										form.facsimile.value = reformatUSPhone(stripCharsInBag(form.facsimile.value, phoneNumberDelimiters))
									}	//end if fax not blank
									
									return true;
								}
								else
								{
									alert("Please tell us how you heard about us.");
									form.howheard.focus();
									form.howheard.select();
									return false;
								}	//end if how heard
							//}
							//else
							//{
							//	alert("Please enter your web site address or a dash (-) if you do not have a web site.");
							//	form.web_addr.focus();
							//	form.web_addr.select();
							//	return false;
							//}	//end if web_addr
						}
						else
						{
							form.e_mail.focus();
							form.e_mail.select();
							return false;
						}	//end if e_mail
					}
					else
					{
						alert("Please enter your country.");
						form.country.focus()
						return false;
					}	//end if country not blank
				}
				else
				{
					alert("Please enter your city.");
					form.city.focus();
					form.city.select();
					return false;
				}	//end if city
			}
			else
			{
				alert("Please enter your street address.");
				form.address1.focus();
				form.address1.select();
				return false;
			}	//end if address
		}
		else
		{
			alert("Please enter your clinic's name.");
			form.clinic_name.focus();
			form.clinic_name.select();
			return false;
		}	//end if clinic
	}
	else
	{
		alert("Please enter the doctor's name.");
		form.name.focus();
		form.name.select();
		return false;
	}	//end if name
}	//end formValidate(form)

