/**
*
*  AJAX IFRAME METHOD (AIM)
*  http://www.webtoolkit.info/
*
**/

AIM = {

    frame : function(c) {

        var n = 'f' + Math.floor(Math.random() * 99999);
        var d = document.createElement('DIV');
        d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
        document.body.appendChild(d);

        var i = document.getElementById(n);
        if (c && typeof(c.onComplete) == 'function') {
            i.onComplete = c.onComplete;
        }

        return n;
    },

    form : function(f, name) {
        f.setAttribute('target', name);
    },

    submit : function(f, c) {
        AIM.form(f, AIM.frame(c));
        if (c && typeof(c.onStart) == 'function') {
            return c.onStart();
        } else {
            return true;
        }
    },

    loaded : function(id) {
        var i = document.getElementById(id);
        if (i.contentDocument) {
            var d = i.contentDocument;
        } else if (i.contentWindow) {
            var d = i.contentWindow.document;
        } else {
            var d = window.frames[id].document;
        }
        if (d.location.href == "about:blank") {
            return;
        }

        if (typeof(i.onComplete) == 'function') {
            i.onComplete(d.body);
        }
    }

}

function getCld(par, cld)
{
	var foo = par.getElementsByTagName(cld);
	return foo[0];
}

function getClt(par, cld)
{
	return getCld(par, cld).childNodes[0].nodeValue;
}

function commentAddCallback()
{
}

function commentAddedCallback(xml)
{
	var num = getClt(xml, "num");
	showBlogComments(num);
}

window.wordsCache = [];
window.definitionCache = [];
window.idCache = [];
window.loadId = 0;
window.loaded = [];
window.cancelled = [];
window.displayed = 0;
window.imagePreload = -1;
window.criticalPreload = -1;
window.critToLoad = 0;
window.allToLoad = 0;
window.dictShown = true;
window.currentSettings = 0;
window.savedSettings = [];
window.langsCache = [];

window.dictAssign = [];
window.dictAssign[1] = "img/flag_eng.gif";
window.dictAssign[5] = "img/flag_de.gif";
window.dictAssign[4] = "img/flag_es.gif";
window.dictAssign[2] = "img/flag_fr.gif";
window.dictAssign[3] = "img/flag_it.gif";
window.dictAssign[6] = "img/flag_ru.gif";
window.dictAssign[101] = "img/flag_pl.gif";

function preloadImages()
{
	imgp = new Array();
	imgpi = new Array();
	imgp.push("banner_tlo-ps.gif");
 	imgp.push("button_all_on.gif");
 	imgp.push("button_cyrylica.gif");
 	imgp.push("search_background.gif");
 	imgp.push("search_button.gif");
 	imgp.push("flag_de.gif");
 	imgp.push("flag_eng.gif");
 	imgp.push("flag_es.gif");
 	imgp.push("flag_fr.gif");
 	imgp.push("flag_it.gif");
 	imgp.push("flag_pl.gif");
 	imgp.push("flag_ru.gif");
 	imgp.push("ling_logo.gif");
	window.criticalPreload = imgp.length;
	window.critToLoad = imgp.length;
	for (i = 0; i < imgp.length; i++)
	{
		imgpi[i] = new Image;
		imgpi[i].onload = function() {
			window.criticalPreload--;
		}
		imgpi[i].onerror = function() {
			window.criticalPreload--;
		}
		imgpi[i].src = "img/" + imgp[i];
	}
}

function preloadOtherImages()
{
	imgs = new Array();
	imgs2 = new Array();
	imgo = new Array();
	imgo2 = new Array();
 	imgs.push("button_main_on.gif");
 	imgs.push("button_google.gif");
 	imgs.push("button_main_off.gif");
 	imgs.push("button_igoogle.gif");
 	imgs.push("button_lingtoolbar.gif");
	imgs.push("main_tab_background.gif");
	imgs.push("main_tab_bottom.gif");
	imgs.push("main_tab_left_right.gif");
	imgs.push("main_tab_top.gif");
	imgs.push("main_title_background.gif");
	imgs.push("main_title_background2.gif");
	imgs.push("najpopularniejsze_hasla_bg.gif");
	// obligatory imgs stop here
 	imgs2.push("button_cyrylica_click.gif");
 	imgs2.push("button_cyrylica_on.gif");
 	imgs2.push("button_google_on.gif");
 	imgs2.push("button_igoogle_on.gif");
 	imgs2.push("button_lingtoolbar_on.gif");
 	imgs2.push("button_main_off2.gif");
 	imgs2.push("button_main_off_onmouseover.gif");
 	imgs2.push("button_none.gif");
 	imgs2.push("button_none_click.gif");
 	imgs2.push("button_none_on.gif");
 	imgs2.push("cyrylica_background.gif");
 	imgs2.push("cyrylica_highlight.gif");
 	imgs2.push("cyrylica_zamknij.gif");
 	imgs2.push("highlight_symbol.gif");
 	imgs2.push("highlight_symbol2.gif");
 	imgs2.push("kpmg.gif");
 	imgs2.push("main_menu_button_background1.gif");
 	imgs2.push("main_menu_button_background2.gif");
 	imgs2.push("search_button_click.gif");
 	imgs2.push("search_button_on.gif");
 	imgs2.push("search_toolbar_background.gif");
 	imgs2.push("searchresults_closetab.gif");
 	imgs2.push("searchresults_current_tab_left.gif");
 	imgs2.push("searchresults_current_tab_middle.gif");
 	imgs2.push("searchresults_current_tab_right.gif");
 	imgs2.push("searchresults_minus.gif");
 	imgs2.push("searchresults_minus_on_or_click copy.gif");
 	imgs2.push("searchresults_minus_on_or_click.gif");
 	imgs2.push("searchresults_plus.gif");
 	imgs2.push("searchresults_plus_on_or_click.gif");
 	imgs2.push("searchresults_tab_left.gif");
 	imgs2.push("searchresults_tab_line.gif");
 	imgs2.push("searchresults_tab_middle.gif");
 	imgs2.push("searchresults_tab_middle_jpg.gif");
 	imgs2.push("searchresults_tab_right.gif");
 	imgs2.push("searchtoolbar_1column_mouseout.gif");
 	imgs2.push("searchtoolbar_1column_mouseover.gif");
 	imgs2.push("searchtoolbar_1column_selected.gif");
 	imgs2.push("searchtoolbar_2columns_mouseout.gif");
 	imgs2.push("searchtoolbar_2columns_mouseover.gif");
 	imgs2.push("searchtoolbar_2columns_selected.gif");
 	imgs2.push("searchtoolbar_lettersize_selected_or_mouseouver.gif");
 	imgs2.push("searchtoolbar_savesettings_background.gif");
 	imgs2.push("searchtoolbar_savesettings_background_click.gif");
 	imgs2.push("searchtoolbar_savesettings_background_on.gif");
 	imgs2.push("searchtoolbar_searchwidth_narrow_on_or_selected.gif");
 	imgs2.push("searchtoolbar_searchwidth_normal_on_or_selected.gif");
	imgs2.push("searchtoolbar_searchwidth_selected_or_mouseover.gif");
 	imgs2.push("searchtoolbar_searchwidth_narrow_off.gif");
 	imgs2.push("searchtoolbar_searchwidth_normal_off.gif");
    imgs2.push("searchtoolbar_searchwidth_wide_off.gif");
 	imgs2.push("searchtoolbar_searchwidth_selected_or_mouseover2.gif");
 	imgs2.push("searchtoolbar_searchwidth_wide_on_or_selected.gif");
 	imgs2.push("searchtoolbar_spacer.gif");
 	imgs2.push("speaker_icon.gif");
	imgs2.push("button_all.gif");
	imgs2.push("button_all_click.gif");
	window.imagePreload = imgs.length;
	window.allToLoad = imgs.length;
	for (i = 0; i < imgs.length; i++)
	{
		imgo[i] = new Image;
		imgo[i].onload = function() {
			window.imagePreload--;
		}
		imgo[i].onerror = function() {
			window.imagePreload--;
		}
		imgo[i].src = "img/" + imgs[i];	
	}
	for (i = 0; i < imgs2.length; i++)
	{
		imgo2[i] = new Image;
		imgo2[i].src = "img/" + imgs2[i];
	}
}

function setSrc(div, img)
{
  var tgt = document.getElementById(div);
  tgt.src = img;
}

function loadRandomWords()
{
  if (window.XMLHttpRequest) 
  { // Mozilla, Safari, Opera ...
    http_request = new XMLHttpRequest();
  } 
  else if (window.ActiveXObject) 
  { // IE
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
  }
  http_request.onreadystatechange = function() {
    if (http_request.readyState == 4 && http_request.status == 200)
    {
	  var sprep = "Czy znasz te słowa: ";
	  var foo = http_request.responseXML;
      var wds = foo.getElementsByTagName("word");
	  for (i = 0; i < wds.length; i++)
	  {
        if (i > 0) sprep += ", ";
		var el = wds[i].childNodes[0].nodeValue;
		if (el == null) continue;
		sprep += "<a href='/def_" + encodeURIComponent(el) + "'>" + el + "</a>";
	  }
	  document.getElementById('randomWords').innerHTML = sprep;
	}
  }
  http_request.open('GET', 'randomWords.xml', true);
  http_request.send(null);
}

function handleDaAdz()
{
	var now = new Date();
  
  
  var n = document.getElementById('reklamaFrame').contentWindow.document.body;
  
  if ( n.hasChildNodes() ){
    while ( n.childNodes.length >= 1 ) {
      n.removeChild( n.firstChild );       
    } 
  }
    
	document.getElementById('reklamaFrame').contentWindow.document.body.innerHTML = "";
	document.getElementById('reklamaFrame').src = "reklama.html" + "?" + now.getTime();
	//checkStupidAdHeight();
	reIndex();
	fooLoad();
}

function clearLoadingScreen()
{
	if (window.criticalPreload == -1) 
	{
		preloadImages();
	}
	if (window.criticalPreload == 0) 
	{
//		document.getElementById('loading').style.display = "none";
		document.getElementById('gorneMenu').style.display = "block";
		document.getElementById('gora').style.display = "block";
		document.getElementById('gorneButtony').style.display = "none";
		document.getElementById('reklama').style.display = "none";
		document.getElementById('wyniki').style.display = "none";
		document.getElementById('slowniki').style.display = "none";
		document.getElementById('podstrona').style.display = "none";
		document.getElementById('main').style.display = "block";
		document.body.style.background = "white top left repeat-x url(img/banner_tlo-ps.gif)";
		document.getElementById('wordbox').focus();
		//loadRandomWords();
		window.criticalPreload = -2;
		preloadOtherImages();
	}
	if (window.imagePreload == 0 && window.criticalPreload == -2)
	{
		document.getElementById('gorneMenu').style.display = "block";
		document.getElementById('gora').style.display = "block";
		document.getElementById('gorneButtony').style.display = "block";
		document.getElementById('reklama').style.display = "block";
		document.getElementById('wyniki').style.display = "none";
		document.getElementById('slowniki').style.display = "block";
		document.getElementById('podstrona').style.display = "block";
		window.imagePreload = -2;
		window.finishedLoading = true;
		handleDaAdz();
	}
	if (window.imagePreload > 0 || window.criticalPreload > 0)
	{
		if (window.criticalPreload > 0)
		{
			var perc = (window.critToLoad - window.criticalPreload) * 100 / window.critToLoad;
			perc = Math.round(perc);
//			document.getElementById('perc_load').innerHTML = "" + perc;
		}
	}
	if (window.criticalPreload != -2 || window.imagePreload != -2)
	{
		setTimeout("clearLoadingScreen()", 100);
	}
}

function getElementPosition(elemID)
{
	var offsetTrail = document.getElementById(elemID);
	var offsetLeft = 0;
	var offsetTop = 0;
	while (offsetTrail)
	{
		offsetLeft += offsetTrail.offsetLeft;
		offsetTop += offsetTrail.offsetTop;
		offsetTrail = offsetTrail.offsetParent;
	}
	if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != 'undefined')
	{
		offsetLeft += document.body.leftMargin;
		offsetTop += document.body.topMargin;
	}
	return { left: offsetLeft, top: offsetTop };
}

window.kaunter = 0;

var ile=0;

function checkStupidAdHeight()
{
  var rf = document.getElementById('reklamaFrame').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("checkStupidAdHeight()", 1000);
  } else {
  
  
    //document.getElementById('reklama').style.display = 'block';
    //document.getElementById('reklama').innerHTML = xxx.substring(pos+9,xxx.length);
    

    // usuniecie starej reklamy
    if ( document.getElementById('reklama').hasChildNodes() ){
      while ( document.getElementById('reklama').childNodes.length >= 1 ) {
        document.getElementById('reklama').removeChild( document.getElementById('reklama').firstChild );       
      } 
    }
    
    // przekopiowanie nowej reklamy  
    for (i=0 ; i<childs.length ; i++) {
      document.getElementById('reklama').appendChild(childs[i]);    
    }


    setTimeout("reallyCheckStupidAdHeight()", 100);
  } 
   

}

function reallyCheckStupidAdHeight()
{

  var hgt = document.getElementById('reklama').clientHeight;  
  if (hgt == undefined || hgt == 0)
  {
    setTimeout("reallyCheckStupidAdHeight()", 100);
  }
  else
  {
    putMain('wyniki', 170, hgt + 200);
	putMain('podstrona', 170, hgt + 200);
	putMain('slowniki', 0, hgt + 200);
  }

}

window.finishedLoading = false;

function whenFinishedLoad()
{
	if (window.finishedLoading == true) loadSpecificWord(window.wtl, true);
	else setTimeout("whenFinishedLoad();", 200);
}

function playWord(word)
{
	try
	{
		document.getElementById('mp3player').playSound('playWord.php?word=' + word);
	}
	catch (e)
	{
		document.getElementById('mp3player').CallFunction("<invoke name='playSound'><arguments><string>" + word + "</string></arguments></invoke>");
	}
}


// put element absolute
function putAbs(target, offsetX, offsetY)
{
  var tLayer = document.getElementById(target);
  if (tLayer == null)
  {
    alert("Bad name:" + target);
  }
  tLayer.style.top = offsetY + "px";
  tLayer.style.left = offsetX + "px";
  tLayer.style.position = "absolute";
}

// put element relative to
function putERT(source, target, offsetX, offsetY)
{
  var sLayer = document.getElementById(source);
  var tLayer = document.getElementById(target);
  if (sLayer == null || tLayer == null)
  {
    alert("Bad names:" + source + ", " + target);
  }
  tLayer.style.top = offsetY + "px";
  tLayer.style.left = offsetX + "px";
  tLayer.style.position = "absolute";
  if (source == "main" && !window.finishedLoading) tLayer.style.display = "none";
}

function putMain(target, offsetX, offsetY)
{
  putERT('main', target, offsetX, offsetY); 
}

// insert element at end of other
function putEOF(source, target)
{
  var sLayer = document.getElementById(source);
  var tLayer = document.getElementById(target);
  sLayer.appendChild(target);
}

function clearRadioImg(div)
{
  var dt = document.getElementById(div);
  dt.style.background = "";
}

// toggle radio button background
function toggleRadioImg(keyw, div, field, value)
{
  var dt = document.getElementById(div);
  for (area in window.radioButtonsClear[keyw])
  {
    eval(window.radioButtonsClear[keyw][area]);
  }
  dt.style.background = "url(img/highlight_symbol2.gif)";
  document.getElementById(field).value = value;
  var allB = document.getElementById('radio_wordform_clf_all');
  allB.style.background = "url(img/button_all.gif) top left no-repeat";
  window.allRadioBackground = "img/button_all.gif";
}

function setupAllRadioBg()
{
  setBg('radio_wordform_clf_all', window.allRadioBackground);
}

function toggleAllRadioImg()
{
  var dt = document.getElementById('radio_wordform_clf_all');
  for (area in window.radioButtonsClear['wordform_clf'])
  {
    eval(window.radioButtonsClear['wordform_clf'][area]);
  }
  dt.style.background = "url(img/button_all_on.gif) top left no-repeat";
  window.allRadioBackground = "img/button_all_on.gif";
  document.getElementById('clf').value = "";    
}

// create toggle'able radio button from image
function createRadioImg(form, div, image, input, value, enabled)
{
  var container = document.getElementById(div)
  var divId = "radio_" + form + "_" + input + "_" + value;
  var keyword = form + "_" + input;
  var prepStr = "<span class='radioButton' id='" + divId + "' " + 
    "onClick=\"toggleRadioImg('" + keyword + "', '" +
    divId + "', '" + input + "', '" + value + "');\">" +
    "<img class='radioImage' src='" + image + "' /></span>";
  container.innerHTML += prepStr;
  if (window.radioButtonsClear == undefined)
  {
    window.radioButtonsClear = [];
  }
  if (window.radioButtonsClear[keyword] == undefined)
  {
    window.radioButtonsClear[keyword] = [];
  }
  window.radioButtonsClear[keyword][value] = "clearRadioImg('" + divId + "');";
  if (enabled == 1)
  {
   toggleRadioImg(divId, input, value);
  }
}

function changeClassDef(cls, field, value)
{
  var ss = document.styleSheets[0];
  var rl = null;
  if (ss.rules != undefined) rl = ss.rules;
  else rl = ss.cssRules;
  var ssl = rl.length;
  for (i = 0; i < ssl; i++)
  {
    if (rl[i].selectorText == "." + cls)
	{
	  rl[i].style[field] = value;
	}
  }
}

function applyFontSettings()
{
  var nextSet = (window.currentSettings - (window.currentSettings % 2)) / 2;
  if (nextSet % 3 == 0)
  {
    changeClassDef("dictname", "fontSize", "18px");
	changeClassDef("dictsmallprint", "fontSize", "9px");
	changeClassDef("dictword", "fontSize", "14px");
	changeClassDef("dictdef", "fontSize", "12px");
  }
  else if (nextSet % 3 == 1)
  {
    changeClassDef("dictname", "fontSize", "16px");
	changeClassDef("dictsmallprint", "fontSize", "8px");
	changeClassDef("dictword", "fontSize", "12px");
	changeClassDef("dictdef", "fontSize", "11px");
  }
  else
  {
    changeClassDef("dictname", "fontSize", "20px");
	changeClassDef("dictsmallprint", "fontSize", "10px");
	changeClassDef("dictword", "fontSize", "16px");
	changeClassDef("dictdef", "fontSize", "14px");
  }

}

function changeSettings(mod)
{
  window.currentSettings += mod;
  applyFontSettings();
  makeSettingsBar();
  displayWord(window.wordsCache[window.displayed]);
}

function makeSettingsBar()
{
  var prepStr = "<span class='sb_wyniki'>Wyświetlanie: ";
  if (window.currentSettings % 2 == 0)
  {
    prepStr += "<img class='sb_wyniki_but' src='img/searchtoolbar_1column_selected.gif' /><a href='javascript:changeSettings(1)' onMouseOver=\"setSrc('sb_wyniki_img2', 'img/searchtoolbar_2columns_mouseover.gif');\" onMouseOut=\"setSrc('sb_wyniki_img2', 'img/searchtoolbar_2columns_mouseout.gif');\"><img id='sb_wyniki_img2' class='sb_wyniki_but' src='img/searchtoolbar_2columns_mouseout.gif' alt='2 kol.' border='0' /></a>";
  }
  else
  {
    prepStr += "<a href='javascript:changeSettings(-1)' onMouseOver=\"setSrc('sb_wyniki_img1', 'img/searchtoolbar_1column_mouseover.gif');\" onMouseOut=\"setSrc('sb_wyniki_img1', 'img/searchtoolbar_1column_mouseout.gif');\"><img id='sb_wyniki_img1' border='0' class='sb_wyniki_but' src='img/searchtoolbar_1column_mouseout.gif'></a><img class='sb_wyniki_but' src='img/searchtoolbar_2columns_selected.gif' alt='2 kol.' />";
  }
  prepStr += "</span><img class='sb_sep' src='img/searchtoolbar_spacer.gif' alt='|' /><span class='sb_rozmiar'>";
  var nextSet = (window.currentSettings - (window.currentSettings % 2)) / 2;
  if (nextSet % 3 == 0)
  {
    prepStr += "<span class='letter_button_small' id='lb_1' onMouseOver=\"setBg('lb_1', 'img/searchtoolbar_lettersize_selected_or_mouseouver.gif');\" onMouseOut=\"clearBg('lb_1');\" onClick=\"changeSettings(2);\"><div>A</div></span><span class='letter_button_mid' style='background: url(img/searchtoolbar_lettersize_selected_or_mouseouver.gif)' id='lb_2'><div>A</div></span><span class='letter_button_big' id='lb_3' onMouseOver=\"setBg('lb_3', 'img/searchtoolbar_lettersize_selected_or_mouseouver.gif');\" onMouseOut=\"clearBg('lb_3');\" onClick='changeSettings(4);'><div>A</div></span>";
  }
  else if (nextSet % 3 == 1)
  {
    prepStr += "<span class='letter_button_small' style='background: url(img/searchtoolbar_lettersize_selected_or_mouseouver.gif);' id='lb_1'><div>A</div></span><span class='letter_button_mid' id='lb_2' onMouseOver=\"setBg('lb_2', 'img/searchtoolbar_lettersize_selected_or_mouseouver.gif');\" onMouseOut=\"clearBg('lb_2');\" onClick=\"changeSettings(-2);\"><div>A</div></span><span class='letter_button_big' id='lb_3' onMouseOver=\"setBg('lb_3', 'img/searchtoolbar_lettersize_selected_or_mouseouver.gif');\" onMouseOut=\"clearBg('lb_3');\" onClick='changeSettings(2);'><div>A</div></span>";
  }
  else
  {
    prepStr += "<span class='letter_button_small' id='lb_1' onMouseOver=\"setBg('lb_1', 'img/searchtoolbar_lettersize_selected_or_mouseouver.gif');\" onMouseOut=\"clearBg('lb_1');\" onClick=\"changeSettings(-2);\"><div>A</div></span><span class='letter_button_mid' id='lb_2' onMouseOver=\"setBg('lb_2', 'img/searchtoolbar_lettersize_selected_or_mouseouver.gif');\" onMouseOut=\"clearBg('lb_2');\" onClick='changeSettings(-4);'><div>A</div></span><span class='letter_button_big' style='background: url(img/searchtoolbar_lettersize_selected_or_mouseouver.gif);' id='lb_3'><div>A</div></span>";
  }
  nextSet = (nextSet - (nextSet % 3)) / 3;
  prepStr += "</span><img class='sb_sep' src='img/searchtoolbar_spacer.gif' alt='|' /><span class='sb_zasieg'>";
  if (nextSet % 3 == 0)
  {
    prepStr += "<span class='range_narrow' onMouseOver=\"setSrc('rb_1', 'img/searchtoolbar_searchwidth_narrow_on_or_selected.gif');\" onMouseOut=\"setSrc('rb_1', 'img/searchtoolbar_searchwidth_narrow_off.gif');\" onClick=\"changeSettings(6);\"><img id='rb_1' alt='[waski]' src='img/searchtoolbar_searchwidth_narrow_off.gif' /></span>";
	prepStr += "<span class='range_mid'><img alt='[sredni]' src='img/searchtoolbar_searchwidth_normal_on_or_selected.gif' /></span>";
	prepStr += "<span class='range_wide' onMouseOver=\"setSrc('rb_3', 'img/searchtoolbar_searchwidth_wide_on_or_selected.gif');\" onMouseOut=\"setSrc('rb_3', 'img/searchtoolbar_searchwidth_wide_off.gif');\" onClick=\"changeSettings(12);\"><img id='rb_3' alt='[szeroki]' src='img/searchtoolbar_searchwidth_wide_off.gif' /></span>";
  }
  else if (nextSet % 3 == 1)
  {
    prepStr += "<span class='range_narrow'><img id='rb_1' alt='[waski]' src='img/searchtoolbar_searchwidth_narrow_on_or_selected.gif' /></span>";
	prepStr += "<span class='range_mid' onMouseOver=\"setSrc('rb_2', 'img/searchtoolbar_searchwidth_normal_on_or_selected.gif');\" onMouseOut=\"setSrc('rb_2', 'img/searchtoolbar_searchwidth_normal_off.gif');\" onClick=\"changeSettings(-6);\"><img alt='[sredni]' src='img/searchtoolbar_searchwidth_normal_off.gif' id='rb_2' /></span>";
	prepStr += "<span class='range_wide' onMouseOver=\"setSrc('rb_3', 'img/searchtoolbar_searchwidth_wide_on_or_selected.gif');\" onMouseOut=\"setSrc('rb_3', 'img/searchtoolbar_searchwidth_wide_off.gif');\" onClick=\"changeSettings(6);\"><img id='rb_3' alt='[szeroki]' src='img/searchtoolbar_searchwidth_wide_off.gif' /></span>";
  }
  else
  {
    prepStr += "<span class='range_narrow' onMouseOver=\"setSrc('rb_1', 'img/searchtoolbar_searchwidth_narrow_on_or_selected.gif');\" onMouseOut=\"setSrc('rb_1', 'img/searchtoolbar_searchwidth_narrow_off.gif');\" onClick=\"changeSettings(-6);\"><img id='rb_1' alt='[waski]' src='img/searchtoolbar_searchwidth_narrow_off.gif' /></span>";
 	prepStr += "<span class='range_mid' onMouseOver=\"setSrc('rb_2', 'img/searchtoolbar_searchwidth_normal_on_or_selected.gif');\" onMouseOut=\"setSrc('rb_2', 'img/searchtoolbar_searchwidth_normal_off.gif');\" onClick=\"changeSettings(-12);\"><img alt='[sredni]' src='img/searchtoolbar_searchwidth_normal_off.gif' id='rb_2' /></span>";
	prepStr += "<span class='range_wide'><img id='rb_3' alt='[szeroki]' src='img/searchtoolbar_searchwidth_wide_on_or_selected.gif' /></span>";
  }


  prepStr += "</span>";

	prepStr += "<div style='width: 245px;height:36px;float:right;padding-top:0px;margin-top:0px;'><iframe scrolling='no' frameborder='0' marginwidth='0' marginheight='0' src='http://www2.ling.pl/cpc03_2010.html' allowtransparency='true' style='border: none; margin:0px; width: 240px; height: 34px;'></iframe></div>";

  document.getElementById('setbar').innerHTML = prepStr;
  document.getElementById('main').style.display = "block";
  document.getElementById('searchBox').style.display = "block";
  document.getElementById('wordbox').focus();
}

// create 'all languages' radio button
function createAllRadioImg()
{ 
  var container = document.getElementById('wybierzJezykBut');
  var prepStr = "<span class='racont'><span class='radioAllButton' id='radio_wordform_clf_all' " +
    "onClick=\"toggleAllRadioImg();\" " + 
    "onMouseDown=\"setBg('radio_wordform_clf_all', 'img/button_all_click.gif');\" " +
    "onMouseUp=\"setupAllRadioBg();\">all</span></span>";
  window.allRadioBackground = "img/button_all_on.gif";
  container.innerHTML += prepStr;  
}

function createRIW(img, val, en)
{
  createRadioImg("wordform", "wybierzJezykBut", img, "clf", val, en) 
}

function appendToForm(input, text)
{
    document.getElementById(input).value = 
      document.getElementById(input).value + text;
}


function createLetterButton(div, input, letter, classname)
{
  var container = document.getElementById(div);
  var divId = "letter_" + letter;
  var prepStr = "<span class='" + classname + "' id='" + divId + "' " +
    "onMouseOver=\"setBg('" + divId + "', 'img/highlight_symbol.gif');\" " +
    "onMouseOut=\"clearBg('" + divId +"');\" " +
    "onClick=\"appendToForm('" + input + "', '" + letter + "');\"><div>" +
    letter + "</div></span>";
  container.innerHTML += prepStr;
}

function langStr(lang)
{
  if (lang == "") return "";
  var ld = parseInt(lang);
  return "<img style='margin-right: 5px' border='0' src='" + window.dictAssign[ld] + "' />";
}

function makeActiveWordButton(word, lang)
{
  var prepStr = "<span class='activeWord'><table cellpadding='0' cellspacing='0'><tr height='28'><td><img class='border' alt='[' src='img/searchresults_current_tab_left.gif' /></td><td class='aw_middle'><span class='activeWordInside'>" + word + "</span> <span class='activeWordClose' onClick=\"javascript:closeWord('" + word + "', '" + lang + "');\">" + langStr(lang) + "<img border='0' src='img/searchresults_closetab.gif' alt='[X]' /></span></td><td><img class='border' alt=']' src='img/searchresults_current_tab_right.gif' /></td></tr></table></span>";
  return prepStr;
}

function makePassiveWordButton(word, lang)
{
  var prepStr = "<span class='passiveWord'><table cellpadding='0' cellspacing='0'><tr height='23'><td><img class='border' alt='[' src='img/searchresults_tab_left.gif' /></td><td class='pw_middle'><span class='passiveWordInside' onClick=\"displayWordLang('" + word + "', '" + lang + "');\">" + word + "</span> <span class='passiveWordClose' onClick=\"javascript:closeWord('" + word + "', '" + lang + "');\">" + langStr(lang) + "<img border='0' src='img/searchresults_closetab.gif' alt='[X]' /></span></td><td><img class='border' alt=']' src='img/searchresults_tab_right.gif' /></td></tr><tr height='1'><td colspan='3' height='1' class='pw_bot'></td></tr></table></span>";
  return prepStr;
}

function createLBW(letter)
{
  createLetterButton("literki", "wordbox", letter, "letterButton");
}

function createLBWN(letter)
{
  createLetterButton("literki", "wordbox", letter, "letterButtonNarrow");
}


// only works right now for objects that contain only divs
function getHalfDivide(container)
{
  var clds = document.getElementById(container).childNodes;
  var totHeight = 0;
  for (i = 0; i < clds.length; i++)
  {
    totHeight += clds[i].clientHeight;
  }
  var cnt = 0;
  var addedHeight = 0;
  while (addedHeight < totHeight / 2)
  {
    addedHeight += clds[cnt].clientHeight;
    cnt++;
  }
  return cnt;
}

function moveElements(srcDiv, tgtDiv, num)
{
  var src = document.getElementById(srcDiv);
  var tgt = document.getElementById(tgtDiv);
  for (i = 0; i < num; i++)
  {
    var movNode = src.removeChild(src.childNodes[0]);
    tgt.appendChild(movNode);
  }
}

function displayTwoColumns()
{
  var num = getHalfDivide('tresc');
  var tot = document.getElementById('tresc').childNodes.length;
  moveElements('tresc', 'tresc_kol1', num);
  moveElements('tresc', 'tresc_kol2', tot - num);
  document.getElementById('tresc').innerHTML = "";
  document.getElementById('tresc').style.display = "none";
  document.getElementById('tresc_kol1').style.display = "block";
  document.getElementById('tresc_kol2').style.display = "block";
}

function displayOneColumn()
{
  var col1 = document.getElementById('tresc_kol1');
  var col2 = document.getElementById('tresc_kol2');
  col1.innerHTML = "";
  col2.innerHTML = "";
  col1.style.display = "none";
  col2.style.display = "none";
  document.getElementById('tresc').style.display = "block";
}

function showCyr()
{
  document.getElementById('cyrylicaShow').style.display = "block";
  document.getElementById('cyrylica').style.display = "none";
  document.getElementById('cyrylicaShow').style.zIndex = 100000;
}

function hideCyr()
{
  document.getElementById('cyrylicaShow').style.display = "none";
  document.getElementById('cyrylica').style.display = "block";
}

function setBg(div, img)
{
  var tgt = document.getElementById(div);
  tgt.style.backgroundImage = "url(" + img + ")";
}

function clearBg(div)
{
  var tgt = document.getElementById(div);
  tgt.style.background = "";
}

function cleanDivs(tgt)
{
  var clds = tgt.childNodes;
  for (i = 0; i < clds.length; i++)
  {
    while (clds[i] != undefined && clds[i].clientHeight == undefined)
	{
	  tgt.removeChild(clds[i]);
	}
	if (document.classes) // IE Only 
	{
		clds[i].style.height = "1px";
	}
  }
}

function makeIVO(tgt)
{
  var wrds = tgt.getElementsByTagName("div");
  for (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 || cl != "dictword") continue;
	var foo = wrds[i].getElementsByTagName("span");
    if (foo == null || foo.length < 1) continue;
	var boo = foo[0];
    var bcl = boo.getAttribute("class");
	if (bcl == null && boo.attributes != null && boo.attributes['class'] != null) bcl = boo.attributes['class'].nodeValue;
	if (bcl == null || bcl != "mw") continue;
	var word = wrds[i].childNodes[0].nodeValue;
	if (word == null) continue;
	var link = document.createElement("a");
	var img = document.createElement("img");
	img.src = "img/speaker_icon.gif";
	img.style.border = "0";
	link.href = "javascript:playWord('" + encodeURIComponent(word) + "')";
	link.appendChild(img);
	boo.appendChild(link);
  }
}

function applySettings(reload, ind)
{
  if (window.currentSettings % 2 == 1) displayTwoColumns();
  if (reload == true) loadSpecificWord(window.wordsCache[ind], true, window.langsCache[ind]);
}

function loadFile(file, callback)
{
  if (window.XMLHttpRequest) 
  { // Mozilla, Safari, Opera ...
    http_request = new XMLHttpRequest();
  } 
  else if (window.ActiveXObject) 
  { // IE
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
  }
  http_request.onreadystatechange = function() {
    if (http_request.readyState == 4 && http_request.status == 200)
    {
	  callback(http_request.responseText);
	}
  }
  http_request.open('GET', file, true);
  http_request.send(null);
}

function loadFileXML(file, callback)
{
  if (window.XMLHttpRequest) 
  { // Mozilla, Safari, Opera ...
    http_request = new XMLHttpRequest();
  } 
  else if (window.ActiveXObject) 
  { // IE
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
  }
  http_request.onreadystatechange = function() {
    if (http_request.readyState == 4 && http_request.status == 200)
    {
	  callback(http_request.responseXML);
	}
  }
  http_request.open('GET', file, true);
  http_request.send(null);
}


function registerLoad(word)
{
  if (window.XMLHttpRequest) 
  { // Mozilla, Safari, Opera ...
    http_request = new XMLHttpRequest();
  } 
  else if (window.ActiveXObject) 
  { // IE
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
  }
  http_request.open('GET', 'regUsage.php?word=' + encodeURIComponent(word), true);
  http_request.send(null);
}

function enterSamples(xml)
{
  var foo = xml.getElementsByTagName('sample');
  var prepStr = "";
  if (foo.length == 0) prepStr += "Brak przykładów."
  else
  {
	for (i = 0; i < foo.length; i++)
	{
	  var tit = foo[i].getElementsByTagName('title')[0].childNodes[0].nodeValue;
	  var sen = foo[i].getElementsByTagName('sentence')[0].childNodes[0].nodeValue;
	  prepStr += "<div class='sample'><div class='sampleSentence'>" + sen + "</div><div class='sampleTitle'>" + tit + "</div></div>";
	}
  }
  document.getElementById('samplecontent').innerHTML = prepStr;
}

function loadSample(word)
{
  loadFileXML("getSamples.php?word=" + encodeURIComponent(word), enterSamples);
}

function getText(req, ind, url)
{
  if (req.readyState == 4 && req.status == 200)
  {
    if (document.getElementById('clf').value == '' || 
		document.getElementById('clf').value == '1')
	{
		if (req.responseText.charAt(5) == '1')
			window.definitionCache[ind] = "<div id='dictsample'><div class='dictname'><a href=\"javascript:loadSample('" + window.wordsCache[ind] + "');\" class='dictname'>Przykłady użycia słowa '" + window.wordsCache[ind] + "'</a></div><div class='dictdef' id='samplecontent'></div></div>\n";
		else window.definitionCache[ind] = "";
	}
	else window.definitionCache[ind] = "";
    window.definitionCache[ind] += req.responseText;
	window.loaded[ind] = true;
	if (ind == window.displayed) 
	{
	  var tgt = document.getElementById('tresc');
	  displayWord(window.wordsCache[ind]);
	}
	registerLoad(window.wordsCache[ind]);
  }
}

function loadDef(ind, url, uid)
{
  if (window.XMLHttpRequest) 
  { // Mozilla, Safari, Opera ...
    http_request = new XMLHttpRequest();
  } 
  else if (window.ActiveXObject) 
  { // IE
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
  }
  http_request.onreadystatechange = function() {
    if (window.cancelled.length < uid || window.cancelled[uid] != 1)
	{
     getText(http_request, ind, url);
	}
  }
  http_request.open('GET', url, true);
  http_request.send(null);
}

function findWordIndex(word, lang)
{
  var words = window.wordsCache;
  var langs = window.langsCache;
  for (i = 0; i < words.length; i++)
  {
    if (words[i] == word && langs[i] == lang) return i;
  }
  return -1;
}

function displayWord(word)
{
  var lang = document.getElementById('clf').value;
  displayWordLang(word, lang);
}

function displayWordLang(word, lang)
{
  var words = window.wordsCache;
  var langs = window.langsCache;
  var defs = window.definitionCache;
  var ind = findWordIndex(word, lang);
  var container = document.getElementById('wordBar');
  var textContainer = document.getElementById('tresc');
  if (ind == -1 || ind >= words.length) ind = 0;
  var prepStr = "";
  var hashStr = "words?";
  for (i = 0; i < words.length; i++)
  {
  	if (words.length - i > 7) continue;
    if (words[i] == undefined)
	{
	  words.length = 0;
      showDictionariesBoard();
	}
    if (ind == i) 
	{
		prepStr += makeActiveWordButton(words[i], langs[i]);
		if (i > 0) hashStr += "&";
		hashStr += "act[" + i + "]=1&word[" + i + "]=" + encodeURIComponent(words[i]) + "&lang[" + i + "]=" + langs[i];
	}
	else
	{
		prepStr += makePassiveWordButton(words[i], langs[i]);
		hashStr += "act[" + i + "]=0&word[" + i + "]=" + encodeURIComponent(words[i]) + "&lang[" + i + "]=" + langs[i];
	}
  }
  container.innerHTML = prepStr;
  location.hash = hashStr;
  displayOneColumn();
  textContainer.innerHTML = defs[ind];
  cleanDivs(textContainer);
  makeIVO(textContainer);
  window.displayed = ind;
  if (window.dictShown) showResultsBoard();
  if (window.loaded[ind]) 
  {
    if (window.savedSettings[ind] == -1)
	{
	  window.savedSettings[ind] = window.currentSettings;
	  applySettings(false, ind);
	}
	else
	{
	  var oldSet = window.savedSettings[ind];
	  oldSet = (oldSet - (oldSet % 2)) / 2;
	  oldSet = (oldSet - (oldSet % 3)) / 3;
	  var newSet = window.currentSettings;
	  newSet = (newSet - (newSet % 2)) / 2;
	  newSet = (newSet - (newSet % 3)) / 3;
	  window.savedSettings[ind] = window.currentSettings;
	  if (oldSet == newSet) applySettings(false, ind);
	  else applySettings(true, ind);
	}
  }
}

function showResultsBoard()
{
  window.dictShown = false;
  document.getElementById('podstrona').style.display = "none";
  document.getElementById('wyniki').style.display = "block";
  document.getElementById('slowniki').style.display = "none";
}

function showDictionariesBoard()
{
  window.dictShown = true;
  document.getElementById('podstrona').style.display = "none";
  document.getElementById('wyniki').style.display = "none";
  document.getElementById('slowniki').style.display = "block";
}



function closeWord(word, lang)
{
  var defs = window.definitionCache;
  var words = window.wordsCache;
  var ids = window.idCache;
  var langs = window.langsCache;
  var ind = findWordIndex(word, lang);
  var curWord = words[window.displayed];
  if (ind == -1) return;
  var uid = ids[ind];
  if (ind >= defs.length) return;
  for (i = ind; i < defs.length; i++)
  {
    defs[i] = defs[i+1];
    words[i] = words[i+1];
	ids[i] = ids[i+1];
	langs[i] = langs[i+1];
  }
  defs.length = defs.length - 1;
  words.length = words.length - 1;
  ids.length = ids.length - 1;
  langs.length = langs.length - 1;
  window.cancelled[uid] = 1;
  if (words.length < 1)
  {
    words.length = 0;
    showDictionariesBoard();
  }
  else
  {
    if (ind == window.displayed) displayWord(words[(words.length - 1)]);
	else displayWord(curWord);
  }
}

function loadWord()
{
  /*
   if (document.getElementById('nwwc').checked = true)
   {
     var fm = document.createElement('form');
	 fm.method = "POST";
	 fm.action = "indexalt.php?word=" + encodeURIComponent(document.getElementById('wordbox').value);
	 fm.target = "_blank";
	 document.body.appendChild(fm);
	 fm.submit();
	 return;
  }
  */
  if (window.finishedLoading == false)
  {
  	setTimeout("loadWord();", 500);
	return;
  }
  
  
  var word = document.getElementById('wordbox').value;
  loadSpecificWord(word, false);
  handleDaAdz();
  if (pageTracker != undefined) 
  {
  	pageTracker._trackPageview("/" + word);
	gemius_hit('zZbq_KNcG0FqexICdvlW1bbv7MpYut.2DXq.pBdzRtr.N7');
  }
}

function getLevelFromSettings()
{
  var set = window.currentSettings;
  set = (set - (set % 2)) / 2;
  set = (set - (set % 3)) / 3;
  set = set % 3;
  if (set == 0) return 0;
  else if (set == 1) return 2;
  else return 1;
}

function loadSpecificWord(word, force)
{
  var lang = document.getElementById('clf').value;
  loadSpecificWordLang(word, force, lang);
}

function loadSpecificWordLang(word, force, lang)
{
  var ii = findWordIndex(word, lang);
  if (ii != -1 && force == false)
  {
	  displayWord(word);
	  return;
  }
  var prepStr = "lingfeed-ps.php?word=" + encodeURIComponent(word);
  prepStr += "&ajax=1&sType=" + getLevelFromSettings();
  if (lang != "")
  {
    prepStr += "&chooseLang=" + encodeURIComponent(lang);
  }
  var loading = "<span class='loading'>Ładowanie wyników, proszę czekać...</span>";
  var ind = window.wordsCache.length;
  if (ii != -1 && force == true) ind = ii;
  window.wordsCache[ind] = word;
  window.loaded[ind] = false;
  window.definitionCache[ind] = loading;
  window.idCache[ind] = window.loadId;
  window.loadId = window.loadId + 1;
  window.savedSettings[ind] = -1;
  window.langsCache[ind] = lang;
  displayWord(word);
  loadDef(ind, prepStr);
}

function convertCyrTable()
{
  var tb = document.getElementById('cyrTable');
  var foo = tb.getElementsByTagName('td');
  for (i = 0; i < foo.length; i++)
  {
    var el = foo[i];
	var id = el.getAttribute('id');
	if (id != null) continue;
	el.style.cursor = "pointer";
	el.onmouseover = function() { 
		this.style.background = 'url(img/cyrylica_highlight.gif)';
	};
	el.onmouseout = function() {
		this.style.background = '';
	};
	el.onclick = function() { 
		appendToForm('wordbox', this.childNodes[0].nodeValue);
	};
  }
}

window.rpwAligns = [];

function alreadyPlacedRPW(hrnd, rnd, ww, wh)
{
  for (var i = 0; i < window.rpwAligns.length; i++)
  {
    var el = window.rpwAligns[i];
	// lewy gorny rog
	if (el.x1 <= rnd && el.x2 >= rnd && el.y1 <= hrnd && el.y2 >= hrnd)
      return true;
	// prawy gorny rog
	if (el.x1 <= (rnd + ww) && el.x2 >= (rnd + ww) && el.y1 <= hrnd && el.y2 >= hrnd)
	  return true;
	// lewy dolny rog
	if (el.x1 <= rnd && el.x2 >= rnd && el.y1 <= (hrnd + wh) && el.y2 >= (hrnd + wh))
	  return true;
	// prawy dolny rog
	if (el.x1 <= (rnd + ww) && el.x2 >= (rnd + ww) && el.y1 <= (hrnd + wh) && el.y2 >= (hrnd + wh)) 
	  return true;
	// lewa krawedz
	if (el.x1 <= rnd && el.x2 >= rnd && el.y1 >= hrnd && el.y2 <= (hrnd + wh))
      return true;
	// prawa krawedz
	if (el.x1 <= (rnd + ww) && el.x2 >= (rnd + ww) && el.y1 >= hrnd && el.y2 <= (hrnd + wh))
	  return true;
	// gorna krawedz
	if (el.x1 >= rnd && el.x2 <= (rnd + ww) && el.y1 <= hrnd && el.y2 >= hrnd)
	  return true;
	// dolna krawedz
	if (el.x1 >= rnd && el.x2 <= (rnd + ww) && el.y1 <= (hrnd + wh) && el.y2 >= (hrnd + wh)) 
	  return true;
	// w srodku
	if (el.x1 >= rnd && el.x2 <= (rnd + ww) && el.y1 >= hrnd && el.y2 <= (hrnd + wh))
	  return true;
  }
  return false;
}

function randomPutWord(word, box, mw, mh)
{
	var div = document.getElementById(box);
	var wbox = document.createElement('div');
	wbox.innerHTML = "<a class='rndlink' href='def_" + encodeURIComponent(word) + "'>" + word + "</a>";
	wbox.style.position = "absolute";
	wbox.style.display = "block";
	wbox.style.fontFamily = "Verdana";
	var size = 10 + (Math.floor(Math.random() * 12));
	wbox.style.fontSize = size + "px";
	div.appendChild(wbox);
	var ww = word.length * (size - 2);
	var wh = Math.floor(size * 1.5);
	while (ww > ((mw * 3) / 4))
	{
		size--;
		ww = word.length * (size - 2);
		wh = Math.floor(size * 1.5);
		wbox.style.fontSize = size + "px";
	}
	var start = mw - ww;
	var rnd = Math.floor(Math.random() * start);
	var hstart = mh - wh;
	var hrnd = Math.floor(Math.random() * hstart);
	wbox.style.top = hrnd;
	wbox.style.left = rnd;
	if (alreadyPlacedRPW(hrnd, rnd, ww, wh))
	{
	  div.removeChild(wbox);
	  randomPutWord(word, box, mw, mh);
	}
	else
	{
	  var foo = new Object();
	  foo.x1 = rnd;
	  foo.x2 = rnd + ww;
	  foo.y1 = hrnd;
	  foo.y2 = hrnd + wh;
//	  alert (foo.x1 + ", " + foo.x2 + ", " + foo.y1 + ", " + foo.y2);
	  rpwAligns.push(foo);
	}
}

function rpw(word)
{
  randomPutWord(word, 'czywieszze', 750, 160);
}

function putRandomWords()
{
  var dr = document.getElementById('czywieszze');
  var foo = new Array();
  for (var i = 0; i < dr.childNodes.length; i++)
  {
    var cn = dr.childNodes[i];
	if (cn.childNodes != null && cn.childNodes[0] != null)
	{
	  var wn = cn.childNodes[0];
	  if (wn.childNodes != null)
	  {
	    var tmp = wn.childNodes[0].nodeValue;
		foo.push(tmp);
	  }
	}
  }
  dr.innerHTML = "";
  for (var i = 0; i < foo.length; i++)
  {
    rpw(foo[i]);
  }
}

function loadSub(file)
{
  var fn = function(cont) {
    document.getElementById('podstrona').innerHTML = cont;
    document.getElementById('podstrona').style.display = "block";
    document.getElementById('wyniki').style.display = "none";
	document.getElementById('slowniki').style.display = "none";
	window.dictShown = true;
  }
  loadFile(file, fn);
  if (pageTracker != "undefined") pageTracker._trackPageview("/" + file);
  location.hash = "file?name=" + encodeURIComponent(file);
}

function loadSubFun(file, fun)
{
  var fn = function(cont) {
    document.getElementById('podstrona').innerHTML = cont;
    document.getElementById('podstrona').style.display = "block";
    document.getElementById('wyniki').style.display = "none";
	document.getElementById('slowniki').style.display = "none";
	window.dictShown = true;
	fun();
  }
  loadFile(file, fn);
  if (pageTracker != "undefined") pageTracker._trackPageview("/" + file);
  location.hash = "file?name=" + encodeURIComponent(file);
}

function showBlogComments(num)
{
  var fn = function(cont) {
	document.getElementById('bt_comments_' + num).innerHTML = cont;
  }
  loadFile('blog.php?action=comments&num=' + num, fn);
}

function checkPrefLang()
{
  var defLang = readCookie('defLang');
  for (var i = 0; i < 7; i++)
  {
    document.getElementById('prefer_lang_' + i).checked = false;
  }
  if (defLang == null) document.getElementById('prefer_lang_0').checked = true;
  else document.getElementById('prefer_lang_' + defLang).checked = true;
}

function checkPrefRange()
{
  var defRange = readCookie('defRange');
  for (var i = 0; i < 3; i++)
  {
    document.getElementById('prefer_range_' + i).checked = false;
  }
  if (defRange == null) document.getElementById('prefer_range_0').checked = true;
  else document.getElementById('prefer_range_' + defRange).checked = true;
}

function checkFontRange()
{
  var defFont = readCookie('defFont');
  for (var i = 0; i < 3; i++)
  {
    document.getElementById('prefer_font_' + i).checked = false;
  }
  if (defFont == null) document.getElementById('prefer_font_0').checked = true;
  else document.getElementById('prefer_font_' + defFont).checked = true;
}

function checkColsRange()
{
  var defCols = readCookie('defCols');
  for (var i = 0; i < 2; i++)
  {
    document.getElementById('prefer_cols_' + i).checked = false;
  }
  if (defCols == null) document.getElementById('prefer_cols_0').checked = true;
  else document.getElementById('prefer_cols_' + defCols).checked = true;
}


function setupPrefData()
{
  checkPrefLang();
  checkPrefRange();
  checkFontRange();
  checkColsRange();
}

function submitDaForm(e)
{
  var cc;
  if (e && e.which) cc = e.which;
  else cc = event.keyCode;
  if (cc == 13) loadWord();
}

window.reindexDone = false;

function reIndex()
{
	if (window.reindexDone) return;
	zi = 2000;
	cn = document.getElementsByTagName('div');
	for (n=0;n<cn.length;n++)
	{
		cn[n].style.zIndex=zi--;
	}
	window.reindexDone = true;	
}














