/* open a tag */
function openTag (tag)
{
    htmlWrite ("<");
    htmlWrite (tag);
}

/* open a tag with a class */
function openTagClass (tag, whatClass)
{
    if (whatClass != null && whatClass.length != 0)
    {
        openTag (tag);
        addClass (whatClass);
    }
    else
    {
        openTag (tag);
    }
}

/* close a tag */
function closeTag (tag)
{
    htmlWrite (">");
}

/* close a tag with '/>' */
function slashCloseTag (tag)
{
    htmlWrite (" />");
}

/* closing tag */
function closingTag (tag)
{
    htmlWrite ("</");
    htmlWrite (tag);
    htmlWrite (">");
}

/* write full tag */
function writeTag (tag)
{
    openTag (tag);
    closeTag ();
}

function writeTagClass (tag, whatClass)
{
    if (whatClass != null && whatClass.length != 0)
    {
        openTag (tag);
        addClass (whatClass);
        closeTag ();
    }
    else
    {
        writeTag (tag);
    }
}

/* add an attribute */
function addAttr (attr, value)
{
    htmlWrite (" ");
    htmlWrite (attr);
    htmlWrite ('="');
    htmlWrite (value);
    htmlWrite ('"');
}

/* add class attribute (this is probably the most used one */
function addClass (whatClass)
{
    htmlWrite (" class=");
    htmlWrite ('"');
    htmlWrite (whatClass);
    htmlWrite ('"');
}

/* write HTML */
function htmlWrite (text)
{
    document.write (text);
}

/* blank line */
function htmlNewLine ()
{
    document.write ("<br />");
}

/* write text and make a new line */
function htmlWriteLn (text)
{
    htmlWrite (text);
    htmlNewLine ();
}

/* horizontal rule */
function htmlHRule ()
{
    htmlWrite ("<hr />");
}

/* write a tag with an id */
function writeTagID (tag, id)
{
    openTagID (tag, id);
    closeTag ();
}

/* open tage with an id */
function openTagID (tag, id)
{
    openTag (tag);
    addAttr (id);
}

/* add IMG tag */
function addImg (imgSrc)
{
    openTag ("img");
    addAttr ("src", imgSrc);
    slashCloseTag ();
}

function addImgID (imgSrc, imgID)
{
    openTag ("img");
    addAttr ("src", imgSrc);
    addAttd ("id", imgID);
    slashCloseTag ();
}

/* find an element by id */
function findByID (id)
{
    return document.getElementById (id);
}

/* write a tage with a style */
function writeTagStyle (tag, style)
{
    if (style != null && style.length != 0)
    {
        openTagStyle (tag, style);
    }
    else 
    {
        openTag (tag);
    }
    
    closeTag ();
}

function openTagStyle (tag, style)
{
    openTag (tag);
    
    if (style != null && style.length != 0)
    {
        addAttr ("style", style);
    }
}

function createAnchor (anchorName, anchorText)
{
    openTag ("a");
    addAttr ("name", anchorName);
    addAttr ("id", anchorName);
    closeTag ();
    
    if (!emptyString (anchorText))
    {
        htmlWrite (anchorText);
    }

    closingTag ("a");
}
