// JavaScript Document

var thisTool = 0;
var editTools = new Array();
var orderTools = new Array();
var slideTools = new Array();
var editToolType = 0;
var editToolId = 1;
var checkToolDel = 2;
var checkToolOrder = 3;
var editToolForm = 4; // forms
var editToolLink = 5; // links
var toolImgData = 6; // this sets where in the array the img data is
var toolVidData = 7; // this sets where in the array the img data is
var editToolObj = 9; // i just felt like it ^^
var txtDataReservoir = new Array();
var deleteWidth = 640; // must create a div to wrap the delete div in order to control width
var iframeWidth = 620; //deleteWidth - style padding of 20px
var iframeHeightImg = 210;
var iframeHeightVid = 270;
var editToolClass = 'editTool';
var txtLineSize = 75;
var txtLineSizeMini = '1" maxlength="3';
var actBorder = 1; //activate borders for most tables
var actAuxBorder = 0; //activate borders for auxiliary tables
var actFrameBorder = 0; //activate borders for iframes
var formatToolsTableWidth = '50%';
var formatToolsTableWidthTxt = '100%';
var formatToolsCellPadding = 1;
var insDiv; //just to be able to use it in editMenuBar
var editMenuBar0 = '\
<br />\
<table width="100%" border="' + actAuxBorder +  '" cellspacing="0" cellpadding="0">\
  <tr align="center">\
    <td><a href="javascript: addLine(\''; /* insDiv */ var editMenuBar1 = '\');">L&iacute;nea</a></td>\
    <td><a href="javascript: addParagraph(\''; /* insDiv */ var editMenuBar2 = '\');">P&aacute;rrafo</a></td>\
    <!-- <td><a href="javascript: addBr(\''; /* insDiv */ var editMenuBar3 = '\');">Salto</a></td> -->\
    <td><a href="javascript: addList(\''; /* insDiv */ var editMenuBar4 = '\');">Lista</a></td>\
    <td><a href="javascript: addImg(\''; /* insDiv */ var editMenuBar5 = '\');">Imagen</a></td>\
    <td><a href="javascript: addVid(\''; /* insDiv */ var editMenuBar6 = '\');">Video</a></td>\
    <td><a href="javascript: addGroup(\''; /* insDiv */ var editMenuBar7 = '\');">Grupo</a></td>\
  </tr>\
</table>\
<br />\
';
var txtFormatMenu0 = '\
		<tr>\
			<td>\
				Color\
				&nbsp;\
			</td>\
			<td>\
				<select name="'; /* idForm */ var txtFormatMenu1 = '" class="formatColor">\
					'; /* txtColorChoices */ var txtFormatMenu2 = '\
				</select>\
			</td>\
		</tr>\
		<tr>\
			<td>\
				Fuente\
				&nbsp;\
			</td>\
			<td>\
				<select name="'; /* idForm */ var txtFormatMenu3 = '" class="formatFont">\
					'; /* txtFontChoices */ var txtFormatMenu4 = '\
				</select>\
			</td>\
		</tr>\
		<tr>\
			<td>\
				Tama&ntilde;o\
				&nbsp;\
			</td>\
			<td>\
				<select name="'; /* idForm */ var txtFormatMenu5 = '" class="formatSize">\
					'; /* txtSizeChoices */ var txtFormatMenu6 = '\
				</select>\
			</td>\
		</tr>\
	</table>\
<br />\
	<label>\
		<input type="checkbox" name="'; /* idForm */ var txtFormatMenu7 = '" class="formatBold" value="bold" />\
		<b>Negrita</b>\
	</label>\
<br />\
	<label>\
		<input type="checkbox" name="'; /* idForm */ var txtFormatMenu8 = '" class="formatItalic" value="italic" />\
		<i>Cursiva</i>\
	</label>\
<br />\
	<label>\
		<input type="checkbox" name="'; /* idForm */ var txtFormatMenu9 = '" class="formatUnderline" value="underline" />\
		<u>Subrayado</u>\
	</label>\
';
var txtColorChoices = '\
<option value="yellow" class="txtColorChoices" style="color:yellow;">Amarillo</option>\
<option value="blue" class="txtColorChoices" style="color:blue;">Azul</option>\
<option value="navy" class="txtColorChoices" style="color:blue;">Azul Marino</option>\
<option value="teal" class="txtColorChoices" style="color:teal;">Azul Verdoso</option>\
<option value="white" class="txtColorChoices" style="color:white;">Blanco</option>\
<option value="aqua" class="txtColorChoices" style="color:aqua;">Celeste</option>\
<option value="coral" class="txtColorChoices" style="color:coral;">Coral</option>\
<option value="gray" class="txtColorChoices" style="color:gray;">Gris</option>\
<option value="fuchsia" class="txtColorChoices" style="color:fuchsia;">Fucsia</option>\
<option value="lime" class="txtColorChoices" style="color:lime;">Lima</option>\
<option value="maroon" class="txtColorChoices" style="color:maroon;">Marr&oacute;n</option>\
<option value="orange" class="txtColorChoices" style="color:orange;">Naranja</option>\
<option value="black" class="txtColorChoices" style="color:black;">Negro</option>\
<option value="olive" class="txtColorChoices" style="color:olive;">Oliva</option>\
<option value="silver" class="txtColorChoices" style="color:silver;">Plateado</option>\
<option value="purple" class="txtColorChoices" style="color:purple;">P&uacute;rpura</option>\
<option value="red" class="txtColorChoices" style="color:red;">Rojo</option>\
<option value="orangered" class="txtColorChoices" style="color:orangered;">Rojo Anaranjado</option>\
<option value="green" class="txtColorChoices" style="color:green;">Verde</option>\
<option value="" class="txtColorChoices" style="color:;" selected="selected"></option>\
';
var txtFontChoices = '\
<option value="Arial, Helvetica, sans-serif" class="txtFontChoices" style="font-family:Arial, Helvetica, sans-serif;">Arial</option>\
<option value="\'Times New Roman\', Times, serif" class="txtFontChoices" style="font-family:\'Times New Roman\', Times, serif;">Times New Roman</option>\
<option value="\'Courier New\', Courier, monospace" class="txtFontChoices" style="font-family:\'Courier New\', Courier, monospace;">Courier New</option>\
<option value="Georgia, \'Times New Roman\', Times, serif" class="txtFontChoices" style="font-family:Georgia, \'Times New Roman\', Times, serif;">Georgia</option>\
<option value="Verdana, Arial, Helvetica, sans-serif" class="txtFontChoices" style="font-family:Verdana, Arial, Helvetica, sans-serif;">Verdana</option>\
<option value="Geneva, Arial, Helvetica, sans-serif" class="txtFontChoices" style="font-family:Geneva, Arial, Helvetica, sans-serif;">Geneva</option>\
<option value="" class="txtFontChoices" style="font-family:;" selected="selected"></option>\
';
var txtSizeChoices = '\
<option value="xx-small" class="txtSizeChoices" style="font-size:small;">Diminuto</option>\
<option value="x-small" class="txtSizeChoices" style="font-size:small;">Muy Peque&ntilde;o</option>\
<option value="" class="txtSizeChoices" style="font-size:;" disabled="disabled"></option>\
<option value="small" class="txtSizeChoices" style="font-size:small;">Peque&ntilde;o</option>\
<option value="medium" class="txtSizeChoices" style="font-size:medium;">Mediano</option>\
<option value="large" class="txtSizeChoices" style="font-size:large;">Grande</option>\
<option value="" class="txtSizeChoices" style="font-size:;" disabled="disabled"></option>\
<option value="x-large" class="txtSizeChoices" style="font-size:large;">Muy Grande</option>\
<option value="xx-large" class="txtSizeChoices" style="font-size:large;">Enorme</option>\
<option value="" class="txtSizeChoices" style="font-size:;" selected="selected"></option>\
';
var toolOpacChoices = '\
<option value="1" class="toolOpacChoices" style="">100%</option>\
<option value="0.9" class="toolOpacChoices" style="">90%</option>\
<option value="0.8" class="toolOpacChoices" style="">80%</option>\
<option value="0.7" class="toolOpacChoices" style="">70%</option>\
<option value="0.6" class="toolOpacChoices" style="">60%</option>\
<option value="0.5" class="toolOpacChoices" style="">50%</option>\
<option value="0.4" class="toolOpacChoices" style="">40%</option>\
<option value="0.3" class="toolOpacChoices" style="">30%</option>\
<option value="0.2" class="toolOpacChoices" style="">20%</option>\
<option value="0.1" class="toolOpacChoices" style="">10%</option>\
<option value="0" class="toolOpacChoices" style="">0%</option>\
<option value="" class="toolOpacChoices" style="" selected="selected"></option>\
';
var toolTextAlignChoices = '\
<option value="center" class="toolTextAlignChoices" style="">Centrar</option>\
<option value="justify" class="toolTextAlignChoices" style="">Justificar</option>\
<option value="left" class="toolTextAlignChoices" style="">Izquierda</option>\
<option value="right" class="toolTextAlignChoices" style="">Derecha</option>\
<option value="" class="toolTextAlignChoices" style="" selected="selected"></option>\
';
var toolAniDiv0 = '\
<a href="javascript: '; /* objAniDiv */ var toolAniDiv1 = '.slideit()">'; /* linkAniDiv */ var toolAniDiv2 = '</a>\
<br />\
<br />\
<div id="'; /* divAniDiv */ var toolAniDiv3 = '" style="width:100%; height:100px; background-color:#FFFF99;">\
	<div style="padding:20px 20px 20px 20px;">'; /* content */ var toolAniDiv4 = '\
	</div>\
</div>\
';
var arrAniDiv = new Array();

function Morph(l, r, c, n) { // left, right, container, name
	var self = this;
	this.name = n;
	
	this.left = d.getElementById(l);
	this.right = d.getElementById(r);
	this.cont = d.getElementById(c);
	
	var leftWidth = this.left.offsetWidth;
	var leftHeight = this.left.offsetHeight;
	var rightWidth = this.right.offsetWidth;
	var rightHeight = this.right.offsetHeight;
	if( leftWidth <= rightWidth )
	{
		this.commonWidth = rightWidth + 'px';
	}
	else
	{
		this.commonWidth = leftWidth + 'px';
	}
	if( leftHeight <= rightHeight )
	{
		this.commonHeight = rightHeight + 'px';
	}
	else
	{
		this.commonHeight = leftHeight + 'px';
	}
	this.left.style.width = this.commonWidth;
	this.left.style.height = this.commonHeight;
	this.right.style.width = this.commonWidth;
	this.right.style.height = this.commonHeight;
	this.cont.style.width = this.commonWidth;
	this.cont.style.height = this.commonHeight;
	this.left.style.overflow = 'hidden';
	this.left.style.cssFloat = 'left';
	this.left.style.position = 'absolute';
	this.left.style.display = 'none';
	this.cont.style.overflow = 'hidden';
	
	this.fin = parseInt(this.commonWidth);
	var init = false;
	this.left.style.width = (init)? this.fin + 'px' : '0px';
	this.dir;
	
	this.slide = function() {
		self.left.style.display = '';
		var w = parseInt(self.left.style.width);
		if(w == 0) {
			self.dir = 'l';
			self._engine('l');
		}
		else {
			self.dir = 'r';
			self._engine('r');
		}
	}
	
	this._engine = function(dir) {
		var p = (dir == 'l')? 40 : -40;
		var f = (dir == 'l')? self.fin : 0;
		var w = parseInt(self.left.style.width);
		w += p;
		self.left.style.width = w + 'px';
		if(w != f)
		{
			var code = self.name + '._engine("' + self.dir + '")';
			var t = window.setTimeout(code, 30);
		}
		else
		{
			/*for(x in self)
			{
				alert( x );
			}*/
			//alert(self.fin);
			//alert(self.left.style.width);
		}
	}
}

function deleteTool(t, x) {
	editTools[t][checkToolDel] = '';
	if(editTools[t][editToolType] == 'list_') {
		var tBis = ++t;
		editTools[tBis][checkToolDel] = '';
	}
	var div = d.getElementById(x);
	div.innerHTML = '';
}

function preserveTxtData() {
	var x;
	var y;
	for(x in editTools) {
		if(editTools[x][editToolType] == 'line_') {
			y = d.getElementById(editTools[x][editToolId]);
			if(y) { //chequéa que el párrafo no haya sido eliminado
				txtDataReservoir[x] = new Array();
				txtDataReservoir[x][0] = y.id;
				txtDataReservoir[x][1] = y.value;
			}
		}
		if(editTools[x][editToolType] == 'para_') {
			y = d.getElementById(editTools[x][editToolId]);
			if(y) { //chequéa que el párrafo no haya sido eliminado
				txtDataReservoir[x] = new Array();
				txtDataReservoir[x][0] = y.id;
				txtDataReservoir[x][1] = y.value;
			}
		}
	}
}

function restoreTxtData() {
	var x;
	var y;
	for(x in txtDataReservoir) {
		y = d.getElementById(txtDataReservoir[x][0]);
		if(y) { //chequéa que el párrafo no haya sido eliminado
			y.value = txtDataReservoir[x][1];
		}
	}
}

function addBr(x) {
	preserveTxtData();
	var type = 'br_';
	var suffix = type + thisTool;
	var idDiv = 'del_' + suffix;
	var idInput = 'ins_' + suffix;

	var insDiv = 'div_' + suffix;
	var div = d.getElementById(x);
	var oldDiv;
	var newDiv;

	var s = '\
<div id="' + idDiv + '">\
	<hr />\
	<table width="100%" border="' + actBorder + '" cellspacing="0" cellpadding="0">\
		<tr>\
	    <td align="center" width="' + deleteWidth + '">\
				<div class="editTool">\
					&lt;-- Salto de p&aacute;rrafo --&gt;\
				</div>\
				<input type="hidden" id="' + idInput + '" name="jacqueline" />\
			</td>\
			<td align="center">\
				<a href="javascript: deleteTool(' + thisTool + ', \'' + idDiv + '\');">\
					Eliminar\
				</a>\
			</td>\
		</tr>\
	</table>\
	<hr />\
	' + editMenuBar0 + insDiv + editMenuBar1 + insDiv + editMenuBar2 + insDiv + editMenuBar3 + insDiv + editMenuBar4 + insDiv + editMenuBar5 + insDiv + editMenuBar6 + insDiv + editMenuBar7 + '\
</div>\
<div id="' + insDiv + '"></div>\
	';
	oldDiv = div.innerHTML;
	div.innerHTML = '';
	newDiv = s + oldDiv;
	try {
		div.innerHTML = newDiv;
	}
	catch(e) {
		alert(e.description);
	}
	
	editTools[thisTool] = new Array();
	editTools[thisTool][editToolType] = type;
	editTools[thisTool][editToolId] = idInput;
	editTools[thisTool][checkToolDel] = idDiv; //check if it has not been erased
	++thisTool;
	restoreTxtData();
}

function addList(x) {
	preserveTxtData();
	var type = 'list_';
	var suffix = type + thisTool;
	var thisToolBis = thisTool + 1;
	var suffixBis = type + thisToolBis;
	var idDiv = 'del_' + suffix;
	var idInput = 'ins_' + suffix;
	var idInputBis = 'ins_' + suffixBis;
	var idForm = 'form_' + suffix;
	var idFormBis = 'form_' + suffixBis;

	var insDiv = 'div_' + suffix;
	var listItemsDiv = 'items_' + suffix;
	var div = d.getElementById(x);
	var oldDiv;
	var newDiv;

	var s = '\
<div id="' + idDiv + '">\
	<hr />\
	<table width="100%" border="' + actBorder + '" cellspacing="0" cellpadding="0">\
		<tr>\
			<td>\
				<div class="editToolsTitle">\
					Lista :: \
					<span class="editToolsSubtitle">\
						Explicaci&oacute;n...\
					</span>\
				</div>\
			</td>\
			<td rowspan="2" align="center">\
				<a href="javascript: deleteTool(' + thisTool + ', \'' + idDiv + '\');">\
					Eliminar\
				</a>\
			</td>\
		</tr>\
		<tr>\
	    <td width="' + deleteWidth + '">\
				<div class="editTool">\
					<input type="hidden" id="' + idInput + '" name="jacqueline" value="begin" />\
					' + editMenuBar0 + listItemsDiv + editMenuBar1 + listItemsDiv + editMenuBar2 + listItemsDiv + editMenuBar3 + listItemsDiv + editMenuBar4 + listItemsDiv + editMenuBar5 + listItemsDiv + editMenuBar6 + listItemsDiv + editMenuBar7 + '\
				</div>\
			</td>\
		</tr>\
			<td colspan="2">\
				<div id="' + listItemsDiv + '" class="jacqueline">\
					&nbsp;\
				</div>\
				<input type="hidden" id="' + idInputBis + '" name="jacqueline" value="end" />\
			</td>\
		</tr>\
		<tr>\
			<td colspan="2">\
				<div class="editTool">\
					<label>\
						<input type="checkbox" name="' + idForm + '" class="formatLineBr" value="lineBr" checked="checked" />\
						Salto de l&iacute;nea\
					</label>\
					<label>\
						<input type="checkbox" name="' + idForm + '" class="formatParaBr" value="paraBr" />\
						Salto de p&aacute;rrafo\
					</label>\
				<br /><br />\
					<fieldset>\
						<legend>\
							Tipo\
							&nbsp;\
						</legend>\
						<div class="fieldsetDiv">\
							<label>\
								<input type="radio" name="' + idForm + '" class="formatListType" value="ul" checked="checked">\
								Listado\
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\
							</label>\
							<label>\
								<input type="radio" name="' + idForm + '" class="formatListType" value="ol">\
								Numerada\
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\
							</label>\
						</div>\
					</fieldset>\
				</div>\
			</td>\
		</tr>\
	</table>\
	<hr />\
	' + editMenuBar0 + insDiv + editMenuBar1 + insDiv + editMenuBar2 + insDiv + editMenuBar3 + insDiv + editMenuBar4 + insDiv + editMenuBar5 + insDiv + editMenuBar6 + insDiv + editMenuBar7 + '\
</div>\
<div id="' + insDiv + '"></div>\
	';
	oldDiv = div.innerHTML;
	div.innerHTML = '';
	newDiv = s + oldDiv;
	div.innerHTML = newDiv;
	
	editTools[thisTool] = new Array();
	editTools[thisTool][editToolType] = type;
	editTools[thisTool][editToolId] = idInput;
	editTools[thisTool][checkToolDel] = idDiv; //check if it has not been erased
	editTools[thisTool][editToolForm] = idForm;
	++thisTool;
	editTools[thisTool] = new Array();
	editTools[thisTool][editToolType] = type;
	editTools[thisTool][editToolId] = idInputBis;
	editTools[thisTool][checkToolDel] = idDiv; //check if it has not been erased
	editTools[thisTool][editToolForm] = idForm;
	++thisTool;
	restoreTxtData();
}

function addLine(x) {
	preserveTxtData();
	var type = 'line_';
	var suffix = type + thisTool;
	var idDiv = 'del_' + suffix;
	var idInput = 'ins_' + suffix;
	var idForm = 'form_' + suffix;
	var idLink = 'link_' + suffix;
	var idSlide = 'slide_' + suffix;

	var divAniDiv = 'ani_' + suffix;
	var insDiv = 'div_' + suffix;
	var div = d.getElementById(x);
	var oldDiv;
	var newDiv;

	var s = '\
<div id="' + idDiv + '">\
	<hr />\
	<table width="100%" border="' + actBorder + '" cellspacing="0" cellpadding="0">\
		<tr>\
			<td>\
				<div class="editToolsTitle">\
					L&iacute;nea :: \
					<span class="editToolsSubtitle">\
						Explicaci&oacute;n...\
					</span>\
				</div>\
			</td>\
			<td rowspan="2" align="center">\
				<a href="javascript: deleteTool(' + thisTool + ', \'' + idDiv + '\');">\
					Eliminar\
				</a>\
			</td>\
		</tr>\
		<tr>\
			<td width="' + deleteWidth + '">\
				<div id="' + idSlide + '_cont" class="editTool" style="">\
					<!--\
					<a href="javascript: slideTools[ ' + thisTool + ' ].slide();" onclick="">do it</a>\
					<div id="' + idSlide + '_left" style="z-index:100; background:white;">\
						<div id="' + idSlide + '_aux" style="width:640px;">\
						</div>\
					</div>\
					<div id="' + idSlide + '_right" style="position:absolute;">\
					</div>\
					-->\
					<input type="text" id="' + idInput + '" name="jacqueline" class="jacqueline" size="' + txtLineSize + '" />\
				<br /><br />\
					<label>\
						<input type="checkbox" name="' + idForm + '" class="formatLineBr" value="lineBr" checked="checked" />\
						Salto de l&iacute;nea\
					</label>\
					<label>\
						<input type="checkbox" name="' + idForm + '" class="formatParaBr" value="paraBr" />\
						Salto de p&aacute;rrafo\
					</label>\
				<br /><br />\
					<table width="' + formatToolsTableWidth + '" border="' + actAuxBorder +  '" cellspacing="0" cellpadding="' + formatToolsCellPadding + '">\
					' + txtFormatMenu0 + idForm + txtFormatMenu1 + txtColorChoices + txtFormatMenu2 + idForm + txtFormatMenu3 + txtFontChoices + txtFormatMenu4 + idForm + txtFormatMenu5 + txtSizeChoices + txtFormatMenu6 + idForm + txtFormatMenu7 + idForm + txtFormatMenu8 + idForm + txtFormatMenu9 + '\
				<br /><br />\
					<label>\
						Hyperv&iacute;nculo\
						&nbsp;\
						<input type="text" id="' + idLink + '" name="jacquelink" size="' + txtLineSize + '" />\
					</label>\
				</div>\
			</td>\
		</tr>\
	</table>\
	<hr />\
	' + editMenuBar0 + insDiv + editMenuBar1 + insDiv + editMenuBar2 + insDiv + editMenuBar3 + insDiv + editMenuBar4 + insDiv + editMenuBar5 + insDiv + editMenuBar6 + insDiv + editMenuBar7 + '\
</div>\
<div id="' + insDiv + '"></div>\
	';
	oldDiv = div.innerHTML;
	div.innerHTML = '';
	newDiv = s + oldDiv;
	div.innerHTML = newDiv;
	
	//arrAniDiv[divAniDiv] = new animatedcollapse(divAniDiv, 800, false, 'contract');
	//after the div has been taken out from var s -the html code- this line makes no sense.
	//slideTools[ thisTool ] = new Morph( idSlide + '_left', idSlide + '_right', idSlide + '_cont', 'slideTools[ ' + thisTool + ' ]' );

	editTools[thisTool] = new Array();
	editTools[thisTool][editToolType] = type;
	editTools[thisTool][editToolId] = idInput;
	editTools[thisTool][checkToolDel] = idDiv; //check if it has not been erased
	editTools[thisTool][editToolForm] = idForm;
	editTools[thisTool][editToolLink] = idLink; //add hyperlink
	++thisTool;
	restoreTxtData();
}

function addParagraph(x) {
	preserveTxtData();
	var type = 'para_';
	var suffix = type + thisTool;
	var idDiv = 'del_' + suffix;
	var idInput = 'ins_' + suffix;
	var idForm = 'form_' + suffix;

	var insDiv = 'div_' + suffix;
	var div = d.getElementById(x);
	var oldDiv;
	var newDiv;

	var s = '\
<div id="' + idDiv + '">\
	<hr />\
	<table width="100%" border="' + actBorder + '" cellspacing="0" cellpadding="0">\
		<tr>\
			<td>\
				<div class="editToolsTitle">\
					P&aacute;rrafo :: \
					<span class="editToolsSubtitle">\
						Explicaci&oacute;n...\
					</span>\
				</div>\
			</td>\
			<td rowspan="2" align="center">\
				<a href="javascript: deleteTool(' + thisTool + ', \'' + idDiv + '\');">\
					Eliminar\
				</a>\
			</td>\
		</tr>\
		<tr>\
			<td width="' + deleteWidth + '">\
				<div class="editTool">\
					<textarea id="' + idInput + '" name="jacqueline" class="jacqueline" cols="64" rows="10"></textarea>\
					<br /><br />\
						<label>\
							<input type="checkbox" name="' + idForm + '" class="formatLineBr" value="lineBr" checked="checked" />\
							Salto de l&iacute;nea\
						</label>\
						<label>\
							<input type="checkbox" name="' + idForm + '" class="formatParaBr" value="paraBr" />\
							Salto de p&aacute;rrafo\
						</label>\
					<br /><br />\
						<table width="' + formatToolsTableWidth + '" border="' + actAuxBorder +  '" cellspacing="0" cellpadding="' + formatToolsCellPadding + '">\
						' + txtFormatMenu0 + idForm + txtFormatMenu1 + txtColorChoices + txtFormatMenu2 + idForm + txtFormatMenu3 + txtFontChoices + txtFormatMenu4 + idForm + txtFormatMenu5 + txtSizeChoices + txtFormatMenu6 + idForm + txtFormatMenu7 + idForm + txtFormatMenu8 + idForm + txtFormatMenu9 + '\
				</div>\
			</td>\
		</tr>\
	</table>\
	<hr />\
	' + editMenuBar0 + insDiv + editMenuBar1 + insDiv + editMenuBar2 + insDiv + editMenuBar3 + insDiv + editMenuBar4 + insDiv + editMenuBar5 + insDiv + editMenuBar6 + insDiv + editMenuBar7 + '\
</div>\
<div id="' + insDiv + '"></div>\
	';
	oldDiv = div.innerHTML;
	div.innerHTML = '';
	newDiv = s + oldDiv;
	div.innerHTML = newDiv;
	
	editTools[thisTool] = new Array();
	editTools[thisTool][editToolType] = type;
	editTools[thisTool][editToolId] = idInput;
	editTools[thisTool][checkToolDel] = idDiv; //check if it has not been erased
	editTools[thisTool][editToolForm] = idForm;
	++thisTool;
	restoreTxtData();
}

function addImg( x )
{
	editTools[thisTool] = new Array();
	editTools[thisTool][editToolObj] = new ImgTool( thisTool );
	editTools[thisTool][editToolObj].insertTool( x );
}

function ImgTool( t ) {
	var self = this;
	this.tool = t;
	this.type = 'img_';
	
	var suffix = this.type + this.tool;
	var idDiv = 'del_' + suffix;
	var idInput = 'ins_' + suffix;
	var idForm = 'form_' + suffix;
	var idLink = 'link_' + suffix;

	var idFrame = idInput + '_iframe';
	var idAjax = idInput + '_ajax';
	var mode = 'start';

	var insDiv = 'div_' + suffix;
	
	editTools[this.tool][editToolType] = this.type;
	editTools[this.tool][editToolId] = idInput;
	editTools[this.tool][checkToolDel] = idDiv; //check if it has not been erased
	editTools[this.tool][editToolForm] = idForm;
	editTools[this.tool][editToolLink] = idLink; //add hyperlink
	
	this.data = {
		name : null,
		file : null,
		thumb : null,
		master_id : null,
		type : null,
		size_kb : null,
		width_px : null,
		height_px : null,
		cover : null,
		desc : null,
		tags : null
	}
	
	this.code = '\
<div id="' + idDiv + '">\
	<hr />\
	<table width="100%" border="' + actBorder + '" cellspacing="0" cellpadding="0">\
		<tr>\
			<td>\
				<div class="editToolsTitle">\
					Imagen :: \
					<span class="editToolsSubtitle">\
						Explicaci&oacute;n...\
					</span>\
				</div>\
			</td>\
			<td rowspan="3" align="center"><a href="javascript: deleteTool(' + self.tool + ', \'' + idDiv + '\');">Eliminar</a></td>\
		</tr>\
		<tr>\
			<td width="' + deleteWidth + '">\
				<div class="jacqueline">\
					<iframe id="' + idFrame + '" name="' + idFrame + '" src="php/sp_img_tool.php?mode=' + mode + '&emperor=' + idInput + '&this_tool=' + self.tool + '&txt_size=' + txtLineSize + '" width="' + iframeWidth + '" height="' + iframeHeightImg + '" frameborder="' + actFrameBorder + '" scrolling="no">\
					</iframe>\
				</div>\
			</td>\
		</tr>\
		<tr>\
			<td>\
				<div class="editTool">\
					<label>\
						<input type="checkbox" name="' + idForm + '" class="formatLineBr" value="lineBr" checked="checked" />\
						Salto de l&iacute;nea\
					</label>\
					<label>\
						<input type="checkbox" name="' + idForm + '" class="formatParaBr" value="paraBr" />\
						Salto de p&aacute;rrafo\
					</label>\
				<br /><br />\
					<table width="100%" border="' + actAuxBorder + '" cellspacing="0" cellpadding="0">\
						<tr>\
							<td>\
								<label>\
									Ancho de la Imagen\
									&nbsp;\
									<input type="text" name="' + idForm + '" class="formatImgWidth" size="' + txtLineSizeMini + '" />\
									&nbsp;\
									px\
								</label>\
							</td>\
							<td>\
								<label>\
									M&aacute;rgenes\
									&nbsp;\
									<input type="text" name="' + idForm + '" class="formatImgMargin" size="' + txtLineSizeMini + '" />\
									&nbsp;\
									px\
								</label>\
							</td>\
							<td>\
								<label>\
									Opacidad&nbsp;\
									<select name="' + idForm + '" class="formatOpac">\
										' + toolOpacChoices + '\
									</select>\
								</label>\
							</td>\
						</tr>\
					</table>\
				<br />\
					<label>\
						Hyperv&iacute;nculo\
						&nbsp;\
						<input type="text" id="' + idLink + '" name="jacquelink" size="' + txtLineSize + '" />\
					</label>\
				<br /><br />\
					<!-- <input name="applyImage" type="button" value="Aplicar Imagen" onclick="javascript: iBelieve(' + self.tool + ',\'' + idInput + '\')" /> -->\
					<span id="' + idAjax + '"></span>\
					<input type="hidden" id="' + idInput + '" name="jacqueline" />\
				</div>\
			</td>\
		</tr>\
	</table>\
	<hr />\
	' + editMenuBar0 + insDiv + editMenuBar1 + insDiv + editMenuBar2 + insDiv + editMenuBar3 + insDiv + editMenuBar4 + insDiv + editMenuBar5 + insDiv + editMenuBar6 + insDiv + editMenuBar7 + '\
</div>\
<div id="' + insDiv + '"></div>\
	';
	
	this.insertTool = function( x )
	{
		preserveTxtData();
		
		var div = d.getElementById(x);
		var oldDiv = div.innerHTML;
		var newDiv = self.code + oldDiv;
		div.innerHTML = '';
		if( div.innerHTML = newDiv )
		{
			thisTool = self.tool + 1; // very important, only adds a tool if the tool was successfuly inserted
		}
		
		restoreTxtData();
	}
	
	this.applyImg = function( dataObj )
	{
		try
		{
			var f;
			var j = d.getElementById( idInput );
			var s = d.getElementById( idAjax );

			// if contentDocument exists, W3C compliant ( Mozilla )
			if( document.getElementById( idFrame ).contentDocument )
			{
				f = document.getElementById( idFrame ).contentDocument;
			}
			else
			{
				// IE
				f = d.frames[ idFrame ].document;
			}

			var jackie = f.getElementById( 'jacqueline' ).value;
			alert("DEBUG -> "+jackie);
			var file = f.dbData.file;
			var size_kb = f.dbData.size_kb;
			var width_px = f.dbData.width_px;
			var height_px = f.dbData.height_px;
			var gallery = f.dbData.gallery;
			if( jackie )
			{
				editTools[self.tool][toolImgData] = new Array();
				editTools[self.tool][toolImgData][0] = file;
				editTools[self.tool][toolImgData][1] = size_kb;
				editTools[self.tool][toolImgData][2] = width_px;
				editTools[self.tool][toolImgData][3] = height_px;
				editTools[self.tool][toolImgData][4] = gallery; // added later
				s.innerHTML = '\
<span class="sys">' + file + '</span><span class="subSys">&nbsp;ha sido aplicada con &eacute;xito.</span>\
				';
				j.value = file;
			}
			else
			{
				s.innerHTML = '\
<span class="sys">C&oacute;digo incorrecto.</span><span class="subSys">&nbsp;Asegurate de que el c&oacute;digo ingresado provenga de <i>YouTube</i> y no haya sido modificado.</span>\
				';
			}
		}
		catch(e)
		{
			alert('Ha ocurrido un error : "' + e.description + '".');		
		}
	}
}

function addVid(x){
	preserveTxtData();
	var type = 'vid_';
	var suffix = type + thisTool;
	var idDiv = 'del_' + suffix;
	var idInput = 'ins_' + suffix;
	var idForm = 'form_' + suffix;

	var idFrame = idInput + '_iframe';
	var idAjax = idInput + '_ajax';
	var mode = 'start';

	var insDiv = 'div_' + suffix;
	var div = d.getElementById(x);
	var oldDiv;
	var newDiv;

	var s = '\
<div id="' + idDiv + '">\
	<hr />\
	<table width="100%" border="' + actBorder + '" cellspacing="0" cellpadding="0">\
		<tr>\
			<td>\
				<div class="editToolsTitle">\
					Video :: \
					<span class="editToolsSubtitle">\
						Explicaci&oacute;n...\
					</span>\
				</div>\
			</td>\
			<td rowspan="3" align="center">\
				<a href="javascript: deleteTool(' + thisTool + ', \'' + idDiv + '\');">\
					Eliminar\
				</a>\
			</td>\
		</tr>\
		<tr>\
			<td width="' + deleteWidth + '">\
				<div class="jacqueline">\
					<iframe id="' + idFrame + '" name="' + idFrame + '" src="php/sp_vid_tool.php?mode=' + mode + '&emperor=' + idInput + '&this_tool=' + thisTool + '&txt_size=' + txtLineSize + '" width="' + iframeWidth + '" height="' + iframeHeightVid + '" frameborder="' + actFrameBorder + '" scrolling="no">\
					</iframe>\
				</div>\
			</tr>\
		</td>\
		<tr>\
			<td>\
				<div class="editTool">\
					<label>\
						<input type="checkbox" name="' + idForm + '" class="formatLineBr" value="lineBr" checked="checked" />\
						Salto de l&iacute;nea\
					</label>\
					<label>\
						<input type="checkbox" name="' + idForm + '" class="formatParaBr" value="paraBr" />\
						Salto de p&aacute;rrafo\
					</label>\
				<br /><br />\
					<label>\
						Ancho del Video\
						&nbsp;\
						<input type="text" name="' + idForm + '" class="formatVidWidth" size="' + txtLineSizeMini + '" />\
						&nbsp;\
						px\
					</label>\
				<br /><br />\
					<input name="applyVideo" type="button" value="Aplicar Video" onclick="iLove(' + thisTool + ',\'' + idInput + '\')" />\
					<span id="' + idAjax + '"></span>\
					<input type="hidden" id="' + idInput + '" name="jacqueline" />\
				</div>\
			</td>\
		</tr>\
	</table>\
	<hr />\
	' + editMenuBar0 + insDiv + editMenuBar1 + insDiv + editMenuBar2 + insDiv + editMenuBar3 + insDiv + editMenuBar4 + insDiv + editMenuBar5 + insDiv + editMenuBar6 + insDiv + editMenuBar7 + '\
</div>\
<div id="' + insDiv + '"></div>\
	';
	oldDiv = div.innerHTML;
	div.innerHTML = '';
	newDiv = s + oldDiv;
	div.innerHTML = newDiv;
	
	editTools[thisTool] = new Array();
	editTools[thisTool][editToolType] = type;
	editTools[thisTool][editToolId] = idInput;
	editTools[thisTool][checkToolDel] = idDiv; //check if it has not been erased
	editTools[thisTool][editToolForm] = idForm;
	++thisTool;
	restoreTxtData();
}

function addGroup(x) {
	preserveTxtData();
	var type = 'group_';
	var suffix = type + thisTool;
	var thisToolBis = thisTool + 1;
	var suffixBis = type + thisToolBis;
	var idDiv = 'del_' + suffix;
	var idInput = 'ins_' + suffix;
	var idInputBis = 'ins_' + suffixBis;
	var idForm = 'form_' + suffix;
	var idFormBis = 'form_' + suffixBis;
	var idLink = 'link_' + suffix;

	var insDiv = 'div_' + suffix;
	var listItemsDiv = 'items_' + suffix;
	var div = d.getElementById(x);
	var oldDiv;
	var newDiv;

	var s = '\
<div id="' + idDiv + '">\
	<hr />\
	<table width="100%" border="' + actBorder + '" cellspacing="0" cellpadding="0">\
		<tr>\
			<td>\
				<div class="editToolsTitle">\
					Grupo :: \
					<span class="editToolsSubtitle">\
						Explicaci&oacute;n...\
					</span>\
				</div>\
			</td>\
			<td rowspan="2" align="center"><a href="javascript: deleteTool(' + thisTool + ', \'' + idDiv + '\');">Eliminar</a></td>\
		</tr>\
		<tr>\
	    <td width="' + deleteWidth + '">\
				<div class="editTool">\
					<input type="hidden" id="' + idInput + '" name="jacqueline" value="begin" />\
					' + editMenuBar0 + listItemsDiv + editMenuBar1 + listItemsDiv + editMenuBar2 + listItemsDiv + editMenuBar3 + listItemsDiv + editMenuBar4 + listItemsDiv + editMenuBar5 + listItemsDiv + editMenuBar6 + listItemsDiv + editMenuBar7 + '\
				</div>\
			</td>\
		</tr>\
		<tr>\
			<td colspan="2">\
				<div id="' + listItemsDiv + '" class="jacqueline">\
					&nbsp;\
				</div>\
				<input type="hidden" id="' + idInputBis + '" name="jacqueline" value="end" />\
			</td>\
		</tr>\
		<tr>\
			<td colspan="2">\
				<div class="editTool">\
					<label>\
						<input type="checkbox" name="' + idForm + '" class="formatLineBr" value="lineBr" checked="checked" />\
						Salto de l&iacute;nea\
					</label>\
					<label>\
						<input type="checkbox" name="' + idForm + '" class="formatParaBr" value="paraBr" />\
						Salto de p&aacute;rrafo\
					</label>\
				<br /><br />\
					<table width="100%" border="' + actAuxBorder + '" cellspacing="0" cellpadding="0">\
						<tr>\
							<td>\
								<label>\
									Ancho del Grupo\
									&nbsp;\
									<input type="text" name="' + idForm + '" class="formatDivWidth" size="' + txtLineSizeMini + '" />\
									&nbsp;\
									px\
								</label>\
							</td>\
							<td>\
								<label>\
									Alinear Contenido&nbsp;\
									<select name="' + idForm + '" class="formatTextAlign">\
										' + toolTextAlignChoices + '\
									</select>\
								</label>\
							</td>\
							<td>\
								<label>\
									Opacidad&nbsp;\
									<select name="' + idForm + '" class="formatOpac">\
										' + toolOpacChoices + '\
									</select>\
								</label>\
							</td>\
						</tr>\
					</table>\
				<br />\
					<fieldset>\
						<legend>\
							Alinear Grupo\
							&nbsp;\
						</legend>\
						<div class="fieldsetDiv">\
							<label>\
								<input type="radio" name="' + idForm + '" class="formatDivAlign" value="left">\
								Izquierda\
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\
							</label>\
							<label>\
								<input type="radio" name="' + idForm + '" class="formatDivAlign" value="center">\
								Centro\
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\
							</label>\
							<label>\
								<input type="radio" name="' + idForm + '" class="formatDivAlign" value="right">\
								Derecha\
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\
							</label>\
						</div>\
					</fieldset>\
				<br />\
					<fieldset>\
						<legend>\
							Flotar Grupo\
							&nbsp;\
						</legend>\
						<div class="fieldsetDiv">\
							<label>\
								<input type="radio" name="' + idForm + '" class="formatDivFloat" value="left">\
								Izquierda\
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\
							</label>\
							<label>\
								<input type="radio" name="' + idForm + '" class="formatDivFloat" value="none" checked="checked">\
								No&nbsp;flotar\
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\
							</label>\
							<label>\
								<input type="radio" name="' + idForm + '" class="formatDivFloat" value="right">\
								Derecha\
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\
							</label>\
						</div>\
					</fieldset>\
				<br />\
					<fieldset>\
						<legend>\
							Ep&iacute;grafe\
							&nbsp;\
						</legend>\
						<div class="fieldsetDiv">\
							<label>\
								Texto\
								&nbsp;\
								<input type="text" name="' + idForm + '" class="imgCaption" size="' + txtLineSize + '" />\
							</label>\
						<br /><br />\
							<label>\
								Ancho del Ep&iacute;grafe\
								&nbsp;\
								<input type="text" name="' + idForm + '" class="imgCaptionWidth" size="' + txtLineSizeMini + '" />\
								&nbsp;\
								px\
							</label>\
						<br /><br />\
							<table width="' + formatToolsTableWidth + '" border="' + actAuxBorder +  '" cellspacing="0" cellpadding="' + formatToolsCellPadding + '">\
							' + txtFormatMenu0 + idForm + txtFormatMenu1 + txtColorChoices + txtFormatMenu2 + idForm + txtFormatMenu3 + txtFontChoices + txtFormatMenu4 + idForm + txtFormatMenu5 + txtSizeChoices + txtFormatMenu6 + idForm + txtFormatMenu7 + idForm + txtFormatMenu8 + idForm + txtFormatMenu9 + '\
						<br /><br />\
							<label>\
								Hyperv&iacute;nculo\
								&nbsp;\
								<input type="text" id="' + idLink + '" name="jacquelink" size="' + txtLineSize + '" />\
							</label>\
						</div>\
					</fieldset>\
				</div>\
			</td>\
		</tr>\
	</table>\
	<hr />\
	' + editMenuBar0 + insDiv + editMenuBar1 + insDiv + editMenuBar2 + insDiv + editMenuBar3 + insDiv + editMenuBar4 + insDiv + editMenuBar5 + insDiv + editMenuBar6 + insDiv + editMenuBar7 + '\
</div>\
<div id="' + insDiv + '"></div>\
	';
	oldDiv = div.innerHTML;
	div.innerHTML = '';
	newDiv = s + oldDiv;
	div.innerHTML = newDiv;
	
	editTools[thisTool] = new Array();
	editTools[thisTool][editToolType] = type;
	editTools[thisTool][editToolId] = idInput;
	editTools[thisTool][checkToolDel] = idDiv; //check if it has not been erased
	editTools[thisTool][editToolForm] = idForm;
	editTools[thisTool][editToolLink] = idLink; //add hyperlink
	++thisTool;
	editTools[thisTool] = new Array();
	editTools[thisTool][editToolType] = type;
	editTools[thisTool][editToolId] = idInputBis;
	editTools[thisTool][checkToolDel] = idDiv; //check if it has not been erased
	editTools[thisTool][editToolForm] = idForm;
	editTools[thisTool][editToolLink] = idLink; //add hyperlink
	++thisTool;
	restoreTxtData();
}

function addHTML(x) {
	alert('Bajo desarrollo.');
}