// JavaScript Document

	
	function checkForm(){
		
		//Check email address is valid.
		

		
		//Set error checking flag.
		errCheckCount = 0;
		

		
		//Check email addresses match.
		if(document.getElementById('mailadd').value != document.getElementById('conf_mail').value){

			document.getElementById('mailadd').style.background = '#FD7F7F';
			document.getElementById('conf_mail').style.background = '#FD7F7F';
			errCheckCount = errCheckCount + 1;
			alert('E-Mail values do not match or are invalid e-mail addresses.');
			document.getElementById('errField').style.background = '#FD7F7F';
			document.getElementById('errField').innerHTML = 'Errors detected.  Fields marked in <strong><font color="#C00000">RED</font></strong> need attention.';
			
			}else{
			
			document.getElementById('errField').style.background = '#FFFFFF';
			document.getElementById('errField').innerHTML = '';
			document.getElementById('conf_mail').style.background = '#FFFFFF';
		}
		
		//Check email address
		mailCheck = document.getElementById('mailadd').value;
		mailCheck = mailCheck.match("@");
		
		if(mailCheck == null){
		
			
			errCheckCount = errCheckCount + 1;
			document.getElementById('mailadd').style.background = '#FD7F7F';
			
			}else{
			
			document.getElementById('mailadd').style.background = '#FFFFFF';
			
		}
				
		//Check personal details.
		
		//Name & Title Check
		errCheck = CheckFieldComplete('title', 'NULL');
		errCheckCount = errCheckCount + errCheck;
		errCheck = CheckFieldComplete('forename', '');
		errCheckCount = errCheckCount + errCheck;
		errCheck = CheckFieldComplete('surname', '');
		errCheckCount = errCheckCount + errCheck;
		
					
		
		

		//Check for additional comments.		
		if (document.getElementById('comments').value == ''){
		
			document.getElementById('comments').value = "No additional comments submitted.";
			
		}
		

		if(errCheckCount == 0){

				//Check to make sure at least one category selected.
				catCount = 0;
				
				catChecker = catCheck('residential');
				catCount = catCount + catChecker;
		
				catChecker = catCheck('commercial');
				catCount = catCount + catChecker;
		
				catChecker = catCheck('sites');
				catCount = catCount + catChecker;
		
				catChecker = catCheck('overseas');
				catCount = catCount + catChecker;
		
				catChecker = catCheck('res_rentals');
				catCount = catCount + catChecker;
		
				catChecker = catCheck('comm_rentals');
				catCount = catCount + catChecker;
		
				catChecker = catCheck('developments');
				catCount = catCount + catChecker;
						
				catChecker = catCheck('other');
				catCount = catCount + catChecker;
				
				if(catCount == 0){
				
					alert("You must select at least one information category in the checkbox list.");
					
					}else{
					
					document.sendreg.submit();
							
				}
			
		}
		
	}
	
	function CheckFieldComplete(varField, varValue, errCheckCount){
	
		checkString = "document.getElementById('" + varField + "').value == '" + varValue + "'";
		errorString = "document.getElementById('" + varField + "').style.background = '#FD7F7F'";
		okString = "document.getElementById('" + varField + "').style.background = '#FFFFFF'";
		 		
		if(eval(checkString)){
			
			eval(errorString);
			document.getElementById('errField').style.background = '#FD7F7F';
			document.getElementById('errField').innerHTML = 'Errors detected.  Fields marked in <strong><font color="#C00000">RED</font></strong> need attention.';
			return 1;
			
			}else{
			
			eval(okString);
			return 0;
			
		}
		
		
	
	}
	
	function catCheck(varCat){
		
		checkString = "document.getElementById('" + varCat + "').checked";
		valueString = "document.getElementById('" + varCat + "').value = 'N'";
		valueString2 = "document.getElementById('" + varCat + "').value";
		
		if(eval(checkString) == false){
			

			return 0;
			
			}else{
			
			return 1;
		}
	
	
	}
