/* 
**************************************************************************************
2003 - 2017 © Yal Publicidad . JavaScript Document | WYEDITORT
**************************************************************************************
website: www.yalpublicidad.com
Sist. Weby+: www.webyplus.com

*/
		

		wyEditorT = {
			init: function () {
				if(window.onload==document.getElementById(wyEditor.Contenedor)){
					window.onload=this.cEditor;
				}				
			},
			
			cEditor: function(){
				/* Cargo hoja de estilos CSS del editor */
				var styles = ( wyEditor.Ruta != null) ? wyEditor.Ruta + "/cssy_wyEditorT.css" : "cssy_wyEditorT.css";
				var head  = document.getElementsByTagName('head')[0];
				var link  = document.createElement('link');
					//link.id   = cssId;
					link.rel  = 'stylesheet';
					link.type = 'text/css';
					link.href = styles;
					link.media = 'all';
					head.appendChild(link);
					
				/* Creo width de editor */
				sWidth = ( wyEditor.Width != '' ) ? wyEditor.Width : '100%';
				
				/* Creo Height de editor */
				sHeight = ( wyEditor.Height != null ) ? wyEditor.Height : '90px';
					
				/* Creo contenedor del editor */
				var textareaEditorT  = document.getElementById(wyEditor.TextArea);
				var divEditorT  = document.createElement('div');
					divEditorT.id   = 'eEditor';
					divEditorT.style.width = sWidth;
					textareaEditorT.parentNode.insertBefore( divEditorT, textareaEditorT.nextSibling );
				
				/* oculto TextAreas */
				if(textareaEditorT){ 
					textareaEditorT.style.display = 'none'; 
				}
				
				
				
				
				
				sdlgHelper		= '<OBJECT id=dlgHelper CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" width="0px" height="0px"></OBJECT><div class="eEditor">';
				SBarraAlinear	= '<span class="tooltip-separador">'+
                        '<a href="javascript:Cformato(\'InsertUnorderedList\');" class="vinetas" title="Lista viñetas"></a>'+
                        '<a href="javascript:Cformato(\'InsertOrderedList\');" class="numeracion" title="Lista numerada"></a>'+
						'</span>'+
						'<span class="tooltip-separador">'+
                        '<a href="javascript:Cformato(\'JustifyLeft\');" class="izq" title="Alinear a la izquierda"></a>'+
                        '<a href="javascript:Cformato(\'JustifyCenter\');" class="centro" title="Alinear al centro"></a>'+
                        '<a href="javascript:Cformato(\'JustifyRight\');" class="der" title="Alinear a la derecha"></a>'+
						'<a href="javascript:Cformato(\'JustifyFull\');" class="der" title="Justificar"></a>'+
						'</span>';
				sBarraInsertar	= '<span class="tooltip-separador">'+
                        '<a href="javascript:;" class="enlace" title="Editar / Insertar enlace"></a>'+
						'<a href="javascript:;" class="imagen" title="Insertar imagen"></a>'+
						'</span>';
						
				tfContructor = sdlgHelper;
				tfContructor = tfContructor+'<div class="eEditor">'+
                    '<div class="box-tooltip">'+
                    	'<span class="tooltip-separador">'+
                        '<a href="javascript:Cformato(\'Bold\');" class="negrita" title="Negrita"></a>'+
                        '<a href="javascript:Cformato(\'Italic\');" class="cursiva" title="Itálica"></a>'+
                        '<a href="javascript:Cformato(\'Underline\');" class="subrayado" title="Subrayado"></a>'+
						'</span>';
						
					if(wyEditor.BarraAlinear==true){
						tfContructor = tfContructor+SBarraAlinear;
					}
					
					if(wyEditor.BarraInsertar==true){
						tfContructor = tfContructor+sBarraInsertar;
					}
					
					var divTexto = ( document.getElementById(wyEditor.TextArea).value != '' ) ? document.getElementById(wyEditor.TextArea).value : '<p></p>';
					tfContructor = tfContructor + '</div>' + 
					'<div id="oContainer" style="position: relative; top: 0; overflow: hidden;" Dir="LTR">'+
						'<div class="editArea" id="Editor_Div" name="Editor_Div" innerhtml="" contentEditable="true" style="overflow:auto; left:0px; right:0px; height: ' + sHeight + '; display:block; Background-color: White;" onmouseout="PonerTextoOculto()">'+divTexto+'</div><div>p</div>'+
					'</div>'+				
                '</div>';
				
				return document.getElementById('eEditor').innerHTML=tfContructor;
				
			}
		}
				
	//if(document.getElementById('eEditor')) document.getElementById('eEditor').innerHTML = ypEditor;
	
	htmlentities = function(str){
		x = convertHTML(str.value);
		str.value = x;
	}
	
	function nl2br (str, is_xhtml) {
		var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
		return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
	}
	
	function convertHTML(sCadena) {

		especiales = new Array('á','é','í','ó','ú','ñ','Á','É','Í','Ó','Ú','Ñ','´','\'','"','1/2');
		strHTML = new Array('&aacute;','&eacute;','&iacute;','&oacute;','&uacute;','&ntilde;','&Aacute;','&Eacute;','&Iacute;','&Oacute;','&Uacute;','&Ntilde;','&acute;','&prime;','&quot;','&frac12;');
	 
		//nuevoAlias = nuevoAlias.toLowerCase();
	 
		i=0;
		while (i<especiales.length) {
			//nuevoAlias = nuevoAlias.replace(especiales[i], normales[i]);
			sCadena = sCadena.split(especiales[i]).join(strHTML[i]);
			i++
		}
	
		return sCadena;
	
	}
	
	function PonerTextoOculto()
	{   
			document.getElementById(wyEditor.TextArea).value = editor_getText('Editor_Div');
			return true;
	}
		
	function editor_getText(objname) {
		var editor_obj = document.all[objname];
		var isTextarea = (editor_obj.tagName.toLowerCase() == 'textarea');

		if (isTextarea) { return editor_obj.value; }
		else            { return editor_obj.innerHTML; }
	}
		
	function setFocus()
	{
			if (document.frm.from.value == '' )
				document.frm.from.focus();
			else if (document.frm.sbj.value == '')
				document.frm.sbj.focus();
			//else if (document.frm.txtTitulo.value == '')
				//document.frm.txtTitulo.focus();
			else
				;
				
	}
	
	var sInitColor = null;		
		
		var Datos = {
			divEditor: 'Editor_Div'
		}
		
		function Cformato(str)
		{	
			try
			{
				document.getElementById(Datos.divEditor).focus();
				format(str);
			}catch(e){
				alert("Operacion de formateo incapaz de preformas");
			}	
		}
		
		function format (str)
		{
			document.execCommand(str);
		}
		
		function setHeader(value)
		{
			document.execCommand('removeFormat');
			document.execCommand('formatBlock','','Normal');
			s = document.selection.createRange();
			
			html = '<font class=\'' + value + '\'>' + s.htmlText + '</font>';
			s.pasteHTML(html);
		}
		
		function setFont(val,e)
		{
			document.getElementById(Datos.divEditor).focus();
			document.execCommand(e, false, val);
		}
		
		/*function setFontSize(val,e)
		{
			ed = GetEditor(e);
			document.getElementById(Datos.divEditor).focus();
			document.execCommand('fontsize', false, val);
		}
		
		function setFont(val,e)
		{
			ed = GetEditor(e);
			document.getElementById(ed.DivID).focus();
			document.execCommand('fontname', false, val);
		}*/
		
		
		
		
		
		
		
		/*var numero = 0;

// Funciones comunes
c= function (tag) { // Crea un elemento
   return document.createElement(tag);
}
d = function (id) { // Retorna un elemento en base al id
   return document.getElementById(id);
}
e = function (evt) { // Retorna el evento
   return (!evt) ? event : evt;
}
f = function (evt) { // Retorna el objeto que genera el evento
   return evt.srcElement ?  evt.srcElement : evt.target;
}

addField = function () {
   container = d('files');
   
   span = c('SPAN');
   span.className = 'file';
   span.id = 'file' + (++numero);

   field = c('INPUT');   
   field.name = 'archivos[]';
   field.type = 'file';
   
   a = c('A');
   a.name = span.id;
   a.href = 'javascript:void(0)';
   a.onclick = removeField;
   a.innerHTML = 'Quitar';

   span.appendChild(field);
   span.appendChild(a);
   container.appendChild(span);
}
removeField = function (evt) {
   lnk = f(e(evt));
   span = d(lnk.name);
   span.parentNode.removeChild(span);
}
*/