﻿//Functions used in the forms game

	function GetForm()
	{
		//alert("GetForm");
		GameFunctions.GetForm(myGameName, mySession, GetForm_Callback);
	}

	function GetForm_Callback(response)
	{
		//alert("GetForm returned " + response.value);
		if(response.error) 
		{
			//alert(response.error);	
			flash.ShowError("Could not get forms for this case.");
		}
		else
		{
			var dictionary = CreateDictionaryWrap(response.value);
		    var succeeded = GetValue(dictionary, 'Success');
		    if(succeeded == "True")
			    flash.StoreForm(response.value);
		    else
		        flash.ShowError("Form not available for this case.");
		}
	}
	
	function GetResultForFormReviewAction(section)
	{
		//alert("GetResultForFormReviewAction");
		GameFunctions.GetResultForFormReviewAction(myGameName, mySession, section, GetResultForFormReviewAction_Callback);
	}

	function GetResultForFormReviewAction_Callback(response)
	{
		//alert("EvaluateForm returned " + response.value);
		if(response.error) 
		{
			//alert(response.error);	
			flash.ShowError("Could not evaluate labels.");
		}
		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.ShowFormEvaluation(evalText, actionScore);
			    flash.UpdateFormsRow(response.value);
			}
		    else
		        flash.ShowError("Dispensing could not be evaluated.  Please finish the case.");
		}
	}

    //////////////////////////////////////////////////

	function GetResultForFormLabelAction(labelsString)
	{
		//alert("GetResultForFormLabelAction " + labelsString);
		GameFunctions.GetResultForFormLabelAction(myGameName, mySession, labelsString, GetResultForFormLabelAction_Callback);
	}

	function GetResultForFormLabelAction_Callback(response)
	{
		//alert("EvaluateLabels returned " + response.value);
		if(response.error) 
		{
			//alert(response.error);	
			flash.ShowError("EvalLabels Error: " + response.error);
		}
		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.ShowFormEvaluation(evalText, actionScore);
			}
		    else
		        flash.ShowError("Label Evaluation Error. Please close the form.");
		}
	}