function ValidatePatientReferral()
{		
	var PatientName = document.getElementById('txtPatientName');
	var Phone = document.getElementById('txtPhone');
	var Date = document.getElementById('txtDate');
	var Dr = document.getElementById('txtDr');
	
	//PatientName
	if(PatientName.value == '')
	{
		alert("Please, enter a valid a patient name.");
		PatientName.focus();
		return false;
	}
	else
	{
        if(!ValidateName(PatientName.value))
		{
			alert("Please check your patient name.");
			PatientName.focus();			
			return false;
		}

		if(!ValidateConsonants(PatientName.value))
		{
			alert("Please check your patient name.");
			PatientName.focus();
			return false;
		}
	}
	
	
	//Phone
	if(!ValidatePhone(Phone.value))
	{
		alert("Please, enter a valid phone number.");
		Phone.focus();
		return false;
	}
	
	
	
	//Date
	var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;	
	
	
	if(!Date.value.match(RegExPattern))
	{
		alert('Please, enter a valid date.');
		Date.focus();
		return false;
	}
	
	
	//Dr.
	if(Dr.value != '')
	{
        if(!ValidateName(Dr.value))
		{
			alert("Please check the Dr name.");
			Dr.focus();			
			return false;
		}

		if(!ValidateConsonants(Dr.value))
		{
			alert("Please check the Dr name.");
			Dr.focus();
			return false;
		}
	}
			
	return true;
}

function ValidatePhone(incoming)
{
	var ValidChars = "0123456789.()- ";
	var IsCorrect=true;
	var Char;

	for (cont = 0; cont < incoming.length && IsCorrect == true; cont++) 
	{ 
		Char = incoming.charAt(cont); 
		if (ValidChars.indexOf(Char) == -1) 
			return false;
	}
	return true;
}

function ValidateConsonants(valor) 
{
       valor = valor.toLowerCase();
	if (/[bcdfghjklmnpqrstvwxyz]{7}/.test(valor))
		return false;
	else
		return true;
}  


function ValidateName(valor) 
{
      	valor = valor.toLowerCase();
	if (/^[a-z ]+$/i.test(valor))
		return true;
	else
		return false;
} 

