
var $ = jQuery.noConflict();

function GetPageFilename()
{
    var strPageFilename = window.location.pathname.toLowerCase();
    
    strPageFilename = strPageFilename.substring( strPageFilename.lastIndexOf( "/" ) + 1 );
    
    return strPageFilename;
}

function InitBakersComparisonSchemeLivery()
//$( document ).ready( function( e )
{
//	//** IE fix for drop down menus with large values **/
//	var browserName = navigator.appName;
//	
//	if ( browserName == "Microsoft Internet Explorer" )
//	{
//	    // Function to expand the selection box
//		var expand = function()
//		{
//		    // Capture the original width the first time round
//			if( $( this ).data( 'origWidth' ) == undefined )
//			    $( this ).data( 'origWidth', $(this).css( 'width' ) );
//	
//			// Expand the select
//			$( this )
//		        .addClass( 'expand' )
//				.css( "width", "auto" );
//        }
//	
//		// Function to contract the selection box
//		var contract = function()
//		{
//		    // No hide workaround for IE6 to stop the element contacting when clicked
//			if( !$(this).data( 'noHide' ) )
//			    $( this )
//                    .removeClass( 'expand' )
//				    .css( "width", $( this ).data( 'origWidth' ) );
//        }
//	
//		// Set the noHide workaround on focus and blur
//		var focus = function()
//		{
//		    $( this ).data( 'noHide', true );
//		}
//		
//		var blur = function()
//		{
//		    $( this ).data( 'noHide', false );
//		    contract.call( this );
//		}
//			
//		/** Add IDs into the two statements where needed e.g. $('#f-aboutus, #f-field1, #f-field2')  **/
//		if( $.browser.version.substr( 0, 1 ) < 7 )
//		{
//		    // IE6
//			$( '#ctl00_ContentPlaceHolderMain_ddlWhereHeardAboutUs' )
//                .hover( expand, contract )
//				.focus( focus )
//				.click( focus )
//				.blur( blur )
//				.change( blur );
//	
//        }
//        else
//        {
//            //IE7 >
//			$( '#ctl00_ContentPlaceHolderMain_ddlWhereHeardAboutUs' )
//                .mousedown( expand )
//				.change( contract )
//				.blur( contract );
//        }
//    }					   
	
	/** ADDITIONAL INFO BOXES - USING QTIP JQUERY PLUGIN **/
	
    $( 'a.additional-info' ).cluetip( { activation: 'hover', width: 200 } );
	
	/** FOCUS AND BLUR EVENTS FOR INPUT ELEMENTS REQUIRED FOR IE **/
	$( '.xs-txt, .xs-txt-error, .s-txt, .s-txt-error, .m-txt, m-txt-error, .m-txt-date, .m-txt-date-error, .m-txt-currency, .m-txt-currency-error, .l-txt, .l-txt-error' ).focus( function()
	{
		$( this ).addClass( 'field-highlight' );
 		$( this ).parent().addClass( 'label-highlight' );
	});
	
	$( '.xs-txt, .xs-txt-error, .s-txt, .s-txt-error, .m-txt, m-txt-error, .m-txt-date, .m-txt-date-error, .m-txt-currency, .m-txt-currency-error, .l-txt, .l-txt-error' ).blur( function()
	{
		$( this ).removeClass( 'field-highlight' );
 		$( this ).parent().removeClass( 'label-highlight' );
	});
	
	$( '.radio' ).focus( function()
	{
 		$( this ).parent().addClass( 'label-highlight' );
		$( this ).parent().parent().addClass( 'label-highlight' );
	});
	
	$( '.radio' ).blur( function()
	{
 		$( this ).parent().removeClass( 'label-highlight' );
		$( this ).parent().parent().removeClass( 'label-highlight' );
	});
	
	// Set events for SELECT elements
	$( "#ctl00_ContentPlaceHolderMain_ddlClient1Title, #ctl00_ContentPlaceHolderMain_ddlNumOfClaims, #ctl00_ContentPlaceHolderMain_ddlWhereHeardAboutUs, select[id*='ctl00_ContentPlaceHolderMain_ddlClaimType'], #ctl00_ContentPlaceHolderMain_ddlManufactureYear, #ctl00_ContentPlaceHolderMain_ddlStorageLocationType, #ctl00_ContentPlaceHolderMain_ddlTrackingDevice, #ctl00_ContentPlaceHolderMain_ddlWheelLockDevice, #ctl00_ContentPlaceHolderMain_ddlOccupationType, #ctl00_ContentPlaceHolderMain_ddlCaravanMake, #ctl00_ContentPlaceHolderMain_HomeAddressDetails1_ddlFoundAddresses, #ctl00_ContentPlaceHolderMain_StorageAddressDetails1_ddlFoundAddresses" ).focus( function()
	{
	    $( this ).addClass( 'field-highlight' );
 		$( this ).parent().addClass( 'label-highlight' );
	} );
	
	// Set events for 'non-expandable' SELECT elements
	$( "#ctl00_ContentPlaceHolderMain_ddlClient1Title, #ctl00_ContentPlaceHolderMain_ddlNumOfClaims, #ctl00_ContentPlaceHolderMain_ddlManufactureYear, #ctl00_ContentPlaceHolderMain_ddlCaravanMake" ).blur( function()
	{
	    $( this ).removeClass( 'field-highlight' );
 		$( this ).parent().removeClass( 'label-highlight' );
	} );
	
	$( "#ctl00_ContentPlaceHolderMain_ddlClient1Title, #ctl00_ContentPlaceHolderMain_ddlNumOfClaims, #ctl00_ContentPlaceHolderMain_ddlManufactureYear, #ctl00_ContentPlaceHolderMain_ddlCaravanMake" ).mousedown( function()
	{
	    // The mouseDown even handler is used to highlight the Drop-down field when the user selects the Drop-down using the mouse.
	    // Without this event, the Drop-down's focus event handler will highlight the control, but then will prevent the Drop-down list from being shown, therefore the user will need to "click" on
	    // the Drop-down twice to see the selection list.
	    // Normal operation of a Drop-down is that you it "click" once to see the selection list.
	    $( this ).addClass( 'field-highlight' );
 		$( this ).parent().addClass( 'label-highlight' );
	} );
	
	// Set events for 'expandable' SELECT elements.
	// As the SELECT elements/Drop-downs have fixed length, which are not long enough for certain items in the Drop-downs, these Drop-downs need to be expanded to allow the user to see
	// the "long-worded" options, and then return to its fixed length after the user has either selected an option, or lost "focus" on the Drop-down.
	// The two variables below are used to track the Change and Click events of the drop-down - the tracking is required to track whether the user has re-selected the currently selected option using the
	// mouse, as the Change event is not raised.
	var _fDDLChanged = false;
	var _fDDLClicked = false;
	
	$( "#ctl00_ContentPlaceHolderMain_ddlWhereHeardAboutUs, select[id*='ctl00_ContentPlaceHolderMain_ddlClaimType'], #ctl00_ContentPlaceHolderMain_ddlStorageLocationType, #ctl00_ContentPlaceHolderMain_ddlTrackingDevice, #ctl00_ContentPlaceHolderMain_ddlWheelLockDevice, #ctl00_ContentPlaceHolderMain_ddlOccupationType, #ctl00_ContentPlaceHolderMain_HomeAddressDetails1_ddlFoundAddresses, #ctl00_ContentPlaceHolderMain_StorageAddressDetails1_ddlFoundAddresses" ).blur( function()
	{
	    // The user has lost focus on the Drop-down.
	    
	    // Reset the Drop-down events tracking variables.
	    _fDDLChanged = false;
	    _fDDLClicked = false;
	    
	    // De-highlight the Drop-down and its label
	    $( this ).removeClass( 'field-highlight' );
 		$( this ).parent().removeClass( 'label-highlight' );
 		
 		// Set the Drop-down's width to its original fixed length
 		if ( $( this ).data( 'origWidth' ) != undefined )
            $( this ).css( "width", $( this ).data( 'origWidth' ) );
	} );
	
	$( "#ctl00_ContentPlaceHolderMain_ddlWhereHeardAboutUs, select[id*='ctl00_ContentPlaceHolderMain_ddlClaimType'], #ctl00_ContentPlaceHolderMain_ddlStorageLocationType, #ctl00_ContentPlaceHolderMain_ddlTrackingDevice, #ctl00_ContentPlaceHolderMain_ddlWheelLockDevice, #ctl00_ContentPlaceHolderMain_ddlOccupationType" ).change( function()
	{
	    // The user has selected an option in the Drop-down, which is different from the currently selected one.
	
	    // Set the Change event tracking variable to true.
	    _fDDLChanged = true;
	    
	    // Set the Drop-down's width to its original fixed length
        $( this ).css( "width", $( this ).data( 'origWidth' ) );
	} );
	
	$( "#ctl00_ContentPlaceHolderMain_ddlWhereHeardAboutUs, select[id*='ctl00_ContentPlaceHolderMain_ddlClaimType'], #ctl00_ContentPlaceHolderMain_ddlStorageLocationType, #ctl00_ContentPlaceHolderMain_ddlTrackingDevice, #ctl00_ContentPlaceHolderMain_ddlWheelLockDevice, #ctl00_ContentPlaceHolderMain_ddlOccupationType, #ctl00_ContentPlaceHolderMain_HomeAddressDetails1_ddlFoundAddresses, #ctl00_ContentPlaceHolderMain_StorageAddressDetails1_ddlFoundAddresses" ).click( function()
	{
	    // The user has clicked on the Drop-down.
	
        if ( _fDDLClicked == false )
            // It is assumed at this point the user has "Clicked" on the Drop-down to make the Drop-down list appear.
            // No need to expand the Drop-down to allow the "longest-worded" option to be displayed, as this has been done by the MouseDown event.
            // If this has done now, then a change the Drop-down now, will make the Drop-down list disappear.
            // Set the Click event tracking variable to true.
            _fDDLClicked = true;
        else
        {
            // It is assumed at this point the user has "Clicked" on the Drop-down's list to select on option.
            if ( _fDDLChanged == true )
                // As the user has selected an option which is different from the current one selected, then the Drop-down's Change event handler has reset its width to its original fixed length, and
                // there is no need to this now.
                // The Change event can only change the width of the Drop-down, otherwise just using this event to change the Drop-down's width, will prevent the Drop-down selected option from being
                // selected.
                // Reset the Change event tracking variable to false.
                _fDDLChanged = false;
            else
                // Set the Drop-down's width to its original fixed length, as the user has selected an option which is the same as the currently selected one.
                $( this ).css( "width", $( this ).data( 'origWidth' ) );
            
            // Reset the Click event tracking variable to false
            _fDDLClicked = false;
        }
	} );
	
	$( "#ctl00_ContentPlaceHolderMain_ddlWhereHeardAboutUs, select[id*='ctl00_ContentPlaceHolderMain_ddlClaimType'], #ctl00_ContentPlaceHolderMain_ddlStorageLocationType, #ctl00_ContentPlaceHolderMain_ddlTrackingDevice, #ctl00_ContentPlaceHolderMain_ddlWheelLockDevice, #ctl00_ContentPlaceHolderMain_ddlOccupationType, #ctl00_ContentPlaceHolderMain_HomeAddressDetails1_ddlFoundAddresses, #ctl00_ContentPlaceHolderMain_StorageAddressDetails1_ddlFoundAddresses" ).keypress( function( event )
	{
	    // The user has pressed a button on the keyboard whilst the Drop-down has been on "focus".
	    // Check to see if they have pressed the Return key.
        if ( event.keyCode == "13" )
        {
            // The user has pressed the Return key to select the option instead of using the mouse.
            
            // Reset the Drop-down events tracking variables.
            _fDDLChanged = false;
	        _fDDLClicked = false;
	        
	        // Set the Drop-down's width to its original fixed length
	        $( this ).css( "width", $( this ).data( 'origWidth' ) );
        }
	} );
	
	$( "#ctl00_ContentPlaceHolderMain_ddlWhereHeardAboutUs, select[id*='ctl00_ContentPlaceHolderMain_ddlClaimType'], #ctl00_ContentPlaceHolderMain_ddlStorageLocationType, #ctl00_ContentPlaceHolderMain_ddlTrackingDevice, #ctl00_ContentPlaceHolderMain_ddlWheelLockDevice, #ctl00_ContentPlaceHolderMain_ddlOccupationType, #ctl00_ContentPlaceHolderMain_HomeAddressDetails1_ddlFoundAddresses, #ctl00_ContentPlaceHolderMain_StorageAddressDetails1_ddlFoundAddresses" ).mousedown( function()
	{
	    // The user has the mouse pointer over the Drop-down and has pushed the left mouse button down to "click" on it.
	    // It is assumed that the user wants to make the Drop-down list appear on the screen, so therefore the Drop-down needs its width expanded to allow the "longest-worded" option to be displayed in
	    // full.
	    // Expanding the width here, instead of doing at the Click event handler will prevent the list from disappearing when the width of the Drop-down had changed.
	
        // Get the original width of the Drop-down is not defined.
        if ( $( this ).data( 'origWidth' ) == undefined )
            $( this ).data( 'origWidth', $( this ).css( 'width' ) );

        // Highlight the Drop-down and its label         
        $( this ).addClass( 'field-highlight' );
 		$( this ).parent().addClass( 'label-highlight' );
 		
 		// Set the Drop-down's width to allow it to display the "longest-worded" option
 		$( this ).css( "width", "auto" );
	} );
	
	$( "#ctl00_ContentPlaceHolderMain_HomeAddressDetails1_ddlFoundAddresses" ).change( function()
	{
	    // The user has selected an option in the Drop-down, which is different from the currently selected one.
	
	    // Set the Change event tracking variable to true.
	    _fDDLChanged = true;
	    
	    // Set the Drop-down's width to its original fixed length
        $( this ).css( "width", $( this ).data( 'origWidth' ) );
        
        // Call the FindAddressAndPopulate function regarding this drop-down
        FindAddressAndPopulate( $( "#ctl00_ContentPlaceHolderMain_HomeAddressDetails1_ddlFoundAddresses" ) );
	} );
	
	$( "#ctl00_ContentPlaceHolderMain_StorageAddressDetails1_ddlFoundAddresses" ).change( function()
	{
	    // The user has selected an option in the Drop-down, which is different from the currently selected one.
	
	    // Set the Change event tracking variable to true.
	    _fDDLChanged = true;
	    
	    // Set the Drop-down's width to its original fixed length
        $( this ).css( "width", $( this ).data( 'origWidth' ) );
        
        // Call the FindAddressAndPopulate function regarding this drop-down
        FindAddressAndPopulate( $( "#ctl00_ContentPlaceHolderMain_StorageAddressDetails1_ddlFoundAddresses" ) );
	} );
	
	/** DATE PICKER **/
	// Set Date Pickers
	$( "#ctl00_ContentPlaceHolderMain_txtCoverStartDate" ).datepicker(
	{
	    dateFormat: "dd/mm/yy",
	    minDate: 0,
	    maxDate: 30
	} );
	
	$( "input[id*='ctl00_ContentPlaceHolderMain_txtClaimDate']" ).datepicker(
	{
	    dateFormat: 'dd/mm/yy',
	    minDate: "-3y",
	    maxDate: 0,
	    changeYear: true
	} );
	
	$( "#ctl00_ContentPlaceHolderMain_txtDOB" ).datepicker(
	{
	    dateFormat: "dd/mm/yy",
	    minDate: "-120y",
	    maxDate: "-18y",
	    changeYear: true,
	    yearRange: "-120y,-18y"
	} );
	
//	/** INVALID FIELD INDICATION MANAGEMENT **/
//	// The following code ensures that invalid fields are highlighted.
//	$( "span.validation-error" ).bind( "DOMAttrModified propertychange", function( e )
//	{
//	    // Exit early if IE because it throws this event lots more
//	    if ( e.originalEvent.propertyName && e.originalEvent.propertyName != "isvalid" )
//	        return;
//	        
//	    var controlToValidate = $( "#" + this.controltovalidate );
//	    var validators = controlToValidate.attr( "Validators" );
//	    
//	    if ( validators == null )
//	        return;
//	        
//	    var isValid = true;
//	    
//	    $( validators ).each( function()
//	    {
//	        if ( this.isvalid !== true )
//	            isValid = false;
//	    });
//	    
//	    if ( isValid )
//	    {
//	        controlToValidate.removeClass( "l-txt-error" );
//	        controlToValidate.addClass( "l-txt" );
//	    }
//	    else
//	    {
//	        controlToValidate.removeClass( "l-txt" );
//	        controlToValidate.addClass( "l-txt-error" );
//	    }
//	});
	
//	if ( $( 'body' ).is( '#Quote' ) )
//	{
//		$( function()
//		{
//		    $( "#slider" ).slider(
//		    {
//				value:100,
//				min: 0,
//				max: 500,
//				step: 50,
//				slide: function( event, ui )
//				{
//					$( "#f-excess" ).val( ui.value );
//				}
//			});
//			$( "#f-excess" ).val( $( "#slider" ).slider( "value" ) );
//			
//			$("#slider2").slider(
//			{
//				value:0,
//				min: 0,
//				max: 360,
//				step: 30,
//				slide: function( event, ui )
//				{
//					$( "#f-european" ).val( ui.value + ' days' );
//				}
//			});
//			$( "#f-european" ).val( $( "#slider2" ).slider( "value" ) + ' days' );
//		});
//	}

	// Quick Quote Page, i.e. page displaying quotes grid.
	if ( GetPageFilename() == "quickquote.aspx" )
	{
	    // Apply styles and Slider controls on this page
	    $( "#NavPanel" ).hide();
	    $( "#Contents" ).css( "background", " #fff5cc url(images/template/content-bg-l.png) no-repeat 0 bottom" );
	    $( "#Contents" ).css( "display", "inline" );
	    $( "#Contents" ).css( "float", "left" );
	    $( "#Contents" ).css( "padding", "0 0 30px 0" );
	    $( "#Contents" ).css( "position", "relative" );
	    $( "#Contents" ).css( "width", "900px" );
	    
	    $( "#ctl00_ContentPlaceHolderMain_lblExcessSlider" ).slider(
		{
			min: 50,
			max: 500,
			step: 50,
			slide: function( event, ui )
			{
				$( "#ctl00_ContentPlaceHolderMain_txtExcess" ).val( ui.value );
				
				EnableUpdateButton();
			}
		});
		$( "#ctl00_ContentPlaceHolderMain_lblExcessSlider" ).slider( "value", $( "#ctl00_ContentPlaceHolderMain_txtExcess" ).val() );
		
		$("#ctl00_ContentPlaceHolderMain_lblEuropeanCoverSlider").slider(
	    {
		    min: 0,
		    max: 360,
		    step: 30,
		    slide: function( event, ui )
		    {
			    $( "#ctl00_ContentPlaceHolderMain_txtEuropeanCover" ).val( ui.value + ' days' );
			    
			    EnableUpdateButton();
		    }
	    });
	    $( "#ctl00_ContentPlaceHolderMain_lblEuropeanCoverSlider" ).slider( "value",
	        $( "#ctl00_ContentPlaceHolderMain_txtEuropeanCover" ).val().substring( 0, $( "#ctl00_ContentPlaceHolderMain_txtEuropeanCover" ).val().indexOf( " days" ) ) );
	}

} //);

/** ADD .radio CLASS TO RADIO OPTIONS **/
// Need to add .radio CSS Class to Radio options, as ASP.NET does not render the radio option with classes.
function AddRadioClassToRadioOptions()
{
    $( "#ctl00_ContentPlaceHolderMain_radCaravanTypeSingle" ).addClass( "radio" );
    $( "#ctl00_ContentPlaceHolderMain_radCaravanTypeTwin" ).addClass( "radio" );
    $( "#ctl00_ContentPlaceHolderMain_radTrackerProactive" ).addClass( "radio" );
    $( "#ctl00_ContentPlaceHolderMain_radTrackerNonProactive" ).addClass( "radio" );
    $( "#ctl00_ContentPlaceHolderMain_radTrackerNone" ).addClass( "radio" );
    $( "#ctl00_ContentPlaceHolderMain_radAlarmTQA" ).addClass( "radio" );
    $( "#ctl00_ContentPlaceHolderMain_radAlarmFFitted" ).addClass( "radio" );
    $( "#ctl00_ContentPlaceHolderMain_radAlarmNone" ).addClass( "radio" );
    $( "#ctl00_ContentPlaceHolderMain_radChassisSecureWheellockYes" ).addClass( "radio" );
    $( "#ctl00_ContentPlaceHolderMain_radChassisSecureWheellockNo" ).addClass( "radio" );
    $( "#ctl00_ContentPlaceHolderMain_radHitchPostYes" ).addClass( "radio" );
    $( "#ctl00_ContentPlaceHolderMain_radHitchPostNo" ).addClass( "radio" );
    $( "#ctl00_ContentPlaceHolderMain_radMuleYes" ).addClass( "radio" );
    $( "#ctl00_ContentPlaceHolderMain_radMuleNo" ).addClass( "radio" );
    $( "#ctl00_ContentPlaceHolderMain_radMicrotagYes" ).addClass( "radio" );
    $( "#ctl00_ContentPlaceHolderMain_radMicrotagNo" ).addClass( "radio" );
}

function EnableUpdateButton()
{
    var cmdBuy;
    var intIndex = 0;

    // Enable Update button on Quick Quote page
    document.getElementById( "ctl00_ContentPlaceHolderMain_cmdUpdate" ).disabled = false;
    $( "#ctl00_ContentPlaceHolderMain_cmdUpdate" ).removeClass( "disabled" );

//    // Disable Save button on Quick Quote page
//    document.getElementById( "ctl00_ContentPlaceHolderMain_cmdSave" ).disabled = true;
//    $( "#ctl00_ContentPlaceHolderMain_cmdSave" ).addClass( "disabled" );
    
    // Disable Buy buttons on Quick Quote page
    cmdBuy = document.getElementById( "ctl00_ContentPlaceHolderMain_cmdBuy" + intIndex );
    
    while ( cmdBuy )
    {
        cmdBuy.disabled = true;
        $( "#ctl00_ContentPlaceHolderMain_cmdBuy" + intIndex ).addClass( "disabled" );
        
        intIndex++;
        cmdBuy = document.getElementById( "ctl00_ContentPlaceHolderMain_cmdBuy" + intIndex );
    }
}

/** INVALID FIELDS INDICATORS **/
// Create array listing fields and their validation controls, so that the HightlightInvalidFields function can hightlight invalid fields.
var _FieldsValidationControls = new Array();

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_ddlClient1Title" ] = "ctl00_ContentPlaceHolderMain_rfvClient1Title";
    
_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtContactFirstName" ] = "ctl00_ContentPlaceHolderMain_rfvContactFirstName";
    
_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtContactLastName" ] = "ctl00_ContentPlaceHolderMain_rfvContactLastName";
    
_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtContactEmail" ] = "ctl00_ContentPlaceHolderMain_rfvContactEmail,ctl00_ContentPlaceHolderMain_revContactEmail";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtConfirmEmail" ] = "ctl00_ContentPlaceHolderMain_rfvConfirmEmail,ctl00_ContentPlaceHolderMain_comvConfirmEmail";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtContactTel" ] = "ctl00_ContentPlaceHolderMain_rfvContactTel,ctl00_ContentPlaceHolderMain_revContactTel";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_ddlOccupationType" ] = "ctl00_ContentPlaceHolderMain_rfvOccupationType";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtCoverStartDate" ] = "ctl00_ContentPlaceHolderMain_rfvCoverStartDate,ctl00_ContentPlaceHolderMain_cvCoverStartDate,ctl00_ContentPlaceHolderMain_rvCoverStartDate";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_ddlWhereHeardAboutUs" ] = "ctl00_ContentPlaceHolderMain_rfvWhereHeardAboutUs";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_ddlNumOfClaims" ] = "ctl00_ContentPlaceHolderMain_rfvNumOfClaims";


_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_ddlManufactureYear" ] = "ctl00_ContentPlaceHolderMain_rfvManufactureYear";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtCaravanValue" ] = "ctl00_ContentPlaceHolderMain_rfvCaravanValue, ctl00_ContentPlaceHolderMain_cvCaravanValue";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtContentsValue" ] = "ctl00_ContentPlaceHolderMain_cvContentsValue";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_ddlStorageLocationType" ] = "ctl00_ContentPlaceHolderMain_rfvStorageLocationType";


_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_HomeAddressDetails1_txtPostcode" ] = "ctl00_ContentPlaceHolderMain_HomeAddressDetails1_rfvPostcode";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_HomeAddressDetails1_txtPostcode" ] = "ctl00_ContentPlaceHolderMain_HomeAddressDetails1_rfvAddressLine1";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_HomeAddressDetails1_txtPostTown" ] = "ctl00_ContentPlaceHolderMain_HomeAddressDetails1_rfvPostTown";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_HomeAddressDetails1_txtCounty" ] = "ctl00_ContentPlaceHolderMain_HomeAddressDetails1_rfvCounty";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtDOB" ] = "ctl00_ContentPlaceHolderMain_rfvDOB,ctl00_ContentPlaceHolderMain_cvDOB,ctl00_ContentPlaceHolderMain_rvDOB";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_ddlCaravanMake" ] = "ctl00_ContentPlaceHolderMain_rfvCaravanMake";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtCaravanModel" ] = "ctl00_ContentPlaceHolderMain_rfvCaravanModel";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_StorageAddressDetails1_txtPostcode" ] = "ctl00_ContentPlaceHolderMain_StorageAddressDetails1_rfvPostcode";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_StorageAddressDetails1_txtPostcode" ] = "ctl00_ContentPlaceHolderMain_StorageAddressDetails1_rfvAddressLine1";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_StorageAddressDetails1_txtPostTown" ] = "ctl00_ContentPlaceHolderMain_StorageAddressDetails1_rfvPostTown";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_StorageAddressDetails1_txtCounty" ] = "ctl00_ContentPlaceHolderMain_StorageAddressDetails1_rfvCounty";


_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtDirectDebitAccHolderName" ] = "ctl00_ContentPlaceHolderMain_rfvDirectDebitAccHolderName";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtDirectDebitBankName" ] = "ctl00_ContentPlaceHolderMain_rfvDirectDebitBankName";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtDirectDebitAccNum" ] = "ctl00_ContentPlaceHolderMain_rfvDirectDebitAccNum, ctl00_ContentPlaceHolderMain_revDirectDebitAccNum";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtDirectDebitAccNum" ] = "ctl00_ContentPlaceHolderMain_rfvDirectDebitAccNum, ctl00_ContentPlaceHolderMain_revDirectDebitAccNum";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtDirectDebitSortCode1" ] = "ctl00_ContentPlaceHolderMain_cvDirectDebitSortCode";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtDirectDebitSortCode2" ] = "ctl00_ContentPlaceHolderMain_cvDirectDebitSortCode";

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtDirectDebitSortCode3" ] = "ctl00_ContentPlaceHolderMain_cvDirectDebitSortCode";


_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtEmailAddress" ] = "ctl00_ContentPlaceHolderMain_rfvEmailAddress, ctl00_ContentPlaceHolderMain_revEmailAddress"

_FieldsValidationControls[ "ctl00_ContentPlaceHolderMain_txtQuoteRef" ] = "ctl00_ContentPlaceHolderMain_rfvQuoteRef";

function HighlightInvalidFields( source, args )
{
    var intIndex;
    var objField;
    var objValidator;
    var strFieldID;
    var strValidationControlIDs;
    var strValidatedControls = new Array();
    
    // Interate through all the fields that have validation controls within this Web Quote application
    for ( strFieldID in _FieldsValidationControls )
    { 
        // Check if the current field exists on the current page
        if ( document.getElementById( strFieldID ) )
        {
            // The current field does exist on the current page.
            
            // Get the field object.
            objField = document.getElementById( strFieldID );
    
            // Get list of validation controls for the field
            strValidationControlIDs = _FieldsValidationControls[ strFieldID ].split( "," );

            // Interate through each validation control until all have been interated, or the field value is invalid for a validation control.
            intIndex = 0;
            while ( intIndex < strValidationControlIDs.length && ( strValidatedControls[ strFieldID ] == null || strValidatedControls[ strFieldID ] == true ) )
            {
                // Get the validation control object
                objValidator = eval( strValidationControlIDs[ intIndex ] );
            
                // Check whether the field's value is valid for the current validation control
                if ( objValidator.isvalid == true )
                {                    
                    // The field's value is valid for the current validation control - indicate this in the list of ValidatedControls.
                    strValidatedControls[ strFieldID ] = true;
                
                    // Check if the field is already highlighted as being invalid, and remove the highlight, as it is valid.
                    if ( objField.className.indexOf( "-error" ) > -1 )
                        objField.className = objField.className.replace( "-error", "" );
                }
                else
                {
                    // The field's value is invalid for the current validation control - indicate this in the list of ValidatedControls.
                    strValidatedControls[ strFieldID ] = false;
                
                    // Check if the field is not highlighted
                    if ( objField.className.indexOf( "-error" ) == -1 )
                    {
                        // Highlight the field to indicated that it contains an invalid value
                        if ( objField.className.indexOf( " hasDatepicker" ) > -1 )
                            // This highlight is required for fields that are Datepickers
                            objField.className = objField.className.replace( " hasDatepicker", "-error hasDatepicker" );
                        else
                            objField.className = objField.className + "-error";
                    }
                }
            
                intIndex++;
            }
        } 
    }
    
    // Always set args.IsValid to true.
    args.IsValid = true;
}

