/*
	Prototype definition for the User objects used in IGN scripts.

	*** IGN_Core.js must be executed prior to executing this script
	*** IGN_String.js must be executed prior to executing this script
	*** IGN_Number.js must be executed prior to executing this script
	*** IGN_Array.js must be executed prior to executing this script

	Author: OldManLink (Peter Hugosson-Miller)
	Creation date: 2005-08-05
	Version: 1.0

	OldManLink.vipColors = UserColors.fromInfoString('Goldenrod bold normal DarkBlue none Goldenrod');

*/

UserColors = function()					// The prototype comes into existence
{
	this.mainColor = 'Goldenrod';		// Initialize the default values to OldManLink's colours
	this.fontWeight = 'bold';
	this.fontStyle = 'normal';
	this.backgroundColor = 'DarkBlue';
	this.textDecoration = 'none';
	this.borderColor = 'Goldenrod';
}

UserColors.fromInfoString = function(userColorsString)
{/*
	Parse the supplied information string into the expected tokens, and if
	successful create a UserColors instance and return it.
	Otherwise, return null.
*/
	var tUserColors = null;
	var tTokens=userColorsString.match(/(\S*) (\S*) (\S*) (\S*) (\S*) (\S*)/);
	if (tTokens != null)
	{
		tUserColors = new UserColors();
		tUserColors.mainColor=tTokens[1];
		tUserColors.fontWeight=tTokens[2];
		tUserColors.fontStyle=tTokens[3];
		tUserColors.backgroundColor=tTokens[4];
		tUserColors.textDecoration=tTokens[5];
		tUserColors.borderColor=tTokens[6];
	}
	return tUserColors;
}

UserColors.fromInfoStrings = function(MUStrings)
{/*
	Parse the string <MUStrings> to obtain an Array of
	userColors with user name attached.
	Return the resulting Array if sucessful.
	Return null otherwise.
*/
	var tUserColors = null;
	var tLines=MUStrings.match(/^.*$/gm);
	var tSuccess=tLines.length > 0;

	if (tSuccess)
	{
		tUserColors = new Array();
		tLines.iterate( function(line)
			{
				var tFirstSpacePosition = line.indexOf(' ');
				var tUserName = line.substring (0, tFirstSpacePosition);
				var tUserColor = UserColors.fromInfoString(line.substring (tFirstSpacePosition + 1, line.length) + ' none none');
				if (tUserColor != null)
				{
					if(tUserColors[tUserName + '_'] == null)
					{
						tUserColor.userName = tUserName;
						tUserColors[tUserColors.length]=tUserColor;
						tUserColors[tUserName + '_']=tUserColor;
					}
					else
						User.transcript.value += 'Warning: duplicate VIP Color\'' + line + '\' - ignored.\n';
				}
			});
	}
	return tUserColors;
}


UserColors.prototype.getCssString = function()
{/*
	Return my "style" string, suitable for using with the IGN style sheet.
*/

	tStyleString = 'style="';
	tStyleString += 'color: ' + this.mainColor + ';';
	tStyleString += 'font-weight: ' + this.fontWeight + ';';
	tStyleString += 'font-style: ' + this.fontStyle + ';';
	tStyleString += 'background-color: ' + this.backgroundColor + ';';
	tStyleString += 'text-decoration: ' + this.textDecoration + ';';
	tStyleString += 'border-top: 1px solid ' + this.borderColor + ';';
	tStyleString += 'border-bottom: 1px solid ' + this.borderColor + ';';
	tStyleString += 'border-right: 1px solid ' + this.borderColor + ';';
	tStyleString += 'border-left: 1px solid ' + this.borderColor + ';';
	tStyleString += '"';

	return tStyleString;
}


UserColors.prototype.fontWeightTag = function()
{/*
	Return my "font weight" string, suitable for using as a markup tag.
*/
	if(this.fontWeight == 'bold')
	return 'b';
	else return '';
}


UserColors.prototype.fontStyleTag = function()
{/*
	Return my "font style" string, suitable for using as a markup tag.
*/
	if(this.fontStyle == 'italic')
	return 'i';
	else return '';
}


UserColors.prototype.getMarkupColors = function(userNameString)
{/*
	Return the supplied userName string, with style and colors added using markup.
*/
	var tMarkupString = ' ' + userNameString;
	tMarkupString = tMarkupString.markupPair(this.fontWeightTag());
	tMarkupString = tMarkupString.markupPair(this.fontStyleTag());
	tMarkupString = tMarkupString.markupPair('color=' + this.mainColor);
	return tMarkupString.markupPair('hl=' + this.backgroundColor);
}

