////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	DLib HTML functions - copyright davidviner.com 2011
//
//	12.10.2011	5.10.1	DJV		Added _attrs.
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var	_attrs = [];

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Handle INCS values.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function _handleIDC (id)
{
	var	cl = "",
		st = "",
		ind = "";

	if (id.indexOf ("@") > -1)
	{
		var s = id.split ("@");
		id = s[0];
		st = s[1];
	}

	if (id.indexOf (".") > -1)
	{
		var s = id.split (".");
		id = s[0];
		cl = s[1];
	}

	if (id.indexOf ("[") > -1)
	{
		var s = id.split ("[");
		id = s[0];
		ind = parseInt (s[1]);
	}

	var idc = "";

	if (id != "")
	{
		if (id.charAt (0) == "#")
			id = id.substr (1);

		if (id.charAt (0) != "_")
			idc += ' id="' + id + ind + '"';

		idc += ' name="' + id + '"';
	}

	_attrs.id = id + ind;
	_attrs.name = id;
	_attrs.cls = cl;
	_attrs.style = st;

	if (cl != "") idc += ' class="' + cl + '"';
	if (st != "") idc += ' style="' + st + '"';

	return idc;
}

//F/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Output a simple span block with either an id or a class attribute.
// @span	string	Supplied string wrapped in span tags.
// @ics		string	See HtmlGlobal.
// @content	string	The supplied content string.
// @[other]	string	Any other attribute information that needs to be sent to the span.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function span (ics, content, other)
{
	other = (other == undefined ? "" : " " + other);
	return "<span" + _handleIDC (ics) + other + ">" + content + "</span>";
}

//F/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Output a simple div block with either an id or a class attribute.
// @div		string	Supplied string wrapped in div tags.
// @ics		string	See HtmlGlobal.
// @content	string	The supplied content string.
// @[other]	string	Any other attribute information that needs to be sent to the div.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function div (ics, content, other)
{
	other = (other == undefined ? "" : " " + other);
	return "<div" + _handleIDC (ics) + other + ">" + content + "</div>";
}

//F////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Return an image (img) tag with the specified id/class/style set.
// @imgidc		string	The fully formed HTML for this image.
// @src			string	The source location of this image.
// @[idc]		string	The class name (or "@style settings").
// @[border]	int		The border size - default is 0.
// @[alt]		string	The alt/title tag - default is blank. See img() for 'tooltip' information.
// @[useMap]	string	The name of the map if client-side image mapping is required.
// @[other]		string	Any other information that needs to be sent to the image tag.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function imgidc (src, idc, border, alt, useMap, other)
{
	idc = undef (idc);
	border = undef (border);
	alt = undef (alt);
	useMap = undef (useMap);
	other = undef (other, true);

	if (useMap != "")
	{
		if (useMap.charAt (0) != "#")
			useMap = "#" + useMap;

		useMap = ' usemap="' + useMap + '"';
	}

	return '<img src="' + src + '"' + _handleIDC (idc) + (border.length > 0 ? ' border="' + border + '"' : "") +
		(alt != "" ? "" : ' alt="' + alt + '" title="' + alt + '"') + useMap + other + ' />';
}

//F////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Return an image (img) tag.
// @img			string	The fully formed HTML for this image.
// @src			string	The source location of this image.
// @[border]	int		The border size - default is 0.
// @[alt]		string	The alt tag - default is blank. Also outputs a title tag.
// @[useMap]	string	The name of the map if client-side image mapping is required.
// @[other]		string	Any other information that needs to be sent to the image tag.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function img (src, border, alt, useMap, other)
{
	return imgidc (src, "", border, alt, useMap, other);
}

//F/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Output a specified number of non-blank spaces.
// @spaces	string	The specified number of non-blank spaces (nbsp).
// @qty		int		The quantity required.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function spaces (qty)
{
	sp = "";

	for (var i = 0; i < qty; i++)
		sp += "&nbsp;";

	return sp;
}

//F/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Output a specified number of blank lines.
// @br		string	The specified number of blank lines (BR tags).
// @qty		int		The quantity required. If qty is negative then the number is converted back to positive but the
//					last tag is output with a clear="all" attribute.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function br (qty)
{
	qty = (undefined ? 1 : qty);
	var doClr = (qty < 0);
	qty = Math.abs (qty);
	ln = "";

	for (var i = 0; i < qty; i++)
		ln += "<br" + ((doClr && i == qty - 1) ? ' clear="all" ' : "") + '/>';

	return ln;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

