
var noHelp = "vandrestier,cykelstier,ridestier,Friovernatninger,fugletaarne,naturudstillinger,naturskoler,tilgaenglighed,parkering,betalingsfiskerier,frifiskerier"


function swap (id) {
	if (document.getElementById("mSub"+id) && document.getElementById("mSub"+id).style.display != "block") {
		document.getElementById("mSub"+id).style.display = "block";
		document.getElementById("t"+id).className = "Expanded";
		document.getElementById("arrowM"+id).setAttribute("src","images/bullets/arrow_red_expanded.gif");		
	}
	else{		
		document.getElementById("mSub"+id).style.display = "none";
		document.getElementById("t"+id).className = "Collapsed";
		document.getElementById("arrowM"+id).setAttribute("src","images/bullets/arrow_red_collapsed.gif");		
	}
}

var subSwapObj;
function subswap (id) {
	subSwapObj = document.getElementById("s"+id);	

	if (subSwapObj) 
	{
		if (subSwapObj.style.display != "block")
		{
			subSwapObj.style.display = "block";
		}
		else
		{
			subSwapObj.style.display = "none";
		}
	}	
}

var subSwapArrow;
function swapArrow(id)
{
	subSwapArrow = document.getElementById("arrow"+id);
	
	if (subSwapArrow) 
	{
		if (subSwapArrow.getAttribute("src").indexOf("collapsed") > -1)
		{
			subSwapArrow.setAttribute("src","images/bullets/arrow_red_expanded.gif");
		}
		else
		{
			subSwapArrow.setAttribute("src","images/bullets/arrow_red_collapsed.gif");
		}		
	}
}


function setDropdowns(field) {
  if (document.forms["AddForm"].elements[field].selectedIndex == 0) {
    if (field == "county") document.forms["AddForm"].elements["kommune"].disabled = false;
    if (field == "kommune") document.forms["AddForm"].elements["county"].disabled = false;
  } else {
    if (field == "county") document.forms["AddForm"].elements["kommune"].disabled = true;
    if (field == "kommune") document.forms["AddForm"].elements["county"].disabled = true;
  }
}

function clearForm() {
  if (confirm("Er du sikker på at du vil slette alle dine søgekriterier?")) {
    
    for (var i=0; i<70; i++) {
      if (document.getElementById('s'+i)) {
        if (document.getElementById('s'+i).style.display == "block") {
          document.getElementById('s'+i).style.display = "none";
          if (document.getElementById('arrow'+i))
			document.getElementById('arrow'+i).setAttribute("src","images/arrow_red_collapsed.gif");
        }
      }
    }

    for (var i=0; i<70; i++) {
      if (document.getElementById('mSub'+i)) {
        if (document.getElementById('mSub'+i).style.display == "block") {
          document.getElementById('mSub'+i).style.display = "none";
          if (document.getElementById('arrowM'+i))
			document.getElementById('arrowM'+i).setAttribute("src","images/arrow_red_collapsed.gif");
		  if (document.getElementById('t'+i))
			document.getElementById('t'+i).className = "Collapsed";
        }
      }
    }
    
    document.forms["AddForm"].reset();
  }
}

function selectChilds(obj) {
  var d = document;
  var no = new Number(obj.getAttribute("value"));
  var id = new String(no+1);
  var fLen = d.forms["AddForm"].elements["FT"].length;
  var state = false;
  if (obj.checked) state = true;
  if (id.length == 1) id = "0"+id;
  id = "_" + id;  
  
  if (fLen == undefined && d.forms["AddForm"].elements["FT"])
	d.forms["AddForm"].elements["FT"].checked = state;
	    
  for (var i=0; i<fLen; i++) {
    if (d.forms["AddForm"].elements["FT"][i].value.indexOf(id) != -1) {
		d.forms["AddForm"].elements["FT"][i].checked = state;
	}
  }
}

function selectParent(obj,mode) {
  if (mode == "input") var no = obj.value;
  else if (mode == "script") var no = obj;

  var d = document;
  var fLen = d.forms["AddForm"].elements["FT"].length;
  var state = false;
  var isChecked = false;
  
  var cutPos = no.indexOf("_");
  var id = no.substr(cutPos);
  var no = new Number(no.substr(cutPos+1));
    
  for (var i=0; i<fLen; i++) {	
    if (d.forms["AddForm"].elements["FT"][i].value.indexOf(id) != -1) {
      if (d.forms["AddForm"].elements["FT"][i].checked) {
        isChecked = true;
        break;
      }
    }
  }
  
  if (isChecked) state = true;
       
  if (fLen == undefined && d.forms["AddForm"].elements["FT"])
	d.forms["AddForm"].elements["d"+(no-1)].checked = d.forms["AddForm"].elements["FT"].checked;
  else  
    d.forms["AddForm"].elements["d"+(no-1)].checked = state;    
}

function selectChildParent(obj,id) {
  var d = document.AddForm;
  var ftLen = d.FT.length;
  var id = id;
  var pId;
  var group = obj.name;
  var isActive = false;
  var state = false;

  var cutPos = group.indexOf("_");
  group = group.substr(0,cutPos+1);

  if (obj.type == "text") {
    if (obj.value.length == 1) {
      for (var i=0; i<ftLen; i++) {
        if (d.FT[i].value == id) {
          d.FT[i].checked = true;
          break;
        }
      }
    } else if (obj.value.length == 0) {
      isActive = checkChilds(group);
      if (isActive) state = true;
      for (var i=0; i<ftLen; i++) {
        if (d.FT[i].value == id) {
          d.FT[i].checked = state;
          break;
        }
      }
    }
    selectParent(id,'script');
  } else if (obj.type == "checkbox") {
    if (obj.checked) {
      for (var i=0; i<ftLen; i++) {
        if (d.FT[i].value == id) {
          d.FT[i].checked = true;
          break;
        }
      }
    } else {
      isActive = checkChilds(group);
      if (isActive) state = true;
      for (var i=0; i<ftLen; i++) {
        if (d.FT[i].value == id) {
          d.FT[i].checked = state;
          break;
        }
      }
    }
    selectParent(id,'script');
  }
}

function checkChilds(group) {
  var d = document.AddForm;
  var fLen = d.length;

  for (var i=0; i<fLen; i++) {
    if (d.elements[i].name.indexOf(group) != -1) {
      if (d.elements[i].type == "text") {
        if (d.elements[i].value.length > 0) {
          return(true);
          break;
        }
      } else if (d.elements[i].type == "checkbox") {
        if (d.elements[i].checked) {
          return(true);
          break;
        }
      }
    }
  }
  return(false);
}


function doHand(e) {
  if (e) e = e.target;
  else e = window.event.srcElement;

  if (getTagName(e) != "img") return;

  if (getTagName(e) == "img") {
    if (e.src.indexOf("/icons/") != -1) {
      if (e.getAttribute("noHelp")) return;
      cutPos = e.src.lastIndexOf("/");
      topic = e.src.substr(cutPos+1);
      cutPos = topic.indexOf(".gif");
      topic = topic.substr(0,cutPos);
      noHelpArr = noHelp.split(",");
      noHelpArrLen = noHelpArr.length;
      for (var i=0; i<noHelpArrLen; i++) {
        if (noHelpArr[i].toLowerCase() == topic.toLowerCase()) {
          e.style.cursor = "default";
          return;
          break;
        }
      }
      e.style.cursor = "hand";
      return;
    }
  }
}

function doHelp(e) {
  if (e) e = e.target;
  else e = window.event.srcElement;

  if (getTagName(e) != "img") return;

  if (getTagName(e) == "img") {
    if (e.src.indexOf("/icons/") != -1) {
      if (e.getAttribute("noHelp")) return;
      cutPos = e.src.lastIndexOf("/");
      topic = e.src.substr(cutPos+1);
      cutPos = topic.indexOf(".gif");
      topic = topic.substr(0,cutPos);
      noHelpArr = noHelp.split(",");
      noHelpArrLen = noHelpArr.length;
      for (var i=0; i<noHelpArrLen; i++) {
        if (noHelpArr[i].toLowerCase() == topic.toLowerCase()) {
          return;
          break;
        }
      }
      e.style.cursor = "hand";
      window.open("help.asp?topic="+topic,"help","toolbar=0,resizable=0,directories=0,status=0,menubar=0,scrollbars=1,location=0,width=250,height=300");
      return;
    }
  }
}

function doSkovkort() {
  window.open("skovkort.asp","skovkort","toolbar=0,resizable=0,directories=0,status=0,menubar=0,scrollbars=1,location=0,width=640,height=480");
}

function doSignatur() {
  window.open("grundkort.asp","grundkort","toolbar=0,resizable=0,directories=0,status=0,menubar=0,scrollbars=1,location=0,width=640,height=480");
}


function bigImg(imageName) {
    var s = "?image=" + imageName
  window.open("display_image.asp"+s,"imageviewer","toolbar=0,resizable=1,directories=0,status=0,menubar=0,scrollbars=1,location=0");
}

function ScrollMap(x,y) {
  document.mapForm.dynX.value = x;
  document.mapForm.dynY.value = y;
  document.mapForm.submit();
}

var nIE4Win;
var nCanPrint;
var printed;

function doPrint() {
  printed = "no";
  if (window.print) {
    nCanPrint = "yes";
  } else {
    nCanPrint = "no";
  }

  var agt=navigator.userAgent.toLowerCase()

  nVersion = parseInt(navigator.appVersion);
  nIE  = (agt.indexOf("msie") != -1);
  nWin   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
  nMac = (agt.indexOf("mac") != -1);
  nIE4Win  = (nIE && (nVersion == 4) && nWin);
  doPrintIt();
}

function doPrintIt() {
  if (nCanPrint == "yes") {
    printed="yes";
    window.print();

  } else if (nIE4Win) {
    printed="yes";
    //IEPrint();
  }
}

function insertEmailLink(address,text) {
	document.write("<a href=\"mailto:"+address+"\">"+text+"</a>");
}

function openWin(URL, height, width) {
	window.open(URL,height+width,"height="+height+",width="+width);
}

var cTimeout;
var cObj;
function cMouseOver ( id )
{
	if ( cObj && ( cObj == document.getElementById("mo_"+id) ) )
		window.clearTimeout(cTimeout);
	else
	{
		if ( cObj )
			cObj.style.display = 'none';	
		cObj = document.getElementById("mo_"+id);
		window.clearTimeout(cTimeout);
	}
	
	if ( cObj )
		cObj.style.display = 'block';
}

function cMouseOut()
{
	if ( cObj )
	{
		cTimeout = window.setTimeout("cObj.style.display = 'none';",50);
	}		
}


function cMouseMove( evt )
{
	x = evt.pageX ? evt.pageX : (evt.clientX + document.body.scrollLeft);
	y = evt.pageY ? evt.pageY : (evt.clientY + document.body.scrollTop);
	
	if ( cObj )
	{			
		cObj.style.left = x + 10;
		cObj.style.top = y;
	}
}

var newStyle;
function toggleBox ( id )
{
	cObj = document.getElementById("mo_"+id);
		
	if ( cObj )
	{
		if ( cObj.currentStyle )
		{
			cObj.currentStyle.display == 'none' ? newStyle = 'block' : newStyle = 'none';
		}
		else if ( window.getComputedStyle )
		{			
			var cObjStyle = window.getComputedStyle(cObj, "");						
			cObjStyle.getPropertyValue("display") == 'none' ? newStyle = 'block' : newStyle = 'none';
		}
		
		cObj.style.display = newStyle;		
		swapArrow( id );
		
	}
		
	cObj = null;
}
			
