/*
 * Copyright (c) 2005 Absolutely Training Limited
 * 
 * Created on 06-Dec-2005
 */
/**
 * Translation of the Java HtmlCreator class into JavaScript
 * 
 * @author paulb
 */
function HtmlCreator() {}

HtmlCreator.prototype.htmlText = [];
HtmlCreator.prototype.divNesting = 0;

HtmlCreator.prototype.getHtmlText = function() {
    if ( this.divNesting > 0 ) {
        throw new Error( "Not all divs closed");
    }
    return this.htmlText.join('');
};

HtmlCreator.prototype.clearHtmlText = function() {
	this.htmlText = [];
}

HtmlCreator.prototype.line = function( text ) {
    this.htmlText.push( text );
    this.newline();
};

HtmlCreator.prototype.newline = function() {
    this.htmlText.push( "\r\n");
};

HtmlCreator.prototype.div = function( cssClass ) {
    this.line( "<div class=\"" + cssClass + "\">");
    this.divNesting++;
};

HtmlCreator.prototype.divWithStyle = function( cssClass, style ) {
    this.line( "<div class=\"" + cssClass + "\" style=\"" + style + "\">");
    this.divNesting++;
};    

HtmlCreator.prototype.divWithText = function( cssClass, textValue, floatSide ) {
    var text = textValue ? textValue.toString() : "";
    this.line( "<div style=\"" +(floatSide ? "float:" + floatSide : "")+ "\" class=\"" + cssClass + "\">" + text + "</div>");
};

HtmlCreator.prototype.divWithTextAndId = function( cssClass, id, textValue, floatSide ) {
    var text = textValue ? textValue.toString() : "";
    this.line( "<div style=\"" +(floatSide ? "float:" + floatSide : "")+ "\" class=\"" + cssClass + "\" id=\"" + id + "\" name=\"" + id + "\">" + text + "</div>");
};

HtmlCreator.prototype.divWithId = function( id ) {
    this.line( "<div id=\"" + id + "\">");
    this.divNesting++;
};

HtmlCreator.prototype.divWithIdAndStyle = function( id, style ) {
    this.line( "<div id=\"" + id + "\" style=\"" + style + "\">");
    this.divNesting++;
};

HtmlCreator.prototype.endDiv = function() {
    if ( this.divNesting == 0 ) {
        throw new Error( "Tried to end div when none was started");
    }
    this.line( "</div>");
    this.divNesting--;
};

HtmlCreator.prototype.form = function( action ) {
    this.line( "<form action=\"" + action + "\" >" );
};

HtmlCreator.prototype.endForm = function() {
    this.line( "</form>" );
};

HtmlCreator.prototype.tableRow = function() {
    this.line( "<tr>");
};

HtmlCreator.prototype.endTableRow = function() {
    this.line( "</tr>");
};

HtmlCreator.prototype.inputRadio = function( name, value ) {
    this.line( "<input type=\"radio\" name=\"" + name + "\" value=\"" + value + "\" />");
};

HtmlCreator.prototype.inputCheckBox = function( name, value ) {
    this.line( "<input type=\"checkbox\" name=\"" + name + "\" value=\"" + value + "\" />");
};

HtmlCreator.prototype.inputHidden = function( name, value ) {
    this.line( "<input type=\"hidden\" name=\"" + name + "\" id=\"" + name + "\" value=\"" + value + "\" />");
};

HtmlCreator.prototype.inputButton = function( value, onClick ) {
    this.line( "<input class=\"button\" type=\"button\" value=\"" + value + "\" onClick=\"" + onClick + "\" />");
};

HtmlCreator.prototype.link = function( cssClass, onClick, text ) {
    var classAttr = cssClass ? "class\"" + cssClass + "\" " : "";
    this.line( "<a " + classAttr + "href=\"\" onClick=\"" + onClick + "\">" + text + "</a>" );
};


