//*** Err handling for LMS

//*** error number, error description, err diagnostics

var LMSerrors =
   [
      ["0", "No Error", "The previous LMS API Function call completed successfully."],
      ["101", "General Exception", "An unspecified, unexpected exception has occured"],
      ["201", "Invalid argument error", ""],
      ["202", "Element can not have children", ""],
      ["203", "Element not an array - cannot have count", ""],
      ["301", "Not initialized", "The LMS is not initialized."],
      ["302", "LMS error", "Last call to LMSSetValue()was unsuccessful" +
			  "Data will not be saved"],
      ["401", "Not implemented error",
         "The data model element in question was not implemented"],
      ["402", "Invalid set value, element is a key word",
         "Trying to set a reserved key word in the data model" +
         "Trying to set a key word (_count, _children, or _version) " +
         "This is prohibited"],
      ["403", "Element is read only",
         "Data Element is Read Only (Not Writeable)"+
         "Cannot call LMSSetValue() for the element in question"],
      ["404", "Element is write only",
         "Data Element is Write Only (Not Readable)"+
         "Cannot call LMSGetValue() for the element in question"],
      ["405", "Incorrect Data Type",
         "Invalid Type being used for setting element"+
         "The type being used as the set value argument does not match" +
         " that of the element being set"],
      ["499", "Interaction type unknown",
         "Interaction type must be defined first"+
         "Interaction type unknown..."]
	];
   
 function clLMSErrorManager() {
 	this.currentErrorCode='0';
	this.currentNotDefinedErrorDescription = "";  //for errors not predefined in the LMS
	this.GetCurrentErrorCode=GetCurrentErrorCode;
 	this.SetCurrentErrorCode=SetCurrentErrorCode;
 	this.ClearCurrentErrorCode=ClearCurrentErrorCode;
 	this.GetErrorDescription=GetErrorDescription;
 	this.GetErrorDiagnostic=GetErrorDiagnostic;
 	this.GetErrorElement=GetErrorElement;
}

function GetCurrentErrorCode() { 
	return this.currentErrorCode; 
}

function SetCurrentErrorCode(code){ 
	if ((code != null) && (code != '')) 
		this.currentErrorCode = code; 
	else 
		this.currentErrorCode = '0'; 
}

function ClearCurrentErrorCode() { 
	this.currentErrorCode = LMSerrors[0][0]; 
}

function GetErrorDescription(code) { 
	if((code != null) && (code != "") && (code > 100)) 
		return this.GetErrorElement(code)[1]; 
	else 
		return this.currentNotDefinedErrorDescription; 
}

function GetErrorDiagnostic(code) { 
	if((code != null) && (code != "") && (code > 100)) 
		return this.GetErrorElement(code)[2]; 
	else 
		return ""; 
}
   
function GetErrorElement(code)
{
  for(i=0; i < LMSerrors.length; i++)
    if(LMSerrors[i][0] == code) 
		return LMSerrors[i];
 
  return [code,this.currentNotDefinedErrorDescription,this.currentNotDefinedErrorDescription];
}


