//This code is based on a singleton pattern developed by Douglas Crockford (commonly referred
//to as the 'module pattern').
//This pattern keeps your code out of the global namespace, provides publically addressable
//API methods, and supports protected or 'private' data and methods.
//
//     Usage Overview:
//     * Import the RIA scripts into all relevant html pages.
//     * This module acts as a factory to create proxy objects that represent
//       non-primitive parameter types - used when calling the web service api methods.

//Setup the module's namespace (typically, the module namespace will be your domain name)
/*global JMT Ext $*/
if (!JMT) {
	var JMT = {};
}

JMT.i18n = function(){
	//private variables and methods:   //can be accessed only from within JMT.i18n
	var i18n_dict = {};

	return{
		//the following section returns publicly accessable properties and methods
		//public variables can be accessed as this.myPublicProperty from within public methods
		//public methods can be accessed as JMT.i18n.publicMethodName

		myPublicProperty: [],
		
		setDictionary: function(dict) {
			i18n_dict = dict;
		},			

		init: function(){
			//example initialize : retrieve the appropriate dictionary back from the server, and push into the i18n dictionary
			i18dict = {
				//navigator constants
				"Cargo Enquiry"						: "Cargo Enquiry",
				"Enquire on cargo in the terminal"	: "Enquire on cargo in the terminal",
				"Cargo Notification Request"		: "Cargo Notification Request",
				"Notify me if something happens"	: "Notify me if something happens",
				"Cargo Release Imports"				: "Cargo Release Imports",
				"Assign import release"				: "Assign import release",
				"Cargo Stop Request"				: "Cargo Stop Request",
				"Add or remove cargo stops"			: "Add or remove cargo stops",
				"Pre-Notes"							: "Pre-Notes",
				"Run Reports"						: "Run Reports",
				"Report on cargo in the terminal"	: "Report on cargo in the terminal",
				"Change your JMT access password"	: "Change your JMT access password",
				"User Preference"					: "Change your user preferences",
				//form constants
				"Add"						: "Add",
				"Cancel"					: "Cancel",
				"Delete"					: "Delete",
				"Edit"						: "Edit",
				"Update" 					: "Update",
				"Advanced"					: "Advanced",
				"Advanced Search Criteria"	: "Advanced Search Criteria",
				"Loading..."				: "Loading...",
				"Output Options"			: "Output Options",
				"Parameters"				: "Parameters",
				"Report Parameters"			: "Report Parameters",
				"Run"						: "Run",
				"Run Report"				: "Run Report",
				"Search"					: "Search",
				"Search for"				: "Search for",
				"Search Results"			: "Search Results",
				//miscellaneous constants
				"Report Running"			: "Report Running, please wait...",
				//error message constants
				"Errors"					: "Errors",
				"Data not ready"			: "Data not ready",
				"Notification Request"		: "Notification Request",				
				"Parameter 'repeatedStoreField' has value" 		: "Parameter 'repeatedStoreField' has value",
				", which is not a defined webservices type" 	: ", which is not a defined webservices type",
				"The action failed due to the following errors"	: "The action failed due to the following errors",
				"Are you sure you want to delete the selected Notification Request?"	: "Are you sure you want to delete the selected Notification Request?",
				// Login/Logout
				"Logging out"								: "Logging out", // Loading message
				"Server returned an unexpected error"		: "Server returned an unexpected error", // Generic message for login/logout error dialog
				"System Error"								: "System Error", // Error dialog title
				"Logout has been completed with problems"	: "Logout has been completed with problems.", // Error message for logout dialog
				"Failed to login"							: "Failed to login", // Used as error dialog title AND in the status bar
				"Username"									: "Username", // form field
				"Password"									: "Password", // form field
				"Login to JMT"								: "Login to JMT", // Login screen title
				"Login"										: "Login", // Login screen button
				// Options Navigator
				"Options"			: "Options", // Window title
				// Options Navigator - ChangePassword form
				"Change Password"					: "Change Password", // Form title
				"OK"								: "OK", // form button
				"Current password"					: "Current password", // form field
				"New password"						: "New password", // form field
				"Confirm new password"				: "Confirm new password", // form field
				"Password confirmation is required"	: "Password confirmation is required", // Error message
				"Current password is required"		: "Current password is required", // Error message
				"New password is required"			: "New password is required", // Error message
				"Passwords do not match"			: "Passwords do not match", // Error message
				"Failed to change password"			: "Failed to change password", // Error message dialog
				"Failed to change password (click for details...)"	: "Failed to change password (click for details...)", // Status bar
				"The form has errors (click for details...)"		: "The form has errors (click for details...)", // Status bar
				"Click again to hide the error list"				: "Click again to hide the error list", // Status bar
				"Password changed successfully"						: "Password changed successfully", // Success message
				// Recipient Window
				"Select Recipients"					: "Select Recipients",
				"Add New Contact"					: "Add New Contact",
				"E-mail Contacts"					: "E-mail Contacts",
				"To"								: "To",
				"CC"								: "CC",
				"BCC"								: "BCC",
				"Drag contacts here"				: "Drag contacts here",
				"Reset"								: "Reset"
			};
			this.setDictionary(i18dict);
		},
		
	
		
		xlt: function (str) {
			var transl = str;
			if (i18n_dict && i18n_dict[str]) {
				transl = i18n_dict[str];
			}
			return transl;
		}
	};
}(); // the parens here cause the anonymous function to execute and return

//initialize the module
JMT.i18n.init();

