//var serverURL = 'http://web2.ling.pl/';
var serverURL = '/';

var slowa = [];
var ajaxs = [];
var curid = 1;
var zeroBackgroundColor = "#f1c41d"; 
var defVoice;
var defRange;
var defLang;
var defDownInfoVisible;
 
var langArray = new Array();
    langArray[0]  = 'all';
    langArray[1]  = 'ang';
    langArray[2]  = 'ger';
    langArray[3]  = 'esp';
    langArray[4]  = 'fra';
    langArray[5]  = 'ita';
    langArray[6]  = 'pol';
    langArray[7]  = 'rus';
    langArray[8]  = 'all';
    langArray[9]  = 'ang';
    langArray[10] = 'ger';
    


function initPage() {
  fooLoad();
}

function initPageAlt(st, ln) {

  document.getElementById('searchword').focus();
  document.getElementById('searchword').select();
  
  var pw = document.getElementById('buttonLeft_0');
  if (pw != null) {
    var idiv = document.createElement('div');
    var iid = 'invisible_0';
    idiv.style.display = "none";
    idiv.setAttribute('id',iid);
    document.getElementById('invisibles').appendChild(idiv);
    idiv.innerHTML = document.getElementById('replaceme').innerHTML;
    
    if (pw.addEventListener) {
      pw.addEventListener('click', showTranslation, false);
      pw.addEventListener('mouseover', mouseOverHandler, false);
      pw.addEventListener('mouseout', mouseOutHandler, false);
    }
    else {
      pw.attachEvent('click', showTranslation);
      pw.attachEvent('mouseover', mouseOverHandler);
      pw.attachEvent('mouseout', mouseOutHandler);
    }
    
    pw.setAttribute('selectedTranslation', '1');
    makeIVO(document.getElementById('definitionDIV'));
    
  }
  checkForDefValues();
  if (defDownInfoVisible == null) {
    document.getElementById('downInfo').style.display = 'block';  
  } else if (defDownInfoVisible != 'none') {
    document.getElementById('downInfo').style.display = 'block'; 
  } 
  
  if (st == -1 || ln == -1) {
    // uruchamiam przez strone typu html
    if (defRange== null || defLang == null) {
      // jesli ktores jest nieustawione, wymuszam wlasne ustawienia
      createCookie('defLang', 0, 1000);
      document.getElementById('jezykList').selectedIndex = 0;
      defLang = 0;
      
      createCookie('defRange', 1, 1000);
      document.getElementById('zakresList').selectedIndex = 1;
      defRange = 1;

      sR(defRange);
      sL(defLang);     
      lcClick(document.getElementById('lc_flag_'+defLang));

    } else {
      sR(defRange);
      sL(defLang);     
      lcClick(document.getElementById('lc_flag_'+defLang));
    }
  } else {
    sR(st);
    sL(ln);     
    lcClick(document.getElementById('lc_flag_'+ln));
  }

  
}

function isset () {
    var a=arguments, l=a.length, i=0;
        if (l===0) {
        throw new Error('Empty isset'); 
    }
    
    while (i!==l) {        if (typeof(a[i])=='undefined' || a[i]===null) { 
            return false; 
        } else { 
            i++; 
        }    }
    return true;
}





function deleteAllWords() {
  var children = document.getElementById('listaslow').childNodes;
  for (var i=children.length-1 ; i>=0 ; i--) {
    document.getElementById('listaslow').removeChild( children[i] );
  }
}


function ppHighlight_on() {
  if (document.getElementById('pokazujPodpowiedziCheckbox').checked != true) {
    document.getElementById('pokazujPodpowiedziImg').src = '/img/checkbox_over.png';
  }
  document.getElementById('pokazujPodpowiedziString').style.textDecoration = 'underline';
}

function ppHighlight_off() {
  if (document.getElementById('pokazujPodpowiedziCheckbox').checked != true) {
    document.getElementById('pokazujPodpowiedziImg').src = '/img/checkbox_off.png';
  }
  document.getElementById('pokazujPodpowiedziString').style.textDecoration = 'none';
}

function pokazujPodpowiedziSetter() {

  if (document.getElementById('pokazujPodpowiedziCheckbox').checked == true) {
    document.getElementById('wordform').setAttribute('autoComplete',"on");
    document.getElementById('pokazujPodpowiedziImg').src = '/img/checkbox_off.png';
    document.getElementById('pokazujPodpowiedziCheckbox').checked = false;
  } else {         
    document.getElementById('wordform').setAttribute('autoComplete',"off");
    document.getElementById('pokazujPodpowiedziImg').src = '/img/checkbox_on.png';
    document.getElementById('pokazujPodpowiedziCheckbox').checked = true;
  }
}

function createNewDef(word, sType, chooseLang) {
  document.getElementById('searchword').select();
  curid = curid + 1;

  // button on the right
  var newdiv = document.createElement('div');
  var ide = 'buttonLeft_' + curid;
 
  if (word == undefined) {
    word = document.getElementById('searchword').value;
    var selIndex;
    selIndex = document.getElementById('jezykList').selectedIndex;
    if (selIndex == -1) selIndex=1;
    chooseLang = document.getElementById('jezykList').options[selIndex].value;
    selIndex = document.getElementById('zakresList').selectedIndex;
    if (selIndex == -1) selIndex=1;
    sType = document.getElementById('zakresList').options[selIndex].value ;
  } else {
  }
   
  if (word.length > 1 && document.getElementById('invisibles')!=null ) {
    newdiv.setAttribute('id', ide);
    newdiv.setAttribute('ling_word', word);
    newdiv.setAttribute('ling_lang', chooseLang);
    newdiv.setAttribute('ling_type', sType);
    newdiv.setAttribute('ling_tabidnumber', curid);
    newdiv.className = "buttonleft";
    newdiv.setAttribute('selectedTranslation', '0');
  
    var buttonAreaDiv = document.createElement('div');
    buttonAreaDiv.setAttribute('ling_word', word);
    buttonAreaDiv.setAttribute('ling_lang', chooseLang);
    buttonAreaDiv.setAttribute('ling_type', sType);
    buttonAreaDiv.setAttribute('ling_tabidnumber', curid);
    buttonAreaDiv.setAttribute('id', 'infobutton_'+curid);
    buttonAreaDiv.className = 'infobutton'; 

    var str = "";
    str += createLangImage(chooseLang);
    str += createRangeImage(sType);
    str += "<div style='width: 166px;'>" + word + "</div>";
    str += createCloseImage(ide);
    buttonAreaDiv.innerHTML = str;  
    
    newdiv.appendChild(buttonAreaDiv);
    document.getElementById('listaslow').appendChild(newdiv);
  
    if (newdiv.addEventListener) {
      newdiv.addEventListener('click', showTranslation, false);
      newdiv.addEventListener('mouseover', mouseOverHandler, false);
      newdiv.addEventListener('mouseout', mouseOutHandler, false);
    }
    else {
      newdiv.attachEvent('onclick', function () {
      
        document.getElementById('listawyszukiwanychdiv').style.display = 'block';
        var trgt = newdiv;
        var inode = document.getElementById('invisible_'+trgt.getAttribute('ling_tabidnumber'));
        var fillnode = document.getElementById('replaceme');
        fillnode.innerHTML = inode.innerHTML;
        trgt.style.backgroundColor = zeroBackgroundColor;
        var children = document.getElementById('listaslow').childNodes;
        var tmpID; 
        
        for (var i=children.length-1 ; i>=0 ; i--) {
          var tmpID = children[i].id;
          document.getElementById(tmpID).style.backgroundColor = '#ffffff';
          document.getElementById(tmpID).setAttribute('selectedTranslation', '0');  
        }
        trgt.style.backgroundColor = '#ff9713';
        trgt.setAttribute('selectedTranslation', '1');
        updateFormData( trgt.getAttribute('ling_word'), trgt.getAttribute('ling_type'), trgt.getAttribute('ling_lang') );
        
        document.title = trgt.getAttribute('ling_word') + " : LING.pl - internetowy słownik angielski, francuski, niemiecki, hiszpański, rosyjski";
        document.getElementById('pasektop_poz').innerHTML = "TŁUMACZENIE SŁOWA "+this.getAttribute('ling_word').toUpperCase()+", DEFINICJA I ZNACZENIE '"+this.getAttribute('ling_word').toUpperCase()+"'";
            
        sR(trgt.getAttribute('ling_type'));
        sL(trgt.getAttribute('ling_lang'));
        lcClick(document.getElementById('lc_flag_'+trgt.getAttribute('ling_lang')));
      }
      
       );
       

      newdiv.attachEvent('onmouseover', function () {
          if (newdiv.getAttribute('selectedTranslation')=='0') {
            newdiv.style.backgroundColor = '#e5e5e5';
          }
        });
      newdiv.attachEvent('onmouseout', function () {
          if (newdiv.getAttribute('selectedTranslation')=='0') {
            newdiv.style.backgroundColor = '#ffffff';
          }
        });
    }
  
    var idiv = document.createElement('div');
    var iid = 'invisible_' + curid;
    idiv.style.display = "none";
    idiv.setAttribute('id',iid);
    document.getElementById('invisibles').appendChild(idiv);
        
    var children = document.getElementById('listaslow').childNodes;
    var tmpID; 
    
    for (var i=children.length-1 ; i>=0 ; i--) {
      var tmpID = children[i].id;
      document.getElementById(tmpID).style.backgroundColor = '#ffffff';
      document.getElementById(tmpID).setAttribute('selectedTranslation', '0');  
    }
    
    newdiv.style.backgroundColor = '#ff9713';
    newdiv.setAttribute('selectedTranslation', '1');
    document.title = word + " : LING.pl - internetowy słownik angielski, francuski, niemiecki, hiszpański, rosyjski";
    document.getElementById('pasektop_poz').innerHTML = "TŁUMACZENIE SŁOWA "+word.toUpperCase()+", DEFINICJA I ZNACZENIE '"+word.toUpperCase()+"'";
    
    doit(word, chooseLang, sType, iid);
  } 
   
  return false;
}

function mouseOverHandler() {
  if (this.getAttribute('selectedTranslation')=='0') {
    this.style.backgroundColor = '#e5e5e5';
  }
}

function mouseOutHandler() {
  if (this.getAttribute('selectedTranslation')=='0') {
    this.style.backgroundColor = '#ffffff';
  }
}

function showTranslation() {
  document.getElementById('listawyszukiwanychdiv').style.display = 'block';
  var inode = document.getElementById('invisible_'+this.getAttribute('ling_tabidnumber'));
  var fillnode = document.getElementById('replaceme');
  fillnode.innerHTML = inode.innerHTML;
  this.style.backgroundColor = zeroBackgroundColor;
  var children = document.getElementById('listaslow').childNodes;
  var tmpID; 
  
  for (var i=children.length-1 ; i>=0 ; i--) {
    var tmpID = children[i].id;
    document.getElementById(tmpID).style.backgroundColor = '#ffffff';
    document.getElementById(tmpID).setAttribute('selectedTranslation', '0');  
  }
  this.style.backgroundColor = '#ff9713';
  this.setAttribute('selectedTranslation', '1');
  updateFormData( this.getAttribute('ling_word'), this.getAttribute('ling_type'), this.getAttribute('ling_lang') );

  document.title = this.getAttribute('ling_word') + " : LING.pl - internetowy słownik angielski, francuski, niemiecki, hiszpański, rosyjski";
  document.getElementById('pasektop_poz').innerHTML = "TŁUMACZENIE SŁOWA "+this.getAttribute('ling_word').toUpperCase()+", DEFINICJA I ZNACZENIE '"+this.getAttribute('ling_word').toUpperCase()+"'";
      

  var rangetoset;
  if ( this.getAttribute('ling_type') == 2 ) {
    rangetoset = 0;
  } else if ( this.getAttribute('ling_type') == 0 ) {
    rangetoset = 1;
  } else {
    rangetoset = 2;
  }
  
  sR(rangetoset);
  sL(this.getAttribute('ling_lang'));
  lcClick(document.getElementById('lc_flag_'+this.getAttribute('ling_lang')));
}

function updateFormData(word, type, lang) {
  document.getElementById('searchword').value = word;
  
  var i;
  
  for (i=0 ; i<document.getElementById('jezykList').options.length ; i++) {
    if (document.getElementById('jezykList').options[i].value == lang) {
       document.getElementById('jezykList').selectedIndex = i;   
    }
  }

  for (i=0 ; i<document.getElementById('zakresList').options.length ; i++) {
    if (document.getElementById('zakresList').options[i].value == type) {
       document.getElementById('zakresList').selectedIndex = i;   
    }
  }
  
}

function closeButton(bid) {
  document.getElementById('listaslow').removeChild( document.getElementById(bid) );
}

function createCloseImage(ide) {
  return "<div style='width: 19px;'><img src='/img/but/x_g_off.png' vspace='0' hspace='0' onmouseover='this.src=\"/img/but/x_g_over.png\";' onmousedown='this.src=\"/img/but/x_g_on.png\";' onmouseout='this.src=\"/img/but/x_g_off.png\";' onmouseup='this.src=\"/img/but/x_g_off.png\";' onclick='closeButton(\""+ide+"\")' /></div>";
}

function closeButtonsAll() {
  var node = document.getElementById('listaslow');

  while (node.hasChildNodes())
	{
	  node.removeChild(node.firstChild);
	}

}

function createLangImage(chooseLang) {
  var filename = '';
  switch (chooseLang) {
    case "0":   filename = '/img/flag_all.gif'; break;
    case "1":   filename = '/img/flag_eng.gif'; break;
    case "5":   filename = '/img/flag_de.gif'; break;
    case "4":   filename = '/img/flag_es.gif'; break;
    case "2":   filename = '/img/flag_fr.gif'; break;
    case "3":   filename = '/img/flag_it.gif'; break;
    case "101": filename = '/img/flag_pl.gif'; break;
    case "6":   filename = '/img/flag_ru.gif'; break;
  }
  return "<div style='width: 34px;'><img src='" + filename + "' style='border: 1px solid #fff;' vspace='0' hspace='0' /></div>";
}

function createRangeImage(sType) {
  var filename = '';
  switch (sType) {
    case "0": filename = '/img/range_normal.gif'; break;
    case "1": filename = '/img/range_wide.gif'; break;
    case "2": filename = '/img/range_narrow.gif'; break;
  }
  return "<div style='width: 28px;'><img src='" + filename + "' vspace='0' hspace='0' /></div>";
}

function makeInfoColumn(word, sType, chooseLang, element, examplesString) {

  var tmpHTML;
  var t;
  var wd = removeWeirdLetters(word);
  var linkURL = serverURL + wd +"," +chooseLang + "," + sType;
  var codedlinkURL = escape(linkURL);
  var title = "Tłumaczenie słowa " + wd + " w słowniku internetowym Ling.pl";
  var codedTitle = escape(title);
  
  var filename = '';
  switch (chooseLang) {
    case "0":   filename = '/img/flag_all.gif'; break;
    case "":    filename = '/img/flag_all.gif'; break;
    case "1":   filename = '/img/flag_eng.gif'; break;
    case "5":   filename = '/img/flag_de.gif'; break;
    case "4":   filename = '/img/flag_es.gif'; break;
    case "2":   filename = '/img/flag_fr.gif'; break;
    case "3":   filename = '/img/flag_it.gif'; break;
    case "101": filename = '/img/flag_pl.gif'; break;
    case "6":   filename = '/img/flag_ru.gif'; break;
  }
  var langimage = filename;

  switch (sType) {
    case "0": filename = '/img/range_normal.png'; break;
    case "1": filename = '/img/range_wide.png'; break;
    case "2": filename = '/img/range_narrow.png'; break;
  }
  var rangeimage = filename;
  
  tmpHTML = "";
  tmpHTML += "      <div style='width:720px;height:98px;float:left;'>";
  tmpHTML += "        <div class='topwordtitle'>";
  tmpHTML += "          <div style='width: 43px'><img style='margin-left:7px;border: 1px solid #fff;' src='" + langimage + "'  /></div>";
  tmpHTML += "          <div style='width: 29px'><img src='" + rangeimage + "' /></div>";
  tmpHTML += "          <div style='padding-right: 10px;'>" + wd + "</div>";
  tmpHTML += "        </div>";
  tmpHTML += "        <div style='float:left;text-align:left;height:65px;width: 720px;background-color:#000000;'>";
  tmpHTML += "          <div style='width: 362px;float:left;height: 65px;'>";          
  tmpHTML += "            <div id='podzielsie_zero'>";
  tmpHTML += "              <div class='first'><span>Podziel się ze znajomymi:</span></div>";
  tmpHTML += "              <div style='float:right;width:20px;height:20px;margin-top:3px;margin-right:2px;'><img src='/img/pin_down_off.png' vspace='0' hspace='0' style='cursor:pointer;' onclick='mopen(\"podzielsiediv\")' onmouseout='mclosetime()' /></div>";
  tmpHTML += "              <div id='podzielsiediv' class='podzielsiediv' onmouseover='mcancelclosetime()' onmouseout='mclosetime()'>";
  tmpHTML += "                  <div class='podzielsiepierwszy'><span>Podziel się ze znajomymi:</span></div>";
  tmpHTML += "                  <div class='icons_row' style='margin-top: 9px;'>";
  tmpHTML += "                    <div class='icon_facebook' onmouseover='this.className=\"icon_facebook_over\";' onmouseout='this.className=\"icon_facebook\";'><div style='float:left;width:17px;height:100%'>&nbsp;</div><div style='float:left;'><a target='_blank' href='http://www.facebook.com/share.php?u=" + codedlinkURL + "' >facebook</a></div></div>";
  tmpHTML += "                    <div class='icon_wykop' onmouseover='this.className=\"icon_wykop_over\";' onmouseout='this.className=\"icon_wykop\";'><div style='float:left;width:30px;height:100%'>&nbsp;</div><div style='float:left;'><a target='_blank' href='http://www.wykop.pl/dodaj?url=" + codedlinkURL + "&title=" + codedTitle + "'>wykop</a></div></div>";
  tmpHTML += "                    <div class='icon_ludzieonet' onmouseover='this.className=\"icon_ludzieonet_over\";' onmouseout='this.className=\"icon_ludzieonet\";'><div style='float:left;width:26px;height:100%'>&nbsp;</div><div style='float:left;'>ludzie.onet.pl</div></div>";
  tmpHTML += "                  </div>";
  tmpHTML += "                  <div class='icons_row'>";
  tmpHTML += "                    <div class='icon_twitter' onmouseover='this.className=\"icon_twitter_over\";' onmouseout='this.className=\"icon_twitter\";' ><div style='float:left;width:34px;height:100%'>&nbsp;</div><div style='float:left;'><a target='_blank' href='http://twitter.com/home?status=" + codedlinkURL + "'>twitter</a></div></div>";
  tmpHTML += "                    <div class='icon_digg' onmouseover='this.className=\"icon_digg_over\";' onmouseout='this.className=\"icon_digg\";' ><div style='float:left;width:28px;height:100%'>&nbsp;</div><div style='float:left;'><a target='_blank' href='http://digg.com/submit?url=" + codedlinkURL + "'>digg</a></div></div>";
  tmpHTML += "                    <div class='icon_sledzik' onmouseover='this.className=\"icon_sledzik_over\";' onmouseout='this.className=\"icon_sledzik\";' ><div style='float:left;width:28px;height:100%'>&nbsp;</div><div style='float:left;'><a target='_blank' href='http://nasza-klasa.pl//sledzik?shout=" + codedTitle + "%20" + codedlinkURL + "'>śledzik.pl</a></div></div>";
  tmpHTML += "                  </div>";
  tmpHTML += "                  <div class='icons_row'>";
  tmpHTML += "                    <div class='icon_delicious' onmouseover='this.className=\"icon_delicious_over\";' onmouseout='this.className=\"icon_delicious\";' ><div style='float:left;width:27px;height:100%'>&nbsp;</div><div style='float:left;'><a target='_blank' href='http://del.icio.us/post?url=" + codedlinkURL + "&title=" + codedTitle + "'>del.icio.us</a></div></div>";
  tmpHTML += "                    <div class='icon_blip' onmouseover='this.className=\"icon_blip_over\";' onmouseout='this.className=\"icon_blip\";' ><div style='float:left;width:39px;height:100%'>&nbsp;</div><div style='float:left;'><a target='_blank' href='http://blip.pl/dashboard?body=" + codedTitle + "+" + codedlinkURL + "'>blip</a></div></div>";
  tmpHTML += "                    <div class='icon_googlebookmarks' onmouseover='this.className=\"icon_googlebookmarks_over\";' onmouseout='this.className=\"icon_googlebookmarks\";' ><div style='float:left;width:27px;height:100%'>&nbsp;</div><div style='float:left;'><a target='_blank' href='http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=" + codedlinkURL + "&title=" + codedTitle + "'>googlebookmarks</a></div></div>";
  tmpHTML += "                  </div>";
  tmpHTML += "                  <div class='icons_row'>";
  tmpHTML += "                    <div class='icon_technokrati' onmouseover='this.className=\"icon_technokrati_over\";' onmouseout='this.className=\"icon_technokrati\";' ><div style='float:left;width:29px;height:100%'>&nbsp;</div><div style='float:left;'>technokrati</div></div>";
  tmpHTML += "                    <div class='icon_flaker' onmouseover='this.className=\"icon_flaker_over\";' onmouseout='this.className=\"icon_flaker\";'><div style='float:left;width:31px;height:100%'>&nbsp;</div><div style='float:left;'><a target='_blank' href='http://flaker.pl/add2flaker.php?url=" + codedlinkURL + "&title=" + codedTitle + "'>flaker</a></div></div>";
  tmpHTML += "                    <div class='icon_pinger' onmouseover='this.className=\"icon_pinger_over\";' onmouseout='this.className=\"icon_pinger\";' ><div style='float:left;width:33px;height:100%'>&nbsp;</div><div style='float:left;'><a target='_blank' href='http://pinger.pl/share?title=" + codedTitle + "&content=" + codedlinkURL + "'>pinger</a></div></div>";
  tmpHTML += "                  </div>";
  tmpHTML += "              </div>";
  tmpHTML += "            </div>";
  tmpHTML += "            <div id='przyklady_zero' class='przyklady_zero'>";
  tmpHTML += "              <div class='przyklady_zero_first'><span>Przykłady użycia słowa:</span></div>";
  tmpHTML += "              <div style='float:right;width:20px;height:20px;margin-top:3px;margin-right:2px;'><img src='/img/pin_down_off.png' vspace='0' hspace='0' style='cursor:pointer;' onclick='mopen(\"przykladydiv\")' onmouseout='mclosetime()' /></div>";
  tmpHTML += "              <div class='przykladydiv' id='przykladydiv' onmouseover='mcancelclosetime()'' onmouseout='mclosetime()'><span  class='przyklady_zero_first'>Przykłady użycia słowa:</span><br /><div class='examples'>"+examplesString+"</div></div>";
  tmpHTML += "            </div>";
  tmpHTML += "          </div>";
  tmpHTML += "          <div style='float:left;width: 358px;height: 65px;'>";
  tmpHTML += "            <div class='odnosnikdiv'>Odnośnik do bieżącego tłumaczenia:</div>";
  tmpHTML += "            <div class='odnosnikinputdiv'><input type='text' class='odnosnikinput' value='http://www.ling.pl/" + word + "," + chooseLang + "," + sType + "' /></div>";
  tmpHTML += "            <div class='odnosnikikreskadiv'><img src='/img/odnosniki_kreska.png' /></div>";
  tmpHTML += "            <div class='sprawdzwinnychdiv'>Sprawdź także w innych słownikach</div>";
  tmpHTML += "            <div class='inneslownikidiv'><a target='_blank' href='http://angielski.leksyka.pl/search?ctg=0.0.0&sr=0&sp=" + word + "&st=1'>Leksyka.pl</a> | <a target='_blank' href='http://www.dict.pl/dict?word=" + word + "&words=&lang=EN'>dict.pl</a> | <a target='_blank' href='http://www.macmillandictionary.com/dictionary/british/"+word+"'>Merriam-Webster</a></div>";
  tmpHTML += "          </div>";
  tmpHTML += "        </div>";
  tmpHTML += "      </div>";
  
  element.innerHTML = tmpHTML + element.innerHTML; 

}



function whenLoading(){
	document.getElementById('replaceme').innerHTML = "<p>Ładowanie danych</p>";
}

function whenLoaded(){
	document.getElementById('replaceme').innerHTML = "<p>Ładowanie danych...</p>";
}

function whenInteractive(){
  document.getElementById('replaceme').innerHTML = "<p>Ładowanie danych......</p>";
}

function whenCompleted(){
  document.getElementById('listawyszukiwanychdiv').style.display = 'block';

  //var arrayConnectionNr = this.vars['activeConnection'][0];
  var rr = document.getElementById('replaceme');
  var tmpElement = document.getElementById(this.element);
  
  var cl;
  if (this.vars['chooseLang'] == undefined) {
    cl = '0';
  } else {
    cl = this.vars['chooseLang'][0];
  }
  
  var word = this.vars['word'][0];
  
  word = removeWeirdLetters(word);
  word = word.toLowerCase();
  
  ajax_options_hide();

  var importDIVs = tmpElement.getElementsByTagName("div");
  var examplesString = '';
  for (var i = 0; i < importDIVs.length; i++)
  {
    var clName = importDIVs[i].getAttribute("class");
    if (clName == "przykladyImport") {
      examplesString = importDIVs[i].innerHTML;
      tmpElement.removeChild( importDIVs[i] );
    }                                                                 7
  }
 // alert(examplesString);
  if (word!='zgarnij 50zł na e-booki!') {
    makeInfoColumn(word, this.vars['sType'][0], cl, tmpElement, examplesString);
    makeIVO(tmpElement);
  }
          //alert(word);
  if (defVoice == 'None') {
  
  } else if (defVoice =='Br') {
    playBrit(word);
  } else if (defVoice =='Am') {
    playWord(word);
  }
       
  rr.innerHTML = tmpElement.innerHTML;


  if (pageTracker != undefined && pageTracker != null) {
  	pageTracker._trackPageview("/" + word);
  }
  
  rr.innerHTML = tmpElement.innerHTML;
  var now = new Date();
  var rfs = document.getElementById('reklamaFrameSmall');
  if (rfs != null) {
  	rfs.contentWindow.document.body.innerHTML = "";
    rfs.src = "reklamaSmall.html" + "?" + now.getTime();
  }
  
  document.getElementById('reklamaFrame').src =  "reklama.html" + "?" + now.getTime();
  setTimeout("reloadReklama()", 1000);
  
  
  
  if (word=='zgarnij 50zł na e-booki!') {
  
    document.getElementById('infocolumnsblock').style.display = 'none';
    rr.style.width = '1000';
    document.getElementById('arbodiv').innerHTML = '';
    document.getElementById('reklamaFrameSmall').style.display = 'none';
    
  } else {
    document.getElementById('infocolumnsblock').style.display = 'block';   
    document.getElementById('reklamaFrameSmall').style.display = 'block';
    rr.style.width = '720';
  }
  
  
}



function doit(word, chooseLang, sType, iid){
  ajax = new sack();

	ajax.setVar("word", word);
	ajax.setVar("sType", sType);
    
  if (chooseLang > 0) {
    ajax.setVar("chooseLang", chooseLang);
  }
  
  ajax.requestFile = serverURL + "php/lingfeed-30.php";
	ajax.method = "POST";
	ajax.element = iid;
	ajax.onLoading = whenLoading;
	ajax.onLoaded = whenLoaded; 
	ajax.onInteractive = whenInteractive;
	ajax.onCompletion = whenCompleted;
	ajax.runAJAX();


}




 /* 
  FUNKCJE LUŹNE
 */ 
 
function atf(text) {
  document.getElementById('searchword').value = document.getElementById('searchword').value + text;
  document.getElementById('searchword').focus();
}
function sbg(div) {
  div.style.backgroundImage = "url('/img/highlight_symbol.gif')";
}
function clearBg(div) {
  div.style.background = "";
}

function makeIVO(tgt) {

    var currentDictionary = '';
    var tmp;
    
    if (tgt != null) {
    
      var wrds = tgt.getElementsByTagName("div");
      for (var i = 0; i < wrds.length; i++)
      {
        var cl = wrds[i].getAttribute("class");
      	if (cl == null && wrds[i].attributes != null && wrds[i].attributes['class'] != null) cl = wrds[i].attributes['class'].nodeValue;
        if (cl == null) continue;
        // zapisujemy w jakim slowniku jestesmy
        if (cl == "dictname") {
          tmp = wrds[i].innerHTML;
          if ((tmp.toLowerCase().indexOf('angielsko') != -1 ) || (tmp.toLowerCase().indexOf('dictionary') != -1 ) ) {
            currentDictionary = "angielski";
          } else if (tmp.toLowerCase().indexOf('niemiecko') != -1 ) {
            currentDictionary = "niemiecki";
          } else if (tmp.toLowerCase().indexOf('włosko') != -1 ) {
            currentDictionary = "wloski";
          } else if (tmp.toLowerCase().indexOf('rosyjsko') != -1 ) {
            currentDictionary = "rosyjski";
          } else if (tmp.toLowerCase().indexOf('francusko') != -1 ) {
            currentDictionary = "francuski";
          } else if (tmp.toLowerCase().indexOf('hiszpańsko') != -1 ) {
            currentDictionary = "hiszpanski";
          } else {
            currentDictionary = '';
          }
        }
        
      	if (cl == null || cl != "dictword") continue;
    
        var glosnik;
        var przerywnik;
        var glosnik2;
        var maxMillan;
        
        var slowoGole = strip_tags(wrds[i].innerHTML,"").toLowerCase();
        if (currentDictionary == 'angielski') {
          glosnik = "<a href=\"javascript:playWord('" + slowoGole.toLowerCase()  + "')\"><img class='glosnikus' src='/php/glosnik.php?word="+slowoGole+"&lang=us' /></a>";
          przerywnik = '';//<img src="/img/snd_przerywnik.png" hspace="0" vspace="0" class="glosnikprzerywnik" />';
          glosnik2 = "<a onmouseover='mopen(\"macobrazek_"+i+"\")' onmouseout='mclosetime()' href=\"javascript:playBrit('" + slowoGole.toLowerCase()  + "')\"><img class='glosnikbrit' src='/php/glosnik.php?word="+slowoGole+"&lang=br' /></a>"; 
          macMillan = '<a id="macobrazek_'+i+'" style="visibility:hidden;font-size:10px;line-height: 12px;vertical-align: middle;text-decoration:none;" target="_blank" href="http://www.macmillandictionary.com/dictionary/british/'+slowoGole.toLowerCase()+'"><img onmouseover="mcancelclosetime()" onmouseout="mclosetime()" src="/img/partnerzy/pbymaxmillan.gif" target="_blank" /></a>';
          wrds[i].innerHTML = '<span class="goleslowo">' + slowoGole + "</span>" + glosnik + przerywnik + glosnik2 + macMillan; 
        
        } else if (currentDictionary == 'francuski') {
          //
          glosnik = "<a href=\"javascript:playFr('" + slowoGole.toLowerCase()  + "')\"><img class='glosnikus' src='/php/glosnik.php?word="+slowoGole+"&lang=fr' /></a>";
          wrds[i].innerHTML = '<span class="goleslowo">' + slowoGole + "</span>" + glosnik; 
        
        } else if (currentDictionary == 'niemiecki') {
          glosnik = "<a href=\"javascript:playDe('" + slowoGole.toLowerCase()  + "')\"><img class='glosnikus' src='/php/glosnik.php?word="+slowoGole+"&lang=de' /></a>";
          wrds[i].innerHTML = '<span class="goleslowo">' + slowoGole + "</span>" + glosnik; 
        
        } else if (currentDictionary == 'wloski') {
          glosnik = "<a href=\"javascript:playIt('" + slowoGole.toLowerCase()  + "')\"><img class='glosnikus' src='/php/glosnik.php?word="+slowoGole+"&lang=it' /></a>";
          wrds[i].innerHTML = '<span class="goleslowo">' + slowoGole + "</span>" + glosnik; 
        
        } else if (currentDictionary == 'rosyjski') {
          
          glosnik = "<a href=\"javascript:playRu('" + decodeCyrylica(slowoGole)  + "')\"><img class='glosnikus' src='/php/glosnik.php?word="+slowoGole+"&lang=ru' /></a>";
          wrds[i].innerHTML = '<span class="goleslowo">' + slowoGole + "</span>" + glosnik; 
  
        } else if (currentDictionary == 'hiszpanski') {
          glosnik = "<a href=\"javascript:playEs('" + slowoGole.toLowerCase()  + "')\"><img class='glosnikus' src='/php/glosnik.php?word="+slowoGole+"&lang=es' /></a>";
          wrds[i].innerHTML = '<span class="goleslowo">' + slowoGole + "</span>" + glosnik; 
              
        } else {
          wrds[i].innerHTML = '<span class="goleslowo">' + slowoGole + "</span>";
        }
    }
  
    
    
  } 
    
}

function playWord(word) {
	try { document.getElementById('mp3player').playSound('/php/playWord.php?word=' + word); }
	catch (e) { }
}

function playBrit(word) {
	try { document.getElementById('mp3player').playSound('/php/playBrit.php?word=' + word); }
	catch (e) { }
}

function playFr(word) {
	try { document.getElementById('mp3player').playSound('/php/playFr.php?word=' + word); }
	catch (e) { }
}

function playDe(word) {
	try { document.getElementById('mp3player').playSound('/php/playDe.php?word=' + word); }
	catch (e) { }
}

function playIt(word) {
	try { document.getElementById('mp3player').playSound('/php/playIt.php?word=' + word); }
	catch (e) { }
}

function playEs(word) {
	try { document.getElementById('mp3player').playSound('/php/playEs.php?word=' + word); }
	catch (e) { }
}

function playRu(word) {
	try { document.getElementById('mp3player').playSound('/php/playRu.php?word=' + word); }
	catch (e) { }
}

function sV(type) {
  defVoice = type;
  createCookie('defVoice', type, 1000);
  document.getElementById('voiceAsDef_Am').style.fontWeight = 'normal';
  document.getElementById('voiceAsDef_Br').style.fontWeight = 'normal';
  document.getElementById('voiceAsDef_None').style.fontWeight = 'normal';
  document.getElementById('voiceAsDef_'+type).style.fontWeight = 'bold';
}

function sL(nr) {
  if (document.getElementById('jezykList').options[nr] != null) {
    document.getElementById('jezykList').options[nr].selected = true;
  }
}

function sL_default(nr) {
  /**********************/
  /* wersja multiselect */
  /**********************/
  var jL = document.getElementById('jezykList');
  
  if (nr == 0) {
  
    jL.options[0].selected = false;
    var i;
    for (i=1 ; i<jL.length ; i++) {
      jL.options[i].selected = true;
      document.getElementById('opts_lang_'+i).checked = true;
    }
    
  } else {
  
    if (jL.options[nr].selected == true) {
      jL.options[nr].selected = false;
    } else {
      jL.options[nr].selected = true;
    }

  }
}


function sR(nr) {
  document.getElementById("zakresList").selectedIndex=nr;
  document.getElementById("range0").src = '/img/range_narrow.png';
  document.getElementById("range1").src = '/img/range_normal.png';
  document.getElementById("range2").src = '/img/range_wide.png';
  if (nr == 0) {
    document.getElementById("range0").src = '/img/range_narrow_on.png';  
  } else if (nr == 1) {
    document.getElementById("range1").src = '/img/range_normal_on.png';  
  } else if (nr == 2) {
    document.getElementById("range2").src = '/img/range_wide_on.png';  
  }
}

function tab2str(tab) {
  var i;
  var str = '';
  for (i=0 ; i<tab.length ; i++) {
    str += tab[i] + ';';
  }
  return str;
}




function showMoreLanguages() {

}

function imON(id) {
  document.getElementById(id).style.display="block";
}

function imOFF(id) {
  document.getElementById(id).style.display="none";
}

function switchONOFF(id) {
  if (document.getElementById(id).style.display == 'none') {
    document.getElementById(id).style.display="block";
  } else {
    document.getElementById(id).style.display="none";
  }
}







function decodeCyrylica(word) {
word = word.replace("а","a");
word = word.replace("б","b");
word = word.replace("в","w");
word = word.replace("г","g");
word = word.replace("д","d");
word = word.replace("е","e");
word = word.replace("ж","z");
word = word.replace("з","z");
word = word.replace("и","i");
word = word.replace("й","j");
word = word.replace("к","k");
word = word.replace("л","l");
word = word.replace("м","m");
word = word.replace("н","n");
word = word.replace("о","o");
word = word.replace("п","p");
word = word.replace("р","r");
word = word.replace("с","s");
word = word.replace("т","t");
word = word.replace("у","u");
word = word.replace("ф","f");
word = word.replace("х","c");
word = word.replace("ц","c");
word = word.replace("ч","c");
word = word.replace("ш","s");
word = word.replace("щ","s");
word = word.replace("ъ","y");
word = word.replace("ы","y");
word = word.replace("ь","y");
word = word.replace("э","e");
word = word.replace("ю","i");
word = word.replace("я","j");
return word;

}




function removeWeirdLetters(word) {
word = word.replace("%C4%99","ę");
word = word.replace("%C3%B3","ó");
word = word.replace("%C5%82","ł");      
word = word.replace("%C5%9B","ś");
word = word.replace("%C4%85","ą");
word = word.replace("%C5%BC","ż");
word = word.replace("%C5%BA","ź");
word = word.replace("%C4%87","ć");
word = word.replace("%C5%84","ń");
word = word.replace("%C4%98","ę");
word = word.replace("%C3%93","ó");
word = word.replace("%C5%81","ł");
word = word.replace("%C5%9A","ś");
word = word.replace("%C4%84","ą");
word = word.replace("%C5%BB","ż");
word = word.replace("%C5%B9","ź");
word = word.replace("%C4%86","ć");
word = word.replace("%C5%83","ń");
word = word.replace("%20"," ");word = word.replace("%20"," ");word = word.replace("%20"," ");word = word.replace("%20"," ");word = word.replace("%20"," ");
word = word.replace("%c5%93","œ");
word = word.replace("%c3%bf","ÿ");
word = word.replace("%c3%b1","ñ");
word = word.replace("%c3%af","ï");
word = word.replace("%c3%b9","ù");
word = word.replace("%c3%bb","û");
word = word.replace("%c3%aa","ê");
word = word.replace("%c3%a2","â");
word = word.replace("%c3%a0","à");
word = word.replace("%c3%b4","ô");
word = word.replace("%c3%ae","î");
word = word.replace("%c3%a8","è");
word = word.replace("%c3%a7","ç");
word = word.replace("%c3%ba","ú");
word = word.replace("%c3%ad","í");
word = word.replace("%c3%a9","é");
word = word.replace("%c3%a1","á");
word = word.replace("%c3%ab","ë");
word = word.replace("%c3%bc","ü");
word = word.replace("%c3%a4","ä");
word = word.replace("%c3%b6","ö");
word = word.replace("%c3%9f","ß");
word = word.replace("%d0%b0","а");
word = word.replace("%d0%b1","б");
word = word.replace("%d0%b2","в");
word = word.replace("%d0%b3","г");
word = word.replace("%d0%b4","д");
word = word.replace("%d0%b5","е");
word = word.replace("%d0%b6","ж");
word = word.replace("%d0%b7","з");
word = word.replace("%d0%b8","и");
word = word.replace("%d0%b9","й");
word = word.replace("%d0%ba","к");
word = word.replace("%d0%bb","л");
word = word.replace("%d0%bc","м");
word = word.replace("%d0%bd","н");
word = word.replace("%d0%be","о");
word = word.replace("%d0%bf","п");
word = word.replace("%d1%80","р");
word = word.replace("%d1%81","с");
word = word.replace("%d1%82","т");
word = word.replace("%d1%83","у");
word = word.replace("%d1%84","ф");
word = word.replace("%d1%85","х");
word = word.replace("%d1%86","ц");
word = word.replace("%d1%87","ч");
word = word.replace("%d1%88","ш");
word = word.replace("%d1%89","щ");
word = word.replace("%d1%8a","ъ");
word = word.replace("%d1%8b","ы");
word = word.replace("%d1%8c","ь");
word = word.replace("%d1%8d","э");
word = word.replace("%d1%8e","ю");
word = word.replace("%d1%8f","я");

  return word;  
}






function strip_tags (input, allowed) {
           allowed = (((allowed || "") + "")
              .toLowerCase()
              .match(/<[a-z][a-z0-9]*>/g) || [])
              .join(''); // making sure the allowed arg is a string containing only tags in lowercase (<a><b><c>)
           var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
               commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
           return input.replace(commentsAndPhpTags, '').replace(tags, function($0, $1){
              return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
           });
        }


var start=false;

function animateOpacity() {
    if (start == false) {
      start = true;
      //setTimeout('animateOpacityOn();', 600)
    }
}

var step = 0;
function animateOpacityOn() {
  if (step < 9) {
    step = step + 0.7;
    setTimeout('animateOpacityOn();', 100);
    var z = 0.1 * step;
    var x = 10 * step;
    if ( document.getElementById('replaceme')!= null ) {
      document.getElementById('replaceme').style.opacity = z;
      document.getElementById('replaceme').style.filter = "alpha(opacity="+x+")";
    }
    if ( document.getElementById('infocolumnsblock')!= null ) {
      document.getElementById('infocolumnsblock').style.opacity = z;
      document.getElementById('infocolumnsblock').style.filter = "alpha(opacity="+x+")";
    }
  } else {
    if ( document.getElementById('replaceme')!= null ) {
      document.getElementById('replaceme').style.opacity = "1.0";
      document.getElementById('replaceme').style.filter = "alpha(opacity=100)";
    }
    if ( document.getElementById('infocolumnsblock')!= null ) {
      document.getElementById('infocolumnsblock').style.opacity = "1.0";
      document.getElementById('infocolumnsblock').style.filter = "alpha(opacity=100)";
    }
  }

}



var timeout	= 500;
var closetimer	= null;
var ddmenuitem	= null;

function mopen(id)
{	
	mcancelclosetime();
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}

function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

function moreInfo() { 
  var txt; 
  if (window.getSelection) { txt = window.getSelection(); } 
  else if (document.getSelection) { txt = document.getSelection(); } 
  else if (document.selection) { txt = document.selection.createRange().text; } 
  else { return; } 
  
  var count = txt.toString().length;
 
  if (count > 1) {
    sR(1);
    lcClick(document.getElementById('lc_flag_0'));
    sL(0);
    document.getElementById('searchword').value = txt;
    createNewDef();
  }
}

function closeDownInfo() {
  document.getElementById('downInfo').style.display = 'none';
  createCookie('defDownInfoVisible', 'none', 1000);
}  

  















function reloadReklama() {

  var rf = document.getElementById('reklamaFrame').contentWindow.document.body;  
  if (rf != null) {
    rf.innerHTML = rf.innerHTML.replace("<center>",'');
    rf.innerHTML = rf.innerHTML.replace("</center>",'');
    
    var xxx = rf.innerHTML;
    var pos = xxx.indexOf('</script>');
    rf.innerHTML = xxx.substring(pos+9,xxx.length);
    
    var childs = rf.childNodes;
    var i = 0;
    
    if (childs.length < 2) {
      // nie zaladowana reklama, czekamy dalej
      setTimeout("reloadReklama()", 1000);
    } else {
      // usuniecie starej reklamy
      if ( document.getElementById('arbodiv').hasChildNodes() ){
        while ( document.getElementById('arbodiv').childNodes.length >= 1 ) {
          document.getElementById('arbodiv').removeChild( document.getElementById('arbodiv').firstChild );       
        } 
      }
      
      document.getElementById('arbodiv').innerHTML = '';
      
      // przekopiowanie nowej reklamy  
      for (i=0 ; i<childs.length ; i++) {
        document.getElementById('arbodiv').appendChild(childs[i]);    
      }
    }
   }  
}


function reloadReklamaSmall() {

  var rf = document.getElementById('reklamaFrameSmall').contentWindow.document.body;  
  
  rf.innerHTML = rf.innerHTML.replace("<center>",'');
  rf.innerHTML = rf.innerHTML.replace("</center>",'');
  
  var xxx = rf.innerHTML;
  var pos = xxx.indexOf('</script>');
  rf.innerHTML = xxx.substring(pos+9,xxx.length);
  
  var childs = rf.childNodes;
  var i = 0;
  
  if (childs.length < 2) {
    // nie zaladowana reklama, czekamy dalej
    setTimeout("reloadReklamaSmall()", 1000);
  } else {
    // usuniecie starej reklamy
    if ( document.getElementById('arbodivsmall').hasChildNodes() ){
      while ( document.getElementById('arbodivsmall').childNodes.length >= 1 ) {
        document.getElementById('arbodivsmall').removeChild( document.getElementById('arbodivsmall').firstChild );       
      } 
    }
    
    // przekopiowanie nowej reklamy  
    for (i=0 ; i<childs.length ; i++) {
      document.getElementById('arbodivsmall').appendChild(childs[i]);    
    }
  }  
}


function loadAlterWord(alterWordSpan) {
  document.getElementById('searchword').value = alterWordSpan.innerHTML;
  createNewDef();  
}



