﻿//******************************************************************************************
// References.
//******************************************************************************************
/// <reference path="Scripts/Helper.js" />
/// <reference path="Scripts/Validator.js" />
/// <reference path="Scripts/jQuery.js" />
/// <reference path="DatePicker.js" />
/// <reference name="MicrosoftAjax.js" />

//******************************************************************************************
// Constants.
//******************************************************************************************

var POP_UP_PREFIX = LEFT_CONTENT_PREFIX + "popUpIncidentDetails_";

//******************************************************************************************
// Local variables.
//******************************************************************************************
var _hfJavaScriptTest = null;
var _hfEdit = null;

var _txtCoverStartDate_Day = null;
var _txtCoverStartDate_Month = null;
var _txtCoverStartDate_Year = null;
var _txtCoverStartDate = null;

var _ddlCoverType = null;
var _divBuildingsCover = null;
var _divContentsCover = null;
var _divLandlordAccreditedSchemeMember = null;
var _divJointPolicyDetails = null;
var _divIncidentDetails = null;

var _txtHouseNameNumberProperty = null;
var _txtPostcodeProperty = null;
var _hfAddressLine1Property = null;
var _hfAddressLine2Property = null;

var _txtHouseNameNumberClient = null;
var _txtPostcodeClient = null;
var _hfAddressLine1Client = null;
var _hfAddressLine2Client = null;

var arrValidationBuildings = new Array();
var arrValidationContents = new Array();
var arrValidationLandlordAccreditedSchemeMember = new Array();
var arrValidationJointPolicyDetails = new Array();

var val_BuildingsVoluntaryExcess = null;
var val_ContentsCoverAmount = null;
var val_compareMax_ContentsCoverAmount = null;
var val_compareMin_ContentsCoverAmount = null;

var val_LandlordAccreditedSchemeMember = null;

var val_FirstNameJoint = null;
var val_SurnameJoint = null;
var val_DateOfBirthJoint = null;
var val_compareMax_DateOfBirthJoint = null;

var isClientAddressValid = false;
var isPropertyAddressValid = false;

var hdnUpdate_pnlIncidentDetails = null;

var txtIncidentDate_Day = null;
var txtIncidentDate_Month = null;
var	txtIncidentDate_Year = null;
var txtIncidentDate = null;
var txtIncidentCost = null;
var ddlIncidentSectionAffected = null;
var ddlIncidentType = null;

var arrIncidentDateInputs = new Array();
var arrIncidentPopUpInputs = new Array();

var val_IncidentDate = null;
var val_Min_IncidentDate = null;
var val_Max_IncidentDate = null;
var val_IncidentCost = null;
var val_Min_IncidentCost = null;
var val_Max_IncidentCost = null;
var val_IncidentSectionAffected = null;
var val_IncidentType = null;
var val_custPreviousClaims = null;

var btnAddIncidentDetails = null;
var btnSaveIncidentChanges = null;

var incidentPopUpValidationSummary = null

var showProgress = null;
//******************************************************************************************
// Page events.
//******************************************************************************************

//Fired when the page is loaded.
$(document).ready(function()
{
	// Set up local variables
	setUpLocalVariables();

	// Place value in hidden field to show that Javascript is running
	_hfJavaScriptTest.value = "1";
	
	// Set up the cover specific validator groups (Buildings / Contents)
	setUpValidationGroups();
	
	// Set up help popups
	setUpHelpPopUps();
	
	// Set up Auto Complete Lists
	setUpAutoCompleteLists();
	
	// Set up progress animations
	setUpProgress();
	
	// Refresh cover type display
	refreshCoverTypeDisplaySections();
	
	// Refresh Landlord Accredited Scheme Member display
	refreshLandlordAccreditedSchemeMemberDisplaySection($get(LEFT_CONTENT_PREFIX + 'radLandlordAccreditedScheme_0').checked);
	
	// Refresh Joint Policy Details display
	refreshJointPolicyDisplaySection($get(LEFT_CONTENT_PREFIX + 'radJointPolicy_0').checked);
	
	// Refresh Joint Policy Details display
	refreshPreviousClaimsDisplaySection($get(LEFT_CONTENT_PREFIX + 'radPreviousClaims_0').checked);

	//Refresh the update panel.
	refreshPanel($get(LEFT_CONTENT_PREFIX + 'hdnUpdate_pnlIncidentDetails'), -1);
	
	// Refresh risk address
	refreshAddress(true)
	
	// Refresh client address
	refreshAddress(false)
	
	// Hide Chrome errors div
	$get('divChromeErrors').style.display = 'none';
	
	// Get the form data that some browsers forget (e.g. autocomplete issue in Chrome).
	Service.GetMissingFormData(GetMissingFormData_Response);

});

function AJAXRequest_Finished(sender, args) 
{

	

	if (_hfEdit.value == QUERY_STRING_EDIT_EXCESS)
	{
		// Scroll to the buildings cover div and Focus the excess control
		scrollToElement(buildingsCover);
		$get(LEFT_CONTENT_PREFIX + 'ddlBuildingsVoluntaryExcess').focus();
		
		//Clear hidden field value
		_hfEdit.value = "";
	}
	else if (_hfEdit.value == QUERY_STRING_EDIT_QUOTE)
	{
		// Focus & select the cover start date day textbox
		_txtCoverStartDate_Day.focus();
		_txtCoverStartDate_Day.select();
		
		//Clear hidden field value
		_hfEdit.value = "";	
	}
	else if  ($get(LEFT_CONTENT_PREFIX + 'divIncidentDetails').style.display == 'block')
	{
		// Bit of a frig this but as the claims update panel causes the page to reload after adding / removing claims, we need to keep the page postion on the claims section,
		// rather than focus the cover start date (first input on the page) as we do below when the page loads for the very first time.
		scrollToElement(divClaimHistory);
	}
	else
	{
		// Focus & select the cover start date day textbox
		_txtCoverStartDate_Day.focus();
		_txtCoverStartDate_Day.select();
	}
	
	// Add date picker to cover start date year field	
	var coverStartDatePicker = new DatePicker(LEFT_CONTENT_PREFIX + 'txtCoverStartDate', 0, 30);
	
	// ********************* Date picker causes error with update panel so remove for now *********************************
	
	// Add date picker to the incident (claims pop up) date year field
	// We are only interested in claims in the past 5 years (or 1825 days!)
	//var incidentDatePicker = new DatePicker(LEFT_CONTENT_PREFIX + 'popUpIncidentDetails_txtIncidentDate', 1825, 0);
	
	// ********************* Date picker causes error with update panel so remove for now *********************************
}

//******************************************************************************************
// Control events.
//******************************************************************************************

// Change event for the ddl coverType
function ddlCoverType_Change() 
{
	refreshCoverTypeDisplaySections();
}

// Click event for the radJointPolicy control
function radLandlordAccreditedScheme_Click(show) 
{
	refreshLandlordAccreditedSchemeMemberDisplaySection(show);
}

// Click event for the radJointPolicy control
function radJointPolicy_Click(show) 
{
	refreshJointPolicyDisplaySection(show);
}

// Click event for the radPreviousClaims control
function radPreviousClaims_Click(show) 
{		
	// If user has clicked "No" to claims, check that they have not previously added any.
	// If they have, ask them if they want to delete them before continuing..
	if (!show)
	{
		var pannelLengthNoChildren = 3;
		var Browser = new BrowserInfo();
		if (Browser.IsIE)
			pannelLengthNoChildren = 1;

		// If claims exist, ask if they need to be deleted
		if ($get(LEFT_CONTENT_PREFIX + 'pnlIncidentDetails').childNodes.length > pannelLengthNoChildren) 
		{
			answer = confirm('You have already added claims. Do you want to delete them?');

			// Delete the claims & hide the claims section
			if (answer != 0) 
			{
				// Hide claims section
				refreshPreviousClaimsDisplaySection(show);
				
				$get(LEFT_CONTENT_PREFIX + 'radPreviousClaims_0').checked = false;
				$get(LEFT_CONTENT_PREFIX + 'radPreviousClaims_1').checked = true;
				
				//Delete claims froom collection
				refreshPanel($get(LEFT_CONTENT_PREFIX + 'hdnUpdate_pnlIncidentDetails'), "RemoveAllIncidents");
			}
			else 
			{
				// User does not want to delete the claims so set claims radio button back to "Yes"
				$get(LEFT_CONTENT_PREFIX + 'radPreviousClaims_1').checked = false;
				$get(LEFT_CONTENT_PREFIX + 'radPreviousClaims_0').checked = true;
				
				// Return false and close prompt
				return false;
			}
		}
		else
		{
			// Hide claims section
			refreshPreviousClaimsDisplaySection(show);
		}
	}
	else 
	{	
		// Show claims section
		refreshPreviousClaimsDisplaySection(show);
	}	
}

// Gender look up
function ddlTitle_Change(e) {
	if ($get(LEFT_CONTENT_PREFIX + 'ddlTitle').value != '') {
		Service.GetGender($get(LEFT_CONTENT_PREFIX + 'ddlTitle').value, GetGender_Response);
	}
}

// Click event for btn FindAddressProperty
function btnFindAddressProperty_Click() 
{
	if (_hfAddressLine1Property != null) _hfAddressLine1Property.value = '';
	if (_hfAddressLine2Property != null) _hfAddressLine2Property.value = '';
	findAddress(_txtHouseNameNumberProperty.value, _txtPostcodeProperty.value, true, 'Property');
}

// Click event for btn FindAddressClient
function btnFindAddressClient_Click() 
{
	if (_hfAddressLine1Client != null) _hfAddressLine1Client.value = '';
	if (_hfAddressLine2Client != null) _hfAddressLine2Client.value = '';
	findAddress(_txtHouseNameNumberClient.value, _txtPostcodeClient.value, false, 'Client');
}

// Click event for get quote button
function btnGetQuote_ClientClick() 
{
	validatePageInputs()
	
	if (Validator.IsPageValid())
	{
		populateHiddenAddressFields()

		// Ensure btnPayonline click event is fired (firefox 2 fix)
		document.forms[0].__EVENTTARGET.value = 'ctl00$leftContentPlaceHolder$btnGetQuote';

		// Show progress image
		showProgress.showProgressImage();
	}
	else
	{
		// This is a bug fix for the Chrome browser.  
		// IF the page fails validation the default .net behaviour is to go back to the top of the page. 
		// However, we tend to override this and scroll to the buy button which is at the bottom of the page.
		// This causes display issues with the page in Chrome as the DOM doesnt update corectly.
		// So for Chrome, go to the top of the page and show an error div with instructions to the customer.
		
		var Browser = new BrowserInfo();
		if (Browser.IsChrome)
		{
			$get('divChromeErrors').style.display = 'block';
		}
		else
		{
			$get('divChromeErrors').style.display = 'none';
			
			scrollToElement(LEFT_CONTENT_PREFIX + 'btnGetQuote');
		}
	}
}

// On blur event for cover start date day
function txtCoverStartDate_Day_OnBlur()
{
    constructDate(_txtCoverStartDate_Day, _txtCoverStartDate_Month, _txtCoverStartDate_Year, _txtCoverStartDate);
}

// On blur event for cover start date month
function txtCoverStartDate_Month_OnBlur()
{
	constructDate(_txtCoverStartDate_Day, _txtCoverStartDate_Month, _txtCoverStartDate_Year, _txtCoverStartDate);
}

// On blur event for cover start date year
function txtCoverStartDate_Year_OnBlur()
{
	constructDate(_txtCoverStartDate_Day, _txtCoverStartDate_Month, _txtCoverStartDate_Year, _txtCoverStartDate);
}

// On blur event for txtHouseNameNumberProperty
function txtHouseNameNumberProperty_OnBlur()
{
	refreshAddress(true);
}

// On blur event for txtPostcodeProperty 
function txtPostcodeProperty_OnBlur()
{
	refreshAddress(true);
}

// On blur event for txtHouseNameNumberClient
function txtHouseNameNumberClient_OnBlur()
{
	refreshAddress(false);
}

// On blur event for txtPostcodeClient
function txtPostcodeClient_OnBlur()
{
	refreshAddress(false);
}

// Hide ddlUnion on focus
function txtFullTimeOccupation_OnFocus()
{
	$get(LEFT_CONTENT_PREFIX + 'ddlUnion').style.visibility = 'hidden';
}

// Show ddlUnion on blur
function txtFullTimeOccupation_OnBlur()
{
	$get(LEFT_CONTENT_PREFIX + 'ddlUnion').style.visibility = 'visible';
}

function txtIncidentDate_Day_OnBlur() 
{
	// Set up local variables again so we have them in their latest state.
	setUpLocalVariables();
	
	constructDate(txtIncidentDate_Day, txtIncidentDate_Month, txtIncidentDate_Year, txtIncidentDate);
}

function txtIncidentDate_Month_OnBlur() 
{
	// Set up local variables again so we have them in their latest state.
	setUpLocalVariables();
	
	constructDate(txtIncidentDate_Day, txtIncidentDate_Month, txtIncidentDate_Year, txtIncidentDate);
}

function txtIncidentDate_Year_OnBlur() 
{
	// Set up local variables again so we have them in their latest state.
	setUpLocalVariables();
	
	constructDate(txtIncidentDate_Day, txtIncidentDate_Month, txtIncidentDate_Year, txtIncidentDate);
}

// Opens Claims / Incident Details popup
function btnOpenIncidentDetails_Click() 
{	
	// Enable incident pop up validators
	toggleIncidentPopUpValidators(true);
		
	// Reset custom validation
	val_custPreviousClaims.Reset();
	
	// Clear any previous data entered
	clearInicidentDetailsPopUp();
	
	// Show the add details button
    btnAddIncidentDetails.style.display = 'block';

	// Hide the save changes button   
	btnSaveIncidentChanges.style.display = 'none';
	
	// Show the pop up	
    showPopUp(LEFT_CONTENT_PREFIX + 'popUpIncidentDetails', 'middleCenter', 220, 730);
    
    // Focus & select first input field
    var dayField = $get(POP_UP_PREFIX + 'txtIncidentDate_Day');
    dayField.focus();
    dayField.select();
}

// Click event for btnAddIncidentDetails & btnSaveIncidentChanges
function btnAddIncidentDetails_ClientClick()
{
	hdnUpdate_pnlIncidentDetails.value = -1;
	
	// Set up local variables again so we have them in their latest state.
	setUpLocalVariables();
	
	return validateIncidentPopUpInputs();
}

function btnSaveChanges_ClientClick() 
{
	// Set up local variables again so we have them in their latest state.
	setUpLocalVariables();

	return validateIncidentPopUpInputs();
}

// Closes the Claims / Incident Details popup
function btnCancelIncidentDetails_ClientClick()
{
	answer = confirm('Are you sure you wish to close without saving?');

	if (answer != 0) 
	{
		//Disable incident pop up validators
		toggleIncidentPopUpValidators(false);
		
		// Validate page based on the above validators - forces page.isvalid to equal true. 
		// This is a bit of a frig but needed in order for the update panel to post back correctly
		Validator.ValidatePage('vgIncidentDetails');
		
		test = Page_IsValid;
				
		// Set hidden panel value back to -1
		hdnUpdate_pnlIncidentDetails.value = -1;

		// Close pop up window
		hidePopUp(LEFT_CONTENT_PREFIX + 'popUpIncidentDetails');
		return false;
	}
	else 
	{
		// Simply return false and close prompt
		return false;
	}
}

function btnEditIncidentDetails_ClientClick(incidentDate, incidentAmount, incidentSectionAffectedIndex, IncidentTypeIndex, index)
{
	// Set up local variables again so we have them in their latest state.
	setUpLocalVariables();
	
	// Reset custom validation
	val_custPreviousClaims.Reset();
	
	// Reset Incident Pop Up Validators
	resetIncidentPopUpValidators();
	
	//Hide validation summary
	incidentPopUpValidationSummary.style.display = 'none';
	
	// Set values of Pop Up inputs to match those of the Incident Details being edited
	txtIncidentDate_Day.value = incidentDate.toString().substr(0, 2); ;
	txtIncidentDate_Month.value = incidentDate.toString().substr(3, 2);
	txtIncidentDate_Year.value = incidentDate.toString().substr(6, 4); ;
	txtIncidentDate.value = incidentDate;
	txtIncidentCost.value = incidentAmount;
	ddlIncidentSectionAffected.selectedIndex = incidentSectionAffectedIndex;
	ddlIncidentType.selectedIndex = IncidentTypeIndex;
	
	// Set hidden field to  = index.  This number is used when finding the right incident in the collection to edit 
	hdnUpdate_pnlIncidentDetails.value = index;
	
	// Hide the add details button
    btnAddIncidentDetails.style.display = 'none';

	// Show the save changes button   
	btnSaveIncidentChanges.style.display = 'block';
	
	// Show the pop up
	showPopUp(LEFT_CONTENT_PREFIX + 'popUpIncidentDetails', 'middleCenter', 220, 730);
}

// Remove the interested party
function btnRemoveIncident_ClientClick(e, index) 
{
	refreshPanel($get(e.srcElement.id), index);
}

//******************************************************************************************
// Supporting functions
//******************************************************************************************
function checkPage()
{
	if ($.browser.mozilla)
	{
		// If we have a postcode but no bedroom count when the page is loaded, then reload the page.
		//TODO: NOTE this will have to change if the page is pre-filled at some point in the future!!!!
		if ($get(LEFT_CONTENT_PREFIX + 'txtPostcodeProperty').value != '' && $get(LEFT_CONTENT_PREFIX + 'ddlBedrooms').selectedIndex == -1)
		{
			var btnUpdatePage = LEFT_CONTENT_PREFIX + 'btnUpdatePage';
			btnUpdatePage.replace('_', '$');
			__doPostBack(btnUpdatePage, '');
		}
	}
}

function refreshPanel(panelTrigger, value) 
{
	if (panelTrigger) 
	{
		$get(LEFT_CONTENT_PREFIX + 'hdnUpdate_pnlIncidentDetails').value = value;
		__doPostBack(panelTrigger.id, '');
	}
}


// Set up the local variables for this page
function setUpLocalVariables() 
{
	_hfJavaScriptTest = $get(HIDDEN_CONTENT_PREFIX + 'hfJavaScriptTest');
	_hfEdit = $get(HIDDEN_CONTENT_PREFIX + 'hfEdit'); 
	
	_txtCoverStartDate_Day = $get(LEFT_CONTENT_PREFIX + 'txtCoverStartDate_Day');
	_txtCoverStartDate_Month = $get(LEFT_CONTENT_PREFIX + 'txtCoverStartDate_Month');
	_txtCoverStartDate_Year = $get(LEFT_CONTENT_PREFIX + 'txtCoverStartDate_Year');
	_txtCoverStartDate = $get(LEFT_CONTENT_PREFIX + 'txtCoverStartDate');

	_ddlCoverType = $get(LEFT_CONTENT_PREFIX + 'ddlCoverType');
	_divBuildingsCover = $get('buildingsCover');
	_divContentsCover = $get('contentsCover');
	_divLandlordAccreditedSchemeMember = $get('divLandlordAccreditedSchemeMember');
	_divJointPolicyDetails = $get('divJointPolicyDetails');
	_divIncidentDetails = $get(LEFT_CONTENT_PREFIX + 'divIncidentDetails');
	
	_txtHouseNameNumberProperty = $get(LEFT_CONTENT_PREFIX + 'txtHouseNameNumberProperty');
	_txtPostcodeProperty = $get(LEFT_CONTENT_PREFIX + 'txtPostcodeProperty');
	_hfAddressLine1Property = $get(LEFT_CONTENT_PREFIX + 'hfAddressLine1Property');
	_hfAddressLine2Property = $get(LEFT_CONTENT_PREFIX + 'hfAddressLine2Property');
	
	_txtHouseNameNumberClient = $get(LEFT_CONTENT_PREFIX + 'txtHouseNameNumberClient');
	_txtPostcodeClient = $get(LEFT_CONTENT_PREFIX + 'txtPostcodeClient');
	_hfAddressLine1Client = $get(LEFT_CONTENT_PREFIX + 'hfAddressLine1Client');
	_hfAddressLine2Client = $get(LEFT_CONTENT_PREFIX + 'hfAddressLine2Client');
	
	// Set up hidden panel
	hdnUpdate_pnlIncidentDetails = $get(LEFT_CONTENT_PREFIX + 'hdnUpdate_pnlIncidentDetails');	
	
	// Claims / Incident inputs
	txtIncidentDate_Day = $get(POP_UP_PREFIX + 'txtIncidentDate_Day');
	txtIncidentDate_Month = $get(POP_UP_PREFIX + 'txtIncidentDate_Month');
	txtIncidentDate_Year = 	$get(POP_UP_PREFIX + 'txtIncidentDate_Year');
	txtIncidentDate = $get(POP_UP_PREFIX + 'txtIncidentDate');
	txtIncidentCost = $get(POP_UP_PREFIX + 'txtIncidentCost');
    ddlIncidentSectionAffected = $get(POP_UP_PREFIX + 'ddlIncidentSectionAffected');
    ddlIncidentType = $get(POP_UP_PREFIX + 'ddlIncidentType');
		
	// Array of Incident date inputs
	arrIncidentDateInputs[0] = POP_UP_PREFIX + 'txtIncidentDate_Day';
	arrIncidentDateInputs[1] = POP_UP_PREFIX + 'txtIncidentDate_Month';
	arrIncidentDateInputs[2] = POP_UP_PREFIX + 'txtIncidentDate_Year';

	// Set up validator objects
	val_IncidentDate = new Validator(POP_UP_PREFIX + 'eccDV_IncidentDate', POP_UP_PREFIX + 'lblDateOfIncident', arrIncidentDateInputs, STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	val_Min_IncidentDate = new Validator(POP_UP_PREFIX + 'eccDV_compareMin_IncidentDate', POP_UP_PREFIX + 'lblDateOfIncident', arrIncidentDateInputs, STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);		
	val_Max_IncidentDate = new Validator(POP_UP_PREFIX + 'eccDV_compareMax_IncidentDate', POP_UP_PREFIX + 'lblDateOfIncident', arrIncidentDateInputs, STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	val_IncidentCost = new Validator(POP_UP_PREFIX + 'req_txtIncidentCost', POP_UP_PREFIX + 'lblIncidentCost', POP_UP_PREFIX + 'txtIncidentCost', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	val_Min_IncidentCost = new Validator(POP_UP_PREFIX + 'compareMin_txtIncidentCost', POP_UP_PREFIX + 'lblIncidentCost', POP_UP_PREFIX + 'txtIncidentCost', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	val_Max_IncidentCost = new Validator(POP_UP_PREFIX + 'compareMax_txtIncidentCost', POP_UP_PREFIX + 'lblIncidentCost', POP_UP_PREFIX + 'txtIncidentCost', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	val_IncidentSectionAffected = new Validator(POP_UP_PREFIX + 'req_ddlIncidentSectionAffected', POP_UP_PREFIX + 'lblIncidentSectionAffected', POP_UP_PREFIX + 'ddlIncidentSectionAffected', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	val_IncidentType = new Validator(POP_UP_PREFIX + 'req_ddlIncidentType', POP_UP_PREFIX + 'lblIncidentType', POP_UP_PREFIX + 'ddlIncidentType', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);
		
	// Array of pop up inputs
	arrIncidentPopUpInputs[0] = val_IncidentDate;
	arrIncidentPopUpInputs[1] = val_Min_IncidentDate;
	arrIncidentPopUpInputs[2] = val_Max_IncidentDate;
	arrIncidentPopUpInputs[3] = val_IncidentCost;
	arrIncidentPopUpInputs[4] = val_IncidentSectionAffected;
	arrIncidentPopUpInputs[5] = val_IncidentType;
	arrIncidentPopUpInputs[6] = val_Min_IncidentCost;
	arrIncidentPopUpInputs[7] = val_Max_IncidentCost;
	
	// Set up the pop up buttons
	btnAddIncidentDetails = $get(LEFT_CONTENT_PREFIX + 'popUpIncidentDetails_btnAddIncidentDetails');
	btnSaveIncidentChanges = $get(LEFT_CONTENT_PREFIX + 'popUpIncidentDetails_btnSaveIncidentChanges');
	
	// Claims / Incident validation summary
	incidentPopUpValidationSummary = $get(LEFT_CONTENT_PREFIX + 'popUpIncidentDetails_validationSummaryIncidentDetails');	
}

// Set up the cover specific validator groups (Buildings / Contents) 
function setUpValidationGroups()
{
	 // Add validation controls to Buildings validation array
	arrValidationBuildings[0] = $get(LEFT_CONTENT_PREFIX + 'req_ddlBuildingsVoluntaryExcess');
	 
	// Add validation controls to Contents validation array
	arrValidationContents[0] = $get(LEFT_CONTENT_PREFIX + 'req_txtContentsCoverAmount');
	arrValidationContents[1] = $get(LEFT_CONTENT_PREFIX + 'compareMax_txtContentsCoverAmount');
	arrValidationContents[2] = $get(LEFT_CONTENT_PREFIX + 'compareMin_txtContentsCoverAmount');
	
	// Add validation controls to Landlord Accredited Scheme Member validation array
	arrValidationLandlordAccreditedSchemeMember[0] = $get(LEFT_CONTENT_PREFIX + 'req_ddlLandlordAccreditedSchemeMember');
	
	// Add validation controls to Joint Policy details validation array
	arrValidationJointPolicyDetails[0] = $get(LEFT_CONTENT_PREFIX + 'req_txtFirstNameJoint');
	arrValidationJointPolicyDetails[1] = $get(LEFT_CONTENT_PREFIX + 'req_txtSurnameJoint');
	arrValidationJointPolicyDetails[2] = $get(LEFT_CONTENT_PREFIX + 'eccDV_DateOfBirthJoint');
	arrValidationJointPolicyDetails[3] = $get(LEFT_CONTENT_PREFIX + 'eccDV_compareMax_DateOfBirthJoint');
	
	var arrJointPolicyDateOfBirth = new Array();
	arrJointPolicyDateOfBirth[0] = $get(LEFT_CONTENT_PREFIX + 'txtDOB_Day_Joint');
	arrJointPolicyDateOfBirth[1] = $get(LEFT_CONTENT_PREFIX + 'txtDOB_Month_Joint');
	arrJointPolicyDateOfBirth[2] = $get(LEFT_CONTENT_PREFIX + 'txtDOB_Year_Joint');
	
	// These needs to be here so they can be accessed by the refreshCoverTypeDisplaySections() function
	val_BuildingsVoluntaryExcess = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlBuildingsVoluntaryExcess', LEFT_CONTENT_PREFIX + 'lblBuildingsVoluntaryExcess', LEFT_CONTENT_PREFIX + 'ddlBuildingsVoluntaryExcess', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	val_ContentsCoverAmount = new Validator(LEFT_CONTENT_PREFIX + 'req_txtContentsCoverAmount', LEFT_CONTENT_PREFIX + 'lblContentsCoverAmount', LEFT_CONTENT_PREFIX + 'txtContentsCoverAmount', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	val_compareMax_ContentsCoverAmount = new Validator(LEFT_CONTENT_PREFIX + 'compareMax_txtContentsCoverAmount', LEFT_CONTENT_PREFIX + 'lblContentsCoverAmount', LEFT_CONTENT_PREFIX + 'txtContentsCoverAmount', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	val_compareMin_ContentsCoverAmount = new Validator(LEFT_CONTENT_PREFIX + 'compareMin_txtContentsCoverAmount', LEFT_CONTENT_PREFIX + 'lblContentsCoverAmount', LEFT_CONTENT_PREFIX + 'txtContentsCoverAmount', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	
	// This needs to be here so it can be accessed by the refreshLandlordAccreditedSchemeMemberDisplaySection() function
	val_LandlordAccreditedSchemeMember = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlLandlordAccreditedSchemeMember', LEFT_CONTENT_PREFIX + 'lblLandlordAccreditedSchemeMember', LEFT_CONTENT_PREFIX + 'ddlLandlordAccreditedSchemeMember', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	
	// These needs to be here so they can be accessed by the refreshJointPolicyDisplaySection() function
	val_FirstNameJoint = new Validator(LEFT_CONTENT_PREFIX + 'req_txtFirstNameJoint', LEFT_CONTENT_PREFIX + 'lblFirstNameJoint', LEFT_CONTENT_PREFIX + 'txtFirstNameJoint', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	val_SurnameJoint = new Validator(LEFT_CONTENT_PREFIX + 'req_txtSurnameJoint', LEFT_CONTENT_PREFIX + 'lblSurnameJoint', LEFT_CONTENT_PREFIX + 'txtSurnameJoint', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	val_DateOfBirthJoint = new Validator(LEFT_CONTENT_PREFIX + 'eccDV_DateOfBirthJoint', LEFT_CONTENT_PREFIX + 'lblDateOfBirthJoint', arrJointPolicyDateOfBirth, STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	val_compareMax_DateOfBirthJoint = new Validator(LEFT_CONTENT_PREFIX + 'eccDV_compareMax_DateOfBirthJoint', LEFT_CONTENT_PREFIX + 'lblDateOfBirthJoint', arrJointPolicyDateOfBirth, STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	
	val_custPreviousClaims = new Validator(LEFT_CONTENT_PREFIX + 'cust_radPreviousClaims', LEFT_CONTENT_PREFIX + 'lblPreviousClaims', LEFT_CONTENT_PREFIX + 'radPreviousClaims', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
}

// Sets up the eHelp pop ups
function setUpHelpPopUps()
{
	var helpCoverStartDate = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpCoverStartDate', null, 'helpCoverStartDate', false, true);
	var helpHouseNameNumberProperty = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpHouseNumberNameProperty', null, 'helpHouseNameNumberProperty', false, true);
	var helpTenants = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpLettingType', null, 'helpLettingType', false, true);
	var helpBathrooms = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpBathrooms', null, 'helpBathrooms', false, true);
	var helpPropertyBuildDate = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpPropertyBuildDate', null, 'helpPropertyBuildDate', false, true);
	var helpLettingType = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpTenants', null, 'helpTenants', false, true);
	var helpTenancyAgreement = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpTenancyAgreement', null, 'helpTenancyAgreement', false, true);
	var helpLettingAgentManagement = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpLettingAgentManagement', null, 'helpLettingAgentManagement', false, true);
	var helpLandlordAccreditedScheme = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpLandlordAccreditedScheme', null, 'helpLandlordAccreditedScheme', false, true);
	var helpTenantReferencing = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpTenantReferencing', null, 'helpTenantReferencing', false, true);
	var helpMainEntranceDoor = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpMainEntranceDoor', null, 'helpMainEntranceDoor', false, true);
	var helpOtherExternalDoors = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpOtherExternalDoors', null, 'helpOtherExternalDoors', false, true);
	var helpPatioDoors = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpPatioDoors', null, 'helpPatioDoors', false, true);
	var helpAccessibleWindows = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpAccessibleWindows', null, 'helpAccessibleWindows', false, true);
	var helpBurglarAlarm = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpBurglarAlarm', null, 'helpBurglarAlarm', false, true);
	var helpSmokeAlarm = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpSmokeAlarm', null, 'helpSmokeAlarm', false, true);
	var helpCoverType = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpCoverType', null, 'helpCoverType', false, true);
	var helpPropertyVoluntaryExcess = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpPropertyVoluntaryExcess', null, 'helpPropertyVoluntaryExcess', false, true);
	var helpBuildingsAD = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpBuildingsAccidentalDamage', null, 'helpBuildingsAD', false, true);
	var helpContentsCoverAmount = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpContentsCoverAmount', null, 'helpContentsCoverAmount', false, true);
	var helpContentsAD = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpContentsAccidentalDamage', null, 'helpContentsAD', false, true);
	var helpMainOccupation = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpOccupation', null, 'helpMainOccupation', false, true);
	var helpUnion = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpUnion', null, 'helpUnion', false, true);
	var helpHouseNameNumberClient = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpHouseNumberNameClient', null, 'helpHouseNameNumberClient', false, true);
	var helpEmailAddress = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpEmailAddress', null, 'helpEmailAddress', false, true);	
	var helpExistingHomePolicyHolder = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpExistingHomePolicyHolder', null, 'helpExistingHomePolicyHolder', false, true);
	var helpJointPolicy = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpJointPolicy', null, 'helpJointPolicy', false, true);
	var helpClaims = new ShowHelp(LEFT_CONTENT_PREFIX + 'imgHelpClaims', null, 'helpClaims', false, true);
}

// Clear any date in the Inicident Details Pop Up
function clearInicidentDetailsPopUp()
{
	// Set up local variables again so we have them in their latest state.
	setUpLocalVariables();
	
	txtIncidentDate_Day.value = 'dd';
	txtIncidentDate_Month.value = 'mm';
	txtIncidentDate_Year.value = 'yyyy';
	txtIncidentDate.value = '';
    txtIncidentCost.value = '';
    ddlIncidentSectionAffected.selectedIndex = '0';
    ddlIncidentType.selectedIndex = '0';
    
    // Reset Incident Pop Up Validators
	resetIncidentPopUpValidators();
	
	//Hide validation summary
	incidentPopUpValidationSummary.style.display = 'none';
}


// Sets up the Auto complete lists
function setUpAutoCompleteLists()
{
	var mainOccupationsAutoComplete = new Autocomplete(LEFT_CONTENT_PREFIX + 'txtFullTimeOccupation', LEFT_CONTENT_PREFIX + 'lstFullTimeOccupation', LEFT_CONTENT_PREFIX + 'ddlFullTimeOccupation', 'autoCompleteWrapper', 'autoCompleteContent', null, null, LEFT_CONTENT_PREFIX + 'slidePanelFullTimeOccupation', LEFT_CONTENT_PREFIX + 'slideContentFullTimeOccupation', 75);
																																																													
    mainOccupationsAutoComplete.NoValueFoundListText = "No matching occupations found";
    mainOccupationsAutoComplete.ValueSelectedHelpText = "An occupation has been successfully selected from the list.";
    mainOccupationsAutoComplete.StartTypingHelpText = "Start typing your job title to search our list of occupations.";
    mainOccupationsAutoComplete.NoMatchesFoundHelpText = "<div style='margin-bottom: 5px;' class='title'>0 matches found</div>  Try a less specific description and choose the job title which best describes what you do.";
    mainOccupationsAutoComplete.OneMatchFoundHelpText = "<div style='margin-bottom: 5px;' class='title'>1 match found</div>  Please select the occupation which best describes what you do from the list.";
    mainOccupationsAutoComplete.MultipleMatchesFoundHelpText1 = "<div style='margin-bottom: 5px;' class='title'>";
    mainOccupationsAutoComplete.MultipleMatchesFoundHelpText2 = " matches found</div>  Please select the occupation which best describes what you do from the list.";
    mainOccupationsAutoComplete.filterList(false, 400, false, false);
    
    // Hide the drop down union list if we're using IE 6.
    if ($.browser.msie && $.browser.version == 6)
    {
		addEvent($get(LEFT_CONTENT_PREFIX + 'txtFullTimeOccupation'), "focus", txtFullTimeOccupation_OnFocus);
		addEvent($get(LEFT_CONTENT_PREFIX + 'txtFullTimeOccupation'), "blur", txtFullTimeOccupation_OnBlur);
	}
}

// Sets up the progress animations
function setUpProgress()
{
	//Set up progress image.
	showProgress = new ShowProgress(LEFT_CONTENT_PREFIX + 'imgProgress', LEFT_CONTENT_PREFIX + 'btnGetQuote', true);
	showProgress.UseAbsolute = false;
}

// Hide / Show relevant cover sections
function refreshCoverTypeDisplaySections() 
{
	var contentsDisplayed = false;
	var buildingsDisplayed = false;
	
	var ddlBuildingsVoluntaryExcess = ($get(LEFT_CONTENT_PREFIX + 'ddlBuildingsVoluntaryExcess'));
	var chkBuildingsAccidentalDamage = ($get(LEFT_CONTENT_PREFIX + 'chkBuildingsAccidentalDamage'));
	var txtContentsCoverAmount = ($get(LEFT_CONTENT_PREFIX + 'txtContentsCoverAmount'));
	var chkContentsAccidentalDamage = ($get(LEFT_CONTENT_PREFIX + 'chkContentsAccidentalDamage'));
	
	if (_ddlCoverType.value == LISTITEM_COVER_TYPE_BUILDINGS) 
	{
		buildingsDisplayed = true;
	}
	else if (_ddlCoverType.value == LISTITEM_COVER_TYPE_CONTENTS) 
	{
		contentsDisplayed = true;
	}
	else if (_ddlCoverType.value == LISTITEM_COVER_TYPE_BUILDINGS_CONTENTS) 
	{
		contentsDisplayed = true;
		buildingsDisplayed = true;
	}
	toggleDisplaySection(_divBuildingsCover, buildingsDisplayed, arrValidationBuildings);
	toggleDisplaySection(_divContentsCover, contentsDisplayed, arrValidationContents);
	
	// Resest buildings validation 
	validatorReset(arrValidationBuildings);
	val_BuildingsVoluntaryExcess.Reset();
	
	// Resest contents validation 
	validatorReset(arrValidationContents);
	val_ContentsCoverAmount.Reset();
	val_compareMax_ContentsCoverAmount.Reset();
	val_compareMin_ContentsCoverAmount.Reset();
	
	// Show contents excess help inside the buidlings eHelp if the customer has requested contents cover
	// This is rubbish I know and doesnt make sense but Marketing dont make sense!!!!!
	var divContentsExcessHelp = $get('divContentsExcessHelp');
	if (contentsDisplayed)
	    divContentsExcessHelp.style.display = 'block';
    else
        divContentsExcessHelp.style.display = 'none';
}


// Hide / Show Landlord Accredited Scheme Member Display section
function refreshLandlordAccreditedSchemeMemberDisplaySection(show)
{
	toggleDisplaySection(_divLandlordAccreditedSchemeMember, show, arrValidationLandlordAccreditedSchemeMember);
	
	// Resest validation 
	validatorReset(arrValidationLandlordAccreditedSchemeMember);
	val_LandlordAccreditedSchemeMember.Reset();
}

// Hide / Show Joint Policy Display section
function refreshJointPolicyDisplaySection(show)
{
	toggleDisplaySection(_divJointPolicyDetails, show, arrValidationJointPolicyDetails);
	
	// Resest validation 
	validatorReset(arrValidationJointPolicyDetails);
	val_FirstNameJoint.Reset();
	val_SurnameJoint.Reset();
	val_DateOfBirthJoint.Reset();
	val_compareMax_DateOfBirthJoint.Reset();
}

// Hide / Show Previous Claims Display section
function refreshPreviousClaimsDisplaySection(show)
{
	toggleDisplaySection(_divIncidentDetails, show, null);
}

// Hide / show parts of the quote page
function toggleDisplaySection(displaySection, show, validatorArray) 
{
	if (show)
	{
		displaySection.style.display = 'block';
		// Enable validators in the validatorArray
		if (validatorArray != null)
            validatorEnable(validatorArray);
	}
	else 
	{
		displaySection.style.display = 'none';
		// Disable validators in the validatorArray
		if (validatorArray != null)
			validatorDisable(validatorArray);
	}
}

function constructDate(dayField, monthField, yearField, targetField)
{
	var day = dayField.value;
    var month = monthField.value;
    var year = yearField.value;
    
	if (day.length == 0 || month.length == 0 || year.length == 0)
	{
		targetField.value = '';
	}
	else
	{
		if (day.length == 1)
			day = "0" + day;
		if (month.length == 1)
			month = "0" + month;
		if (year.length == 2)
			year = "20" + year;
        targetField.value = day + '/' + month + '/' + year;
	}
}

function toggleIncidentPopUpValidators(enable)
{
	$get(POP_UP_PREFIX + 'eccDV_IncidentDate').enabled = enable;
	$get(POP_UP_PREFIX + 'eccDV_compareMin_IncidentDate').enabled = enable;
	$get(POP_UP_PREFIX + 'eccDV_compareMax_IncidentDate').enabled = enable;
	$get(POP_UP_PREFIX + 'req_txtIncidentCost').enabled = enable;
	$get(POP_UP_PREFIX + 'compareMin_txtIncidentCost').enabled = enable;
	$get(POP_UP_PREFIX + 'compareMax_txtIncidentCost').enabled = enable;
	$get(POP_UP_PREFIX + 'req_ddlIncidentSectionAffected').enabled = enable;
	$get(POP_UP_PREFIX + 'req_ddlIncidentType').enabled = enable;

}

//******************************************************************************************
// Find address helper functions.
//******************************************************************************************

function findAddress(houseNameNumber, postcode, riskAddress, desc) 
{
	// Are we delaing with risk address or client's own address?
	if (riskAddress) 
	{
		if (validateAddressProperty()) 
		{
			// Risk address look up
			Endsleigh.AddressNamespace.WebService.Service.FindAddressMultiple(houseNameNumber, postcode, desc, FindAddress_ResponseProperty);
		}
	}
	else
	{
		if (validateAddressClient()) 
		{
			// Client address look up
			Endsleigh.AddressNamespace.WebService.Service.FindAddressMultiple(houseNameNumber, postcode, desc, FindAddress_ResponseClient);
		}	
	}
}

function refreshAddress(riskAddress)
{
	// Are we delaing with risk address or client's own address?
	if (riskAddress) 
	{
		if (_txtHouseNameNumberProperty.value != '' && _txtPostcodeProperty.value != '')
		{
			findAddress(_txtHouseNameNumberProperty.value, _txtPostcodeProperty.value, true, 'Property');
		}
	}
	else
	{
		if (_txtHouseNameNumberClient.value != '' && _txtPostcodeClient.value != '')
		{
			findAddress(_txtHouseNameNumberClient.value, _txtPostcodeClient.value, false, 'Client');
		}
	}
}

// Update the address fields.
function FindAddress_ResponseProperty(result, eventArgs)
{
	isPropertyAddressValid = false
	
	var addressHolder = $get('addressHolderProperty');
	var cust_validationAddressProperty = $get(LEFT_CONTENT_PREFIX + 'cust_validationAddressProperty');
	
	var AddressClientLabels = new Array();
	AddressClientLabels[0] = LEFT_CONTENT_PREFIX + 'lblHouseNumberOrNameProperty';
	AddressClientLabels[1] = LEFT_CONTENT_PREFIX + 'lblPostcodeProperty';

	var AddressClientInputs = new Array();
	AddressClientInputs[0] = LEFT_CONTENT_PREFIX + 'txtHouseNameNumberProperty';
	AddressClientInputs[1] = LEFT_CONTENT_PREFIX + 'txtPostcodeProperty';

	var val_AddressCustomValidationProperty = new Validator(LEFT_CONTENT_PREFIX + 'cust_validationAddressProperty', AddressClientLabels, AddressClientInputs, STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);

	// Hide Address holder
	addressHolder.style.display = 'none';
    
    // Set local variable (used in cust_validationAddressPropertyVgQuote_OnValidate)
    isPropertyAddressValid = result.IsValid;
    
    if (result.IsValid)
    {
    	// Allow 2 line address edit
    	addressHolder.innerHTML = result.AddressHtmlWithTwoLineEdit;
        
        //Set the specific margin for this page.
        $get('divAddressHtmlProperty').style.marginLeft = '283px';

        // Show Address Holder
        addressHolder.style.display = 'block';

        if (_hfAddressLine1Property.value != '') $get('lblAddressLine1Property').innerHTML = _hfAddressLine1Property.value;
        if (_hfAddressLine2Property.value != '') $get('lblAddressLine2Property').innerHTML = _hfAddressLine2Property.value;

        var txtAddressLine1 = $get('txtAddressLine1Property');
        var txtAddressLine2 = $get('txtAddressLine2Property');

        setUpAddressEditBoxes(txtAddressLine1, txtAddressLine2);

        // Address has been found so reset validator
        val_AddressCustomValidationProperty.Reset();
    }
    else
    {   	   	
    	// Validate in order to style inputs
    	val_AddressCustomValidationProperty.Validate();
    	
    	// Update validation summary
    	validationSummary($get(LEFT_CONTENT_PREFIX + 'validationSummaryAddressProperty'), new Array(cust_validationAddressProperty));
    }
}

// Update the address fields.
function FindAddress_ResponseClient(result, eventArgs) 
{
	isClientAddressValid = false;
	
	var addressHolder = $get('addressHolderClient');
	var cust_validationAddressClient = $get(LEFT_CONTENT_PREFIX + 'cust_validationAddressClient');

	var AddressClientLabels = new Array();
	AddressClientLabels[0] = LEFT_CONTENT_PREFIX + 'lblHouseNumberOrNameClient';
	AddressClientLabels[1] = LEFT_CONTENT_PREFIX + 'lblPostcodeClient';

	var AddressClientInputs = new Array();
	AddressClientInputs[0] = LEFT_CONTENT_PREFIX + 'txtHouseNameNumberClient';
	AddressClientInputs[1] = LEFT_CONTENT_PREFIX + 'txtPostcodeClient';

	var val_AddressCustomValidationClient = new Validator(LEFT_CONTENT_PREFIX + 'cust_validationAddressClient', AddressClientLabels, AddressClientInputs, STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);

	// Hide Address holder
	addressHolder.style.display = 'none';

	// Set local variable (used in cust_validationAddressClientVgQuote_OnValidate)
	isClientAddressValid = result.IsValid;
	
	if (result.IsValid) 
	{
		// Allow 2 line address edit
		addressHolder.innerHTML = result.AddressHtmlWithTwoLineEdit;
		
		//Set the specific margin for this page.
		$get('divAddressHtmlClient').style.marginLeft = '283px';
		
		// Show Address Holder
		addressHolder.style.display = 'block';

		if (_hfAddressLine1Client.value != '') $get('lblAddressLine1Client').innerHTML = _hfAddressLine1Client.value;
		if (_hfAddressLine2Client.value != '') $get('lblAddressLine2Client').innerHTML = _hfAddressLine2Client.value;

		var txtAddressLine1 = $get('txtAddressLine1Client');
		var txtAddressLine2 = $get('txtAddressLine2Client');

		setUpAddressEditBoxes(txtAddressLine1, txtAddressLine2);

		// Address has been found so reset validator
		val_AddressCustomValidationClient.Reset();
	}
	else 
	{	
		// Validate in order to style inputs 
		val_AddressCustomValidationClient.Validate();
		
		// Update validation summary
		validationSummary($get(LEFT_CONTENT_PREFIX + 'validationSummaryAddressClient'), new Array(cust_validationAddressClient));
	}
}

function setUpAddressEditBoxes(txtAddressLine1, txtAddressLine2) 
{
	//Style edit boxes to match the page's other imputs
	txtAddressLine1.classname = '';
	txtAddressLine2.classname = '';
	txtAddressLine1.style.backgroundColor = 'white';
	txtAddressLine2.style.backgroundColor = 'white';
	txtAddressLine1.style.color = 'black';
	txtAddressLine2.style.color = 'black';
	txtAddressLine1.style.width = _txtHouseNameNumberProperty.style.width
	txtAddressLine2.style.width = _txtHouseNameNumberProperty.style.width
}

function populateHiddenAddressFields()
{
	// Ensure that any Address edits are captured in the hidden fields 
	// (these are used when writing addresses to objects in the code behind)

	if ($get('lblAddressLine1Property') != null)
		_hfAddressLine1Property.value = $get('lblAddressLine1Property').innerHTML;
	
	if ($get('lblAddressLine2Property') != null)
		_hfAddressLine2Property.value = $get('lblAddressLine2Property').innerHTML;
	
	if ($get('lblAddressLine1Client') != null)
		_hfAddressLine1Client.value = $get('lblAddressLine1Client').innerHTML;

	if ($get('lblAddressLine2Client') != null) 
		_hfAddressLine2Client.value = $get('lblAddressLine2Client').innerHTML;
}

//******************************************************************************************
// Functions to handle AJAX responses
//******************************************************************************************

// General function to handle AJAX errors
function errorHandler(error) 
{
	// Simply direct user to message page
	window.location = PAGE_MESSAGE_SERVICE;
}

// Update the gender drop down selected value
function GetGender_Response(result, eventArgs)
{
	$get(LEFT_CONTENT_PREFIX + 'ddlGender').value = result;
}

function GetMissingFormData_Response(result, eventArgs)
{
	if (result)
	{
		$get(LEFT_CONTENT_PREFIX + 'txtFullTimeOccupation').value = result.FullTimeOccupation;
	}
}

//******************************************************************************************
// Validation code.
//******************************************************************************************

function validateIncidentPopUpInputs()
{
	var retVal = true;
	
	// Validate the page using the vgIncidentDetails validation group
	Validator.ValidatePage('vgIncidentDetails');

	// Validate & Check for invailid inputs 
	for (var x = 0; x < arrIncidentPopUpInputs.length; x++)
	{
		arrIncidentPopUpInputs[x].Validate();
		
		if (!arrIncidentPopUpInputs[x].IsValid)
			retVal = false;
	}
	
	// Close pop up window if pop up inputs are valid
	if (retVal)	
		hidePopUp(LEFT_CONTENT_PREFIX + 'popUpIncidentDetails');
		
	return retVal;
}

// Reset Incident Pop Up Validators
function resetIncidentPopUpValidators()
{
	for (var x = 0; x < arrIncidentPopUpInputs.length; x++)
	{
		arrIncidentPopUpInputs[x].Reset();	
	}
}

function validatePageInputs()
{
	// Validate the page using the vgQuote validation group
	Validator.ValidatePage('vgQuote');
	
	// Set up new Validator objects to validate & style inputs

	// Number of tenants array
	var NumberOfTenants = new Array();
	NumberOfTenants[0] = LEFT_CONTENT_PREFIX + 'txtStudents';
	NumberOfTenants[1] = LEFT_CONTENT_PREFIX + 'txtWorkingProfessional';
	NumberOfTenants[2] = LEFT_CONTENT_PREFIX + 'txtHousingAssociation';
	NumberOfTenants[3] = LEFT_CONTENT_PREFIX + 'txtAsylumSeeker';
	NumberOfTenants[4] = LEFT_CONTENT_PREFIX + 'txtHolidayRental';
	NumberOfTenants[5] = LEFT_CONTENT_PREFIX + 'txtOther';

	// Cover start date array
	var CoverStartDateInputs = new Array();
	CoverStartDateInputs[0] = LEFT_CONTENT_PREFIX + 'txtCoverStartDate_Day';
	CoverStartDateInputs[1] = LEFT_CONTENT_PREFIX + 'txtCoverStartDate_Month';
	CoverStartDateInputs[2] = LEFT_CONTENT_PREFIX + 'txtCoverStartDate_Year';
	
	// Date of birth array
	var DateOfBirthInputs = new Array();
	DateOfBirthInputs[0] = LEFT_CONTENT_PREFIX + 'txtDOB_Day';
	DateOfBirthInputs[1] = LEFT_CONTENT_PREFIX + 'txtDOB_Month';
	DateOfBirthInputs[2] = LEFT_CONTENT_PREFIX + 'txtDOB_Year';
	
	// Occupation array
	var OccupationInputs = new Array();
	OccupationInputs[0] = LEFT_CONTENT_PREFIX + 'txtFullTimeOccupation';
	OccupationInputs[1] = LEFT_CONTENT_PREFIX + 'lstFullTimeOccupation';
	
	var val_CoverStartDate = new Validator(LEFT_CONTENT_PREFIX + 'eccDV_CoverStartDate', LEFT_CONTENT_PREFIX + 'lblCoverStartDate', CoverStartDateInputs, STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);
	var val_compareMin_txtCoverStartDate = new Validator(LEFT_CONTENT_PREFIX + 'eccDV_compareMin_CoverStartDate', LEFT_CONTENT_PREFIX + 'lblCoverStartDate', CoverStartDateInputs, STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);
	var val_compareMax_txtCoverStartDate = new Validator(LEFT_CONTENT_PREFIX + 'eccDV_compareMax_CoverStartDate', LEFT_CONTENT_PREFIX + 'lblCoverStartDate', CoverStartDateInputs, STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);
	
	// Property info inputs	
	var val_TypeOfProperty = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlPropertyType', LEFT_CONTENT_PREFIX + 'lblTypeOfProperty', LEFT_CONTENT_PREFIX + 'ddlPropertyType', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);
	var val_NumberOfTenants = new Validator(LEFT_CONTENT_PREFIX + 'cust_NumberOfTenants', LEFT_CONTENT_PREFIX + 'lblNumberOfTenants', NumberOfTenants, STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_Bedrooms = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlBedrooms', LEFT_CONTENT_PREFIX + 'lblBedrooms', LEFT_CONTENT_PREFIX + 'ddlBedrooms', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_Bathrooms = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlBathrooms', LEFT_CONTENT_PREFIX + 'lblBathrooms', LEFT_CONTENT_PREFIX + 'ddlBathrooms', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_PropertyBuildDate = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlPropertyBuildDate', LEFT_CONTENT_PREFIX + 'lblPropertyBuildDate', LEFT_CONTENT_PREFIX + 'ddlPropertyBuildDate', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_OwnershipDuration = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlOwnershipDuration', LEFT_CONTENT_PREFIX + 'lblOwnershipDuration', LEFT_CONTENT_PREFIX + 'ddlOwnershipDuration', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_LettingType = new Validator(LEFT_CONTENT_PREFIX + 'req_radLettingType', LEFT_CONTENT_PREFIX + 'lblLettingType', LEFT_CONTENT_PREFIX + 'radLettingType', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_WallConstruction = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlWallConstruction', LEFT_CONTENT_PREFIX + 'lblWallConstruction', LEFT_CONTENT_PREFIX + 'ddlWallConstruction', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_RoofConstruction = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlRoofConstruction', LEFT_CONTENT_PREFIX + 'lblRoofConstruction', LEFT_CONTENT_PREFIX + 'ddlRoofConstruction', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_TenancyAgreement = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlTenancyAgreement', LEFT_CONTENT_PREFIX + 'lblTenancyAgreement', LEFT_CONTENT_PREFIX + 'ddlTenancyAgreement', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_LettingAgentManagement = new Validator(LEFT_CONTENT_PREFIX + 'req_radLettingAgentManagement', LEFT_CONTENT_PREFIX + 'lblLettingAgentManagement', LEFT_CONTENT_PREFIX + 'radLettingAgentManagement', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_TenantReferencing = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlTenantReferencing', LEFT_CONTENT_PREFIX + 'lblTenantReferencing', LEFT_CONTENT_PREFIX + 'ddlTenantReferencing', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_LandlordAccreditedScheme = new Validator(LEFT_CONTENT_PREFIX + 'req_radLandlordAccreditedScheme', LEFT_CONTENT_PREFIX + 'lblLandlordAccreditedScheme', LEFT_CONTENT_PREFIX + 'radLandlordAccreditedScheme', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	

	// Security info inputs
	var val_MainEntranceDoor = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlMainEntranceDoor', LEFT_CONTENT_PREFIX + 'lblMainEntranceDoor', LEFT_CONTENT_PREFIX + 'ddlMainEntranceDoor', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_OtherExternalDoors = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlOtherExternalDoors', LEFT_CONTENT_PREFIX + 'lblOtherExternalDoors', LEFT_CONTENT_PREFIX + 'ddlOtherExternalDoors', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_PatioDoors = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlPatioDoors', LEFT_CONTENT_PREFIX + 'lblPatioDoors', LEFT_CONTENT_PREFIX + 'ddlPatioDoors', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_AccessibleWindows = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlAccessibleWindows', LEFT_CONTENT_PREFIX + 'lblAccessibleWindows', LEFT_CONTENT_PREFIX + 'ddlAccessibleWindows', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);		
	var val_BurglarAlarm = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlBurglarAlarm', LEFT_CONTENT_PREFIX + 'lblBurglarAlarm', LEFT_CONTENT_PREFIX + 'ddlBurglarAlarm', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_SmokeAlarm = new Validator(LEFT_CONTENT_PREFIX + 'req_radSmokeAlarm', LEFT_CONTENT_PREFIX + 'lblSmokeAlarm', LEFT_CONTENT_PREFIX + 'radSmokeAlarm', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);		

	// Cover info inputs
	var val_CoverType = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlCoverType', LEFT_CONTENT_PREFIX + 'lblCoverType', LEFT_CONTENT_PREFIX + 'ddlCoverType', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);		
	
	// Client info inputs	
	var val_Title = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlTitle', LEFT_CONTENT_PREFIX + 'lblTitle', LEFT_CONTENT_PREFIX + 'ddlTitle', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);
	var val_FirstName = new Validator(LEFT_CONTENT_PREFIX + 'req_txtFirstName', LEFT_CONTENT_PREFIX + 'lblFirstName', LEFT_CONTENT_PREFIX + 'txtFirstName', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);
	var val_Surname = new Validator(LEFT_CONTENT_PREFIX + 'req_txtSurname', LEFT_CONTENT_PREFIX + 'lblSurname', LEFT_CONTENT_PREFIX + 'txtSurname', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);
	var val_DateOfBirth = new Validator(LEFT_CONTENT_PREFIX + 'eccDV_DateOfBirth', LEFT_CONTENT_PREFIX + 'lblDateOfBirth', DateOfBirthInputs, STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);
	var val_compareMax_DateOfBirth = new Validator(LEFT_CONTENT_PREFIX + 'eccDV_compareMax_DateOfBirth', LEFT_CONTENT_PREFIX + 'lblDateOfBirth', DateOfBirthInputs, STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);
	var val_Gender = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlGender', LEFT_CONTENT_PREFIX + 'lblGender', LEFT_CONTENT_PREFIX + 'ddlGender', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);
	var val_MaritalStatus = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlMaritalStatus', LEFT_CONTENT_PREFIX + 'lblMaritalStatus', LEFT_CONTENT_PREFIX + 'ddlMaritalStatus', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);
	var val_FullTimeOccupationRequired = new Validator(LEFT_CONTENT_PREFIX + 'req_txtFullTimeOccupation', LEFT_CONTENT_PREFIX + 'lblMainOccupationSearch', OccupationInputs, STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);
	var val_FullTimeOccupationCustom = new Validator(LEFT_CONTENT_PREFIX + 'cust_txtFullTimeOccupation', LEFT_CONTENT_PREFIX + 'lblSelectOccupation', OccupationInputs, STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);
	var val_TelephonenumberRequired = new Validator(LEFT_CONTENT_PREFIX + 'req_txtTelephoneNumber', LEFT_CONTENT_PREFIX + 'lblTelephonenumber', LEFT_CONTENT_PREFIX + 'txtTelephoneNumber', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_TelephonenumberRegularExpression = new Validator(LEFT_CONTENT_PREFIX + 'regex_txtTelephoneNumber', LEFT_CONTENT_PREFIX + 'lblTelephonenumber', LEFT_CONTENT_PREFIX + 'txtTelephoneNumber', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_EmailAddressRequired = new Validator(LEFT_CONTENT_PREFIX + 'req_txtEmailAddress', LEFT_CONTENT_PREFIX + 'lblEmailAddress', LEFT_CONTENT_PREFIX + 'txtEmailAddress', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_EmailAddressRegularExpression = new Validator(LEFT_CONTENT_PREFIX + 'regex_txtEmailAddress', LEFT_CONTENT_PREFIX + 'lblEmailAddress', LEFT_CONTENT_PREFIX + 'txtEmailAddress', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_txtHouseNameNumberPropertyVgQuote = new Validator(LEFT_CONTENT_PREFIX + 'req_txtHouseNameNumberPropertyVgQuote', LEFT_CONTENT_PREFIX + 'lblHouseNumberOrNameProperty', LEFT_CONTENT_PREFIX + 'txtHouseNameNumberProperty', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_txtPostcodePropertyVgQuote = new Validator(LEFT_CONTENT_PREFIX + 'req_txtPostcodePropertyVgQuote', LEFT_CONTENT_PREFIX + 'lblPostcodeProperty', LEFT_CONTENT_PREFIX + 'txtPostcodeProperty', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_txtHouseNameNumberClientVgQuote = new Validator(LEFT_CONTENT_PREFIX + 'req_txtHouseNameNumberClientVgQuote', LEFT_CONTENT_PREFIX + 'lblHouseNumberOrNameClient', LEFT_CONTENT_PREFIX + 'txtHouseNameNumberClient', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_txtPostcodeClientVgQuote = new Validator(LEFT_CONTENT_PREFIX + 'req_txtPostcodeClientVgQuote', LEFT_CONTENT_PREFIX + 'lblPostcodeClient', LEFT_CONTENT_PREFIX + 'txtPostcodeClient', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_PropertiesCurrentlyLet = new Validator(LEFT_CONTENT_PREFIX + 'req_txtPropertiesCurrentlyLet', LEFT_CONTENT_PREFIX + 'lblPropertiesCurrentlyLet', LEFT_CONTENT_PREFIX + 'txtPropertiesCurrentlyLet', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);
	var val_ExistingHomePolicyHolder = new Validator(LEFT_CONTENT_PREFIX + 'req_radExistingHomePolicyHolder', LEFT_CONTENT_PREFIX + 'lblExistingHomePolicyHolder', LEFT_CONTENT_PREFIX + 'radExistingHomePolicyHolder', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);
	var val_radJointPolicy = new Validator(LEFT_CONTENT_PREFIX + 'req_radJointPolicy', LEFT_CONTENT_PREFIX + 'lblJointPolicy', LEFT_CONTENT_PREFIX + 'radJointPolicy', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	
	// Claim inputs
	var val_YearsClaimFree = new Validator(LEFT_CONTENT_PREFIX + 'req_ddlYearsClaimFree', LEFT_CONTENT_PREFIX + 'lblYearsClaimFree', LEFT_CONTENT_PREFIX + 'ddlYearsClaimFree', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_PreviousClaims = new Validator(LEFT_CONTENT_PREFIX + 'req_radPreviousClaims', LEFT_CONTENT_PREFIX + 'lblPreviousClaims', LEFT_CONTENT_PREFIX + 'radPreviousClaims', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	

    // Validate inputs
    
    // Property info inputs	
    val_CoverStartDate.Validate();

    if (val_CoverStartDate.IsValid) 
    {    	
    	val_compareMin_txtCoverStartDate.Validate();
		val_compareMax_txtCoverStartDate.Validate();
    }

    val_TypeOfProperty.Validate();
    val_NumberOfTenants.Validate();
    val_Bedrooms.Validate();
	val_Bathrooms.Validate();
	val_PropertyBuildDate.Validate();
	val_OwnershipDuration.Validate();
	val_LettingType.Validate();
	val_WallConstruction.Validate();
	val_RoofConstruction.Validate();
	val_TenancyAgreement.Validate(); 
	val_LettingAgentManagement.Validate(); 
	val_TenantReferencing.Validate(); 
	val_LandlordAccreditedScheme.Validate();
	// val_LandlordAccreditedSchemeMember validator should only be enabled if the client has said they are a member of such a scheme
	// see function refreshLandlordAccreditedSchemeMemberDisplaySection
	var req_ddlLandlordAccreditedSchemeMember = ($get(LEFT_CONTENT_PREFIX + 'req_ddlLandlordAccreditedSchemeMember'));
	if (req_ddlLandlordAccreditedSchemeMember.enabled == true)
	{
		val_LandlordAccreditedSchemeMember.Validate();
	}
	else
	{
		val_LandlordAccreditedSchemeMember.Reset();		
	}
	
	//Security info inputs
	val_MainEntranceDoor.Validate(); 
	val_OtherExternalDoors.Validate(); 
	val_PatioDoors.Validate(); 
	val_AccessibleWindows.Validate(); 
	val_BurglarAlarm.Validate(); 
	val_SmokeAlarm.Validate(); 
    
    // Cover info inputs
    val_CoverType.Validate();
    
	var req_ddlBuildingsVoluntaryExcess = ($get(LEFT_CONTENT_PREFIX + 'req_ddlBuildingsVoluntaryExcess'));
	var req_txtContentsCoverAmount = ($get(LEFT_CONTENT_PREFIX + 'req_txtContentsCoverAmount'));
	var compareMax_txtContentsCoverAmount = ($get(LEFT_CONTENT_PREFIX + 'compareMax_txtContentsCoverAmount'));
	var compareMin_txtContentsCoverAmount = ($get(LEFT_CONTENT_PREFIX + 'compareMin_txtContentsCoverAmount'));
    
    // Buildings / Contents validators should only be enabled if the cover type has been requested
    // see function toggleDisplaySection(displaySection, show, validatorArray) 
    if (req_ddlBuildingsVoluntaryExcess.enabled == true)
    {
		val_BuildingsVoluntaryExcess.Validate();
	}
	else
	{
		val_BuildingsVoluntaryExcess.Reset();		
	}

	if (req_txtContentsCoverAmount.enabled == true) 
	{
		val_ContentsCoverAmount.Validate();
		val_compareMax_ContentsCoverAmount.Validate();
		val_compareMin_ContentsCoverAmount.Validate();
	}
	else 
	{
		val_ContentsCoverAmount.Reset();
		val_compareMax_ContentsCoverAmount.Reset();
		val_compareMin_ContentsCoverAmount.Reset();
	}
    
    // Client info inputs
    val_Title.Validate();
    val_FirstName.Validate();
    val_Surname.Validate();
    val_DateOfBirth.Validate();

    if (val_DateOfBirth.IsValid) 
    {
    	val_compareMax_DateOfBirth.Validate();
    }
    
    val_Gender.Validate();
    val_MaritalStatus.Validate();
    val_FullTimeOccupationRequired.Validate();
    
    if (val_FullTimeOccupationRequired.IsValid)
    {
		val_FullTimeOccupationCustom.Validate();
	}
	
	val_TelephonenumberRequired.Validate();
	val_TelephonenumberRegularExpression.Validate();
	val_EmailAddressRequired.Validate();
	val_EmailAddressRegularExpression.Validate();
	val_txtHouseNameNumberPropertyVgQuote.Validate();
	val_txtPostcodePropertyVgQuote.Validate();
	val_txtHouseNameNumberClientVgQuote.Validate();
	val_txtPostcodeClientVgQuote.Validate();
	val_PropertiesCurrentlyLet.Validate();
    val_ExistingHomePolicyHolder.Validate();
	val_radJointPolicy.Validate();
	
	// Joint policy inputs
	var req_txtFirstNameJoint = $get(LEFT_CONTENT_PREFIX + 'req_txtFirstNameJoint');
	var req_txtSurnameJoint = $get(LEFT_CONTENT_PREFIX + 'req_txtSurnameJoint');
	var eccDV_DateOfBirthJoint = $get(LEFT_CONTENT_PREFIX + 'eccDV_DateOfBirthJoint');
	var eccDV_compareMax_DateOfBirthJoint = $get(LEFT_CONTENT_PREFIX + 'eccDV_compareMax_DateOfBirthJoint');
    
    // Joint policy validators should only be enabled if Joint Policy has been requested
    // see function refreshJointPolicyDisplaySection
	if (req_txtFirstNameJoint.enabled == true)
    {
		val_FirstNameJoint.Validate();
	}
	else
	{
		val_FirstNameJoint.Reset();
	}

	if (req_txtSurnameJoint.enabled == true)
    {
		val_SurnameJoint.Validate();
	}
	else
	{
		val_SurnameJoint.Reset();
	}
	
	if (eccDV_DateOfBirthJoint.enabled == true)
    {
		val_compareMax_DateOfBirthJoint.Validate();
	}
	else
	{
		val_compareMax_DateOfBirthJoint.Reset();
	}
	
	if (eccDV_compareMax_DateOfBirthJoint.enabled == true)
    {
		val_DateOfBirthJoint.Validate();
	}
	else
	{
		val_DateOfBirthJoint.Reset();
	}
	
	// Claim inputs
	val_YearsClaimFree.Validate();
	val_PreviousClaims.Validate();
	
	if (val_PreviousClaims.IsValid) 
		val_custPreviousClaims.Validate();
		
}

// Tests the address fields to see if the data is valid.
// Displays error icons + error text if not.
function validateAddressProperty()
{
	var retVal = true;
	
	Validator.ValidatePage('vgAddressProperty');
	
	var val_HouseNumberOrNameProperty = new Validator(LEFT_CONTENT_PREFIX + 'req_txtHouseNameNumberProperty', LEFT_CONTENT_PREFIX + 'lblHouseNumberOrNameProperty', LEFT_CONTENT_PREFIX + 'txtHouseNameNumberProperty', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_PostcodeRequiredProperty = new Validator(LEFT_CONTENT_PREFIX + 'req_txtPostcodeProperty', LEFT_CONTENT_PREFIX + 'lblPostcodeProperty', LEFT_CONTENT_PREFIX + 'txtPostcodeProperty', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_PostcodeRegularExpressionProperty = new Validator(LEFT_CONTENT_PREFIX + 'regex_txtPostcodeProperty', LEFT_CONTENT_PREFIX + 'lblPostcodeProperty', LEFT_CONTENT_PREFIX + 'txtPostcodeProperty', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
			
	val_HouseNumberOrNameProperty.Validate();
	val_PostcodeRequiredProperty.Validate();
	if (val_PostcodeRequiredProperty.IsValid)
	    val_PostcodeRegularExpressionProperty.Validate();
	
	var arrAddressProperty = new Array();
	arrAddressProperty[0] = val_HouseNumberOrNameProperty;
	arrAddressProperty[1] = val_PostcodeRequiredProperty;
	arrAddressProperty[2] = val_PostcodeRegularExpressionProperty;
	
	var itemValid = true; 
	
	for (var x = 0; x < arrAddressProperty.length; x++)
		if (!arrAddressProperty[x].IsValid)
		itemValid = false;
	
	if (itemValid) 
	{
		// Hide the validation Summary
		$get(LEFT_CONTENT_PREFIX + 'validationSummaryAddressProperty').style.display = 'none';
	}
	else
	{
		// This is a bug fix for the Chrome browser.  
		// IF the page fails validation the default .net behaviour is to go back to the top of the page. 
		// However, we tend to override this and scroll to something on the page.
		// This causes display issues with the page in Chrome as the DOM doesnt update corectly.
		// So for Chrome, go to the top of the page and show an error div with instructions to the customer.
		
		var Browser = new BrowserInfo();
		if (Browser.IsChrome)
		{
			$get('divChromeErrors').style.display = 'block';
		}
		else
		{
			// Scroll to the label above the validation summmary - 
			// a bit of a frigh but scrolling to the validation summary caused display issues in IE7!
			scrollToElement($get(LEFT_CONTENT_PREFIX + 'lblTypeOfProperty'));
			retVal = false;
		}
	}

	return retVal;
}

function validateAddressClient()
{
	var retVal = true;

	Validator.ValidatePage('vgAddressClient');

	var val_HouseNumberOrNameClient = new Validator(LEFT_CONTENT_PREFIX + 'req_txtHouseNameNumberClient', LEFT_CONTENT_PREFIX + 'lblHouseNumberOrNameClient', LEFT_CONTENT_PREFIX + 'txtHouseNameNumberClient', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_PostcodeRequiredClient = new Validator(LEFT_CONTENT_PREFIX + 'req_txtPostcodeClient', LEFT_CONTENT_PREFIX + 'lblPostcodeClient', LEFT_CONTENT_PREFIX + 'txtPostcodeClient', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	var val_PostcodeRegularExpressionClient = new Validator(LEFT_CONTENT_PREFIX + 'regex_txtPostcodeClient', LEFT_CONTENT_PREFIX + 'lblPostcodeClient', LEFT_CONTENT_PREFIX + 'txtPostcodeClient', STYLE_LABEL_ERROR, STYLE_INPUT_ERROR);	
	
	val_HouseNumberOrNameClient.Validate();
	val_PostcodeRequiredClient.Validate();
	if (val_PostcodeRequiredClient.IsValid)
	    val_PostcodeRegularExpressionClient.Validate();
	
	var arrAddressClient = new Array();
	arrAddressClient[0] = val_HouseNumberOrNameClient;
	arrAddressClient[1] = val_PostcodeRequiredClient;
	arrAddressClient[2] = val_PostcodeRegularExpressionClient;
	
	var itemValid = true; 
	
	for (var x = 0; x < arrAddressClient.length; x++)
		if (!arrAddressClient[x].IsValid)
		itemValid = false;
	
	if (itemValid) 
	{
		// Hide the validation Summary
		$get(LEFT_CONTENT_PREFIX + 'validationSummaryAddressClient').style.display = 'none';
	}
	else
	{
		// This is a bug fix for the Chrome browser.  
		// IF the page fails validation the default .net behaviour is to go back to the top of the page. 
		// However, we tend to override this and scroll to something on the page.
		// This causes display issues with the page in Chrome as the DOM doesnt update corectly.
		// So for Chrome, go to the top of the page and show an error div with instructions to the customer.
		
		var Browser = new BrowserInfo();
		if (Browser.IsChrome)
		{
			$get('divChromeErrors').style.display = 'block';
		}
		else
		{
			scrollToElement($get(LEFT_CONTENT_PREFIX + 'validationSummaryAddressClient'));
			retVal = false;
		}
	}

	return retVal;
}

// Function for the Full Time Occupation Custom validator 
function cust_txtFullTimeOccupation_OnValidate(source, arguments)
{
	var retVal = false;
    var txtFullTimeOccupation = ($get(LEFT_CONTENT_PREFIX + 'txtFullTimeOccupation'));
    var lstFullTimeOccupation = ($get(LEFT_CONTENT_PREFIX + 'lstFullTimeOccupation'));
    var cust_txtFullTimeOccupation = ($get(LEFT_CONTENT_PREFIX + 'cust_txtFullTimeOccupation'));
    var slidePanelFullTimeOccupation = ( $get(LEFT_CONTENT_PREFIX + 'slidePanelFullTimeOccupation'));
    
	if (txtFullTimeOccupation.value.length >=3)
	{
		// Check if we have an item selected
		for (var x = 0; x < lstFullTimeOccupation.options.length; x++)
		{
			// Check that the text in the textbox does not = "No occupation selected" (option value="000")
			if ((lstFullTimeOccupation.options[x].value == 000) & (lstFullTimeOccupation.options[x].text == txtFullTimeOccupation.value))
			{
				retVal = false;
				break;
			}
			// Check that the entry in the text box matches the text in the list box
			if (lstFullTimeOccupation.options[x].text == txtFullTimeOccupation.value)
			{
				retVal = true;
				break;
			}
		}
	}
    
    arguments.IsValid = retVal;
    
    if (arguments.IsValid == false)
        // Slide panel to display list if required
        slidePanelFullTimeOccupation.style.display = 'block';
    
    return retVal;
}

// Check that at some tenents have been entered
function cust_NumberOfTenants_OnValidate(source, arguments)
{
	var retVal = false;
	
	// Number of tenants array
	var NumberOfTenants = new Array();
	NumberOfTenants[0] = txtStudents = ($get(LEFT_CONTENT_PREFIX + 'txtStudents'));;
	NumberOfTenants[1] = txtWorkingProfessional = ($get(LEFT_CONTENT_PREFIX + 'txtWorkingProfessional'));;
	NumberOfTenants[2] = txtHousingAssociation = ($get(LEFT_CONTENT_PREFIX + 'txtHousingAssociation'));;
	NumberOfTenants[3] = txtAsylumSeeker = ($get(LEFT_CONTENT_PREFIX + 'txtAsylumSeeker'));;
	NumberOfTenants[4] = txtHolidayRental = ($get(LEFT_CONTENT_PREFIX + 'txtHolidayRental'));;
	NumberOfTenants[5] = txtOther = ($get(LEFT_CONTENT_PREFIX + 'txtOther'));;
	
	for (var i = 0; i < NumberOfTenants.length; i++) 
	{
		// Test that the input has a value
		if 	(NumberOfTenants[i].value.length > 0)
		{
			// Test that the value is not "0"
			if 	(parseInt(NumberOfTenants[i].value, 10) > 0)
			{
				retVal = true;	
			}
		}
	}

	arguments.IsValid = retVal;
	
	return retVal;
}

function cust_validationAddressClient_OnValidate(sender, args) 
{
	// Set the IsValid property on the custom validator based on the local variable isClientAddressValid
	// that is set on address look up - see function FindAddress_ResponseClient()
	args.IsValid = isClientAddressValid;
}

function cust_validationAddressProperty_OnValidate(sender, args) 
{
	// Set the IsValid property on the custom validator based on the local variable isPropertyAddressValid
	// that is set on address look up - see function FindAddress_ResponseProperty()
	args.IsValid = isPropertyAddressValid;
}

// Check that any claims have been added by looking at the childNode length of the update panel
function cust_radPreviousClaims_OnValidate(source, arguments)
{
	var retVal = true;

	var pannelLengthNoChildren = 3;
	var Browser = new BrowserInfo();
	if (Browser.IsIE)
		pannelLengthNoChildren = 1;

	if ($get(LEFT_CONTENT_PREFIX + 'radPreviousClaims_0').checked)
		retVal = $get(LEFT_CONTENT_PREFIX + 'pnlIncidentDetails').childNodes.length > pannelLengthNoChildren
	else
		retVal = true;

	arguments.IsValid = retVal;
	return retVal;
}

//******************************************************************************************
// General events.
//******************************************************************************************

// Notify the ScriptManager that the JS file has finished loading
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(AJAXRequest_Finished);
