﻿
var manheim_retailservices_insurance =
{
	/*
	=============================
	CONSTANTS
	=============================
	*/
	
	"insuranceManager" : null,

	/*
	=============================
	CONSTRUCTOR
	=============================
	*/
	"init" : function ()
	{
		this.insuranceManager = $.insuranceManager;
		
		this.insuranceManager.initialise(
		{
			"responseType" : $.insuranceManager.responseTypes.JSON,
			"requestType" : $.insuranceManager.getRequestType(),
			"groupId" : $('input#groupId').val(),
			"groupTypeId" : $('input#groupTypeId').val()
		});
		
		this.processState();
	},
	

	/*
	=============================
	PUBLIC MEMBERS
	=============================
	*/
	"processState" : function ()
	{
		this._setDisplayState();
		
		// add our ui vehicles to the insurance manager
		this.insuranceManager.addVehicles();
		
		// fire off the insurance request
		this.insuranceManager.getData();
	},
	
	
	/*
	=============================
	PRIVATE MEMBERS
	=============================
	*/
	
	"_setDisplayState" : function ()
	{
		var __this = this;
		
		// loop through each insurance ui item and work out if check state should be activated
		$(this.insuranceManager.UI.INSURANCE_ITEM_RESULTS_LIST_ITEM + ", " + this.insuranceManager.UI.INSURANCE_ITEM_SINGLE).each(
			function ()
			{
				var uiInsuranceItem = $(this);
				
				var capId = uiInsuranceItem.find("input.capId").val();
				
				if (capId && capId !== 0)
				{
					$.insuranceManager.switchUIInsuranceState($.insuranceManager.uiDisplayStates.CHECKING, null, uiInsuranceItem);
				}
			}
		);
	},
	
	
	"end" : {}
};

// fire the insurance request
$(document).ready(function ()
{
	manheim_retailservices_insurance.init();
});