
var dragdiv="";
		
function dstart(event){
	dragStart(event, dragdiv);
}
			
/******************************************/
/**Funciones auxiliares */
/******************************************/	
function setSelectionRange(input, selectionStart, selectionEnd) {
  if (input.setSelectionRange) {
    input.focus();
    input.setSelectionRange(selectionStart, selectionEnd);
  }
  else if (input.createTextRange) {
    var range = input.createTextRange();
    range.collapse(true);
    range.moveEnd('character', selectionEnd);
    range.moveStart('character', selectionStart);
    range.select();
  }
}


function setCaretToPos (input, pos) {
  setSelectionRange(input, pos, pos);
}





/******************************************/
/**Funciones auxiliares del panel de color*/
/******************************************/
			var colors=new Array(122);
			colors[0]='ff0000';
			colors[1]='ffff00';
			colors[2]='00ff00';
			colors[3]='00FFFF';
			colors[4]='0000ff';
			colors[5]='FF00FF';
			colors[6]='ffffff';
			colors[7]='E6E6E6';
			colors[8]='DADADA';
			colors[9]='CDCDCD';
			colors[10]='C0C0C0';
			colors[11]='C1C1C1';
			colors[12]='B4B4B4';
			colors[13]='A7A7A7';
			colors[14]='8E8E8E';
			colors[15]='818181';
			
			colors[16]='ED1C24';
			colors[17]='FFF100';
			colors[18]='00A650';
			colors[19]='00AEEF';
			colors[20]='2F3192';
			colors[21]='ED008C';
			colors[22]='737373';
			colors[23]='666666';
			colors[24]='595959';
			colors[25]='4B4B4B';
			colors[26]='3D3D3D';
			colors[27]='303030';
			colors[28]='212121';
			colors[29]='131313';
			colors[30]='050505';
			colors[31]='000000';
			
			colors[32]='F69679';
			colors[33]='F9AD81';
			colors[34]='FDC689';
			colors[35]='FFF799';
			colors[36]='C4DF9B';
			colors[37]='A3D39C';
			colors[38]='82CA9C';
			colors[39]='7ACCC8';
			colors[40]='6DCFF6';
			colors[41]='7DA7D9';
			colors[42]='8393CA';
			colors[43]='8781BD';
			colors[44]='A186BE';
			colors[45]='BD8CBF';
			colors[46]='F49AC1';
			colors[47]='F5989D';
			
			colors[48]='F16C4D';
			colors[49]='F68E54';
			colors[50]='FBAF5A';
			colors[51]='FFF467';
			colors[52]='ACD372';
			colors[53]='A4D49D';
			colors[54]='81CA9D';
			colors[55]='7BCDC9';
			colors[56]='6CCFF7';		
			colors[57]='7CA6D8';
			colors[58]='8293CA';
			colors[59]='8881BE';
			colors[60]='A286BD';
			colors[61]='BC8CBF';
			colors[62]='F49BC1';
			colors[63]='F5999D';
			
			colors[64]='EE1D24';
			colors[65]='F16522';
			colors[66]='F7941D';
			colors[67]='FFF100';
			colors[68]='8FC63D';
			colors[69]='37B44A';
			colors[70]='00A650';
			colors[71]='00A99E';
			colors[72]='00AEEF';
			colors[73]='0072BC';
			colors[74]='0054A5';
			colors[75]='2F3192';
			colors[76]='652C91';
			colors[77]='91278F';
			colors[78]='ED008C';
			colors[79]='EE105A';
			
			colors[80]='9D0A0F';
			colors[81]='A1410D';
			colors[82]='A36209';
			colors[83]='ABA000';
			colors[84]='588528';
			colors[85]='197B30';
			colors[86]='007236';
			colors[87]='00736A';
			colors[88]='0076A4';
			colors[89]='004A80';
			colors[90]='003370';
			colors[91]='1D1363';
			colors[92]='450E61';
			colors[93]='62055F';
			colors[94]='9D005C';
			colors[95]='9D0039';
			
			colors[96]='790000';
			colors[97]='7B3000';
			colors[98]='7C4900';
			colors[99]='827A00';
			colors[100]='3E6617';
			colors[101]='045F20';
			colors[102]='005824';
			colors[103]='005951';
			colors[104]='005B7E';
			colors[105]='003562';
			colors[106]='002056';
			colors[107]='0C004B';
			colors[108]='30004A';
			colors[109]='4B0048';
			colors[110]='7A0045';
			colors[111]='7A0026';
			
			colors[112]='C7B198';
			colors[113]='9A8575';
			colors[114]='726357';
			colors[115]='534841';
			colors[116]='362F2C';
			colors[117]='C69C6D';
			colors[118]='A77C50';
			colors[119]='8C623A';
			colors[120]='744B24';
			colors[121]='613813';
			


var colorpanelopened=false;
var inp;

function showColorPanel(bttn,input,sendto,selector_color) { 
		 if(fontsizepanelopened){
			//si esta abierto el panel de tamaņo de texto lo cierro
			document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsize'));
			fontsizepanelopened=false;
		}

		if(smileyspanelopened){
			//si esta abierto el panel de color lo chapo
			document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));
			smileyspanelopened=false;
		}
				
		if(!colorpanelopened){
			 var w=180;
			 var h=147;
			 
			 var x=(findPosX(bttn)) ;
			 
			 var y=(findPosY(bttn) + findObjHeight(bttn));
			
			dragdiv='promptcolor';
	  	  	   		
			promptbox = document.createElement('div'); 
			promptbox.setAttribute ('id' , 'promptcolor') 
			promptbox.style.position='absolute';
			promptbox.style.width=w+'px';
	    promptbox.style.height=h+'px';
	    promptbox.style.left=x+'px';
	    promptbox.style.top=y+'px';
			promptbox.className='panel';
			
			prompttitbox = document.createElement('div'); 
			prompttitbox.setAttribute ('id' , 'promptcolortit') 
	    prompttitbox.style.height=18+'px';
	    prompttitbox.className='paneltitbar';
	    prompttitbox.innerHTML=selector_color;
	    promptbox.appendChild(prompttitbox);
			addEvent(prompttitbox,'mousedown', dstart); 
	
			promptcontentbox = document.createElement('div'); 
			promptcontentbox.setAttribute('id' , 'promptcolorcontent') 
	    promptbox.appendChild(promptcontentbox);  	
	   			
			
				
			var cuerpo = "";

	
			cuerpo+=" <table class=\"colores\" cellspacing='0' cellpadding='0' border='0' width='100%'>";
			cuerpo+=" <tr>";
			for(j=0;j<colors.length;j++){
				cuerpo+=" <td style=\"background-color:#"+colors[j]+"\" onMouseDown=\""+sendto+"('"+colors[j]+"');document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptcolor'));colorpanelopened=false;\">&nbsp;</td>";
				if((j+1)%16==0){
					cuerpo+=" </tr>";
					cuerpo+=" <tr>";
				}
			}
			
			
			cuerpo+=" </tr>";
			cuerpo+=" <tr>";
			cuerpo+=" <th align='right' colspan=16>";
			cuerpo+=" <input type='button' class='foro' value='Cancel' onClick='" + sendto + "(\"\"); document.getElementsByTagName(\"body\")[0].removeChild(document.getElementById(\"promptcolor\"));colorpanelopened=false;'>";
			cuerpo+=" </th></tr>";
			cuerpo+=" </table>";
			
			promptcontentbox.innerHTML=cuerpo;
			document.getElementsByTagName('body')[0].appendChild(promptbox);
	
			input.focus();
			colorpanelopened=true;
		 
		}

} 

/**Funcion que muestra el panel de color*/
function promptColor(num,bttn,input,selector_color){
	inp=input;
	edit(num,input);
	showColorPanel(bttn,input,'setColor');
}




/******************************************/
/**Functiones auxiliares de panel de texto*/
/******************************************/
var fontsizepanelopened=false;

function showFontSizePanel(bttn,input,sendto,tamano_fuente){ 
		if(colorpanelopened){
			//si esta abierto el panel de color lo chapo
			document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptcolor'));
			colorpanelopened=false;
		}
		
		if(smileyspanelopened){
			//si esta abierto el panel de color lo chapo
			document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));
			smileyspanelopened=false;
		}
		
		 if(!fontsizepanelopened){
			 var w=150;
			 var h=100;
			 
			 var x=(findPosX(bttn)) ;
			 
			 var y=(findPosY(bttn) + findObjHeight(bttn));
			
			dragdiv='promptsize';
	  	  	   		
			promptbox = document.createElement('div'); 
			promptbox.setAttribute ('id' , 'promptsize') 
			promptbox.style.position='absolute';
			promptbox.style.width=w+'px';
	    promptbox.style.height=h+'px';
	    promptbox.style.left=x+'px';
	    promptbox.style.top=y+'px';
			promptbox.className='panel';
			
			prompttitbox = document.createElement('div'); 
			prompttitbox.setAttribute ('id' , 'promptsizetit') 
	    prompttitbox.style.height=18+'px';
	    prompttitbox.className='paneltitbar';
	    prompttitbox.innerHTML=tamano_fuente;
	    promptbox.appendChild(prompttitbox);
			addEvent(prompttitbox,'mousedown', dstart); 
	
			promptcontentbox = document.createElement('div'); 
			promptcontentbox.setAttribute ('id' , 'promptsizecontent') 
	    promptbox.appendChild(promptcontentbox);  	
	   			
			
				
			var cuerpo = "";
			cuerpo+=" <table class=\"textSize\" cellspacing='5' cellpadding='0' border='0' width='100%'>";
			cuerpo+=" <tr>";
			cuerpo+=" <td style=\"font-size:3px\" onMouseDown=\""+sendto+"('3');document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsize'));fontsizepanelopened=false;\">A</td>";
			cuerpo+=" <td style=\"font-size:5px\" onMouseDown=\""+sendto+"('5');document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsize'));fontsizepanelopened=false;\">A</td>";
			cuerpo+=" <td style=\"font-size:7px\" onMouseDown=\""+sendto+"('7');document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsize'));fontsizepanelopened=false;\">A</td>";
			cuerpo+=" <td style=\"font-size:9px\" onMouseDown=\""+sendto+"('9');document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsize'));fontsizepanelopened=false;\">A</td>";
			cuerpo+=" <td style=\"font-size:10px\" onMouseDown=\""+sendto+"('10');document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsize'));fontsizepanelopened=false;\">A</td>";
			cuerpo+=" <td style=\"font-size:12px\" onMouseDown=\""+sendto+"('12');document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsize'));fontsizepanelopened=false;\">A</td>";
			cuerpo+=" </tr>";
			cuerpo+=" <tr>";
			cuerpo+=" <td style=\"font-size:13px\" onMouseDown=\""+sendto+"('13');document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsize'));fontsizepanelopened=false;\">A</td>";
			cuerpo+=" <td style=\"font-size:15px\" onMouseDown=\""+sendto+"('15');document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsize'));fontsizepanelopened=false;\">A</td>";
			cuerpo+=" <td style=\"font-size:17px\" onMouseDown=\""+sendto+"('17');document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsize'));fontsizepanelopened=false;\">A</td>";
			cuerpo+=" <td style=\"font-size:19px\" onMouseDown=\""+sendto+"('19');document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsize'));fontsizepanelopened=false;\">A</td>";
			cuerpo+=" <td style=\"font-size:20px\" onMouseDown=\""+sendto+"('20');document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsize'));fontsizepanelopened=false;\">A</td>";
			cuerpo+=" <td style=\"font-size:22px\" onMouseDown=\""+sendto+"('22');document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsize'));fontsizepanelopened=false;\">A</td>";
			cuerpo+=" </tr>";
			cuerpo+=" <tr>";
			cuerpo+=" <th align='right' colspan=6>";
			cuerpo+=" <input type='button' class='foro' value='Cancel'  onClick='" + sendto + "(\"\"); document.getElementsByTagName(\"body\")[0].removeChild(document.getElementById(\"promptsize\"));fontsizepanelopened=false;'>";
			cuerpo+=" </th></tr>";
			cuerpo+=" </table>";
			
			promptcontentbox.innerHTML=cuerpo;
			document.getElementsByTagName('body')[0].appendChild(promptbox);
	
			input.focus();
			fontsizepanelopened=true;
		 
		}

} 


/**Funcion que muestra el panel de texto*/
function promptTextSize(num,bttn,input,tamano_fuente){
	inp=input;
	edit(num,input);
	showFontSizePanel(bttn,input,'setSize',tamano_fuente);
}



/********************************************/
/**Functiones auxiliares de panel de smileys*/
/********************************************/
var smileyspanelopened=false;

function showSmileysPanel(frm,bttn,input,sendto,selector_smileys){ 
		if(colorpanelopened){
			//si esta abierto el panel de color lo chapo
			document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptcolor'));
			colorpanelopened=false;
		}
		if(fontsizepanelopened){
			//si esta abierto el panel de color lo chapo
			document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsize'));
			fontsizepanelopened=false;
		}
		
		 if(!smileyspanelopened){
			 var w=137;
			 var h=90;
			 
			 var x=(findPosX(bttn)) ;
			 
			 var y=(findPosY(bttn) + findObjHeight(bttn));
			
			dragdiv='promptsmiley';
	  	  	   		
			promptbox = document.createElement('div'); 
			promptbox.setAttribute ('id' , dragdiv) 
			promptbox.style.position='absolute';
			promptbox.style.width=w+'px';
	    //promptbox.style.height=h+'px';
	    promptbox.style.left=x+'px';
	    promptbox.style.top=y+'px';
			promptbox.className='panel';
			
			prompttitbox = document.createElement('div'); 
			prompttitbox.setAttribute ('id' , 'promptsmileytit') 
	    prompttitbox.style.height=18+'px';
	    prompttitbox.className='paneltitbar';
	    prompttitbox.innerHTML=selector_smileys;
	    promptbox.appendChild(prompttitbox);
			addEvent(prompttitbox,'mousedown', dstart); 
	
			promptcontentbox = document.createElement('div'); 
			promptcontentbox.setAttribute ('id' , 'promptsmileycontent') 
	    promptbox.appendChild(promptcontentbox);  	
	   			
			
				
			var cuerpo = "";
			cuerpo+=" <img style=\"cursor:pointer\" src=\"images/smileys/sonrisa.gif\" onclick=\"addSmiley('sonrisa',document."+frm.name+".ta); document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));smileyspanelopened=false;\" />";
			cuerpo+=" <img style=\"cursor:pointer\" src=\"images/smileys/risa.gif\"  onclick=\"addSmiley('risa',document."+frm.name+".ta); document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));smileyspanelopened=false;\" />";
			cuerpo+=" <img style=\"cursor:pointer\" src=\"images/smileys/carcajada.gif\"  onclick=\"addSmiley('carcajada',document."+frm.name+".ta); document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));smileyspanelopened=false;\" />";
			cuerpo+=" <img style=\"cursor:pointer\" src=\"images/smileys/triste.gif\" onclick=\"addSmiley('triste',document."+frm.name+".ta); document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));smileyspanelopened=false;\" />";
			cuerpo+=" <img style=\"cursor:pointer\" src=\"images/smileys/lengua.gif\" onclick=\"addSmiley('lengua',document."+frm.name+".ta); document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));smileyspanelopened=false;\" />";
			cuerpo+=" <img style=\"cursor:pointer\" src=\"images/smileys/guinyo.gif\"  onclick=\"addSmiley('guinyo',document."+frm.name+".ta); document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));smileyspanelopened=false;\" />";
			cuerpo+=" <img style=\"cursor:pointer\" src=\"images/smileys/avergonzado.gif\"  onclick=\"addSmiley('avergonzado',document."+frm.name+".ta); document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));smileyspanelopened=false;\" />";
			cuerpo+=" <img style=\"cursor:pointer\" src=\"images/smileys/preocupado.gif\"  onclick=\"addSmiley('preocupado',document."+frm.name+".ta); document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));smileyspanelopened=false;\" />";
			cuerpo+=" <img style=\"cursor:pointer\" src=\"images/smileys/sorpresa.gif\"  onclick=\"addSmiley('sorpresa',document."+frm.name+".ta); document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));smileyspanelopened=false;\" />";
			cuerpo+=" <img style=\"cursor:pointer\" src=\"images/smileys/llanto.gif\"  onclick=\"addSmiley('llanto',document."+frm.name+".ta); document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));smileyspanelopened=false;\" />";
			cuerpo+=" <img style=\"cursor:pointer\" src=\"images/smileys/corazon.gif\"  onclick=\"addSmiley('corazon',document."+frm.name+".ta); document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));smileyspanelopened=false;\" />";
			cuerpo+=" <img style=\"cursor:pointer\" src=\"images/smileys/pensativo.gif\"  onclick=\"addSmiley('pensativo',document."+frm.name+".ta); document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));smileyspanelopened=false;\" />";
			cuerpo+=" <img style=\"cursor:pointer\" src=\"images/smileys/sospechoso.gif\"  onclick=\"addSmiley('sospechoso',document."+frm.name+".ta); document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));smileyspanelopened=false;\" />";
			cuerpo+=" <img style=\"cursor:pointer\" src=\"images/smileys/enfadado.gif\"  onclick=\"addSmiley('enfadado',document."+frm.name+".ta); document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));smileyspanelopened=false;\" />";
			cuerpo+=" <img style=\"cursor:pointer\" src=\"images/smileys/chulo.gif\"  onclick=\"addSmiley('chulo',document."+frm.name+".ta); document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));smileyspanelopened=false;\" />";
			cuerpo+=" <img style=\"cursor:pointer\" src=\"images/smileys/fiesta.gif\"  onclick=\"addSmiley('fiesta',document."+frm.name+".ta); document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));smileyspanelopened=false;\" />";
			cuerpo+=" <img style=\"cursor:pointer\" src=\"images/smileys/rujada.gif\"  onclick=\"addSmiley('rujada',document."+frm.name+".ta); document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));smileyspanelopened=false;\" />";
			cuerpo+=" <img style=\"cursor:pointer\" src=\"images/smileys/chiton.gif\"  onclick=\"addSmiley('chiton',document."+frm.name+".ta); document.getElementsByTagName('body')[0].removeChild(document.getElementById('promptsmiley'));smileyspanelopened=false;\" />";

			cuerpo+=" <table class=\"textSize\" cellspacing='5' cellpadding='0' border='0'  width='100%'>";
			cuerpo+=" <tr>";
			cuerpo+=" <th align='right'>";
			cuerpo+=" <input type='button' class='foro' value='Cancel' onClick='" + sendto + "(\"\"); document.getElementsByTagName(\"body\")[0].removeChild(document.getElementById(\"promptsmiley\"));smileyspanelopened=false;'>";
			cuerpo+=" </th></tr>";
			cuerpo+=" </table>";
			
			promptcontentbox.innerHTML=cuerpo;
			document.getElementsByTagName('body')[0].appendChild(promptbox);
	
			input.focus();
			smileyspanelopened=true;
		 
		}

} 



/**Funcion que muestra el panel de smileys*/
function promptSmileys(num,frm,bttn,input,selector_smileys){
	inp=input;
	edit(num,input);
	showSmileysPanel(frm,bttn,input,'addSmiley',selector_smileys);
}




/******************************************************/
/******************************************************/
/******************************************************/
/******************************************************/



/**Funciones de estilo del area de texto*/
function setBold(num,input){
	 edit(num,input);
	 setTag('b',input,'','');
}

function setItalic(num,input){
	 edit(num,input);
	 setTag('i',input,'','');
}
function setUnderline(num,input){
	 edit(num,input);
	 setTag('u',input,'','');
}



/**funcion que aņade una url al editor */
function addUrl(num,input,url_pagina,nombre_pagina){
	edit(num,input);
	
	var datos="";
	var contenido="";
	
	datos=prompt(url_pagina);
	if(datos==null ||datos==undefined) return;
	
	if(input.setSelectionRange){
	  var selectionStart = input.selectionStart;
    var selectionEnd = input.selectionEnd;
    if(selectionStart==selectionEnd){
    	contenido=prompt(nombre_pagina);
    	if(contenido==null ||contenido==undefined) return;
	
    }else{
    	contenido=input.value.substring(selectionStart, selectionEnd);
   
    }
	}else{ 		//si explorer
  	var range = document.selection.createRange();
  	var txtanterior=range.text;
  	if(range.text == ''){
  		contenido=prompt(nombre_pagina);
  		if(contenido==null ||contenido==undefined) return;
	
    }else{
    	contenido=range.text;
    }
  }
  
  setTag('url',input,datos,contenido);
}


/**funcion que aņade una imagen al editor */
function addImage(num,input,url_imagen){
  edit(num,input);
	var datos="";
	var contenido="";
	
	datos=prompt(url_imagen);
	if(datos==null ||datos==undefined) return;
	
	if(input.setSelectionRange){
	  var selectionStart = input.selectionStart;
    var selectionEnd = input.selectionEnd;
    if(selectionStart!=selectionEnd){
    	contenido=input.value.substring(selectionStart, selectionEnd);
   
    }
	}else{ 		//si explorer
  	var range = document.selection.createRange();
  	var txtanterior=range.text;
  	if(range.text != ''){
  		contenido=range.text;
    }
  }
  
  setTag('img',input,datos,contenido);
}



/**funcion que define el color al texto */
function setColor(value) { 
	var contenido="";
	
	if(value.length<=0){

	 return false;

	}else{
		if(inp.setSelectionRange){
		  var selectionStart = inp.selectionStart;
	    var selectionEnd = inp.selectionEnd;
	    if(selectionStart!=selectionEnd){
	    	contenido=inp.value.substring(selectionStart, selectionEnd);
	    }
		}else{ 		//si explorer
	  	var range = document.selection.createRange();
	  	var txtanterior=range.text;
	  	if(range.text != ''){
	  		contenido=range.text;
	    }
	  }

		setTag('color',inp,value,contenido);

	}
} 


/**funcion que define el tamaņo al texto */
function setSize(value){
	var contenido="";
	
	if(value.length<=0){

	 return false;

	}else{
		if(inp.setSelectionRange){
		  var selectionStart = inp.selectionStart;
	    var selectionEnd = inp.selectionEnd;
	    if(selectionStart!=selectionEnd){
	    	contenido=inp.value.substring(selectionStart, selectionEnd);
	    }
		}else{ 		//si explorer
	  	var range = document.selection.createRange();
	  	var txtanterior=range.text;
	  	if(range.text != ''){
	  		contenido=range.text;
	    }
	  }

		setTag('size',inp,value,contenido);

	}
} 



/**funcion que aņade un smiley al editor */
function addSmiley(value){
	if(value.length<=0){
		 return false;
	}else{
		setTag('smiley',inp,value+'.gif','');
	}
}


/**funcion que aņade una etiqueta al editor */
function setTag(tag, input,datos, contenido){
	
	var opentag='';
	var closetag='';
	switch(tag){
		case 'b':
		case 'u':
		case 'i':
			opentag='['+tag+']';
			closetag='[/'+tag+']';
			break;
		case 'url':
			var theurl='src=\"'+ datos + '\"';
			opentag= '['+tag+' '+ theurl+']';
			closetag='[/'+tag+']';
			break;
		case 'img':
			var theurl='src=\"'+ datos + '\"';
			opentag= '['+tag+' '+ theurl+'/]';
			closetag='';
			break;
		case 'smiley':
			var theurl='face=\"'+ datos + '\"';
			opentag= '['+tag+' '+ theurl+'/]';
			closetag='';
			break;
		case 'color':
			var theurl='color=\"#'+ datos + '\"';
			opentag= '[font '+ theurl+']';
			closetag='[/font]';
			break;
		case 'size':
			var theurl='size=\"'+ datos + 'px\"';
			opentag= '[font '+ theurl+']';
			closetag='[/font]';
			break;
		default:break;
			
	}
	
	input.focus();
	
	if (input.setSelectionRange){//si mozilla
	
    var selectionStart = input.selectionStart;
    var selectionEnd = input.selectionEnd;
    
    var txt=input.value.substring(selectionStart, selectionEnd);
    if(txt=='') txt=contenido;
    
    input.value = input.value.substring(0, selectionStart) + opentag + txt + closetag + input.value.substring(selectionEnd);
    if (selectionStart != selectionEnd){ // has there been a selection
      setSelectionRange(input, selectionStart, selectionEnd + opentag.length + closetag.length);
    }else{ // set caret
      setCaretToPos(input, selectionStart + opentag.length);
    }

  }else{ 		//si explorer
  	var range = document.selection.createRange();
  	if (range.parentElement() == input ) {
      
   		var isCollapsed = range.text == '';
      var txtanterior=range.text;
      if(txtanterior.length==0) txtanterior=contenido;
      
      range.text = opentag+txtanterior+closetag;
      if(!isCollapsed){
      	var replaceString=opentag+txtanterior+closetag;
      	range.moveStart('character', -replaceString.length);
        range.select();	
      }else{
      	range.moveStart('character', -closetag.length);
        range.moveEnd('character', -closetag.length);
        range.select();	
      }
    }
  }
  
 input.focus();
 
}






/**funcion que transforma el lenguaje de etiquetas a HTML */
function Tag2HTML(input){
	var txt=input.value;
	var myregexp = new RegExp("[b]");
	txt=txt.replace(/\[b\]/g,'<b>');
	txt=txt.replace(/\[\/b\]/g,'</b>');
	txt=txt.replace(/\[u\]/g,'<u>');
	txt=txt.replace(/\[\/u\]/g,'</u>');
	txt=txt.replace(/\[i\]/g,'<i>');
	txt=txt.replace(/\[\/i\]/g,'</i>');
	txt=txt.replace(/\[smiley face=\"/g,'<img border="0" src="images/smileys/');
	txt=txt.replace(/\[url src=\"/g,'<a target="_blank" href="');
	txt=txt.replace(/\[\/url\]/g,'</a>');
	txt=txt.replace(/\[img src=\"/g,'<img border="0" src="');
	txt=txt.replace(/\[font color=\"/g,'<font style="color:');
	txt=txt.replace(/\[font size=\"/g,'<font style="font-size:');
	txt=txt.replace(/\[\/font\]/g,'</font>');
//	txt=txt.replace(/\[\/size\]/g,'</u>');
	
	txt=txt.replace(/\"\/]/g,'">');
	txt=txt.replace(/\"]/g,'">');
	txt=txt.replace(/\n/g,'<br/>\n');
	
	return txt;
	//document.getElementById("htmlfield").innerHTML=txt;
	
}


var prev=false;
function preview(num,input){
	var editbtn=getObj("editbutton"+num);
	var viewbtn=getObj("previewbutton"+num);
		
	if(!prev){
		var ident='previewbox';
		promptbox = document.createElement('div'); 
		promptbox.setAttribute ('id' , ident);
		 
		promptbox.style.position='absolute';
		
	  if(!input.setSelectionRange){
	  	promptbox.style.height=(findObjHeight(input)-2)+'px';
	  	promptbox.style.width=(findObjWidth(input)-2)+'px';
	  }else{
	  	promptbox.style.height=(findObjHeight(input))+'px';
	 		promptbox.style.width=findObjWidth(input)+'px';
	  }
	  promptbox.style.left=findPosX(input)+'px';
	  promptbox.style.top=findPosY(input)+'px';
	  promptbox.style.overflow='auto';
	  promptbox.className='previewbox';
	  promptbox.style.zindex=100;
		promptbox.innerHTML=Tag2HTML(input);
		document.getElementsByTagName('body')[0].appendChild(promptbox);
		//btn.value='Edit';
		input.disabled=true;
		prev=true;
		editbtn.className='foroUnselected';
		viewbtn.className='foroSelected';
		editbtn.style.zindex=0;
		viewbtn.style.zindex=1000;
		
	}
	
}

function edit(num,input){
	var editbtn=getObj("editbutton"+num);
	var viewbtn=getObj("previewbutton"+num);
	
	if(prev){
		document.getElementsByTagName('body')[0].removeChild(document.getElementById('previewbox'));
		input.disabled=false;
		//btn.value='Preview';
		prev=false;
		editbtn.className='foroSelected';
		viewbtn.className='foroUnselected';
		editbtn.style.zindex=1000;
		viewbtn.style.zindex=0;
	}	
}
