window.onload = function()
{
   var elements = document.getElementsByTagName('div');
   var image, caption;

   for(i = 0; i < elements.length; i++)
   {
      if(elements[i].className.substring(0,8) == "floating")
	  {
         image = elements[i].getElementsByTagName('img');
	     caption = elements[i].getElementsByTagName('p');
	     caption[0].style.width = image[0].offsetWidth + 'px';
      }
   }
}

function basename(path)
{
   return path.replace(/\\/g,'/').replace( /.*\//, '' );
}

function insertAtCursor(strText)
{
   var field = document.getElementById('wikiarea');

   // Internet Explorer support
   if (document.selection)
   {
      field.focus();
      sel = document.selection.createRange();
      sel.text = strText;
   }

   // Gecko support
   if (field.selectionStart || field.selectionStart == '0')
   {
      var first = field.value.slice(0, field.selectionStart);
      var second = field.value.slice(field.selectionStart);
      field.value = first + strText + second;
   }
   else 
   {
      field.value += strText;
   }

   field.focus();
}
