// Activar el modo diseņo para el IFrame
var timeOut = 500;
function initIFrameEditor(_f, _i, _c, _theNextAction) {
	if(!arguments.length>0){
		frames.iframeEditor.document.designMode = "On";
	}else{
		editFrame=eval("window.frames."+_i+".document");
		f = eval(_f);
		inputForm = eval("f.elements." + _c);
		inputValue = inputForm.value;
		//
		editFrame.designMode = "On";
		//
		if(arguments.length>=4){
			setTimeout("subInitIFrameEditor(editFrame, inputValue); eval("+_theNextAction+");", timeOut);
		}else{
			setTimeout("subInitIFrameEditor(editFrame, inputValue);", timeOut);
		}
	}
}
function subInitIFrameEditor(_i, _v) {
	_i.body.innerHTML+=_v;
}

function resetIFrameEditor(_f, _i, _c) {
	editFrame=eval("window.frames."+_i+".document");
	f = eval(_f);
	inputForm = eval("f.elements." + _c);
	inputValue = inputForm.value;
	//
	editFrame.designMode = "On";
	//
	editFrame.body.innerHTML = inputValue;
}

function doFormat(_i, what) {
	editFrame=eval("window.frames."+_i);
    var tr = editFrame.document.selection.createRange()
    tr.execCommand(what, false, null);
    tr.select()
    editFrame.focus()
 }

function copyValue(_f, _i, _c) {
	f=eval(_f);
	editFrame=eval("window.frames."+_i);
	
	iFrameValue=editFrame.document.body.innerHTML;

	// formatear texto
	var iFrameValueArray = iFrameValue.split("</P>");
	iframeValue="";
	for(i=0; i<iFrameValueArray.length; i++) {
		iFrameValueArray[i] = iFrameValueArray[i].replace("<P>", "");
		iFrameValueArray[i] = iFrameValueArray[i].replace("<p>", "");
		var breaking = "<br/>";
		if(iFrameValueArray[i]!="")
		{
			if(i==0) breaking="";
			iframeValue = iframeValue + breaking + iFrameValueArray[i];
		}
	}
	
	campo = eval("f.elements." + _c);
	campo.value = iframeValue;
	
	return true;
}
