function SendQueryValid()
{
	var PatientName=document.SendQueryForm.patient_name;
	var Age=document.SendQueryForm.patient_age;
	var Phone=document.SendQueryForm.phone;
	var emailID=document.SendQueryForm.email;
	var SpecialityId=document.SendQueryForm.speciality;
	var LocationId=document.SendQueryForm.location;
	var InqDet=document.SendQueryForm.inq_det;
	
	var State=document.SendQueryForm.state.value;
	var Country=document.SendQueryForm.country.value;
	
	var name = "#SendYourQueryResultDiv";
	
	if(PatientName.value==""){
		alert("Please Enter Name");
		PatientName.focus();
		return false;
	}
	if(Age.value==""){
		alert("Please Enter Age.");
		Age.focus();
		return false;
	}  
	var checkOK = "0123456789";
	var checkStr = Age.value;
	var allValid = true;
	var allNum = "";
	
	for (i = 0;  i < checkStr.length;  i++)
	{
	   ch = checkStr.charAt(i);
		  for (j = 0;  j < checkOK.length;  j++)
		   if (ch == checkOK.charAt(j))
			 break;
			if (j == checkOK.length)
			{
				  allValid = false;
				  break;	
			}
			if (ch != ",")
			allNum += ch;
	}			   
	if (!allValid)
	{
		 alert("Please enter only digits in the \"Age\" field.");
		 Age.focus();
		 Age.value="";
		 return false;
	} 
	/*if(Age.value.length <10)
	{
		alert("The Age should not be less than 10 digits");
		Age.focus();
		return false;
	}
								  
	if(Age.value.length >10)
	{
		alert("The Phone Number should not be more than 10 digits");
		Age.focus();
		return false;
	}*/
	if(Phone.value=="")
	{
		alert("You must enter the Phone Number");
		Phone.focus();
		return false;
	}
	var checkOK = "0123456789";
	var checkStr = Phone.value;
	var allValid = true;
	var allNum = "";
	
	for (i = 0;  i < checkStr.length;  i++)
	{
	   ch = checkStr.charAt(i);
		  for (j = 0;  j < checkOK.length;  j++)
		   if (ch == checkOK.charAt(j))
			 break;
			if (j == checkOK.length)
			{
				  allValid = false;
				  break;	
			}
			if (ch != ",")
			allNum += ch;
	}			   
	if (!allValid)
	{
		 alert("Please enter only digits in the \"Phone Number\" field.");
		 Phone.focus();
		 Phone.value="";
		 return false;
	}
	
	if(emailID.value=="")
	{
		alert("You must enter current emailid");
		emailID.focus();	
		return false;
	}	
	var checkEmail = "@.";
	var checkStr = emailID.value;
	var EmailValid = false;
	var EmailAt = false;
	var EmailPeriod = false;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkEmail.length;  j++)
		{
			if (ch == checkEmail.charAt(j) && ch == "@")
			EmailAt = true;
			if (ch == checkEmail.charAt(j) && ch == ".")
			EmailPeriod = true;
			if (EmailAt && EmailPeriod)
			break;
			if (j == checkEmail.length)
			break;
		}
		
		if (EmailAt && EmailPeriod)
		{
			EmailValid = true;
			break;
		}
	}
	if (!EmailValid)
	{
		alert("The \"email\" field must contain an \"@\" and \".\".");
		emailID.focus();
		emailID.value="";
		return false;
	}	
	if(SpecialityId.value==""){
		alert("Please select Speciality");
		SpecialityId.focus();
		return false;
	}	
	if(LocationId.value==""){
		alert("Please select Location");
		LocationId.focus();
		return false;
	}	
	if(InqDet.value==""){
		alert("Please Enter Inqiury Details");
		InqDet.focus();
		return false;
	}else
	{
		 $.post("SendYourQuery.php", { PatientName: PatientName.value, Age: Age.value, Phone: Phone.value, emailID: emailID.value, SpecialityId: SpecialityId.value, LocationId: LocationId.value, Country: Country, State: State, Details: InqDet.value},
		  function(data){
			//alert("Data Loaded: " + data);			
			$(name).html(data);
			setTimeout("EmptyFields()", 1000);
			/*if(data==0)
			{
				alert("Data Loaded: " + data);
				alert("Sorry but the email could not be sent. Please try again!");
			}else{
				$(name).html(data);
				alert("Data Loaded: " + data);				
			}*/
		  });
		return false;
	}
	return true;
}

function EmptyFields()
{	
	document.SendQueryForm.patient_name.value="";
	document.SendQueryForm.patient_age.value="";
	document.SendQueryForm.phone.value="";
	document.SendQueryForm.email.value="";
	//document.SendQueryForm.speciality.value="";
	document.SendQueryForm.location.value="";
	document.SendQueryForm.state.value="";
	document.SendQueryForm.country.value="";
	//document.SendQueryForm.appointment_date.value="";	
	document.SendQueryForm.inq_det.value="";
}