var DateObj = "";
var UserName = "WebMail";
var GeneralPanel = null;
var InboxPanel = null;
var ReadingPanel = null;
var ReadingHeader = null;
var ReadingBody = null;
var ReadingFooter = null;
var EditorPanel = null;
var CmdBarPanel = null;
var LeftMenuPanel = null;
var InfoLabel = null;
//var ProcessingLabel = null;
var GuestLabel = null;
var OriginalAlert = null;
var FTB = null;
var GotMailTemplate = "<a href=\"javascript: M_ShowNewMsg();\" class='NewMsgAlert'><img src='images/accept.gif' class='imgLink'>#</a>";
var oMailbox = null;
var oContacts = null;
var oProfile = null;
var oHelp = null;
var oAdmin = null;
var oEditor = null;
var oProfileSettings = null;
var FTB_IconsLoaded = false;
var FTB_Reloading = false;
var oTreeNavMenu = null;
var oTreeMenu = null;
var ImagesLoaded = true;
var oImgLoader = null;
var oImgLoaderMisc = null;
var oImgLoaderView = null;
var oImgLoaderFTB = null;
var ImageList = new Array("del_16.gif","RT.gif","RTR.gif","RTF.gif","RF.gif","AF.gif","PN.gif","PH.gif","PL.gif","AT.gif","edit_16.gif","folder.gif","nosort.gif","plusN.gif","indent.gif","refresh.gif","del_22.gif","folder_inbox.gif","folder_drafts.gif","folder_sent.gif","folder_trash.gif","managefolder.gif","sortup.gif","sortdown.gif","down.gif","empty_trash.gif","newmail.gif","plusF.gif","indent.gif","menusep.gif","menusep1.gif","empty_18.gif","junk.gif","nosort_empty.gif");
var ImageListMisc = new Array("refresh.gif","contact_22.gif","contact_group_22.gif","domainusers.gif","domaingroups.gif","import_22.gif","export_22.gif","prefs_22.gif","chart_22.gif","RT_22.gif","edit_22.gif","about_32.gif","stop_32.gif","del_16H.gif","processing.gif","read_22.gif","unread_22.gif","high_22.gif","low_22.gif","none_22.gif","info_22.gif","sysspam_22.gif","blacklist_22.gif","whitelist_22.gif");
var ImageListView = new Array("reply.gif","replyall.gif","forward.gif","print_22.gif","prev.gif","next.gif","close_22.gif","sel_false.gif","sel_true.gif","send.gif","save.gif","cancel.gif");
var ImageListFTB = new Array("separator.horizontal.gif","fontforecolorpicker.gif","fontbackcolorpicker.gif","bold.gif","italic.gif","underline.gif","strikethrough.gif","superscript.gif","subscript.gif","removeformat.gif","createlink.gif","unlink.gif","print.gif","toolbar.horizontal.start.gif","justifyleft.gif","justifyright.gif","justifycenter.gif","justifyfull.gif","bulletedlist.gif","numberedlist.gif","indent.gif","outdent.gif","cut.gif","copy.gif","paste.gif","undo.gif","redo.gif","delete.gif","insertrule.gif","insertdate.gif","toolbar.horizontal.end.gif");
// BROWSER VERSION
var agt = navigator.userAgent.toLowerCase();
// On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
// Opera and WebTV spoof Navigator.
var is_nav  = ((agt.indexOf('mozilla')!= -1) && (agt.indexOf('spoofer')== -1)
              && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')== -1)
              && (agt.indexOf('webtv')== -1) && (agt.indexOf('hotjava')== -1));
var is_gecko = (agt.indexOf('gecko') != -1);
var is_ff    = (is_gecko && agt.indexOf('firefox') != -1);
var is_ff0x  = (is_gecko && agt.indexOf('firefox/0.') != -1);
var is_ff10x = (is_gecko && agt.indexOf('firefox/1.0') != -1);
var is_ff15up =(is_ff && !is_ff0x && !is_ff10x);
var is_opera = (agt.indexOf('opera') != -1);
var is_aol   = (agt.indexOf("aol") != -1);
var is_webtv = (agt.indexOf("webtv") != -1);
var is_konqueror = (navigator.vendor == 'KDE');
var is_safari = (agt.indexOf("safari") !=-1);

var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4") != -1));
var is_ie4up  = (is_ie && (is_major >= 4));
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0") != -1));
var is_ie5down = (is_ie3 || is_ie4 || is_ie5);
var is_ie55   = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") != -1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_ie55up = (is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie6	  = (is_ie && (agt.indexOf("msie 6") != -1));
var is_ie7    = (is_ie && (agt.indexOf("msie 7") != -1));
var is_ie8    = (is_ie && (agt.indexOf("msie 8") != -1));
var is_win95  = ((agt.indexOf("win95") != -1) || (agt.indexOf("windows 95") != -1));
var is_win98  = ((agt.indexOf("win98") != -1) || (agt.indexOf("windows 98") != -1));
var is_win9x  = (is_win95 || is_win98);
var use_full_editor = (is_ie55 || is_ie6 || is_ie7 || is_ff || is_aol);
var use_custom_alert = (is_ie6 || is_ie7 || is_ie8 || is_ff || is_aol);

function PageInit(){
	if(is_ie5down){
		window.location="Basic/Mailbox.aspx";
	}
	if(use_custom_alert){
		OriginalAlert = window.alert;
		window.alert = function(txt){
			createCustomAlert(txt);
		}
	}
	var result = Anthem_InvokeSync("P_GetProfile", null);
	oProfileSettings = result.value;
	GetPageAnchors();
	ShowElement("NAV_BAR");
	ShowElement("btnLogout");
	P_ShowAutoResponderAlert();
	oEditor = new Editor();
	oEditor.init();
	
	//KeepAliveCallback(null, null);
	window.setTimeout("CheckForNewMailCallback(null, null)", 120000);
	//window.setTimeout("FadeOff('Ban_lbAnnouncement', 50)", 120000);
	StartUpDateTimer();
	InitTreeMenu();
	NB_Nav("Mailbox");
	UpdateGuestStatus();
	var obj = GetElementById("Ban_lbUserName");
	if (obj!=null){
		UserName = obj.innerHTML;
	}
};
function InitTreeMenu(){
	oTreeNavMenu = new TreeControl(GetElementById("LEFT_MENU_PANEL"), "LTreeNav");
	oTreeNavMenu.createHeader("");
	oTreeNavMenu.addItem(locMailbox, "", "", "NB_Nav('Mailbox');", "");
	oTreeNavMenu.addItem(locContacts, "", "", "NB_Nav('Contacts');", "");
	oTreeNavMenu.addItem(locProfile, "", "", "NB_Nav('Profile');", "");
	oTreeNavMenu.addItem(locHelp, "", "", "NB_Nav('Help');", "");
	if(oProfileSettings.IsAdmin){
		oTreeNavMenu.addItem(locAdmin, "", "", "NB_Nav('Admin');", "");
	}
};
var funcClose = null;
function KeyDown(oEvent){
	if(!oEvent){
		oEvent = window.event;
	}
	if(27 == oEvent.keyCode && funcClose != null){
		funcClose();
	}
}
function KeepAliveWorker(){
	Anthem_InvokeAsync("KeepAlive", [], KeepAliveCallback, null);
};
function KeepAliveCallback(result,args){
	window.setTimeout("KeepAliveWorker()", 900000); // 15 minutes
};
function AllImagesPreloading(){
	if(is_ie){
		delete oImgLoader;
		delete oImgLoaderView;
		delete oImgLoaderMisc;
		delete oImgLoaderFTB;
		oImgLoader = new ImagePreloader(ImageList, "images/", null);
		oImgLoaderMisc = new ImagePreloader(ImageListMisc, "images/", null);
		oImgLoaderView = new ImagePreloader(ImageListView, "images/", null);
		oImgLoaderFTB = new ImagePreloader(ImageListFTB, "ftb/officexp/", null);
	}
};
function CheckForNewMailWorker(){
	AllImagesPreloading();
	Anthem_InvokeAsync("M_CheckForNewMail", [], CheckForNewMailCallback, null);
};
function CheckForNewMailCallback(result,args){
	if(result != null){
		if(null == result.error && result.value > 0){
			document.title = locNewMail.replace(/#/, result.value) + " " + UserName;
			var o = GetElementById("Ban_lbGotMail")
			if(1 == result.value){
				o.innerHTML = GotMailTemplate.replace(/#/, locOneNewMessage);
			}
			else{
				o.innerHTML = GotMailTemplate.replace(/#/, locNewMessages.replace(/#/, result.value));
			}
			FadeIn('Ban_lbGotMail', 0);
		}
	}
	window.setTimeout("CheckForNewMailWorker()", 120000); // 2 minutes
};
function M_ShowNewMsg(){
	NB_Nav("Mailbox");
	window.setTimeout("oMailbox.CurrentFolder = null; oMailbox.SetFolder('Inbox');", 200);
};
function GetPageAnchors(){
	CmdBarPanel = GetElementById("COMMAND_BAR_PANEL");
	LeftMenuPanel = GetElementById("LEFT_MENU_PANEL");
	GeneralPanel = GetElementById("GENERAL_PANEL");
	EditorPanel = GetElementById("EDITOR_PANEL");
	InboxPanel = GetElementById("INBOX_PANEL");
	ReadingPanel = GetElementById("READING_PANEL");
	ReadingHeader = GetElementById("MSG_HEADER");
	ReadingBody = GetElementById("MSG_BODY");
	ReadingFooter = GetElementById("MSG_FOOTER");
	InfoLabel = GetElementById("NBInfo");
	//ProcessingLabel = GetElementById("NBProcessing");
	GuestLabel = GetElementById("Ban_lbGuest");
};
function GetControl(Id){
	var result = Anthem_InvokeSync("GetControl", [Id]);
	if(result.error != null){
		alertKO(result.error);
		return "";
	}
	return result.value;
};
function GetControlArray(Id){
	var result = Anthem_InvokeSync("GetControlArray", [Id]);
	if(result.error != null){
		alertKO(result.error);
	}
	return result.value;
};
function Logout(){
	Anthem_InvokeSync("Logout", null);
	InboxPanel.innerHTML = "";
	LeftMenuPanel.innerHTML = "";
	CmdBarPanel.innerHTML = "";
	GeneralPanel.innerHTML = "";
	ReadingPanel.innerHTML = "";
	HideObject(ReadingPanel);
	SetInfoLabel("");
	oEditor.hide();
	HideElement("btnLogout");
	HideElement("Ban_lbUserName");
	HideElement("NAV_BAR");
	window.alert = OriginalAlert;
	window.setTimeout("window.location='Mail.aspx';", 100);
};
function UpdateGuestStatus(){
	if(oProfileSettings.IsGuest){
		var result = Anthem_InvokeSync("M_GetGuestStatus", null);
		if(result.error == null){
			GuestLabel.innerHTML="<span>" + result.value + "</span>";
		}
	}
};
function SetInfoLabel(text){
	InfoLabel.innerHTML = text;
};
function SetInfoLabelBold(text){
	InfoLabel.innerHTML = "<font color='#ae4c4c'><b>" + text + "</b></font>";
};
function GetInfoLabelText(){
	return InfoLabel.innerHTML;
};
//**********
// NAV BAR
var CalLeftMenuHTML = null;
var KonLeftMenuHTML = null;
var ProLeftMenuHTML = null;
var CalCmdBarHTML = null;
var NB_CurrentTab = "";
var sCurrPage = "";
function LeavingPage(){
	if(sCurrPage!=""){
		Anthem_InvokeAsync("LeavingPage", [sCurrPage], null, null);
		sCurrPage="";
	}
};
function NB_Nav(target){
	NB_NavEx(target, true);
};
function NB_NavEx(target, bAsync){
	if(target == NB_CurrentTab){
		if(target != "Mailbox"){
			return;
		}
	}
	if("Mailbox" == NB_CurrentTab && oMailbox != null){
		if(!oMailbox.NavOut()){
			return;
		}
	}
	if(NB_CurrentTab==""){
		NB_CurrentTab = "Mailbox";
	}
	LeavingPage();
	funcClose = null;
	oEditor.hide();
	CmdBarPanel.innerHTML = "";
	ShowObject(CmdBarPanel);
	GeneralPanel.innerHTML = "";
	SetInfoLabelBold(locLoading);
	
	var currentId = "NB_TD_" + NB_CurrentTab;
	var currentObj = GetElementById(currentId);
	currentObj.className = "NavBarCell";
	currentObj.firstChild.className = "NavBarLabel";

	var targetId = "NB_TD_" + target;
	var targetObj = GetElementById(targetId);
	targetObj.className = "NavBarCellSel";
	targetObj.firstChild.className = "";

	NB_CurrentTab = target;
	if(bAsync){
		window.setTimeout("NB_NavWorker()", 0);
	}else{
		NB_NavWorker();
	}
};
function NB_NavWorker(){
	switch (NB_CurrentTab){
		case "Mailbox":
			if(null == oMailbox){
				oMailbox = new Mailbox();
			}
			oTreeNavMenu.selectItem(0);
			NB_CurrentTab = "Mailbox";
			oMailbox.NavIn();
		break;

		case "Calendar":
			if(null == CalLeftMenuHTML){
				CalLeftMenuHTML = GetControl("C_LeftPanelMenu");
			}
			if(null == CalCmdBarHTML){
				CalCmdBarHTML = GetControlArray("C_CmdBarMenu");
			}
			CmdBarPanel.innerHTML = CalCmdBarHTML[0];
			SetInfoLabel("");
		break;
		
		case "Contacts":
			oTreeNavMenu.selectItem(1);
			if(null == oContacts){
				oContacts = new Contacts();
			}
			oContacts.NavIn();
		break;
		
		case "Profile":
			oTreeNavMenu.selectItem(2);
			if(null == oProfile){
				oProfile = new Profile();
			}
			oProfile.NavIn();
		break;

		case "Help":
			oTreeNavMenu.selectItem(3);
			if(null == oHelp){
				oHelp = new Help();
			}
			oHelp.NavIn();
			break;
			
		case "Admin":
			oTreeNavMenu.selectItem(4);
			if(null == oAdmin){
				oAdmin = new Admin();
			}
			oAdmin.NavIn();
		break;
	}
};
function C_SetMenuItem(index){
};
function GetSelectedItems(GridId){
	return GetSelectedItemsIdx(GridId,1);
};
function GetSelectedItemsIdx(GridId,start){
	var aItems = new Array(0);
	var table = GetElementById(GridId);
	if(table!= null){
		var inputs = table.getElementsByTagName('input');
		for(var i=start; i<inputs.length; i++){
			if(inputs[i].type == 'checkbox'){
				if(inputs[i].checked){
					aItems[aItems.length] = inputs[i].value;
				}
			}
		}
	}
	return aItems;
};
function GetElementById(Id){
	var o = null;
	if(document.getElementById){
		o = document.getElementById(Id); // DOM3 = IE5, NS6
	}
	else{
		if(document.layers){
			o = document[Id]; // Netscape 4
		}
		else{
			o = document.all[Id]; // IE 4
		}
	}
	return o;
};
function GetTZOffset(){
	var d = new Date();
	GetElementById("hidTZOffset").value = d.getTimezoneOffset();
};
function CR(e){
	var curElm = e;
	while (curElm && !(curElm.tagName == "TR")){
		curElm = curElm.parentNode;
	}
	if(curElm != e){
		if(e.checked){
				curElm.className += " MGTRChecked";
		}
		else{
			curElm.className = curElm.className.replace(/ MGTRChecked/, "");
			curElm.className = curElm.className.replace(/MGTRChecked/, "");
		}
	}
};
function checkAllCB(sender, dataGrid){
	var table = GetElementById(dataGrid);
	var inputs = table.getElementsByTagName('input');
	var checkState = sender.checked;
	for(var i=1;i<inputs.length;i++){
		if(inputs[i].length == null){
			if(inputs[i].type == 'checkbox'){
				var cb = inputs[i];
				if(cb.checked != checkState){
					cb.checked = checkState;
					var TR = cb.parentNode.parentNode;
					if(checkState)	{
						TR.className += " MGTRChecked";
					}
					else{
						TR.className = TR.className.replace(/ MGTRChecked/, "");
						TR.className = TR.className.replace(/MGTRChecked/, "");
					}
				}
			}
		} 
	}
};
function FormatSize(iSize){
	var factor = 0;
	var result;
	while(iSize > 1024){
		iSize = Math.floor(iSize/1024);
		factor++;
	}
	result = iSize.toString();
	switch(factor){
		case 0:
			result += " B";
			break;
		case 1:
			result += " KB";
			break;
		case 2:
			result += " MB";
			break;
		case 3:
			result += " GB";
			break;
	}
	return result;
};
function IFrameHelper(iFrameId){
	this.id = iFrameId;
	this.oIframe = null;
	this.oIframeDoc = null;
};
IFrameHelper.prototype.getElementById = function(id){
	this.oIframe = document.getElementById(this.id);
	this.oIframeDoc = (this.oIframe.contentWindow || this.oIframe.contentDocument);
	if(this.oIframeDoc.document){
		this.oIframeDoc = this.oIframeDoc.document;
	}
	if(this.oIframeDoc != null){
		if(this.oIframeDoc.getElementById){
			return this.oIframeDoc.getElementById(id);
		}
		else{
			return this.oIframeDoc[Id];
		}
	}
	return null;
};
IFrameHelper.prototype.submit = function(){
	this.oIframeDoc.forms[0].submit()
};
//**********
function ShowBlock(Id){
	var o = GetElementById(Id);
	if(o != null){
		o.style.visibility = "visible";
		o.style.display = "block";
	}
};
function TriggerShowElement(Id, bShow){
	if(bShow) ShowObject(GetElementById(Id));
	else HideObject(GetElementById(Id));
};
function ShowElement(Id){
	ShowObject(GetElementById(Id));
};
function HideElement(Id){
	HideObject(GetElementById(Id));
};
function ShowObject(o){
	if(o != null){
		o.style.visibility = "visible";
		o.style.display = "";
	}
};
function HideObject(o){
	if(o != null)	{
		o.style.visibility = "hidden";
		o.style.display = "none";
	}
};
function FocusElement(Id){
	FocusObject(GetElementById(Id));
};
function FocusObject(o){
	try	{
		if(o != null){
			o.focus();
			o.select();
		}
	}
	catch(e){}
};
//***********
function StartUpDateTimer(){
	DateObj = GetElementById("NBDate");
	if(is_ie){
		UpdateTimeIE();
	}else{
		UpdateTimeFF();
		var d = new Date();
		var t = (60 - d.getSeconds()) * 1000;
		window.setTimeout("SyncUp();", t);
	}
};
function SyncUp(){
	UpdateTimeFF();
	window.setTimeout("UpdateTimeFF();", 60000);
};
function UpdateTimeIE(){
	var d = new Date();
	var s = d.toLocaleDateString() + ", " + d.toLocaleTimeString();
	DateObj.innerText = s;
	window.setTimeout("UpdateTimeIE();", 1000);
};
function UpdateTimeFF(){
	var d = new Date();
	var s = d.toLocaleDateString() + ", " + d.toLocaleTimeString();
	s = s.substr(0, s.length - 3);
	DateObj.innerHTML = s;
	window.setTimeout("UpdateTimeFF();", 60000);
};
//**********
var fadingOff = false;
function FadeOff(id, opacity){
	opacity -= 5;
	var o = GetElementById(id);
	if(null == o){
		return;
	}
	fadingOff = true;
	if(opacity < 10){
		o.style.visibility = "hidden";
		o.style.display = "none";
		if(is_ie){
			o.style.filter = "alpha(opacity:100)";
		}
		else if(is_gecko){
			o.style.MozOpacity = 1.0;
		}
		fadingOff = false;
	}
	else{
		if(is_ie){
			o.style.filter = "alpha(opacity:"+opacity+")";
		}
		else if(is_gecko){
			o.style.MozOpacity = opacity/100;
		}
		window.setTimeout("FadeOff('"+id+"',"+opacity+")", 50);
	}
}
function FadeIn(id, opacity){
	opacity += 5;
	var o = GetElementById(id);
	if(null == o || true == fadingOff){
		return;
	}
	if(opacity > 90){
		if(is_ie){
			o.style.filter = "alpha(opacity:100)";
		}
		else if(is_gecko){
			o.style.MozOpacity = 1.0;
		}
	}
	else{
		o.style.visibility = "visible";
		o.style.display = "";
		if(is_ie){
			o.style.filter = "alpha(opacity:"+opacity+")";
		}
		else if(is_gecko){
			o.style.MozOpacity = opacity/100;
		}
		window.setTimeout("FadeIn('"+id+"',"+opacity+")", 50);
	}
}
//**********
function RemoveHelpText(sender){
	var tr = sender.createTextRange();
	if(tr.text.substr(0,1) == "["){
		tr.text = "";
	}
}
function TrapEnterKey(e){
	if(e.keyCode == 13){
		return false;
	}
}
//**********
var selElem;
function AC(email){
	var elementValue = GetElementById(selElem).value;
	if(elementValue.indexOf(email) == -1){
		GetElementById(selElem).value = email + "; " + elementValue;
	}
}
function SetElem(ID1, ID2, ID3, CurrElem){
	GetElementById(ID1).style.visibility = 'visible';
	GetElementById(ID2).style.visibility = 'hidden';
	GetElementById(ID3).style.visibility = 'hidden';
	selElem = CurrElem;
}
//**********
function getDialogTop(width, height){
	var top = 10;
	if(self.innerHeight){ //FF
		top = self.innerHeight > 240 ? (self.innerHeight/2 - 120) : 10;
	}
	else if(document.documentElement && document.documentElement.clientHeight){ //IE 6
		top = document.documentElement.clientHeight > 240 ? (document.documentElement.clientHeight/2 - 120) : 10;
	}
	else if(document.body){ //Other
		top = document.body.clientHeight > 240 ?(document.body.clientHeight/2 - 120) : 10;
	}
	return top;
};
function MessageBox(alertType, title, txt, txtType, OKBtn){
	var d = document;
	if(d.getElementById("modalContainer")) return;
	
	var body = d.getElementsByTagName("body")[0];
	var mObj = body.appendChild(d.createElement("div"));
	mObj.id = "modalContainer";
	mObj.style.height = (d.documentElement.scrollHeight-4) + "px";
	
	var alertObj = mObj.appendChild(d.createElement("div"));
	alertObj.id = alertType;
	alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";
	alertObj.style.visiblity="visible";
	alertObj.style.top = getDialogTop() + "px"
	
	var h1 = alertObj.appendChild(d.createElement("h1"));
	h1.appendChild(d.createTextNode(title));

	if(txt != null){
		var msg = alertObj.appendChild(d.createElement("p"));
		if(txtType){
			msg.appendChild(d.createTextNode(txt));
		}
		else{
			msg.innerHTML = txt;
		}
	}
	var btn = null;
	if(OKBtn){
		var div = alertObj.appendChild(d.createElement("div"));
		btn = div.appendChild(d.createElement("a"));
		btn.id = "closeBtn";
		btn.appendChild(d.createTextNode(locAlertButtonText));
		btn.href = "#";
		btn.onclick = function(){ removeCustomAlert(); return false; }
		btn.onkeydown = function(oEvent){
			if(!oEvent){
				oEvent = window.event;
			}
			if(oEvent.keyCode == 27 || oEvent.keyCode == 13){
				removeCustomAlert(); 
				return false;
			}
		}
	}
	var alertFrame = GetElementById("AlertIframe");
	alertFrame.style.width = body.clientWidth + "px";
	alertFrame.style.height = body.clientHeight + "px";
	if(is_ie) alertFrame.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
	if(btn != null){
		btn.focus();
	}
};
function createCustomAlert(txt){
	MessageBox("alertBox", locAlertTitle, txt, true, true); 
};
function alertKO(txt){
	if(use_custom_alert){
		MessageBox("alertBoxKO", locAlertTitleKO, txt, true, true); 
	}else{
		alert(txt);
	}
};
function ShowProcessingBox(title){
	if("" == title){
		title = locProcessing;
	}
	if(title.lastIndexOf("...")<0){
		title+="...";
	}
	MessageBox("processingBox", title, null, false, false); 
};
function ShowImportExportResult(title, txt){
	MessageBox("alertImport", title, txt, false, true); 
};
function HideProcessingBox(){
	removeCustomAlert();
};
function removeCustomAlert(){
	var o = GetElementById("modalContainer");
	if(null == o){
		return;
	}
	document.getElementsByTagName("body")[0].removeChild(o);
	var alertFrame = GetElementById("AlertIframe");
	alertFrame.style.width = "0px";
	alertFrame.style.height = "0px";
};
// Image Preloader
function onImagePreload(){
	ImagesLoaded = true;
	AllImagesPreloading();
};
function ImagePreloader(images, path, callback){
	this.path = path;
	this.callback = callback;
	this.nLoaded = 0;
	this.nProcessed = 0;
	this.aImages = new Array();
	this.nImages = images.length;
	for(var i=0; i<images.length; i++) 
		this.preload(images[i]);
};
ImagePreloader.prototype.preload = function(image){
	var oImage = new Image;
	this.aImages[this.aImages.length] = oImage;
	oImage.onload = ImagePreloader.prototype.onload;
	oImage.onerror = ImagePreloader.prototype.onerror;
	oImage.onabort = ImagePreloader.prototype.onabort;
	oImage.oImagePreloader = this;
	oImage.bLoaded = false;
	oImage.src = this.path + image;
};
ImagePreloader.prototype.onComplete = function(){
	this.nProcessed++;
	if(this.nProcessed == this.nImages){
		if(this.callback != null){
			this.callback(this.aImages);
		}
		for(var i=0; i<this.aImages.length; i++){
			delete this.aImages[i];
		}
	}
};
ImagePreloader.prototype.onload = function(){
	this.bLoaded = true;
	this.oImagePreloader.nLoaded++;
	this.oImagePreloader.onComplete();
};
ImagePreloader.prototype.onerror = function(){
	this.bError = true;
	this.oImagePreloader.onComplete();
};
ImagePreloader.prototype.onabort = function(){
	this.bAbort = true;
	this.oImagePreloader.onComplete();
};
// FTB
function LoadFTB(){
	if(use_full_editor == false || FTB != null){
		return;
	}
	if(false == FTB_IconsLoaded){
		var o = GetElementById("FTBDiv");
		var f = FTB_HTML_UTF8.replace(/Font/,locFont);
		f = f.replace(/Size/,locSize);
		f = f.replace(/Symbols/,locSymbols);
		f = f.replace(/Bold/,locBold);
		f = f.replace(/Bulleted List/,locBulletedList);
		f = f.replace(/Copy/,locCopy);
		f = f.replace(/Create Link/,locCreateLink);
		f = f.replace(/Cut/,locCut);
		f = f.replace(/Delete/,locDelete);
		f = f.replace(/Indent/,locIndent);
		f = f.replace(/Insert Date/,locInsertDate);
		f = f.replace(/Insert Image/,locInsertImage);
		f = f.replace(/Insert Rule/,locInsertRule);
		f = f.replace(/Italic/,locItalic);
		f = f.replace(/Justify Right/,locJustifyRight);
		f = f.replace(/Justify Center/,locJustifyCenter);
		f = f.replace(/Justify Full/,locJustifyFull);
		f = f.replace(/Justify Left/,locJustifyLeft);
		f = f.replace(/Numbered List/,locNumberedList);
		f = f.replace(/Outdent/,locOutdent);
		f = f.replace(/Paste/,locPaste);
		f = f.replace(/Print/,locPrint);
		f = f.replace(/Redo/,locRedo);
		f = f.replace(/Remove All Formatting/,locRemoveFormat);
		f = f.replace(/Remove Link/,locRemoveLink);
		f = f.replace(/StrikeThrough/,locStrikeThrough);
		f = f.replace(/Superscript/,locSuperScript);
		f = f.replace(/Subscript/,locSubScript);
		f = f.replace(/Underline/,locUnderline);
		f = f.replace(/Undo/,locUndo);
		f = f.replace(/Fore Color Picker/,locFontColorPicker);
		f = f.replace(/Background Color Picker/,locBackgroundColorPicker);
		o.innerHTML = f;
	}
	InitFTB();
};
function InitFTB(){
	FTB_API['FreeTextBox1'] = FTB = new FTB_FreeTextBox('FreeTextBox1',
	true,
	false,
	new Array(
		new FTB_Button('FreeTextBox1_0_3','',function(){ this.ftb.FontForeColorPicker(); },null,false,null),
		new FTB_Button('FreeTextBox1_0_4','',function(){ this.ftb.FontBackColorPicker(); },null,false,null),
		new FTB_Button('FreeTextBox1_0_6','bold',null,null,false,null),
		new FTB_Button('FreeTextBox1_0_7','italic',null,null,false,null),
		new FTB_Button('FreeTextBox1_0_8','underline',null,null,false,null),
		new FTB_Button('FreeTextBox1_0_9','strikethrough',null,null,false,null),
		new FTB_Button('FreeTextBox1_0_11','superscript',null,null,false,null),
		new FTB_Button('FreeTextBox1_0_12','subscript',null,null,false,null),
		new FTB_Button('FreeTextBox1_0_13','removeformat',null,null,false,null),
		new FTB_Button('FreeTextBox1_0_15','print',function(){ this.ftb.Print(); },null,true,null),
		new FTB_Button('FreeTextBox1_1_0','justifyleft',null,null,false,null),
		new FTB_Button('FreeTextBox1_1_1','justifyright',null,null,false,null),
		new FTB_Button('FreeTextBox1_1_2','justifycenter',null,null,false,null),
		new FTB_Button('FreeTextBox1_1_3','justifyfull',null,null,false,null),
		new FTB_Button('FreeTextBox1_1_5','insertunorderedlist',null,null,false,null),
		new FTB_Button('FreeTextBox1_1_6','insertorderedlist',null,null,false,null),
		new FTB_Button('FreeTextBox1_1_7','indent',null,null,false,null),
		new FTB_Button('FreeTextBox1_1_8','outdent',null,null,false,null),
		new FTB_Button('FreeTextBox1_1_10','cut',function(){ this.ftb.Cut(); },null,true,null),
		new FTB_Button('FreeTextBox1_1_11','copy',function(){ this.ftb.Copy(); },null,true,null),
		new FTB_Button('FreeTextBox1_1_12','paste',function(){ this.ftb.Paste(); },null,true,null),
		new FTB_Button('FreeTextBox1_1_14','undo',function(){ this.ftb.Undo(); },null,false,function(){ this.disabled=!this.ftb.CanUndo(); }),
		new FTB_Button('FreeTextBox1_1_15','redo',function(){ this.ftb.Redo(); },null,false,function(){ this.disabled=!this.ftb.CanRedo(); }),
		new FTB_Button('FreeTextBox1_1_17','',function(){ this.ftb.DeleteContents(); },null,false,null),
		new FTB_Button('FreeTextBox1_1_19','createlink',function(){ this.ftb.CreateLink(); },null,false,null),
		new FTB_Button('FreeTextBox1_1_20','unlink',null,null,false,function(){ this.disabled = !(this.ftb.GetParentElement().tagName.toLowerCase() == 'a') }),
		new FTB_Button('FreeTextBox1_1_22','inserthorizontalrule',null,null,false,null),
		new FTB_Button('FreeTextBox1_1_23','',function(){ var d = new Date();this.ftb.InsertHtml(d.toLocaleDateString()); },null,false,null)
		),
	new Array(
		new FTB_DropDownList('FreeTextBox1_0_1','fontname',null,null,null),
		new FTB_DropDownList('FreeTextBox1_0_2','fontsize',null,null,null),
		new FTB_DropDownList('FreeTextBox1_1_21','',function(){ this.ftb.InsertHtml(this.list.options[this.list.options.selectedIndex].value); },null,null)
		),				
	FTB_BREAK_P,
	FTB_PASTE_DEFAULT,
	FTB_TAB_INSERTSPACES,
	FTB_MODE_DESIGN,									
	null,
	'FTB/IFrame.css',
	'',
	'',
	'',
	'',
	'',
	'',
	false,
	21,
	20);
};
function trim(str){
	while(str.charAt(0) == " "){
		str = str.substr(1);
	}
	while(str.charAt(str.length-1) == " "){
		str = str.substr(0, str.length-1);
	}
	return str;
};
// HELP
function Help(){
	this.HTMLContent = new Array(9);
}
Help.prototype.NavIn = function(){
	this.InitTreeMenu();
	SetInfoLabel("");
	ShowObject(GeneralPanel);
	H_GetPage(1);
};
Help.prototype.InitTreeMenu = function(){
	if(oTreeMenu != null){
		oTreeMenu.dispose();
	}
	oTreeMenu = new TreeControl(GetElementById("LEFT_MENU_PANEL"), "LTree");
	oTreeMenu.createHeader(locHelpTopics);
	var aTreeDef = new Array();
	aTreeDef[aTreeDef.length] = new Array(locOverview, "", "", "H_GetPage(1);");
	aTreeDef[aTreeDef.length] = new Array(locConfiguration, "", "", "H_GetPage(2);");
	aTreeDef[aTreeDef.length] = new Array(locReadingMessages, "", "", "H_GetPage(3);");
	aTreeDef[aTreeDef.length] = new Array(locComposingMessages, "", "", "H_GetPage(4);");
	aTreeDef[aTreeDef.length] = new Array(locUsingContacts, "", "", "H_GetPage(5);");
	aTreeDef[aTreeDef.length] = new Array(locArchivingMessages, "", "", "H_GetPage(6);");
	//aTreeDef[aTreeDef.length] = new Array(locAdminHelp, "", "", "H_GetPage(7);");
	//aTreeDef[aTreeDef.length] = new Array("F.A.Q.", "", "", "H_GetPage(8);");
	//aTreeDef[aTreeDef.length] = new Array("Features Request", "", "", "");
	for(var i=0; i< aTreeDef.length; i++){
		if(!oProfileSettings.ShowMenuIcons){
			aTreeDef[i][2] = "";
		}
		oTreeMenu.addItem(aTreeDef[i][0], aTreeDef[i][1], aTreeDef[i][2], aTreeDef[i][3], "");
	}
	oTreeMenu.selectItem(0);
	delete aTreeDef;
};
function H_GetPage(page){
	if(oHelp.HTMLContent[page] == null){
		var result = Anthem_InvokeSync("H_GetHelpPage", [page]);
		if(result.error != null){
			alertKO(result.error);
		}else{
			oHelp.HTMLContent[page] = result.value;
		}
	}
	GeneralPanel.innerHTML = oHelp.HTMLContent[page];
};
function endsWith(str,s){
	var reg = new RegExp(s + "$");
	return reg.test(str);
};

