
var bendingIdOpen = "";

dictionaries = new Object();
dictionaries.dropDown = new Object();

dictionaries.logon = function() {

  if (document.getElementById('dictionary_username').value == '' || document.getElementById('dictionary_username').value == 'Skriva brúkaranavn títt her') {
    alert('Vinarliga skriva brúkaranavn títt');
    document.getElementById('dictionary_username').focus();
  } else if (document.getElementById('dictionary_password').value == '' || document.getElementById('dictionary_password').value == 'Skriva loyniorð títt her') {
    alert('Vinarliga skriva loyniorð títt');
    document.getElementById('dictionary_password').focus();
  } else {
    document.getElementById('bookBanner').style.visibility='hidden';
  }

}

dictionaries.checkUserCount = function() {

  xmlHttp_dictionaryCheck = ajaxObj();

  xmlHttp_dictionaryCheck.onreadystatechange=function() {
    if(xmlHttp_dictionaryCheck.readyState==4 && xmlHttp_dictionaryCheck.status==200) {
      if (xmlHttp_dictionaryCheck.responseText == "available") {
        setTimeout("dictionaries.checkUserCount()",1000);
      } else {
        setTimeout("dictionaries.checkUserCount()",1000);
      }
    }
  }

  xmlHttp_dictionaryCheck.open("GET",lnk+"modules/post/dictionary.checkUserCount.php",true);
  xmlHttp_dictionaryCheck.send(null);

}

dictionaries.backgroundFades = new Array;
dictionaries.backgroundFades[10] = '#fafafa';
dictionaries.backgroundFades[9] = '#fafafa';
dictionaries.backgroundFades[8] = '#fbfbfb';
dictionaries.backgroundFades[7] = '#fbfbfb';
dictionaries.backgroundFades[6] = '#fcfcfc';
dictionaries.backgroundFades[5] = '#fafafa';
dictionaries.backgroundFades[4] = '#fefefe';
dictionaries.backgroundFades[3] = '#fefefe';
dictionaries.backgroundFades[2] = '#fefefe';
dictionaries.backgroundFades[1] = '#fefefe';
dictionaries.backgroundFades[0] = '#fefefe';


dictionaries.fields = new Object();

dictionaries.isPressed = false;

dictionaries.fields.keypress = function(f,e) {

  if (e.which) { ekc = e.which; }
  else if (e.keyCode) { ekc = e.keyCode; }

  if (ekc == 40) { 
    if (document.getElementById('dictionarySearchFieldList').style.visibility == 'visible') { 
      dictionaries.dropDown.moveDown(); 
    } 
  } else if (ekc == 38) { 
    if (document.getElementById('dictionarySearchFieldList').style.visibility == 'visible') { 
      dictionaries.dropDown.moveUp();
    }
  } else if (ekc == 13) { 
    dictionaries.isPressed = true;
    if (f.value!='' && document.getElementById('dictionarySearchFieldList').style.visibility == 'visible' && dictionaries.dropDown.lastPos != 0) {
      dictionaries.search(document.getElementById('dictionarySearchFieldItem_'+dictionaries.dropDown.lastPos).innerHTML); 
      dictionaries.dropDown.lastUsedSearchWord = document.getElementById('dictionarySearchFieldItem_'+dictionaries.dropDown.lastPos).innerHTML; 
      document.getElementById('dictionarySearchFieldList').style.visibility = 'hidden'; 
      document.getElementById('searchWord').value=document.getElementById('dictionarySearchFieldItem_'+dictionaries.dropDown.lastPos).innerHTML; 
      document.getElementById('searchWord').focus();
      if (document.getElementById('divSearchBoxSearchedLeft')) { 
        document.getElementById('divSearchBoxSearchedLeft').innerHTML = ((parseInt(document.getElementById('divSearchBoxSearchedLeft').innerHTML)-1) <= 0 ? 0 : (parseInt(document.getElementById('divSearchBoxSearchedLeft').innerHTML)-1));
      }
      dictionaries.isPressed = false;
      return false;
    } else if (f.value!='' && f.value!='Skriva orð') { 
      if (document.getElementById('divSearchBoxSearchedLeft')) { 
        document.getElementById('divSearchBoxSearchedLeft').innerHTML = ((parseInt(document.getElementById('divSearchBoxSearchedLeft').innerHTML)-1) <= 0 ? 0 : (parseInt(document.getElementById('divSearchBoxSearchedLeft').innerHTML)-1));
      }
      document.getElementById('dictionarySearchFieldList').style.visibility = 'hidden';
      dictionaries.search(f.value);
      return false;
    } else {
      alert('Vinaliga skriva eitt leitiorð'); 
      document.getElementById('searchWord').focus();
      return false;
    }
  } else {
    dictionaries.dropDown.show(); 
  }

}


dictionaries.showOptions = function() {

  if (document.getElementById('dictionary_options').style.visibility == 'visible') {

    i = 100;
    setTimeout("dictionaries.fade('"+i+"');",10);

    document.getElementById('showoptionsmenuitemImage').src=lnk+'/images/content/leitimoguleikar_pluss_hover.png';

    document.getElementById('showoptionsmenuitemLink1').title='Fleiri møguleikar';

  } else {

    document.getElementById('dictionary_options').style.opacity='(0)';
    document.getElementById('dictionary_options').style.filter='alpha(opacity=0)';
    document.getElementById('dictionary_options').style.visibility='visible';
    document.getElementById('dictionary_options').style.position='';

    document.getElementById('showoptionsimg').style.visibility='visible';

    i = 0;
    setTimeout("dictionaries.unfade('"+i+"');",10);

    document.getElementById('showoptionsmenu').style.backgroundColor='#fafafa';

    document.getElementById('showoptionsmenu').style.borderTop='1px solid #eeeeee';
    document.getElementById('showoptionsmenu').style.borderLeft='1px solid #eeeeee';
    document.getElementById('showoptionsmenu').style.borderRight='1px solid #eeeeee';

    document.getElementById('showoptionsmenu').style.paddingTop='5px';
    document.getElementById('showoptionsmenu').style.paddingLeft='0px';
    document.getElementById('showoptionsmenu').style.paddingRight='0px';

    document.getElementById('showoptionsmenuitemImage').src=lnk+'/images/content/leitimoguleikar_minus_hover.png';

    document.getElementById('showoptionsmenuitemLink1').title='Færri møguleikar';

  }

}

dictionaries.unfade = function(i) {

  document.getElementById('showoptionsmenu').style.backgroundColor=dictionaries.backgroundFades[i/10];
  document.getElementById('showoptionsimg').style.backgroundColor=dictionaries.backgroundFades[i/10];
  document.getElementById('showoptionsimg').style.visibility='visible';

  document.getElementById('dictionary_options').style.height = (i*1.2)+'px';

  document.getElementById('dictionary_options').style.opacity=(i/100);
  document.getElementById('dictionary_options').style.filter='alpha(opacity='+i+')';
  document.getElementById('dictionary_options').style.khtmlOpacity=(i/100);
  document.getElementById('dictionary_options').style.MozOpacity=(i/100);

  if (i < 100) {
    i = (parseInt(i)+10);
    setTimeout("dictionaries.unfade('"+i+"');",5);
  } else {
    document.getElementById('dictionary_options').style.overflow = 'visible';
  }
}

dictionaries.fade = function(i) {

  document.getElementById('dictionary_options').style.overflow = 'hidden';

  document.getElementById('showoptionsmenu').style.backgroundColor=dictionaries.backgroundFades[i/10];
  document.getElementById('showoptionsimg').style.backgroundColor=dictionaries.backgroundFades[i/10];

  if (i == 50) {
    document.getElementById('showoptionsmenu').style.border='0px';
    document.getElementById('showoptionsmenu').style.paddingTop='6px';
    document.getElementById('showoptionsmenu').style.paddingLeft='1px';
    document.getElementById('showoptionsmenu').style.paddingRight='1px';
  }

  document.getElementById('dictionary_options').style.height = (i*0.8)+'px';

  document.getElementById('dictionary_options').style.opacity=(i/100);
  document.getElementById('dictionary_options').style.filter='alpha(opacity='+i+')';
  document.getElementById('dictionary_options').style.khtmlOpacity=(i/100);
  document.getElementById('dictionary_options').style.MozOpacity=(i/100);

  if (i > 0) {
    i = (parseInt(i)-10);
    setTimeout("dictionaries.fade('"+i+"');",5);
  } else {
    document.getElementById('dictionary_options').style.visibility='hidden';
    document.getElementById('dictionary_options').style.position='absolute';
    document.getElementById('showoptionsmenu').style.border='0px';
    document.getElementById('showoptionsmenu').style.backgroundColor='transparent';
    document.getElementById('showoptionsimg').style.visibility='hidden';
  }
}


dictionaries.selectDictionary = function(id,t,bg,col,bg2,col2) {

  dictionaries.selectDictionaryCount(id);

  if (document.getElementById('dictionaryDisabled_'+id).value != 'true') {

    if (document.getElementById('dictionaryList_'+id)) {
      if (t == 3) {
        if (document.getElementById('dictionaryList_name_'+id).value == 'sel') {
          if (dictionaries.sdc > 1) {
            document.getElementById('dictionaryList_'+id).style.background='url(/images/dictionaries/list_tabs/'+bg2+')';
            document.getElementById('dictionaryList_'+id).style.color=col2;
            document.getElementById('dictionaryList_name_'+id).value = '';
            document.getElementById('dictionaryListPlus_'+id).src = '/images/dictionaries/minus_hvitt.png';
            dictionaries.tabs.loadTabs(lastSearchWord,lastDictionary,id,2);
          }
        } else {
          document.getElementById('dictionaryList_'+id).style.background='url(/images/dictionaries/list_tabs/'+bg+')';
          document.getElementById('dictionaryList_name_'+id).value = 'sel';
          document.getElementById('dictionaryList_'+id).style.color=col;
          document.getElementById('dictionaryListPlus_'+id).src = '/images/dictionaries/minus_hvitt.png';
          dictionaries.tabs.loadTabs(lastSearchWord,lastDictionary,id,1);
        }
      } else if (t == 1 && document.getElementById('dictionaryList_name_'+id).value != 'sel') {
        document.getElementById('dictionaryList_'+id).style.background='url(/images/dictionaries/list_tabs/'+bg+')';
        document.getElementById('dictionaryList_name_'+id).value = 'sel';
        document.getElementById('dictionaryList_'+id).style.color=col2;
        document.getElementById('dictionaryListPlus_'+id).src = '/images/dictionaries/minus_hvitt.png';
        dictionaries.tabs.loadTabs(lastSearchWord,lastDictionary,id,t);
      } else {
        if (dictionaries.sdc > 1) {
          if ((t == 1 && document.getElementById('dictionaryList_name_'+id).value == 'sel') || document.getElementById('dictionaryList_name_'+id).value == 'two') {
            document.getElementById('dictionaryList_'+id).style.background='url(/images/dictionaries/list_tabs/'+bg2+')';
            document.getElementById('dictionaryList_name_'+id).value = '';
            document.getElementById('dictionaryList_'+id).style.color=col;
            document.getElementById('dictionaryListPlus_'+id).src = '/images/dictionaries/minus_hvitt.png';
            dictionaries.tabs.loadTabs(lastSearchWord,lastDictionary,id,2);
          } else {
            document.getElementById('dictionaryList_'+id).style.background='url(/images/dictionaries/list_tabs/'+bg2+')';
            document.getElementById('dictionaryList_name_'+id).value = 'sel';
            document.getElementById('dictionaryList_'+id).style.color=col2;
            document.getElementById('dictionaryListPlus_'+id).src = '/images/dictionaries/minus_hvitt.png';
            dictionaries.tabs.loadTabs(lastSearchWord,lastDictionary,id,2);
          }
        }
      }
    }

  }

  dictionaries.selectDictionaryCount(id);

}


dictionaries.selectDictionarySlide = function(t) {

  if (document.getElementById('dictionary_select_div').style.visibility == 'visible') { 
    i = 100;
    setTimeout("dictionaries.selectDictionary_fade('"+i+"');",10);
    t.firstChild.src='/images/content/vel_ordabokur_pluss_hover.png';
  } else { 
    i = 0;
    setTimeout("dictionaries.selectDictionary_unfade('"+i+"');",10);
    t.firstChild.src='/images/content/vel_ordabokur_minus_hover.png';
  }

}


dictionaries.selectDictionaryHover = function(id,tab_img_hover) {

  if (document.getElementById('dictionaryList_name_'+id).value != 'sel' && document.getElementById('dictionaryDisabled_'+id).value != 'true') { 
    document.getElementById('dictionaryList_'+id).style.background='url(/images/dictionaries/list_tabs/'+tab_img_hover+')'; 
    document.getElementById('dictionaryList_'+id).style.color='#ffffff'; 
    document.getElementById('dictionaryListPlus_'+id).src='/images/dictionaries/pluss_hvitt.png';
  }
 
}


dictionaries.selectDictionaryUnHover = function(id,alt_tab_color) {

  if (document.getElementById('dictionaryList_name_'+id).value != 'sel' && document.getElementById('dictionaryDisabled_'+id).value != 'true') { 
    document.getElementById('dictionaryList_'+id).style.background=''; 
    document.getElementById('dictionaryList_'+id).style.color=alt_tab_color; 
    document.getElementById('dictionaryListPlus_'+id).src='/images/dictionaries/plusses/'+document.getElementById('dictionaryListPlusImg_'+id).value;
  }

}

function onMouseLeave(e) { 
  if (!e) var e = window.event;
  e.cancelBubble = true;
  if (e.stopPropagation) e.stopPropagation();
}


dictionaries.maxSelectedDictionaries = 5;
dictionaries.sdc = 0;

dictionaries.selectDictionaryCount = function(id,m) {

  lns = new Array;
  dictionaries.sdc = 0;

  for(i=0;i<=document.getElementById('maxDictionaryValue').value;i++) {
    if (document.getElementById('dictionaryList_name_'+i)) {
      if (document.getElementById('dictionaryList_name_'+i).value == 'sel') {
        dictionaries.sdc++;
      } else {
        lns[i] = i;
      }
    }
  }

  if (parseInt(dictionaries.sdc) == dictionaries.maxSelectedDictionaries) {
    for(j=0;j<lns.length;j++) {
      if (lns[j] != undefined) {
        document.getElementById('dictionaryDisabled_'+lns[j]).value = 'true';
        document.getElementById('dictionaryList_'+lns[j]).style.color='#cccccc';
        document.getElementById('dictionaryList_'+lns[j]).style.cursor='default';
        document.getElementById('dictionaryListPlus_'+lns[j]).src = '/images/dictionaries/pluss_gratt.png';
      }
    }
  } else {
    for(j=0;j<lns.length;j++) {
      if (lns[j] != undefined) {
        if (lns[j] != id) {
          document.getElementById('dictionaryDisabled_'+lns[j]).value = 'false';
          document.getElementById('dictionaryList_'+lns[j]).style.color=document.getElementById('dictionaryListText_'+lns[j]).value;
          document.getElementById('dictionaryList_'+lns[j]).style.cursor='pointer';
          document.getElementById('dictionaryListPlus_'+lns[j]).src = '/images/dictionaries/plusses/'+document.getElementById('dictionaryListPlusImg_'+lns[j]).value;
        } else {
          document.getElementById('dictionaryDisabled_'+lns[j]).value = 'false';
//          document.getElementById('dictionaryList_'+lns[j]).style.color=document.getElementById('dictionaryListText_'+lns[j]).value;
          document.getElementById('dictionaryList_'+lns[j]).style.cursor='pointer';
//          document.getElementById('dictionaryListPlus_'+lns[j]).src = '/images/dictionaries/plusses/'+document.getElementById('dictionaryListPlusImg_'+lns[j]).value;
        }
      }
    }
  }	

}

dictionaries.selectDictionary_unfade = function(i) {

  document.getElementById('dictionary_select_div').style.visibility = 'visible';
//  document.getElementById('dictionary_select_div').style.height = (i*1.2)+'px';

  document.getElementById('dictionary_select_div').style.opacity=(i/100);
  document.getElementById('dictionary_select_div').style.filter='alpha(opacity='+i+')';
  document.getElementById('dictionary_select_div').style.khtmlOpacity=(i/100);
  document.getElementById('dictionary_select_div').style.MozOpacity=(i/100);

  if (i < 100) {
    i = (parseInt(i)+10);
    setTimeout("dictionaries.selectDictionary_unfade('"+i+"');",5);
  } else {

  }
}

dictionaries.selectDictionary_fade = function(i) {

//  document.getElementById('dictionary_select_div').style.height = (i*0.8)+'px';

  document.getElementById('dictionary_select_div').style.opacity=(i/100);
  document.getElementById('dictionary_select_div').style.filter='alpha(opacity='+i+')';
  document.getElementById('dictionary_select_div').style.khtmlOpacity=(i/100);
  document.getElementById('dictionary_select_div').style.MozOpacity=(i/100);

  if (i > 0) {
    i = (parseInt(i)-10);
    setTimeout("dictionaries.selectDictionary_fade('"+i+"');",5);
  } else {
    document.getElementById('dictionary_select_div').style.visibility='hidden';
    document.getElementById('dictionary_select_div').style.position='absolute';
  }
}


var ob_book = '';

dictionaries.showBookLoader = function(i) {
  if (i <= 12) {
    document.getElementById('dictionary_loader').firstChild.src=lnk+'/images/bok/bok'+i+'.png';
    ob_book = setTimeout("dictionaries.showBookLoader("+(parseInt(i)+2)+")",100);
  } else {
    ob_book = setTimeout("dictionaries.showBookLoader(1)",100);
  }
}

dictionaries.showLoader = function() {
  ob_book = setTimeout("dictionaries.showBookLoader(1)",100);
  intranet.overlay.show();
  intranet.overlay.update();
  var dlw = 200;
  var dlh = 120;
  if (document.getElementById('dictionary_loader')) {
    document.getElementById('dictionary_loader').style.width=dlw+'px';
    document.getElementById('dictionary_loader').style.height=dlh+'px';
    document.getElementById('dictionary_loader').style.left=((document.body.clientWidth/2)-(dlw/2))+'px';
    document.getElementById('dictionary_loader').style.visibility='visible';
  }
}
dictionaries.hideLoader = function() {
  if (document.getElementById('dictionary_loader')) {
    document.getElementById('dictionary_loader').style.visibility='hidden';
    document.getElementById('dictionary_loader').style.width='0px';
    document.getElementById('dictionary_loader').style.height='0px';
    document.getElementById('dictionary_loader').style.left='0px';
  }
  intranet.overlay.hide();
}


var lastSearchWord;
var lastDictionary;

dictionaries.favorite = function(ob,id,s,p) {
	
  xmlHttp_dictionaryRightStp = ajaxObj();

  xmlHttp_dictionaryRightStp.onreadystatechange=function() {
    if(xmlHttp_dictionaryRightStp.readyState==4 && xmlHttp_dictionaryRightStp.status==200) {
      if (xmlHttp_dictionaryRightStp.responseText) {
        document.getElementById('dictionaryRightMain').innerHTML = xmlHttp_dictionaryRightStp.responseText;
      }	
    }
  }

  xmlHttp_dictionaryRightStp.open("GET",lnk+"modules/post/dictionaryRight.php?type=favorites&s="+s+"&p="+p+"&ob="+ob+"&id="+id,false);
  xmlHttp_dictionaryRightStp.send(null);

}

dictionaries.rightMenu = function(ob,id,s,tp) {

  if (tp == undefined) { tp = ''; }

//  alert(ob+' - '+id+' - '+s+' - '+document.getElementById('dictionaryRightMain'));

  xmlHttp_dictionaryRight = ajaxObj();

  xmlHttp_dictionaryRight.onreadystatechange=function() {
    if(xmlHttp_dictionaryRight.readyState==4 && xmlHttp_dictionaryRight.status==200) {	
      if (xmlHttp_dictionaryRight.responseText) {
        document.getElementById('dictionaryRightMain').innerHTML = xmlHttp_dictionaryRight.responseText;
//alert(document.getElementById('dictionaryRightMain').offsetHeight);
      }
    }
  }

  xmlHttp_dictionaryRight.open("GET",lnk+"modules/post/dictionaryRight.php?type="+tp+"&ob="+ob+"&id="+id+"&s="+s,false);
  xmlHttp_dictionaryRight.send(null);

}

dictionaries.search = function(s,scrollTop,s_ob,s_id) {

  if (s == undefined) { s = ''; }

  var ob = '';

  if (s_ob) {

    n_ob = s_ob;

  } else {

    n_ob = document.getElementById('dictionary_chosen').value;

/*
    if (document.getElementById('ordb-en-fo').checked == true) { n_ob = 'en-fo'; }
    if (document.getElementById('ordb-fo-en').checked == true) { n_ob = 'fo-en'; }
    if (document.getElementById('ordb-dk-fo').checked == true) { n_ob = 'da-fo'; }
    if (document.getElementById('ordb-de-fo').checked == true) { n_ob = 'de-fo'; }
    if (document.getElementById('ordb-fo-spa').checked == true) { n_ob = 'fo-es'; }
    if (document.getElementById('ordb-fr-fo') && document.getElementById('ordb-fr-fo').checked == true) { n_ob = 'fr-fo'; }
  //  if (document.getElementById('ordb-rus-fo').checked == true) { n_ob = 'rus-fo'; }
*/

  }

  dictionaries.tabs.loadTabs(s,n_ob);

  ob = '&ob='+n_ob;

  if (s == lastSearchWord && n_ob == lastDictionary) { } else { if (document.getElementById('ordabokasida')) { document.getElementById('ordabokasida').value = 1; } }

  lastSearchWord = s;
  var tm = parseInt(new Date().getTime());

  dictionaries.hideLoader();
  clearTimeout(ob_book);

  if (s != '') {
    clearTimeout(overlayshow);
    var overlayshow = setTimeout("dictionaries.showLoader()",500);
  }

  xmlHttp_dictionarySearch = ajaxObj();

  xmlHttp_dictionarySearch.onreadystatechange=function() {

    if (xmlHttp_dictionarySearch.readyState==4 && xmlHttp_dictionarySearch.status==500) {

      alert('Ein trupulleiki var við leitingini');
      dictionaries.hideLoader();
      clearTimeout(overlayshow);
      clearTimeout(ob_book);

    } else if(xmlHttp_dictionarySearch.readyState==4 && xmlHttp_dictionarySearch.status==200) {

      if (xmlHttp_dictionarySearch.responseText) {

        document.getElementById('dictionary_results').innerHTML = xmlHttp_dictionarySearch.responseText;
        document.getElementById('dictionary_results').style.visibility='visible';
        document.getElementById('dictionary_results').style.position='relative';

        dictionaries.hideLoader();
        clearTimeout(overlayshow);
        clearTimeout(ob_book);

        var tm2 = parseInt(new Date().getTime());
        var ntm = ""+((tm2-tm)/1000);
        if (document.getElementById('microseconds')) { document.getElementById('microseconds').innerHTML = ntm.replace(/\./g, ","); }

        if (scrollTop != undefined && scrollTop != '') {
          scroll(0,scrollTop);
        }

        dictionaries.rightMenu(n_ob,'',s);

      } else {

        dictionaries.hideLoader();
        clearTimeout(overlayshow);
        clearTimeout(ob_book);
        document.getElementById('dictionary_results').innerHTML = 'Skipanin fann einki orð, ið passaði til leitingina';

      }

    }
  }

  var sida = 1;
  if (document.getElementById('ordabokasida')) { sida = document.getElementById('ordabokasida').value; }

  sida = '&sida='+sida;

//  document.getElementById('dictionary_loader').innerHTML = 'Leitar eftir "'+s+'"...';

//  document.getElementById('dictionary_results').innerHTML = '';
//  document.getElementById('dictionary_results').style.visibility='hidden';
//  document.getElementById('dictionary_results').style.position='absolute';

  st = '';

  if (document.getElementById('searchOnlyWholeWords').checked == true) {
    st = st+'&st=searchOnlyWholeWords';
  } else if (document.getElementById('lookforPartofWord').checked == true) {
    st = st+'&st=lookforPartofWord';
  }
  if (document.getElementById('casesensitive').checked == true) {
    st = st+'&cs=caseSensitive';
  }

  if (document.getElementById('lookInExplanation').checked == true) {
    st = st+'&li=explanation';
  }

  var ib = '';

  if (document.getElementById('intranet_user_activated') && document.getElementById('intranet_user_activated').value == '112') {
    ib = '&in=112';
  }

  var rus = "";

  if (n_ob == "rus-fo") {
    rus = "&entity="+encodeURIComponent(numEncode(s));
  }

  var id = "";

  if (s_id != undefined) {
    id = "&id="+s_id;
  }

  xmlHttp_dictionarySearch.open("GET",lnk+"/modules/post/dictionarySearch.php?s="+encodeURIComponent(s)+ob+st+sida+rus+ib+id,true);
  xmlHttp_dictionarySearch.send(null);

  lastDictionary = n_ob;

}

numEncode = function(s){

		var e = "";
		for (var i = 0; i < s.length; i++)
		{
			var c = s.charAt(i);
			if (c < " " || c > "~")
			{
				c = "&#" + c.charCodeAt() + ";";
			}
			e += c;
		}
		return e;
}


dictionaries.editOldVal = '';
dictionaries.editIsPressed = '';
dictionaries.editCurrentlyOpen = '';

dictionaries.changeEditStyle = function(id,t) {
/*
  if (t == 1) {
    document.getElementById('wordSection_'+id).style.marginLeft='-5px';
    document.getElementById('wordSection_'+id).style.paddingLeft='4px';
    document.getElementById('wordSection_'+id).style.marginRight='-5px';
    document.getElementById('wordSection_'+id).style.paddingRight='4px';
    document.getElementById('wordSection_'+id).style.marginBottom='-6px';
    document.getElementById('wordSection_'+id).style.paddingBottom='0px';
    document.getElementById('wordSection_'+id).style.paddingTop='4px';
    document.getElementById('wordSection_'+id).style.border='1px solid #eeeeee';
  } else {
    if (dictionaries.editIsPressed != id) {
      document.getElementById('wordSection_'+id).style.marginLeft='0px';
      document.getElementById('wordSection_'+id).style.paddingLeft='0px';
      document.getElementById('wordSection_'+id).style.marginRight='0px';
      document.getElementById('wordSection_'+id).style.paddingRight='0px';
      document.getElementById('wordSection_'+id).style.marginBottom='0px';
      document.getElementById('wordSection_'+id).style.paddingBottom='0px';
      document.getElementById('wordSection_'+id).style.paddingTop='5px';
      document.getElementById('wordSection_'+id).style.border='0px';
    }
  }
*/
}

dictionaries.pressEditStyle = function(id,dictionary) {

  xmlHttp_dictionaryAdmin = ajaxObj();

  xmlHttp_dictionaryAdmin.onreadystatechange=function() {
    if(xmlHttp_dictionaryAdmin.readyState==4 && xmlHttp_dictionaryAdmin.status==200) {
      if (xmlHttp_dictionaryAdmin.responseText) {
        document.getElementById('dictionaryAdmin').innerHTML = xmlHttp_dictionaryAdmin.responseText;

        if (document.getElementById('dictionaryAdmin_edit_field_inflexcats')) { WYSIWYG.attach('dictionaryAdmin_edit_field_inflexcats', dictionary_inflexcat, 1); }
        if (document.getElementById('dictionaryAdmin_edit_field_grammarComment')) { WYSIWYG.attach('dictionaryAdmin_edit_field_grammarComment', dictionary_inflexcat, 1); }
        if (document.getElementById('dictionaryAdmin_edit_field_text')) { WYSIWYG.attach('dictionaryAdmin_edit_field_text', dictionary_text, 1); }
        if (document.getElementById('dictionaryAdmin_edit_field_uppruni')) { WYSIWYG.attach('dictionaryAdmin_edit_field_uppruni', dictionary_text, 1); }
        if (document.getElementById('dictionaryAdmin_edit_field_danishtext')) { WYSIWYG.attach('dictionaryAdmin_edit_field_danishtext', dictionary_text, 1); }
        if (document.getElementById('dictionaryAdmin_edit_field_upprunakelda').outerHTML.match('TEXTAREA')) { WYSIWYG.attach('dictionaryAdmin_edit_field_upprunakelda', dictionary_text, 1); }

        intranet.overlay.show();
//        document.body.style.overflow = "hidden";
        document.getElementById('dictionaryAdmin').style.visibility='visible';

      }
    }
  }

  xmlHttp_dictionaryAdmin.open("GET",lnk+"modules/pages/dictionaryAdmin.edit.php?ord="+id+"&ob="+dictionary,true);
  xmlHttp_dictionaryAdmin.send(null);

    st = 0;

    if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
      st = document.body.scrollTop;
    } else if( typeof( window.pageYOffset ) == 'number' ) {
      st = document.documentElement.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollTop ) ) {
      st = document.documentElement.scrollTop;
    }

    if (st == 0) {
      document.getElementById('dictionaryAdmin').style.marginTop=50+'px';
    } else if (st != '' && st != undefined) {
      document.getElementById('dictionaryAdmin').style.marginTop=(parseInt(st)+50)+'px';
      dictionaries.sTop = st;
    }

}


dictionaries.activateToolbar = function(id) {
  if (document.getElementById('dictionaryAdmin').style.visibility == 'visible') {
    document.getElementById(id+'_menu').style.visibility='visible';
  }
}

dictionaries.editUndoChanges = function(id) {

}


dictionaries.sTop = 0;


dictionaries.addWord = function() {

  xmlHttp_dictionaryAdmin = ajaxObj();

  xmlHttp_dictionaryAdmin.onreadystatechange=function() {
    if(xmlHttp_dictionaryAdmin.readyState==4 && xmlHttp_dictionaryAdmin.status==200) {
      if (xmlHttp_dictionaryAdmin.responseText) {
        document.getElementById('dictionaryAdmin').innerHTML = xmlHttp_dictionaryAdmin.responseText;

        if (document.getElementById('dictionaryAdmin_edit_field_inflexcats')) { WYSIWYG.attach('dictionaryAdmin_edit_field_inflexcats', dictionary_inflexcat, 1); }
        if (document.getElementById('dictionaryAdmin_edit_field_grammarComment')) { WYSIWYG.attach('dictionaryAdmin_edit_field_grammarComment', dictionary_inflexcat, 1); }
        if (document.getElementById('dictionaryAdmin_edit_field_text')) { WYSIWYG.attach('dictionaryAdmin_edit_field_text', dictionary_text, 1); }
        if (document.getElementById('dictionaryAdmin_edit_field_uppruni')) { WYSIWYG.attach('dictionaryAdmin_edit_field_uppruni', dictionary_text, 1); }
        if (document.getElementById('dictionaryAdmin_edit_field_danishtext')) { WYSIWYG.attach('dictionaryAdmin_edit_field_danishtext', dictionary_text, 1); }

        intranet.overlay.show();
//        document.body.style.overflow = "hidden";
        document.getElementById('dictionaryAdmin').style.visibility='visible';

      }
    }
  }

  ob = "";

  ob = document.getElementById('dictionary_chosen').value;

  if (ob == 'en-fo') {
    ob = "dictionary_en_fo";
  } else if (ob == 'fo-en') {
    ob = "dictionary_fo_en";
  } else if (ob == 'da-fo') {
    ob = "dictionary_da_fo";
  } else if (ob == 'fr-fo') {
    ob = "dictionary_fr_fo";
  } else if (ob == 'fo-es') {
    ob = "dictionary_fo_spa";
  }

/*
  if (document.getElementById('ordb-en-fo').checked == true) {
    ob = "dictionary_en_fo";
  } else if (document.getElementById('ordb-fo-en').checked == true) {
    ob = "dictionary_fo_en";
  } else if (document.getElementById('ordb-dk-fo').checked == true) {
    ob = "dictionary_da_fo";
  } else if (document.getElementById('ordb-de-fo').checked == true) {
    ob = "dictionary_de_fo";
  } else if (document.getElementById('ordb-fo-spa').checked == true) {
    ob = "dictionary_fo_spa";
  } else if (document.getElementById('ordb-fr-fo') && document.getElementById('ordb-fr-fo').checked == true) {
    ob = "dictionary_fr_fo";
//  } else if (document.getElementById('ordb-rus-fo').checked == true) {
//    ob = "dictionary_rus_fo";
  }
*/

  xmlHttp_dictionaryAdmin.open("GET",lnk+"modules/pages/dictionaryAdmin.edit.php?ob="+ob,true);
  xmlHttp_dictionaryAdmin.send(null);

    st = 0;

    if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
      st = document.body.scrollTop;
    } else if( typeof( window.pageYOffset ) == 'number' ) {
      st = document.documentElement.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollTop ) ) {
      st = document.documentElement.scrollTop;
    }

    if (st == 0) {
      document.getElementById('dictionaryAdmin').style.marginTop=50+'px';
    } else if (st != '' && st != undefined) {
      document.getElementById('dictionaryAdmin').style.marginTop=(parseInt(st)+50)+'px';
      dictionaries.sTop = st;
    }

}


dictionaries.addWord2 = function() {

  xmlHttp_dictionaryAdmin = ajaxObj();

  xmlHttp_dictionaryAdmin.onreadystatechange=function() {
    if(xmlHttp_dictionaryAdmin.readyState==4 && xmlHttp_dictionaryAdmin.status==200) {
      if (xmlHttp_dictionaryAdmin.responseText) {
        document.getElementById('dictionaryAdmin').innerHTML = xmlHttp_dictionaryAdmin.responseText;

        if (document.getElementById('dictionaryAdmin_edit_field_inflexcats')) { WYSIWYG.attach('dictionaryAdmin_edit_field_grammarComment', dictionary_inflexcat, 1); }
        if (document.getElementById('dictionaryAdmin_edit_field_grammarComment')) { WYSIWYG.attach('dictionaryAdmin_edit_field_inflexcats', dictionary_inflexcat, 1); }
        if (document.getElementById('dictionaryAdmin_edit_field_text')) { WYSIWYG.attach('dictionaryAdmin_edit_field_text', dictionary_text, 1); }
        if (document.getElementById('dictionaryAdmin_edit_field_uppruni')) { WYSIWYG.attach('dictionaryAdmin_edit_field_uppruni', dictionary_text, 1); }

        intranet.overlay.show();
//        document.body.style.overflow = "hidden";
        document.getElementById('dictionaryAdmin').style.visibility='visible';

      }
    }
  }

  ob = 'dictionary_fr_fo';

  xmlHttp_dictionaryAdmin.open("GET",lnk+"modules/pages/dictionaryAdmin.edit.php?ob="+ob,true);
  xmlHttp_dictionaryAdmin.send(null);

    st = 0;

    if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
      st = document.body.scrollTop;
    } else if( typeof( window.pageYOffset ) == 'number' ) {
      st = document.documentElement.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollTop ) ) {
      st = document.documentElement.scrollTop;
    }

    if (st == 0) {
      document.getElementById('dictionaryAdmin').style.marginTop=50+'px';
    } else if (st != '' && st != undefined) {
      document.getElementById('dictionaryAdmin').style.marginTop=(parseInt(st)+50)+'px';
      dictionaries.sTop = st;
    }

}


dictionaries.closeEditWindow = function() {
  if (confirm('Vilt tú annulera møguligar broytingar?')) {
    intranet.overlay.hide();
    document.body.style.overflow = "auto";
    document.getElementById('dictionaryAdmin').style.visibility='hidden';
  }
}

dictionaries.saveChanges = function(id,ob) {

  xmlHttp_dictionaryAdminPost = ajaxObj();

  xmlHttp_dictionaryAdminPost.onreadystatechange=function() {
    if(xmlHttp_dictionaryAdminPost.readyState==4 && xmlHttp_dictionaryAdminPost.status==200) {
      if (xmlHttp_dictionaryAdminPost.responseText == "ok") {

        if (document.getElementById('searchWord')) {
          dictionaries.search(document.getElementById('searchWord').value,dictionaries.sTop);
        } else {
          intranet.overlay.hide();
        }

        document.body.style.overflow = "auto";
        document.getElementById('dictionaryAdmin').style.visibility='hidden';
      } else {
        alert(xmlHttp_dictionaryAdminPost.responseText);
        alert('Ein trupulleiki hendi, meðan skipanin royndi at goyma broytingarnar - vinaliga royn aftur');
      }
    }
  }

  wl = '';

  if (document.getElementById('dictionaryAdmin_edit_field_wordlist')) {
    wl = "&wordlist="+encodeURIComponent(document.getElementById('dictionaryAdmin_edit_field_wordlist').value);
  }

  var params = "searchword="+encodeURIComponent(document.getElementById('dictionaryAdmin_edit_field_searchWord').value)+"&wordNr="+encodeURIComponent(document.getElementById('dictionaryAdmin_edit_field_wordNr').value)+"&grammarComment="+encodeURIComponent(WYSIWYG.getEditorWindow('dictionaryAdmin_edit_field_grammarComment').document.body.innerHTML)+"&phonetic="+encodeURIComponent(document.getElementById('dictionaryAdmin_edit_field_phonetic').value)+"&inflexcats="+encodeURIComponent(WYSIWYG.getEditorWindow('dictionaryAdmin_edit_field_inflexcats').document.body.innerHTML)+"&explanation="+encodeURIComponent(WYSIWYG.getEditorWindow('dictionaryAdmin_edit_field_text').document.body.innerHTML)+"&uppruni="+encodeURIComponent(WYSIWYG.getEditorWindow('dictionaryAdmin_edit_field_uppruni').document.body.innerHTML)+"&upprunakelda="+encodeURIComponent((document.getElementById('dictionaryAdmin_edit_field_upprunakelda').outerHTML.match('TEXTAREA') == 'TEXTAREA' ? WYSIWYG.getEditorWindow('dictionaryAdmin_edit_field_upprunakelda').document.body.innerHTML : document.getElementById('dictionaryAdmin_edit_field_upprunakelda').value))+wl;

  xmlHttp_dictionaryAdminPost.open("POST",lnk+"modules/post/intranet/dictionaryAdmin.edit.post.php?ord="+id+"&ob="+ob,true);
  xmlHttp_dictionaryAdminPost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlHttp_dictionaryAdminPost.send(params);

}

dictionaries.saveChangesNew = function(id,ob) {

  if (document.getElementById('dictionaryAdmin_edit_field_dictionary')) {
    ob = document.getElementById('dictionaryAdmin_edit_field_dictionary').value;
  }

  xmlHttp_dictionaryAdminPost = ajaxObj();

  xmlHttp_dictionaryAdminPost.onreadystatechange=function() {
    if(xmlHttp_dictionaryAdminPost.readyState==4 && xmlHttp_dictionaryAdminPost.status==200) {
      if (xmlHttp_dictionaryAdminPost.responseText == "ok") {
        if (document.getElementById('searchWord')) {
          document.getElementById('searchWord').value = document.getElementById('dictionaryAdmin_edit_field_searchWord').value;
          dictionaries.search(document.getElementById('searchWord').value);
        } else {
          intranet.overlay.hide();
        }

        document.body.style.overflow = "auto";
        document.getElementById('dictionaryAdmin').style.visibility='hidden';
      } else {
        alert('Ein trupulleiki hendi, meðan skipanin royndi at goyma orðið - vinaliga royn aftur');
      }
    }
  }

  var params = "searchword="+encodeURIComponent(document.getElementById('dictionaryAdmin_edit_field_searchWord').value)+"&wordNr="+encodeURIComponent(document.getElementById('dictionaryAdmin_edit_field_wordNr').value)+"&grammarComment="+encodeURIComponent(WYSIWYG.getEditorWindow('dictionaryAdmin_edit_field_grammarComment').document.body.innerHTML)+"&phonetic="+encodeURIComponent(document.getElementById('dictionaryAdmin_edit_field_phonetic').value)+"&inflexcats="+encodeURIComponent(WYSIWYG.getEditorWindow('dictionaryAdmin_edit_field_inflexcats').document.body.innerHTML)+"&explanation="+encodeURIComponent(WYSIWYG.getEditorWindow('dictionaryAdmin_edit_field_text').document.body.innerHTML)+"&uppruni="+encodeURIComponent(WYSIWYG.getEditorWindow('dictionaryAdmin_edit_field_uppruni').document.body.innerHTML)+"&upprunakelda="+encodeURIComponent(document.getElementById('dictionaryAdmin_edit_field_upprunakelda').value);

  xmlHttp_dictionaryAdminPost.open("POST",lnk+"modules/post/intranet/dictionaryAdmin.add.post.php?ob="+ob,true);
  xmlHttp_dictionaryAdminPost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlHttp_dictionaryAdminPost.send(params);

}


dictionaries.forgotPassword = function() {

  intranet.overlay.show();

  if( typeof( window.pageYOffset ) == 'number' ) {
    st = window.pageYOffset;
    sl = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    st = document.body.scrollTop;
    sl = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    st = document.documentElement.scrollTop;
    sl = document.documentElement.scrollLeft;
  }

  document.getElementById('readfrombooktext').style.width = '350px';
  document.getElementById('rfb1').style.width = '330px';
  document.getElementById('rfb2').style.visibility = 'hidden';
  document.getElementById('rfb3').style.visibility = 'hidden';
  document.getElementById('rfb2').style.position = 'absolute';
  document.getElementById('rfb3').style.position = 'absolute';

  if (document.getElementById('upperbottom')) { document.getElementById('upperbottom').style.visibility='hidden'; }
  if (document.getElementById('bottom')) { document.getElementById('bottom').style.visibility='hidden'; }

  intranet.overlay.show();
  intranet.overlay.update();
  document.getElementById('readfrombooktitle').innerHTML = 'Gloymt loyniorð';

  xmlHttp_loadBookText = ajaxObj();

  xmlHttp_loadBookText.onreadystatechange=function() {
    if(xmlHttp_loadBookText.readyState==4) {
      if (xmlHttp_loadBookText.responseText) {
        document.getElementById('readfrombookinnertext').innerHTML = xmlHttp_loadBookText.responseText;
        document.getElementById('readfrombooktext').style.marginLeft='100px';
        document.getElementById('readfrombooktext').style.visibility='visible';
        document.getElementById('quote').style.visibility='hidden';
        document.getElementById('quote').style.position='absolute';
        scroll(0,intranet.scrollBannerTop);
      } else {
        document.getElementById('quote').style.visibility='visible';
        document.getElementById('quote').style.position='relative';
        intranet.overlay.hide();
      }
    }
  }

  xmlHttp_loadBookText.open("GET",lnk+"modules/post/forgotPassword.php",true);
  xmlHttp_loadBookText.send(null);

}

dictionaries.forgotPasswordPost = function() {

  if (document.getElementById('forgotpassword_email').value.match(emailFilter)) {

    xmlHttp_forgotPasswordPost = ajaxObj();

    xmlHttp_forgotPasswordPost.onreadystatechange=function() {
      if(xmlHttp_forgotPasswordPost.readyState==4) {
        if (xmlHttp_forgotPasswordPost.responseText == '_issent') {
          document.getElementById('readfrombooktext').style.visibility='hidden';
          intranet.alert.show('Ein teldupostur er sendur tær á '+document.getElementById('forgotpassword_email').value);
        } else {
        }
      }
    }

    xmlHttp_forgotPasswordPost.open("GET",lnk+"modules/post/forgotPasswordPost.php?email="+document.getElementById('forgotpassword_email').value,true);
    xmlHttp_forgotPasswordPost.send(null);

  } else {

    document.getElementById('readfrombooktext').style.zIndex='1';
    intranet.alert.show('Telduposturin má vera líkur hesum sniði: navn@teldupostur.fo');

  }

}



dictionaries.calculatePrice = function(id) {
  avsl = new Array;
  avsl[12] = 0.05;
  avsl[24] = 0.10;
  document.getElementById('bookSalesPrice_time_'+id).innerHTML = document.getElementById('bookSalesPriceMonths_'+id).value+' mán.';
  document.getElementById('bookSalesPrice_amount_'+id).innerHTML = document.getElementById('bookSalesPriceNums_'+id).value;
  if (document.getElementById('bookSalesPriceMonths_'+id).value >= 24) {
    document.getElementById('bookSalesPrice_totalprice_'+id).innerHTML = ((document.getElementById('bookSalesPriceOrg_'+id).value*(document.getElementById('bookSalesPriceMonths_'+id).value*document.getElementById('bookSalesPriceNums_'+id).value)))+',-';
    document.getElementById('bookSalesPrice_'+id).innerHTML = ((document.getElementById('bookSalesPriceOrg_'+id).value*(document.getElementById('bookSalesPriceMonths_'+id).value*document.getElementById('bookSalesPriceNums_'+id).value))*0.90)+',-';
    document.getElementById('bookSalesPrice_discount_'+id).innerHTML = ((document.getElementById('bookSalesPriceOrg_'+id).value*(document.getElementById('bookSalesPriceMonths_'+id).value*document.getElementById('bookSalesPriceNums_'+id).value))*0.10)+',-';
  } else if (document.getElementById('bookSalesPriceMonths_'+id).value >= 12) {
    document.getElementById('bookSalesPrice_totalprice_'+id).innerHTML = ((document.getElementById('bookSalesPriceOrg_'+id).value*(document.getElementById('bookSalesPriceMonths_'+id).value*document.getElementById('bookSalesPriceNums_'+id).value)))+',-';
    document.getElementById('bookSalesPrice_'+id).innerHTML = ((document.getElementById('bookSalesPriceOrg_'+id).value*(document.getElementById('bookSalesPriceMonths_'+id).value*document.getElementById('bookSalesPriceNums_'+id).value))*0.95)+',-';
    document.getElementById('bookSalesPrice_discount_'+id).innerHTML = ((document.getElementById('bookSalesPriceOrg_'+id).value*(document.getElementById('bookSalesPriceMonths_'+id).value*document.getElementById('bookSalesPriceNums_'+id).value))*0.05)+',-';
  } else {
    document.getElementById('bookSalesPrice_totalprice_'+id).innerHTML = ((document.getElementById('bookSalesPriceOrg_'+id).value*(document.getElementById('bookSalesPriceMonths_'+id).value*document.getElementById('bookSalesPriceNums_'+id).value)))+',-';
    document.getElementById('bookSalesPrice_'+id).innerHTML = (document.getElementById('bookSalesPriceOrg_'+id).value*(document.getElementById('bookSalesPriceMonths_'+id).value*document.getElementById('bookSalesPriceNums_'+id).value))+',-';
    document.getElementById('bookSalesPrice_discount_'+id).innerHTML = 0+',-';
  }
}


dictionaries.insertSpecial = function(char) {
  if (document.getElementById('searchWord')) {
    if (document.getElementById('searchWord').value != 'Skriva orð' && document.getElementById('searchWord').value != '') {

      if (document.selection) {
        document.getElementById('searchWord').focus();
        sel = document.selection.createRange();
        sel.text = char;
      }
      else if (document.getElementById('searchWord').selectionStart || document.getElementById('searchWord').selectionStart == '0') {
        var startPos = document.getElementById('searchWord').selectionStart;
        var endPos = document.getElementById('searchWord').selectionEnd;
        document.getElementById('searchWord').value = document.getElementById('searchWord').value.substring(0, startPos)
                  + char
                  + document.getElementById('searchWord').value.substring(endPos, document.getElementById('searchWord').value.length);
      } else {
        document.getElementById('searchWord').value += char;
      }

    } else {

      document.getElementById('searchWord').value = '';

      if (document.selection) {
        document.getElementById('searchWord').focus();
        sel = document.selection.createRange();
        sel.text = char;
      }
      else if (document.getElementById('searchWord').selectionStart || document.getElementById('searchWord').selectionStart == '0') {
        var startPos = document.getElementById('searchWord').selectionStart;
        var endPos = document.getElementById('searchWord').selectionEnd;
        document.getElementById('searchWord').value = document.getElementById('searchWord').value.substring(0, startPos)
                  + char
                  + document.getElementById('searchWord').value.substring(endPos, document.getElementById('searchWord').value.length);
      } else {
        document.getElementById('searchWord').value += char;
      }

    }
  }
}


dictionaries.insertSpecial2 = function(id,char) {
  if (document.getElementById(id)) {
    if (document.getElementById(id).value != 'Skriva orð' && document.getElementById(id).value != '') {

      if (document.selection) {
        document.getElementById(id).focus();
        sel = document.selection.createRange();
        sel.text = char;
      }
      else if (document.getElementById(id).selectionStart || document.getElementById(id).selectionStart == '0') {
        var startPos = document.getElementById(id).selectionStart;
        var endPos = document.getElementById(id).selectionEnd;
        document.getElementById(id).value = document.getElementById(id).value.substring(0, startPos)
                  + char
                  + document.getElementById(id).value.substring(endPos, document.getElementById(id).value.length);
      } else {
        document.getElementById(id).value += char;
      }

    } else {

      document.getElementById(id).value = '';

      if (document.selection) {
        document.getElementById(id).focus();
        sel = document.selection.createRange();
        sel.text = char;
      }
      else if (document.getElementById(id).selectionStart || document.getElementById(id).selectionStart == '0') {
        var startPos = document.getElementById(id).selectionStart;
        var endPos = document.getElementById(id).selectionEnd;
        document.getElementById(id).value = document.getElementById(id).value.substring(0, startPos)
                  + char
                  + document.getElementById(id).value.substring(endPos, document.getElementById(id).value.length);
      } else {
        document.getElementById(id).value += char;
      }

    }
  }
}


dictionaries.showOrigin = function(id,ob,title) {

  if( typeof( window.pageYOffset ) == 'number' ) {
    st = window.pageYOffset;
    sl = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    st = document.body.scrollTop;
    sl = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    st = document.documentElement.scrollTop;
    sl = document.documentElement.scrollLeft;
  }

  if (document.getElementById('upperbottom')) { document.getElementById('upperbottom').style.visibility='hidden'; }
  if (document.getElementById('bottom')) { document.getElementById('bottom').style.visibility='hidden'; }
  document.getElementById('quote').src='http://sprotin.fo/images/content/ordupp.png';

  intranet.overlay.show();
  intranet.overlay.update();
  document.getElementById('readfrombooktitle').innerHTML = title;
  document.getElementById('readfrombooktext').style.width = '600px';
  document.getElementById('rfb1').style.width = '580px';
  document.getElementById('rfb3').style.visibility = 'hidden';
  document.getElementById('rfb3').style.position = 'absolute';

  xmlHttp_loadBookText = ajaxObj();

  xmlHttp_loadBookText.onreadystatechange=function() {
    if(xmlHttp_loadBookText.readyState==4) {
      if (xmlHttp_loadBookText.responseText) {
        document.getElementById('readfrombookinnertext').innerHTML = xmlHttp_loadBookText.responseText;
        if (document.getElementById('bottom')) {
          document.getElementById('readfrombooktext').style.marginLeft='0px';
        } else {
          document.getElementById('readfrombooktext').style.marginTop='50px';
//          document.getElementById('readfrombooktext').style.marginLeft='-225px';
        }
        document.getElementById('readfrombooktext').style.visibility='visible';
        if (document.getElementById('bottom')) { scroll(0,intranet.scrollBannerTop); }
      } else {
        intranet.overlay.hide();
      }
    }
  }

  xmlHttp_loadBookText.open("GET",lnk+"/modules/post/dictionaryOrigin.php?id="+id+"&ob="+ob,true);
  xmlHttp_loadBookText.send(null);

}

dictionaries.hideOrigin = function() {
  document.getElementById('readfrombooktitle').innerHTML = '';
  document.getElementById('readfrombookinnertext').innerHTML = '';
  document.getElementById('readfrombooktext').style.visibility='hidden';
  if (document.getElementById('upperbottom')) { document.getElementById('upperbottom').style.visibility='visible'; }
  if (document.getElementById('bottom')) { document.getElementById('bottom').style.visibility='visible'; }
  intranet.overlay.hide();
  scroll(sl,st);
}


dictionaries.intranetRequest = new Object();

dictionaries.intranetRequest.validate = function() {
  if (document.getElementById('dictionaries.intranetRequest.name').value == '' || document.getElementById('dictionaries.intranetRequest.name').value == 'Skúli, fyritøka ella stovnur') {
    alert('Vinaliga skriva navnið á skúlanum, fyritøkuni ella stovninum');
    document.getElementById('dictionaries.intranetRequest.name').focus();
  } else if (document.getElementById('dictionaries.intranetRequest.contactperson').value == '' || document.getElementById('dictionaries.intranetRequest.contactperson').value == 'Kontaktpersónur') {
    alert('Vinaliga skriva navnið á kontaktpersóni tygara');
    document.getElementById('dictionaries.intranetRequest.contactperson').focus();
  } else if (document.getElementById('dictionaries.intranetRequest.address').value == '' || document.getElementById('dictionaries.intranetRequest.address').value == 'Bústaður') {
    alert('Vinaliga skriva bústaðin hjá skúlanum, fyritøkuni ella stovninum');
    document.getElementById('dictionaries.intranetRequest.address').focus();
  } else if (document.getElementById('dictionaries.intranetRequest.city').value == '' || document.getElementById('dictionaries.intranetRequest.address').city == 'Bygd/býur') {
    alert('Vinaliga skriva heimbygdina/heimbýin hjá skúlanum, fyritøkuni ella stovninum');
    document.getElementById('dictionaries.intranetRequest.city').focus();
  } else if (document.getElementById('dictionaries.intranetRequest.email').value == '' || document.getElementById('dictionaries.intranetRequest.email').value == 'Teldupostbústaður') {
    alert('Vinaliga skriva teldupostbústaðin hjá skúlanum, fyritøkuni, stovninum ella kontaktpersóninum');
    document.getElementById('dictionaries.intranetRequest.email').focus();
  } else if (document.getElementById('dictionaries.intranetRequest.phone').value == '' || document.getElementById('dictionaries.intranetRequest.phone').value == 'Telefon') {
    alert('Vinaliga skriva telefonnummarið hjá skúlanum, fyritøkuni, stovninum ella kontaktpersóninum');
    document.getElementById('dictionaries.intranetRequest.phone').focus();
  } else if (document.getElementById('dictionaries.intranetRequest.iplist').value == '' || document.getElementById('dictionaries.intranetRequest.iplist').value == 'Internet IP-adressa/ur (1 pr. linju)') {
    alert('Vinaliga skriva eina ella fleiri internet IP-adressur');
    document.getElementById('dictionaries.intranetRequest.iplist').focus();
  } else {

    xmlHttp_intranetRequest = ajaxObj();

    xmlHttp_intranetRequest.onreadystatechange=function() {
      if(xmlHttp_intranetRequest.readyState==4) {
        if (xmlHttp_intranetRequest.responseText == 'ok') {
          alert('Fyrispurningur er sendur okkum og vit seta okkum í samband við tygum sum skjótast');
        } else {
          alert('Ein feilur hendi. Vinaliga royn aftur');
        }
      }
    }


    var params = "name="+encodeURIComponent(document.getElementById('dictionaries.intranetRequest.name').value)+"&contactperson="+encodeURIComponent(document.getElementById('dictionaries.intranetRequest.contactperson').value)+"&address="+encodeURIComponent(document.getElementById('dictionaries.intranetRequest.address').value)+"&email="+encodeURIComponent(document.getElementById('dictionaries.intranetRequest.email').value)+"&phone="+encodeURIComponent(document.getElementById('dictionaries.intranetRequest.phone').value)+"&iplist="+encodeURIComponent(document.getElementById('dictionaries.intranetRequest.iplist').value)+"&city="+encodeURIComponent(document.getElementById('dictionaries.intranetRequest.city').value)+"&postnumber="+encodeURIComponent(document.getElementById('dictionaries.intranetRequest.postnumber').value);

    xmlHttp_intranetRequest.open("POST",lnk+"modules/post/intranetRequest.php",true);
    xmlHttp_intranetRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp_intranetRequest.send(params);

  }
}


dictionaries.dropDown.lastPos = 0;
dictionaries.dropDown.maxPos = 10;
dictionaries.dropDown.lastSearch = '';
dictionaries.dropDown.lastUsedSearchWord = '';

dictionaries.dropDown.show = function() {

  s = document.getElementById('searchWord').value;

  if (s != '' && s.length >= 1 && s != dictionaries.dropDown.lastUsedSearchWord) {

  ob = "";

  ob = document.getElementById('dictionary_chosen').value;

/*
  if (document.getElementById('ordb-en-fo').checked == true) {
    ob = "en-fo";
  } else if (document.getElementById('ordb-fo-en').checked == true) {
    ob = "fo-en";
  } else if (document.getElementById('ordb-dk-fo').checked == true) {
    ob = "da-fo";
  } else if (document.getElementById('ordb-de-fo').checked == true) {
    ob = "de-fo";
  } else if (document.getElementById('ordb-fo-spa').checked == true) {
    ob = "fo-es";
  } else if (document.getElementById('ordb-fr-fo') && document.getElementById('ordb-fr-fo').checked == true) {
    ob = "fr-fo";
//  } else if (document.getElementById('ordb-rus-fo').checked == true) {
//    ob = "dictionary_rus_fo";
  }
*/

  xmlHttp_loadDropdown = ajaxObj();

  xmlHttp_loadDropdown.onreadystatechange=function() {
    if(xmlHttp_loadDropdown.readyState==4) {
      if (xmlHttp_loadDropdown.responseText) {
        if (xmlHttp_loadDropdown.responseText == dictionaries.dropDown.lastSearch) {
        } else {
          dictionaries.dropDown.lastPos = 0;
          document.getElementById('dictionarySearchFieldList').innerHTML = xmlHttp_loadDropdown.responseText;
          dictionaries.dropDown.lastSearch = xmlHttp_loadDropdown.responseText;
          document.getElementById('dictionarySearchFieldList').style.visibility = 'visible';
        }
      } else {
        document.getElementById('dictionarySearchFieldList').style.visibility = 'hidden';
        dictionaries.dropDown.lastUsedSearchWord = '';
      }
    }
  }

  xmlHttp_loadDropdown.open("GET",lnk+"/modules/post/dictionarySearchField.php?s="+s+"&ob="+ob,true);
  xmlHttp_loadDropdown.send(null);

  } else {
    document.getElementById('dictionarySearchFieldList').style.visibility = 'hidden';
  }

}


dictionaries.dropDown.moveUp = function() {
  if (document.getElementById('dictionarySearchFieldItem_'+dictionaries.dropDown.lastPos)) { document.getElementById('dictionarySearchFieldItem_'+dictionaries.dropDown.lastPos).style.backgroundColor=''; }
  if (dictionaries.dropDown.lastPos > 0) {
    dictionaries.dropDown.lastPos = parseInt(dictionaries.dropDown.lastPos)-1;
  }
  if (document.getElementById('dictionarySearchFieldItem_'+dictionaries.dropDown.lastPos)) { document.getElementById('dictionarySearchFieldItem_'+dictionaries.dropDown.lastPos).style.backgroundColor='#f1f1f1'; }
//  alert(document.getElementById('dictionarySearchFieldItem_'+dictionaries.dropDown.lastPos).innerHTML);
}

dictionaries.dropDown.moveDown = function() {
  if (document.getElementById('dictionarySearchFieldItem_'+dictionaries.dropDown.lastPos)) { document.getElementById('dictionarySearchFieldItem_'+dictionaries.dropDown.lastPos).style.backgroundColor=''; }
  if (dictionaries.dropDown.lastPos < dictionaries.dropDown.maxPos) {
    dictionaries.dropDown.lastPos = parseInt(dictionaries.dropDown.lastPos)+1;
  }
  if (document.getElementById('dictionarySearchFieldItem_'+dictionaries.dropDown.lastPos)) { document.getElementById('dictionarySearchFieldItem_'+dictionaries.dropDown.lastPos).style.backgroundColor='#f1f1f1'; }
//  alert(document.getElementById('dictionarySearchFieldItem_'+dictionaries.dropDown.lastPos).innerHTML);
}

dictionaries.tabs = new Object;


dictionaries.tabs.loadTabs = function(s,ob,tbid,tbtp) {

  if (document.getElementById('dictionary_tabs')) {

    xmlHttp_loadTabs = ajaxObj();

    xmlHttp_loadTabs.onreadystatechange=function() {
      if(xmlHttp_loadTabs.readyState==4) {
        if (xmlHttp_loadTabs.responseText) {
          document.getElementById('dictionary_tabs').innerHTML = xmlHttp_loadTabs.responseText;
        }
      }
    }

    if (!lnk) { t_lnk = ""; } else { t_lnk = lnk; }

    var tbld = '';
    if (document.getElementById('vel_ordabok')) {
      tbld = '&tbld=1';
    }

    xmlHttp_loadTabs.open("GET",t_lnk+"modules/post/dictionary_tabs.php?s="+s+"&o="+ob+"&tbid="+tbid+"&tbtp="+tbtp+tbld,true);
    xmlHttp_loadTabs.send(null);

  }

}


dictionaries.communication = new Object();

dictionaries.communication.validate = function() {

  var el = document.getElementById('dictionaries.communication.select');
  var dd = el.selectedIndex;
  var ss = el[dd].text; 

  owner = '';

  if (document.getElementById('owner_'+el.value)) {
    owner = document.getElementById('owner_'+el.value).value;
  }

  intranet.information.show('Sendir fyrispurning ...');

  if (document.getElementById('dictionaries.communication.name').value == '' || document.getElementById('dictionaries.communication.name').value == 'Navn *') {
    intranet.alert.show('Vinaliga skriva navn títt.');
  } else if (document.getElementById('dictionaries.communication.email').value == '' || document.getElementById('dictionaries.communication.email').value == 'Teldupostbústaður *') {
    intranet.alert.show('Vinaliga skriva tín teldupostbústað.');
  } else if (!document.getElementById('dictionaries.communication.email').value.match(emailFilter)) {
    intranet.alert.show('Teldupostbústaðurin er ikki rætt skrivaður.');
  } else if (document.getElementById('dictionaries.communication.comment').value == '' || document.getElementById('dictionaries.communication.comment').value == 'Vit vilja fegin samskifta við brúkararnar, taka brúkararnar við upp á ráð og bjóða brúkarunum til samstarv og at dagføra bøkurnar *') {
    intranet.alert.show('Vinaliga skriva eina viðmerking.');
  } else {

    xmlHttp_sendComment = ajaxObj();

    xmlHttp_sendComment.onreadystatechange=function() {
      if(xmlHttp_sendComment.readyState==4) {
        if (xmlHttp_sendComment.responseText == "true") {
          intranet.alert.show('Fyrispurningurin er sendur. Takk fyri.');
        } else {
          intranet.alert.show('Fyrispurningurin er ikki sendur. Vinaliga royn aftur.');
        }
      }
    }

    var str = "/modules/post/sendComment.php?name="+document.getElementById('dictionaries.communication.name').value+"&email="+document.getElementById('dictionaries.communication.email').value+"&phone="+document.getElementById('dictionaries.communication.phone').value+"&comment="+document.getElementById('dictionaries.communication.comment').value+"&scode="+el.value+"&stext="+ss+"&owner="+owner;

    xmlHttp_sendComment.open("GET",str,true);
    xmlHttp_sendComment.send(null);

  }

}


dictionaries.communication.checkOwner = function(id) {

  owner = '';

  if (document.getElementById('owner_'+id)) {

    owner = document.getElementById('owner_'+id).value;

  }

    if (owner == 'OBG') {

      document.getElementById('sendtoSprotin').name = 'true';
      document.getElementById('sendtoSprotin').style.cursor = 'default';
      document.getElementById('sendtoSprotin').src = 'images/content/send_hover.png';
      document.getElementById('sendtoSprotin').setAttribute('onclick','');

      document.getElementById('sendtoOBG').name = 'false';
      document.getElementById('sendtoOBG').style.cursor = 'pointer';
      document.getElementById('sendtoOBG').src = 'images/content/send_obg.png';
      document.getElementById('sendtoOBG').setAttribute('onclick','dictionaries.communication.validate();');

    } else {

      document.getElementById('sendtoOBG').name = 'true';
      document.getElementById('sendtoOBG').style.cursor = 'default';
      document.getElementById('sendtoOBG').src = 'images/content/send_obg_hover.png';
      document.getElementById('sendtoOBG').setAttribute('onclick','');

      if (owner == '') {

        document.getElementById('sendtoSprotin').name = 'true';
        document.getElementById('sendtoSprotin').style.cursor = 'default';
        document.getElementById('sendtoSprotin').src = 'images/content/send_hover.png';
        document.getElementById('sendtoSprotin').setAttribute('onclick','');

      } else {

        document.getElementById('sendtoSprotin').name = 'false';
        document.getElementById('sendtoSprotin').style.cursor = 'pointer';
        document.getElementById('sendtoSprotin').src = 'images/content/send.png';
        document.getElementById('sendtoSprotin').setAttribute('onclick','dictionaries.communication.validate();');

      }

  }

}
