function check_service(selectedservice)
{
	//alert(selectedservice);
	if (selectedservice=='servicetochoose')
		document.appointment.pct_chosen.style.visibility='hidden';
	else 
		document.appointment.pct_chosen.style.visibility='inherit';
	document.appointment.pct_chosen.length=0;
	document.appointment.pct_chosen.options[0]= new Option('Your Practitioner',0);
}

function myfixselection()
{
	var rem=0;
	for (var i = 1; i <=document.appointment.pct_chosen.length; i++) 
	{ 
		
  		if (document.appointment.pct_chosen.options[i].value == "") 
	 	{
				if (rem==0)
					rem=i;
			
	 			for (var j=i; j < document.appointment.pct_chosen.length; j++)
     			{
					if (document.appointment.pct_chosen.options[j].value != "")
					{
						document.appointment.pct_chosen.options[i]= new Option(document.appointment.pct_chosen.options[j].text,document.appointment.pct_chosen.options[j].value);
						document.appointment.pct_chosen.options[j]=new Option("","");
						//document.appointment.pct_chosen.length=document.appointment.pct_chosen.length-1;
						j=document.appointment.pct_chosen.length;
						rem++;
						//alert(document.appointment.pct_chosen.length);
					}
				}
   		}
		//else
			//rem--;
	}
	if (rem==0)
	{
		rem=2;
		//alert(rem);
	}
	//alert(rem);
	document.appointment.pct_chosen.length=rem;
}
/*function select_practitioner(service_id)
{
	if(service_id==1)
	{
		document.appointment.pct_chosen.options[1]= new Option('Mahnaz',1);
	}
	else
	{
		document.appointment.pct_chosen.length=1;
		//document.appointment.pct_chosen.options[1]= new Option();
	}
}*/

function check_submission()
{
	var message="Please fix the following problems and resubmit the form.  \n*******************************************************          \n\n\n";
	var checker=0;
	hourvalidation();
	servicevalidation();
	pracvalidation();
	function hourvalidation()
	{
		if (document.appointment.hour.value=="")
		{
			message +="Probably you are trying to make an appointmen on Sunday, We are closed on Sunday. Please have your appointment on some other day\n";
			return false;
		}
	}
	function servicevalidation()
	{
		if(document.appointment.service_chosen.selectedIndex==0 || document.appointment.service_chosen.selectedIndex=='')//=="servicetochoose")
		{
			message +="Please choose a service before you make an appointment. Then choose your favourite practitioner\n";
			checker=1;
			return false;
		}
	}
	function pracvalidation()
	{
		//if (servicevalidation())
		//{
		
			if (document.appointment.pct_chosen.selectedIndex==0 || document.appointment.pct_chosen.selectedIndex=='' )
			{
				message +="Please pick your favourite practitioner for your selected service.";
				var browserName=navigator.appName;
				if (browserName!="Microsoft Internet Explorer")
				{
					message +="\n\nNote: If you are using Netscape internet browser, please try using Internet explorer.Thank you.";
				}
				return false;
			}
		//}
	
	}
	
	if (message=="Please fix the following problems and resubmit the form.  \n*******************************************************          \n\n\n")
	{return true;	}//document.appointment.submit();
	
	else
	{
		alert (message);
		return false;
	}


}









function formvalidate()
{
	var message="You didn't enter the following highlighted fields properly. Please fill in          \n*******************************************************          \n\n\n";
	
	fnamevalidation();
	lnamevalidation();
	addressvalidation();
	cityvalidation();
	pcodevalidation();
	emailvalidation();
	phonevalidation();
	passwordvalidation();

	function fnamevalidation()
	{
		//document.formenquiry.fname.style.borderColor="";
		document.formenquiry.fname.style.backgroundColor="white";
		var checkit= /^[A-Z,a-z]{2,}/;
		if (checkit.test(document.formenquiry.fname.value))
		{
			document.formenquiry.fname.value=document.formenquiry.fname.value.toUpperCase();
			return (true);
		}
		else
		{
			//document.formenquiry.fname.style.borderColor="red";
			document.formenquiry.fname.style.backgroundColor="wheat";
			message +="Invalid First name (Must be 2 or more characters only)\n";
			return false;
		}
	}
	function lnamevalidation()
	{
		//document.formenquiry.lname.style.borderColor="";
		document.formenquiry.lname.style.backgroundColor="white";
		var checkit= /^[A-Z,a-z]{2,}/;
		if (checkit.test(document.formenquiry.lname.value))
		{
			document.formenquiry.lname.value=document.formenquiry.lname.value.toUpperCase();
			return (true);
		}
		else
		{
			//document.formenquiry.lname.style.borderColor="red";
			document.formenquiry.lname.style.backgroundColor="wheat";
			message +="\nInvalid Last name (Must be 2 or more characters only. Without spaces.)\n";
			return false;
		}
	}
	function addressvalidation()
	{
		//document.formenquiry.address.style.borderColor="";
		document.formenquiry.address.style.backgroundColor="white";
		
		if (document.formenquiry.address.value.length >= 4)
		{
			document.formenquiry.address.value=document.formenquiry.address.value.toUpperCase();
			return (true);
		}
		else
		{
			//document.formenquiry.address.style.borderColor="red";
			document.formenquiry.address.style.backgroundColor="wheat";
			message +="\nInvalid Address (Must be 4 or more characters or digits)\n";
			return false;
		}
	}
	function cityvalidation()
	{
		//document.formenquiry.city.style.borderColor="";
		document.formenquiry.city.style.backgroundColor="white";
		
		if (document.formenquiry.city.value.length >= 4)
		{
			document.formenquiry.city.value=document.formenquiry.city.value.toUpperCase();
			return (true);
		}
		else
		{
			//document.formenquiry.city.style.borderColor="red";
			document.formenquiry.city.style.backgroundColor="wheat";
			message +="\nInvalid City name (Must be 4 or more characters only)\n";
			return false;
		}
	}
	function pcodevalidation()
	{
		//document.formenquiry.pcode.style.borderColor="";
		document.formenquiry.pcode.style.backgroundColor="white";
		var checkit= /^[A-Z,a-z][0-9][A-Z,a-z][0-9][A-Z,a-z][0-9]/;
		if (checkit.test(document.formenquiry.pcode.value))
		{
			document.formenquiry.pcode.value=document.formenquiry.pcode.value.toUpperCase();
			return (true);
		}
		else
		{
			//document.formenquiry.pcode.style.borderColor="red";
			document.formenquiry.pcode.style.backgroundColor="wheat";
			message +="\nInvalid Postal Code (Must be in the right format)\n";
			return false;
		}
	}
	function emailvalidation()
	{
		//document.formenquiry.email.style.borderColor="";	
		document.formenquiry.email.style.backgroundColor="white";
		var checkit;
		checkit=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})$/;


		if (checkit.test(document.formenquiry.email.value))
		{
			document.formenquiry.email.value=document.formenquiry.email.value.toLowerCase();
			return (true);
		}
			else
			{
				//document.formenquiry.email.style.borderColor="red";	
				document.formenquiry.email.style.backgroundColor="wheat";
				message +="\nInvalid Email address (Must be in the right format)\n";
				return false;
			}
	}
	function phonevalidation()
	{
		//document.formenquiry.phone.style.borderColor="";
		document.formenquiry.phone.style.backgroundColor="white";
		/*if (document.formenquiry.phone.value=="" || document.formenquiry.phone.value=="Optional")
		{
			return (true);
		}
		else
		{*/
			var checkit= /^[0-9]{3}[-]?[0-9]{3}[-]?[0-9]{4}/;
			if (checkit.test(document.formenquiry.phone.value) && document.formenquiry.phone.value.length>9)
			{
				return (true);
			}
			else
			{
				//document.formenquiry.phone.style.borderColor="red";
				document.formenquiry.phone.style.backgroundColor="wheat";

				message +="\nInvalid Phone no (Must be 10 digits only)\n";
				return false;
			}
		//}
	}
	function passwordvalidation()
	{
		//document.formenquiry.phone.style.borderColor="";
		document.formenquiry.password.style.backgroundColor="white";
		if (document.formenquiry.password.value.length < 6)
		{
			//document.formenquiry.enquiry.style.borderColor="red";
			document.formenquiry.password.style.backgroundColor="wheat";
			message +="\nPassword must be 6 to 15 characters long.";
			return false;
		}
	}
	if (message=="You didn't enter the following highlighted fields properly. Please fill in          \n*******************************************************          \n\n\n")
	document.formenquiry.submit();
	//return true;	
	else
	{
		alert (message);
		return false;
	}

}
function again()
{
	document.formenquiry.email.style.backgroundColor="white";
	document.formenquiry.fname.style.backgroundColor="white";
	document.formenquiry.lname.style.backgroundColor="white";
	document.formenquiry.address.style.backgroundColor="white";
	document.formenquiry.city.style.backgroundColor="white";
	document.formenquiry.pcode.style.backgroundColor="white";
	document.formenquiry.phone.style.backgroundColor="white";
	document.formenquiry.password.style.backgroundColor="white";
}