

function updateSession(chrFieldId,chrValue) {
	
	updateSessionItem(chrFieldId,chrValue);
	
	//additional special updating for suggestion based items
	if ($.FindNoCase('suggest',chrFieldId)) {
		var chrUpdateFieldId = $.ReplaceNoCase(chrFieldId,'_suggest','');
		var chrUpdateFieldValue = '';
		var chrSuggestResultsId = chrFieldId + '_suggestResults';
		var chrSuggestResultsSel = '#' + chrSuggestResultsId + ' li';
		$(chrSuggestResultsSel).each(function() {
			if ($.LCase($.Trim(chrValue)) == $.LCase($.Trim($(this).text()))) {
				chrUpdateFieldValue = $(this).attr('ref');
			}
		});
		//update the session code
		if (isFieldValidated(chrFieldId)) {
			updateSessionItem(chrUpdateFieldId,chrUpdateFieldValue);
		}
	}	
	
}

function updateSessionItem(chrFieldId,chrValue) {
	doAjaxCall({fuseAction:'updateSession',data:{chrFieldId : chrFieldId ,chrValue : chrValue}});
}

function deleteSession(chrFieldId) {
	doAjaxCall({fuseAction:'deleteSession',data:{chrFieldId : chrFieldId}});
}

function getSession(chrFieldId,chrCallBack) {
	doAjaxCall({fuseAction:'getSession',callBack:chrCallBack,data:{chrFieldId : chrFieldId}});
}

function updateFormSession(chrNextStepLocation) {
	//serialise the form and update the session and when completed redirect to next step
	$textFields = $('input[type=text]').serialize();
	$radioFields = $('input[type=radio]').serialize();
	//do not take form field for numRiders (as values are 1-3 and 0 is set on handler if required)
	$selectFields = $('select').not('#policy_numRiders').serialize();
	var qsFormData = $textFields + '&' + $radioFields + '&' + $selectFields;
	doAjaxCall({fuseAction:'updateFormSession',callBack:'relocate',callBackArg:chrNextStepLocation,data:qsFormData});
}

