
function openPage(url, width, height, target, posx, posy) {
  // Åbner et nyt vindue hvor
  // url = adressen på siden der skal åbnes
  // target = navn på vinduet
  // width,height = størrelsen af vinduet
  if (target == null || target == '') {
    return;
  }
  if (width == null || width == '') {
    width = 640;
  }
  if (height == null || height == '') {
    height = 480;
  }
  var Win = window.open(url, target, 'width=' + width + ',height=' + height + ',resizable=no,scrollbars=yes,menubar=no,status=no');
  if (posx != null && posy != null) {
    Win.moveTo(posx, posy);
  }
}

/* cross-browser add event handler*/
function addEvent(elm, evType, fn, useCapture) {
  if (elm.addEventListener) {
    elm.addEventListener(evType, fn, useCapture);
    return true;
  }
  else if (elm.attachEvent) {
    var r = elm.attachEvent('on' + evType, fn);
    return r;
  }
  else {
    elm['on' + evType] = fn;
  }
}
// MouseOver CourseStatus
function mover(obj, link, event)
{
  var lCS = document.getElementById("coursestatus");
  if (lCS != null)
  {
    var coord = findPos(obj);
    lCS.style.display = "block";
    var lY = (coord[1] - 185);
    if (lY < 0) lY = 0;
    lCS.style.top = lY + 'px';
    lCS.innerHTML = "<iframe src='" + link + "' frameborder='0'></iframe>";
  }
}

// MouseOut CourseStatus
function mout()
{
  var lCS = document.getElementById("coursestatus");
  if (lCS != null)
  {
    lCS.style.display = "none";
  }
}

// Find obj's real position
function findPos(obj)
{
  var curleft = curtop = 0;
  if (obj.offsetParent)
  {
    do
    {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
    return [curleft, curtop];
  }
}

function getScrollXY()
{
  var scrOfX = 0, scrOfY = 0;
  if (typeof (window.pageYOffset) == 'number')
  {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if (document.body && (document.body.scrollLeft || document.body.scrollTop))
  {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
  {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [scrOfX, scrOfY];
}

function getWindowSize()
{
  var myWidth = 0, myHeight = 0;
  if (typeof (window.innerWidth) == 'number')
  {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
  {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if (document.body && (document.body.clientWidth || document.body.clientHeight))
  {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth, myHeight];
}





function setupGoogleCode() {
  try {
    var pageTracker = _gat._getTracker("UA-293663-1");
    pageTracker._trackPageview();
    setupGoogleCustomSeachControl();
    setupGoogleMapControl();
  }
  catch (err) { 
  }
}

function setupGoogleCustomSeachControl() {
  var cse = document.getElementById('cse');
  if (cse != null) {
    google.load('search', '1');
    google.setOnLoadCallback(function() {
      new google.search.CustomSearchControl().draw('cse');
    });
  }
}

var Lat = null;
var Lng = null;
var Zoom = null;
var gmc = null;
var Info = null;

function setupGoogleMapControl() {
  gmc = document.getElementById('gmc');
  if (gmc != null) {
    var lValue = gmc.firstChild.nodeValue;
    if (lValue != null) {
      var lSplit = lValue.split(",");
      if (lSplit != null && lSplit.length == 3) {
        Lat = lSplit[0];
        Lng = lSplit[1];
        Zoom = Number(lSplit[2]);
        if (gmc.childNodes.length >= 2) {
          Info = gmc.childNodes[1].innerHTML;
        }        
        google.load('maps', '2', { "other_params": "sensor=false" });
        google.setOnLoadCallback(DrawMap);
        addEvent(window, 'unload', GoogleUnload, false);
      }
    }
  }
}

function GoogleUnload() {
  google.maps.Unload();
}

function DrawMap() {
  if (gmc != null && google.maps.BrowserIsCompatible()) {
    gmc.style.display = "block";
    var map = new google.maps.Map2(gmc);
    var lLatLng = new google.maps.LatLng(Lat, Lng);
    map.setCenter(lLatLng, Zoom);
    var lMarker = new google.maps.Marker(lLatLng);
    map.addOverlay(lMarker);
    if (Info != null) {
      lMarker.openInfoWindowHtml(Info);
    }    
    map.addControl(new google.maps.LargeMapControl());
    map.addControl(new google.maps.MapTypeControl());
  }
}



