
  function cambiar1 (url, variables, capa, opcion,cont)
  {
	 
 va=document.getElementById(cont).innerHTML;
	  va=escape(va);
//va=escape(va);

  variables= variables + va;

  	include_dinamico (url,variables,capa,opcion);
  }
  
  
  function cambiar (url, variables, capa, opcion)
  {
	  vas=document.getElementById(capa).innerHTML;
	  vas=escape(vas);
  variables= variables + vas;

  	include_dinamico (url,variables,capa,opcion);
  }


	function abrir (cod,nombrecapa,tipo,cona,tabla,nomid,capa)
	{
		
		// codigo
		// nombre capa
		// tipo de
		// contenedor
		// tabla
		// nombre del codigo de tabla
		// nombre capa
//		document.getElementById('f' + adr).contentWindow.document.execCommand

	caa=document.getElementById('textarea').innerHTML;
	

//	caa=document.getElementById('frmEditor').contentWindow.document.value;
	caa=escape(caa);
	include_dinamico ('guardar.php','id='+cod +'&campo1='+ caa + '&capa=' + capa + '&tabla=' + tabla + '&nomid=' + nomid + '&nom=' + nombrecapa + '&tipo=' + tipo + '&contenedor=' + cona,nombrecapa,tipo);
	}
	
	
		function abrir2 (cod,nombrecapa,tipo,cona,tabla,nomid)
	{
//		document.getElementById('f' + adr).contentWindow.document.execCommand
	caa=document.form1.fecha.value;
//	caa=document.getElementById('frmEditor').contentWindow.document.value;
caa=escape(caa);
	include_dinamico ('guardar.php','id='+cod +'&campo1='+ caa + '&tabla=' + tabla + '&nomid=' + nomid + '&nom=' + nombrecapa + '&tipo=' + tipo + '&contenedor=' + cona,nombrecapa,tipo);
	}

/*
	function abrir ()
	{
//		document.getElementById('f' + adr).contentWindow.document.execCommand
	caa=frmEditor.document.body.innerHTML;
//	caa=document.getElementById('frmEditor').contentWindow.document.value;

	include_dinamico ('guardar.php','id=1&campo1='+caa,'include',2);
	}*/

//Su explorador no soporta java o lo tiene deshabilitado; esta pagina necesita javascript para funcionar correctamente<!-- 
//Copyright © McAnam.com 
	
	var iNumDoc = 1;
	var sNomDoc = "Documento" + iNumDoc + ".htm";
	var bCodigo = 0;
	
	
	
	function comienzo(){
		
		if (!document.execCommand){ 
			alert("Función no disponible"); 
			return false; 
		}
		
		var iCont, sElemento, oOpcion;
		
		for (iCont = 0 ; iCont < document.all.length ; iCont++)
		
		
			document.all(iCont).unselectable = 'on';
		
		frmEditor.document.execCommand("EditMode");
		frmEditor.document.execCommand("LiveResize", false, true);
		frmEditor.document.execCommand("2D-Position", false, true);
		frmEditor.document.execCommand("MultipleSelection", false, true);
		
		// Inicializamos las fuentes del sistema
		
		// Tipos:
		for (iCont = 1 ; iCont <= document.getElementById("dialogHelper").fonts.count ; iCont++){ 
			
			sElemento = document.getElementById("dialogHelper").fonts.item(iCont);
			
			oOpcion = document.createElement("option");
			oOpcion.value = sElemento;
			oOpcion.text = sElemento;
			
			document.getElementById("sltTipoFuentes").add(oOpcion);
			
		}
		
		// Tamaños:
		for (iCont = 1 ; iCont < 8 ; iCont ++){
			
			oOpcion = document.createElement("option");
			oOpcion.value = iCont;
			oOpcion.text = iCont;
			
			document.getElementById("sltTamFuentes").add(oOpcion);
			
		}
		
		// Inicializamos los formatos del sistema
		
		// Tipos:
		for (iCont = 1 ; iCont <= document.getElementById("dialogHelper").blockFormats.count ; iCont++){ 
			
			sElemento = document.getElementById("dialogHelper").blockFormats.item(iCont);
			
			oOpcion = document.createElement("option");
			oOpcion.value = sElemento;
			oOpcion.text = sElemento;
			
			document.getElementById("sltFormatos").add(oOpcion);
			
		}
		
		frmEditor.focus();
		
	}
	
	function comando_documento(sComando, bInterfaz_de_usuario, Anadido){ 
		if (!document.execCommand){ 
			alert("Función no disponible"); 
			return false; 
		} 
		
		frmEditor.document.execCommand(sComando, bInterfaz_de_usuario, Anadido);
		
		frmEditor.focus();
		
	} 
	
	function color(sComando){
		
		if (!document.execCommand){ 
			alert("Función no disponible"); 
			return false; 
		} 
		
		var iColor = document.getElementById("dialogHelper").ChooseColorDlg(0xFFFFFF);
		
		var sColor = iColor.toString(16);
		sColor = "#" + "000000".substring(0, 6 - sColor.length) + sColor;
		
		frmEditor.document.execCommand(sComando, false, sColor);
		
		frmEditor.focus();
	 	
	}
	
	function ancla(){
	
		if (!document.execCommand){ 
			alert("Función no disponible"); 
			return false; 
		}
		
		var sNombre = prompt("Introduce el nombre del ancla", "");
		frmEditor.document.execCommand("CreateBookmark", false, sNombre);
		
		frmEditor.focus();
		
	}
	
	function insertar_elemento(sElemento){
		
		if (!document.execCommand){ 
			alert("Función no disponible"); 
			return false; 
		}
		
		switch(sElemento){
		
			case "InsertImage":
				
				frmEditor.document.execCommand(sElemento, true);
				
			 break;
			
			default:
				
				var sNombre = prompt("Introduce el id (identificador) del elemento", "");
				frmEditor.document.execCommand(sElemento, true, sNombre);
			
			 break;
		
		}
		
		frmEditor.focus();
		
	}
	
	function cambio_archivo(){
	
		if (confirm("¿Desea guardar el documento actual?"))
			comando_documento("saveAs", true, sNomDoc);
		
		var archivo = objFichero.value
		
		frmEditor.location.href = archivo;
		
		sNomDoc = archivo.substring(archivo.lastIndexOf("\\") + 1);
		
	}
	
	function nuevo(){
	
		if (confirm("¿Desea guardar el documento actual?"))
			comando_documento("saveAs", true, sNomDoc);
		
		frmEditor.location.href = "about:blank";
		
		sNomDoc = "Documento" + (++iNumDoc) + ".htm";
		
	}
	
	function codigo(objBoton){
		if (bCodigo){
			bCodigo = 0;
			objBoton.innerText = "Ver código";
			
			frmEditor.document.body.innerHTML = frmEditor.document.body.innerText;
		
			var vContenedor = document.getElementById("cldBotones").children;
		
			for (var iCont = 0 ; iCont < vContenedor.length ; iCont++)
							vContenedor.item(iCont).disabled = false;
		
			var vContenedor = document.getElementById("cldOpciones").children;
		
			for (var iCont = 0 ; iCont < vContenedor.length ; iCont++)
					vContenedor.item(iCont).disabled = false;
		
		}else{
			bCodigo = 1;
			objBoton.innerText = "Ver diseño";
			
			frmEditor.document.body.innerText = frmEditor.document.body.innerHTML;
		
			var vContenedor = document.getElementById("cldBotones").children;
		
			for (var iCont = 0 ; iCont < vContenedor.length ; iCont++){
					if ((vContenedor.item(iCont).type == "button") && (vContenedor.item(iCont).name != "codigo"))
							vContenedor.item(iCont).disabled = true;
					else
							vContenedor.item(iCont).disabled = false;
			}
		
			var vContenedor = document.getElementById("cldOpciones").children;
		
			for (var iCont = 0 ; iCont < vContenedor.length ; iCont++)
				vContenedor.item(iCont).disabled = true;
		
		}
	}
	
	
		function limpiar_html( $html ) {
// Eliminar todos los atributos class
$html = str_replace("n", '', str_replace("r", '', $html));
$html = preg_replace('/(class|xml:lang|lang)="[ -_a-zA-Z0-9]+"/', '', $html);

// Limpiar etiquetas de word, ...
tidy_parse_string($html);
tidy_setopt('output-xhtml', TRUE);
tidy_setopt('show-body-only', TRUE);
tidy_setopt('drop-proprietary-attributes', TRUE);
tidy_setopt('drop-font-tags', TRUE);
tidy_setopt('word-2000', TRUE);
tidy_setopt('drop-empty-paras', TRUE);
tidy_setopt('clean', TRUE);
tidy_setopt('bare', TRUE);
tidy_setopt('newline', 'LF');
tidy_clean_repair();
$html = tidy_get_output();

// Eliminar los atributos class generados por tidy
$html = str_replace("n", '', $html);
$html = preg_replace('/ class="[ -_a-zA-Z0-9]+"/', '', $html);

// Segunda limpieza, eliminar etiquetas redundantes
tidy_parse_string($html);
tidy_setopt('show-body-only', TRUE);
tidy_setopt('newline', 'LF');
tidy_setopt('merge-divs', TRUE);
$html = tidy_get_output();

// Añadir slash si se desea insertar en base de datos
$html = addslashes($html);
return( str_replace("n", '', $html) );
}
//-->



///////////////////////////////////////////////////////////////////////////////////////////////
// include dinamico ajax

$f=0;
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
		
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {

        xmlhttp.open(sMethod, sURL, true);
		
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
	
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-Type", "ISO-8859-1");
      }
	
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
		 document.getElementById("padre").style.zIndex="1";

    return true;
  };
  return this;
}




function include_dinamico (url,variables,capa,op)
{


	if (op==1)
	{

	var myConn = new XHConn();
	
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");

	var include_terminado = function (oXML) { document.getElementById(capa).innerHTML = oXML.responseText; };

	document.getElementById(capa).innerHTML = "<div id='cargador' style='width=200px; height=200px;' class='cargador'><img src='images/loading.gif' /></div>";

//	myConn.connect(url, "GET", variables, include_terminado);
	$f=1;
	}
	else
	{

		var myConn = new XHConn();

	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");

	var include_terminado = function (oXML) { document.getElementById(capa).innerHTML = oXML.responseText; };

	//document.getElementById(capa).innerHTML = "<div id='cargador' class='cargador'><img src='images/loading.gif' /></div>";
//	document.body.append("<div id='padre'></div>");

	

	document.getElementById(capa).innerHTML = "<div id='cargador' style='width=200px; height=200px;' class='cargador'><img src='images/loading.gif' /></div>";
	

    //document.getElementById("padre").style.zIndex="10";
	//document.getElementById("padre").style.background="#000000";
//document.getElementById("padre").style.filter="alpha(opacity:50)"; 
//div.style.zIndex = "20";
	//div.style.background="#000000";
	//div.style.filter="alpha(opacity:90)"; 
	
	//document.getElementById("padre").style.backgroundColor="#999999";
		//document.getElementById("padre").style.zIndex="1";
//		document.getElementById('padre').style;
		
	myConn.connect(url, "POST", variables, include_terminado);
	
	}
}


function guardaBlur(url,variable,cap) {

	include_dinamico(url,variable,cap);

}


function guardaEnter(url,variable,cap) {

	include_dinamico(url,variable,cap);

}




function guardaEnter(url,variable,evt,cap) {
	evt = (evt) ? evt : window.event;
	if (evt.keyCode == 13) {
		include_dinamico(url,variable,cap);
	} else {
		return true;
	}
}
///////////





function Del() {

alert ("Fsd");
//r=window.clipboardData.getData("Text");
//document.getElementById().innerHTML="fsd";
//str = clipboardData.getData("Text");


//clp = window.clipboardData.getData("Text");
//alert(escape(clp));
//alert ();
	/*Word=c.value;
a = Word.indexOf("<");
b = Word.indexOf(">");
len = Word.length;
c = Word.substring(0, a);
if(b == -1)
b = a;
d = Word.substring((b + 1), len);
Word = c + d;
tagCheck = Word.indexOf("<");
if(tagCheck != -1)
{
Word = Del(Word);
}
document.getElementById("textarea").innerHTML="FSF";
//return Word;*/
}


function iniciar()
{
div = document.createElement("div");
document.body.appendChild(div);
	div.id="padre";
}



	function cargar_div()
	{
	
	document.getElementById("padre").innerHTML="<img src='images/loading.gif' />";
		document.getElementById("padre").style.position="absolute";
	document.getElementById("padre").style.top="40%";
	document.getElementById("padre").style.left="50%";
		document.getElementById("padre").style.width="200px";
		document.getElementById("padre").style.height="200px";
	document.getElementById("padre").style.zIndex="20";
	document.getElementById("padre").style.background="#FFFFFF";
//	alert (document.frmEditor.document.body.innerHTML);
	texto=document.getElementById("frmEditor").innerHTML;

	//alert (texto);
	//texto=escape(texto);
	
		//document.forma.catexto.value=texto;
	
	document.forma.catexto.value=texto;
		document.forma.submit();
	//div = document.createElement("div");
	
	
//	div.id="padre";
	//div.style.width = "100%";
//	div.style.height = "100%";
	//div.style.position="absolute";
	//div.style.zIndex = "20";
	//div.style.background="#000000";
	//div.style.filter="alpha(opacity:90)"; 
	//parent.document.body.appendChild(div);
	}
//	cargar_div();




			estado=1;
								
								function estadoedicion (capita)
								{
								if (estado)
								{
									estado=0;
									
									document.getElementById(capita).style.cursor= "default";
								}
								else
								{
								    estado=1;
									document.getElementById(capita).style.cursor= "hand";
								}
								
								}
								
	function delHTML(){
var re= /<\S[^><]*>/g
r=window.clipboardData.getData("Text");

tex=r.replace (re, "");
window.clipboardData.setData("Text", tex); 

//document.body.innerHTML=tex;
//for (i=0; i<arguments.length; i++)
//arguments[i].value=arguments[i].value.replace(re, "")
//r=window.clipboardData.getData("Text");
//document.getElementById().innerHTML="fsd";
//str = clipboardData.getData("Text");


//clp = window.clipboardData.getData("Text");

}


function editar(capita)
								{
								
								if (document.getElementById(capita).style.visibility=="visible")
								{
								if (estado)
								{
								document.getElementById(capita).style.visibility= "hidden";
									document.getElementById(capita).style.width= "0px";
								document.getElementById(capita).style.height= "0px";
									document.getElementById(capita).style.position= "absolute";
								}
								}
								else
								{
								if (estado)
								{
								document.getElementById(capita).style.visibility= "visible";
								document.getElementById(capita).style.width= "16px";
								document.getElementById(capita).style.height= "16px";
									document.getElementById(capita).style.position= "relative";
									}
								}
								}
