

var DemoWarning = '';


var LEFT = 'left';
var RIGHT = 'right';
if (window.RTL) {
	LEFT = 'right';
	RIGHT = 'left';
}

var HideFromInput = false;

// defines for sections
var SECTION_LOGIN = 0;
var SECTION_MAIL = 1;
var SECTION_SETTINGS = 2;
var SECTION_CONTACTS = 3;
var SECTION_CALENDAR = 4;

// defines for screens
var SCREEN_LOGIN = 0;
var SCREEN_MESSAGES_LIST_VIEW = 1;
var SCREEN_MESSAGES_LIST = 2;
var SCREEN_VIEW_MESSAGE = 3;
var SCREEN_NEW_MESSAGE = 4;
var SCREEN_USER_SETTINGS = 5;
	var PART_COMMON_SETTINGS = 0;
	var PART_ACCOUNT_PROPERTIES = 1;
	var PART_FILTERS = 2;
	var PART_SIGNATURE = 3;
	var PART_AUTORESPONDER = 4;
	var PART_MANAGE_FOLDERS = 5;
	var PART_CONTACTS_SETTINGS = 6;
	var PART_CALENDAR_SETTINGS = 7;
	var PART_MANAGE_FOLDERS_TYPE = 8;
var SCREEN_CONTACTS = 6;
	var PART_CONTACTS = 0;
	var PART_NEW_CONTACT = 1;
	var PART_VIEW_CONTACT = 2;
	var PART_EDIT_CONTACT = 3;
	var PART_NEW_GROUP = 4;
	var PART_VIEW_GROUP = 5;
	var PART_IMPORT_CONTACT = 6;
var SCREEN_CALENDAR = 7;

var Sections = Array();
Sections[SECTION_LOGIN] = {Scripts: [], Screens: Array()};
Sections[SECTION_MAIL] = {Scripts: [], Screens: Array()};
Sections[SECTION_MAIL].Screens[SCREEN_MESSAGES_LIST_VIEW] = 'screen = new CMessagesListViewScreen(SkinName);';
Sections[SECTION_MAIL].Screens[SCREEN_MESSAGES_LIST] = 'screen = new CMessagesListScreen(SkinName);';
Sections[SECTION_MAIL].Screens[SCREEN_VIEW_MESSAGE] = 'screen = new CViewMessageScreen(SkinName);';
Sections[SECTION_MAIL].Screens[SCREEN_NEW_MESSAGE] = 'screen = new CNewMessageScreen(SkinName);';
//Sections[SECTION_SETTINGS] = {Scripts: ['screen.user-settings.js', 'screen.common-settings.js', 'screen.accounts-settings.js', 'screen.account-properties.js', 'screen.contacts-settings.js'], Screens: Array()}
Sections[SECTION_SETTINGS] = {Scripts: [], Screens: Array()};
Sections[SECTION_SETTINGS].Screens[SCREEN_USER_SETTINGS] = 'screen = new CUserSettingsScreen(SkinName);';
//Sections[SECTION_CONTACTS] = {Scripts: ['screen.contacts.js', 'screen.view-contact.js'], Screens: Array()}
Sections[SECTION_CONTACTS] = {Scripts: [], Screens: Array()};
Sections[SECTION_CONTACTS].Screens[SCREEN_CONTACTS] = 'screen = new CContactsScreen(SkinName);';
Sections[SECTION_CALENDAR] = {Scripts: [], Screens: Array()};
Sections[SECTION_CALENDAR].Screens[SCREEN_CALENDAR] = 'screen = new CCalendarScreen(SkinName);';

var Screens = Array();
Screens[SCREEN_LOGIN] = {SectionId: SECTION_LOGIN, PreRender: true, ShowHandler: ''};
Screens[SCREEN_MESSAGES_LIST_VIEW] = {SectionId: SECTION_MAIL, PreRender: true, ShowHandler: ''};
Screens[SCREEN_MESSAGES_LIST] = {SectionId: SECTION_MAIL, PreRender: false, ShowHandler: ''};
Screens[SCREEN_VIEW_MESSAGE] = {SectionId: SECTION_MAIL, PreRender: false, ShowHandler: ''};
Screens[SCREEN_NEW_MESSAGE] = {SectionId: SECTION_MAIL, PreRender: true, ShowHandler: ''};
Screens[SCREEN_USER_SETTINGS] = {SectionId: SECTION_SETTINGS, PreRender: true, ShowHandler: ''};
Screens[SCREEN_CONTACTS] = {SectionId: SECTION_CONTACTS, PreRender: true, ShowHandler: ''};
Screens[SCREEN_CALENDAR] = {SectionId: SECTION_CALENDAR, PreRender: true, ShowHandler: ''};

// defines data types
var TYPE_ACCOUNT_BASE = 0; // includes FOLDERS_LIST, MESSAGES_LIST
var TYPE_ACCOUNT_PROPERTIES = 1;
var TYPE_ACCOUNTS_LIST = 2;
var TYPE_AUTORESPONDER = 3;
var TYPE_BASE = 4; // includes SETTINGS_LIST, ACCOUNTS_LIST, FOLDERS_LIST, MESSAGES_LIST
var TYPE_CONTACT = 5;
var TYPE_CONTACTS = 6;
var TYPE_CONTACTS_SETTINGS = 7;
var TYPE_FILTER_PROPERTIES = 8;
var TYPE_FILTERS = 9;
var TYPE_FOLDERS_BASE = 10; // includes MESSAGES_LISTs for 1 page in several folders
var TYPE_FOLDERS_LIST = 11;
var TYPE_GROUP = 12;
var TYPE_GROUPS = 13;
var TYPE_MESSAGE = 14;
var TYPE_MESSAGES_BODIES = 15; // includes MESSAGE for messages with size<=75K in last MESSAGES_LIST
var TYPE_MESSAGES_LIST = 16;
var TYPE_MESSAGES_OPERATION = 17;
var TYPE_SETTINGS_LIST = 18;
var TYPE_SIGNATURE = 19;
var TYPE_SPELLCHECK = 20;
var TYPE_UPDATE = 21;
var TYPE_USER_SETTINGS = 22;

//defines for folder types
var FOLDER_TYPE_DEFAULT = 0;
var FOLDER_TYPE_INBOX = 1;
var FOLDER_TYPE_SENT = 2;
var FOLDER_TYPE_DRAFTS = 3;
var FOLDER_TYPE_TRASH = 4;
var FOLDER_TYPE_SPAM = 5;
var FOLDER_TYPE_QUARANTINE = 6;
var FOLDER_TYPE_DEFAULT_SYNC = 20;
var FOLDER_TYPE_INBOX_SYNC = 21;
var FOLDER_TYPE_SENT_SYNC = 22;
var FOLDER_TYPE_DRAFTS_SYNC = 23;
var FOLDER_TYPE_TRASH_SYNC = 24;
var FOLDER_TYPE_SPAM_SYNC = 25;
var FOLDER_TYPE_QUARANTINE_SYNC = 26;

var FolderDescriptions = [];
FolderDescriptions[FOLDER_TYPE_DEFAULT] = {x: 0, y: 2};
FolderDescriptions[FOLDER_TYPE_DEFAULT_SYNC] = {x: 1, y: 2};
FolderDescriptions[FOLDER_TYPE_DRAFTS] = {x: 2, y: 2, langField: 'FolderDrafts'};
FolderDescriptions[FOLDER_TYPE_DRAFTS_SYNC] = {x: 3, y: 2, langField: 'FolderDrafts'};
FolderDescriptions[FOLDER_TYPE_INBOX] = {x: 4, y: 2, langField: 'FolderInbox'};
FolderDescriptions[FOLDER_TYPE_INBOX_SYNC] = {x: 5, y: 2, langField: 'FolderInbox'};
FolderDescriptions[FOLDER_TYPE_SENT] = {x: 6, y: 2, langField: 'FolderSentItems'};
FolderDescriptions[FOLDER_TYPE_SENT_SYNC] = {x: 7, y: 2, langField: 'FolderSentItems'};
FolderDescriptions[FOLDER_TYPE_TRASH] = {x: 8, y: 2, langField: 'FolderTrash'};
FolderDescriptions[FOLDER_TYPE_TRASH_SYNC] = {x: 9, y: 2, langField: 'FolderTrash'};
FolderDescriptions[FOLDER_TYPE_SPAM] = {x: 10, y: 2, langField: 'FolderSpam'};
FolderDescriptions[FOLDER_TYPE_SPAM_SYNC] = {x: 11, y: 2, langField: 'FolderSpam'};
FolderDescriptions[FOLDER_TYPE_QUARANTINE] = {x: 0, y: 2, langField: 'FolderQuarantine'};
FolderDescriptions[FOLDER_TYPE_QUARANTINE_SYNC] = {x: 1, y: 2, langField: 'FolderQuarantine'};

//defines for sync type
var SYNC_TYPE_NO = 0;
var SYNC_TYPE_NEW_HEADERS = 1;
var SYNC_TYPE_ALL_HEADERS = 2;
var SYNC_TYPE_NEW_MSGS = 3;
var SYNC_TYPE_ALL_MSGS = 4;
var SYNC_TYPE_DIRECT_MODE = 5;

var SORT_FIELD_NOTHING = -1;
var SORT_FIELD_DATE = 0;
var SORT_FIELD_FROM = 2;
var SORT_FIELD_TO = 4;
var SORT_FIELD_SIZE = 6;
var SORT_FIELD_SUBJECT = 8;
var SORT_FIELD_ATTACH = 10;
var SORT_FIELD_FLAG = 12;
var SORT_ORDER_DESC = 0;
var SORT_ORDER_ASC = 1;

//defines for inbox headers
var IH_CHECK = 0;
var IH_ATTACHMENTS = 1;
var IH_FLAGGED = 2;
var IH_FROM = 3;
var IH_TO = 4;
var IH_DATE = 5;
var IH_SIZE = 6;
var IH_SUBJECT = 7;
var IH_CC = 8;
var IH_BCC = 9;
var IH_REPLY_TO = 10;

/*
sortIconPlace values:
	0 - left of content
	1 - instead of content
	2 - right of content
align values: 'left', 'center', 'right'
*/
var InboxHeaders = Array();
InboxHeaders[IH_CHECK] =
{
	DisplayField: 'Check',
	LangField: '',
	Picture: '',
	SortField: SORT_FIELD_NOTHING,
	SortIconPlace: 1,
	Align: 'center', 
	Width: 24,
	MinWidth: 24,
	IsResize: false
};
InboxHeaders[IH_ATTACHMENTS] =
{
	DisplayField: 'HasAttachments',
	LangField: '',
	Picture: 'wm_inbox_lines_attachment',
	SortField: SORT_FIELD_ATTACH,
	SortIconPlace: 1,
	Align: 'center', 
	Width: 20,
	MinWidth: 20,
	IsResize: false
};
InboxHeaders[IH_FLAGGED] =
{
	DisplayField: 'Flagged',
	LangField: '',
	Picture: 'wm_inbox_lines_flag',
	SortField: SORT_FIELD_FLAG,
	SortIconPlace: 1,
	Align: 'center', 
	Width: 20,
	MinWidth: 20,
	IsResize: false
};
/*rtl*/
InboxHeaders[IH_FROM] =
{
	DisplayField: 'FromAddr',
	LangField: 'From',
	Picture: '',
	SortField: SORT_FIELD_FROM,
	SortIconPlace: 2,
	Align: window.LEFT, 
	Width: 150,
	MinWidth: 100,
	IsResize: true
};
InboxHeaders[IH_TO] =
{
	DisplayField: 'ToAddr',
	LangField: 'To',
	Picture: '',
	SortField: SORT_FIELD_TO,
	SortIconPlace: 2,
	Align: window.LEFT, 
	Width: 150,
	MinWidth: 100,
	IsResize: true
};
InboxHeaders[IH_DATE] =
{
	DisplayField: 'Date',
	LangField: 'Date',
	Picture: '',
	SortField: SORT_FIELD_DATE,
	SortIconPlace: 2,
	Align: 'center', 
	Width: 140,
	MinWidth: 100,
	IsResize: true
};
InboxHeaders[IH_SIZE] =
{
	DisplayField: 'Size',
	LangField: 'Size',
	Picture: '',
	SortField: SORT_FIELD_SIZE,
	SortIconPlace: 2,
	Align: 'center', 
	Width: 50,
	MinWidth: 40,
	IsResize: true
};
InboxHeaders[IH_SUBJECT] =
{
	DisplayField: 'Subject',
	LangField: 'Subject',
	Picture: '',
	SortField: SORT_FIELD_SUBJECT,
	SortIconPlace: 2,
	Align: window.LEFT, 
	Width: 150,
	MinWidth: 100,
	IsResize: true
};
InboxHeaders[IH_CC] =
{
	DisplayField: 'CCAddr',
	LangField: 'CC',
	Picture: '',
	SortField: SORT_FIELD_NOTHING,
	SortIconPlace: 2,
	Align: 'center', 
	Width: 100,
	MinWidth: 100,
	IsResize: false
};
InboxHeaders[IH_BCC] =
{
	DisplayField: 'BCCAddr',
	LangField: 'BCC',
	Picture: '',
	SortField: SORT_FIELD_NOTHING,
	SortIconPlace: 2,
	Align: 'center', 
	Width: 100,
	MinWidth: 100,
	IsResize: false
};
InboxHeaders[IH_REPLY_TO] =
{
	DisplayField: 'ReplyToAddr',
	LangField: 'ReplyTo',
	Picture: '',
	SortField: SORT_FIELD_NOTHING,
	SortIconPlace: 2,
	Align: 'center', 
	Width: 100,
	MinWidth: 100,
	IsResize: false
};

//defines for parts of message type
var PART_MESSAGE_HEADERS = 0;
var PART_MESSAGE_HTML = 1;
var PART_MESSAGE_MODIFIED_PLAIN_TEXT = 2;
var PART_MESSAGE_REPLY_HTML = 3;
var PART_MESSAGE_REPLY_PLAIN = 4;
var PART_MESSAGE_FORWARD_HTML = 5;
var PART_MESSAGE_FORWARD_PLAIN = 6;
var PART_MESSAGE_FULL_HEADERS = 7;
var PART_MESSAGE_ATTACHMENTS = 8;
var PART_MESSAGE_UNMODIFIED_PLAIN_TEXT = 9;
 
// defines for toolbar items
var TOOLBAR_NEW_MESSAGE = 1;
var TOOLBAR_CHECK_MAIL = 2;
var TOOLBAR_RELOAD_FOLDERS = 3;
var TOOLBAR_REPLY = 4;
var TOOLBAR_REPLYALL = 5;
var TOOLBAR_FORWARD = 6;
var TOOLBAR_MARK_READ = 7;
var TOOLBAR_MOVE_TO_FOLDER = 8;
var TOOLBAR_DELETE = 9;
var TOOLBAR_UNDELETE = 10;
var TOOLBAR_PURGE = 11;
var TOOLBAR_EMPTY_TRASH = 12;
var TOOLBAR_IS_SPAM = 13;
var TOOLBAR_NOT_SPAM = 14;
var TOOLBAR_SEARCH = 15;
var TOOLBAR_BIG_SEARCH = 16;
var TOOLBAR_SEARCH_ARROW_DOWN = 17;
var TOOLBAR_SEARCH_ARROW_UP = 18;
var TOOLBAR_ARROW = 19;

//second line in mail.png
var TOOLBAR_BACK_TO_LIST = 20;
var TOOLBAR_SEND_MESSAGE = 21;
var TOOLBAR_SAVE_MESSAGE = 22;
var TOOLBAR_HIGH_IMPORTANCE = 23;
var TOOLBAR_LOW_IMPORTANCE = 24;
var TOOLBAR_NORMAL_IMPORTANCE = 25;
var TOOLBAR_PRINT_MESSAGE = 26;
var TOOLBAR_NEXT_ACTIVE = 27;
var TOOLBAR_NEXT_INACTIVE = 28;
var TOOLBAR_PREV_ACTIVE = 29;
var TOOLBAR_PREV_INACTIVE = 30;
var TOOLBAR_NEW_CONTACT = 31;
var TOOLBAR_NEW_GROUP = 32;
var TOOLBAR_ADD_CONTACTS_TO = 33;
var TOOLBAR_IMPORT_CONTACTS = 34;
var TOOLBAR_IMPORTANCE = 35;

//third line in mail.png
var TOOLBAR_MARK_UNREAD = 36;
var TOOLBAR_FLAG = 37;
var TOOLBAR_UNFLAG = 38;
var TOOLBAR_MARK_ALL_READ = 39;
var TOOLBAR_MARK_ALL_UNREAD = 40;

var TOOLBAR_EMPTY_SPAM = 41;

var OperationTypes = Array();
OperationTypes[TOOLBAR_DELETE] = 'delete';
OperationTypes[TOOLBAR_UNDELETE] = 'undelete';
OperationTypes[TOOLBAR_PURGE] = 'purge';
OperationTypes[TOOLBAR_MARK_READ] = 'mark_read';
OperationTypes[TOOLBAR_MARK_UNREAD] = 'mark_unread';
OperationTypes[TOOLBAR_FLAG] = 'flag';
OperationTypes[TOOLBAR_UNFLAG] = 'unflag';
OperationTypes[TOOLBAR_MARK_ALL_READ] = 'mark_all_read';
OperationTypes[TOOLBAR_MARK_ALL_UNREAD] = 'mark_all_unread';
OperationTypes[TOOLBAR_MOVE_TO_FOLDER] = 'move_to_folder';
OperationTypes[TOOLBAR_IS_SPAM] = 'spam';
OperationTypes[TOOLBAR_NOT_SPAM] = 'not_spam';
OperationTypes[TOOLBAR_EMPTY_SPAM] = 'clear_spam';

var REDRAW_NOTHING = 0;
var REDRAW_FOLDER = 1;
var REDRAW_HEADER = 2;
var REDRAW_PAGE = 3;

var COOKIE_STORAGE_DAYS = 20;
var FOLDERS_TREES_INDENT = 8;
var AUTOSELECT_CHARSET = -1;
var X_ICON_SHIFT = 40;
var Y_ICON_SHIFT = 40;

var POP3_PROTOCOL = 0;
var IMAP4_PROTOCOL = 1;
var WMSERVER_PROTOCOL = 2;
var POP3_PORT = 110;
var IMAP4_PORT = 143;
var SMTP_PORT = 25;

var VIEW_MODE_WITH_PANE = 1;
var VIEW_MODE_SHOW_PICTURES = 2;

var $Title = Array();
$Title[SCREEN_LOGIN] = Lang.TitleLogin;
$Title[SCREEN_MESSAGES_LIST_VIEW] = Lang.TitleMessagesListView;
$Title[SCREEN_MESSAGES_LIST] = Lang.TitleMessagesList;
$Title[SCREEN_VIEW_MESSAGE] = Lang.TitleViewMessage;
$Title[SCREEN_NEW_MESSAGE] = Lang.TitleNewMessage;
$Title[SCREEN_USER_SETTINGS] = Lang.TitleSettings;
$Title[SCREEN_CONTACTS] = Lang.TitleContacts;
$Title[SCREEN_CALENDAR] = Lang.Calendar;
Lang.Title = $Title;

var $SyncTypes = Array();
$SyncTypes[SYNC_TYPE_NO] = Lang.SyncTypeNo;
$SyncTypes[SYNC_TYPE_NEW_HEADERS] = Lang.SyncTypeNewHeaders;
$SyncTypes[SYNC_TYPE_ALL_HEADERS] = Lang.SyncTypeAllHeaders;
$SyncTypes[SYNC_TYPE_NEW_MSGS] = Lang.SyncTypeNewMessages;
$SyncTypes[SYNC_TYPE_ALL_MSGS] = Lang.SyncTypeAllMessages;
$SyncTypes[SYNC_TYPE_DIRECT_MODE] = Lang.SyncTypeDirectMode;
Lang.SyncTypes = $SyncTypes;

var $Pop3InboxSyncTypes = Array();
$Pop3InboxSyncTypes[SYNC_TYPE_NEW_HEADERS] = Lang.Pop3SyncTypeEntireHeaders;
$Pop3InboxSyncTypes[SYNC_TYPE_NEW_MSGS] = Lang.Pop3SyncTypeEntireMessages;
$Pop3InboxSyncTypes[SYNC_TYPE_DIRECT_MODE] = Lang.Pop3SyncTypeDirectMode;
Lang.Pop3InboxSyncTypes = $Pop3InboxSyncTypes;

//defines for contacts headers
var CH_CHECK = 20;
var CH_GROUP = 21;
var CH_NAME = 22;
var CH_EMAIL = 23;

var SORT_FIELD_GROUP = 0;
var SORT_FIELD_NAME = 1;
var SORT_FIELD_EMAIL = 2;
var SORT_FIELD_USE_FREQ = 3;

var ContactsHeaders = Array();
ContactsHeaders[CH_CHECK] =
{
	DisplayField: 'Check',
	LangField: '',
	Picture: '',
	SortField: SORT_FIELD_NOTHING,
	SortIconPlace: 1,
	Align: 'center', 
	Width: 24,
	MinWidth: 24,
	IsResize: false
};
ContactsHeaders[CH_GROUP] =
{
	DisplayField: 'IsGroup',
	LangField: '',
	Picture: 'wm_inbox_lines_group',
	SortField: SORT_FIELD_GROUP,
	SortIconPlace: 1,
	Align: 'center', 
	Width: 25,
	MinWidth: 25,
	IsResize: false
};
ContactsHeaders[CH_NAME] =
{
	DisplayField: 'Name',
	LangField: 'Name',
	Picture: '',
	SortField: SORT_FIELD_NAME,
	SortIconPlace: 2,
	Align: window.LEFT, 
	Width: 150,
	MinWidth: 100,
	IsResize: true
};
ContactsHeaders[CH_EMAIL] =
{
	DisplayField: 'Email',
	LangField: 'Email',
	Picture: '',
	SortField: SORT_FIELD_EMAIL,
	SortIconPlace: 2,
	Align: window.LEFT,
	Width: 150,
	MinWidth: 100,
	IsResize: true
};

var PRIMARY_HOME_EMAIL = 0;
var PRIMARY_BUSS_EMAIL = 1;
var PRIMARY_OTHER_EMAIL = 2;

var GET_FOLDERS_NOT_CHANGE_ACCT = -1;
var GET_FOLDERS_NOT_SYNC = 0;
var GET_FOLDERS_SYNC_MESSAGES = 1;
var GET_FOLDERS_SYNC_FOLDERS = 2;

if (window.JSFileLoaded != undefined) JSFileLoaded();
/*
 * Classes, prototypes:
 *  CBrowser
 *  CPopupMenu
 *  CPopupMenus
 *  CSearchForm
 *  CError
 *  CReport
 *  ReportPrototype
 *  CInformation
 *  CFadeEffect
 *  CValidate
 *  CPageSwitcher
 * 
 *  CCheckMail
 * 
 *  CScriptLoader
 *  CNetLoader
 *  CDictionary
 *
 *  CLanguageChanger
 */

function CBrowser()
{
	this.Init = function()
	{
		var len = this.Profiles.length;
		for (var i = 0; i < len; i++) {
			if (this.Profiles[i].Criterion) {
				this.Name = this.Profiles[i].Id;
				this.Version = this.Profiles[i].Version();
				this.Allowed = this.Version >= this.Profiles[i].AtLeast;
     			break;
			}
   		};
		this.IE = (this.Name == 'Microsoft Internet Explorer');
		this.Opera = (this.Name == 'Opera');
		this.Mozilla = (this.Name == 'Mozilla' || this.Name == 'Firefox' || this.Name == 'Netscape' || this.Name == 'Chrome');
		this.Safari = (this.Name == 'Safari');
		this.Chrome = (this.Name == 'Chrome');
		this.Gecko = (this.Opera || this.Mozilla);
	};

	this.Profiles = [
		{
			Id: 'Opera',
			Criterion: window.opera,
			AtLeast: 8,
			Version: function() {
				var start, end;
				var r = navigator.userAgent;
				var start1 = r.indexOf('Opera/');
				var start2 = r.indexOf('Opera ');
				if (-1 == start1) {
					start = start2 + 6;
					end = r.length;
				} else {
					start = start1 + 6;
					end = r.indexOf(' ');
				};
				r = parseFloat(r.slice(start, end));
				return r;
			}
		},
		{
			Id: 'Chrome',
			Criterion:
			(
				(navigator.appCodeName.toLowerCase() == 'mozilla') &&
				(navigator.appName.toLowerCase() == 'netscape') &&
				(navigator.product.toLowerCase() == 'gecko') &&
				(navigator.userAgent.toLowerCase().indexOf('chrome') != -1)
			),
			AtLeast: 0,
			Version: function() {
				return parseFloat(navigator.userAgent.split('Chrome/').reverse().join('Chrome/'));
			}
		},
		{
			Id: 'Safari',
			Criterion:
			(
				(navigator.appCodeName.toLowerCase() == 'mozilla') &&
				(navigator.appName.toLowerCase() == 'netscape') &&
				(navigator.product.toLowerCase() == 'gecko') &&
				(navigator.userAgent.toLowerCase().indexOf('safari') != -1)
			),
			AtLeast: 1.2,
			Version: function() {
				var r = navigator.userAgent;
				return parseFloat(r.split('Version/').reverse().join(' '));
			}
		},
		{
			Id: 'Firefox',
			Criterion:
			(
				(navigator.appCodeName.toLowerCase() == 'mozilla') &&
				(navigator.appName.toLowerCase() == 'netscape') &&
				(navigator.product.toLowerCase() == 'gecko') &&
				((navigator.userAgent.toLowerCase().indexOf('firefox') != -1) ||
				(navigator.userAgent.toLowerCase().indexOf('iceweasel') != -1))
			),
			AtLeast: 1,
			Version: function() {
				var userAgent = navigator.userAgent.toLowerCase();
				if (userAgent.indexOf('firefox/') != -1) {
					return parseFloat(userAgent.split('firefox/').reverse().join('firefox/'));
				}
				if (userAgent.indexOf('iceweasel/') != -1) {
					return parseFloat(userAgent.split('iceweasel/').reverse().join('iceweasel/'));
				}
				return 0;
			}
		},
		{
			Id: 'Netscape',
			Criterion:
			(
				(navigator.appCodeName.toLowerCase() == 'mozilla') &&
				(navigator.appName.toLowerCase() == 'netscape') &&
				(navigator.product.toLowerCase() == 'gecko') &&
				(navigator.userAgent.toLowerCase().indexOf('netscape') != -1)
			),
			AtLeast: 7,
			Version: function() {
				var r = navigator.userAgent.split(' ').reverse().join(' ');
				r = parseFloat(r.slice(r.indexOf('/')+1,r.indexOf(' ')));
				return r;
			}
		},
		{
			Id: 'Mozilla',
			Criterion:
			(
				(navigator.appCodeName.toLowerCase() == 'mozilla') &&
				(navigator.appName.toLowerCase() == 'netscape') &&
				(navigator.product.toLowerCase() == 'gecko') &&
				(navigator.userAgent.toLowerCase().indexOf('mozilla') != -1)
			),
			AtLeast: 1,
			Version: function() {
				var r = navigator.userAgent;
				return parseFloat(r.split('Firefox/').reverse().join('Firefox/'));
			}
		},
		{
			Id: 'Microsoft Internet Explorer',
			Criterion:
			(
				(navigator.appName.toLowerCase() == 'microsoft internet explorer') &&
				(navigator.appVersion.toLowerCase().indexOf('msie') != 0) &&
				(navigator.userAgent.toLowerCase().indexOf('msie') != 0) &&
				(!window.opera)
			),
			AtLeast: 5,
			Version: function() {
				var r = navigator.userAgent.toLowerCase();
				r = parseFloat(r.slice(r.indexOf('msie')+4,r.indexOf(';',r.indexOf('msie')+4)));
				return r;
			}
		}
	];

	this.Init();
}

function CPopupMenu(popup_menu, popup_control, menu_class, popup_move, popup_title, move_class, move_press_class, title_class, title_over_class)
{
	this.popup = popup_menu;
	this.control = popup_control;
	this.move = popup_move;
	this.title = popup_title;
	this.menu_class = menu_class;
	this.move_class = move_class;
	this.move_press_class = move_press_class;
	this.title_class = title_class;
	this.title_over_class = title_over_class;
}

function CPopupMenus()
{
	this.items = Array();
	this.isShown = 0;
}

CPopupMenus.prototype = {
	getLength: function()
	{
		return this.items.length;
	},
	
	addItem: function(popup_menu, popup_control, menu_class, popup_move, popup_title, move_class, move_press_class, title_class, title_over_class)
	{
		this.items.push(new CPopupMenu(popup_menu, popup_control, menu_class, popup_move, popup_title, move_class, move_press_class, title_class, title_over_class));
		this.hideItem(this.getLength() - 1);
	},
	
	showItem: function(item_id)
	{
		this.hideAllItems();
		var item = this.items[item_id];
		var bounds = GetBounds(this.items[item_id].move);
		if (!window.RTL) {
    		item.popup.style.left = bounds.Left + 'px';
		}
		item.popup.style.top = bounds.Top + bounds.Height + 'px';

		item.popup.className = item.menu_class;
		if (item.title_class && item.title_class != '') {
			item.control.className = item.title_class;
			item.title.className = item.title_class;
		}
		if (item.move_press_class && item.move_press_class != '')
			item.move.className = item.move_press_class;
		var obj = this;
		item.control.onclick = function() {
			obj.hideItem(item_id);
		};
		var borders = 1;
		if (item.title_over_class != '') {
			item.control.onmouseover = function(){};
			item.control.onmouseout = function(){};
			item.title.onmouseover = function(){};
			item.title.onmouseout = function(){};
			borders = 2;
		}
		this.isShown = 2;
		item.popup.style.width = 'auto';
		var pOffsetWidth = item.popup.offsetWidth;
		var cOffsetWidth = item.control.offsetWidth;
		var tOffsetWidth = (item.control == item.title) ? 0 : item.title.offsetWidth;
		item.popup.style.width = (pOffsetWidth < (cOffsetWidth + tOffsetWidth - borders))
			? (cOffsetWidth + tOffsetWidth - borders) + 'px' : (pOffsetWidth + borders) + 'px';

		/* rtl */
		if (window.RTL) {
	    	item.popup.style.left = (bounds.Left + bounds.Width - item.popup.offsetWidth) + 'px';
		}

		item.popup.style.height = 'auto';
		var pOffsetHeight = item.popup.offsetHeight;
		var height = GetHeight();
		if (pOffsetHeight > height*2/3) {
			item.popup.style.height = Math.round(height*2/3) + 'px';
			item.popup.style.overflowY = 'auto';
		} else {
			item.popup.style.overflowY = 'hidden';
		}
	},
	
	hideItem: function(item_id)
	{
		this.items[item_id].popup.className = 'wm_hide';
		if (this.items[item_id].move_class && this.items[item_id].move_class != '' && this.items[item_id].move.className != 'wm_hide')
			this.items[item_id].move.className = this.items[item_id].move_class;
		var obj = this;
		this.items[item_id].control.onclick = function() {
			obj.showItem(item_id);
		};
		if (obj.items[item_id].title_over_class != ''){
			this.items[item_id].control.onmouseover = function() {
				obj.items[item_id].title.className = obj.items[item_id].title_over_class; 
				obj.items[item_id].control.className = obj.items[item_id].title_over_class;
			};
			this.items[item_id].control.onmouseout = function() {
				obj.items[item_id].title.className = obj.items[item_id].title_class; 
				obj.items[item_id].control.className = obj.items[item_id].title_class; 
			};
			this.items[item_id].title.onmouseover = function() {
				obj.items[item_id].title.className = obj.items[item_id].title_over_class; 
			};
			this.items[item_id].title.onmouseout = function() {
				obj.items[item_id].title.className = obj.items[item_id].title_class; 
			}
		}
	},
	
	hideAllItems: function()
	{
		for (var i = this.getLength() - 1; i >= 0; i--) {
			this.hideItem(i);
		};
		this.isShown = 0;
	},
	
	checkShownItems: function()
	{
		if (this.isShown == 1) {
			this.hideAllItems()
		};
		if (this.isShown == 2) {
			this.isShown = 1;
		}
	}
};

function CSearchForm(BigSearchForm, SmallSearchForm, downButton, upButton, bigFormId, bigLookFor, smallLookFor)
{
	this.form = BigSearchForm;
	this._bigFormId = bigFormId;
	this.smallForm = SmallSearchForm;
	this.downButton = downButton;
	this.upButton = upButton;
	this._bigLookFor = bigLookFor;
	this._smallLookFor = smallLookFor;
	this.isShown = 0;
	this.shown = false;
	this._searchIn = null;
}

CSearchForm.prototype = 
{
	Show: function ()
	{
		this.shown = true;
		this.isShown = 0;
		this.smallForm.className = 'wm_toolbar_search_item';
		var obj = this;
		this.downButton.onclick = function() { obj.ShowBigForm(); };
		this.ShowDownButton();
		this.form.className = 'wm_hide';
		this.HideUpButton();
	},
	
	ChangeSkin: function (newSkinName)
	{
	},
	
	ShowDownButton: function ()
	{
		var obj = this;
		this.downButton.onmouseover = function() {
			obj.downButton.className = 'wm_toolbar_search_item_over';
			obj.smallForm.className = 'wm_toolbar_search_item_over';
		};
		this.downButton.onmouseout = function() {
			obj.downButton.className = 'wm_toolbar_search_item';
			obj.smallForm.className = 'wm_toolbar_search_item';
		};
		this.downButton.className = 'wm_toolbar_search_item';
	},
	
	HideDownButton: function ()
	{
		this.downButton.onmouseover = function() { };
		this.downButton.onmouseout = function() { };
		this.downButton.className = 'wm_hide';
	},
	
	ShowUpButton: function ()
	{
		var obj = this;
		this.upButton.onmouseover = function() {
			obj.upButton.className = 'wm_toolbar_search_item_over';
		};
		this.upButton.onmouseout = function() {
			obj.upButton.className = 'wm_toolbar_search_item';
		};
		this.upButton.className = 'wm_toolbar_search_item';
	},
	
	HideUpButton: function ()
	{
		this.upButton.onmouseover = function() { };
		this.upButton.onmouseout = function() { };
		this.upButton.className = 'wm_hide';
	},
	
	Hide: function ()
	{
		this.shown = false;
		this.smallForm.className = 'wm_hide';
		this.HideDownButton();
		this.form.className = 'wm_hide';
		this.HideUpButton();
	},
	
	SetSearchIn: function (searchIn)
	{
		this._searchIn = searchIn;
	},
	
	ShowBigForm: function()
	{
		var bounds = GetBounds(this.smallForm);
		this.form.style.top = bounds.Top + 'px';
		if (window.RTL) {
		    this.form.style.left = bounds.Left + 'px';
		}
		else {
		    this.form.style.right = (GetWidth() - bounds.Left - bounds.Width) + 'px';
		}
		this.form.className = 'wm_search_form';
		this.smallForm.className = 'wm_hide';
		this.HideDownButton();
		this.ShowUpButton();
		this.isShown = 2;
		this._bigLookFor.value = this._smallLookFor.value;
		if (null != this._searchIn) {
			this._searchIn.className = '';
		}
	},
	
	checkVisibility: function(ev, isM)
	{
		if (this.isShown == 1) {
			ev = ev ? ev : window.event;
			if (isM) { elem = ev.target; }
			else { elem = ev.srcElement; }
			while (elem && elem.tagName != 'DIV') {
				if (elem.parentNode) { elem = elem.parentNode; }
				else { break; }
			}
			if (elem.id != this._bigFormId) { this.Show(); }
		}
		if (this.isShown == 2) this.isShown = 1;
	}
};

function CError(name)
{
	this._name = name;
	this._containerObj = null;
	this._messageObj = null;
	this._controlObj = null;
	this._fadeObj = null;
	this._delay = 10000;

	this.Build = function ()
	{
		var tbl = CreateChildWithAttrs(document.body, 'table', [['class', 'wm_hide']]);
		var tr = tbl.insertRow(0);
		var td = tr.insertCell(0);
		var div = CreateChildWithAttrs(td, 'div', [['class', 'wm_info_block']]);
		var shadowDiv = CreateChildWithAttrs(div, 'div', [['class', 'wm_shadow']]);
		var aDiv = CreateChildWithAttrs(shadowDiv, 'div', [['class', 'a']]);
		aDiv.innerHTML = '&nbsp;';
		var infoDiv = CreateChildWithAttrs(div, 'div', [['class', 'wm_info_message']]);
		aDiv = CreateChildWithAttrs(div, 'div', [['class', 'a']]);
		aDiv.innerHTML = '&nbsp;';
		var bDiv = CreateChildWithAttrs(div, 'div', [['class', 'b']]);
		bDiv.innerHTML = '&nbsp;';
		this._containerObj = tbl;
		var imageDiv = CreateChildWithAttrs(infoDiv, 'div', [['class', 'wm_info_image']]);
		this._messageObj = CreateChild(infoDiv, 'span');
		var closeImageDiv = CreateChildWithAttrs(infoDiv, 'div', [['class', 'wm_close_info_image wm_control']]);
		var obj = this;
		closeImageDiv.onclick = function () { obj.Hide(); };
		this._controlObj = new CInformation(tbl, 'wm_error_information');
	}
}

function CReport(name)
{
	this._name = name;
	this._containerObj = null;
	this._messageObj = null;
	this._controlObj = null;
	this._fadeObj = null;
	this._delay = 5000;

	this.Build = function ()
	{
		var tbl = CreateChildWithAttrs(document.body, 'table', [['class', 'wm_hide']]);
		var tr = tbl.insertRow(0);
		var td = tr.insertCell(0);
		var div = CreateChildWithAttrs(td, 'div', [['class', 'wm_info_block']]);
		var shadowDiv = CreateChildWithAttrs(div, 'div', [['class', 'wm_shadow']]);
		var aDiv = CreateChildWithAttrs(shadowDiv, 'div', [['class', 'a']]);
		aDiv.innerHTML = '&nbsp;';
		var infoDiv = CreateChildWithAttrs(div, 'div', [['class', 'wm_info_message']]);
		aDiv = CreateChildWithAttrs(div, 'div', [['class', 'a']]);
		aDiv.innerHTML = '&nbsp;';
		var bDiv = CreateChildWithAttrs(div, 'div', [['class', 'b']]);
		bDiv.innerHTML = '&nbsp;';
		this._containerObj = tbl;
		this._messageObj = infoDiv;
		this._controlObj = new CInformation(tbl, 'wm_report_information');
	}
}

var ReportPrototype = 
{
	Show: function (msg, priorDelay)
	{
		this._messageObj.innerHTML = msg;
		this._controlObj.Show();
		this._controlObj.Resize();
		if (null != this._fadeObj) {
			if (this._name) {
				var interval = this._fadeObj.Go(this._containerObj, (priorDelay) ? priorDelay : this._delay);
				setTimeout(this._name + '.Hide()', interval);
			}
		} else {
			if (this._name) {
				setTimeout(this._name + '.Hide()', (priorDelay) ? priorDelay : this._delay);
			}
		}
	},
	
	SetFade: function (fadeObj)
	{
		this._fadeObj = fadeObj;
	},
	
	Hide: function ()
	{
		this._controlObj.Hide();
		if (null != this._fadeObj) {
			this._fadeObj.SetOpacity(1, IsGoodIE());
		}
	},
	
	Resize: function ()
	{
		this._controlObj.Resize();		
	}
};

CReport.prototype = ReportPrototype;
CError.prototype = ReportPrototype;

/* for control placement and displaying of information block */
function CInformation(cont, cls)
{
	this._mainContainer = cont;
	this._containerClass = cls;
}

CInformation.prototype = {
	Show: function ()
	{
		this._mainContainer.className = this._containerClass;
	},
	
	Hide: function ()
	{
		this._mainContainer.className = 'wm_hide';
	},

	Resize: function ()
	{
		var cont = this._mainContainer;
		cont.style.right = 'auto';
		cont.style.width = 'auto';
		var offsetWidth = cont.offsetWidth;
		var width = GetWidth();
		if (offsetWidth >  0.4 * width) {
			cont.style.width = '40%';
		}
		offsetWidth = cont.offsetWidth;
		cont.style.top = this.GetScrollY() + 'px';
		cont.style.left = Math.round((width - offsetWidth)/2) + 'px';
	},

	GetScrollY: function()
	{
		var scrollY = 0;
		if (document.body && typeof document.body.scrollTop != 'undefined') {
			scrollY += document.body.scrollTop;
			if (scrollY == 0 && document.body.parentNode && typeof document.body.parentNode != 'undefined') {
				scrollY += document.body.parentNode.scrollTop;
			}
		}
		else if (typeof window.pageXOffset != 'undefined') {
			scrollY += window.pageYOffset;
		}
		return scrollY;
	}
};

function CFadeEffect(name)
{
	this._name = name;
	this._elem = null;
}

CFadeEffect.prototype = 
{
	Go: function (elem, delay)
	{
		this._elem = elem;
		var interval = 50;
		var iCount = 10;
		var diff = 1/iCount;
		var isIE = IsGoodIE() ? 'true' : 'false';
		for(var i=0; i<=iCount; i++) {
			setTimeout(this._name + '.SetOpacity('+ (1 - diff*i) + ', '+ isIE + ')', delay + interval*i);
		};
		return delay + interval*iCount;
	},
	
	SetOpacity: function (opacity, isIE)
	{
		var elem = this._elem;
		// Internet Exploder 5.5+
		if (isIE) {
			opacity *= 100;
			var oAlpha = elem.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha;
			if (oAlpha) {
				oAlpha.opacity = opacity;
			}
			else {
				elem.style.filter += 'progid:DXImageTransform.Microsoft.Alpha(opacity='+opacity+')';
			}
		}
		else {
			elem.style.opacity = opacity;		// CSS3 compliant (Moz 1.7+, Safari 1.2+, Opera 9)
			elem.style.MozOpacity = opacity;	// Mozilla 1.6-, Firefox 0.8
			elem.style.KhtmlOpacity = opacity;	// Konqueror 3.1, Safari 1.1
		}
	}
};

function CValidate()
{
}

CValidate.prototype = 
{
    IsEmpty : function (strValue)
    {
        if(strValue.replace(/\s+/g,'') == '') {
            return true;
        };
        return false;
    },
    
    HasEmailForbiddenSymbols : function (strValue)
    {
        if(strValue.match(/[^A-Z0-9\"!#\$%\^\{\}`~&'\+-=_@\.]/i)) {
            return true;
        };
        return false;
    },
    
    IsCorrectEmail : function (strValue)
    {
        if(strValue.match(/^[A-Z0-9\"!#\$%\^\{\}`~&'\+-=_\.]+@[A-Z0-9\.-]+$/i)) {
            return true;
        };
        return false;
    },
    
    IsCorrectServerName : function (strValue)
    {
        if(!strValue.match(/[^A-Z0-9\.-]/i))
        {
            return true;
        }
        return false;
    },
    
    IsPositiveNumber : function (intValue)
    {
        if(isNaN(intValue) || intValue <= 0 || Math.round(intValue) != intValue) {
            return false;
        };
        return true;
    },
    
    IsPort : function (intValue)
    {
        if(this.IsPositiveNumber(intValue) && intValue <= 65535) {
            return true;
        };
        return false;
    },
    
    HasSpecSymbols : function (strValue)
    {
        if(strValue.match(/["\/\\*?<>|:]/)) {
            return true;
        };
        return false;
    },
    
    IsCorrectFileName : function (strValue)
    {
        if (!this.HasSpecSymbols(strValue)) {
			return !strValue.match(/^(CON|AUX|COM1|COM2|COM3|COM4|LPT1|LPT2|LPT3|PRN|NUL)$/i);
        };
        return false;
    },
    
    CorrectWebPage : function (strValue)
    {
        return strValue.replace(/^[\/;<=>\[\\#\?]+/g,'');
    },
    
    HasFileExtention : function (strValue, strExtension)
    {           
        if( strValue.substr(strValue.length - strExtension.length - 1,strExtension.length + 1).toLowerCase() == '.'+strExtension.toLowerCase()) {
            return true;
        };
        return false;
    }
};

function CPageSwitcher(skinName)
{
	this._skinName = skinName;
	this._mainCont = null;
	this._pagesCont = null;
	this._count = 0;
	this._perPage = 0;
	this.PagesCount = 0;
}

CPageSwitcher.prototype = {
	Show: function (page, perPage, count, beginOnclick, endOnclick)
	{
		this.PagesCount = 0;
		if (page == 0) {
			this._mainCont.className = 'wm_inbox_page_switcher';
		}
		else {
			this.Hide();
			this._count = count;
			this._perPage = perPage;
			if (count > perPage) {
				var strPages = '';
				var pagesCount = Math.ceil(count/perPage);
				this.PagesCount = pagesCount;
				var firstPage, lastPage;
				if (pagesCount > 4) {
					firstPage = page - 2;
					if (firstPage < 1) {
						firstPage = 1;
					}
					lastPage = firstPage + 4;
					if (lastPage > pagesCount) {
						lastPage = pagesCount;
						firstPage = lastPage - 4;
					}
				}
				else {
					firstPage = 1;
					lastPage = pagesCount;
				}
				if (firstPage != lastPage) {
					if (firstPage > 1) {
						var strFirstPage = '<a href="#" onclick="' + beginOnclick + '1' + endOnclick + ' return false;" class="wm_page_switcher_first"><div title="' + Lang.FirstPage + '"></div></a>';
						var strPrevPage = '<a href="#" onclick="' + beginOnclick + (firstPage - 1) + endOnclick + ' return false;" class="wm_page_switcher_prev"><div title="' + Lang.PreviousPage + '"></div></a>';
						if (window.RTL) {
							strPages = strPrevPage + strFirstPage + strPages;
						}
						else {
							strPages += strFirstPage + strPrevPage;
						}
					}
					for (var i = firstPage; i <= lastPage; i++) {
						if (page == i) {
							if (window.RTL) {
								strPages = '<font>' + i + '</font>' + strPages;
							}
							else {
								strPages += '<font>' + i + '</font>';
							}
						} else {
							if (window.RTL) {
								strPages = '<a href="#" onclick="' + beginOnclick + i + endOnclick + ' return false;">' + i + '</a>' + strPages;
							}
							else {
								strPages += '<a href="#" onclick="' + beginOnclick + i + endOnclick + ' return false;">' + i + '</a>';
							}
						}
					}
					if (pagesCount > lastPage) {
						var strNextPage = '<a href="#" onclick="' + beginOnclick + (lastPage + 1) + endOnclick + ' return false;" class="wm_page_switcher_next"><div title="' + Lang.NextPage + '"></div></a>';
						var strLastPage = '<a href="#" onclick="' + beginOnclick + pagesCount + endOnclick + ' return false;" class="wm_page_switcher_last"><div title="' + Lang.LastPage + '"></div></a>';
						if (window.RTL) {
							strPages = strLastPage + strNextPage + strPages;
						}
						else {
							strPages += strNextPage + strLastPage;
						}
					}
					this._mainCont.className = 'wm_inbox_page_switcher';
					this._pagesCont.innerHTML = strPages;
				}
			} // if (count > perPage)
		}
	},
	
	GetLastPage: function (removeCount, perPage)
	{
		var count = this._count - removeCount;
		if (perPage) this._perPage = perPage;
		var page = Math.ceil(count/this._perPage);
		if (page < 1) page = 1;
		return page;
	},
	
	Hide: function ()
	{
		this._mainCont.className = 'wm_hide';
	},

	Replace: function (obj)
	{
		var oBounds = GetBounds(obj);
		var ps = this._mainCont;
		ps.style.top = (oBounds.Top - ps.offsetHeight) + 'px';
		/* rtl */
		if (window.RTL) {
			ps.style.left = (oBounds.Left + 18) + 'px';
		} else {
			ps.style.left = (oBounds.Left + oBounds.Width - ps.offsetWidth - 18) + 'px';
		}
	},
	
	ChangeSkin: function (skinName)
	{
		this._skinName = skinName;
	},
	
	Build: function ()
	{
		var tbl = CreateChild(document.body, 'table');
		this._mainCont = tbl;
		tbl.className = 'wm_hide';
		var tr = tbl.insertRow(0);
		var td = tr.insertCell(0);
		var div = CreateChild(td, 'div');
		div.className = 'wm_inbox_page_switcher_left';
		td = tr.insertCell(1);
		this._pagesCont = td;
		td.className = 'wm_inbox_page_switcher_pages';
		td = tr.insertCell(2);
		div = CreateChild(td, 'div');
		div.className = 'wm_inbox_page_switcher_right';
	}
};

var CHECK_MAIL_BY_CLICK = 0;
var CHECK_MAIL_AT_LOGIN = 1;

function CCheckMail(type)
{
	this.isBuilded = false;
	this._type = (type) ? type : CHECK_MAIL_BY_CLICK;
	this.started = false;
	
	this._url = CheckMailUrl;
	this._email = '';
	this._msgsCount = 0;
	this._preText = '';
	
	this._form = null;
	this._typeObj = null;
	
	this._mainContainer = null;
	this._infomation = null;
	this._message = null;
	this._progressBarUsed = null;
}

CCheckMail.prototype = {
	Start: function ()
	{
	    if (this.started) return;
		if (this.isBuilded) {
			if (this._type == CHECK_MAIL_BY_CLICK) this._infomation.Show();
		}
		else {
			this.Build();
		}
		this._preText = '';
		this.SetText(Lang.LoggingToServer);
		this._msgsCount = 1;
		this.UpdateProgressBar(0);
		this._msgsCount = 0;
		this._typeObj.value = this._type;
		this._form.action = this._url + '?param=' + Math.random();
		this._form.submit();
		this.started = true;
	},
	
	SetAccount: function (account)
	{
		this._email = account;
		this._mainContainer.className = 'wm_connection_information';
		this._preText = '<b>' + this._email + '</b><br/>';
	},

	SetFolder: function (folderName, msgsCount)
	{
		this.UpdateProgressBar(0);
		this._folderName = folderName;
		this._msgsCount = msgsCount;
		this._preText = '';
		if (this._email.length > 0) this._preText += '<b>' + this._email + '</b><br/>';
		this._preText += Lang.Folder + ' <b>' + this._folderName + '</b><br/>';
	},
	
	SetText: function (text)
	{
		this._message.innerHTML = this._preText + text;
		if (this._type == CHECK_MAIL_BY_CLICK) this._infomation.Resize();
	},
	
	DeleteMsg: function (msgNumber) {
		if (msgNumber == -1) {
			this.SetText(Lang.DeletingMessages);
		}
		else {
			this.SetText(Lang.DeletingMessage + ' #' + msgNumber + ' ' + Lang.Of + ' ' + this._msgsCount);
			this.UpdateProgressBar(msgNumber);
		}
	},
	
	SetMsgNumber: function (msgNumber)
	{
		if (msgNumber <= this._msgsCount) {
			this.SetText(Lang.RetrievingMessage + ' #' + msgNumber + ' ' + Lang.Of + ' ' + this._msgsCount);
		}
		this.UpdateProgressBar(msgNumber);
	},
	
	UpdateProgressBar: function (msgNumber)
	{
		if (this._msgsCount > 0) {
			var percent = Math.ceil((msgNumber - 1)*100/this._msgsCount);
			if (percent < 0) { percent = 0; }
			else if (percent > 100) { percent = 100; }
			this._progressBarUsed.style.width = percent + 'px';
		}
	},
	
	End: function ()
	{
		if (this._type == CHECK_MAIL_BY_CLICK) this._infomation.Hide();
		this.started = false;
	},
	
	Build: function ()
	{
		var tbl, tr, td, div;

		/* iframe block building */
		CreateChildWithAttrs(document.body, 'iframe', [['id', 'CheckMailIframe'], ['name', 'CheckMailIframe'], ['src', EmptyHtmlUrl], ['class', 'wm_hide']]);
		var frm = CreateChildWithAttrs(document.body, 'form', [['action', this._url], ['target', 'CheckMailIframe'], ['method', 'post'], ['id', 'CheckMailForm'], ['name', 'CheckMailForm'], ['class', 'wm_hide']]);
		this._typeObj = CreateChildWithAttrs(frm, 'input', [['name', 'Type'], ['value', this._type]]);
		this._form = frm;
		switch (this._type) {
			/* information block building for type 0 */
			case CHECK_MAIL_BY_CLICK:
				tbl = CreateChildWithAttrs(document.body, 'table', [['class', 'wm_information wm_connection_information']]);
				tr = tbl.insertRow(0);
				td = tr.insertCell(0);
				div = CreateChildWithAttrs(td, 'div', [['class', 'wm_info_block']]);
				var shadowDiv = CreateChildWithAttrs(div, 'div', [['class', 'wm_shadow']]);
				var aDiv = CreateChildWithAttrs(shadowDiv, 'div', [['class', 'a']]);
				aDiv.innerHTML = '&nbsp;';
				var infoDiv = CreateChildWithAttrs(div, 'div', [['class', 'wm_info_message']]);
				aDiv = CreateChildWithAttrs(div, 'div', [['class', 'a']]);
				aDiv.innerHTML = '&nbsp;';
				var bDiv = CreateChildWithAttrs(div, 'div', [['class', 'b']]);
				bDiv.innerHTML = '&nbsp;';
				this._containerObj = div;
				this._message = CreateChild(infoDiv, 'span');
				var divPB = CreateChildWithAttrs(infoDiv, 'div', [['class', 'wm_progressbar']]);
				this._progressBarUsed = CreateChildWithAttrs(divPB, 'div', [['class', 'wm_progressbar_used']]);
				this._infomation = new CInformation(tbl, 'wm_information wm_connection_information');
				break;
			/* information block building for type 1 */
			case CHECK_MAIL_AT_LOGIN:
				var parent = document.getElementById('content');
				tbl = CreateChild((parent) ? parent : document.body, 'table');
				tbl.className = 'wm_hide';
				this._mainContainer = tbl;
				tbl.style.marginTop = '30px';
				tr = tbl.insertRow(0);
				td = tr.insertCell(0);
				td.className = 'wm_connection_header';
				td.colSpan = '3';
				td.innerHTML = Lang.Connection;
				CreateChild(td, 'span');
				tr = tbl.insertRow(1);
				td = tr.insertCell(0);
				td.className = 'wm_connection_icon';
				td = tr.insertCell(1);
				td.className = 'wm_connection_message';
				td.align = 'center';
				this._message = td;
				td = tr.insertCell(2);
				td.className = 'wm_connection_empty';
				tr = tbl.insertRow(2);
				td = tr.insertCell(0);
				td.className = 'wm_connection_progressbar';
				td.colSpan = 3;
				div = CreateChildWithAttrs(td, 'div', [['align', 'center']]);
				var subDiv = CreateChildWithAttrs(div, 'div', [['class', 'wm_progressbar']]);
				this._progressBarUsed = CreateChildWithAttrs(subDiv, 'div', [['class', 'wm_progressbar_used']]);
				break;
		}
		/* it's builded! */
		this.isBuilded = true;
	}
};

function CScriptLoader()
{
	this.onLoad = null;
	this.loadedCount = 0;
	this.scriptsCount = 0;
	this._onLoad = null;
	this._scripts = new CDictionary();
}

CScriptLoader.prototype = {
	Load: function(urlArray, loadHandler)
	{
		this.onLoad = loadHandler;
		this.loadedCount = 0;
		this.scriptsCount = urlArray.length;
		if (this.scriptsCount == 0)
			this.onLoad.call();
		for (var i in urlArray)
			this.LoadItem(urlArray[i], this.ScriptLoadHandler);
	},
	
	ScriptLoadHandler: function()
	{
		this.loadedCount++;
		if (this.loadedCount == this.scriptsCount)
			this.onLoad.call();
	},
	
	LoadItem: function(url, loadHandler)
	{
		this._onLoad = loadHandler;
		var script = document.createElement('script');
		script.setAttribute('type', 'text/javascript');
		var obj = this;
		if (Browser.IE) {
			script.onreadystatechange = function () {
				if (obj._scripts.exists(this.src)) {
					if (this.readyState == 'complete' || this.readyState == 'loaded') {
						obj._scripts.remove(this.src);
						obj._onLoad.call(obj);
					}
				}
			};
		}
		else {
			script.onload = function () {
				obj._scripts.remove(this.src);
				obj._onLoad.call(obj);
			};
		}
		this._scripts.add(url, true);
		script.src = url;
		var HeadElements = document.getElementsByTagName('head');
		HeadElements[0].appendChild(script);
	}
};

function CNetLoader()
{
	this.Url = null;
	this.onLoad = null;
	this.onError = null;
	this.responseXML = null;
	this.responseText = null;
	this.ErrorDesc = null;
	this.Request = null;
	this.Log = '';
}

CNetLoader.prototype = {
	GetTransport: function()
	{
		var transport = null;
		if(window.XMLHttpRequest) {
			transport = new XMLHttpRequest();
		}
		else {
			if(window.ActiveXObject) {
				try {
					transport = new ActiveXObject('Msxml2.XMLHTTP');
				}
				catch (err) {
					try {
						transport = new ActiveXObject('Microsoft.XMLHTTP');
					}
					catch (err2) {
					}
				}
			}
		};
		return transport;
	},

	LoadXMLDoc: function(Url, PostParams, onLoad, onError)
	{
		this.Url = Url;
		this.onLoad = onLoad;
		this.onError = onError;
		var Request = this.GetTransport();

		if(Request) {
			try {
				Request.open('POST', this.Url, true);
				Request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
				var obj = this;
				Request.onreadystatechange = function() { obj.OnReadyState(Request); };
				Request.send(PostParams);
			}
			catch (err) {
				this.ErrorDesc = Lang.ErrorRequestFailed;
				this.onError.call(this);
			}
		}
		else {
			this.ErrorDesc = Lang.ErrorAbsentXMLHttpRequest;
			this.onError.call(this);
		}
		this.Request = Request;
	},
	
	OnReadyState: function(Request)
	{
		var ReadyStateComplete = 4;
		var Ready = Request.readyState;
		if(Ready == ReadyStateComplete) {
			var HttpStatus;
			try {
				if(Request.status != undefined) {
					HttpStatus = Request.status;
				}
				else {
					HttpStatus = 13030;
				}
			}
			catch(e) {
				// 13030 is the custom code to indicate the condition -- in Mozilla/FF --
				// when the o object's status and statusText properties are
				// unavailable, and a query attempt throws an exception.
				HttpStatus = 13030;
			};
			if (HttpStatus == 200 || HttpStatus == 0) {
				if (HttpStatus == 0 && Request.getResponseHeader('Content-Type') == null) return;
				this.responseXML = Request.responseXML;
				this.responseText = Request.responseText;
				this.onLoad.call(this);
			}
			else if (HttpStatus != 13030) {
				this.ErrorDesc = Lang.ErrorConnectionFailed + '\n' + HttpStatus + '\n' + Request.responseText;
				this.onError.call(this);
			}
		}
	},
	
	CheckRequest: function ()
	{
		if (null != this.Request) {
			this.Request.onreadystatechange = null;
			this.Request.abort();
		}
	}
};

function CDictionary()
{
	this.count = 0;
	this.Obj = new Object();
}

CDictionary.prototype = {
	exists: function (sKey)
	{
		return (this.Obj[sKey]) ? true : false;
	},

	add: function (sKey, aVal)
	{
		var K = String(sKey);
		if(this.exists(K)) return false;
		this.Obj[K] = aVal;
		this.count++;
		return true;
	},

	remove: function (sKey)
	{
		var K = String(sKey);
		if (!this.exists(K)) return false;
		delete this.Obj[K];
		this.count--;
		return true;
	},

	removeAll: function ()
	{
		for(var key in this.Obj) delete this.Obj[key];
		this.count = 0;
	},

	values: function ()
	{
		var Arr = new Array();
		for(var key in this.Obj) Arr[Arr.length] = this.Obj[key];
		return Arr;
	},

	keys: function ()
	{
		var Arr = new Array();
		for (var key in this.Obj) Arr[Arr.length] = key;
		return Arr;
	},

	items: function ()
	{
		var Arr = new Array();
		for (var key in this.Obj) {
			var A = new Array(key,this.Obj[key]);
			Arr[Arr.length] = A;
		};
		return Arr;
	},

	getVal: function(sKey)
	{
		var K = String(sKey);
		return this.Obj[K];
	},

	setVal: function(sKey, aVal)
	{
		var K = String(sKey);
		if (this.exists(K))
			this.Obj[K] = aVal;
		else
			this.add(K,aVal);
	},

	setKey: function (sKey, sNewKey)
	{
		var K = String(sKey);
		var Nk = String(sNewKey);
		if (this.exists(K)) {
			if (!this.exists(Nk)) {
				this.add(Nk, this.getVal(K));
				this.remove(K);
			}
		}
		else if (!this.exists(Nk))
			this.add(Nk, null);
	}
};

var Logger = {
	_container: null,
	_initialized: false,
	
	_init: function ()
	{
		if (this._initialized == true) return;
		this._container = document.getElementById('logo');
		this._container.dir = 'ltr';
		this._container.style.color = 'white';
		this._container.style.textAlign = 'left';
		this._initialized = true;
	},
	
	WriteLine: function (msg)
	{
		this._init();
		this._container.innerHTML = this._container.innerHTML + msg + '<br />';
	}
};

function CreateSessionSaver()
{
	CreateChildWithAttrs(document.body, 'iframe', [['id', 'session_saver'], ['name', 'session_saver'], ['src', 'session-saver.php'], ['class', 'wm_hide']]);
}

function IsGoodIE()
{
	if (document.body.filters)
	{
		var marray = navigator.appVersion.match(/MSIE ([\d.]+);/);
		if (marray && marray.length > 1 && marray[1] >= 5.5)
		{
			return true;
		}
	}
	return false;
}

function CLanguageChanger()
{
	this._innerHTML = Array();
	this._iCount = 0;
	this._value = Array();
	this._vCount = 0;
	this._title = Array();
	this._tCount = 0;
}

CLanguageChanger.prototype = {
	Register: function (type, obj, field, end, start, number)
	{
		if (!start) start = '';
		switch (type) {
			default:
			case 'innerHTML':
				if (!number) {
					number = this._iCount;
					this._iCount++;
				};
				this._innerHTML[number] = {Elem: obj, Field: field, End: end, Start: start};
				return number;
			break;
			case 'value':
				if (!number) {
					number = this._vCount;
					this._vCount++;
				};
				this._value[number] = {Elem: obj, Field: field, End: end, Start: start};
				return number;
			break;
			case 'title':
				if (!number) {
					number = this._tCount;
					this._tCount++;
				};
				this._title[number] = {Elem: obj, Field: field, End: end, Start: start};
				return number;
			break;
		}
	},

	Go: function ()
	{
		var i = 0;
		var obj;
		var iCount = this._innerHTML.length;
		for (i=0; i<iCount; i++) {
			obj = this._innerHTML[i];
			if (obj && obj.Elem) obj.Elem.innerHTML = obj.Start + Lang[obj.Field] + obj.End;
		};

		iCount = this._value.length;
		for (i=0; i<iCount; i++) {
			obj = this._value[i];
			if (obj && obj.Elem) obj.Elem.value = Lang[obj.Field] + obj.End;
		};

		iCount = this._title.length;
		for (i=0; i<iCount; i++) {
			obj = this._title[i];
			if (obj && obj.Elem) obj.Elem.title = Lang[obj.Field] + obj.End;
		}
	}
};

if (window.JSFileLoaded != undefined) JSFileLoaded();
function MakeOpaqueOnSelect(element)
{
	if (Browser.IE && Browser.Version < 7) {
		CreateChildWithAttrs(element, 'iframe', 
			[
				['src', EmptyHtmlUrl],
				['scrolling', 'no'],
				['frameborder', '0'],
				['class', 'wm_for_ie_select']
			]
		);
	}
}

function GetBorderWidth(style, width)
{
	if (style == 'none') {
		return 0;
	} else {
		var floatWidth = parseFloat(width);
		return (isNaN(floatWidth)) ? 0 : Math.round(floatWidth);
	}
}

function GetBorders(element)
{
	var top, right, bottom, left;
	if (Browser.Mozilla) {
		top = GetBorderWidth(ReadStyle(element, 'border-top-style'), ReadStyle(element, 'border-top-width'));
		right = GetBorderWidth(ReadStyle(element, 'border-right-style'), ReadStyle(element, 'border-right-width'));
		bottom = GetBorderWidth(ReadStyle(element, 'border-bottom-style'), ReadStyle(element, 'border-bottom-width'));
		left = GetBorderWidth(ReadStyle(element, 'border-left-style'), ReadStyle(element, 'border-left-width'));
	} else {
		top = GetBorderWidth(ReadStyle(element, 'borderTopStyle'), ReadStyle(element, 'borderTopWidth'));
		right = GetBorderWidth(ReadStyle(element, 'borderRightStyle'), ReadStyle(element, 'borderRightWidth'));
		bottom = GetBorderWidth(ReadStyle(element, 'borderBottomStyle'), ReadStyle(element, 'borderBottomWidth'));
		left = GetBorderWidth(ReadStyle(element, 'borderLeftStyle'), ReadStyle(element, 'borderLeftWidth'));
	};
	return {Top: top, Right: right, Bottom: bottom, Left: left};
}

function ReadStyle(element, property)
{
	if (element.style[property]) {
		return element.style[property];
	} else if (element.currentStyle) {
		return element.currentStyle[property];
	} else if (document.defaultView && document.defaultView.getComputedStyle) {
		var style = document.defaultView.getComputedStyle(element, null);
		return style.getPropertyValue(property);
	}
	return null;
}

function GetMarginLeft(element)
{
	var mLeft = (Browser.Mozilla || Browser.Safari)
		? ReadStyle(element, 'margin-left') : ReadStyle(element, 'marginLeft');
	if (mLeft != null) {
		return mLeft.replace(/px/, '') - 0;
	}
	return Number.NaN;
}

function GetMarginRight(element)
{
	var mRight = (Browser.Mozilla || Browser.Safari)
		? ReadStyle(element, 'margin-right') : ReadStyle(element, 'marginRight');
	if (mRight != null) {
		return mRight.replace(/px/, '') - 0;
	}
	return Number.NaN;
}

//email parts for adding to contacts
function GetEmailParts(fullEmail)
{
	var quote1 = fullEmail.indexOf('"');
	var quote2 = fullEmail.indexOf('"', quote1+1);
	var leftBrocket = fullEmail.indexOf('<', quote2);
	var prevLeftBroket = -1;
	while (leftBrocket != -1) {
		prevLeftBroket = leftBrocket;
		leftBrocket = fullEmail.indexOf('<', leftBrocket+1);
	};
	leftBrocket = prevLeftBroket;
	var rightBrocket = fullEmail.indexOf('>', leftBrocket+1);
	var name = '';
	var email = '';
	if (leftBrocket == -1) {
		email = Trim(fullEmail);
	} else {
		if (quote1 == -1) {
			name = Trim(fullEmail.substring(0, leftBrocket));
		} else {
			name = Trim(fullEmail.substring(quote1+1, quote2));
		};
		email = Trim(fullEmail.substring(leftBrocket+1, rightBrocket));
	};
	return {Name: name, Email: email, FullEmail: fullEmail};
}

function PopupPrintMessage(url)
{
	PopupWindow(url, 'PopupPrintMessage', 640, 480, true);
	return false;
}

function PopupContacts(wUrl)
{
	PopupWindow(wUrl, 'PopupContacts', 300, 400);
	return false;
}

function PopupWindow(wUrl, wName, wWidth, wHeight, toolbar)
{
	var toolbarVar = (toolbar) ? 'yes' : 'no';
	var wLeft, wTop;
	if (window.screen) { wTop = (screen.height - wHeight) / 2; } else { wTop = 200; }
	if (window.screen) { wLeft = (screen.width - wWidth) / 2; } else { wLeft = 200; }
	var wArgs = 'toolbar=' + toolbarVar + ',location=no,directories=no,copyhistory=no,';
	wArgs += 'status=yes,scrollbars=yes,resizable=yes,';
	wArgs += 'width=' + wWidth + ',height=' + wHeight + ',left=' + wLeft + ',top=' + wTop;
	var shown = window.open(wUrl, wName, wArgs);
	shown.focus();
}

function SetBodyAutoOverflow(isAuto)
{
	var OverFlow = 'hidden';
	var Scroll = 'no';
	if (isAuto) {
		OverFlow = 'auto';
		Scroll = 'yes';
	}
	if (Browser.IE) {
		WebMail._html.style.overflow = OverFlow;
	}
	else {
		document.body.scroll = Scroll;
		document.body.style.overflow = OverFlow;
	}
}

function OpenURL(strUrl)
{
	var val = new CValidate();
	strUrl = val.CorrectWebPage(Trim(strUrl));
	if (strUrl.length > 0) {
		var newWin, strProt;
		strProt = strUrl.substr(0,4);
		if (strProt != "http" && strProt != "ftp:")
			strUrl = "http://" + strUrl;
		newWin = window.open(encodeURI(strUrl), null,"toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,resizable=yes,copyhistory=yes");
		newWin.focus();
	}
}

function Trim(str) {
    return str.replace(/^\s+/, '').replace(/\s+$/, '');
}

function EncodeStringForEval(source)
{
	return source.replace(/'/g, '\\\'').replace(/"/g, '\\"');
}

function HtmlEncode(source)
{
	return source.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;');
}

function HtmlDecode(source)
{
	return source.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&');
}

function HtmlEncodeBody(source)
{
	return source.replace(/]]>/g, '&#93;&#93;&gt;');
}

function HtmlDecodeBody(source)
{
	return source.replace(/&#93;&#93;&gt;/g, ']]>');
}

function GetCData(source, isBody)
{
	if (isBody) {
		return '<![CDATA[' + HtmlEncodeBody(source) + ']]>';
	}
	else {
		return '<![CDATA[' + HtmlEncode(source) + ']]>';
	}
}

function isEnter(ev)
{
	var key = -1;
	if (window.event) {
		key = window.event.keyCode;
	} else if (ev) {
		key = ev.which;
	}
	return (key == 13);
}

function TextAreaLimit(ev, obj, count)
{
	ev = ev ? ev : window.event;
	var key = -1;
	if (window.event)
		key = window.event.keyCode;
	else if (ev)
		key = ev.which;
	if (key != 8 //backspace
	 && key != 13 //enter
	 && key != 16 //shift
	 && key != 17 //ctrl
	 && key != 18 //alt
	 && key != 35 //end
	 && key != 36 //home
	 && key != 37 //to the right
	 && key != 38 //up
	 && key != 39 //to the left
	 && key != 40 //down
	 && key != 46) { //delete
		if (!ev.ctrlKey && !ev.shiftKey) {
			if (obj.value.length >= count)
				return false;
		}
	};
	return true;
}

function isRightClick(ev)
{
	var key = -1;
	if (window.event) {
		key = window.event.button;
	} else if (ev) {
		key = ev.which;
	}
	return (key == 3 || key == 2);
}

function GetWidth()
{
	var width = 1024;
	if (document.documentElement && document.documentElement.clientWidth)
		width = document.documentElement.clientWidth;
	else if (document.body.clientWidth)
		width = document.body.clientWidth;
	else if (self.innerWidth)
		width = self.innerWidth;
	return width;
}

function GetHeight()
{
	var height = 768;
	if (self.innerHeight)
		height = self.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight)
		height = document.documentElement.clientHeight;
	else if (document.body.clientHeight)
		height = document.body.clientHeight;
	return height;
}

function CreateChild(parent, tagName)
{
	var node = document.createElement(tagName);
	parent.appendChild(node);
	return node;
}

function CreateTextChild(parent, text)
{
	var node = document.createTextNode(text);
	parent.appendChild(node);
	return node;
}
    
function CreateChildWithAttrs(parent, tagName, arAttrs)
{
	var i, t, key, val, node, attrsLen;
	if (Browser.IE) {
		strAttrs = '';
		attrsLen = arAttrs.length;
		for (i=attrsLen-1; i>=0; i--) {
			t = arAttrs[i];
			key = t[0];
			val = t[1];
			strAttrs += ' ' + key + '="'+ val + '"';
		};
		tagName = '<' + tagName + strAttrs + '>';
		node = document.createElement(tagName);
	} else {
		node = document.createElement(tagName);
		attrsLen = arAttrs.length;
		for (i=attrsLen-1; i>=0; i--) {
			t = arAttrs[i];
			key = t[0];
			val = t[1];
			node.setAttribute(key, val);
		}
	};
	parent.appendChild(node);
	return node;
}

function GetBounds(object)
{
	if (object == null) {
		return {Left: 0, Top: 0, Width: 0, Height: 0};
	}
	var left = object.offsetLeft;
	var top = object.offsetTop;
	for (var parent = object.offsetParent; parent; parent = parent.offsetParent) {
		left += parent.offsetLeft;
		top += parent.offsetTop;
	};
	return {Left: left, Top: top, Width: object.offsetWidth, Height: object.offsetHeight};
}

function GetScrollY(object)
{
	if (object == null) {
		return 0;
	}
    var scrollY = 0;
    if (object && typeof(object.scrollTop) != 'undefined') {
	    scrollY += object.scrollTop;
	    if (scrollY == 0 && object.parentNode && typeof(object.parentNode) != 'undefined') {
		    scrollY += object.parentNode.scrollTop;
	    }
    } else if (typeof object.pageXOffset != 'undefined') {
	    scrollY += object.pageYOffset;
    };
	return scrollY;
}

function CleanNode(object)
{
  while (object.firstChild)
    object.removeChild(object.firstChild);
}

function GetAppPath()
{
	var path = location.pathname;
	var dotIndex = path.lastIndexOf('.');
	var delimIndex = path.lastIndexOf('/');
	if (delimIndex < dotIndex || delimIndex == path.length - 1) {
		path = path.substring(0, delimIndex);
	};
	if (path.length == 0) {
		path = '/';
	} else if (path.substr(path.length - 1, 1) != '/') {
		path += '/';
	};
	return path;
}

function CreateCookie(name, value, days) {
	var expires = '';
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days*24*60*60*1000));
		expires = '; expires=' + date.toGMTString();
	}
	var path = '; path=' + GetAppPath();
	document.cookie = name + '=' + value + expires + path;
}

function ReadCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0; i<ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) {
			return c.substring(nameEQ.length, c.length);
		}
	};
	return null;
}

function EraseCookie(name) {
	CreateCookie(name, "", -1);
}

function HighlightMessageLine(source)
{
	return '<font>' + source + '</font>';
}

function HighlightContactLine(source)
{
	return '<b>' + source + '</b>';
}

function isEqualArray(arr1, arr2)
{
    if (!(arr1 instanceof Array) || !(arr2 instanceof Array)) return false;
    if (arr1.length != arr2.length) return false;
    for (var i=0; i<arr1.length; i++) {
        if (arr1[i] != arr2[i]) return false;
    }
    return true;
}

String.prototype.PrepareForRegExp = function ()
{
	var search = this.replace(/\\/g, '\\\\').replace(/\^/g, '\\^').replace(/\$/g, '\\$');
	search = search.replace(/\./g, '\\.').replace(/\*/g, '\\*').replace(/\+/g, '\\+');
	search = search.replace(/\?/g, '\\?').replace(/\|/g, '\\|').replace(/\(/g, '\\(');
	search = search.replace(/\)/g, '\\)').replace(/\[/g, '\\[');
	return search;
};

String.prototype.ReplaceStr = function (search, replacement)
{
	return this.replace(new RegExp (search.PrepareForRegExp(), 'gi'), replacement);
};

function GetBirthDay(d, m, y)
{
	res = '';
	if (y != 0) {
		res += y;
		if (d != 0 || m != 0) res += ',';
	}
	if (d != 0) res += ' ' + d;
	switch (m) {
		case 1: res += ' ' + Lang.ShortMonthJanuary; break;
		case 2: res += ' ' + Lang.ShortMonthFebruary; break;
		case 3: res += ' ' + Lang.ShortMonthMarch; break;
		case 4: res += ' ' + Lang.ShortMonthApril; break;
		case 5: res += ' ' + Lang.ShortMonthMay; break;
		case 6: res += ' ' + Lang.ShortMonthJune; break;
		case 7: res += ' ' + Lang.ShortMonthJuly; break;
		case 8: res += ' ' + Lang.ShortMonthAugust; break;
		case 9: res += ' ' + Lang.ShortMonthSeptember; break;
		case 10: res += ' ' + Lang.ShortMonthOctober; break;
		case 11: res += ' ' + Lang.ShortMonthNovember; break;
		case 11: res += ' ' + Lang.ShortMonthDecember; break;
	}
	return res;
}
	
function GetFriendlySize(byteSize)
{
	var size = Math.ceil(byteSize / 1024);
	var mbSize = size / 1024;
	if (mbSize > 1) {
		size = Math.ceil(mbSize*10)/10 + Lang.Mb;
	}
	else {
		size = size + Lang.Kb;
	};
	return size;
}

function GetExtension(fileName)
{
	var ext = '';
	var dotPos = fileName.lastIndexOf('.');
	if (dotPos > -1) {
		ext = fileName.substr(dotPos + 1).toLowerCase();
	};
	return ext;
}

function GetFileParams(fileName)
{
	var ext = GetExtension(fileName);
	switch (ext) {
		case 'asp':
		case 'asa':
		case 'inc':
			return {x: 12*X_ICON_SHIFT, y: 2*Y_ICON_SHIFT, view: false};
			break;
		case 'css':
			return {x: 11*X_ICON_SHIFT, y: 2*Y_ICON_SHIFT, view: false};
			break;
		case 'doc':
			return {x: 10*X_ICON_SHIFT, y: 2*Y_ICON_SHIFT, view: false};
			break;
		case 'html':
		case 'shtml':
		case 'phtml':
		case 'htm':
			return {x: 9*X_ICON_SHIFT, y: 2*Y_ICON_SHIFT, view: false};
			break;
		case 'pdf':
			return {x: 8*X_ICON_SHIFT, y: 2*Y_ICON_SHIFT, view: false};
			break;
		case 'xls':
			return {x: 7*X_ICON_SHIFT, y: 2*Y_ICON_SHIFT, view: false};
			break;
		case 'bat':
		case 'exe':
		case 'com':
			return {x: 5*X_ICON_SHIFT, y: 2*Y_ICON_SHIFT, view: false};
			break;
		case 'bmp':
			return {x: 4*X_ICON_SHIFT, y: 2*Y_ICON_SHIFT, view: true};
			break;
		case 'gif':
			return {x: 3*X_ICON_SHIFT, y: 2*Y_ICON_SHIFT, view: true};
			break;
		case 'png':
		case 'jpg':
		case 'jpeg':
			return {x: 2*X_ICON_SHIFT, y: 2*Y_ICON_SHIFT, view: true};
			break;
		case 'tiff':
		case 'tif':
			return {x: 1*X_ICON_SHIFT, y: 2*Y_ICON_SHIFT, view: true};
			break;
		case 'txt':
			return {x: 0*X_ICON_SHIFT, y: 2*Y_ICON_SHIFT, view: false};
			break;
		case 'eml':
			return {x: 6*X_ICON_SHIFT, y: 2*Y_ICON_SHIFT, view: true};
			break;
		default:
			return {x: 6*X_ICON_SHIFT, y: 2*Y_ICON_SHIFT, view: false};
			break;
	}
}

// Neox added 2009.02.10 !-->
function $addHandler(object, event, handler) {
	if (object && event && handler) {
		if (typeof object.addEventListener != 'undefined') {
			if (event == 'mousewheel') {
				event = 'DOMMouseScroll';
			}
			object.addEventListener(event, handler, false);
			return true;
		} else if (typeof object.attachEvent != 'undefined') {
			object.attachEvent('on' + event, handler);
			return true;
		}
	}
	return false;
}

function $removeHandler(object, event, handler) {
	if (object && event && handler) {
		if (typeof object.removeEventListener != 'undefined') {
			if (event == 'mousewheel') {
				event = 'DOMMouseScroll';
			}
			object.removeEventListener(event, handler, false);
			return true;
		} else if (typeof object.detachEvent != 'undefined') {
			object.detachEvent('on' + event, handler);
			return true;
		}
	}
	return false;
}

function $removeHandlers(object, event) {
	if (!object) {
		throw Error("Object must be specified");
	}
	if (object._events) {
		var cache = {};
		if (event) {
			cache[event] = object._events[event];
		} else {
			cache = object._events;
		}
		var cacheEvent, events, handler, len, i;
		for (cacheEvent in cache) {
			events = cache[cacheEvent];
			len = events.length;
			for (i = 0; i < len; i++) {
				handler = events[i].handler;
				$removeHandler(object, event, handler);
			}
		}
	}
}

function $isHandler(object, event, handler) {
	if (!object) {
		throw Error("Object must be specified");
	}
	if (!event) {
		throw Error("Event must be specified");
	}
	if (!handler) {
		throw Error("Handler must be specified");
	}
	if (object._events && object._events[event]) {
		var events = object._events[event];
		var len = events.length;
		for (var i = 0; i < len; i++) {
			if (events[i].handler == handler) {
				return true;
			}
		}
	}
	return false;
}

function $createDelegate(instance, method) {
	if (!instance) {
		throw Error("Instance must be specified");
	}
	if (!method) {
		throw Error("Method must be specified");
	}
	return function() {
		return method.apply(instance, arguments);
	}
}

function $createCallback(instance, method, context) {
	if (!instance) {
		instance = window;
	}
	if (!method) {
		throw Error("Method must be specified");
	}
	return function() {
		var l = arguments.length;
		if (l > 0) {
			var args = [];
			for (var i = 0; i < l; i++) {
				args[i] = arguments[i];
			}
			args[l] = context;
			return method.apply(instance, args);
		}
		return method.call(instance, context);
	}
}

function IsRtlLanguage(langName) {
	return (langName == 'Hebrew' || langName == 'Arabic');
}

function GetStyleValue(e,type1,type2) {
    if (!type2) {
		type2 = type1;
	}
    if (e.currentStyle&&e.currentStyle[type2] != '') {
		return e.currentStyle[type2];
	} else if (window.getComputedStyle(e, '').getPropertyValue(type1) != '') {
		return window.getComputedStyle(e, '').getPropertyValue(type1);
	}
	return false;
}

function IsNum(value) {
	var reg = /^[0-9]+$/;
	return reg.test(value);
}

if (window.JSFileLoaded != undefined) JSFileLoaded();
