// Search box for Mediawiki
// (c) 2006 ], released under GPL
// Adaptación para uso con el WSS: ]
//<pre><nowiki>
importStylesheet('Usuario:Chixpy/WSS1/formbusqueda.css');
var sr$t;
var sr$f;
var sr$s;
var sr$r;
var sr$w;
var sr$re;
var sr$mc;
function $e(id) {return document.getElementById(id)}
function srBack()
{
if (sr$s.value=='') {sr$t.focus(); return }
if (sr$re.checked) {
var searchString = sr$s.value;
} else {
searchString=sr$s.value.replace(/(\{\}\|\.\*\?\(\)\$\^\\])/g,'\\$1');
}
searchString="("+searchString+")(?!*"+searchString+")";
if (sr$mc.checked)
var re=new RegExp(searchString);
else
var re=new RegExp(searchString,"i");
var res = re.exec (sr$t.value.substring(0,sr$t.selectionStart));
if (!res) {
var res = re.exec (sr$t.value)
}
if (res)
{
sr$t.selectionStart=res.index;
sr$t.selectionEnd=res.index+res.length;
}
else sr$t.selectionStart=sr$t.selectionEnd;
srSync();
}
function srNext()
{
if (sr$s.value=='') {sr$t.focus(); return }
if (sr$re.checked) {
var searchString = sr$s.value;
} else {
searchString=sr$s.value.replace(/(\{\}\|\.\*\?\(\)\$\^\\])/g,'\\$1');
}
if (sr$mc.checked)
var re=new RegExp(searchString,"g");
else
var re=new RegExp(searchString,"gi");
re.lastIndex=sr$t.selectionEnd;
var res = re.exec (sr$t.value)
if (!res) {
re.lastIndex=0;
var res = re.exec (sr$t.value)
}
if (res)
{
sr$t.selectionStart=res.index;
sr$t.selectionEnd=res.index+res.length;
}
else sr$t.selectionStart=sr$t.selectionEnd;
srSync();
}
function srReplace()
{
var sels=sr$t.selectionStart;
var sele=sr$t.selectionEnd;
var selr=sr$t.value.length-sele;
if (sr$s.value=='' || sels==sele) {sr$t.focus(); return }
if (sr$re.checked) {
var searchString = sr$s.value;
var replaceString = sr$r.value;
} else {
searchString=sr$s.value.replace(/(\{\}\|\.\*\?\(\)\$\^\\])/g,'\\$1');
replaceString=sr$r.value.replace(/()/g,'\\$1');
}
if (sr$mc.checked)
var re=new RegExp(searchString,"g");
else
var re=new RegExp(searchString,"gi");
re.lastIndex=sels;
var res = re.exec (sr$t.value);
var $$=0;
if (res && res.index==sels && res.length==sele-sels)
{
if (sr$re.checked) {
replaceString=replaceString.replace(/\\\\/g,'&backslash;');
var replaceBits=(" "+replaceString).split(/(?=\$\d)/);
replaceString=replaceBits.substring(1);
for (var i=1; i<replaceBits.length; i++)
{
$$=replaceBits-'0';
if ($$<res.length)
replaceString += res + replaceBits.substring(2)
else
replaceString += replaceBits;
}
replaceString=replaceString.replace (/\\n/,"\n").replace (/&backslash;/g,"\\").replace
(/$/g,"\$")
}
sr$t.value= sr$t.value.substring(0,sels) + replaceString + sr$t.value.substring(sele);
}
sr$t.selectionStart=sels;
sr$t.selectionEnd=sr$t.value.length-selr;
srSync();
}
function srReplaceall()
{
if (!sr$s.value) {sr$t.focus(); return }
var sels=sr$t.selectionStart;
var sele=sr$t.selectionEnd;
var selr=sr$t.value.length-sele;
var reps;
if (sr$re.checked) {
var searchString = sr$s.value;
var replaceString = sr$r.value.replace(/\\\\/,'&backslash;').replace(/\\n/,'\n').replace(/&backslash;/,"\\");
} else {
searchString=sr$s.value.replace(/(\{\}\|\.\*\?\(\)\$\^\\])/g,'\\$1');
replaceString=sr$r.value.replace(/()/g,'\\$1');
}
if (sele>sels)
reps=sr$t.value.substring(sels,sele);
else
reps=sr$t.value;
if (sr$mc.checked)
var re=new RegExp(searchString,"g");
else
var re=new RegExp(searchString,"gi");
var replaceCounter=0;
var replaceFunc=function(){replaceCounter++;return replaceString};
reps=reps.replace(re,replaceFunc);
if (sele>sels)
sr$t.value = sr$t.value.substring(0,sels) + reps + sr$t.value.substring(sele);
else
sr$t.value = reps;
sr$t.selectionStart=sels;
sr$t.selectionEnd=sele>sels ? sr$t.value.length-selr : sels;
window.status = replaceCounter+" ocurrences of " + searchString + " replaced.";
srSync();
}
function srToggleCase()
{
var sels=sr$t.selectionStart;
var sele=sr$t.selectionEnd;
var selr=sr$t.value.length-sele;
var selt=sr$t.value.substring(sels,sele);
if (sele>sels)
{
if (selt==selt.toUpperCase())
selt=selt.toLowerCase()
else if (selt==selt.toLowerCase() && sele-sels>1)
selt=selt.substring(0,1).toUpperCase()+selt.substring(1).toLowerCase()
else
selt=selt.toUpperCase();
sr$t.value = sr$t.value.substring(0,sels) + selt + sr$t.value.substring(sele);
sr$t.selectionStart=sels;
sr$t.selectionEnd=sele>sels ? sr$t.value.length-selr : sels;
}
srSync();
}
function srSync()
{
var i;
var allLines=0;
var lineNo=0;
var w=sr$t.cols-5;
var dummy=sr$t.value.split("\n");
for (i=0;i<dummy.length;i++){allLines+=Math.ceil(dummy.length/w)}
var dummy=sr$t.value.substring(0,sr$t.selectionStart).split("\n");
for (i=0;i<dummy.length;i++){lineNo+=Math.ceil(dummy.length/w)}
// alert (w+" "+lineNo+"/"+allLines);
sr$t.scrollTop=sr$t.scrollHeight*(lineNo-10)/allLines;
sr$t.focus();
}
function srInit()
{
if($e('wpTextbox1')) {
var srBoxCode ='<div id="srForm"><table id="srBox" cellpadding="0" cellspacing="2"><tr>'
+'<td></td>'
+'<td valign="middle">'
+'<input type="checkbox" id="srCase" onclick="sr$t.focus()" tabindex="10"/><small><span style="color:#000000;">Sensible a mayúsculas</span></small> '
+'<input type="checkbox" id="srRegexp" onclick="sr$t.focus()" tabindex="11"/><small><span style="color:#000000;">Usar expresión regular</span></small> '
+'<a href="javascript:srBack()" onmouseover="sr$t.focus()" title="Buscar anterior coincidencia " accesskey="2"><</a> '
+'<a href="javascript:srNext()" onmouseover="sr$t.focus()" title="Buscar siguiente coincidencia " accesskey="3">Buscar ></a> '
+'<a href="javascript:srReplace();srBack()" onmouseover="sr$t.focus()" title="Buscar y reemplazar anterior coincidencia " accesskey="4"><</a> '
+'<a href="javascript:srReplace()" onmouseover="sr$t.focus()" title="replace this match">Reemplazar</a> '
+'<a href="javascript:srReplace();srNext()" onmouseover="sr$t.focus()" title="Buscar y reemplazar siguiente coincidencia " accesskey="5">></a> '
+'<a href="javascript:srReplaceall()" onmouseover="sr$t.focus()" title="Reemplazar todas las coincidencias " accesskey="7">Reemplazar todo</a> '
+'</td>'
+'</tr><tr>'
+'<td valign="bottom"><small><span style="color:#000000;">Buscar:</span></small></td>'
+'<td valign="bottom"><input type="text" id="srSearch" accesskey="F" tabindex="8" onkeypress="event.which == 13 && srNext()"; value=""/></td>'
+'</tr><tr>'
+'<td valign="bottom"><small><span style="color:#000000;">Reemplazar por:</span></small></td>'
+'<td valign="bottom"><input type="text" id="srReplace" accesskey="G" tabindex="9" onkeypress="event.which == 13 && srNext()"; value=""/></td>'
+'</tr></table></div>'
var ep=$e('searchInput');
if (ep) ep.accessKey='none';
sr$t=document.editform.wpTextbox1;
sr$w=sr$t.style.width;
var sr=document.createElement('div');
sr.innerHTML=srBoxCode;
sr.firstChild.style.display='none';
var ep=$e('wpTextbox1');
ep.parentNode.insertBefore(sr,ep);
sr$f=$e('srForm');
sr$s=$e('srSearch');
sr$r=$e('srReplace');
sr$re=$e('srRegexp');
sr$mc=$e('srCase');
}
}
function srShowHide()
{
if (sr$f.style.display=='none')
{
sr$f.style.display='block';
// sr$t.style.width='auto';
sr$s.focus();
}
else
{
sr$f.style.display='none';
sr$t.style.width=sr$w;
}
}
$(srInit);
//</nowiki></pre>