/*
 *  Classe MAHSHtml ---->TODO COMMENT<-----
 */

/* 
 * Questa classe permette TODO
 *
 * @author Antonio Bencivenga <a.bencivenga@mahs.it>, Marco Giammarini <m.giammarini@mahs.it>
 * @version 0.1.0
 * @copyright 2009-2010 - MAHS di Antonio Bencivenga - www.mahs.it  
 * @package mahsJS/mahsJSBase
 */
var MAHSHtml = 
{

  /**
   * Metodo per la creazione di un tag generico che non ha bisogno di altri attributi all'infuori della classe e dell'id.
   *
   **/
  tag: function(tagName, tagClass, tagId)
  {
    // Creo l'oggetto nel documento.
    var tag = document.createElement(tagName);

    // Se è presente la classe, la inserisco.
    if(tagClass != "") 
      tag.className = tagClass;

    // Se è presente l'id lo inserisco.
    if(tagId != "") 
      tag.setAttribute("id",tagId);

    return tag;
  },

  tagA: function(aClass, aId, aHref, aTitle)
  {
    // Creo l'oggetto nel documento.
    var tag = document.createElement("a");
    // Se è presente la classe, la inserisco.
    if(aClass != "") 
      tag.className = aClass;
    // Se è presente l'id lo inserisco.
    if(aId != "") 
      tag.setAttribute("id",aId);
    // Se è presente l'href lo inserisco.
    if(aHref != "") 
      tag.setAttribute("href",aHref);
    // Se è presente il titolo lo inserisco.
    if(aTitle != "") 
      tag.setAttribute("title",aTitle);

    return tag;
  },

  tagIMG: function(imgClass, imgId, imgSrc, imgAlt)
  {
    // Creo l'oggetto nel documento.
    var tag = document.createElement("img");
    // Se è presente la classe, la inserisco.
    if(imgClass != "") 
      tag.className = imgClass;
    // Se è presente l'id lo inserisco.
    if(imgId != "") 
      tag.setAttribute("id",imgId);
    // Se è presente il src lo inserisco.
    if(imgSrc != "") 
      tag.setAttribute("src",imgSrc);
    // Se è presente il testo alternativo lo inserisco.
    if(imgAlt != "") 
      tag.setAttribute("alt",imgAlt);

    return tag;
  },

  tagDIV: function(divClass, divId)
  {
    // Creo l'oggetto nel documento.
    var tag = document.createElement("div");
    // Se è presente la classe, la inserisco.
    if(divClass != "") 
      tag.className = divClass;
    // Se è presente l'id lo inserisco.
    if(divId != "") 
      tag.setAttribute("id",divId);

    return tag;
  },

  tagINPUT: function(inputClass, inputId, inputType, inputName, inputValue, inputLength, disable)
  {
    // Creo l'oggetto nel documento.
    var tag = document.createElement("input");

    // Se è presente la classe, la inserisco.
    if(inputClass != "") 
      tag.className = inputClass;

    // Se è presente l'id lo inserisco.
    if(inputId != "") 
      tag.setAttribute("id",inputId);

    // Se è presente il type lo inserisco, altrimenti metto 'text' di default.
    if(inputType != "") 
      tag.setAttribute("type",inputType);
    else
      tag.setAttribute("type","text");

    // Se è presente name lo inserisco.
    if(inputName != "") 
      tag.setAttribute("name",inputName);

    // Scrivo il value all'interno del tag.
    tag.value = inputValue;

   // Inposto la lunghezza massima dell'input
   if(inputLength > 0)
    tag.setAttribute("maxlength", inputLength);

    // Scelgo se disabilitarlo o meno.
    if(disable)
      tag.disabled = true;
    else
      tag.disabled = false;

    return tag;
  },

  tagTEXTAREA: function(taClass, taId, taName, taValue, taRows, taCols, disable)
  {
    // Creo l'oggetto nel documento.
    var tag = document.createElement("textarea");

    // Se è presente la classe, la inserisco.
    if(taClass != "") 
      tag.className = taClass;

    // Se è presente l'id lo inserisco.
    if(taId != "") 
      tag.setAttribute("id",taId);

    // Se è presente name lo inserisco.
    if(taName != "") 
      tag.setAttribute("name",taName);

    // Scrivo il value all'interno del tag.
    tag.value = taValue;

   // Inposto il numero di colonne
   if(taCols > 0)
    tag.setAttribute("cols", taCols);
   else
    tag.setAttribute("cols", "");

   // Inposto il numero di righe
   if(taRows > 0)
    tag.setAttribute("rows", taRows);
   else
    tag.setAttribute("rows", "");

    // Scelgo se disabilitarlo o meno.
    if(disable)
      tag.disabled = true;
    else
      tag.disabled = false;

    return tag;
  },

  tagLABEL: function(labelClass, labelId, labelFor)
  {
    // Creo l'oggetto nel documento.
    var tag = document.createElement("label");

    // Se è presente la classe, la inserisco.
    if(labelClass != "") 
      tag.className = labelClass;

    // Se è presente l'id lo inserisco.
    if(labelId != "") 
      tag.setAttribute("id",labelId);

    // Se è presente il for lo inserisco.
    if(labelFor != "") 
      tag.setAttribute("for",labelFor);

    return tag;
  },

  tagFORM: function(formClass, formId, formMethod, formAction)
  {
    // Creo l'oggetto nel documento.
    var tag = document.createElement("form");

    // Se è presente la classe, la inserisco.
    if(formClass != "") 
      tag.className = formClass;

    // Se è presente l'id lo inserisco.
    if(formId != "") 
      tag.setAttribute("id",formId);

    // Setto l'attributo 'method' del form, se non c'è 'post' di default.
    if(formMethod != "") 
      tag.setAttribute("method", formMethod);
    else
      tag.setAttribute("method", "post");

    // Setto l'attributo 'action'.
    tag.setAttribute("action", formAction);

    return tag;
  },

  tagFIELDSET: function(fieldClass, fieldId)
  {
    var tag = document.createElement("fieldset");

    // Se è presente la classe, la inserisco.
    if(fieldClass != "") 
      tag.className = fieldClass;

    // Se è presente l'id lo inserisco.
    if(fieldId != "") 
      tag.setAttribute("id",fieldId);

    return tag;
  },

  tagLEGEND: function(legendClass, legendId, legendText)
  {
    var tag = document.createElement("legend");

    // Se è presente la classe, la inserisco.
    if(legendClass != "") 
      tag.className = legendClass;

    // Se è presente l'id lo inserisco.
    if(legendId != "") 
      tag.setAttribute("id",legendId);

    var legendTesto = document.createTextNode(legendText);
    tag.appendChild(legendTesto);

    return tag;
  },

  tagTD: function(tdClass, tdId, colspan, rowspan)
  {
    // Creo l'oggetto nel documento.
    var tag = document.createElement("td");
    // Se è presente la classe, la inserisco.
    if(tdClass != "") 
      tag.className = tdClass;
    // Se è presente l'id lo inserisco.
    if(tdId != "") 
      tag.setAttribute("id",tdId);
    // Se è presente il numero di colonne da unire lo inserisco.
    if(colspan > 0) 
      tag.setAttribute("colspan",colspan);
    // Se è presente il numero di righe da unire lo inserisco.
    if(rowspan > 0) 
      tag.setAttribute("rowspan",colspan);
    return tag;
  },
  
  truncateNode: function(node)
  {
    for(var j = (node.childNodes.length - 1); j > -1 ; j--)
    {
      node.removeChild(node.childNodes[j]);
    }
  }
};

