

// Create a global object (Config) that can hold arbitrary values from the config file.
if (typeof Config == "undefined")
	var Config = {};

Config.WSLSupportSiteURL   = "http://www.aol.de/redirect/webmail/email_hilfe";
Config.NewBaseResourcesURL = "http://o.aolcdn.com/cdn.webmail.aol.com/35464/aol/de-de/";
Config.BaseLitePagesURL = "http://mail.aol.com/35478-211/aol-1/de-de/Lite/";
Config.BaseCssURL = "http://o.aolcdn.com/cdn.webmail.aol.com/35464/css/";
Config.UseOMS = false;
Config.CrossFolderSearch = true;
Config.FriendlyName = true;

// RichTextEditor Config Settings
Config.SpacerImageURL = "http://o.aolcdn.com/cdn.webmail.aol.com/35464/images/common/space.gif";
Config.EnablePictures = false;
Config.ShowRichTextHtml = false;
Config.RteIframeInitUrl = "http://mail.aol.com/common/empty.htm";
Config.UIVariant = "AOL";

Config.Strings = {
	ImageRemoved : " [Keine Grafik] ",
	Bold : "Fett",
	Italic : "Kursiv",
	Underline : "Unterstrichen",
	FontColor : "Textfarbe wählen",
	BackgroundColor : "Hintergrundfarbe für Text wählen",
	JustifyLeft : "Linksbündig ausrichten",
	JustifyCenter : "Zentriert ausrichten",
	JustifyRight : "Rechtsbündig ausrichten",
	OrderedList : "Nummerierte Liste",
	BulletedList : "Aufzählungszeichen",
	DecreaseIndent : "Einzug verkleinern",
	IncreaseIndent : "Einzug vergrößern",
	HorizontalRule : "Horizontale Line",
	ViewHTMLSource : "Quellcode anzeigen",
	Basic_BrowseEntryError : "Klicken Sie auf die Schaltfläche \x22Durchsuchen\x22, um Dateien als Anhang hinzuzufügen.",
	NAddresses: "{0} Adressen",
	SharedGroup: "Gruppe",
	MailFilter_ErrorInvalidCriteriaChars:"In Filterkriterien sind Anführungszeichen (\x22) und umgekehrte Schrägstriche (\\) nicht zulässig.",
	MailFilter_ErrorInvalidEmailChars:"Bei eMail-Adressen sind Anführungszeichen (\x22), umgekehrte Schrägstriche (\\) und Leerzeichen nicht zulässig.",
	MailFilter_EmptyPriority:"Geben Sie bitte vor dem Update für alle Filter eine Priorität ein."
}


// Define dynamic SDK values here
if (typeof WebmailSDK == "undefined")
	var WebmailSDK = new Object();
	
WebmailSDK.hostURL = "http://o.aolcdn.com/cdn.webmail.aol.com/35464/js/lite/autocomplete/";  // syntax - http://hostname/sdk/version/

//WebmailSDK strings
WebmailSDK.textClose = "Schließen";
WebmailSDK.textClosePanel = "Seitenleiste schließen";
WebmailSDK.textAddressPage = "Seite";
WebmailSDK.textAddressOf = "von";
WebmailSDK.textAutoCompleteWindowTitle = "Automatisch vervollständigen";
WebmailSDK.textAutoCompleteLoading = "Laden ...";
WebmailSDK.textAutoCompleteBusyStatus = "Kontaktdaten werden vom Server angefordert ...";
WebmailSDK.textAutoCompleteSearchStatus = "{0} von {1} Kontakten wurden durchsucht {2}";
WebmailSDK.textAutoCompleteMatchState1 = "1 Treffer für \x27{0}\x27";
WebmailSDK.textAutoCompleteMatchState2 = "{0} Treffer für \x27{1}\x27&nbsp;&nbsp;(Erste {2} angezeigt)";
WebmailSDK.textAutoCompleteMatchState3 = "{0} Treffer für \x27{1}\x27";

WebmailSDK.textError = new Array();
WebmailSDK.textError[WebmailSDK.codeErrorUnspecified] = "Ein unbekannter Fehler ist aufgetreten.";
WebmailSDK.textError[WebmailSDK.codeErrorInternal] = WebmailSDK.textError[WebmailSDK.codeErrorUnspecified];
WebmailSDK.textError[WebmailSDK.codeErrorServer] = "Beim Aufrufen der Daten vom Server ist ein Fehler aufgetreten.";
WebmailSDK.textError[WebmailSDK.codeErrorAddress] = "Beim Aufrufen der Adressen vom Server ist ein Fehler aufgetreten.";

WebmailSDK.enableAddressAutoComplete = true;
WebmailSDK.hideFloatingContent = true;

function DateFormat()
{
}

DateFormat.kLongMonthNames = new Array('Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember');
DateFormat.kShortMonthNames = new Array('Jan','Feb','Mrz','Apr','Mai','Jun','Jul','Aug','Sept','Okt','Nov','Dez');
DateFormat.kMonthNames = DateFormat.kLongMonthNames.concat(DateFormat.kShortMonthNames);

DateFormat.kLongDayNames = new Array('Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag');
DateFormat.kShortDayNames = new Array('So','Mo','Di','Mi','Do','Fr','Sa');
DateFormat.kDayNames = DateFormat.kLongDayNames.concat(DateFormat.kShortDayNames);

DateFormat.Date_am = "am";
DateFormat.Date_pm = "pm";


DateFormat.FormatDate = function(date, format)
{
	var y = date.getFullYear() + "";
	var M = date.getMonth() + 1;
	var d = date.getDate();
	var E = date.getDay();
	var H = date.getHours();
	var m = date.getMinutes();
	var s = date.getSeconds();
	
	// Convert real date parts into formatted versions.
	// Avoiding the use of DateFormat.LZ by doing the same thing inline yields
	// a noticable performance improvement when this function is used in a
	// loop.
	var value = new Object();
	value["y"] = y;
	value["yyyy"] = y;
	value["yy"] = y.substring(2,4);
	value["M"] = M;
	value["MM"] = (M < 0 || M > 9) ? M : "0" + M;
	value["MMM"] = DateFormat.kMonthNames[M - 1];
	value["NNN"] = DateFormat.kMonthNames[M + 11];
	value["d"] = d;
	value["dd"] = (d < 0 || d > 9) ? d : "0" + d;
	value["E"] = DateFormat.kDayNames[E + 7];
	value["EE"] = DateFormat.kDayNames[E];
	value["H"] = H;
	value["HH"] = (H < 0 || H > 9) ? H : "0" + H;
	if (H == 0)
		value["h"] = 12;
	else if (H > 12)
		value["h"] = H - 12;
	else
		value["h"] = H;
	value["hh"] = (value["h"] < 0 || value["h"] > 9) ? value["h"] : "0" + value["h"];
	if (H > 11)
		value["K"] = H - 12;
	else
		value["K"] = H;
	value["k"] = H + 1;
	value["KK"] = (value["K"] < 0 || value["K"] > 9) ? value["K"] : "0" + value["K"];
	value["kk"] = (value["k"] < 0 || value["k"] > 9) ? value["k"] : "0" + value["k"];
	if (H > 11)
		value["a"] = "pm";
	else
		value["a"] = "am";
	value["m"] = m;
	value["mm"] = (m < 0 || m > 9) ? m : "0" + m;
	value["s"] = s;
	value["ss"] = (s < 0 || s > 9) ? s : "0" + s;
	
	// Avoiding string concatenation doesn't improve performance, and
	// can actually hurt performance a little bit for smaller strings.
	var result = "";
	// There's a slight performance gain if we avoid using charAt.
	// So we create a character array by splitting the string.
	var formatArray = format.split("");
	var i_format = 0;
	var c = null;
	var token = null;
	while (i_format < format.length)
	{
		c = formatArray[i_format];
		token = "";
		while ((formatArray[i_format] == c) && (i_format < formatArray.length))
			token += formatArray[i_format++];
		if (value[token] != null)
			result = result + value[token];
		else
			result = result + token;
	}
	return result;
};

DateFormat.IsInteger = function(val)
{
	var digits="1234567890";
	for (var i = 0; i < val.length; i++)
	{
		if (digits.indexOf(val.charAt(i)) == -1)
			return false;
	}
	return true;
};

DateFormat.GetInt = function(str, i, minlength, maxlength)
{
	for (var x = maxlength; x >= minlength; x--)
	{
		var token = str.substring(i, i + x);
		if (token.length < minlength)
			return null;
		if (DateFormat.IsInteger(token))
			return token;
	}
	return null;
};

/*the following function doesn't parse E in the format*/
DateFormat.GetDateFromFormat = function(val, format)
{
	val = val + "";
	format = format + "";
	var i_val = 0;
	var i_format = 0;
	var c = "";
	var token = "";
	var token2 = "";
	var x,y;
	var now = new Date();
	var year = now.getYear();
	var month = now.getMonth()+1;
	var date = 1;
	var hh = now.getHours();
	var mm = now.getMinutes();
	var ss = now.getSeconds();
	var ampm = "";
	
	while (i_format < format.length)
	{
		// Get next token from format string
		c = format.charAt(i_format);
		token = "";
		while ((format.charAt(i_format)==c) && (i_format < format.length))
			token += format.charAt(i_format++);
		// Extract contents of value based on format token
		if (token == "yyyy" || token == "yy" || token == "y")
		{
			if (token == "yyyy")
			{
				x = 4;
				y = 4;
			}
			if (token == "yy")
			{
				x = 2;
				y = 2;
			}
			if (token == "y")
			{
				x = 2;
				y = 4;
			}
			year = DateFormat.GetInt(val, i_val, x, y);
			if (year==null)
				return 0;
			i_val += year.length;
			if (year.length == 2)
			{
				if (year > 70)
					year = 1900 + (year - 0);
				else
					year = 2000 + (year - 0);
			}
		}
		else if (token == "MM" || token == "M")
		{
			month = DateFormat.GetInt(val, i_val, token.length, 2);
			if (month == null || (month < 1) || (month > 12))
				return 0;
			i_val += month.length;
		}
		else if (token == "dd" || token == "d")
		{
			date = DateFormat.GetInt(val, i_val, token.length, 2);
			if (date == null || (date < 1) || (date > 31))
				return 0;
			i_val += date.length;
		}
		else if (token == "hh" || token == "h")
		{
			hh = DateFormat.GetInt(val, i_val, token.length, 2);
			if (hh == null || (hh < 1) || (hh > 12))
				return 0;
			i_val += hh.length;
		}
		else if (token == "HH" || token == "H")
		{
			hh = DateFormat.GetInt(val, i_val, token.length, 2);
			if (hh == null || (hh < 0) || (hh > 23))
				return 0;
			i_val += hh.length;
		}
		else if (token == "KK" || token == "K")
		{
			hh = DateFormat.GetInt(val, i_val, token.length, 2);
			if (hh == null || (hh < 0) || (hh > 11))
				return 0;
			i_val += hh.length;
		}
		else if (token == "kk" || token == "k")
		{
			hh = DateFormat.GetInt(val, i_val, token.length, 2);
			if (hh == null || (hh < 1) || (hh > 24))
				return 0;
			i_val += hh.length;
			hh--;
		}
		else if (token == "mm" || token == "m")
		{
			mm = DateFormat.GetInt(val, i_val, token.length, 2);
			if (mm == null || (mm < 0) || (mm > 59))
				return 0;
			i_val += mm.length;
		}
		else if (token == "ss" || token == "s")
		{
			ss = DateFormat.GetInt(val, i_val, token.length, 2);
			if (ss == null || (ss < 0) || (ss > 59))
				return 0;
			i_val += ss.length;
		}
		else if (token == "a")
		{		
			// TODO: NOTE THIS IS DANGEROUS (always assumes two characters)
			var len = 0;
			var ampmStr = val.substring(i_val, i_val+2).toLowerCase();
			if (ampmStr == DateFormat.Date_am) {
				len = DateFormat.Date_am.length;
				ampm = "AM";
			}
			else if (ampmStr == DateFormat.Date_pm) {
				len = DateFormat.Date_pm.length;
				ampm = "PM";
			}
			else {
				return 0;
			}
			i_val += len;
		}
		else
		{
			if (val.substring(i_val, i_val+token.length) != token)
				return 0;
			else
				i_val += token.length;
		}
	}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length)
		return 0;
	// Is date valid for month?
	if (month == 2)
	{
		// Check for leap year
		if ( ( (year % 4 == 0)&&(year % 100 != 0) ) || (year % 400 == 0) ) // leap year
		{
			if (date > 29)
				return 0;
		}
		else
		{
			if (date > 28)
				return 0;
		}
	}
	if ((month == 4) || (month == 6) || (month == 9) || (month == 11))
	{
		if (date > 30)
			return 0;
	}
	// Correct hours value
	if (hh < 12 && ampm == "PM")
		hh = hh - 0 + 12;
	else if (hh > 11 && ampm == "AM")
		hh-=12;
	var newdate = new Date(year, month - 1, date, hh, mm, ss);
	return newdate.getTime();
};

function ShortestDate(date, skipTodayString)
{
	var now = new Date();
	var nowDate = now.getDate();
	var nowMonth = now.getMonth();
	var nowYear = now.getFullYear();
	
	var then = new Date(date);
	var thenDate = then.getDate();
	var thenMonth = then.getMonth();
	var thenYear = then.getFullYear();
	
	var nowMidnight = new Date(nowYear, nowMonth, nowDate);
	var thenMidnight = new Date(thenYear, thenMonth, thenDate);
	var dayDiff = (nowMidnight - thenMidnight) / 86400000;
	var todayStr = skipTodayString?"":"Heute" + " ";
	if (dayDiff == 0)
		return  todayStr + DateFormat.FormatDate(then, "h:mm a");
	else if (dayDiff == 1 && !skipTodayString)
		return "Gestern" + " " + DateFormat.FormatDate(then, "h:mm a");
	else if (dayDiff < 7)
		return DateFormat.FormatDate(then, "E NNN d");
	else if (nowYear == thenYear)
		return DateFormat.FormatDate(then, "NNN d");
	else
		return DateFormat.FormatDate(then, "dd\x2fMM\x2fyyyy");
};

