// JavaScript Document
function init(){
incluidos=init.arguments;
for(i=0;i<incluidos.length;i++){
var cuerpo=document.body.innerHTML;
html="<div id=\"tools\"><div onclick=\"instag('b','"+incluidos[i]+"')\" id=\"toolsquare\"><img src=\"images/bbcode/bold.gif\" title=\"Negrita\"></div> <div id=\"toolsquare\" onclick=\"instag('u','"+incluidos[i]+"')\"><img src=\"images/bbcode/underline.gif\" title=\"Subrayado\"></div> <div id=\"toolsquare\" onclick=\"instag('i','"+incluidos[i]+"')\"><img src=\"images/bbcode/italic.gif\" title=\"Cursiva\"></div> <div id=\"toolsquare\" onclick=\"instag('h2','"+incluidos[i]+"')\"><img src=\"images/bbcode/h2.gif\" title=\"Títulos H2\"></div> <div id=\"toolsquare\" onclick=\"instag('h3','"+incluidos[i]+"')\"><img src=\"images/bbcode/h3.gif\" title=\"Subtítulos H3\"></div> <div id=\"toolsquare\" onclick=\"instag('h4','"+incluidos[i]+"')\"><img src=\"images/bbcode/h4.gif\" title=\"Subtítulos H4\"></div> <div id=\"toolsquare\" onclick=\"instag('left','"+incluidos[i]+"')\"><img src=\"images/bbcode/justifyleft.gif\" title=\"Justificar hacia la izquierda\"></div> <div id=\"toolsquare\" onclick=\"instag('center','"+incluidos[i]+"')\"><img src=\"images/bbcode/justifycenter.gif\" title=\"Centrar\"></div> <div id=\"toolsquare\" onclick=\"instag('right','"+incluidos[i]+"')\"><img src=\"images/bbcode/justifyright.gif\" title=\"Justificar hacia la derecha\"></div> <div id=\"toolsquare\" onclick=\"inslink('"+incluidos[i]+"')\"><img src=\"images/bbcode/link.gif\" title=\"Insertar enlace\"></div> <div id=\"toolsquare\" onclick=\"captura_imag('"+incluidos[i]+"')\"><img src=\"images/bbcode/insertimage.gif\" title=\"Insertar imagen\"></div> <div id=\"toolsquare\" onclick=\"captura_vid('"+incluidos[i]+"')\"><img src=\"images/bbcode/youtube.gif\" title=\"Insertar video\"></div> <div id=\"toolsquare\" onclick=\"instag('code','"+incluidos[i]+"')\"><img src=\"images/bbcode/code.gif\" title=\"Código\"></div> <div id=\"toolsquare\" onclick=\"instag('quote','"+incluidos[i]+"')\"><img src=\"images/bbcode/quote.gif\" title=\"Citar\"></div> <div id=\"toolsquare\" onclick=\"ins_imag('•','"+incluidos[i]+"')\"><img src=\"images/bbcode/bullist.gif\" title=\"Viñeta\" /></div></div><textarea name=\""+incluidos[i]+"\" cols=\"45\" rows=\"5\" id=\""+incluidos[i]+"\">";
pat="<textarea+[^>]*"+incluidos[i]+"+[^<]+";
patron =new RegExp(pat,"gi");
coincidencias=new Array();
coincidencias=cuerpo.match(patron);
for(j=0;j<coincidencias.length;j++){
result=new Array();
result=coincidencias[j].match(/\s+id=[^>\s]+/g);
result[0]=result[0].split('"').join('');
result[0]=result[0].split('id=').join('');
result[0]=result[0].split(' ').join('');
if(result[0]==incluidos[i]){
valor=new Array();
valor2='';
valor=coincidencias[j].split('>');
if(valor.length>1){
for(k=1;k<valor.length;k++){
valor2+=valor[k];
}
}
cuerpo2=cuerpo.split(coincidencias[j]);
}
}
document.body.innerHTML=cuerpo2[0]+html+valor2+cuerpo2[1];
}
}
function instag(tag,campo){
var input = document.getElementById(campo);
if(typeof document.selection != 'undefined' && document.selection) {
var str = document.selection.createRange().text;
input.focus();
var sel = document.selection.createRange();
sel.text = "[" + tag + "]" + str + "[/" +tag+ "]";
sel.select();
return;
}
else if(typeof input.selectionStart != 'undefined'){
if(typeof input.scrollTop != 'undefined'){
var st=input.scrollTop;
var sl=input.scrollTop;
}
var start = input.selectionStart;
var end = input.selectionEnd;
var insText = input.value.substring(start, end);
input.value = input.value.substr(0, start) + '['+tag+']' + insText + '[/'+tag+']'+ input.value.substr(end);
input.focus();
if(typeof input.scrollTop != 'undefined'){
input.scrollTop=st;
input.scrollTop=sl;
}
input.setSelectionRange(start+2+tag.length+insText.length+3+tag.length,start+2+tag.length+insText.length+3+tag.length);
return;
}
else{
input.value+=' ['+tag+']Reemplace este texto[/'+tag+']';
return;
}
}
function inslink(campo){
var input = document.getElementById(campo);
if(typeof document.selection != 'undefined' && document.selection) {
var str = document.selection.createRange().text;
input.focus();
var my_link = prompt("Enter URL:","http://");
if (my_link != null) {
if(str.length==0){
str=my_link;
}
var sel = document.selection.createRange();
sel.text = "[a href=\"" + my_link + "\"]" + str + "[/a]";
sel.select();
}
return;
}else if(typeof input.selectionStart != 'undefined'){
if(typeof input.scrollTop != 'undefined'){
var st=input.scrollTop;
var sl=input.scrollTop;
}
var start = input.selectionStart;
var end = input.selectionEnd;
var insText = input.value.substring(start, end);
var my_link = prompt("Enter URL:","http://");
if (my_link != null) {
if(insText.length==0){
insText=my_link;
}
input.value = input.value.substr(0, start) +"[a href=\"" + my_link +"\"]" + insText + "[/a]"+ input.value.substr(end);
input.focus();
if(typeof input.scrollTop != 'undefined'){
input.scrollTop=st;
input.scrollTop=sl;
}
input.setSelectionRange(start+11+my_link.length+insText.length+4,start+11+my_link.length+insText.length+4);
}
return;
}else{
var my_link = prompt("Ingresar URL:","http://");
var my_text = prompt("Ingresar el texto del link:","");
input.value+=" [a href=\"" + my_link + "\"]" + my_text + "[/a]";
return;
}
}
var reng=5;
function agregar(area){
document.getElementById('quita').disabled=false;
reng=reng+5;
document.getElementById(area).rows=reng;
}
function quitar(area){
reng=reng-5;
if(reng<6){reng=5;
}
document.getElementById(area).rows=reng;
}
function ventana_emot(area){
coordx=screen.width?(screen.width-300)/2:0;
coordy=screen.height?(screen.height-150)/2:0;
window.open("bbcode/emoticons/emoticons.html?campo="+area,"EMOTICONS","width=300,height=150,menubar=no,resizable=yes,left="+coordx+",top="+coordy);
}
function ins_imag(emot,area){
var input = document.getElementById(area);
if(typeof document.selection != 'undefined' && document.selection) {
var str =document.selection.createRange().text;
input.focus();
var sel =document.selection.createRange();
sel.text = str + emot;
sel.select();
return;
}
else if(typeof input.selectionStart != 'undefined'){
if(typeof input.scrollTop != 'undefined'){
var st=input.scrollTop;
var sl=input.scrollTop;
}
var start = input.selectionStart;
var end = input.selectionEnd;
var insText = input.value.substring(start, end);
input.value = input.value.substr(0, start) + insText+ emot + input.value.substr(end);
input.focus();
if(typeof input.scrollTop != 'undefined'){
input.scrollTop=st;
input.scrollTop=sl;
}
input.setSelectionRange(end+emot.length,end+emot.length);
return;
}
else{
input.value+=emot;
return;
}
}
function captura_imag(area){
var my_link = prompt("Ingresar URL:","http://");
if (my_link != null) {
ins_imag('[img src=\"'+my_link+'\"]',area);
}
}
function captura_vid(area){
var my_link = prompt("Ingresar URL:","http://");
if (my_link != null) {
ins_imag('[embed src=\"'+my_link+'\"]',area);
}
}