// Generate map reference
function viewMap (street, city) {
   var no = '';
   var n = street.lastIndexOf(' ');
   tit = 'Kart for adressen ' + street + ', ' + city;
   if (n > 0 && street.charAt(n+1) >= '1' && street.charAt(n+1) <= '9') {
      no = "&no=" + street.substring(n+1);
      street = street.substring (0, n);
      }
   url = "http://www.finn.no/finn/map?street=" + street.replace(/ /g, "+") + no + "&zipcode=" + city.substr(0,4);
   document.write ('<A CLASS=kart TITLE="' + tit + '" HREF="' + url + '"><IMG ALT="" BORDER=0 SRC="/grafikk/kart.gif"></A>');
   } // viewMap

function viewMapXY (x, y, tit) {
   url = "http://www.finn.no/finn/map?utmx=" + x + "&utmy=" + y + "&title=" + tit;
   document.write ('<A CLASS=kart TITLE="' + tit + '" HREF="' + url + '"><IMG ALT="" SRC="/grafikk/kart.gif"></A>');
   } // viewMapXY


// E-mail address de-obfuscator, adapted from <http://lojjic.net/blog/20030828-142754.rdf.html>
function fixEml() {
   if(!document.getElementsByTagName) return;
   var allElts = document.getElementsByTagName("a");
   if(allElts.length == 0 && document.all) allElts = document.all; //hack for IE5

   // walk thru all elements of the document, check for class=eml
   for(var i=0; i<allElts.length; i++) {
      var elt = allElts[i];
      var className = elt.className || elt.getAttribute("class") || elt.getAttribute("className");
      if (!className || !className.match(/\beml\b/)) continue;
      var chd = elt.firstChild;
      if (!chd || chd.nodeType != 3) continue;
      addr = chd.nodeValue;
      addr = addr.replace(/[ \[\{\(\|\/\\]at[ \]\}\)\|\/\\]/i, "@")
                 .replace(/[ \[\{\(\|\/\\]dot[ \]\}\)\|\/\\]/gi, ".");
      elt.setAttribute("href","mailto:"+addr);

      if (elt.childNodes.length == 1)
         elt.replaceChild(document.createTextNode(addr), chd);
      else
         elt.removeChild(chd);
      } // for all <A CLASS=eml ...> elements
   } // fixEml()

window.onload = fixEml;
