function ValidateQuoteRequest()
{
		var message = "";
		  
		// we always want to validate life 1 anyway
		if(Trim(document.getElementById("form1").name1.value)   =="")
		{
			message += "You must fill in your forename\n";
		}
		  
		if(Trim(document.getElementById("form1").surname1.value)   =="")
		{
			message += "You must fill in your surname\n";
		}
		  
		if(Trim(document.getElementById("form1").day1.value)   =="")
		{
			message += "You must fill in your day of birth\n";
		}
		  
		if(Trim(document.getElementById("form1").month1.value)   =="")
		{
			message += "You must fill in your month of birth\n";
		}
		  
		if(Trim(document.getElementById("form1").year1.value)   =="")
		{
			message += "You must fill in your year of birth\n";
		}
		
		if(Len(document.getElementById("form1").year1.value) > 2)
		{
			message += "For year of birth please fill in last 2 digits eg: if 1976 please fill in 76\n";
		}
		
		if(!ValidateDates(document.getElementById("form1").day1.value, document.getElementById("form1").month1.value, document.getElementById("form1").year1.value ))
		{
			message += "The date of birth  you filled in was not valid\n";
		}
		
		if(validateRadioButton(document.getElementById("form1").sex1)  == null)
		{
			message += "You must specify your sex\n";
		}		  
		
		if(validateRadioButton(document.getElementById("form1").smoker1) == null)
		{
			message += "You must specify if you are a smoker or not\n";
		}
		
		if(Trim(document.getElementById("form1").term.value)   =="")
		{
		    message += "You must specify a term\n";
		}
		
		if(document.getElementById("form1").term.value < 10)
		{
			message += "The minimum term is 10 years.\n";
		}
		
		if(Trim(document.getElementById("form1").amount1.value)   =="")
		{
			message += "You must fill in an amount\n";
		}
		
		if(!IsNumeric(Trim(document.getElementById("form1").amount1.value)))
		{
			message += "Please fill in a numeric amount (no commas or decimals)\n";
		}
		
		if(Trim(document.getElementById("form1").amount1.value)   < 1000)
		{
			message += "The minimum amount for a quote is EUR 1,000\n";
		}
		
		if(!emailCheck(document.getElementById("form1").email1.value))
		{
			message += "You have not entered a valid email address\n";
		}
		
		if(Trim(document.getElementById("form1").emailalternative.value) != "")
		{
			if(!emailCheck(document.getElementById("form1").emailalternative.value))
			{
				message += "You have not entered a valid alternative email address\n";
			}
		}				    
		    
		// validate person 2
		if(Trim(document.getElementById("form1").Lives.value) != "Single")
		{
				if(Trim(document.getElementById("form1").name2.value)   =="")
				{
					message += "You must fill in forename of the second person\n";
				}
				  
				if(Trim(document.getElementById("form1").surname2.value)   =="")
				{
					message += "You must fill in the surname of the second person\n";
				}
				  
				if(Trim(document.getElementById("form1").day2.value)   =="")
				{
					message += "You must fill in the day of birth for the second person\n";
				}
				  
				if(Trim(document.getElementById("form1").month2.value)   =="")
				{
					message += "You must fill in the month of birth for the second person\n";
				}
				  
				if(Trim(document.getElementById("form1").year2.value)  =="")
				{
					message += "You must fill in the year of birth for the second person\n";
				}
				
				if(Len(document.getElementById("form1").year2.value) > 2)
				{
					message += "For year of birth for the second person please fill in last 2 digits eg: if 1976 please fill in 76\n";
				}
				
				if(!ValidateDates(document.getElementById("form1").day2.value, document.getElementById("form1").month2.value, document.getElementById("form1").year2.value ))
				{
					message += "The date of birth  you filled in for the second person was not valid\n";
				}
				
				if(validateRadioButton(document.getElementById("form1").sex2) == null)
				{
					message += "You must specify the sex of the second person\n";
				}		  
				
				if(validateRadioButton(document.getElementById("form1").smoker2)  == null)
				{
					message += "You must specify if the second person is a smoker or not\n";
				}
		}
		
			
		// only for dual
		if(Trim(document.getElementById("form1").Lives.value) == "Dual")
		{
			if(Trim(document.getElementById("form1").amount2.value)   =="")
			{
				message += "You must fill in a second amount\n";
			}
			
			if(Trim(document.getElementById("form1").amount2.value)   < 1000)
			{
				message += "The minimum amount for the second amount to get a quote is EUR 1,000\n";
			}
			
			if(!IsNumeric(Trim(document.getElementById("form1").amount2.value)))
			{
					message += "Please fill in a numeric amount for the second amount\n";
			}
		}
		
		
		//lastly make sure they check the "i have read the terms" stuff
		if(!document.getElementById("form1").chkterms.checked)
		{
			message += "You must agree to the terms and conditions before you can continue\n";
		}
		
		if(message=="")
		{
			ChangeCSSToDisplayForLogin();
			return true;
			//document.getElementById("form1").submit();
		}
		else
		{
			alert("Your request could not be processed for the following reasons: \n\n" + message);
			return false;
		}
}

		// check to make sure all fields are entered and that the values entered are valid
		function ValidateDates(day, month, year)
		{
		
			 if(!IsNumeric(Trim(day)) || !IsNumeric(Trim(month)) || !IsNumeric(Trim(year)))
			 {
				return false;
			 }
			 
			 // check start date
			 if ((month > 12) || (month < 1))
			 {
			   return false;
			 }
			 else if ((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) && (day > 31 || day < 1)) 
			 {
			   return false;
			 }
			 else if ((month == 4 || month == 6 || month == 9 || month == 11) && (day > 30 || day < 1)) 
			 {
				return false;
			 }
			 else if (LeapYear(year) && (month == 2) && (day < 1 || day > 29))
			 {
				return false;
			 }
			 else if ((LeapYear(year) == false) && (month == 2) && (day < 1 || day > 28))
			 {
				return false;
			 }
			 			 
			 return true;			

		}//end function


		 // check is it a leap year
		 function LeapYear(intYear) 
		{
			if (intYear % 100 == 0) 
			{
				if (intYear % 400 == 0) 
				{ 
				  return true; 
				}
			}
			else 
			{
				if ((intYear % 4) == 0) 
				{ 
				  return true; 
				}
			}
				return false;
		}
		
		
		function Trim(str)
		{
			//return str.replace(/^\s*(.*\S|.*)\s*$/, '$1');
			return str.replace(/^\s*|\s*$/g,"");
		}
		
		
		function Len(str)
        {  
			return String(str).length;  
		}
				
		//  check for valid numeric strings	
		function IsNumeric(strString)
		{
		   var strValidChars = '0123456789';
		   var strChar;
		   var blnResult = true;

		   if (strString.length == 0) return false;

		   //  test strString consists of valid characters listed above
		   for (i = 0; i < strString.length && blnResult == true; i++)
		   {
			  strChar = strString.charAt(i);
			  if (strValidChars.indexOf(strChar) == -1)
			  {
				 blnResult = false;
			  }
			}
			
			return blnResult;
		}
		
		
		function IsNumericWithDecimals(strString)
		{
		   var strValidChars = '0123456789.';
		   var strChar;
		   var blnResult = true;

		   if (strString.length == 0) return false;

		   //  test strString consists of valid characters listed above
		   for (i = 0; i < strString.length && blnResult == true; i++)
		   {
			  strChar = strString.charAt(i);
			  if (strValidChars.indexOf(strChar) == -1)
			  {
				 blnResult = false;
			  }
			}
			
			return blnResult;
		}
		
		function validateRadioButton(btn) 
		{
			var cnt = -1;
			for (var i=btn.length-1; i > -1; i--) 
			{
				if (btn[i].checked) {cnt = i; i = -1;}
			}
			if (cnt > -1) return btn[cnt].value;
			else return null;
		}
		
		
		function emailCheck (emailStr) 
		{

			/* The following variable tells the rest of the function whether or not
			to verify that the address ends in a two-letter country or well-known
			TLD.  1 means check it, 0 means don't. */

			var checkTLD=1;

			/* The following is the list of known TLDs that an e-mail address must end with. */

			var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

			/* The following pattern is used to check if the entered e-mail address
			fits the user@domain format.  It also is used to separate the username
			from the domain. */

			var emailPat=/^(.+)@(.+)$/;

			/* The following string represents the pattern for matching all special
			characters.  We don't want to allow special characters in the address. 
			These characters include ( ) < > @ , ; : \ " . [ ] */

			var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

			/* The following string represents the range of characters allowed in a 
			username or domainname.  It really states which chars aren't allowed.*/

			var validChars="\[^\\s" + specialChars + "\]";

			/* The following pattern applies if the "user" is a quoted string (in
			which case, there are no rules about which characters are allowed
			and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
			is a legal e-mail address. */

			var quotedUser="(\"[^\"]*\")";

			/* The following pattern applies for domains that are IP addresses,
			rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
			e-mail address. NOTE: The square brackets are required. */

			var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

			/* The following string represents an atom (basically a series of non-special characters.) */

			var atom=validChars + '+';

			/* The following string represents one word in the typical username.
			For example, in john.doe@somewhere.com, john and doe are words.
			Basically, a word is either an atom or quoted string. */

			var word="(" + atom + "|" + quotedUser + ")";

			// The following pattern describes the structure of the user

			var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

			/* The following pattern describes the structure of a normal symbolic
			domain, as opposed to ipDomainPat, shown above. */

			var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

			/* Finally, let's start trying to figure out if the supplied address is valid. */

			/* Begin with the coarse pattern to simply break up user@domain into
			different pieces that are easy to analyze. */

			var matchArray=emailStr.match(emailPat);

			if (matchArray==null) {

			/* Too many/few @'s or something; basically, this address doesn't
			even fit the general mould of a valid e-mail address. */

			return false;
			}
			var user=matchArray[1];
			var domain=matchArray[2];

			// Start by checking that only basic ASCII characters are in the strings (0-127).

			for (i=0; i<user.length; i++) {
			if (user.charCodeAt(i)>127) {
			return false;
			}
			}
			for (i=0; i<domain.length; i++) {
			if (domain.charCodeAt(i)>127) {
			return false;
			}
			}

			// See if "user" is valid 

			if (user.match(userPat)==null) {

			// user is not valid

			return false;
			}

			/* if the e-mail address is at an IP address (as opposed to a symbolic
			host name) make sure the IP address is valid. */

			var IPArray=domain.match(ipDomainPat);
			if (IPArray!=null) {

			// this is an IP address

			for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
			return false;
			}
			}
			return true;
			}

			// Domain is symbolic name.  Check if it's valid.
			 
			var atomPat=new RegExp("^" + atom + "$");
			var domArr=domain.split(".");
			var len=domArr.length;
			for (i=0;i<len;i++) {
			if (domArr[i].search(atomPat)==-1) {
			return false;
			}
			}

			/* domain name seems valid, but now make sure that it ends in a
			known top-level domain (like com, edu, gov) or a two-letter word,
			representing country (uk, nl), and that there's a hostname preceding 
			the domain or country. */

			if (checkTLD && domArr[domArr.length-1].length!=2 && 
			domArr[domArr.length-1].search(knownDomsPat)==-1) {
			return false;
			}

			// Make sure there's a host name preceding the domain.

			if (len<2) {
			return false;
			}

			// If we've gotten this far, everything's valid!
			return true;
			}






	function ChangeCSSToDisplayForLogin()
	{
		var el = document.getElementById("divPleaseWait");		
		
		if (el != null)
		{
			el.style.display = 'inline'; 	
		
			//initialize the image - this only works but is only needed in IE
			// the onload of webquotes checks the user agents and sorts mozilla out
			//document.images['wait'].src = "http://www.labrokers.ie/includes/images/labrokers_insurers.gif";

			img = new Image();
			img.src = "http://www.labrokers.ie/includes/images/labrokers_insurers.gif";
			img.onload = function() {document.images.wait.src = img.src};
		}		
	}
	
	function ValidatePaymentStage1()
	{
	   
		var message = "";
		if(Trim(document.getElementById("form1").name.value)   =="")
		{
			message += "You must fill in your name\n";
		}
		
		if(Trim(document.getElementById("form1").email.value)   =="")
		{
			message += "You must fill in your email address\n";
		}
		
		if(!emailCheck(document.getElementById("form1").email.value))
		{
			message += "You have not entered a valid email address\n";
		}
				
		if(Trim(document.getElementById("form1").amount.value)   =="")
		{
			message += "You must fill in the amount.\n";
		}
		
		if(!IsNumericWithDecimals(Trim(document.getElementById("form1").amount.value)))
		{
			message += "You have not filled in a valid amount.\n";
		}
		
		if(!document.getElementById("form1").chkProceed.checked)
		{
			message += "You must verify that you wish to continue by checking the checkbox.\n";
		}
					
		if(message=="")
		{
			// Replace ampersand in a field value with another char cos the "&" breaks Realex.
			replaceAmp(document.getElementById("form1").name);
			replaceAmp(document.getElementById("form1").reference);
			replaceAmp(document.getElementById("form1").message);
			return true;
		}
		else
		{
			alert("You cannot move on to stage 2 of the make a payment process for the following reasons: \n\n" + message);
			return false;
		}
	}
	
	
	
	// Replace ampersand in a field value with another char cos the "&" breaks Realex.
	function replaceAmp(el){
		var re = new RegExp;
		re = /&/gi;
		el.value = el.value.replace(re,'+');
	}

