/// <reference path="General.js" />

// ** Global object to hold shortcuts to these constructors
var GeneralObjectLibrary = {};


function __GENOBJECT_SettingDefinition(uXMLNode) {
    var b = (uXMLNode != undefined && uXMLNode != null);
    
    try {
        this.ID         = b ? uXMLNode.selectSingleNode("ID").text : '';	
        this.Key1       = b ? uXMLNode.selectSingleNode("Key1").text : '';	
        this.Key2       = b ? uXMLNode.selectSingleNode("Key2").text : '';	
        this.Key3       = b ? uXMLNode.selectSingleNode("Key3").text : '';	
        this.Key4       = b ? uXMLNode.selectSingleNode("Key4").text : '';	
        this.Key5       = b ? uXMLNode.selectSingleNode("Key5").text : '';	
        
        this.Settings   = new Array(0);
        if (b && uXMLNode.selectSingleNode("Settings")) {
            var oSettings = uXMLNode.selectSingleNode("Settings").childNodes;
            for (var i = 0; i < oSettings.length; i++) this.Settings[i] = new __GENOBJECT_Setting(oSettings[i]);
        }
         
    
    } catch (err) {
		var e = new Error();
		e.message = "An error occurred while trying to load the data for struct [__GENOBJECT_SettingDefinition]\n\nThe system returned the following error.\n\n" + err.message;
		e.description = e.message;
		throw e;
	}
}

function __GENOBJECT_Setting(uXMLNode) {
    
    var b =  (uXMLNode != undefined && uXMLNode != null);
    
    try {
        this.ID                 = b && uXMLNode.selectSingleNode("ID") != null ? uXMLNode.selectSingleNode("ID").text : '';	
        this.EntityID           = b && uXMLNode.selectSingleNode("EntityID") != null ? uXMLNode.selectSingleNode("EntityID").text : '';
        this.EntityType         = b && uXMLNode.selectSingleNode("EntityType") != null ? uXMLNode.selectSingleNode("EntityType").text : '';
        this.TextValue1         = b && uXMLNode.selectSingleNode("TextValue1") != null ? uXMLNode.selectSingleNode("TextValue1").text : '';
        this.TextValue2         = b && uXMLNode.selectSingleNode("TextValue2") != null ? uXMLNode.selectSingleNode("TextValue2").text : '';
        this.NumericValue1      = b && uXMLNode.selectSingleNode("NumericValue1") != null ? uXMLNode.selectSingleNode("NumericValue1").text.ToFloat() : '';
        this.NumericValue2      = b && uXMLNode.selectSingleNode("NumericValue2") != null ? uXMLNode.selectSingleNode("NumericValue2").text.ToFloat() : '';
        this.IDValue1           = b && uXMLNode.selectSingleNode("IDValue1") != null ? uXMLNode.selectSingleNode("IDValue1").text : '';
        this.IDValue2           = b && uXMLNode.selectSingleNode("IDValue2") != null ? uXMLNode.selectSingleNode("IDValue2").text : '';
        this.DateValue1         = b && uXMLNode.selectSingleNode("DateValue1") != null ? uXMLNode.selectSingleNode("DateValue1").text : '';
        this.DateValue2         = b && uXMLNode.selectSingleNode("DateValue2") != null ? uXMLNode.selectSingleNode("DateValue2").text : '';        
        this.LongValue1         = b && uXMLNode.selectSingleNode("LongValue1") != null ? uXMLNode.selectSingleNode("LongValue1").text : '';
        this.LongValue2         = b && uXMLNode.selectSingleNode("LongValue2") != null ? uXMLNode.selectSingleNode("LongValue2").text : '';
        
        this.Index              = b && uXMLNode.selectSingleNode("Index") != null ? uXMLNode.selectSingleNode("Index").text.ToInt() : 0;
        
        var nodExt = uXMLNode.selectSingleNode("ExtendedSetting");
        if (nodExt == null) nodExt = uXMLNode.selectSingleNode("ExtendedValues");
        
        this.ExtendedSetting   = b && nodExt != null ? new __GENOBJECT_ExtendedSetting(nodExt) : null; 
        
    } catch (err) {
		var e = new Error();
		e.message = "An error occurred while trying to load the data for struct [__GENOBJECT_SettingDefinition]\n\nThe system returned the following error.\n\n" + err.message;
		e.description = e.message;
		throw e;
	}
}


function __GENOBJECT_ExtendedSetting(uXMLNode) {
	var b =  (uXMLNode != undefined && uXMLNode != null);

	try {
		this.Text01			= b && uXMLNode.selectSingleNode("Text01") != null ? uXMLNode.selectSingleNode("Text01").text : '';	
		this.Text02			= b && uXMLNode.selectSingleNode("Text02") != null ? uXMLNode.selectSingleNode("Text02").text : '';
		this.Text03			= b && uXMLNode.selectSingleNode("Text03") != null ? uXMLNode.selectSingleNode("Text03").text : '';
		this.Text04			= b && uXMLNode.selectSingleNode("Text04") != null ? uXMLNode.selectSingleNode("Text04").text : '';
		this.Text05			= b && uXMLNode.selectSingleNode("Text05") != null ? uXMLNode.selectSingleNode("Text05").text : '';
		this.Text06			= b && uXMLNode.selectSingleNode("Text06") != null ? uXMLNode.selectSingleNode("Text06").text : '';	
		this.Text07			= b && uXMLNode.selectSingleNode("Text07") != null ? uXMLNode.selectSingleNode("Text07").text : '';
		this.Text08			= b && uXMLNode.selectSingleNode("Text08") != null ? uXMLNode.selectSingleNode("Text08").text : '';
		this.Text09			= b && uXMLNode.selectSingleNode("Text09") != null ? uXMLNode.selectSingleNode("Text09").text : '';
		this.Text10			= b && uXMLNode.selectSingleNode("Text10") != null ? uXMLNode.selectSingleNode("Text10").text : '';

		this.Numeric01		= b && uXMLNode.selectSingleNode("Numeric01") != null ? uXMLNode.selectSingleNode("Numeric01").text.toString().ToFloat() : 0;
		this.Numeric02		= b && uXMLNode.selectSingleNode("Numeric02") != null ? uXMLNode.selectSingleNode("Numeric02").text.toString().ToFloat() : 0;
		this.Numeric03		= b && uXMLNode.selectSingleNode("Numeric03") != null ? uXMLNode.selectSingleNode("Numeric03").text.toString().ToFloat() : 0;
		this.Numeric04		= b && uXMLNode.selectSingleNode("Numeric04") != null ? uXMLNode.selectSingleNode("Numeric04").text.toString().ToFloat() : 0;
		this.Numeric05		= b && uXMLNode.selectSingleNode("Numeric05") != null ? uXMLNode.selectSingleNode("Numeric05").text.toString().ToFloat() : 0;
		this.Numeric06		= b && uXMLNode.selectSingleNode("Numeric06") != null ? uXMLNode.selectSingleNode("Numeric06").text.toString().ToFloat() : 0;
		this.Numeric07		= b && uXMLNode.selectSingleNode("Numeric07") != null ? uXMLNode.selectSingleNode("Numeric07").text.toString().ToFloat() : 0;
		this.Numeric08		= b && uXMLNode.selectSingleNode("Numeric08") != null ? uXMLNode.selectSingleNode("Numeric08").text.toString().ToFloat() : 0;
		this.Numeric09		= b && uXMLNode.selectSingleNode("Numeric09") != null ? uXMLNode.selectSingleNode("Numeric09").text.toString().ToFloat() : 0;
		this.Numeric10		= b && uXMLNode.selectSingleNode("Numeric10") != null ? uXMLNode.selectSingleNode("Numeric10").text.toString().ToFloat() : 0;
		
		this.Long01			= b && uXMLNode.selectSingleNode("Long01") != null ? uXMLNode.selectSingleNode("Long01").text.toString().ToInt() : 0;
		this.Long02			= b && uXMLNode.selectSingleNode("Long02") != null ? uXMLNode.selectSingleNode("Long02").text.toString().ToInt() : 0;
		this.Long03			= b && uXMLNode.selectSingleNode("Long03") != null ? uXMLNode.selectSingleNode("Long03").text.toString().ToInt() : 0;
		this.Long04			= b && uXMLNode.selectSingleNode("Long04") != null ? uXMLNode.selectSingleNode("Long04").text.toString().ToInt() : 0;
		this.Long05			= b && uXMLNode.selectSingleNode("Long05") != null ? uXMLNode.selectSingleNode("Long05").text.toString().ToInt() : 0;
		this.Long06			= b && uXMLNode.selectSingleNode("Long06") != null ? uXMLNode.selectSingleNode("Long06").text.toString().ToInt() : 0;
		this.Long07			= b && uXMLNode.selectSingleNode("Long07") != null ? uXMLNode.selectSingleNode("Long07").text.toString().ToInt() : 0;
		this.Long08			= b && uXMLNode.selectSingleNode("Long08") != null ? uXMLNode.selectSingleNode("Long08").text.toString().ToInt() : 0;
		this.Long09			= b && uXMLNode.selectSingleNode("Long09") != null ? uXMLNode.selectSingleNode("Long09").text.toString().ToInt() : 0;
		this.Long10			= b && uXMLNode.selectSingleNode("Long10") != null ? uXMLNode.selectSingleNode("Long10").text.toString().ToInt() : 0;
		
		this.Date01			= b && uXMLNode.selectSingleNode("Date01") != null ? uXMLNode.selectSingleNode("Date01").text : '1899-12-31 12:00 AM';
		this.Date02			= b && uXMLNode.selectSingleNode("Date02") != null ? uXMLNode.selectSingleNode("Date02").text : '1899-12-31 12:00 AM';
		this.Date03			= b && uXMLNode.selectSingleNode("Date03") != null ? uXMLNode.selectSingleNode("Date03").text : '1899-12-31 12:00 AM';
		this.Date04			= b && uXMLNode.selectSingleNode("Date04") != null ? uXMLNode.selectSingleNode("Date04").text : '1899-12-31 12:00 AM';
		this.Date05			= b && uXMLNode.selectSingleNode("Date05") != null ? uXMLNode.selectSingleNode("Date05").text : '1899-12-31 12:00 AM';
		this.Date06			= b && uXMLNode.selectSingleNode("Date06") != null ? uXMLNode.selectSingleNode("Date06").text : '1899-12-31 12:00 AM';
		this.Date07			= b && uXMLNode.selectSingleNode("Date07") != null ? uXMLNode.selectSingleNode("Date07").text : '1899-12-31 12:00 AM';
		this.Date08			= b && uXMLNode.selectSingleNode("Date08") != null ? uXMLNode.selectSingleNode("Date08").text : '1899-12-31 12:00 AM';
		this.Date09			= b && uXMLNode.selectSingleNode("Date09") != null ? uXMLNode.selectSingleNode("Date09").text : '1899-12-31 12:00 AM';
		this.Date10			= b && uXMLNode.selectSingleNode("Date10") != null ? uXMLNode.selectSingleNode("Date10").text : '1899-12-31 12:00 AM';
		
		this.Guid01			= b && uXMLNode.selectSingleNode("Guid01") != null ? uXMLNode.selectSingleNode("Guid01").text : NullGuid;
		this.Guid02			= b && uXMLNode.selectSingleNode("Guid02") != null ? uXMLNode.selectSingleNode("Guid02").text : NullGuid;
		this.Guid03			= b && uXMLNode.selectSingleNode("Guid03") != null ? uXMLNode.selectSingleNode("Guid03").text : NullGuid;
		this.Guid04			= b && uXMLNode.selectSingleNode("Guid04") != null ? uXMLNode.selectSingleNode("Guid04").text : NullGuid;
		this.Guid05			= b && uXMLNode.selectSingleNode("Guid05") != null ? uXMLNode.selectSingleNode("Guid05").text : NullGuid;
		this.Guid06			= b && uXMLNode.selectSingleNode("Guid06") != null ? uXMLNode.selectSingleNode("Guid06").text : NullGuid;
		this.Guid07			= b && uXMLNode.selectSingleNode("Guid07") != null ? uXMLNode.selectSingleNode("Guid07").text : NullGuid;
		this.Guid08			= b && uXMLNode.selectSingleNode("Guid08") != null ? uXMLNode.selectSingleNode("Guid08").text : NullGuid;
		this.Guid09			= b && uXMLNode.selectSingleNode("Guid09") != null ? uXMLNode.selectSingleNode("Guid09").text : NullGuid;
		this.Guid10			= b && uXMLNode.selectSingleNode("Guid10") != null ? uXMLNode.selectSingleNode("Guid10").text : NullGuid;
		
		this.LongText01		= b && uXMLNode.selectSingleNode("LongText01") != null ? uXMLNode.selectSingleNode("LongText01").text : '';
		this.LongText02		= b && uXMLNode.selectSingleNode("LongText02") != null ? uXMLNode.selectSingleNode("LongText02").text : '';
		this.LongText03		= b && uXMLNode.selectSingleNode("LongText03") != null ? uXMLNode.selectSingleNode("LongText03").text : '';
		this.LongText04		= b && uXMLNode.selectSingleNode("LongText04") != null ? uXMLNode.selectSingleNode("LongText04").text : '';
		this.LongText05		= b && uXMLNode.selectSingleNode("LongText05") != null ? uXMLNode.selectSingleNode("LongText05").text : '';		

	} catch (err) {
		var e = new Error();
		e.message = "An error occurred while trying to load the data for struct [__GENOBJECT_ExtendedSetting]\n\nThe system returned the following error.\n\n" + err.message;
		e.description = e.message;
		throw e;
	}

}


function __GENOBJECT_Database(uDatabaseXMLNode) {
	var b = (uDatabaseXMLNode != undefined && uDatabaseXMLNode != null);
	
	try {
		this.ID				= b ? uDatabaseXMLNode.selectSingleNode("ID").text : '';
		this.Description	= b ? uDatabaseXMLNode.selectSingleNode("Description").text : '';
		this.DatabaseType	= b ? uDatabaseXMLNode.selectSingleNode("DatabaseType").text.ToBool() : 0;
		this.Server			= b ? uDatabaseXMLNode.selectSingleNode("Server").text : '';
		this.Catalog		= b ? uDatabaseXMLNode.selectSingleNode("Catalog").text : '';
		
		this.TrustedConnection = b ? uDatabaseXMLNode.selectSingleNode("TrustedConnection").text.ToBool() : 0;
		this.Username		= b ? uDatabaseXMLNode.selectSingleNode("Username").text : '';
		this.Password		= b ? uDatabaseXMLNode.selectSingleNode("Password").text : '';

//		this.ConnectionString = b ? uDatabaseXMLNode.selectSingleNode("ConnectionString").text : '';
		this.DateCreated	= b ? uDatabaseXMLNode.selectSingleNode("DateCreated").text : '';
		this.DateUpdated	= b ? uDatabaseXMLNode.selectSingleNode("DateUpdated").text : '';		
		this.CreatorName	= b ? uDatabaseXMLNode.selectSingleNode("CreatorName").text : '';
		
		this.OrganisationID	= b ? uDatabaseXMLNode.selectSingleNode("OrganisationID").text : '';
		this.GroupViewID	= b ? uDatabaseXMLNode.selectSingleNode("GroupViewID").text : '';
		this.GroupEditID	= b ? uDatabaseXMLNode.selectSingleNode("GroupEditID").text : '';
		this.GroupDeleteID	= b ? uDatabaseXMLNode.selectSingleNode("GroupDeleteID").text : '';
	} catch (err) {
		var e = new Error();
		e.message = "An error occurred while trying to load the data for struct [__GENOBJECT_Database]\n\nThe system returned the following error.\n\n" + err.message;
		throw e;
	}
}



function __GENOBJECT_Form(uFormXMLNode) {
	var b = (uFormXMLNode != undefined && uFormXMLNode != null);
	
	try {
		this.ID				= b ? uFormXMLNode.selectSingleNode("ID").text : '';
		this.Description	= b ? uFormXMLNode.selectSingleNode("Description").text : '';
		this.FormURL		= b ? uFormXMLNode.selectSingleNode("FormURL").text : '';
		this.HeaderURL		= b ? uFormXMLNode.selectSingleNode("HeaderURL").text : '';
		this.GroupViewID	= b ? uFormXMLNode.selectSingleNode("GroupViewID").text : '';
		this.GroupEditID	= b ? uFormXMLNode.selectSingleNode("GroupEditID").text : '';
		this.GroupDeleteID	= b ? uFormXMLNode.selectSingleNode("GroupDeleteID").text : '';
		this.DateCreated	= b ? uFormXMLNode.selectSingleNode("DateCreated").text : '';
		this.DateUpdated	= b ? uFormXMLNode.selectSingleNode("DateUpdated").text : '';
		this.CreatorName	= b ? uFormXMLNode.selectSingleNode("CreatorName").text : '';
		this.FormHeight     = b ? uFormXMLNode.selectSingleNode("FormHeight").text.ToInt() : 0;
		this.TabCount       = b ? uFormXMLNode.selectSingleNode("TabCount").text.ToInt() : 0;
		
	} catch (err) {
		var e = new Error();
		e.message = "An error occurred while trying to load the data for struct [__GENOBJECT_Form]\n\nThe system returned the following error.\n\n" + err.message;
		throw e;
	}
}



function __GENOBJECT_ContactGroup(uContactGroupXMLNode) {
	var b = (uContactGroupXMLNode != undefined && uContactGroupXMLNode != null);
	
	try {
		this.ID				= b ? uContactGroupXMLNode.selectSingleNode("ID").text : '';
		this.Name			= b ? uContactGroupXMLNode.selectSingleNode("Name").text : '';
		this.DisplayName	= b ? uContactGroupXMLNode.selectSingleNode("DisplayName").text : '';
//		this.Type			= b ? uContactGroupXMLNode.selectSingleNode("Type").text.ToInt() : '';
		this.Private		= b ? uContactGroupXMLNode.selectSingleNode("Private").text.ToInt() : '';
		this.GroupViewID	= b ? uContactGroupXMLNode.selectSingleNode("GroupViewID").text : '';
		this.GroupEditID	= b ? uContactGroupXMLNode.selectSingleNode("GroupEditID").text : '';
		this.GroupDeleteID	= b ? uContactGroupXMLNode.selectSingleNode("GroupDeleteID").text : '';
		this.DateCreated	= b ? uContactGroupXMLNode.selectSingleNode("DateCreated").text : '';
		this.DateUpdated	= b ? uContactGroupXMLNode.selectSingleNode("DateUpdated").text : '';
		this.CreatorName	= b ? uContactGroupXMLNode.selectSingleNode("CreatorName").text : '';
	} catch (err) {
		var e = new Error();
		e.message = "An error occurred while trying to load the data for struct [__GENOBJECT_ContactGroup]\n\nThe system returned the following error.\n\n" + err.message;
		throw e;
	}
}


function __GENOBJECT_Report(uReportXMLNode) {
	var b = (uReportXMLNode != undefined && uReportXMLNode != null);
	
	try {
		this.ID			    	 = b ? uReportXMLNode.selectSingleNode("ID").text : '';
		this.Category	    	 = b ? uReportXMLNode.selectSingleNode("Category").text : '';
		this.Filename	    	 = b ? uReportXMLNode.selectSingleNode("Filename").text : '';
		this.ReportType	    	 = b ? uReportXMLNode.selectSingleNode("ReportType").text.ToInt() : '0';
		this.Description    	 = b ? uReportXMLNode.selectSingleNode("Description").text : '';
		this.GroupViewID    	 = b ? uReportXMLNode.selectSingleNode("GroupViewID").text : '';
		this.GroupEditID    	 = b ? uReportXMLNode.selectSingleNode("GroupEditID").text : '';
		this.GroupDeleteID    	 = b ? uReportXMLNode.selectSingleNode("GroupDeleteID").text : '';
		this.DateCreated	     = b ? uReportXMLNode.selectSingleNode("DateCreated").text : '';
		this.DateUpdated	     = b ? uReportXMLNode.selectSingleNode("DateUpdated").text : '';
		this.CreatorName	     = b ? uReportXMLNode.selectSingleNode("CreatorName").text : '';
		this.ImageSRC		     = b & uReportXMLNode.selectSingleNode("ImageSRC") != null ? uReportXMLNode.selectSingleNode("ImageSRC").text : '';
		this.ExtendedDescription = b & uReportXMLNode.selectSingleNode("ExtendedDescription") != null ? uReportXMLNode.selectSingleNode("ExtendedDescription").text : '';
	} catch (err) {
		var e = new Error();
		e.message = "An error occurred while trying to load the data for struct [__GENOBJECT_Report]\n\nThe system returned the following error.\n\n" + err.message;
		throw e;
	}
}


function __GENOBJECT_Addin(uAddinXMLNode) {
	var b = (uAddinXMLNode != undefined && uAddinXMLNode != null);
	
	try {
		this.ID				= b ? uAddinXMLNode.selectSingleNode("ID").text : '';
		this.Description	= b ? uAddinXMLNode.selectSingleNode("Description").text : '';
		this.StartupPage	= b ? uAddinXMLNode.selectSingleNode("StartupPage").text : '';
		this.AddinImage		= b ? uAddinXMLNode.selectSingleNode("AddinImage").text : '';
		this.LargeAddinImage= b ? uAddinXMLNode.selectSingleNode("LargeAddinImage").text : '';
		this.WindowWidth	= b ? uAddinXMLNode.selectSingleNode("WindowWidth").text : '';
		this.WindowHeight	= b ? uAddinXMLNode.selectSingleNode("WindowHeight").text: '';
		this.AddToMenu		= b ? uAddinXMLNode.selectSingleNode("AddToMenu").text : '';
		this.AddToToolbar	= b ? uAddinXMLNode.selectSingleNode("AddToToolbar").text : '';
		
		this.GroupViewID	= b ? uAddinXMLNode.selectSingleNode("GroupViewID").text : '';
		this.GroupEditID	= b ? uAddinXMLNode.selectSingleNode("GroupEditID").text : '';
		this.GroupDeleteID	= b ? uAddinXMLNode.selectSingleNode("GroupDeleteID").text : '';
		this.DateCreated	= b ? uAddinXMLNode.selectSingleNode("DateCreated").text : '';
		this.DateUpdated	= b ? uAddinXMLNode.selectSingleNode("DateUpdated").text : '';
	} catch (err) {
		var e = new Error();
		e.message = "An error occurred while trying to load the data for struct [__GENOBJECT_Addin]\n\nThe system returned the following error.\n\n" + err.message;
		throw e;
	}
}

function __GENOBJECT_ContactOptions(iFlags) 
{
    if (iFlags != undefined) {
        iFlags = parseInt(iFlags, 10);
    } else {
        iFlags = 0;
    }
    
    this.Flags(iFlags);
}
__GENOBJECT_ContactOptions.prototype.Flags = __GENOBJECT_ContactOptions_Flags;

function __GENOBJECT_ContactOptions_Flags(iFlags) {
    
    if (iFlags != undefined) 
    {   // Set
        this.DoNotAllowContactByMailAtWork       = (iFlags != undefined && ((iFlags & Math.pow(2, 0)) != 0));
        this.DoNotAllowContactByMailAtHome       = (iFlags != undefined && ((iFlags & Math.pow(2, 1)) != 0));
        this.DoNotAllowContactByPhoneAtWork      = (iFlags != undefined && ((iFlags & Math.pow(2, 2)) != 0));
        this.DoNotAllowContactByPhoneAtHome      = (iFlags != undefined && ((iFlags & Math.pow(2, 3)) != 0));
        this.DoNotAllowContactByPhoneAtMobile    = (iFlags != undefined && ((iFlags & Math.pow(2, 4)) != 0));
        this.DoNotAllowContactByEmailAtWork      = (iFlags != undefined && ((iFlags & Math.pow(2, 5)) != 0));
        this.DoNotAllowContactByEmailAtHome      = (iFlags != undefined && ((iFlags & Math.pow(2, 6)) != 0));
        this.DoNotAllowContactBySMS              = (iFlags != undefined && ((iFlags & Math.pow(2, 7)) != 0));
    
        return true;
    } 
    else 
    {   // Get 
        iFlags = 0;                    
        if (this.DoNotAllowContactByMailAtWork)     iFlags += Math.pow(2, 0);   
        if (this.DoNotAllowContactByMailAtHome)     iFlags += Math.pow(2, 1);   
        if (this.DoNotAllowContactByPhoneAtWork)    iFlags += Math.pow(2, 2);  
        if (this.DoNotAllowContactByPhoneAtHome)    iFlags += Math.pow(2, 3);  
        if (this.DoNotAllowContactByPhoneAtMobile)  iFlags += Math.pow(2, 4);  
        if (this.DoNotAllowContactByEmailAtWork)    iFlags += Math.pow(2, 5);  
        if (this.DoNotAllowContactByEmailAtHome)    iFlags += Math.pow(2, 6);  
        if (this.DoNotAllowContactBySMS)            iFlags += Math.pow(2, 7);      
        
        return iFlags;
    }                  
}

// ** General Recurring Letter objects added by Rob - 2008-01-14 
// ****************************************************************************************************

__GENOBJECT_RecurringLetterClass.NotificationTypes = { Email : 1, SMS : 2, System : 4 }


__GENOBJECT_RecurringLetterClass.Arguments = new FunctionArguments({
                                                                    // ** Either load from an XML node
                                                                    XMLNode                 : '[xmlnode] [optional] An object reference to an XML node that represents the recurring letter',
                                                                    
                                                                    // ** Or load verbosly using properties
                                                                    ID                      : '[string] [optional] The ID of the recurring letter',   
                                                                    CampaignID              : '[string] [optional] The ID of the associated campaign',   
                                                                    TargetGroupID           : '[string] [optional] The ID of the associated record selection',   
                                                                    DocumentID              : '[string] [optional] The ID of the associated document template',      
                                                                    DatabaseID              : '[string] [optional] The ID of the associated database',
                                                                    ScheduleID              : '[string] [optional] The ID of the associated schedule', 
                                                                    LetterName              : '[string] [optional] The display name of the recurring letter',    
                                                                    LetterDescription       : '[string] [optional] The text description of the recurring letter',
                                                                    RuleBehaviour           : '[int] [optional] Determines whether this recurring letter follows the engine mailing rules',
                                                                    NotificationRequired    : '[int] [optional] Specifies the type of notification to use',
                                                                    NotificationType        : '[int] [optional] Determines the format of the notification',
                                                                    NotificationGroupID     : '[string] [optional] The ID of security group to notify',
                                                                    SecurityGroupID         : '[string] [optional] The ID of the recurring letters security assignment',
                                                                    OwnerID                 : '[string] [optional] The ID of the user that owns the item',
                                                                    Private                 : '[int] [optional] Determines whether this item is publicly viewable',
                                                                    CreatorName             : '[string] [optional] The name of the user that owns the recurring letter',
                                                                    DateCreated             : '[date] [optional] The date the item was created',
                                                                    DateUpdated             : '[date] [optional] The date the item was last modified',
                                                                    OrganisationID          : '[string] [optional] The ID of the organisation that this letter belongs to',
                                                                    JournalRequired         : '[int] [optional] Specifies whether to create a journal item or not',
                                                                    FollowUpActivity        : '[__GENOBJECT_RecurringLetterFollowUpItem] [optional] Object reference to a follow up activity item',
                                                                    FollowUpNote            : '[__GENOBJECT_RecurringLetterFollowUpItem] [optional] Object reference to a follow up note item'
                                                      })

function __GENOBJECT_RecurringLetterClass(Arguments) {

    // ** Make sure we got ok arguments
    if (Arguments == undefined || Arguments == null || typeof(Arguments) != 'object')
        throw new Error("An invalid FunctionArguments object was supplied");
        
    // ** Which method are we going to use
    var bXMLMode = (Arguments.XMLNode != undefined && Arguments.XMLNode != null && typeof(Arguments.XMLNode) == 'object');
    
    switch (bXMLMode)
    {
        case true:

            // try
            // {           
            // ** Assign the standard properties from the XML node
            this.ID = Arguments.XMLNode.selectSingleNode("ID").text;
            this.CampaignID = Arguments.XMLNode.selectSingleNode("CampaignID").text;
            this.TargetGroupID = Arguments.XMLNode.selectSingleNode("TargetGroupID").text;
            this.DocumentID = Arguments.XMLNode.selectSingleNode("DocumentID").text;
            this.DatabaseID = Arguments.XMLNode.selectSingleNode("DatabaseID").text;
            this.ScheduleID = Arguments.XMLNode.selectSingleNode("ScheduleID").text;
            this.LetterName = Arguments.XMLNode.selectSingleNode("LetterName").text;
            this.LetterDescription = Arguments.XMLNode.selectSingleNode("LetterDescription").text;
            this.RuleBehaviour = Arguments.XMLNode.selectSingleNode("RuleBehaviour").text.ToInt();
            this.NotificationRequired = Arguments.XMLNode.selectSingleNode("NotificationRequired").text.ToInt();
            this.NotificationType = Arguments.XMLNode.selectSingleNode("NotificationType").text.ToInt();
            this.NotificationGroupID = Arguments.XMLNode.selectSingleNode("NotificationGroupID").text;
            this.SecurityGroupID = Arguments.XMLNode.selectSingleNode("SecurityGroupID").text;
            this.OwnerID = Arguments.XMLNode.selectSingleNode("OwnerID").text;
            this.Private = Arguments.XMLNode.selectSingleNode("Private").text.ToInt();
            this.CreatorName = Arguments.XMLNode.selectSingleNode("CreatorName").text;
            this.DateCreated = Arguments.XMLNode.selectSingleNode("DateCreated").text;
            this.DateUpdated = Arguments.XMLNode.selectSingleNode("DateUpdated").text;
            this.OrganisationID = Arguments.XMLNode.selectSingleNode("OrganisationID").text;
            this.JournalRequired = (Arguments.XMLNode.selectSingleNode("JournalRequired").text.ToInt() == 1) ? true : false;
            this.JobFlags = Arguments.XMLNode.selectSingleNode("JobFlags").text.ToInt();
            
            // ** Display property for next scheduled run time
            try {
                this.NextOccurance = new Date();
                this.NextOccurance.ParseDate(Arguments.XMLNode.selectSingleNode("NextOccurance").text);
            }
            catch (errNextOccurance) {
                if (this.NextOccurance == undefined)
                    this.NextOccurance = "";
            }

            // ** Get the follow up note properties
            var bCreateNote = (Arguments.XMLNode.selectSingleNode("CreateNote").text.ToInt() == 1) ? true : false;
            var iNoteInterval = Arguments.XMLNode.selectSingleNode("NoteInterval").text.ToInt();
            var iNoteUnit = Arguments.XMLNode.selectSingleNode("NoteUnit").text.ToInt();
            var iNoteDirection = Arguments.XMLNode.selectSingleNode("NoteDirection").text.ToInt();
            var strNoteSubject = Arguments.XMLNode.selectSingleNode("NoteSubject").text;
            var strNoteText = Arguments.XMLNode.selectSingleNode("NoteText").text;
            var strNoteOwnerID = Arguments.XMLNode.selectSingleNode("NoteOwnerID").text;

            // ** Get the follow up activity properties
            var bCreateActivity = (Arguments.XMLNode.selectSingleNode("CreateActivity").text.ToInt() == 1) ? true : false;
            var iActivityInterval = Arguments.XMLNode.selectSingleNode("ActivityInterval").text.ToInt();
            var iActivityUnit = Arguments.XMLNode.selectSingleNode("ActivityUnit").text.ToInt();
            var iActivityDirection = Arguments.XMLNode.selectSingleNode("ActivityDirection").text.ToInt();
            var strActivitySubject = Arguments.XMLNode.selectSingleNode("ActivitySubject").text;
            var strActivityText = Arguments.XMLNode.selectSingleNode("ActivityText").text;
            var strActivityOwnerID = Arguments.XMLNode.selectSingleNode("ActivityOwnerID").text;

            // ** Create the follow up objects
            this.FollowUpNote = new __GENOBJECT_RecurringLetterFollowUpItem("NOTE", bCreateNote, iNoteInterval, iNoteUnit, iNoteDirection, strNoteSubject, strNoteText, strNoteOwnerID, "");
            this.FollowUpActivity = new __GENOBJECT_RecurringLetterFollowUpItem("ACTIVITY", bCreateActivity, iActivityInterval, iActivityUnit, iActivityDirection, strActivitySubject, strActivityText, strActivityOwnerID, "");


            // }
            // catch (err)
            // {
            //     throw new Error("An error occured whilst creating a recurring letter object from an XML node.\nError Returned: " + err.message);
            // }

            break;
            
        case false:            
        
            try
            {
                // ** Assign the standard properties
                this.ID                     = (Arguments.ID                   != undefined) ? Arguments.ID                           : "{00000000-0000-0000-0000-000000000000}";                       
                this.CampaignID             = (Arguments.CampaignID           != undefined) ? Arguments.CampaignID                   : "{00000000-0000-0000-0000-000000000000}";                       
                this.TargetGroupID          = (Arguments.TargetGroupID        != undefined) ? Arguments.TargetGroupID                : "{00000000-0000-0000-0000-000000000000}";                       
                this.DocumentID             = (Arguments.DocumentID           != undefined) ? Arguments.DocumentID                   : "{00000000-0000-0000-0000-000000000000}";                        
                this.DatabaseID             = (Arguments.DatabaseID           != undefined) ? Arguments.DatabaseID                   : "{00000000-0000-0000-0000-000000000000}";
                this.ScheduleID             = (Arguments.ScheduleID           != undefined) ? Arguments.ScheduleID                   : "{00000000-0000-0000-0000-000000000000}";                        
                this.LetterName             = (Arguments.LetterName           != undefined) ? Arguments.LetterName                   : "";                         
                this.LetterDescription      = (Arguments.LetterDescription    != undefined) ? Arguments.LetterDescription            : "";                          
                this.RuleBehaviour          = (Arguments.RuleBehaviour        != undefined) ? Arguments.RuleBehaviour.ToInt()        : 0;                        
                this.NotificationRequired   = (Arguments.NotificationRequired != undefined) ? Arguments.NotificationRequired.ToInt() : 0;                           
                this.NotificationType       = (Arguments.NotificationType     != undefined) ? Arguments.NotificationType.ToInt()     : RecurringLetterClass.NotificationTypes.Email;                            
                this.NotificationGroupID    = (Arguments.NotificationGroupID  != undefined) ? Arguments.NotificationGroupID          : "{00000000-0000-0000-0000-000000000000}";                        
                this.SecurityGroupID        = (Arguments.SecurityGroupID      != undefined) ? Arguments.SecurityGroupID              : "{00000000-0000-0000-0000-000000000000}";                        
                this.OwnerID                = (Arguments.OwnerID              != undefined) ? Arguments.OwnerID                      : "{00000000-0000-0000-0000-000000000000}";                        
                this.Private                = (Arguments.Private              != undefined) ? Arguments.Private.ToInt()              : 0;                         
                this.CreatorName            = (Arguments.CreatorName          != undefined) ? Arguments.CreatorName                  : "";                          
                this.DateCreated            = (Arguments.DateCreated          != undefined) ? Arguments.DateCreated                  : new Date(); 
                this.DateUpdated            = (Arguments.DateUpdated          != undefined) ? Arguments.DateUpdated                  : new Date();  
                this.OrganisationID         = (Arguments.OrganisationID       != undefined) ? Arguments.OrganisationID               : "{00000000-0000-0000-0000-000000000000}";                        
                this.JournalRequired        = (Arguments.RuleBehaviour        != undefined) ? Arguments.RuleBehaviour.ToInt()        : 0;
                this.JobFlags               = (Arguments.JobFlags             != undefined) ? Arguments.JobFlags.ToInt()             : 0;          
                
                // ** Assign the follow up properties
                this.FollowUpActivity       = (Arguments.FollowUpActivity != undefined && Arguments.FollowUpActivity != null && typeof(Arguments.FollowUpActivity)     == 'object' && Arguments.FollowUpActivity.constructor == '__GENOBJECT_RecurringLetterFollowUpItem') ? Arguments.FollowUpActivity : new __GENOBJECT_RecurringLetterFollowUpItem("ACTIVITY", false, 0, 0, 0, "", "", "{00000000-0000-0000-0000-000000000000}", "Unassigned");                
                this.FollowUpNote           = (Arguments.FollowUpNote     != undefined && Arguments.FollowUpNote     != null && typeof(Arguments.FollowUpFollowUpNote) == 'object' && Arguments.FollowUpNote.constructor     == '__GENOBJECT_RecurringLetterFollowUpItem') ? Arguments.FollowUpNote     : new __GENOBJECT_RecurringLetterFollowUpItem("NOTE",     false, 0, 0, 0, "", "", "{00000000-0000-0000-0000-000000000000}", "Unassigned"); 
            }
            catch (err)
            {
                throw new Error("An error occured whilst creating a recurring letter object using properties.\nError Returned: " + err.message);
            }    
                
            break;
    }                
}


__GENOBJECT_RecurringLetterFollowUpItem.prototype.toString = function() { return "RecurringLetter"; }
function __GENOBJECT_RecurringLetterFollowUpItem(strItemType, bCreate, iInterval, iUnit, iDirection, strSubject, strContent, strOwnerID, strOwnerName) {

    this.ItemType  = (strItemType       != undefined) ? strItemType        : "";
    this.Create    = (bCreate           != undefined) ? bCreate            : false;
    this.Interval  = (isNaN(iInterval)  == false)     ? iInterval.ToInt()  : 0;
    this.Unit      = (isNaN(iUnit)      == false)     ? iUnit.ToInt()      : 0;
    this.Direction = (isNaN(iDirection) == false)     ? iDirection.ToInt() : 0;
    
    this.Subject   = (strSubject        != undefined && strSubject != "")   ? strSubject         : "";
    this.Content   = (strContent        != undefined && strContent != "")   ? strContent         : "";    
    this.OwnerID   = (strOwnerID        != undefined && strOwnerID != "")   ? strOwnerID         : "{00000000-0000-0000-0000-000000000000}";
    this.OwnerName = (strOwnerName      != undefined && strOwnerName != "") ? strOwnerName       : "";
}




//GeneralObjects.RecurringLetter = RecurringLetterClass;
//
//var o = new GeneralObjectLibrary.RecurringLetter();
