function Msg(instancia, contenido, estilo){
	this.instancia=instancia;
    if(typeof(contenido)=='undefined') this.contenido='';
    else this.content=contenido;
	if(typeof(estilo)=='undefined') this.estilo='';
    else this.estilo=estilo;
    this.ancho=600;
	this.alto=200;
    this.cont_frame=this.instancia+'_Msg';
    this.cont_hidden=this.instancia+'_mensaje';
    this.filas=Math.round(this.alto/15);
    this.cols=Math.round(this.ancho/8);
}

Msg.prototype.copiar = function (){
    var contenido=document.getElementById(this.cont_frame).contentWindow.document.body.innerHTML;
    document.getElementById(this.cont_hidden).value=contenido;
    return true;
}

Msg.prototype.mostrar = function (){
    if(this.isSupported()){
        document.getElementById(this.instancia+'_mensaje').style.display = "none";
    	document.write('<iframe id="'+this.cont_frame+'" style="margin: 0px 0px 0px 10px; background-color: white; color: black; width:'+this.ancho+'px; height:'+this.alto+'px;"></iframe>');
        document.getElementById(this.cont_hidden).value=this.content;
        var contenido = document.getElementById(this.cont_frame).contentWindow.document;
        contenido.designMode='On';
        contenido = document.getElementById(this.cont_frame).contentWindow.document;
        contenido.open();
        contenido.write('<html><head>');
        if (this.estilo) contenido.write('<style type="text/css">@import url('+this.estilo+');</style>');
		contenido.write('<style type="text/css">');
		contenido.write('<!--');
		contenido.write('body{margin:6px;}');
		contenido.write('body p{margin:0px;padding:0px;}');
		contenido.write('-->');
		contenido.write('</style>');
        contenido.write('</head><body>');
        contenido.write(this.content);
        contenido.write('</body></html>');
        contenido.close();
    }
}

Msg.prototype.doTextFormat = function (command, optn, evnt){
	var frame=document.getElementById(this.cont_frame).contentWindow;
    if(frame.document.queryCommandEnabled(command)){
              frame.document.execCommand(command, false, optn);
    }else return false;
    frame.focus();
	return true;
}

Msg.prototype.setColor = function (color, command){
    if((command == 'hilitecolor') && this.isMSIE()) command = 'backcolor';
	var frame=document.getElementById(this.cont_frame).contentWindow;
	frame.focus()
    /*var sel=frame.document.selection;
    if(sel!=null) rng=sel.createRange();*/
    if(frame.document.queryCommandEnabled(command)){
        frame.document.execCommand(command, false, color);
    }else return false;
    frame.focus();
    return true;
}

Msg.prototype.isSupported = function () {
    document.write('<iframe id="prueba" style="display: none; visibility: hidden;"></iframe>');
    test = typeof(document.getElementById('prueba').contentWindow);
    if(test == 'object'){
        return true;
    }else{
        return false;
    }
    return this.supported;
}

Msg.prototype.isMSIE = function (){
    return (navigator.appVersion.indexOf("MSIE") != -1);
}

Msg.prototype.actpanel = function (color,command)
{
	document.getElementById('postizq').style.display='none';
	//document.getElementById('botoncolor').style.backgroundColor='#'+color;
	this.setColor('#'+color,command);
}

Msg.prototype._color = function (color,command)
{
	return '<td style="background-color:#'+color+'"><a class="paleta" href="#" onclick="'+this.instancia+'.actpanel(\''+color+'\',\''+command+'\');return false;"></a></td>';
}

Msg.prototype.colores = function (tipo)
{
	var op=document.getElementById('postizq');
	if (op.style.display=='none')
	{
		var command,i,j,s;
		var dat = new Array("FFFFFF","CCCCCC","AFAFAF","999999","666666","333333","000000", "FF0000","FFCCCC","FF6666","CC0000","990000","660000","330000", "FF9933","FFCC99","FF9966","FF9900","FF6600","CC6600","993300", "FFFF00","FFFF99","FFFF66","FFCC66","CC9933","999900","666600", "00FF00","99FF99","66FF99","33CC00","009900","006600","003300", "33FFFF","99FFFF","66CCCC","00CCCC","339999","336666","003333", "0000FF","CCFFFF","66FFFF","33CCFF","3366FF","000099","000066", "6633FF","CCCCFF","9999FF","6666CC","6600CC","333399","330099", "CC33CC","FFCCFF","FF99FF","CC66CC","993399","663399","330033");
		if (tipo==0) command='forecolor';
		else command='hilitecolor';
		s='<table border="0" cellpadding="0" cellspacing="1">';
		for (j=0;j<9;j++)
		{
			s+='<tr>';
			for (i=0;i<7;i++)
				s+=this._color(dat[j*7+i],command);
			s+='</tr>';
		}
		s+='</table>';
		op.innerHTML=s;
		op.style.display='block';
	}
	else op.style.display='none';
}

Msg.prototype.addicono = function (n)
{
	document.getElementById('postizq').style.display='none';
	var frame=document.getElementById(this.cont_frame).contentWindow;
	x=(n%5)*20;
	y=(parseInt(n/5))*20;
	frame.focus();
    var sel=frame.document.selection;
	if (this.isMSIE())
	{
		if (sel!=null) rng=sel.createRange();
		else rng=frame.document.body.createTextRange();
		rng.pasteHTML('<span class="lpyico" style="background-position:-'+x+'px -'+y+'px">&#160;</span>');
	}
	else
	{
		sel=frame.getSelection();
		var rng=sel.getRangeAt(0);
		rng.deleteContents();
		var sp=document.createElement('span');
		sp.setAttribute('class','lpyico');
		sp.setAttribute('style','background-position:-'+x+'px -'+y+'px');
		sp.innnerHTML='&#160;';
		rng.insertNode(sp);
	}
	frame.focus();
    return true;
}

Msg.prototype.iconos = function ()
{
	var op=document.getElementById('postizq');
	if (op.style.display=='none')
	{
		var command,i,j,n,x,y,s;
		s='';
		for (j=0;j<6;j++)
		{
			for (i=0;i<5;i++)
			{
				n=5*j+i;
				x=20*i;
				y=20*j;
				s+='<a class="botonico" style="background-position:-'+x+'px -'+y+'px" href="#" onclick="'+this.instancia+'.addicono(\''+n+'\');return false;">&nbsp;</a>';
			}
		}
		op.innerHTML=s;
		op.style.display='block';
	}
	else op.style.display='none';
}
