// JavaScript Document
//Validate appointment form and submit it
function subform(counter)
{//alert(counter);
	var found
		found=0
		
		for (var j=1; j<(counter+1);j++)
		{
			box = eval("document.form1.doctor_" + j); 
			//alert("j="+j+"found="+found+box.checked);
			if (box.checked == true)
			{ 
				found=1;
			}
		}
	
	if (found==0)
	{
		alert("Please select a doctor");
	}
	else if (document.form1.fname.value.length == 0)
			{
				document.form1.fname.focus();
				alert("Please enter 'First name' field");
			}
		else if (document.form1.fname.value.indexOf(" ") == 0)
			{
				document.form1.fname.focus();
				alert("Please correct 'First name' field");
			}
		else if (document.form1.lname.value.length == 0)
			{
				document.form1.lname.focus();
				alert("Please enter 'Last name' field");
			}
		else if (document.form1.lname.value.indexOf(" ") == 0)
			{
				document.form1.lname.focus();
				alert("Please correct 'Last name' field");
			}
		else if (document.form1.dob_01.value.length == 0)
			{
				document.form1.dob_01.focus();
				alert("Please select 'Month'");
			}
 		else if (document.form1.dob_01.value.indexOf("Month") == 0)
			{
				document.form1.dob_01.focus();
				alert("Please select 'Day'");
			}
			else if (document.form1.dob_02.value.length == 0)
			{
				document.form1.dob_02.focus();
				alert("Please select 'Day'");
			}
			else if (document.form1.dob_02.value.indexOf("Month") == 0)
			{
				document.form1.dob_02.focus();
				alert("Please select 'Month'");
			}
				else if (document.form1.dob_03.value.indexOf("Year") == 0)
			{
				document.form1.dob_03.focus();
				alert("Please select 'Year'");
			}
			else if (document.form1.dob_03.value.length == 0)
			{
				document.form1.dob_03.focus();
				alert("Please select 'Year'");
			}
			else if (document.form1.day_phone_1.value.length == 0 || document.form1.day_phone_2.value.length == 0 || document.form1.day_phone_3.value.length == 0)
			{
				document.form1.day_phone_1.focus();
				alert("Please enter 'Day Phone' field");
			}
		else if (document.form1.day_phone_1.value.indexOf(" ") == 0 || document.form1.day_phone_2.value.indexOf(" ") == 0 || document.form1.day_phone_3.value.indexOf(" ") == 0)
			{
				document.form1.day_phone_1.focus();
				alert("Please correct ' Day Phone' field");
			}
			else if (document.form1.evening_phone_1.value.length == 0 || document.form1.evening_phone_2.value.length == 0 || document.form1.evening_phone_3.value.length == 0)
			{
				document.form1.evening_phone_1.focus();
				alert("Please enter 'Evening Phone' field");
			}
		else if (document.form1.evening_phone_1.value.indexOf(" ") == 0 || document.form1.evening_phone_2.value.indexOf(" ") == 0 || document.form1.evening_phone_3.value.indexOf(" ") == 0)
			{
				document.form1.evening_phone_1.focus();
				alert("Please correct 'Evening Phone' field");
			}
 	else if (document.form1.contact.value.length == 0)
			{
				document.form1.contact.focus();
				alert("Please enter 'Contact name' field");
			}
		else if (document.form1.contact.value.indexOf(" ") == 0)
			{
				document.form1.contact.focus();
				alert("Please correct 'Contact name' field");
			}
			else if (document.form1.contact_phone_1.value.indexOf(" ") == 0 || document.form1.contact_phone_2.value.indexOf(" ") == 0 || document.form1.contact_phone_3.value.indexOf(" ") == 0)
			{
				document.form1.contact_phone_1.focus();
				alert("Please correct 'Contact Phone' field");
			}
			else if (document.form1.contact_phone_1.value.length == 0 || document.form1.contact_phone_2.value.length == 0 || document.form1.contact_phone_3.value.length == 0)
			{
				document.form1.contact_phone_1.focus();
				alert("Please enter 'Contact Phone' field");
			}
	else if (document.form1.email.value.length == 0)
			{
				document.form1.email.focus();
				alert("Please enter 'Email' field");
			}
		else if (document.form1.email.value.indexOf(" ") == 0)
			{
				document.form1.email.focus();
				alert("Please correct 'Email' field");

			}
		else if (document.form1.email.value.indexOf("@") == -1)
		    {
				document.form1.email.focus();
				alert("Please 'correct email address' field");
			}
		else
			{//check radio button
			option1 = -1; 
			for (i=0; i < form1.gender.length; i++) 
			{ 
			if (form1.gender[i].checked) 
				{ 
				option1 = i; 
				} 
			} 
			if (option1 == -1) 
				{ 
				alert("Please select 'Gender'"); 
				
				} 
				else 
				{ 
							option1 = -1; 
			for (i=0; i < form1.time_to_call.length; i++) 
			{ 
			if (form1.time_to_call[i].checked) 
				{ 
				option1 = i; 
				} 
			} 
			if (option1 == -1) 
				{ 
				alert("Please select 'Best time to call'"); 
				
				} 
				else 
				{ 
				
				document.form1.submit();
				}
				//document.form1.submit();
				}
				
			}
	}
function noenter()
{
	return !(window.event && window.event.keyCode == 13);
}

function updateForm(FormName)
{
	var TheForm = FormName
	if (document.form1.fname.value.length == 0)
			{
				document.form1.fname.focus();
				alert("Please enter 'First name' field");
			}
		else if (document.form1.fname.value.indexOf(" ") == 0)
			{
				document.form1.fname.focus();
				alert("Please correct 'First name' field");
			}
		else if (document.form1.lname.value.length == 0)
			{
				document.form1.lname.focus();
				alert("Please enter 'Last name' field");
			}
		else if (document.form1.lname.value.indexOf(" ") == 0)
			{
				document.form1.lname.focus();
				alert("Please correct 'Last name' field");
			}
		else if (document.form1.day_phone_1.value.length == 0 || document.form1.day_phone_2.value.length == 0 || document.form1.day_phone_3.value.length == 0)
			{
				document.form1.day_phone_1.focus();
				alert("Please enter 'Day Phone' field");
			}
		else if (document.form1.day_phone_1.value.indexOf(" ") == 0 || document.form1.day_phone_2.value.indexOf(" ") == 0 || document.form1.day_phone_3.value.indexOf(" ") == 0)
			{
				document.form1.day_phone_1.focus();
				alert("Please correct ' Day Phone' field");
			}
		else{
		if (TheForm.sameas[0].checked)
		{
			TheForm.contact.value = TheForm.fname.value + " " + TheForm.lname.value;
			TheForm.contact_phone_1.value = TheForm.day_phone_1.value;
			TheForm.contact_phone_2.value = TheForm.day_phone_2.value;
			TheForm.contact_phone_3.value = TheForm.day_phone_3.value;
			} 
		if (TheForm.sameas[1].checked)
		{
			TheForm.contact.value = "";
			TheForm.contact_phone_1.value = "";
			TheForm.contact_phone_2.value = "";
			TheForm.contact_phone_3.value = "";
			}
		}
return;
}