	function TrimAll(strData)
		{
			while (strData.substring(0,1) == ' ')
			{
				strData = strData.substring(1, strData.length);
			}
			while (strData.substring(strData.length-1, strData.length) == ' ')
			{
				strData = strData.substring(0,strData.length-1);
			}
			return strData;
	}

	function Alphanumeric(strData)
	{
		for(var j=0; j < strData.length; j++)
		{
			var alphaa = strData.charAt(j);
			var hh = alphaa.charCodeAt(0);
			if ((hh > 47 && hh < 59) || (hh > 64 && hh < 91) || (hh > 96 && hh < 123) || (alphaa==" "))
			{
			}
			else
			{
				return false;
			}
		}
		return true;
	}
	function isIllegalwithNums(field)
	{
		var legalChars = false;
		var aIllegalChars = new Array("=","+","#","~","<",">","/","\\","{","}","[","]","%","!","�","^","&","(",")","-","'","$")
		for (var i=0;i<aIllegalChars.length;i++){
			if (field.value.indexOf(aIllegalChars[i]) != -1){
				legalChars = false;
				break;
				}
			else legalChars = true;	
			}
	
		if (legalChars == true){
			return false;
			}
		else{
			return true;
			}
	}
	
	function checkValidDate(inDay,inMonth,inYear) 
	{
		var noDaysInMonth = DaysInMonth(inMonth.value,inYear.value)
		if (inDay.value > noDaysInMonth) 
		{
			return false;
		}
	}
 

	function DaysInMonth(WhichMonth, WhichYear) 
	{ 
	  var DaysInMonth = 31; 
	  if(WhichMonth.length == 1)
	  {
			WhichMonth = "0"+ WhichMonth;
	  }
	  if (WhichMonth == "04" || WhichMonth == "06" || WhichMonth == "09" || WhichMonth == "11") DaysInMonth = 30; 
	  if (WhichMonth == "02" && (WhichYear/4) != Math.floor(WhichYear/4)) DaysInMonth = 28; 
	  if (WhichMonth == "02" && (WhichYear/4) == Math.floor(WhichYear/4)) DaysInMonth = 29; 
	  return DaysInMonth; 
	}

	
	function SubmitClaimsForm()
	{
		if(Verify())
		{
			document.frmRetrieveQuote.submit();
		}
	}
	
	function Verify()
	{
		var strPolicyNo;
		strPolicyNo = TrimAll(document.frmRetrieveQuote.txtReferenceNumber.value);
		var strPostCode;
		strPostCode = TrimAll(document.frmRetrieveQuote.txtPostCode.value);
		if (strPolicyNo == "")
		{
			alert("Please fill the Quote Reference Number to continue");
			document.frmRetrieveQuote.txtReferenceNumber.focus() ; 
			return false;
		}
			
		if (isIllegalwithNums(document.frmRetrieveQuote.txtReferenceNumber))
		{
		    alert ("Sorry, there appears to be some invalid data in Quote Reference Number, please check your entry. If you have any queries, please contact us.") ;
			document.frmRetrieveQuote.txtReferenceNumber.focus() ; 
			return false;
		}
		
		if (Alphanumeric(strPolicyNo) == false)
		{
			alert ("Sorry, there appears to be some invalid data in Quote Reference Number, please check your entry. If you have any queries, please contact us.") ;
			document.frmRetrieveQuote.txtReferenceNumber.focus() ; 
			return false;
		}
	   if (strPostCode == "")
	   {
			alert ("Please fill the postcode to continue.") ;
			document.frmRetrieveQuote.txtPostCode.focus() ; 
			return false;
			
	   }
		if (isIllegalwithNums(document.frmRetrieveQuote.txtPostCode))
		{
		    alert ("Sorry, there appears to be some invalid data in Postcode, please check your entry. If you have any queries, please contact us.") ;
			document.frmRetrieveQuote.txtPostCode.focus() ; 
			return false;
		}
		
		if (Alphanumeric(strPostCode) == false)
		{
			alert ("Sorry, there appears to be some invalid data in Postcode, please check your entry. If you have any queries, please contact us.") ;
			document.frmRetrieveQuote.txtPostCode.focus() ; 
			return false;
		}
		
		if (document.frmRetrieveQuote.slDOBDay.options[0].selected == true) 
		{	alert ("Please tell us your day of birth");
			document.frmRetrieveQuote.slDOBDay.focus();
			return false;
		}
		
		if (document.frmRetrieveQuote.slDOBMonth.options[0].selected == true) 
		{	alert ("Please tell us your month of birth");
			document.frmRetrieveQuote.slDOBMonth.focus();
			return false;
		}
		
		if (document.frmRetrieveQuote.slDOBYear.options[0].selected == true) 
		{	alert ("Please tell us your year of birth");
			document.frmRetrieveQuote.slDOBYear.focus();
			return false;
		}
		if (checkValidDate(document.frmRetrieveQuote.slDOBDay,document.frmRetrieveQuote.slDOBMonth,document.frmRetrieveQuote.slDOBYear) == false) 
		{
			alert("Please enter a valid date of birth");
			document.frmRetrieveQuote.slDOBDay.focus();
			return false;
		}
		
		// To check whether the client date of birth is above 18 years
		var checkDate =new Date();
		if ((document.frmRetrieveQuote.slDOBYear.selectedIndex==1) && (document.frmRetrieveQuote.slDOBMonth.value > checkDate.getMonth()+1))
		{
				alert ("Your age should be above 18 years");
				document.frmRetrieveQuote.slDOBDay.focus();
				return false;
		}
		else
		{
			if ((document.frmRetrieveQuote.slDOBYear.selectedIndex==1) && (document.frmRetrieveQuote.slDOBMonth.value = checkDate.getMonth()+1) && (document.frmRetrieveQuote.slDOBDay.value>checkDate.getDate()))
			{
					alert ("Your age should be above 18 years");
					document.frmRetrieveQuote.slDOBDay.focus();
					return false;
			}				
		}
			
		return true;
		
	}