var url = "http://www.locatiekiezer.nl/Default.aspx";
var stylesheet = "";
var passdataurl = "http://" + location.hostname + "/passdata.php";
var stylesheet = "http://" + location.hostname + "/style/style.css";
var div_width = 800;
var div_height= 600;

// Show PakjesGemak div
function ShowPakjesGemak(api, productlabel, address)
{
  var location = url +  "?apikey=" + api + 
                        "&productlabel=" + productlabel + 
                        "&stylesheet=" + stylesheet +
                        "&passdataurl=" + passdataurl;
  if (address)
  {
    location += "&address=" + address;
  }                          
  var popup = document.getElementById("divPakjesGemak");
  var left = Math.round(scrollLeft() + (clientWidth() - div_width)/2.0);
  if (left < 0) left = 0;
  popup.style.display = "block";
  popup.style.position = "absolute";
  popup.style.top = scrollTop() + "px";  
  popup.style.left = left + "px";
  popup.style.width = div_width + "px";
  popup.style.height = div_height + "px";  
  popup.innerHTML = "<iframe id='iFramePopup' name='iFramePopup' src='" + location + "' frameborder='0' scrolling='no'></iframe>";
}

function ClosePopup()
                                {
                                                var popup = document.getElementById("divPakjesGemak");
                                                popup.style.display = "none";
                                }

// Some code to cut away the 'locationType' in front of the 'name'. Two approached:
// 1: name starts with locationType. Remove locationType and any consecutive &nbsp; elements.
// 2: skip to right after last &nbsp; element, remove everything before.
function GetLocationName(qs)
{
    var location = qs.get("locationType");        
    var name = qs.get("name");
    if (name.substring(0, location.length) == location && name.length > location.length)
    {
      name = name.substring(location.length, name.length);
      while (name.length > 6 && name.substring(0, 6) == "&nbsp;")
      {
        name = name.substring(6, name.length);
      }
    }
    else
    {
      var lio = name.lastIndexOf("&nbsp;");
      if (lio >= 0)
      {
        name = name.substring(lio + 6, name.length);
      }
    }
    return name;
}



// Some functions to get width, height and scroll position of the current window.
function scrollLeft() {
	return filterResults (
		window.pageXOffset ? window.pageXOffset : 65,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function scrollTop() {
	return filterResults (
		window.pageYOffset ? window.pageYOffset : 250,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function clientWidth() {
	return filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}

function clientHeight() {
	return filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

function filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
