	function enableSubmit()
	{
		myObj = document.getElementById('formSubmit');
		myObj.disabled = false;
		return true;
	}	
	function disableSubmit()
	{
		myObj = document.getElementById('formSubmit');
		myObj.disabled = true; // kjp - temporarily commented to facilitate faster testing. 17/11/5
		return true;
	}
	
	function checkForNull( element_id )
	{
		var result = new Boolean(true);
		ctrl = document.getElementById(element_id);
		if( ctrl.value == '' ) {result=false; ctrl.className = 'ctrlError';}
		else ctrl.className='table';
		return result;
	}
	
	function checkForInt( element_id )
	{
		var result = new Boolean(true);
		ctrl = document.getElementById(element_id);
		if( isNaN(parseInt(ctrl.value)) ) {result=false; ctrl.className = 'ctrlError';}
		else ctrl.className='table';
		return result;
	}
	
	function checkForChecked( element_id, error_case )
	{
		/*
			error_case - can be 0 or 1. If it's 0, it means the element is wrong if it's not chequed. (ie checked is required).
		*/
		var result = new Boolean(true);
		ctrl = document.getElementById(element_id);
		if( error_case == 0 )
		{
			// error if the field is not checked.
			if( ctrl.checked == false )
			{
				result=false; 
				ctrl.className = 'ctrlError';
			}
			else
			{
				ctrl.className='table';
			}
		}
		else
		{
			// error if the field is not checked.
			if( ctrl.checked == true )
			{
				result=false; 
				ctrl.className = 'ctrlError';
			}
			else
			{
				ctrl.className='table';
			}
		}
		return result;
	}

	
	function checkForNullOpt( element_id, null_opt_val )
	{
		var result = new Boolean(true);
		ctrl = document.getElementById(element_id);
		var val = new Number(ctrl.value);
		if( val == null_opt_val ) {result=false; ctrl.className = 'ctrlError';}
		else ctrl.className='table';
		return result;
	}
	
	function checkForZero( element_id )
	{
		var result = new Boolean(true);
		ctrl = document.getElementById(element_id);
		var val = new Number(ctrl.value);
		if( val == 0 ) {result=false; ctrl.className = 'ctrlError';}
		else ctrl.className='table';
		return result;
	}
	
	/*
		Generic function for a specific dcdbmType. 
	*/
	function checkForNull_address( element_base_id )
	{
		 // A1 NOT NULL, A2, T NOT NULL, C
		var result = new Boolean(true);
		ctrlA1 = document.getElementById(element_base_id+'A1');
		ctrlA2 = document.getElementById(element_base_id+'A2');
		ctrlT = document.getElementById(element_base_id+'T');
		ctrlC = document.getElementById(element_base_id+'C');
		if( (ctrlA1.value == "") || (ctrlT.value == "") )
		{
			//alert (element_base_id);
			result = false;
			ctrlA1.className = 'ctrlError';
			ctrlT.className = 'ctrlError';
		}
		else
		{	
			ctrlA1.className = 'table';
			ctrlT.className = 'table';
			result = true;
		}
		return result;
	}
	
	function checkForNull_address_full( element_base_id )
	{
		 // same as checkForNull_address with additional P (postcode) NOT NULL
		 
	}
	
	
	function checkSec2_adr( apNo, adrNo )
	{
		// if the duration of this address is 0 then result is always true.
		var result = new Boolean(true); 
		str_dur = new String('add'+apNo+'dur'+adrNo);
		
		// component blocks
		var super_adr = new String('add'+apNo+'address'+adrNo);
		var postcode = new String('add'+apNo+'pc'+adrNo);
		var country = new String('add'+apNo+'country'+adrNo);
		
		if ( duration_getNoMonths( str_dur ) > 0 )		
		{
			 // check for fields. 
			
			// check adr: 
			//alert(super_adr + ' --- ' + str_dur + ' == ' + duration_getNoMonths( str_dur ));
			if( ! checkForNull_address( super_adr )) result = false;
			// check postcode:
			if( ! checkForNull( postcode )) result = false;
			if( ! checkForNullOpt( country, 4 )) result = false; // the null option is ID 4. 
		}
		else
		{
			// bit messy, but you need to use this space to override + remove errors in any of the address items above. 
			cA1 = document.getElementById(super_adr+'A1');
			cT = document.getElementById(super_adr+'T');
			cP = document.getElementById(postcode);
			cC = document.getElementById(country);
			cA1.className = 'table';			
			cT.className = 'table';			
			cP.className = 'table';			
			cC.className = 'table';			
			result = true;
		}
		return result;
	}
	
	
	function duration_getNoMonths( element_base_id )
	{
		ctrlY = document.getElementById(element_base_id + 'Y');
		ctrlM = document.getElementById(element_base_id + 'M');
		
		var yearVal = new Number(ctrlY.value);
		var monthVal = new Number(ctrlM.value);
		noMonths = yearVal*12+monthVal;
		return noMonths;
	}
	
	function checkForZero_duration( element_base_id )
	{
		var result = new Boolean(true);
		
		ctrlY = document.getElementById(element_base_id + 'Y');
		ctrlM = document.getElementById(element_base_id + 'M');
		
		var yearVal = new Number(ctrlY.value);
		var monthVal = new Number(ctrlM.value);
		// duration's consist of two elements, a text input and a select box (month). element_base_id+'Y', element_base_id+'M'
		if( (yearVal == 0) && (monthVal == 0) )
		{
			result=false; 
			ctrlY.className = 'ctrlError';
			ctrlM.className = 'ctrlError';			
		}
		else
		{
			ctrlY.className='table';
			ctrlM.className = 'table';			
		}
		return result;
	}
	
	
	function checkForInvalid_date( baseName )
	{
		var dateCtrlD = document.getElementById(baseName+'day');
		var dateCtrlM = document.getElementById(baseName+'month');
		var dateCtrlY = document.getElementById(baseName+'year');
		var result = new Boolean(true);	
		tday = dateCtrlD.value;
		tmonth = dateCtrlM.value;
		tyear = dateCtrlY.value;

		if( (tday < 1) || (tday > 31) )
		{
			result = false;
		}
		if( (tmonth < 1) || (tmonth > 12) )
		{
			result = false;
		}
		if( (tyear < 1900) || (tyear > 2050) )
		{
			result = false;
		}
		if( result == false )
		{
			// highlight error
			dateCtrlD.className = 'ctrlError';						
			dateCtrlM.className = 'ctrlError';						
			dateCtrlY.className = 'ctrlError';									
		}
		else
		{
			dateCtrlD.className = 'table';						
			dateCtrlM.className = 'table';						
			dateCtrlY.className = 'table';									
		}
		return result;
	}
	
	/*	Name updateSectionStatus
		Note changes the tab colour to indicate the overall status of this section.
	*/
	function updateSectionStatus( result, oldSec )
	{
		// oldSec is the section you've just finished editing before clicking away - it is the one you wish to check.
		currentSec = document.getElementById('currentSec').value;	
		/*	
			Set the colour status for this section, taking into account that it might also 
			be the current section. Overall result per section is indepdenent of noAp value
		*/
		if( result == true ) // ie no invalid values have been entered
		{
			/* If the currentSec is 1 then you should leave the status showing that it's the current section */
			if( currentSec != oldSec) setSecStatus(oldSec, 'complete', 3);
		}
		else
		{ 
			if (currentSec != oldSec ) setSecStatus(oldSec, 'error', 2);
		}		
	}	
	
	
	function checkSec( secNo )
	{
		switch( secNo.toString() )
		{
			case '0':
				return true;
				break;
			case '1':
				return checkSec1();
				break;
			case '2':
				return checkSec2();
				break;
			case '3':
				return checkSec3();
				break;
			case '4':
				return checkSec4();
				break;
			case '5':
				return checkSec5();
				break;
			case '6':
				return checkSec6();
				break;
			case '7':
				return checkSec7();
				break;
			default: return true;
		}
	}
	
	function checkSec1()
	{
		var noAp = new Number(getNoApplicants()); // noApp effects which fields you should check
		var result = new Boolean(true); // overall result for this section.
		/* Start checking fields */
		if( ! checkForZero('appamount')) result = false;
		if( ! checkForZero_duration('appterm')) result = false;
		if( ! checkForNull('app1firstName')) result = false;
		if( ! checkForNull('app1lastName')) result = false;
		if( ! checkForNull('app1tel')) result = false;
		if( ! checkForInvalid_date('app1dob')) result = false;
		if( noAp == 2 )
		{
			if( ! checkForNull('app2firstName')) result = false;
			if( ! checkForNull('app2lastName')) result = false;
			if( ! checkForNull('app2tel')) result = false;
			if( ! checkForInvalid_date('app2dob')) result = false;
		}
		updateSectionStatus( result, 1 );
		return result;
	}



	function checkSec2()
	{
		var result = new Boolean(true); // overall result for this section.

		currentSec = document.getElementById('currentSec').value;	
		var noAp = new Number(getNoApplicants());
		
		/*	13/2/2006 - KJP - initial notes on handling this section.
				
			For any address in which the duration is greater than zero, the user must supply:
			line 1, town, postcode, country. 
			
			Note that you must therefore set the duration to zero whenever an address is 'removed'.
		*/
		var noAdrs = 5;
		for( adrNo = 1; adrNo <= noAdrs; adrNo++ )
		{
			if( ! checkSec2_adr( 1, adrNo )) result = false;
		}
		if( noAp == 2 )
		{
			for( adrNo = 1; adrNo <= noAdrs; adrNo++ )
			{
				if( ! checkSec2_adr( 2, adrNo )) result = false;
			}
		}
		/*				
			The code below handles the specialized constraint that the total no. of address history 
			for each applicant must be greater than 3 years. 
		*/
		var totalNoMonths1 = new Number(tallyDisplayedMonths_address(1));
		if( totalNoMonths1 < 36 )
		{
			document.getElementById('sec2-a1-message_1').className = 'notEnoughAdrHistory';
			setSecStatus(2, 'error', 2);
			result = false;
		}
		else
		{
			document.getElementById('sec2-a1-message_1').className = '';
			setSecStatus(2, 'complete', 3);
		}
		if( (noAp == 2) )
		{
			var totalNoMonths2 = new Number(tallyDisplayedMonths_address(2));
			if( totalNoMonths2 < 36 )
			{
				document.getElementById('sec2-a2-message_1').className = 'notEnoughAdrHistory';
				setSecStatus(2, 'error', 2);
				result = false;
			}
			else
			{
				document.getElementById('sec2-a2-message_1').className = '';
				setSecStatus(2, 'complete', 3);
			}
		}
		return result;
	}

	/*	Name: checkSec3
		Notes:	Employment section. 
		TODO: 	Implement + use functions that accept apNo as a parameter
				for all conditions.
	*/
	function checkSec3()
	{
		var noAp = new Number(getNoApplicants());
		var result = new Boolean(true); // overall result for this section.
		/* 1. CHECK CURRENT EMP */
		
			// if employment is not selected, just highlight type as being incomplete.
		
		
		/* 2. CHECK PREVIOUS EMP */


		/* 3. CHECKING TOTAL HISTORY/DURATION  */

			/* (example snippets only from previous implementation) */
			/*
			var totalNoMonths1 = new Number(tallyDisplayedMonths_employment(1));
			var totalNoMonths2 = new Number(tallyDisplayedMonths_employment(2));
			document.getElementById('sec3-a1-message_1').className = '';
			if( totalNoMonths1 < 12 ) document.getElementById('sec3-a1-message_1').className = 'notEnoughAdrHistory';
			else document.getElementById('sec3-a1-message_1').className = '';		
			*/
		updateSectionStatus( result, 3 );
		return result;				
	}

	// Property
	function checkSec4()
	{
		var result = new Boolean(true); // overall result for this section.
		if( ! checkForInt( 'propmodurM' )) result = false;
		if( ! checkForInt( 'propmodurY' )) result = false;
		if( ! checkForInt( 'propmopreviousdurM' )) result = false;
		if( ! checkForInt( 'propmopreviousdurY' )) result = false;
		if( ! checkForNull_address( 'propaddress' )) result = false;
		if( ! checkForNull('proppc')) result = false;
		if( ! checkForNullOpt('propregion', 0)) result = false;
		if( ! checkForNullOpt('propcountry', 4)) result = false;
		if( ! checkForZero('propval')) result = false;
		if( ! checkForNull('propmoacc')) result = false;
		if( ! checkForNull('propmofirstmointrate')) result = false;
		updateSectionStatus( result, 4 );
		return result;		
	}
	
	// Secured Loans
	function checkSec5()
	{
		var result = new Boolean(true); // overall result for this section.
		var noSecLoans = document.getElementById('infosecurednoloans').value;
		if( noSecLoans == 0 )
		{
			result = true;
		}
		else
		{
			// atleast 1 sec loan. lender, ac no- compulsory.. monthly payment could be zero.
			if( ! checkForNull('infosecuredlender')) result = false;
			if( ! checkForNull('infosecuredaccountno')) result = false;
			if( noSecLoans == 2 ) // also check 2nd sec loan fields
			{
				if( ! checkForNull('infosecuredlender2')) result = false;
				if( ! checkForNull('infosecuredaccountno2')) result = false;
			}
		}
		updateSectionStatus( result, 5 );
		return result;		
	}
	
	// Credit history
	function checkSec6()
	{
		var result = new Boolean(true); // overall result for this section.
		// conditions to set result to false go here
		updateSectionStatus( result, 6 );
		return result;		
	}

	// Quote and confirm
	function checkSec7()
	{
		var result = new Boolean(true); // overall result for this section.
		if( ! checkForChecked('confirmdataprotectionagreed', 0)) result = false;
		if( ! checkForNullOpt('confirmtype', 0)) result = false;
		updateSectionStatus( result, 7 );
		return result;		
	}

	//<section status flags (hidden fields in .lbi file>
	function getSecStatus(secId)
	{
		var val = new Number(document.getElementById('secStatus'+secId.toString()).value );
		if( (val > -1) && (val < 4)) return val;
		else window.status = 'ERROR: Section status value is invalid';
	}
	function setSecStatus(secId, statusClassName, statusId)
	{
		// 0 = not visited yet, 1 = current, 2 = error, 3 = completes		
		// if the className is applied to the current section, overwrite it.
		currentSec = document.getElementById('currentSec').value;
		if( currentSec.toString() == secId.toString() ) setClass('secStatus'+secId.toString()+'T', 'active'); // case: user cilcks on current sec
		else {
			setClass('secStatus'+secId.toString()+'T', statusClassName.toString() );
		}
		var statusId = new Number(statusId);
		document.getElementById('secStatus'+secId.toString()).value = statusId;
		return true;	
	}
	function setClass( elementId, value )
	{
		document.getElementById(elementId).className = value.toString();
		return true;
	}
	//</section status>
	
	function checkWholeForm()
	{
		var flag = new Boolean(true); // flags if ok to enable or not ok.
		for( i=1; i<7; i++)
		{
			if( getSecStatus( i ).toString() != '3' ) 
			{
				flag = false;
			}
		}
		
		// if all the other sections are ok, and sec 7 is current and data protection is checked then all are ok:
		/*	Fail conditions:
			StatusId7	DP	Others	EN
			1			0	0		0
			1			0	1		0
			1			1	0		0
			1			1	1		1
			3			1 	1		1
		
		*/
		
		if( (flag == true) && (checkSec7() == true))
		{
			flag = true;
		}
		else flag = false;
		
	
		enableSubmit();		
		/*
		if( flag == true ) // all sec must be ok
		{
			enableSubmit();
			changeObjectVisibility('sec7-sub-msg', 'hidden'); // hide the mssage that says they need to correct a section
		}
		else 
		{
			disableSubmit();
			changeObjectVisibility('sec7-sub-msg', 'visible'); // else show it.
		}
		*/
		return true;
	}

	/*	Name: isFormReadOnly
		Created: 24/01/2006 / KJP
		Notes:	This allows some of the functions to adjust to handle display of the readonly
				form with the same code as the editable form. 
	*/
	function isFormReadOnly()
	{
		try 
		{
			var formType = new String(document.getElementById('formType').value);
			if (formType == "readonly") return true;
		}
		catch (e) 
		{ 
			// will catch if form is editable. do nothing.
			return false;
		}

	}

