//
// Event type enumeration
//
var EVENT_TYPE_SECURITY		= "SECURITY";
var EVENT_TYPE_ERROR		= "ERROR";
var EVENT_TYPE_WARNING		= "WARNING";

//
// Array of all I-Reach event types
//
var IR_EVENT_TYPES = new Array( 
	EVENT_TYPE_SECURITY,
	EVENT_TYPE_ERROR,
	EVENT_TYPE_WARNING
)



//
// Event enumeration
//
var EVENT_LOGON_FAIL	    = new Pair( EVENT_TYPE_SECURITY,	"LOGON_FAIL" );
var EVENT_LOGON_SUCCESS     = new Pair( EVENT_TYPE_SECURITY,	"LOGON_SUCCESS" );
var EVENT_VIEW_STUDY	    = new Pair( EVENT_TYPE_SECURITY,	"VIEW_STUDY" );
var EVENT_OEM_LOGON		    = new Pair( EVENT_TYPE_SECURITY,	"OEM_LOGON" );
var EVENT_PRINT			    = new Pair( EVENT_TYPE_SECURITY,	"PRINT" );
var EVENT_GSPSS_SAVED	    = new Pair( EVENT_TYPE_SECURITY,	"GSPS_SAVED" );
var EVENT_VIEW_REPORT	    = new Pair( EVENT_TYPE_SECURITY,	"VIEW_REPORT" );
var EVENT_NO_LICENSE	    = new Pair( EVENT_TYPE_WARNING,	    "NO_LICENSE" );
var EVENT_KO_SAVED			= new Pair( EVENT_TYPE_SECURITY,	"KEY_IMAGE_SAVED" );
var EVENT_COMPARE_PATIENTS  = new Pair( EVENT_TYPE_SECURITY,	"COMPARE_PATIENTS" );
var EVENT_STUDY_STATUS_CHANGED  = new Pair( EVENT_TYPE_SECURITY,	"STUDY_STATUS_CHANGED" );
var EVENT_NO_DYNAMIC_LICENSE = new Pair( EVENT_TYPE_WARNING, "NO_DYNAMIC_LICENSE" );

var EVENT_RESTORE_START = new Pair( EVENT_TYPE_SECURITY, "RESTORE_STUDY_START" );
var EVENT_RESTORE_SKIP = new Pair( EVENT_TYPE_SECURITY, "RESTORE_STUDY_SKIP" );
var EVENT_RESTORE_FAILED = new Pair( EVENT_TYPE_SECURITY, "RESTORE_STUDY_FAILED" );
var EVENT_RESTORE_PARTIAL = new Pair( EVENT_TYPE_SECURITY, "RESTORE_PARTIAL_STUDY" );
var EVENT_RESTORE_SUCCESS = new Pair( EVENT_TYPE_SECURITY, "RESTORE_STUDY_SUCCESS" );
var EVENT_RESTORE_ERROR = new Pair( EVENT_TYPE_SECURITY, "RESTORE_STUDY_ERROR" );

//
// Array of all I-Reach events
//
var IR_EVENTS = new Array( 
	EVENT_GSPSS_SAVED,
	EVENT_LOGON_FAIL,
	EVENT_LOGON_SUCCESS,
	EVENT_NO_LICENSE,
	EVENT_OEM_LOGON,
	EVENT_PRINT,
	EVENT_VIEW_STUDY,
	EVENT_VIEW_REPORT,
	EVENT_KO_SAVED,
	EVENT_COMPARE_PATIENTS,
	EVENT_STUDY_STATUS_CHANGED,
	EVENT_NO_DYNAMIC_LICENSE,
	EVENT_RESTORE_START,
	EVENT_RESTORE_SKIP,
	EVENT_RESTORE_FAILED,
	EVENT_RESTORE_PARTIAL,
	EVENT_RESTORE_SUCCESS,
	EVENT_RESTORE_ERROR
)

//
//	Helper class to hold a pair of objects
//
function Pair(val1, val2)
{
	this.m_val1 = val1;
	this.m_val2 = val2;
}

//
// EventLog Class
//
//	Member Data:
//		m_type		:	event type (e.g. SECURITY, ERROR, WARNING)
//		m_message	:	event message
//		m_userID	:	userID of who triggers the event
//		m_hostname	:	client hostname on which the event is triggered
//		m_ntSessionID	:	NT session ID from which the event is triggered
//		m_attrs		:	Additional attributes for the event
//					Stored in an array of Pair object.
//
//	Class methods:
//		addAttr(name, value)	:	Insert attribute in name/value pair
//		getXMLDoc		:	returns an XML doc describing the event
//
// XML Document Structure
//
// <ROOT>
//    <Type		Value="SECURITY">
//    <Message		Value="VIEW_STUDY">
//    <UserID		Value="joe">
//    <Hostname		Value="bambi">
//    <NtSessionID	Value="0">
//    <Attr		Name="Patient Name"	Value="CR HI-RES">
//    <Attr		Name="Patient ID"	Value="669422">
//    <Attr		Name="StudyUID"		Value="1.2.840.113564.2155417063.20961013.25094810.600081">
//</ROOT>
//
//
function EventLog(myEvent, userID, hostname, ntSessionID)
{
	// Initialize class members
	this.m_type = myEvent.m_val1;
	this.m_message = myEvent.m_val2;
	this.m_userID = userID;
	this.m_hostname = hostname;
	this.m_ntSessionID = ntSessionID;
	this.m_attrs = new Array();

	// Initialize class methods
	this.addAttr = EventLogAddAttr;
	this.getXMLDoc = EventLogGetXMLDoc;
}

//
// Function to append attribute to the EventLog object
//
function EventLogAddAttr( attrName, attrValue )
{
	this.m_attrs.push( new Pair(attrName, attrValue) )
}


//
// Function to dump the EventLog into a XML document
//
function EventLogGetXMLDoc()
{
	// Create XML document and root node
	var rootNode, tmpNode;
	var xmlDoc = new ActiveXObject( "Microsoft.XMLDOM" );
	rootNode = xmlDoc.createElement("ROOT");
	xmlDoc.appendChild(rootNode);

	// Type
	tmpNode = xmlDoc.createElement("Type");
	tmpNode.setAttribute( "Value", this.m_type );
	rootNode.appendChild(tmpNode);

	// Message
	tmpNode = xmlDoc.createElement("Message");
	tmpNode.setAttribute( "Value", this.m_message );
	rootNode.appendChild(tmpNode);

	// UserID
	tmpNode = xmlDoc.createElement("UserID");
	tmpNode.setAttribute( "Value", this.m_userID );
	rootNode.appendChild(tmpNode);

	// Hostname
	tmpNode = xmlDoc.createElement("Hostname");
	tmpNode.setAttribute( "Value", this.m_hostname );
	rootNode.appendChild(tmpNode);

	// NTSessionID
	tmpNode = xmlDoc.createElement("NtSessionID");
	tmpNode.setAttribute( "Value", this.m_ntSessionID );
	rootNode.appendChild(tmpNode);

	// Attributes
	var i;
	for (i=0; i<this.m_attrs.length; i++ )
	{
		tmpNode = xmlDoc.createElement("Attr");
		tmpNode.setAttribute( "Name", this.m_attrs[i].m_val1 );
		tmpNode.setAttribute( "Value", this.m_attrs[i].m_val2 );
		rootNode.appendChild(tmpNode);
	}

	return xmlDoc;
}
