// JavaScript Document

function valEnq()
	{
		
		if(document.getElementById('strFirstName').value=="")
					{
						alert("Please enter your first name")
						document.getElementById('strFirstName').focus()
						return false
					}
					
				if(document.getElementById('strLastName').value=="")
					{
						alert("Please enter your last name")
						document.getElementById('strLastName').focus()
						return false
					}
					
				var emailPat=/^(.+)@(.+)$/
				var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
				var validChars="\[^\\s" + specialChars + "\]"
				var quotedUser="(\"[^\"]*\")"
				var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
				var atom=validChars + '+'
				var word="(" + atom + "|" + quotedUser + ")"
				var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
				var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
				var matchArray=document.getElementById('strEmail').value.match(emailPat)
				if (matchArray==null) {
					alert("Email address is invalid(check @ and .'s)")
					document.getElementById('strEmail').focus()
					return false
				}
				var user=matchArray[1]
				var domain=matchArray[2]
				if (user.match(userPat)==null) {
					alert("Email address is invalid, Please correct.")
					document.getElementById('strEmail').focus()
					return false
				}
				var IPArray=domain.match(ipDomainPat)
				if (IPArray!=null) {
					  for (var i=1;i<=4;i++) {
						if (IPArray[i]>255) {
							alert("Email address is invalid, Please correct.!")
						document.getElementById('strEmail').focus()
						return false
						}
					}
				}
				var domainArray=domain.match(domainPat)
				if (domainArray==null) {
					alert("Email address is invalid, Please correct..")
					document.getElementById('strEmail').focus()
					return false
				}
				var atomPat=new RegExp(atom,"g")
				var domArr=domain.match(atomPat)
				var len=domArr.length
				if (domArr[domArr.length-1].length<2 || 
					domArr[domArr.length-1].length>3) {
				   alert("Email address is invalid, Please correct.")
				   document.getElementById('strEmail').focus()
				   return false
				}
				if (len<2) 
					{
					   var errStr="Email address is invalid, Please correct!"
					   alert(errStr)
					   document.getElementById('strEmail').focus()
					   return false	
				   }
			
				if(document.getElementById('strTelephone').value=="")
					{
						alert("Please enter your contact  telephone")
						document.getElementById('strTelephone').focus()
						return false
					}
				
				var intCards=document.getElementById('intCards');
				var intBalance=document.getElementById('intBalance');
				var strFees=document.getElementById('strFees');
				var strPaymentProtect=document.getElementById('strPaymentProtect');
				var intArreas=document.getElementById('intArreas');
				var strIncome=document.getElementById('strIncome');
				var strMortgage=document.getElementById('strMortgage');
				
				if(intCards.options[intCards.selectedIndex].value=="")
					{
						alert("Please the number of credit cards/ Loans taken out before 6th April 2007")
						intCards.focus
						return false
					}
				if(intBalance.options[intBalance.selectedIndex].value=="")
					{
						alert("Please select how many of your credit cards/ Loans taken out before 6th April 2007 have an outstanding balance of between £5,000-£25,000 ")
						intBalance.focus
						return false
					}
					
				if(strFees.options[strFees.selectedIndex].value=="")
					{
						alert("Please tell us if you have ever been charged a fee for a late payment or exceeding your credit limit on any of your credit cards/loans taken out before 6th April 2007")
						strFees.focus
						return false
					}
				if(strPaymentProtect.options[strPaymentProtect.selectedIndex].value=="")
					{
						alert("Please tell us if you have Payment Protection Insurance on any of your credit cards/loans taken out before 6th April 2007")
						strPaymentProtect.focus
						return false
					}
					
				if(intArreas.options[intArreas.selectedIndex].value=="")
					{
						alert("Please tell us many months are you in arrears with your repayments on any of your credit cards/loans taken out before 6th April 2007")
						intArreas.focus
						return false
					}
					
				if(strIncome.options[strIncome.selectedIndex].value=="")
					{
						alert("Please tell us your current source of income")
						strIncome.focus
						return false
					}
					
				if(strMortgage.options[strMortgage.selectedIndex].value=="")
					{
						alert("Please tell us if you have a mortgage")
						strMortgage.focus
						return false
					}
					
	}
	
	
	function valContact()
	{
		if(document.getElementById('strName').value=="")
			{
				alert("Please enter your name")
				document.getElementById('strName').focus()
				return false;
			}
		var emailPat=/^(.+)@(.+)$/
				var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
				var validChars="\[^\\s" + specialChars + "\]"
				var quotedUser="(\"[^\"]*\")"
				var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
				var atom=validChars + '+'
				var word="(" + atom + "|" + quotedUser + ")"
				var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
				var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
				var matchArray=document.getElementById('strEmail').value.match(emailPat)
				if (matchArray==null) {
					alert("Email address is invalid(check @ and .'s)")
					document.getElementById('strEmail').focus()
					return false
				}
				var user=matchArray[1]
				var domain=matchArray[2]
				if (user.match(userPat)==null) {
					alert("Email address is invalid, Please correct.")
					document.getElementById('strEmail').focus()
					return false
				}
				var IPArray=domain.match(ipDomainPat)
				if (IPArray!=null) {
					  for (var i=1;i<=4;i++) {
						if (IPArray[i]>255) {
							alert("Email address is invalid, Please correct.!")
						document.getElementById('strEmail').focus()
						return false
						}
					}
				}
				var domainArray=domain.match(domainPat)
				if (domainArray==null) {
					alert("Email address is invalid, Please correct..")
					document.getElementById('strEmail').focus()
					return false
				}
				var atomPat=new RegExp(atom,"g")
				var domArr=domain.match(atomPat)
				var len=domArr.length
				if (domArr[domArr.length-1].length<2 || 
					domArr[domArr.length-1].length>3) {
				   alert("Email address is invalid, Please correct.")
				   document.getElementById('strEmail').focus()
				   return false
				}
				if (len<2) 
					{
					   var errStr="Email address is invalid, Please correct!"
					   alert(errStr)
					   document.getElementById('strEmail').focus()
					   return false	
				   }
			
				if(document.getElementById('strTelephone').value=="")
					{
						alert("Please enter your contact  telephone")
						document.getElementById('strTelephone').focus()
						return false
					}
					
				var strEnq=document.getElementById('strEnquiry');
				if(strEnq.value=="")
					{
						alert("Please enter your enquiry")
						strEnq.focus()
						return false
					}
				
				//if(strEnq.value.length < 3)
				//	{
				//		alert("Your enquiry details are too short, please re-enter your enquiry with more details")
				//		strEnq.focus()
				//		return false
				//	}
	}
	
	
	function valInfoReq()
	{
		if(document.getElementById('strFirstName').value=="" || document.getElementById('strFirstName').value=="First Name")
					{
						alert("Please enter your first name")
						document.getElementById('strFirstName').focus()
						return false
					}
					
				if(document.getElementById('strLastName').value=="" || document.getElementById('strLastName').value=="Surname")
					{
						alert("Please enter your last name")
						document.getElementById('strLastName').focus()
						return false
					}
					
				var emailPat=/^(.+)@(.+)$/
				var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
				var validChars="\[^\\s" + specialChars + "\]"
				var quotedUser="(\"[^\"]*\")"
				var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
				var atom=validChars + '+'
				var word="(" + atom + "|" + quotedUser + ")"
				var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
				var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
				var matchArray=document.getElementById('strEmail').value.match(emailPat)
				if (matchArray==null) {
					alert("Email address is invalid(check @ and .'s)")
					document.getElementById('strEmail').focus()
					return false
				}
				var user=matchArray[1]
				var domain=matchArray[2]
				if (user.match(userPat)==null) {
					alert("Email address is invalid, Please correct.")
					document.getElementById('strEmail').focus()
					return false
				}
				var IPArray=domain.match(ipDomainPat)
				if (IPArray!=null) {
					  for (var i=1;i<=4;i++) {
						if (IPArray[i]>255) {
							alert("Email address is invalid, Please correct.!")
						document.getElementById('strEmail').focus()
						return false
						}
					}
				}
				var domainArray=domain.match(domainPat)
				if (domainArray==null) {
					alert("Email address is invalid, Please correct..")
					document.getElementById('strEmail').focus()
					return false
				}
				var atomPat=new RegExp(atom,"g")
				var domArr=domain.match(atomPat)
				var len=domArr.length
				if (domArr[domArr.length-1].length<2 || 
					domArr[domArr.length-1].length>3) {
				   alert("Email address is invalid, Please correct.")
				   document.getElementById('strEmail').focus()
				   return false
				}
				if (len<2) 
					{
					   var errStr="Email address is invalid, Please correct!"
					   alert(errStr)
					   document.getElementById('strEmail').focus()
					   return false	
				   }
			
				if(document.getElementById('strTelephone').value=="" || document.getElementById('strTelephone').value=="Contact number")
					{
						alert("Please enter your contact  telephone")
						document.getElementById('strTelephone').focus()
						return false
					}
	}
	
	
	function valReferal()
	{
	
		if(document.getElementById('strName').value=="")
			{
				alert("Please enter your name")
				document.getElementById('strName').focus()
				return false;
			}
			
		var emailPat=/^(.+)@(.+)$/
				var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
				var validChars="\[^\\s" + specialChars + "\]"
				var quotedUser="(\"[^\"]*\")"
				var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
				var atom=validChars + '+'
				var word="(" + atom + "|" + quotedUser + ")"
				var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
				var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
				var matchArray=document.getElementById('strEmail').value.match(emailPat)
				if (matchArray==null) {
					alert("Email address is invalid(check @ and .'s)")
					document.getElementById('strEmail').focus()
					return false
				}
				var user=matchArray[1]
				var domain=matchArray[2]
				if (user.match(userPat)==null) {
					alert("Email address is invalid, Please correct.")
					document.getElementById('strEmail').focus()
					return false
				}
				var IPArray=domain.match(ipDomainPat)
				if (IPArray!=null) {
					  for (var i=1;i<=4;i++) {
						if (IPArray[i]>255) {
							alert("Email address is invalid, Please correct.!")
						document.getElementById('strEmail').focus()
						return false
						}
					}
				}
				var domainArray=domain.match(domainPat)
				if (domainArray==null) {
					alert("Email address is invalid, Please correct..")
					document.getElementById('strEmail').focus()
					return false
				}
				var atomPat=new RegExp(atom,"g")
				var domArr=domain.match(atomPat)
				var len=domArr.length
				if (domArr[domArr.length-1].length<2 || 
					domArr[domArr.length-1].length>3) {
				   alert("Email address is invalid, Please correct.")
				   document.getElementById('strEmail').focus()
				   return false
				}
				if (len<2) 
					{
					   var errStr="Email address is invalid, Please correct!"
					   alert(errStr)
					   document.getElementById('strEmail').focus()
					   return false	
				   }
				   
				if(document.getElementById('strTelephone').value=="" || document.getElementById('strTelephone').value=="Contact number")
					{
						alert("Please enter your contact  telephone")
						document.getElementById('strTelephone').focus()
						return false
					}
					
				if(document.getElementById('strHouseNo').value=="")
				{
					alert("Please enter your House/Building No/Name")
					document.getElementById('strHouseNo').focus()
					return false;
				}
				
				if(document.getElementById('strStreet').value=="")
				{
					alert("Please enter your Street/Road name")
					document.getElementById('strStreet').focus()
					return false;
				}
				
				if(document.getElementById('strTown').value=="")
				{
					alert("Please enter your Town/City")
					document.getElementById('strTown').focus()
					return false;
				}
				
				if(document.getElementById('strCounty').value=="")
				{
					alert("Please enter your County")
					document.getElementById('strCounty').focus()
					return false;
				}
				
				if(document.getElementById('strPostcode').value=="")
				{
					alert("Please enter your Postcode")
					document.getElementById('strPostcode').focus()
					return false;
				}
				
				if(document.getElementById('strFriendName').value=="" && document.getElementById('strFriendName_1').value=="" && document.getElementById('strFriendName_2').value=="" && document.getElementById('strFriendName_3').value=="")
				{
					
						alert("You must enter the details the person you wish to refer")
						document.getElementById('strFriendName').focus()
						return false;
				}
				
				
		
	}