
//class HTMLGenerator
function HTMLGenerator(array, prefix, templateImgDir, debug)
{
	this.array		= array;
	this.prefix		= prefix;
	this.templateImgDir	= templateImgDir;
	this.debug		= debug;

	////////////////////////////////////////////////////////////
	////////////////DATA CONTAINER FUNCTIONS////////////////////
	////////////////////////////////////////////////////////////
	this.getCleanContainer = function ()
	{
		return this.array[this.prefix+"clean"];
	};

	//to get type attribute
	//can be:
	//listTable, msg, form
	this.getContentType = function (indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"type"];
	};

	//to get value attribute
	this.getValue = function (indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"value"];
	};
	
	//to get id attribute
	//this identify who div we rewrite
	this.getContentId = function (indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"id"];
	};

	//to get style attribute
	this.getContentStyle = function (indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"style"];
	};

	//to get parent id
	this.getContentParent = function (indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"parent"];
	};

	this.getContentParentStyle = function (indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"parentStyle"];
	};

	//to get title id
	this.getContentTitle = function (indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"title"];
	};

	////////////////////////////////////////////////////////////
	///////////////////LIST TABLE FUNCTIONS/////////////////////
	////////////////////////////////////////////////////////////
	//to get editable attribute
	this.getEditable = function (indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"editable"];
	};

	this.getComp = function(indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"comp"];
	};

	this.getOtherLink = function(indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"other"];
	};

	//to get style attribute
	this.getHeadListStyle = function (indexContent)
	{
		return this.array["data"][indexContent]["content"][0][this.prefix+"style"];
	};

	//to make the head list talbe
	this.makeHeadList = function (indexContent)
	{
		var from = 0;
		var editable = this.getEditable(indexContent);
		html	= "\n<!-- Generate by makeHeadList functions from array2html.js files -->\n";
		html	+= "<tr class='"+this.getHeadListStyle(indexContent)+"'>\n";
		cols	= this.array["data"][indexContent]["content"][0]["headList"]["col"];
		if ((editable == 3)) from = 1;
		for (var i = from; i < size(cols); i++)
			html += "<td>"+cols[i]+"</td>\n";

		if ( (editable < 4) && (editable > 0) )
			html += "<td></td>\n";

		html += "</tr>\n";

		return html;
	};

	//to get style attribute
	this.getRowStyle = function (indexContent,indexRow)
	{
		if (indexRow > 0)
			return this.array["data"][indexContent]["content"][indexRow][this.prefix+"style"];
	};

	//to make the list talbe
	this.makeList = function (indexContent)
	{
		var editable = this.getEditable(indexContent);
		var from = 0;
		html	= "\n<!-- Generate by makeList functions from array2html.js files -->\n";
		html	+= "<table class='"+this.getContentStyle(indexContent)+"'>\n";
		html	+= this.makeHeadList(indexContent);
		rows	= this.array["data"][indexContent]["content"];
		for (var i = 1; i < size(rows); i++)
		{
			html	+= "<tr class='"+this.getRowStyle(indexContent,i)+"'>\n";
			cols	= rows[i]["row"]["col"];

			if ( (editable < 3) && (editable > 0) )
			{
				rand = Math.random();
				html += "<td><a id='"+cols[0]+"_"+rand+"' url='index.php?comp="+this.getComp(indexContent)+"&action=form&id="+cols[0]+"&ajaxType=embedded' ajaxType='embedded' divTagDestiny='container' href='javascript: void(0);' onfocus='javascript:evalLink(\""+cols[0]+"_"+rand+"\");'>"+cols[0]+"</a></td>\n";
				from = 1;
			}
			else if ((editable == 3)) from = 1;

			for (var j = from; j < size(cols); j++)
			{
				rand = Math.random();
				if ( (j == 1) && (editable == 5) )
					html += "<td><a id='"+cols[0]+"_"+rand+"' url='index.php?comp="+this.getComp(indexContent)+"&action=view&id="+cols[0]+"&ajaxType=embedded' ajaxType='embedded' divTagDestiny='container' href='javascript: void(0);' onfocus='javascript:evalLink(\""+cols[0]+"_"+rand+"\");'>"+cols[j]+"</a></td>\n";
				else
					html += "<td>"+cols[j]+"</td>\n";
			}

			if ( (editable < 4) && (editable > 1) )
			{
				rand = Math.random();
				html += "<td align='left' width='70%'><a id='"+cols[0]+"_"+rand+"' url='index.php?comp="+this.getComp(indexContent)+"&action=delete&id="+cols[0]+"&ajaxType=embedded&"+this.getOtherLink(indexContent)+"' ajaxType='embedded' divTagDestiny='"+this.getContentId(indexContent)+"' href='javascript: void(0);' onfocus='javascript:evalLink(\""+cols[0]+"_"+rand+"\");'><img src='"+this.templateImgDir+"/error.png' border='0'></a></td>\n";
			}

			html += "</tr>\n"
		}
		html	+= "</table>\n";

		return html;
	};

	///////////////////////////////////////////////////////////
	///////////////////LIST TREE FUNCTIONS/////////////////////
	///////////////////////////////////////////////////////////
	this.getTreeName = function (indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"id"];
	};

	this.getTreeAllowHandled = function (indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"allowHandled"];
	};


	this.getTreeAllowComment = function (indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"allowComment"];
	};

	
	this.getTreeAllowCollapse = function (indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"allowCollapse"];
	};

	this.getTreeStyle = function (indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"style"];
	};

	this.getTreeCollapsed = function (indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"collapsed"];
	};

	this.getComponent = function (indexContent)
	{
		if (this.array["data"][indexContent][this.prefix+"component"])
			return this.array["data"][indexContent][this.prefix+"component"];
		else
			return '';
	};

	this.getAction = function (indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"action"];
	};

	this.getOther = function (indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"other"];
	};

	this.getUrl = function (indexContent)
	{
		return this.array["data"][indexContent][this.prefix+"url"];
	};

	this.makeTree = function (indexContent)
	{
		html	= "\n<!-- Generate by makeTree functions from array2html.js files -->\n";
		html	+= "<ul id='"+this.getTreeName(indexContent)+"_ul' ";
		html	+= " style='"+this.getTreeStyle(indexContent)+"' ";
		
		if (this.getTreeAllowCollapse(indexContent) == 1)
		{
			html	+= " onmouseover='javascript: treeList = new Tree(\""+this.getTreeName(indexContent)+"_ul\",\""+this.templateImgDir+"\");' >\n";
		} 
		else 
			html	+= " >\n";

		indexFrom = ((this.getTreeAllowCollapse(indexContent) == 1) || (this.getContentTitle(indexContent)!=''))?0:1;
		uls	= this.array["data"][indexContent]["content"];
		for (var i = indexFrom; i < size(uls); i++)
		{

			if (!uls[i])
				lis	= uls["ul"]["li"];
			else
				lis	= uls[i]["ul"]["li"];
			if (i == 0)
			{
				html	+= "<li class=\"first\">";
				if (this.getTreeAllowCollapse(indexContent) == 1)
					html	+= "<div class='clickeableHeader' onclick=\"javascript: treeList.showHide('','');\">";

				html	+= "<div class='defaultTitle'>"+this.getContentTitle(indexContent)+"</div>\n";

				if (this.getTreeAllowCollapse(indexContent) == 1)
					html	+= "</div>";

				if ((this.getTreeAllowCollapse(indexContent) == 1) || (this.getTreeAllowHandled(indexContent) > 0))
				{
					//if allow handled then insert collapse image and add showHide event
					if (this.getTreeAllowComment(indexContent) == 1)
					{
						id	= Math.random();
						html	+= " <a id='"+id+"' url='index.php?comp="+this.getComponent(indexContent)+"&action=form&subAction=comment&ajaxType=popUp' ajaxType='popUp' divtagdestiny='' href='javascript: void(0);' onfocus='javascript:evalLink(\""+id+"\");'><img border='0' src='"+this.templateImgDir+"/comment.png'></a>\n"
					}

					if (this.getTreeAllowHandled(indexContent) == 1)
					{
						id	= Math.random();
						html	+= " <a id='"+id+"' component='"+this.getComponent(indexContent)+"' action='"+this.getAction(indexContent)+"' other='"+this.getOther(indexContent)+"' url='index.php?comp="+this.getComponent(indexContent)+"&action=form&ajaxType=popUp&"+this.getOther(indexContent)+"' ajaxType='popUp' divtagdestiny='' href='javascript: void(0);' onfocus='javascript:evalLink(\""+id+"\");'><img border='0' src='"+this.templateImgDir+"/add.png'></a>\n"
					}
					if (this.getTreeAllowHandled(indexContent) == 10)
					{
						id	= Math.random();
						html	+= " <a id='"+id+"' component='"+this.getComponent(indexContent)+"' action='"+this.getAction(indexContent)+"' other='"+this.getOther(indexContent)+"' url='index.php?comp="+this.getComponent(indexContent)+"&action=form&ajaxType=popUp&"+this.getOther(indexContent)+"' ajaxType='popUp' divtagdestiny='' href='javascript: void(0);' onfocus='javascript:evalLink(\""+id+"\");'><img border='0' src='"+this.templateImgDir+"/comment.png'></a>\n"
					}
					if (this.getTreeAllowHandled(indexContent) == 2)
					{
						idForm	= Math.random();
						//html	+= " <img id='"+idForm+"Image' border='0' src='"+this.templateImgDir+"/edit.png' onmousedown='javascript: treeList.showForm(\""+idForm+"\",\""+idForm+"Image\");'>\n";
						html	+= "  <a id='"+idForm+"link' href='javascript: void(0);'  onmousedown='javascript: treeList.showForm(\""+idForm+"\",\""+idForm+"Image\");'><img id='"+idForm+"Image' border='0' src='"+this.templateImgDir+"/edit.png'></a>\n";
					}
					if (this.getTreeAllowHandled(indexContent) == 3)
					{
						idForm	= Math.random();
						//html	+= " <img id='"+idForm+"Image' border='0' src='"+this.templateImgDir+"/edit.png' onmousedown='javascript: treeList.showForm(\""+idForm+"\",\""+idForm+"Image\");'>\n";
						html	+= "  <a id='"+idForm+"link' href='javascript: void(0);'  onmousedown='javascript: treeList.showForm(\""+idForm+"\",\""+idForm+"Image\");'><img id='"+idForm+"Image' border='0' src='"+this.templateImgDir+"/save.png'></a>\n";
					}
	
					url = this.getUrl(indexContent);
					if ((url != "")&&(typeof(url) != "undefined"))
					{
						id	= Math.random();
						html	+= " <a id='"+id+"' component='' dims='250 200' action='asignTo' other='' url='"+url+"&ajaxType=popUp' ajaxType='popUp' divtagdestiny='' href='javascript: void(0);' onfocus='javascript:evalLink(\""+id+"\");'><img border='0' src='"+this.templateImgDir+"/assignto.png'></a>\n"
					}
	
					//if allow collapse tree
					if (this.getTreeAllowCollapse(indexContent) == 1)
					{
						if (this.getTreeCollapsed(indexContent) == 1)
							html	+= "<img class='collapse_img' id='imgTreeShowHide"+this.getTreeName(indexContent)+"_ul' border='0' src='"+this.templateImgDir+"/expand.png' onclick=\"javascript: treeList.showHide('','');\">\n"
						else
							html	+= "<img class='collapse_img' id='imgTreeShowHide"+this.getTreeName(indexContent)+"_ul' border='0' src='"+this.templateImgDir+"/collapse.png' onclick=\"javascript: treeList.showHide('','');\">\n"
					}
				}
				else
				{
					//empty div to make the first li tall enough in case no other content is loaded
					html += "<div style='height: 25px;'>&nbsp;</div>\n";
				}	
				html	+= "</li>\n";
			}

			if (this.getTreeCollapsed(indexContent) == 1)
				html	+= "<li class=\"eachcomment\" style='display:none;'>\n";
			else
				html	+= "<li class=\"eachcomment\">\n";


			if (this.getTreeAllowHandled(indexContent) == 1 || this.getTreeAllowHandled(indexContent) == 10)
			{
				id	 = Math.random();
				html	+= "<a id='"+id+"' component='"+this.getComponent(indexContent)+"' action='"+this.getAction(indexContent)+"' other='"+this.getOther(indexContent)+"' url='index.php?comp="+this.getComponent(indexContent)+"&action=form&id="+lis[0]+"&ajaxType=popUp&"+this.getOther(indexContent)+"' ajaxType='popUp' divtagdestiny='' href='javascript: void(0);' onfocus='javascript:evalLink(\""+id+"\");'><img border='0' src='"+this.templateImgDir+"/edit.png'></a>\n";
				html	+= "<ul>\n";
			}

			else if(this.getTreeAllowHandled(indexContent) >= 2)
			{
				html	+= "<form name='"+idForm+"' ";
				html	+= "id='"+idForm+"' ";
				html	+= "actionForm='index.php' ";
				html	+= "action='#' ";
				html	+= "divTagDestiny='"+this.getTreeName(indexContent)+"' ";
				html	+= "class='defaultForm' onmouseover='javascript: evalForm(\""+idForm+"\")'>\n";
				html	+= "<input name='comp' id='comp' type='hidden' value='"+this.getComponent(indexContent)+"'>\n";
				html	+= "<input name='action' id='action' type='hidden' value='"+this.getAction(indexContent)+"'>\n";
				html	+= "<input name='id' type='hidden' value='"+lis[0]+"'>\n";
				html	+= "<input name='ajaxType' id='ajaxType' type='hidden' value='embedded'>\n";
				html	+= "<input name='ajaxDiv' id='ajaxDiv' type='hidden' value='"+this.getTreeName(indexContent)+"'>\n";
				html	+= "<ul>\n";
			}
			else
			{
				html	+= "<ul>\n";
			}
			for (var j = 0; j < size(lis); j++)
				html += "<li class=\"row"+j+"\">"+lis[j]+"</li>\n";
			html += "</ul>\n";

			if(this.getTreeAllowHandled(indexContent) >= 2)
				html += "</form>\n";

			html += "</li>\n";
			if (!uls[i]) break;
		}
		if (this.getTreeCollapsed(indexContent) == 1)
			html	+= "<li class=\"eachcomment\" style=\"clear: both; height:1px; overflow:hidden; border: 0; padding:0; display:none;\"></li>\n";
		else
			html	+= "<li class=\"eachcomment\" style=\"clear: both; height:1px; overflow:hidden; border: 0; padding:0;\"></li>\n";
		html	+= "</ul>\n";
		return html;
	};

	////////////////////////////////////////////////////////////
	////////////////////MESSAGES FUNCTIONS//////////////////////
	////////////////////////////////////////////////////////////
	//to get style attribute
	this.getTitleStyle = function (indexContent)
	{
		return this.array["data"][indexContent]["content"][this.prefix+"style"];
	};

	//to get style attribute
	this.getMsgStyle = function (indexContent)
	{
		return this.array["data"][indexContent]["content"][this.prefix+"style"];
	};

	//to make the message content
	this.makeMsg = function (indexContent)
	{
		html	= "\n<!-- Generate by makeMsg functions from array2html.js files -->\n";
		html	+= "<div class='"+this.getTitleStyle(indexContent)+"'>\n";
		html	+= this.array["data"][indexContent]["content"]["title"]["title"];
		html	+= "</div>\n";
		html	+= "<div class='"+this.getMsgStyle(indexContent)+"'>\n";
		html	+= this.array["data"][indexContent]["content"]["msg"]["msg"];
		html	+= "</div>\n";

		return html;
	};

	////////////////////////////////////////////////////////////
	///////////////////////FORM FUNCTIONS///////////////////////
	////////////////////////////////////////////////////////////
	//to get name attribute
	this.getFormName = function (indexContent)
	{
		return this.array["data"][indexContent]["content"][this.prefix+"name"];
	};

	//get destiny for the action result
	this.getFormDivTagDestiny = function (indexContent)
	{
		return this.array["data"][indexContent]["content"][this.prefix+"divTagDestiny"];
	};

	this.getFormClosePopUp = function (indexContent)
	{
		return this.array["data"][indexContent]["content"][this.prefix+"closePopUp"];
	};

	//to get action attribute
	//this allow know where must do the post action
	this.getFormAction = function (indexContent)
	{
		return this.array["data"][indexContent]["content"]["form"]["action"]["action"];
	};

	//to get style attribute
	this.getFormStyle = function (indexContent)
	{
		return this.array["data"][indexContent]["content"][this.prefix+"style"];
	};

	//to get name attribute
	this.getInputName = function (indexContent, indexInput)
	{
		return this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix+"name"];
	};

	//to get label attribute
	this.getInputLabel = function (indexContent, indexInput)
	{
		return this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix+"label"];
	};

	//to get value attribute
	this.getInputValue = function (indexContent, indexInput)
	{
		return this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix+"value"];
	};

	//to get type attribute
	this.getInputType = function (indexContent, indexInput)
	{
		return this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix+"type"];
	};

	//to get type attribute
	this.getInputStyle = function (indexContent, indexInput)
	{
		return this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix+"style"];
	};

	//to get dataType attribute
	this.getInputDataType = function (indexContent, indexInput)
	{
		return this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix+"dataType"];
	};

	//to get msg attribute
	this.getInputMsg = function (indexContent, indexInput)
	{
		return this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix+"msg"];
	};

	//to get checked attribute
	this.getInputChecked = function (indexContent, indexInput)
	{
		return this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix+"checked"];
	};

	//to get checked attribute
	this.getOptionChecked = function (indexContent, indexInput, indexOption)
	{
		try
		{
			if (this.array["data"][indexContent]["content"]["form"][indexInput]["input"][indexOption][this.prefix+"checked"] == 1)
				return "selected";
			return "";
		}
		catch(e)
		{
			if (this.array["data"][indexContent]["content"]["form"][indexInput]["input"][this.prefix+"checked"] == 1)
				return "selected";
			return "";
		}
	};

	this.getOptionId = function (indexContent, indexInput, indexOption)
	{
		try
			{return this.array["data"][indexContent]["content"]["form"][indexInput]["input"][indexOption][this.prefix+"id"];}
		catch(e)
			{return this.array["data"][indexContent]["content"]["form"][indexInput]["input"][this.prefix+"id"];}
	};

	//to get function attribute
	this.getInputFunction = function (indexContent, indexInput)
	{
		return this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix+"function"];
	};

	//to get function parameters attribute
	this.getInputFunctionParameters = function (indexContent, indexInput)
	{
		return this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix+"functionParameters"];
	};

	//to get event attribute
	this.getInputEvent = function (indexContent, indexInput)
	{
		return this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix+"event"];
	};

	this.getInputGroupBy = function (indexContent, indexInput)
	{
		return this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix+"groupBy"];
	};

	this.getAutocompleteUrl = function (indexContent, indexInput)
	{
		return this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix+"url"];
	};

	this.getSelectRow = function (indexContent, indexInput)
	{
		return this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix+"row"];
	};

	this.getAllowDragDrop = function (indexContent, indexInput)
	{
		return this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix+"allowDragDrop"];
	};

	this.makeClasicInput = function (indexContent, indexInput)
	{
		html	= "\n<!-- Generate by makeClasicInput functions from array2html.js files -->\n";
		if (this.getInputType(indexContent, indexInput) != 'hidden')
		{
			styleClass = this.getInputStyle(indexContent, indexInput);
			if ((styleClass == 'undefined') || (styleClass == '') || (!styleClass)) {
				html += "<p ";
				html += " style='" + this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix + "style"] + "' ";
				html += " id='" + this.getInputName(indexContent, indexInput) +"_p' ";
				html += " >";
			}
			else 
			{
				html += "<p class='" + styleClass + "' ";
				html += " style='" + this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix + "style"] + "' ";
				html += " id='" + this.getInputName(indexContent, indexInput) +"_p' ";
				html += " >";				
			}
			html	+= "<label for='"+this.getInputName(indexContent, indexInput)+"'>";
			html	+= this.getInputLabel(indexContent, indexInput)+"</label>";
			//end of serfeado.
		}
		html	+= "<input type='"+this.getInputType(indexContent, indexInput)+"' ";
		html	+= " autocomplete='off' ";
		html	+= " name='"+this.getInputName(indexContent, indexInput)+"' ";
		html	+= " id='"+this.getInputName(indexContent, indexInput)+"' ";
		html	+= " value='"+this.getInputValue(indexContent, indexInput)+"' ";
		
		if (this.getInputGroupBy(indexContent, indexInput).indexOf('autocomplete') != -1)
		{
			html	+= " divTagDestiny='"+this.getInputName(indexContent, indexInput)+"DivList' ";
			html	+= " url='"+this.getAutocompleteUrl(indexContent, indexInput)+"' ";
		}

		if (this.getInputChecked(indexContent, indexInput) == "1")
			html	+= " checked ";

		func = this.getInputFunction(indexContent, indexInput);
		intEvent = this.getInputEvent(indexContent, indexInput);
		if ((!func) && (intEvent))
		{
			html	+= " onfocus='javascript: evalForm(\""+this.getFormName(indexContent)+"\")' " + intEvent + "='makeSubmit(\""+this.getFormName(indexContent)+"\")' ";
		}
		else if((func) && (intEvent))
		{
			html	+= intEvent + "='" + func + "(\"" + this.getInputFunctionParameters(indexContent, indexInput) + "\"); evalForm(\""+this.getFormName(indexContent)+"\");" +"' ";
		}

		if ((this.getInputType(indexContent, indexInput) != "button")&&(this.getInputType(indexContent, indexInput) != "submit"))
			html	+= " dataType='"+this.getInputDataType(indexContent, indexInput)+"' msg='"+this.getInputMsg(indexContent, indexInput)+"' onfocus='javascript: evalForm(\""+this.getFormName(indexContent)+"\")'>";
		else
			html	+= " onfocus='javascript: evalForm(\""+this.getFormName(indexContent)+"\")' >";
			//html += " >";
		if (this.getInputType(indexContent, indexInput) != 'hidden') {
			html	+= "</p>\n";
		} else {
			html	+= "\n";
		}
		return html;
	};

	this.makeTextAreaInput = function(indexContent, indexInput)
	{
		html	= "\n<!-- Generate by makeTextAreaInput functions from array2html.js files -->\n";
		//serfeado: changed by Gonza to use label tags.
		//html	+= "<p>"+this.getInputLabel(indexContent, indexInput)+" ";
		styleClass = this.getInputStyle(indexContent, indexInput);
		if ((styleClass == 'undefined') || (styleClass == '') || (!styleClass)) {
			html += "<p ";
			html += " style='" + this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix + "style"] + "' ";
			html += " id='" + this.getInputName(indexContent, indexInput)+"_p' ";
			html += " >";
		}
		else 
		{
			html += "<p class='" + styleClass + "' ";
			html += " style='" + this.array["data"][indexContent]["content"]["form"][indexInput][this.prefix + "style"] + "' ";
			html += " id='" + this.getInputName(indexContent, indexInput)+"_p' ";
			html += " >";				
		}
		html	+= "<label for='"+this.getInputName(indexContent, indexInput)+"'>";
		html	+= this.getInputLabel(indexContent, indexInput)+"</label>";
		//end of serfeado.
		html	+= "<textarea type='"+this.getInputType(indexContent, indexInput)+"' ";
		html	+= " name='"+this.getInputName(indexContent, indexInput)+"' ";
		html	+= " id='"+this.getInputName(indexContent, indexInput)+"'>";
		html	+= this.getInputValue(indexContent, indexInput);
		html	+= "</textarea>\n";
		html	+= "</p>\n";

		return html;
	};

	this.makeSelectInput = function (indexContent, indexInput)
	{
		html	= "\n<!-- Generate by makeSelectInput functions from array2html.js files -->\n";
		//serfeado: changed by Gonza to use label tags.
		//html	+= "<p>"+this.getInputLabel(indexContent, indexInput)+" ";
		styleClass = this.getInputStyle(indexContent, indexInput);
		if ( (styleClass == 'undefined') || (styleClass == '') || (!styleClass) )
			html	+= "<p>";
		else
			html	+= "<p class='"+styleClass+"'>";
		html	+= "<label for='"+this.getInputName(indexContent, indexInput)+"'>";
		html	+= this.getInputLabel(indexContent, indexInput)+"</label>";
		//end of serfeado.
		html	+= "\n<select ";
		html	+= " name='"+this.getInputName(indexContent, indexInput)+"' ";
		html	+= " size='"+this.getSelectRow(indexContent, indexInput)+"' ";
		html	+= " id='"+this.getInputName(indexContent, indexInput)+"' ";
		html	+= " allowDragDrop='"+this.getAllowDragDrop(indexContent, indexInput)+"' ";
		html	+= " dataType='"+this.getInputDataType(indexContent, indexInput)+"' msg='"+this.getInputMsg(indexContent, indexInput)+"' ";

		func = this.getInputFunction(indexContent, indexInput);
		intEvent = this.getInputEvent(indexContent, indexInput);
		if ((!func) && (intEvent))
		{
			html	+= intEvent +" ='javascript: makeSubmit(\""+this.getFormName(indexContent)+"\");' ";
		}
		else if((func) && (intEvent))
		{
			if (this.getInputFunctionParameters(indexContent, indexInput)=="this")
				html	+= intEvent + "='" + func + "(" + this.getInputFunctionParameters(indexContent, indexInput) + ")" +"' ";
			else
				html	+= intEvent + "='" + func + "(\"" + this.getInputFunctionParameters(indexContent, indexInput) + "\")" +"' ";
		}
		html	+= ">\n";

		opts = this.array["data"][indexContent]["content"]["form"][indexInput]["input"];
		for (var j = 0; j < size(opts); j++)
		{
			try
				{html	+= "\n<option value='"+this.getOptionId(indexContent, indexInput, j)+"'  "+this.getOptionChecked(indexContent, indexInput, j)+">"+opts[j]["option"]["option"]+"</option>\n";}
			catch(e)
				{html	+= "\n<option value='"+this.getOptionId(indexContent, indexInput, j)+"'  "+this.getOptionChecked(indexContent, indexInput, j)+">"+opts["option"]["option"]+"</option>\n"; j = size(opts);}
		}


		html	+= "</select>\n";
		html	+= "</p>\n";

		return html;
	};

	//to make form content
	this.makeForm = function (indexContent)
	{
		htmlTemp	= "\n<!-- Generate by makeForm functions from array2html.js files -->\n";
		temp = document.createElement('div');
		formObj = document.createElement('form');
		temp.appendChild(formObj);
		formObj.setAttribute('name',this.getFormName(indexContent));
		formObj.setAttribute('id',this.getFormName(indexContent));
		formObj.setAttribute('actionForm',this.getFormAction(indexContent));
		formObj.setAttribute('action','#');
		formObj.setAttribute('divTagDestiny',this.getFormDivTagDestiny(indexContent));
		formObj.setAttribute('closePopUp',this.getFormClosePopUp(indexContent));
		formObj.setAttribute('method','POST');
		formObj.className = this.getFormStyle(indexContent);

		tempChild = document.createElement('div');
		tempChild.setAttribute('id', '');

		inputs	= this.array["data"][indexContent]["content"]["form"];
		for (var i = 0; i < (size(inputs) - 1); i++)
		{
			switch (this.getInputType(indexContent, i))
			{
				case "select":
				{
					htmlInput	= this.makeSelectInput(indexContent, i);
				}
				break;
				case "textarea":
				{
					htmlInput	= this.makeTextAreaInput(indexContent, i);
				}
				break;
				default:
				{
					htmlInput	= this.makeClasicInput(indexContent, i);
				}
				break
			}
			if (this.getInputGroupBy(indexContent, i))
			{
			
				if (this.getInputGroupBy(indexContent, i))
				{
					if (this.getInputGroupBy(indexContent, i) != tempChild.id)
					{
						tempChild = document.createElement('div');
						formObj.appendChild(tempChild);
						if (this.getInputGroupBy(indexContent, i).indexOf('autocomplete') != -1)
							tempChild.className = 'autocomplete';
						else
							tempChild.setAttribute('id', this.getInputGroupBy(indexContent, i));
					}
				}

				allInnerHtml = tempChild.innerHTML + htmlInput;
				if (this.getInputGroupBy(indexContent, i).indexOf('autocomplete') != -1)
					allInnerHtml += "<div id='"+this.getInputName(indexContent, i)+"DivList'></div>";

				tempChild.innerHTML = allInnerHtml;
			}
			else
				formObj.innerHTML = formObj.innerHTML + htmlInput;
		}
		htmlTemp	+= temp.innerHTML;
		return htmlTemp;
	};

	////////////////////////////////////////////////////////////
	////////////////PAGER CONTAINER FUNCTIONS///////////////////
	////////////////////////////////////////////////////////////
	//get pagination id
	this.getPaginationId = function (indexContent, subSectionIndex)
	{
		return this.array["data"][indexContent]["content"][subSectionIndex][this.prefix+"id"];
	};

	//get pagination style
	this.getPaginationStyle = function (indexContent, subSectionIndex)
	{
		return this.array["data"][indexContent]["content"][subSectionIndex][this.prefix+"style"];
	};

	//get pagination link id
	this.getPaginationLinkId = function (indexContent, subSectionIndex, subSectionName, indexLink)
	{
		return  this.array["data"][indexContent]["content"][subSectionIndex][subSectionName][indexLink][this.prefix+"id"];
	};

	//get pagination link id
	this.getPaginationLinkUrl = function (indexContent, subSectionIndex, subSectionName, indexLink)
	{
		return  this.array["data"][indexContent]["content"][subSectionIndex][subSectionName][indexLink][this.prefix+"url"];
	};

	//get pagination link divTagDestiny
	this.getPaginationLinkDivTagDestiny = function (indexContent, subSectionIndex, subSectionName, indexLink)
	{
		return  this.array["data"][indexContent]["content"][subSectionIndex][subSectionName][indexLink][this.prefix+"divTagDestiny"];
	};

	//get pagination link name
	this.getPaginationLinkValue = function (indexContent, subSectionIndex, subSectionName, indexLink)
	{
		return  this.array["data"][indexContent]["content"][subSectionIndex][subSectionName][indexLink][this.prefix+"value"];
	};

	//make tag a for each element inside browserLink or footerLink
	this.makePaginationLink = function(indexContent, subSectionIndex, subSectionName, indexLink)
	{
		html	= "\n<!-- Generate by makePaginationLink functions from array2html.js files -->\n";
		if (this.getPaginationLinkId(indexContent, subSectionIndex, subSectionName, indexLink) != "disabled")
		{
			html	+= "<a id='"+this.getPaginationLinkId(indexContent, subSectionIndex, subSectionName, indexLink)+"'";
			html	+= " url='"+this.getPaginationLinkUrl(indexContent, subSectionIndex, subSectionName, indexLink)+"&ajaxType=embedded'";
			html	+= " ajaxType='embedded' divTagDestiny='"+this.getPaginationLinkDivTagDestiny(indexContent, subSectionIndex, subSectionName, indexLink)+"'";
			html	+= " href='javascript: void(0);'";
			html	+= " onmouseover=\"javascript:evalLink('"+this.getPaginationLinkId(indexContent, subSectionIndex, subSectionName, indexLink)+"');\" >";
			html	+= this.getPaginationLinkValue(indexContent, subSectionIndex, subSectionName, indexLink) + "</a>\n";
		}
		else
		{
			html	+= this.getPaginationLinkValue(indexContent, subSectionIndex, subSectionName, indexLink);
		}

		return html;
	};

	//make div for browserLink or footerLink
	this.makePaginationSeccionLink = function (indexContent, subSectionIndex, subSectionName)
	{
		html		= "<div id='"+this.getPaginationId(indexContent, subSectionIndex)+"' style='"+this.getPaginationStyle(indexContent, subSectionIndex)+"'\n";
		
		linksElements	= this.array["data"][indexContent]["content"][subSectionIndex][subSectionName];
		for (var i = 0; i < size(linksElements); i++)
			html	+= this.makePaginationLink(indexContent, subSectionIndex, subSectionName, i);

		html	+= "</div>\n";

		return html;
	};

	//make pagination
	this.makePagination = function (indexContent)
	{
		html	= "\n<!-- Generate by makePagination functions from array2html.js files -->\n";
		html	+= this.makePaginationSeccionLink (indexContent, 0, "browserLink");
		html	+= this.makePaginationSeccionLink (indexContent, 1, "footerLink");

		return html;
	};

	////////////////////////////////////////////////////////////
	////////////////PUREHTML CONTAINER FUNCTIONS////////////////
	////////////////////////////////////////////////////////////
	//to get pure html content
	this.getPureHtmlContent = function (indexContent)
	{
		return this.array["data"][indexContent]["content"][this.prefix+"value"];
	};

	//to generate the content type pureHtml
	this.makePureHtml = function (indexContent)
	{
		html	= "\n<!-- Generate by makePureHtml functions from array2html.js files -->\n";
		html	+= this.getPureHtmlContent(indexContent) + "\n";

		return html;
	};

	//generate all html content
	this.generateHtml = function (divByReference)
	{

		if (this.getCleanContainer() == 1)
			document.getElementById('container').innerHTML = "";

		var html	= "\n<!-- Generate by generateHtml functions from array2html.js files -->\n";

		contents = this.array["data"];
		var contentParent;
		var collapsedParent;
		for (var i = 0; i < size(contents); i++)
		{
			if (this.getContentId(i))
			{
				contentType	= this.getContentType(i);
				divTag		= document.getElementById(this.getContentId(i));

				if ( (!divTag) && (divByReference.id == 'mb_contents') )
				{
					divTag	= document.getElementById(divByReference.id);
					divTag.innetHTML = "";
				}

				wasDifferent = false;
				compareContentParent = document.getElementById(this.getContentParent(i));
				if ( ( (contentParent != compareContentParent) && (typeof(contentParent)!='undefined') ) || (contentParent = 'mb_contents'))
					wasDifferent = true;

				contentParent = document.getElementById(this.getContentParent(i));

				switch (contentType)
				{
					case "listTable":
					{
						html += this.makeList(i);
					}
					break;
					case "tree":
					{
						html += this.makeTree(i);
					}
					break;
					case "msg":
					{
						html += this.makeMsg(i);
					}
					break;
					case "form":
					{
						html += this.makeForm(i);
					}
					break;
					case "pagination":
					{
						html += this.makePagination(i);
					}
					break;
					case "pureHtml":
					{
						html += this.makePureHtml(i);
					}
					break;
					case "empty":
					{
						html += "";
						overload_end();
					}
					break;
					case "javascript":
					{
						if(this.getAction(i)=="alert")
						{
							alert(this.getValue(i).replace(/&#10;/g, "\n"));
						}
						else
						{
							eval(this.getAction(i)+"('"+this.getValue(i)+"');");
						}
					}
					break;
					case "javascriptGeneral":
					{
						eval(this.getAction(i)+";");
					}
					break;
					default:
					{
						html += "\n<div>There are not item to show</div>\n";
					}
					break;
				}

				if (!divTag)
				{
					divTag = document.createElement('div');
					divTag.setAttribute('id',this.getContentId(i));
					if ( (!contentParent) && (this.getContentParent(i)) )
					{
                        collapsedParent = false;
						contentParent = document.createElement('div');
						contentParent.setAttribute('id',this.getContentParent(i));
                        
                        if (this.getTreeCollapsed(i) == 1)
                            collapsedParent = true;
                        
						if ( this.getContentParentStyle(i) && (this.getContentParentStyle(i) != 'undefined') && (this.getContentParentStyle(i) != '') )
							contentParent.className = this.getContentParentStyle(i);
						document.getElementById('container').appendChild(contentParent);

						div = document.createElement('div');
						div.setAttribute('id',this.getContentParent(i)+"_div");

						if (contentType != "tree")
						{
							div.setAttribute('templateDir',this.templateImgDir);
// 							div.setAttribute('onmouseover',"javascript: treeList = new Tree('"+this.getContentParent(i)+"_div','"+this.templateImgDir+"')");
							div.onmouseover = function()
							{
								treeList = new Tree(this.getAttribute('id'), this.getAttribute('templateDir'));
							}
							subdiv = document.createElement('div');
							subdiv.className = "first";
// 							if (collapsedParent)
// 								subdiv.onclick = function(e){treeList.showHide("","");};

							subdivTextContent = "";
							if ( (contentType == "pureHtml") || (contentType == "listTable") || (contentType == "form") )
							{
								if (this.getTreeCollapsed(i) > -1){subdivTextContent += "<div class='clickeableHeader' onclick=\"javascript: treeList.showHide('','');\">";}

								subdivTextContent += "<div class='defaultTitle'>"+this.getContentTitle(i)+"</div>\n";

								if (this.getTreeCollapsed(i) > -1){subdivTextContent += "</div>";}
							}

							url = this.getUrl(i);
							if ((url != "")&&(typeof(url) != "undefined"))
							{
								id	= Math.random();
								subdivTextContent	+= " <a id='"+id+"' component='' action='asignTo' other='' url='"+url+"&ajaxType=popUp' ajaxType='popUp' divtagdestiny='' href='javascript: void(0);' onfocus='javascript:evalLink(\""+id+"\");'><img border='0' src='"+this.templateImgDir+"/assignto.png'></a>\n"
							}
		
							if (this.getTreeAllowComment(i) == 1)
							{
								id	= Math.random();
								subdivTextContent	+= " <a id='"+id+"' url='index.php?comp="+this.getComponent(i)+"&action=form&subAction=comment&ajaxType=popUp' ajaxType='popUp' divtagdestiny='' href='javascript: void(0);' onfocus='javascript:evalLink(\""+id+"\");'><img border='0' src='"+this.templateImgDir+"/comment.png'></a>\n"
							}

							
							if (this.getTreeCollapsed(i) == 1)
								subdivTextContent += "<img class='collapse_img' id='imgTreeShowHide"+this.getContentParent(i)+"_div' border='0' src='"+this.templateImgDir+"/expand.png' onclick=\"javascript: treeList.showHide('','');\">\n";
							else if (this.getTreeCollapsed(i) == 0)
								subdivTextContent += "<img class='collapse_img' id='imgTreeShowHide"+this.getContentParent(i)+"_div' border='0' src='"+this.templateImgDir+"/collapse.png' onclick=\"javascript: treeList.showHide('','');\">\n";
                            
							subdiv.innerHTML = subdivTextContent;
							div.appendChild(subdiv);
						}

						contentParent.appendChild(div);

						if (wasDifferent) wasDifferent = false;
					}

					if (contentParent)
					{
						subdiv = document.createElement('div');
						if (contentParent.id != 'mb_contents')
							subdiv.className = "eachElement";
						else
							subdiv.className = "";
						subdiv.appendChild(divTag);
						if (collapsedParent)
							subdiv.style.display = 'none';

						if ( wasDifferent )
							contentParent.appendChild(subdiv);
						else
							div.appendChild(subdiv);
					}
					else
						document.getElementById('container').appendChild(divTag);

				}
				divTag.style.display = 'none';
				divTag.innerHTML = html;
				html = "";
				if (divTag.id == 'subnav')
					subnavGenerator();
				if (this.getContentStyle(i))
					divTag.className = this.getContentStyle(i);

				divTag.style.display = 'block';
			}
		}
	};

}





