﻿// Functions used in the Dispensing Game

	function GetLabels()
	{
		//alert("GetLabels");
		GameFunctions.GetLabels(myGameName, mySession, GetLabels_Callback);
	}

	function GetLabels_Callback(response)
	{
		//alert("GetLabels returned " + response.value);
		if(response.error) 
		{
			//alert(response.error);	
			flash.ShowError("Could not get labels for this case.");
		}
		else
		{
			var dictionary = CreateDictionaryWrap(response.value);
		    var succeeded = GetValue(dictionary, 'Success');
		    if(succeeded == "True")
			    flash.StoreLabels(response.value);
		    else
		        flash.ShowError("Labels not available for this case.");
		}
	}

	function GetResultForDispensingAction(amountsString)
	{
		//alert("GetResultForDispensingAction");
		GameFunctions.GetResultForDispensingAction(myGameName, mySession, amountsString, GetResultForDispensingAction_Callback);
	}

	function GetResultForDispensingAction_Callback(response)
	{
		//alert("GRFDispensingA returned " + response.value);
		if(response.error) 
		{
			//alert(response.error);	
			flash.ShowError("Could not evaluate Dispensing information.");
		}
		else
		{
			var dictionary = CreateDictionaryWrap(response.value);
		    var succeeded = GetValue(dictionary, 'Success');
		    if(succeeded == "True")
			{
				var dictionary = CreateDictionaryWrap(response.value);
			    var actionScore = parseInt(GetValue(dictionary, 'ActionScore'));
			    var evalText = GetValue(dictionary, 'Brief');
			    flash.ShowDispensingEvaluation(evalText, actionScore);
			}
		    else
		        flash.ShowError("Dispensing could not be evaluated.  Please finish the case.");
		}
	}