////////////////////////////////////////////////////////////////////////////
// Interactive revision with STILUS
// (c) DAEDALUS
// All rights reserved
// It is strictly forbidden to copy or reuse this source code without 
// written permission from DAEDALUS
// Questions, comments: stilus@daedalus.es
////////////////////////////////////////////////////////////////////////////

// Style
var istilus_baseStyle = 'font-family:Verdana,Arial,Helvetica,sans-serif;font-size:8pt;color:#000000;margin:0px;padding:0px;outline-style:none;vertical-align:top;text-align:left;'; 
var istilus_textStyle = istilus_baseStyle+'background-color:#e0e0ee;border-style:none;';
var istilus_buttonStyle = istilus_baseStyle+'text-align:center;width:100px;height:20px;';
var istilus_barStyle = istilus_baseStyle+'background-color:#a0a0bb;font-weight:bold;';

// Default configuration
var istilus_srv = 'http://stilus.daedalus.es/istilus.php';
var istilus_cfg = 'http://stilus.daedalus.es/istiluscfg.php';
var istilus_url = 'http://stilus.daedalus.es/';
var istilus_lang = 'es';
var istilus_small = false; 
var istilus_auth = ''; 

// Global variables
var istilus_obj = null;
var istilus_top = '';
var istilus_winLeft = '';
var istilus_winTop = '';
var istilus_win = null;
var istilus_revobj = null;
var istilus_find = false;
var istilus_errors = 0;
var istilus_text = null;
var istilus_iniPos = 0;
var istilus_endPos = 0;
var istilus_selectedText = '';
var istilus_changeText = '';
var istilus_ignored = null;
var istilus_onClickHandler = null;
var istilus_onKeyDownHandler = null;
var istilus_dragObj = new Object();

// Localization
var istilus_msg = new Array();
// Spanish (es)
istilus_msg['es0'] = 'Lo siento, pero no encuentro nada que corregir.';
istilus_msg['es1'] = 'Lo siento, pero STILUS no es compatible (por ahora) con esta página.';
istilus_msg['es2'] = 'Lo siento, pero STILUS no es compatible (por ahora) con su navegador.';
istilus_msg['es3'] = 'No se ha encontrado ning&uacute;n error.';
istilus_msg['es4'] = 'No se han encontrado m&aacute;s errores.';
istilus_msg['es5'] = 'Lo siento, hubo un error fatal al conectar:';
istilus_msg['es6'] = 'Un momento...';
istilus_msg['es10'] = 'ORTOGRAF&Iacute;A';
istilus_msg['es11'] = 'GRAM&Aacute;TICA';
istilus_msg['es12'] = 'ESTILO';
istilus_msg['es13'] = 'TIPOGRAF&Iacute;A';
istilus_msg['es14'] = 'Sugerencias';
istilus_msg['es15'] = '(ninguna)';
istilus_msg['es16'] = 'Omitir';
istilus_msg['es17'] = 'Omitir todas';
istilus_msg['es18'] = 'Cambiar';
istilus_msg['es19'] = 'Cambiar todas';
istilus_msg['es20'] = 'Cerrar';
istilus_msg['es21'] = 'Aceptar';
// English (en)
istilus_msg['en0'] = 'I am sorry, but I cannot find anything to check.';
istilus_msg['en1'] = 'I am sorry, but STILUS is not (yet) compatible with this page.';
istilus_msg['en2'] = 'I am sorry, but STILUS is not (yet) compatible with your browser.';
istilus_msg['en3'] = 'No errors found.';
istilus_msg['en4'] = 'No more errors found.';
istilus_msg['en5'] = 'I am sorry, but there was a fatal error when connecting:';
istilus_msg['en6'] = 'One moment...';
istilus_msg['en10'] = 'SPELLING';
istilus_msg['en11'] = 'GRAMMAR';
istilus_msg['en12'] = 'STYLE';
istilus_msg['en13'] = 'TYPOGRAPHY';
istilus_msg['en14'] = 'Suggestions';
istilus_msg['en15'] = '(none)';
istilus_msg['en16'] = 'Ignore';
istilus_msg['en17'] = 'Ignore all';
istilus_msg['en18'] = 'Change';
istilus_msg['en19'] = 'Change all';
istilus_msg['en20'] = 'Close';
istilus_msg['en21'] = 'OK';


// Main method (the only one which should be public!!)
function istilus_check(obj,left,top) {
  if(obj==null || obj=='') {
    istilus_obj = null;
    istilus_findObject(null);
    istilus_find = true;
  } else {
    istilus_obj = document.getElementById(obj);
    istilus_find = false;
  }
  if(!istilus_obj) {
    alert(istilus_msg[istilus_lang+'0']);
    return false;
  }
  if(istilus_obj!=istilus_revobj) {
    istilus_winLeft = '';
    istilus_winTop = '';
  }
  if(left) {
    istilus_winLeft = left;
  }
  if(top) {
    istilus_winTop = top;
  }
  if(istilus_winLeft=='') {
    istilus_winLeft = istilus_getLeft(istilus_obj);
  }
  if(istilus_winTop=='') {
    istilus_winTop = istilus_getTop(istilus_obj);
  }
  istilus_start();
}; // check


// Find next valid object (text, textarea) to check
function istilus_findObject(doc) {
  var objs, i, b;
  try {
    if(!doc) {
      objs = document.getElementsByTagName('*');
    } else {
      objs = doc.getElementsByTagName('*');
    }
    if(!objs) {
      istilus_obj = null;
      return false;
    }
  } catch(e) { 
    istilus_obj = null;
    return false;
  }
  for(i=0; i<objs.length; i++) {
    if(objs[i].value && (objs[i].type=='text' || objs[i].type=='textarea')) {
      if(istilus_obj) {
        if(objs[i]==istilus_obj) {
          istilus_obj = null;
        }
      } else if(objs[i].value!='') {
        if(document.location.href.indexOf('http://mail.google.com')==0 &&
           objs[i].name!='subject' && objs[i].name!='msgbody') {
          continue;
        }
        istilus_obj = objs[i];
        return true;
      }
    }
  }
  for(i=0; i<objs.length; i++) {
    if(objs[i].tagName=='FRAME' || objs[i].tagName=='IFRAME') {
      try { 
        if(objs[i].contentWindow) {
          b = istilus_findObject(objs[i].contentWindow.document);
        } else if(objs[i].contentDocument) {
          b = istilus_findObject(objs[i].contentDocument);
        }
        if(b) {
          return true;
        }
      } catch(e) { }
    }
  }
  if(!doc) {
    istilus_obj = null;
  }
  return false;
}; // findObject


// Start checking
function istilus_start() {
  if(!istilus_obj.ownerDocument || !istilus_obj.ownerDocument.body) {
    alert(istilus_msg[istilus_lang+'1']);
    return false;
  }
  if(istilus_win) {
    istilus_win.ownerDocument.body.removeChild(istilus_win);
    istilus_win = null;
  }
  istilus_revobj = istilus_obj;
  istilus_win = istilus_obj.ownerDocument.createElement('div');
  istilus_win.style.visibility = 'hidden';
  istilus_win.style.position = 'absolute';
  istilus_win.style.zIndex = 999;
  istilus_win.style.border = 'activeborder 2px outset';
  istilus_win.style.borderCollapse = 'collapse';
  istilus_win.style.backgroundColor = '#e0e0ee';
  istilus_win.style.padding = '0px';
  istilus_win.style.left = istilus_winLeft+'px';
  istilus_win.style.top = istilus_winTop+'px';
  istilus_obj.ownerDocument.body.appendChild(istilus_win);
  istilus_errors = 0;
  istilus_iniPos = 0;
  istilus_endPos = 0;
  istilus_onclickHandler = istilus_obj.onclick;
  istilus_onKeyDownHandler = istilus_obj.onkeydown;
  istilus_obj.onclick = istilus_close;
  istilus_obj.onkeydown = istilus_close;
  istilus_ignored = new Array();
  istilus_next();
}; // start
  

// Next error
function istilus_next() {
  var xmlHttp;
  try { xmlHttp = new ActiveXObject('Msxml2.XMLHTTP'); } 
  catch(e) { try { xmlHttp = new ActiveXObject('Microsoft.XMLHTTP'); }
  catch(e) { try { xmlHttp = new XMLHttpRequest(); }
  catch(e) { 
    istilus_finishWindow(istilus_msg[istilus_lang+'2']);
    return;
  }}}
  istilus_text = istilus_obj.value;
  istilus_text = istilus_text.replace(new RegExp('\r','g'), '');
  xmlHttp.onreadystatechange = function() {
    if(xmlHttp.readyState == 4) {
      istilus_obj.ownerDocument.body.style.cursor = 'auto';
      if(xmlHttp.status == 200) {
        var s = unescape(xmlHttp.responseText);
        if(s.substring(0,5)=='ERROR') {
          istilus_finishWindow(s.substring(5));
        } else if(s=='NOERROR') {
          if(istilus_find && istilus_findObject(null)) {
            istilus_start();
          } else {
            if(istilus_errors==0) {
              istilus_finishWindow(istilus_msg[istilus_lang+'3']);
            } else {
              istilus_finishWindow(istilus_msg[istilus_lang+'4']);
            }
          }
        } else {
          var r = new Function('return '+s)();
          istilus_errors++;
          istilus_iniPos = r[0].inip;
          istilus_endPos = r[0].endp;
          istilus_selectedText = istilus_text.substring(istilus_iniPos,istilus_endPos);
          if(!istilus_isIgnored(istilus_selectedText)) {
            istilus_errorWindow(r[0].type,r[0].msg,r[0].ref,r[0].sugs);
          } else {
            istilus_onIgnore();
          }
        }
      } else {
        istilus_finishWindow(istilus_msg[istilus_lang+'5']+'\n'+xmlHttp.statusText);
      }
    }
  }
  try {
    var s = 'txt='+escape(istilus_text)+
            '&pos='+istilus_iniPos+
            '&lang='+istilus_lang+
            '&coo=1';
    if(!istilus_auth) {
      s += '&auth='+escape('u'+document.location.href.replace(/[#\?].*/,''));
    } else {
      s += '&auth='+escape(istilus_auth);
    }
    xmlHttp.open('POST', istilus_srv, true);
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
    xmlHttp.send(s);
    istilus_obj.ownerDocument.body.style.cursor = 'wait';
    istilus_waitWindow();
  } catch(e) {
    var msg = 'Es necesario que modifique los permisos de acceso<br> en su navegador.<br><br>';
    if(document.all!=undefined) {
      msg += '<b>Internet Explorer</b>:<br>';
      msg += '<b>1)</b> Acceda al men&uacute; <i>"Herramientas"</i> ><br>';
      msg += ' <i>"Opciones de Internet"</i> > <i>"Seguridad"</i>,<br>';
      msg += ' seleccione <i>"Internet"</i> y luego<br>';
      msg += ' <i>"Nivel personalizado"</i>.<br>';
      msg += '<b>2)</b> Al final de la lista, cambie la opci&oacute;n de<br>';
      msg += ' <i>"Tener acceso a origen de datos entre dominios"</i><br>';
      msg += ' a <i>"Pedir datos"</i>.';
    } else {
      msg += '<b>Mozilla Firefox</b>:<br>';
      msg += '<b>1)</b> Teclee "<tt>about:config</tt>" en la barra de<br>';
      msg += ' direcciones.<br>';
      msg += '<b>2)</b> Pulse el bot&oacute;n derecho del rat&oacute;n, seleccione<br>';
      msg += ' <i>"Nuevo"</i> > <i>"Cadena"</i> e introduzca el texto<br>';
      msg += ' "<tt>capability.policy.default.XMLHttpRequest.open</tt>"<br>';
      msg += ' y el valor "<tt>allAccess</tt>".';
    }
    istilus_finishWindow('<div style="text-align:left">'+msg+'</div>');
  }
}; // next
  

// "Error found..."
function istilus_errorWindow(type,msg,ref,sugs) {
  var html;
  html = '<table style="'+istilus_textStyle+'width:1px;">';
  html += '<tr style="'+istilus_barStyle+'"><td style="'+istilus_barStyle+'" nowrap colspan="2" onmousedown="'+istilus_top+'istilus_dragStart(event)"><a href="#" onclick="'+istilus_top+'istilus_close();return false;"><img src="'+istilus_url+'istilus-close.gif" border="0" align="right"></a>';
  if(type=='O') {
    html += istilus_msg[istilus_lang+'10'];
  } else if(type=='G') {
    html += istilus_msg[istilus_lang+'11'];
  } else if(type=='E') {
    html += istilus_msg[istilus_lang+'12'];
  } else if(type=='T') {
    html += istilus_msg[istilus_lang+'13'];
  }
  html += '</td></tr>';
  html += '<tr style="'+istilus_textStyle+'"><td style="'+istilus_textStyle+'" nowrap>';
  html += '<table style="'+istilus_textStyle+'width:1px;">';
  html += '<tr style="'+istilus_textStyle+'"><td style="'+istilus_textStyle+'" colspan="2">';
  html += msg+'<br>';
  if(ref!='') html += '[<i>'+ref+'</i>]<br>';
  html += '</td></tr><tr style="'+istilus_textStyle+'"><td style="'+istilus_textStyle+'">';
  if(!istilus_small) html += istilus_msg[istilus_lang+'14']+':<br>';
  if(sugs!='') {
    html += '<select width="100%" id="sugs" style="'+istilus_baseStyle+';width:100%" size="5" onclick="'+istilus_top+'istilus_onChangeSugs()" ondblclick="'+istilus_top+'istilus_onChangeSugs();'+istilus_top+'istilus_onChange()">';
    var asugs = new Array();
    asugs = sugs.split('\\t');
    for(i=0; i<asugs.length; i++) {
      html += '<option value="'+escape(asugs[i])+'">'+asugs[i];
      for(j=asugs[i].length; j<15; j++) {
        html += '&nbsp;';
      }
      html += '</option>';
    }
  } else {
    html += '<select width="100%" id="sugs" style="'+istilus_baseStyle+';width:100%" size="5" disabled>';
    html += '<option value="">'+istilus_msg[istilus_lang+'15']+'</option>';
  }
  html += '</select><br>';
  html += '<input type="text" id="other" style="'+istilus_baseStyle+';width:100%;" onclick="'+istilus_top+'istilus_onChangeOther()" onkeyup="'+istilus_top+'istilus_onChangeOther()">';
  html += '</td><td style="'+istilus_textStyle+';text-align:center;">';
  if(!istilus_small) html += '<br>';
  html += '<button style="'+istilus_buttonStyle+'" onclick="'+istilus_top+'istilus_onIgnore()">'+istilus_msg[istilus_lang+'16']+'</button>';
  html += '<br>';
  html += '<button style="'+istilus_buttonStyle+'" onclick="'+istilus_top+'istilus_onIgnoreAll()">'+istilus_msg[istilus_lang+'17']+'</button>';
  html += '<br>';
  html += '<button style="'+istilus_buttonStyle+'" id="change" onclick="'+istilus_top+'istilus_onChange()">'+istilus_msg[istilus_lang+'18']+'</button>';
  html += '<br>';
  html += '<button style="'+istilus_buttonStyle+'" id="changeall" onclick="'+istilus_top+'istilus_onChangeAll()">'+istilus_msg[istilus_lang+'19']+'</button>';
  if(!istilus_small) {
    html += '</td></tr>';
    html += '<tr style="'+istilus_textStyle+'"><td style="'+istilus_textStyle+'">';
    html += '<img src="'+istilus_url+'istilus-logo.gif" border="0">&nbsp;';
    html += '</td><td style="'+istilus_textStyle+'vertical-align:middle;" nowrap>';
    html += '&copy; 2010 DAEDALUS<br>';
    html += '<a style="'+istilus_textStyle+'" href="http://stilus.daedalus.es" target="_blank">stilus.daedalus.es</a>';
  }
  html += '</td></tr></table>';
  html += '</td></tr>';
  html += '</table>';
  istilus_window(html);
  istilus_enableOnChange(false);
  istilus_select();
}; // errorWindow


// "Some information..."
function istilus_finishWindow(txt) {
  var html;
  html = '<table style="'+istilus_textStyle+'width:1px;">';
  html += '<tr style="'+istilus_barStyle+'"><td style="'+istilus_barStyle+'" nowrap colspan="2" onmousedown="'+istilus_top+'istilus_dragStart(event)"><a href="#" onclick="'+istilus_top+'istilus_close();return false;"><img src="'+istilus_url+'istilus-close.gif" border="0" align="right"></a>STILUS&reg;</td></tr>';
  html += '<tr style="'+istilus_textStyle+'"><td style="'+istilus_textStyle+'" nowrap>';
  html += '<table style="'+istilus_textStyle+'width:1px;">';
  html += '<tr style="'+istilus_textStyle+'">';
  if(!istilus_small) {
    html += '<td style="'+istilus_textStyle+'text-align:center;vertical-align:middle;" nowrap>';
    html += '<img src="'+istilus_url+'istilus-logo.gif" border="0">&nbsp;';
    html += '<br>&copy; 2010 DAEDALUS<br>';
    html += '<a style="'+istilus_textStyle+'" href="http://stilus.daedalus.es" target="_blank">stilus.daedalus.es</a>';
    html += '&nbsp;</td>';
  }
  html += '<td style="'+istilus_textStyle+'text-align:center;vertical-align:middle;" nowrap>';
  html += txt;
  html += '<br><br><button style="'+istilus_buttonStyle+'" onclick="'+istilus_top+'istilus_close()">'+istilus_msg[istilus_lang+'21']+'</button>';
  html += '</td></tr>';
  html += '</table>';
  html += '</td></tr>';
  html += '</table>';
  istilus_window(html);
  istilus_unselect();
}; // finishWindow


// "Please wait..."
function istilus_waitWindow() {
  var html;
  html = '<table style="'+istilus_textStyle+'width:1px;">';
  html += '<tr style="'+istilus_textStyle+'"><td style="'+istilus_textStyle+'text-align:center;vertical-align:middle;" nowrap>';
  html += istilus_msg[istilus_lang+'6']+'<br>';
  html += '<img src="'+istilus_url+'istilus-wait.gif" border="0">';
  html += '</td></tr></table>';
  istilus_window(html);
}; // waitWindow


// Show window 
function istilus_window(html) {
  var pos;
  istilus_win.innerHTML = html;
  istilus_win.style.visibility='visible';
  if(istilus_winLeft+istilus_win.offsetWidth>istilus_win.offsetParent.offsetWidth) {
    pos = istilus_win.offsetParent.offsetWidth-istilus_win.offsetWidth;
    if(document.all!=undefined) {
      pos -= 30;
    }
    if(pos<0) {
      pos = 0;
    }
    istilus_win.style.left = pos+'px';
  }
}; // istilus_window


// Select error in text box
function istilus_select() {
  if (istilus_obj.createTextRange) {
    var oRange = istilus_obj.createTextRange();
    oRange.collapse();
    oRange.moveStart('character', istilus_iniPos);
    oRange.moveEnd('character', istilus_endPos-istilus_iniPos);
    oRange.select();
    oRange.scrollIntoView();
  } else if (istilus_obj.setSelectionRange) {
    istilus_obj.value = istilus_text.substring(0,istilus_iniPos);
    istilus_obj.scrollTop = istilus_obj.scrollHeight;
    var t = istilus_obj.scrollTop;
    istilus_obj.value = istilus_text;
    if(t>0) {
      if(istilus_obj.style.height) {
        istilus_obj.scrollTop = t+parseInt(istilus_obj.style.height)/2;
      } else {
        istilus_obj.scrollTop = t+15;
      }
    }
    istilus_obj.setSelectionRange(istilus_iniPos,istilus_endPos);
  }
  istilus_obj.focus();
}; // select


// Unselect error in text box
function istilus_unselect() {
  if(istilus_obj) {
    if (istilus_obj.createTextRange) {
      var oRange = istilus_obj.createTextRange();
      oRange.collapse();
    } else if (istilus_obj.setSelectionRange) {
      istilus_obj.setSelectionRange(0,0);
    }
  }
}; // unselect


// Find if text should be ignored
function istilus_isIgnored(txt) {
  var i;
  for(i=0; i<istilus_ignored.length; i++) {
    if(istilus_ignored[i]==txt) {
      return true;
    }
  }
  return false;
}; // isIgnored


// "Change" and "Change all" enabled/disabled 
function istilus_enableOnChange(value) {
  istilus_obj.ownerDocument.getElementById('change').disabled = !value;
  istilus_obj.ownerDocument.getElementById('changeall').disabled = !value;
}; // enableOnChange


// Changes in selected suggestions
function istilus_onChangeSugs() {
  var sugs = istilus_obj.ownerDocument.getElementById('sugs');
  var other = istilus_obj.ownerDocument.getElementById('other');
  istilus_obj.focus();
  istilus_changeText = unescape(sugs.options[sugs.selectedIndex].value);
  other.value = '';
  istilus_enableOnChange(true);
}; // onChangeSugs


// Changes in other suggestion
function istilus_onChangeOther() {
  var sugs = istilus_obj.ownerDocument.getElementById('sugs');
  var other = istilus_obj.ownerDocument.getElementById('other');
  other.focus();
  istilus_changeText = other.value;
  sugs.selectedIndex = -1;
  istilus_enableOnChange(other.value!='');
}; // onChangeOther


// What to do when on "Ignore" button
function istilus_onIgnore() {
  istilus_iniPos++;
  istilus_next();
}; // onIgnore


// What to do when on "Ignore All" button
function istilus_onIgnoreAll() {
  istilus_ignored.push(istilus_selectedText);
  istilus_iniPos++;
  istilus_next();
}; // onIgnoreAll


// What to do when on "Change" button 
function istilus_onChange() {
  istilus_text = istilus_text.substring(0,istilus_iniPos)+istilus_changeText+istilus_text.substring(istilus_endPos);
  istilus_obj.value = istilus_text;
  istilus_next();
}; // onChange


// What to do when on "Change all" button 
function istilus_onChangeAll() {
  var i;
  var l = istilus_selectedText.length;
  var alphanum = /^[a-záäàâéëèêíïìîóöòôúüùûñçÁÄÀÂÉËÈÊÍÏÌÎÓÖÒÔÚÜÙÛÑÇ0-9]+$/i;
  for(i=0; i<istilus_text.length-l; i++) {
    if(istilus_text.substr(i,l)==istilus_selectedText && 
      !alphanum.test(istilus_text.substr(i-1,1)) && 
      !alphanum.test(istilus_text.substr(i+l,1))) {
      istilus_text = istilus_text.substring(0,i)+istilus_changeText+istilus_text.substring(i+l);
    }
  }
  istilus_obj.value = istilus_text;
  istilus_next();
}; // onChangeAll


// Finished!!
function istilus_close() {
  if(istilus_obj) {
    istilus_unselect();
    if(istilus_onclickHandler!=null) {
      istilus_obj.onclick = istilus_onclickHandler;
    } else {
      istilus_obj.onclick = '';
    }
    if(istilus_onKeyDownHandler!=null) {
      istilus_obj.onkeydown = istilus_onKeyDownHandler;
    } else {
      istilus_obj.onkeydown = '';
    }
  }
  if(istilus_win) {
    istilus_winLeft = parseInt(istilus_win.style.left);
    istilus_winTop = parseInt(istilus_win.style.top);
    istilus_win.ownerDocument.body.removeChild(istilus_win);
    istilus_win = null;
  }
}; // close


// Get object position from left border
function istilus_getLeft(obj) {
  var pos = obj.offsetWidth+10;
  if(obj.offsetParent) {
    while(obj.offsetParent) {
      pos += obj.offsetLeft;
      obj = obj.offsetParent;
    }
  }
  return pos;
}; // getLeft


// Get object position from page top
function istilus_getTop(obj) {
  var pos = 10;
  if(obj.offsetParent) {
    while(obj.offsetParent) {
      pos += obj.offsetTop;
      obj = obj.offsetParent;
    }
  }
  return pos;
}; // getTop


// Start dragging
function istilus_dragStart(event) {
  var x, y;
  istilus_dragObj.elNode = istilus_win;
  istilus_dragObj.zIndex = 0;
  if(document.all!=undefined) {
    x = window.event.clientX+istilus_win.ownerDocument.documentElement.scrollLeft+istilus_win.ownerDocument.body.scrollLeft;
    y = window.event.clientY+istilus_win.ownerDocument.documentElement.scrollTop+istilus_win.ownerDocument.body.scrollTop;
  } else {
    x = event.clientX+window.scrollX;
    y = event.clientY+window.scrollY;
  }
  istilus_dragObj.cursorStartX = x;
  istilus_dragObj.cursorStartY = y;
  istilus_dragObj.elStartLeft = parseInt(istilus_dragObj.elNode.style.left);
  istilus_dragObj.elStartTop = parseInt(istilus_dragObj.elNode.style.top);
  if (isNaN(istilus_dragObj.elStartLeft)) istilus_dragObj.elStartLeft = 0;
  if (isNaN(istilus_dragObj.elStartTop)) istilus_dragObj.elStartTop  = 0;
  istilus_dragObj.elNode.style.zIndex = ++istilus_dragObj.zIndex;
  if(document.all!=undefined) {
    istilus_win.ownerDocument.attachEvent('onmousemove', istilus_dragGo);
    istilus_win.ownerDocument.attachEvent('onmouseup', istilus_dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  } else {
    istilus_win.ownerDocument.addEventListener('mousemove', istilus_dragGo, true);
    istilus_win.ownerDocument.addEventListener('mouseup', istilus_dragStop, true);
    event.preventDefault();
  }
} // dragStart


// Perform dragging
function istilus_dragGo(event) {
  var x, y;
  if(document.all!=undefined) {
    x = window.event.clientX+istilus_win.ownerDocument.documentElement.scrollLeft+istilus_win.ownerDocument.body.scrollLeft;
    y = window.event.clientY+istilus_win.ownerDocument.documentElement.scrollTop+istilus_win.ownerDocument.body.scrollTop;
  } else {
    x = event.clientX+window.scrollX;
    y = event.clientY+window.scrollY;
  }
  istilus_dragObj.elNode.style.left = (istilus_dragObj.elStartLeft+x-istilus_dragObj.cursorStartX)+'px';
  istilus_dragObj.elNode.style.top  = (istilus_dragObj.elStartTop+y-istilus_dragObj.cursorStartY)+'px';
  if(document.all!=undefined) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  } else
    event.preventDefault();
} // dragGo


// Stop dragging
function istilus_dragStop(event) {
  if(document.all!=undefined) {
    istilus_win.ownerDocument.detachEvent('onmousemove', istilus_dragGo);
    istilus_win.ownerDocument.detachEvent('onmouseup', istilus_dragStop);
  } else {
    istilus_win.ownerDocument.removeEventListener('mousemove', istilus_dragGo,	true);
    istilus_win.ownerDocument.removeEventListener('mouseup', istilus_dragStop, true);
  }
} // dragStop


// Config
function istilus_config() {
  page = window.open(istilus_cfg,'istiluscfg','marginheight=no,marginwidth=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,width=350,height=520');
  if(window.focus) page.window.focus();
}


// In your browser...
if(document.getElementById('istilusscr')) {
  istilus_top = 'top.';
  istilus_check();
}
