// JavaScript Document
function popUp(url,width,height){

    attrib = 'width=' + width + ',height='+ height+ ',top=10,left=10,scrollbars=yes';
    popwindow = window.open(url,'PopUp',attrib);
}

function actionOnload(e) {
	if (!document.getElementById) {
		alert("Uw browser ondersteund geen geavanceerde Javascript functies, waardoor bepaalde onderdelen van deze website niet goed zullen functioneren. Download de meest recente versie van Internet Explorer of Firefox voor een optimale presentatie van deze website.");
		return;
	}
	boxReset("Vuluwemailadresin");
	boxReset("zoek");
	boxReset("zoekHylo");
	initPCS();
	initLtTool();
	writeDetails();
	galleryInit();
	addListeners();
}

//
// FOR SEARCH RESULTS: DETAILS ON/OFF
//

var largeBox = "";

function writeDetails()
{

  var myID = new Array();
  var x = 0;
  var myData = "<p><a href=\"javascript:void(0);\" onclick=\"javascript:details(this);\">details</a> <a href=\"javascript:void(0);\" onclick=\"javascript:details(this);\"><img src=\"/static/npl/img/plus-sign.gif\" alt=\"Details\" class=\"zoekDetails\" /></a></p>";

  if (document.getElementById("zoekresultaten")) {
  for(i=0;i<document.getElementById("zoekresultaten").getElementsByTagName("div").length;i++)
  {
    if (document.getElementById("zoekresultaten").getElementsByTagName("div")[i].className.indexOf("searchNoDetail") != -1)
    {
      document.getElementById("zoekresultaten").getElementsByTagName("div")[i].getElementsByTagName("div")[1].innerHTML = myData;
    }
  }
  }
}

function details(obj)
{

  myObj = obj.parentNode.parentNode.parentNode;

  smallStyle = (myObj.className.substring(0,4) != "faq_" ) ? "searchNoDetail" : "faq_searchNoDetail";
  largeStyle = (myObj.className.substring(0,4) != "faq_" ) ? "searchDetail" : "faq_searchDetail";

  if (myObj.id != largeBox)
  {

    if (largeBox != "")
    {
      document.getElementById(largeBox).className = smallStyle;
      myObj.getElementsByTagName("img")[0].src = "/static/npl/img/plus-sign.gif";
    }

    myObj.className = largeStyle;
    myObj.getElementsByTagName("img")[0].src = "/static/npl/img/minus-sign.gif";

    largeBox = myObj.id;

  }
  else
  {

    myObj.className = smallStyle;
    myObj.getElementsByTagName("img")[0].src = "/static/npl/img/plus-sign.gif";

    largeBox = "";

  }

}

//
// TOOLTIPS ON (?) FIELDS...
//
// tooltip(this,'Here goes <b>layouted</b> tooltip text...')

function tooltip(obj,txt)
{
  txt = (typeof txt == 'undefined') ? obj.title : txt;

  // alert( obj.id );

  myPosition = findPos(obj);
  myTooltip = document.getElementById('spmTooltip');

  myTooltip.getElementsByTagName("div")[0].innerHTML = txt;
  myTooltip.style.left = (myPosition[0] - 38)+"px";
  myTooltip.style.top = (myPosition[1] - 91)+"px";
  myTooltip.style.visibility = "visible";

}

function tooltipHide()
{
  document.getElementById('spmTooltip').style.visibility = "hidden";
}

function ttpKeepAlive(obj)
{
  document.getElementById(obj.id).style.visibility = "visible";
}

function ttpHide(obj)
{
  document.getElementById(obj.id).style.visibility = "hidden";
}


//
// Initialize large looltips for list of lots...
//

function initLtTool()
{
  var myRow = new Array();
  var x = 0;
  if (document.getElementById("lotsList")) {
  for(i=0;i<document.getElementById("lotsList").getElementsByTagName("table").length;i++)
  {
    for(j=0;j<document.getElementById("lotsList").getElementsByTagName("table")[i].getElementsByTagName("tr").length;j++)
    {
      myRow[x] = document.getElementById("lotsList").getElementsByTagName("table")[i].getElementsByTagName("tr")[j];
      x++;
    }
  }

  for(i=0;i<myRow.length;i++)
  {
    link = myRow[i].getElementsByTagName("a")[0];
    myTxt = myRow[i].getElementsByTagName("a")[0].innerHTML;
    myRow[i].getElementsByTagName("td")[1].innerHTML = myTxt;

    if (document.addEventListener)
    {
      // REGISTERING THE EVENTS FOR DOM COMPLIANT BROWSERS
      myRow[i].addEventListener("mouseover",ltTool,false);
      myRow[i].addEventListener("mouseout",ltTool,false);
    }
    else
    {
      // REGISTERING THE EVENTS FOR IE
      window.event.cancelBubble = true;
      myRow[i].attachEvent("onmouseover",ltTool);
      myRow[i].attachEvent("onmouseout",ltTool);
    }

  }
  }
}



//
// Large ToolTips for the list of lots
//

function ltTool(e)
{
  myObj = (!window.event) ? e.target.parentNode:window.event.srcElement.parentNode;
  // For the cells with strong fonts (event is triggered inside the <strong> tag)
  if (myObj.tagName != "TR")
  {
    myObj = myObj.parentNode;
  }

  var myStyleC = new Array();
  myCells = myObj.getElementsByTagName("td");

  myMethod = (myCells[0].className.lastIndexOf('_norm') != -1) ? "on" : "off";
  myStyleC[0] = myCells[0].className.substring(0,myCells[0].className.indexOf('_'));
  myStyleC[1] = myCells[1].className.substring(0,myCells[1].className.indexOf('_'));
  myPosition = findPos(myObj);
  myTooltip = document.getElementById('ltTooltip');
  myLot = myObj.id.substring(1,myObj.id.length);

  /*
  HERE WE CALL THE FUNCTION THAT WRITES THE NEW DIV...
  */
  if (link.indexOf('?')>0) {
  	writeTooltip(link+"&inlinehtml=true")
  } else {
  	writeTooltip(link+"/inlinehtml=true")
  }

  switch (myMethod)
  {
    case "on":
    myCells[0].className = myStyleC[0] + "_over";
    myCells[1].className = myStyleC[1] + "_over";
    myTooltip.style.visibility = "visible";
    break;

    case "off":
    myCells[0].className = myStyleC[0] + "_norm";
    myCells[1].className = myStyleC[1] + "_norm";
    myTooltip.style.visibility = "hidden";
    break;
  }

  myTooltip.style.left = (myPosition[0] + 150) + "px";
  myTooltip.style.top = (myPosition[1] - 37) + "px";

}


var xmlHttpRef = null;

function writeTooltip(lot)
{
  if( xmlHttpRef != null ) {
    if( xmlHttpRef.readyState != 4 ) {
      xmlHttpRef.abort();
    }
  }

  var myTooltipScript = lot;

  var xmlHttp = null;
  // Mozilla, Opera, Safari and Internet Explorer 7
  if (typeof XMLHttpRequest != 'undefined') {
      xmlHttp = new XMLHttpRequest();
  }
  if (!xmlHttp)
  {
    // IEs<7
    try
    {
      xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
      try
      {
	xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e)
      {
	xmlHttp  = null;
      }
    }
  }
  if (xmlHttp)
  {
    xmlHttpRef = xmlHttp;
    xmlHttp.open('GET', myTooltipScript, true);

    xmlHttp.onreadystatechange = function ()
    {
      if (xmlHttp.readyState == 4)
      {
	if(xmlHttp.responseText.length > 0) {

	   document.getElementById("ltTooltip").innerHTML = xmlHttp.responseText;;
	}
      }
      return true;
    };
    xmlHttp.send(null);
  }
  else
  {
  return false;
  }

}

//
// RESET FUNCTIONALITY FOR INPUT FIELDS...
// INITIALIZE WITH boxReset(id,id...)
//

var inpBox = new Object();

function boxReset()
{
	var myElem;
	for(var i=0;i<arguments.length;i++) {
		myElem = document.getElementById(arguments[i]);

		if (myElem) {
			inpBox[myElem.id] = myElem.value;


			if (document.addEventListener) {
			  // REGISTERING THE EVENTS FOR DOM COMPLIANT BROWSERS
				myElem.addEventListener("focus",boxGotFocus,false);
				myElem.addEventListener("blur",boxLostFocus,false);
			} else {
			  // REGISTERING THE EVENTS FOR IE
				myElem.attachEvent("onblur",boxLostFocus);
				myElem.attachEvent("onfocus",boxGotFocus);
			}

		}
	}
}

function boxGotFocus(e)
{
  myBox = (!window.event) ? e.target:window.event.srcElement;

  if (myBox.value == inpBox[myBox.id])
  {
    myBox.value = "";
  }
}

function boxLostFocus(e)
{
  myBox = (!window.event) ? e.target:window.event.srcElement;

  if (myBox.value == "")
  {
    myBox.value = inpBox[myBox.id];
  }
}

//
// GENERAL FUNCTIONS...
//

//
// THIS IS TAKEN FROM
// http://www.quirksmode.org/js/findpos.html
//

function findPos(obj) {
  var curleft = curtop = 0;
  if (obj.offsetParent) {
    curleft = obj.offsetLeft
    curtop = obj.offsetTop
    while (obj = obj.offsetParent) {
      curleft += obj.offsetLeft
      curtop += obj.offsetTop
    }
  }
  return [curleft,curtop];
}

//
// Overlay functions for Mijn Postcode Loterij
//

//
// Copyright (c) GX creative online development
// Developer: Paul van Eijden
//

function createElm(elmtype,naam,parent) {
	var elm = document.createElement(elmtype);
	elm.className = naam;
	parent.appendChild(elm);
	return elm;
}
function createP(inhoud,parent) {
	var elm = document.createElement("p");
	elm.innerHTML = inhoud;
	parent.appendChild(elm);
	return elm;
}
function buttonClick() {
	var backgroundGray = createElm("div","backgroundGray",document.body);
	backgroundGray.setAttribute("id", "backgroundGray");
	var backgroundGray2 = createElm("div","backgroundGray2",document.body);
	backgroundGray2.setAttribute("id", "backgroundGray2");
	var containerMain = createElm("div","containerMain",backgroundGray2);
	var containerHeader = createElm("div","containerHeader",containerMain);
	var containerContent = createElm("div","containerContent",containerMain);
	var columnLeft = createElm("div","columnLeft",containerContent);
	var columnMiddle = createElm("div","columnMiddle",containerContent);
	var columnMiddleContent = createElm("div","kadertje w530",columnMiddle);
	var columnRight = createElm("div","columnRight",containerContent);

	createElm("span","top",columnMiddleContent);
	createElm("div","title",columnMiddleContent);

	var columnMiddleContentH2 = document.createElement("h2");
	columnMiddleContentH2.title = "Log in en grijp uw BuitenKans!";
	columnMiddleContentH2.innerHTML = "Log in en grijp uw BuitenKans!";
	columnMiddleContent.appendChild(columnMiddleContentH2);

	var columnMiddleContentT = document.createElement("span");
	columnMiddleContentT.style.background = "url('/web/gettext?fractional=false&size=42&fgcolor=&family=Myriad+Pro+Black&text=Log+in+en+grijp+uw+BuitenKans%21&width=1012&height=42&scalex=50&scaley=50&sc=f7ebd2') no-repeat";
	columnMiddleContentH2.insertBefore(columnMiddleContentT,columnMiddleContentH2.firstChild);

	var columnMiddleContentImg = document.createElement("img");
	columnMiddleContentImg.setAttribute("src", "https://www.postcodeloterij.nl/static/npl/img/buitenkans.jpg");
	columnMiddleContentImg.style.cssFloat = "right";
	columnMiddleContentImg.style.styleFloat = "right";
	columnMiddleContentImg.style.margin = "8px 8px 24px 16px";
	columnMiddleContent.appendChild(columnMiddleContentImg);

	createP("<strong>Om gebruik te maken van BuitenKans moet u aan de rechterkant inloggen op Mijn Postcode Loterij.</strong>",columnMiddleContent);
	createP("&nbsp;",columnMiddleContent);
	createP("Bent u wel deelnemer, maar heeft u nog geen persoonlijke pagina? <a href='https://www.postcodeloterij.nl/MijnPostcodeLoterij/RegistreerUVoorMijnPostcodeLoterij.htm'>Registreer u dan snel!</a>",columnMiddleContent);
	createP("&nbsp;",columnMiddleContent);
	createP("Speelt u nog niet mee met de Postcode Loterij? Dan loopt u niet alleen de BuitenKans mis, maar ook de geweldige prijzen die u maandelijks kunt winnen. <a href='https://www.postcodeloterij.nl/LotenBestellen/KoopEenLot.htm'>Koop snel een lot!</a>",columnMiddleContent);

	var columnMiddleContentImg = document.createElement("img");
	columnMiddleContentImg.setAttribute("src", "https://www.postcodeloterij.nl/static/npl/img/close.png");
	columnMiddleContentImg.setAttribute("onclick", "buttonElseClick()");
	columnMiddleContentImg.className = "imgClose";
	columnMiddleContent.appendChild(columnMiddleContentImg);
	if (document.addEventListener) {
		columnMiddleContentImg.addEventListener("onclick",buttonElseClick,false);
	} else {
		columnMiddleContentImg.attachEvent("onclick",buttonElseClick);
	}

	createElm("span","bottom",columnMiddleContent);

	var els = document.getElementById("columnRight").getElementsByTagName("DIV");
	for (i = 0, j = 0; i < els.length; i++) {
		if (els[i].className == "kadertje w185 orange") {
			els[i].zIndex = 99;
			els[i].setAttribute("id", "inloggen");
			columnRight.appendChild(els[i]);
			return true;
		}
	}
	return false;
}
function buttonElseClick() {
	var els = document.getElementById("columnRight").getElementsByTagName("DIV");
	for (i = 0, j = 0; i < els.length; i++) {
		if (els[i].className == "NPL_blocks_Rechts") {
			els[i].insertBefore(document.getElementById("inloggen"),els[i].firstChild);
			document.body.removeChild(document.getElementById("backgroundGray"));
			document.body.removeChild(document.getElementById("backgroundGray2"));
			return true;
		}
	}
	return false;
}