var bookmarks = [

    ['del.icio.us', 'http://del.icio.us/post?url=[URL]&amp;title=[TITLE]', 'bookmark-delicious.png'],
    ['Digg it', 'http://digg.com/submit?phase=2&amp;url=[URL]&amp;title=[TITLE]', 'bookmark-digg.png'],
    ['Furl', 'http://www.furl.net/storeIt.jsp?t=[TITLE]&amp;u=[URL]', 'bookmark-furl.gif'],    
    ['Yahoo MyWeb', 'http://myweb2.search.yahoo.com/myresults/bookmarklet?t=[TITLE]&amp;u=[URL]', 'bookmark-yahoo-myweb.png'],    
    ['StumbleUpon', 'http://www.stumbleupon.com/submit?url=[URL]&title=[TITLE]', 'bookmark-su.png'],    
    ['Google', 'http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=[URL]&amp;title=[TITLE]', 'bookmark-goog.png'],
    ['Technorati', 'http://www.technorati.com/faves?add=[URL]', 'bookmark-technorati.png'],    
    ['BlinkList', 'http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=[URL]&amp;Title=[TITLE]', 'bookmark-blinklist.png'],    
    ['Newsvine', 'http://www.newsvine.com/_wine/save?popoff=0&amp;u=[URL]&amp;h=[TITLE]', 'bookmark-newsvine.png'],    
    ['ma.gnolia', 'http://ma.gnolia.com/bookmarklet/add?url=[URL]&amp;title=[TITLE]', 'bookmark-magnolia.png'],    
    ['reddit', 'http://reddit.com/submit?url=[URL]&amp;title=[TITLE]', 'bookmark-reddit.gif'],    
    ['Windows Live', 'https://favorites.live.com/quickadd.aspx?marklet=1&amp;mkt=en-us&amp;url=[URL]&amp;title=[TITLE]', 'bookmark-live.gif'],    
    /*['Tailrank', 'http://tailrank.com/share/?title=[TITLE]&amp;link_href=[URL]', 'bookmark-tailrank2.png'],*/
    ['Slashdot', 'http://slashdot.org/bookmark.pl?url=[URL]&amp;title=[TITLE]', 'bookmark-slashdot.png'],    
    ['Facebook', 'http://www.facebook.com/sharer.php?u=[URL]', 'bookmark-facebook.gif']

];

hId = "search_help";
timeVisible = 5;
tmpVisible = timeVisible;

intTmpTimer = 0;
statusY = 0;
statusX = 0;

arrstr = new Array();

for (i = 0; i < 30; i ++)
{
   arrstr[i] = "";
}

if (window.XMLHttpRequest)
{
   window.captureEvents(Event.MOUSEMOVE);
   window.onmousemove= displayCoords;
}   


function displayCoords(e) {
    statusX = e.pageX;
    statusY = e.pageY;
}

function set_id(id_name,str_name) {
   document.getElementById(id_name).innerHTML = str_name;}

function get_tagData(my_name){
   return my_name.firstChild.data;}

function writeURL(val)
{
   document.write("<a href=\"" + wwwUrl + "\" target=\"_blank\">see more...</a>");
}

function displayHelp(dstatus)
{
   gId = "display-help";
   sId = "textbox-submit";
   help = "For searching for in categories:<br /><i>{text} + {name categories}</i>.<br />For searching for with use the operations 'OR':<br /><i>{text} or {text} ..</i>";
   if (dstatus == 1)
   {
      if (!window.XMLHttpRequest)
      {
         statusY = event.clientY;
         statusX = event.clientX;
      }
      document.getElementById(gId).style.display = "block";
     document.getElementById(gId).style.top = statusY + 15;
      document.getElementById(gId).style.left = statusX + 15;
      set_id(gId,help);
   }
   else
   {
      document.getElementById(gId).style.display = "none";
   }      
}

function checkForm()
{
   if(document.search_form.str.value.length == 0)
   {
      alert('Error!\nWill enter word for searching!');
      return false;
   }
   else
   {
      return true;
   }
}

function createUrls(uId)
{
   urllink = new Array();
   namelink = new Array();
   word = document.getElementById(uId).firstChild.nodeValue;
   strresult = "";
   namelink[0] = "Encarta World Dictionary";
   urllink[0] = "http://encarta.msn.com/dictionary_/" + word + ".html";
   namelink[1] = "OneLook Dictionaries";
   urllink[1] = "http://www.onelook.com/?w=" + word;
   namelink[2] = "Merriam-Webster";
   urllink[2] = "http://www.m-w.com/cgi-bin/dictionary?book=Dictionary&va=" + word + "&x=0&y=0";
   namelink[3] = "Google Search";
   urllink[3] = "http://www.google.com/search?q=" + word;
   for (i = 0; i < urllink.length; i ++)
   {
      strresult += "<a href=\"" + urllink[i] + "\" target=\"_blank\">" + namelink[i] + "</a>";
      if (i < urllink.length - 1) strresult += ", ";
   }
   set_id(uId,strresult);
}

function LoadEvent()
{
   if (document.search_form) document.search_form.str.focus();
   if (document.getElementById("url-link")) createUrls("url-link");
   addHelpForSearch();
   /** Bookmarks */
   addBookmarks('bookmarks', bookmarks);

   var loaders = [];
   var div = document.getElementsByTagName('DIV');
   for (var i = 0; i < div.length; i++){
        if (div[i].className.indexOf('loader') >= 0)
        loaders.push(div[i]);
   }
   if (loaders.length) setTimeout(function(){
       for (var i = 0; i < loaders.length; i++)
           loaders[i].className = '';
   }, 5000);
}

function addHelpForSearch()
{
  var languages = {
     'ru':'<div>Используйте знаки вопроса пропавших без букв (одна "?" - Одно письмо):\n <code>кап?ал или кап???л</code>\n  Используйте звездочку на ЛЮБОЙ несколько неизвестных писем:\n  <code>навигат* или *злы или кро*ворд</code>\n  Исключить слова, содержащие буквы, которые следуют за дефис (тире):\n <code>п??лы -зн</code>\n</div>',
     'de':'<div>Fragezeichen für fehlende Buchstaben benutzen (einer "?" - ein Buchstabe):\n <code>kap?tal oder kap???l</code>\n  Ein Sternchen für JEDE MÖGLICHE Zahl der unbekannten Buchstaben benutzen:\n  <code>nav* oder *ma oder b*g</code>\n  Die Wörter ausschließen, welche die Buchstaben enthalten, die einem Bindestrich (Schlag) folgen:\n <code>p??zle -whk</code>\n</div>',
     'fr':'<div>Utilisez des points d\'interrogation pour les lettres manquantes (un "?" - Une lettre):\n <code>cap?tal ou cap??a?</code>\n  Utilisez un astérisque pour UNE nombre inconnu de lettres:\n  <code>navigat* ou *zzle ou cro*s</code>\n  Exclure des mots contenant les lettres qui suivent un trait d\'union (tiret):\n <code>p???le -wdxu</code>\n</div>',
     'es':'<div>El uso de signos de letras que faltan (un "?" - Una letra):\n <code>cap?tal o cap??a?</code>\n  Utilice un asterisco para cualquier número de cartas desconocidas:\n  <code>pret* o *robo o de*so</code>\n  Excluir palabras que contienen las letras que siguen un guión (guión):\n <code>de???tor -sml</code>\n</div>'
  }
  if (document.getElementById("search_help"))
  {
    if (location.href.split('/')[3] && languages[ location.href.split('/')[3] ])
    {
       document.getElementById("search_help").innerHTML = languages[ location.href.split('/')[3] ];
    }
    else
    {
       document.getElementById("search_help").innerHTML = '<div>Use question marks for missing letters (one "?" - one letter):\n               <code>cap?tal or cap??a?</code>\n               Use an asterisk for ANY number of unknown letters:\n               <code>navigat* or *zzle or cr*word</code>\n               Exclude words containing the letters that follow a hyphen:\n               <code>p??zle -wdxu</code>\n      </div>';
    }
  }
}

function StartTimeout() 
{   
   tmpVisible--;
   if (tmpVisible > 0)
   {
      intTmpTimer = setTimeout("StartTimeout()", 1000);      
   }
   else
   {
      tmpVisible = timeVisible;
      HelpView(0);
   }      
}


function HelpView(type)
{
   if (type == 0) 
   {
      document.getElementById(hId).style.display = "none";
   }
   else
   {   
      document.getElementById(hId).style.display = "block";
      clearTimeout(intTmpTimer);
      StartTimeout();
   }
}

/* CROSSWORD SOLVERPAGE */
function LengthWord(len)
{
   cachearr = new Array();
   allstr = "";
   
   set_id("count-len",len);
   
   for (i = 0; i < 30; i++ )
   {
      if (document.crossform["boxes_" + i]) arrstr[i] = document.crossform["boxes_" + i].value;
   }
   
   for (i = 0; i < len; i++ )
   {
      allstr += "<input name=\"boxes_" + i + "\" type=\"text\" maxlength=\"1\" value=\"" + arrstr[i] + "\" />";
   }   
   
   set_id("inputboxes",allstr);
}

/**
 *  Add Bookmarks
 *  @param id ul id
 *  @param bookmarks array
 *  format: ['title', 'url', 'image']
 */
function addBookmarks(id, bookmarks)
{
    var this_url = escape('http://' + location.host + '/');
    var this_title = encodeURI('Solve Word Puzzles and Crosswords with Ease at Wordfamous.com!');
    var images_prefix = 'http://' + location.host + '/_img/';
    for (var i = 0; i < bookmarks.length; i++){
        var li = document.createElement('li');
        li.innerHTML = '<a target="_blank" href="' + bookmarks[i][1].replace('[TITLE]', this_title).replace('[URL]', this_url) + '" title="' + bookmarks[i][0] + '"><img src="' + images_prefix + bookmarks[i][2] + '" alt="' + bookmarks[i][0] + '" /></a>'
        document.getElementById(id).appendChild(li);
    }
}

