﻿/* Title: navigation.js*/
//Copyright (c) 2007 Norstedts Juridik AB. All right reserved.
var listValues = new Array();
/*------------------------------------------------------------
   Function: getAnchorElementFromDocument
   Propub
--------------------------------------------------------------    
  Revision History: 
------------------------------------------------------------*/  
function getAnchorElementFromDocument(id, document)
{
	if (document.getElementById)
	{
		return document.getElementsByTagName('a')[id];
	}
	else if (document.all)
	{
		return document.all[id];
	}
	else
	{
		return null;
	}
}

/*------------------------------------------------------------
   Function: populate
   ESP
--------------------------------------------------------------    
  Revision History: 
  - NEW 2006-12-15 tlin2: Initial version. 

------------------------------------------------------------*/  
function populate(elementName, arrayNumber)
{
	var box = eval('document.forms[0].' + elementName);
	var list = listValues[arrayNumber];
	var listText;
	box.options.length = 0;
	for(i=0;i<list.length;i+=2)
	{
		listText = eval('unescape(escape(list[i]))');
		box.options[i/2] = new Option(listText,list[i+1]);
	}
}
/*------------------------------------------------------------
   Function: navigate
   ESP
--------------------------------------------------------------    
  Revision History: 
  - NEW 2006-12-15 tlin2: Initial version. 

------------------------------------------------------------*/ 
function navigate(breadcrumbs, newDrill) {
    var breadcrumbsElement = byId("search_form_breadcrumbs");
    if (typeof submitSearch == "function" && breadcrumbsElement && applyCurrentSimilarity()) {
        breadcrumbsElement.value = breadcrumbs + newDrill;
        submitSearch();
    }
}

/*------------------------------------------------------------
   Function: toggleMore
   ESP
--------------------------------------------------------------    
  Revision History: 
  - NEW 2006-12-15 tlin2: Initial version. 
------------------------------------------------------------*/ 
function toggleMore(id, linkId, more, less) {
    var div = byId(id);
    var link = byId(linkId);
    if (div) {
        if (div.style.display == "none") {
            div.style.display = "block";
            if (link) {
                link.innerHTML = less;
            }
        } else {
            div.style.display = "none";
            if (link) {
                link.innerHTML = more;
            }
        }
    }
}
/*------------------------------------------------------------
   Function: toggleNavigator
   Used to show or hide the navigators
   
   Arguments:
   navigatorId - Div name of the navigator
--------------------------------------------------------------    
  Revision History: 
  - NEW 2006-12-15 tlin2: Initial version. 
------------------------------------------------------------*/ 
function toggleNavigator(navigatorId) {
    toggleByClass(navigatorId, "navigatorOpen", "navigatorClosed");
}

/*------------------------------------------------------------
   Function: toggleCluster
   ESP
--------------------------------------------------------------    
  Revision History: 
  - NEW 2006-12-15 tlin2: Initial version. 

------------------------------------------------------------*/
function toggleCluster(clusterId) {
    toggleByClass(clusterId, "clustersOpen", "clustersClosed");
}
/*------------------------------------------------------------
   Function: hideAll
   Hide all subdivs in the advanced search that depends of the
   upper listbox
--------------------------------------------------------------    
  Revision History: 
  - NEW 2006-12-15 tlin2: Initial version. 

------------------------------------------------------------*/ 
function hideAll() {
	if(getSystemVar('country')=="dk") {
		changeByClass('infotype1', "simpleClosed");
		changeByClass('infotype2', "simpleClosed");
		changeByClass('infotype3', "simpleClosed");
		changeByClass('infotype4', "simpleClosed");
		changeByClass('infotype5', "simpleClosed");
		changeByClass('infotype6', "simpleClosed");
		changeByClass('infotype7', "simpleClosed");
		changeByClass('infotype8', "simpleClosed");
		changeByClass('infotype9', "simpleClosed");
		changeByClass('infotype10', "simpleClosed");
	} else {
		changeByClass('forfattningar', "simpleClosed");
		changeByClass('avgoranden', "simpleClosed");
		changeByClass('forarbeten', "simpleClosed");
		changeByClass('lagkommentarer', "simpleClosed");
		changeByClass('myndighetspublikationer', "simpleClosed");
		changeByClass('artiklar', "simpleClosed");
		changeByClass('eu', "simpleClosed");
	}
	
	changeByClass('ovrigt', "simpleClosed");
}
/*------------------------------------------------------------
   Function: showHideAdvMoreChoice
   Hide or show more options in the advanced search
--------------------------------------------------------------    
  Revision History:
  - UPD 2007-06-01 tlin2: More choices is up and kicking again 
  - UPD 2007-05-30 tlin2: More choices removed
  - NEW 2007-05-18 tlin2: Initial version. 
------------------------------------------------------------*/ 
function showHideAdvMoreChoice() {
  isChecked= true;
  if (document.forms[0].moreChoice.checked == false) isChecked= false;
  if(isChecked==true) {
    changeByClass('morechoiceDiv','simpleOpen');
    changeByClass('moreText','simpleOpen');
  }else {
    changeByClass('morechoiceDiv','simpleClosed');
    changeByClass('moreText','simpleClosed');
  }
}
/*------------------------------------------------------------
   Function: showHideAdvMoreRadio
   Hide or show more options in the advanced search
--------------------------------------------------------------    
  Revision History: 
  - NEW 2007-05-18 tlin2: Initial version. 
------------------------------------------------------------*/ 
function showHideAdvMoreRadio() {
	//alert(document.forms[0].moreRadio[0].checked + " " +document.forms[0].moreRadio[1].checked + " " +document.forms[0].moreRadio[2].checked + " " +document.forms[0].moreRadio[3].checked );
  try {
    if (document.forms[0].moreRadio[0].checked == true || document.forms[0].moreRadio[2].checked == true) {
      changeByClass('moreRadioDiv','simpleClosed');
      changeByClass('moreText','simpleClosed');
    }else {
      changeByClass('moreRadioDiv','simpleOpen');
      changeByClass('moreText','simpleOpen');
    }
  } catch(ex) {
  }
}
/*------------------------------------------------------------
   Function: hideAllAvgSub
   Hide all subdivs in the advanced search that depends of the
   avgorandenSource listbox
--------------------------------------------------------------    
  Revision History: 
  - NEW 2006-12-15 tlin2: Initial version. 

------------------------------------------------------------*/ 
function hideAllAvgSub() {
	changeByClass('avgSourceOptTitle', "simpleClosed");
	changeByClass('avgTargetType1', "simpleClosed");
	changeByClass('avgTargetTypeTitle1', "simpleClosed");
	changeByClass('avgTargetType3', "simpleClosed");
	changeByClass('avgTargetTypeTitle3', "simpleClosed"); 
	changeByClass('avgSourceOpt1Sub', "simpleClosed");
	changeByClass('avgSourceOpt2Sub', "simpleClosed");
	changeByClass('avgSourceOpt3Sub', "simpleClosed");
	changeByClass('avgSourceOpt2SubTitle', "simpleClosed");
	changeByClass('avgSourceOpt3Sub2Sub', "simpleClosed");
	changeByClass('avgSourceOpt3Sub2SubTitle', "simpleClosed");
	changeByClass('avgSourceOpt4Sub', "simpleClosed");
	changeByClass('avgSourceOpt4Sub2Sub', "simpleClosed");
	changeByClass('avgSourceOpt4Sub2SubTitle', "simpleClosed");
	changeByClass('avgSourceOpt5Sub', "simpleClosed");
	changeByClass('avgSourceOpt6Sub', "simpleClosed");
	changeByClass('avgSourceOpt6SubTitle', "simpleClosed");
	changeByClass('avgSourceOpt7Sub', "simpleClosed");
	changeByClass('avgSourceOpt8Sub', "simpleClosed");
	changeByClass('avgSourceOpt9Sub', "simpleClosed");
	changeByClass('avgSourceOpt10Sub', "simpleClosed");
	changeByClass('avgSourceOpt11Sub', "simpleClosed");
	changeByClass('avgTargetType', "simpleClosed");
	changeByClass('avgTargetTypeTitle', "simpleClosed");
	changeByClass('mynSourceOpt2Title', "simpleClosed");
}
/*------------------------------------------------------------
   Function: toggleMynSearch
   Used to show things in the advanced search when the user
   has selected something in the avgorandenSource listbox
   
   Arguments:
   navigatorId - Div name
--------------------------------------------------------------    
  Revision History: 
  - NEW 2006-12-15 tlin2: Initial version. 
  
------------------------------------------------------------*/ 
function toggleMynSearch(nr) {
    hideAllMynSub();
 /*
    if(nr == "2") {
    	changeByClass('mynSourceOpt2', "simpleOpen");
    	changeByClass('mynSourceOpt2Title', "simpleOpen");
    } 
 */
    if (nr == "6"){
    	changeByClass('mynSourceOpt6', "simpleOpen");
    	changeByClass('mynSourceOpt6Title', "simpleOpen");
    }
}
/*------------------------------------------------------------
   Function: hideAllMynSub
   Hide all subdivs in the advanced search that depends of the
   myndigheter listbox
--------------------------------------------------------------    
  Revision History: 
  - NEW 2006-12-15 tlin2: Initial version. 

------------------------------------------------------------*/ 
function hideAllMynSub() {
	changeByClass('mynSourceOpt2', "simpleClosed");
   changeByClass('mynSourceOpt2Title', "simpleClosed");
   changeByClass('mynSourceOpt6', "simpleClosed");
   changeByClass('mynSourceOpt6Title', "simpleClosed");
}
/*------------------------------------------------------------
   Function: changeByClass
   Change class on a div
   
   Arguments:
   elementId - Div name
   className - The new class
--------------------------------------------------------------    
   Revision History: 
  - NEW 2006-12-15 tlin2: Initial version. 

------------------------------------------------------------*/ 
function changeByClass(elementId, className) {
	
    var element = byId(elementId);
    if (element) {
        element.className = className;
    }  
}
	
/*------------------------------------------------------------
   Function: toggleAvgOpt3AdvSearch
   Used to show things in the advanced search when the user
   has selected something in the listbox
   
   Arguments:
   nr - what number that should generate a div to be visible
--------------------------------------------------------------    
  Revision History: 
  - NEW 2006-12-15 tlin2: Initial version. 
------------------------------------------------------------*/ 
function toggleAvgOpt3AdvSearch(nr) {
    if(nr == "2") {
    	changeByClass('avgSourceOpt3Sub2Sub', "simpleOpen");
    	changeByClass('avgSourceOpt3Sub2SubTitle', "simpleOpen");
    } else {
    	changeByClass('avgSourceOpt3Sub2Sub', "simpleClosed");
    	changeByClass('avgSourceOpt3Sub2SubTitle', "simpleClosed");
    }
}
	
/*------------------------------------------------------------
   Function: toggleAvgOpt4AdvSearch
   Used to show things in the advanced search when the user
   has selected something in the listbox
   
   Arguments:
   nr - what number that should generate a div to be visible
--------------------------------------------------------------    
  Revision History: 
  - NEW 2006-12-15 tlin2: Initial version. 
------------------------------------------------------------*/ 
function toggleAvgOpt4AdvSearch(nr) {
	
    if(nr == "2") {
    	changeByClass('avgSourceOpt4Sub2Sub', "simpleOpen");
    	changeByClass('avgSourceOpt4Sub2SubTitle', "simpleOpen");
    } else {
    	changeByClass('avgSourceOpt4Sub2Sub', "simpleClosed");
    	changeByClass('avgSourceOpt4Sub2SubTitle', "simpleClosed");
    }
}
/*------------------------------------------------------------
   Function: toggleAvgAdvSearch
   Used to show things in the advanced search when the user
   has selected something in the avgorandenSource listbox
   
   Arguments:
   navigatorId - Div name
--------------------------------------------------------------    
  Revision History: 
  - NEW 2006-12-15 tlin2: Initial version. 
------------------------------------------------------------*/ 
function toggleAvgAdvSearch(nr) {
	hideAllAvgSub();
	var navigatorId = 'avgSourceOpt' + nr + 'Sub';
	if(nr > 4) return;
	//if(nr==2 || nr==4) {
	if(nr==2) {		
		changeByClass(navigatorId,"simpleOpen");
		changeByClass('avgSourceOptTitle','simpleOpen');
	}
	if(nr == 1) {   		
		changeByClass("avgTargetType1", "simpleOpen");
		changeByClass('avgTargetTypeTitle1', "simpleOpen");
	} else if(nr == 3) {   		
		changeByClass("avgTargetType3", "simpleOpen");
		changeByClass('avgTargetTypeTitle3', "simpleOpen");
	}
}
/*------------------------------------------------------------
   Function: toggleMynSearch
   Used to show things in the advanced search when the user
   has selected something in the avgorandenSource listbox
   
   Arguments:
   navigatorId - Div name
--------------------------------------------------------------    
  Revision History: 
  - NEW 2006-12-15 tlin2: Initial version. 
  
------------------------------------------------------------*/ 
function toggleMynSearch(nr) {
    hideAllMynSub();
    /*
    if(nr == "2") {
    	changeByClass('mynSourceOpt2', "simpleOpen");
    	changeByClass('mynSourceOpt2Title', "simpleOpen");
    } 
    */
    if (nr == "6"){
    	changeByClass('mynSourceOpt6', "simpleOpen");
    	changeByClass('mynSourceOpt6Title', "simpleOpen");
    }
}
/*------------------------------------------------------------
   Function: toggleAdvSearch
   Used to show things in the advanced search
   
   Arguments:
   navigatorId - Div name
--------------------------------------------------------------    
  Revision History: 
  - NEW 2006-12-15 tlin2: Initial version. 

------------------------------------------------------------*/ 
function toggleAdvSearch(navigatorId) {

    hideAll();
    if(getSystemVar('country')!="dk") { 
    	hideAllAvgSub();
    	hideAllMynSub();
    }
    navigatorId = navigatorId.split(" ")[0];
   
    switch(navigatorId) {
		case forfattningar: 
			navigatorId = "forfattningar";
			break;
		case avgoranden: 
		case 'Avgöranden':
			navigatorId = "avgoranden";
			break;
		case forarbeten : 
			navigatorId = "forarbeten";
			break;
		case lagkommentarer.split(" ")[0]: 
			navigatorId = "lagkommentarer";
			return;
			break;
		case myndighetspublikationer: 
			navigatorId = "myndighetspublikationer";
			break;
		case artiklar: 
			navigatorId = "artiklar";
			break;
		case eu: 
			navigatorId = "eu";
			break;																		
		case ovrigt: 
			navigatorId = "ovrigt";
			break;	
    
	}
    toggleByClass(navigatorId, "simpleOpen", "simpleClosed");
}

/*------------------------------------------------------------
   Function: toggleFieldSearch
   Used to hide things in the advanced search
   
   Arguments:
   navigatorId - Div name of the navigator
--------------------------------------------------------------    
  Revision History: 
  - NEW 2006-12-15 tlin2: Initial version. 

------------------------------------------------------------*/ 
function toggleFieldSearch(selector, navigatorId) {
	clearErrorMsg();
	$('.fieldSearchContainer').each(function(index) {
		$(this).addClass('fieldSearchClosed');
		$(this).addClass('simpleClosed');
		$(this).removeClass('fieldSearchOpen');
	});
	$("#"+ navigatorId).removeClass("fieldSearchClosed");
	$("#"+ navigatorId).addClass("fieldSearchOpen");
	/*
	"fieldSearchOpen", "fieldSearchClosed");
	var lastFieldSearch = getCookie('lastFieldSearch');

    if(navigatorId=="#") {
      selector.value = lastFieldSearch;
    	return true;
    }
    else {
      if(lastFieldSearch == null) changeByClass("forfa1", "simpleClosed");
      if(lastFieldSearch != "") {
      	if(navigatorId != lastFieldSearch) {
  	    	changeByClass(lastFieldSearch, "simpleClosed")
      	}
      }
      setCookie('lastFieldSearch',navigatorId);
    	changeByClass(navigatorId, "simpleClosed")
      toggleByClass(navigatorId, "fieldSearchOpen", "fieldSearchClosed");
    }
	*/
}

/*------------------------------------------------------------
   Function: toggleByClass
   Change class on a specific div
   
   Arguments:
   elementId - Div name to change
   openClass - From class
   closedClass - To class
--------------------------------------------------------------    
  Revision History: 
  - NEW 2006-12-15 tlin2: Initial version. 
------------------------------------------------------------*/ 
function toggleByClass(elementId, openClass, closedClass) {
    var element = byId(elementId);
    
    if (element) {
        element.className = element.className == openClass ? closedClass : openClass;
   }
}
/*------------------------------------------------------------
   Function: toggleByClass
   Change text on a specific id
   
   Arguments:
   elementId - Div name to change
   text1 - first text
   text2 - second text
--------------------------------------------------------------    
  Revision History: 
  - NEW 2009-05-27 tlin2: Initial version. 
------------------------------------------------------------*/ 
function toggleTextById(elementId, text1, text2) {
    var element = byId(elementId);
    if (element) {
      //debug("element.innerHTML="+element.innerHTML);
      element.innerHTML = element.innerHTML.indexOf(text1) > -1 ? text2 : text1;
   } 
}

