﻿// JavaScript

var popupTimeInSeconds = 600;



function MWM2POPUPWriteCookie(name,value,days) 

{

	if (days) 

	{

		var date = new Date();

		date.setTime(date.getTime()+(days*24*60*60*1000));

		var expires = "; expires="+date.toGMTString();

	} else {

	    var expires = "";

	}

	document.cookie = name+"="+value+expires+"; path=/";

}

var timer

/* Method that show popup after x seconds */

function startPage() {

	var popupDateTime = MWM2POPUPReadCookie('popupDateTime')

    var noPopupPlease = MWM2POPUPReadCookie('noPopupPlease')

    var current = new Date();

    var timeToGo;

    

	if (!noPopupPlease) {

		if (popupDateTime && !noPopupPlease) { //popup datetime is set

			

			//calculate difference between popupDateTime and current DateTime

			timeToGo = popupDateTime - current.getTime();

		}

		else { //set popup datetime

			var popupDate = new Date();

			var timeToPopup = popupDate.getTime() + (popupTimeInSeconds * 1000)

			MWM2POPUPWriteCookie('popupDateTime', timeToPopup, 1);

			

			// set timeout

			timeToGo = popupTimeInSeconds * 1000;

		}



		if (timeToGo > 0) {

			timer = setTimeout(showPopup, timeToGo);

		} else {

			showPopup();

		}

	}

}





function MWM2POPUPReadCookie(name) 

{

	var nameEQ = name + "=";

	var ca = document.cookie.split(';');

	for(var i=0;i < ca.length;i++) 

	{

		var c = ca[i];

		while (c.charAt(0)==' ') c = c.substring(1,c.length);

	    

		if (c.indexOf(nameEQ) == 0)

		{

		    return c.substring(nameEQ.length,c.length);

		}

	}

	

	return null;

}



function MWM2POPUPEraseCookie(name)

{

    MWM2POPUPWriteCookie(name, "", -1);

}





function PopupCounter(link, title, sbody, imageUrl)

{



    popupDiv = document.createElement('div');

    popupDiv.id = 'MWM2POPUP';

    popupDiv.className='MWM2POPUP';



	var str = '<table border=0 cellpadding=5 cellspacing=3 width=340 align=center><tr>';

	str += '<td class="MWM2POPUPTopbar"><div class="MWM2POPUPTopbar" style="float:left;">' + title + '</div><div style="float:right;" class="MWM2POPUPCloseButton" onclick="document.getElementById(\'MWM2POPUP\').style.display=\'none\';MWM2POPUPWriteCookie(\'noPopupPlease\', true, 1)">&nbsp;</div></td>';

    str += '</tr>';

    str += '<td class=\"MWM2POPUPBody\"><img src=\"' + imageUrl + '\"></td></tr><tr><td>';

    str += sbody;

    str += '</td></tr><tr><td style=\"text-align:center\">';

    str += '<input type=button name=Ja value=\"Ja\" class="MWM2POPUPButtons MWM2POPUPButtonJA" onclick="MWM2PopupClickYes(\'' + link + '\')">';

    str += '<input type=button name=Nee value=\"Nee\" class="MWM2POPUPButtons MWM2POPUPButtonNEE" onclick="MWM2POPUPWriteCookie(\'noPopupPlease\', true, 2000);document.getElementById(\'MWM2POPUP\').style.display=\'none\';">';

//    popupDiv.innerHTML += '                </td></tr></table>';

    str += '</td>';

    str += '</tr>';

	str += '</table>';

	

	popupDiv.innerHTML = str



    document.body.insertBefore(popupDiv, document.body.childNodes[0]);



}



//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

//

//                                          CHANGEBLE PARTS BELOW

//

//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*



function MWM2PopupClickYes(link)

{

    MWM2POPUPWriteCookie('MWM2POPUPCounter',true,'2000');

    document.getElementById('MWM2POPUP').style.display='none';



    window.open(link,'MWM2Onderzoekapplicatie','resizable=1,width=800,height=600');

}



function NCpopup(seconds){

	popupTimeInSeconds = seconds

	startPage()

}



function showPopup()

{

	clearTimeout(timer)

    PopupCounter('http://net.mwm2.nl/go.aspx?vp=45F244E0-C7BC-4F4B-B752-23F875A89727', 

                 'gebruikersonderzoek www.4en5mei.nl', 

                 'Het Nationaal Comité 4 en 5 mei wil graag uw mening weten over de website en nodigt u uit voor een onderzoek.<br />Het invullen kost ongeveer acht minuten van uw tijd. Bovendien maakt u kans op één van de tien dvd\'s van de film Oorlogswinter.<br />Wilt u meewerken aan dit onderzoek?',

                 'http://onderzoek.mwm2.nl/third/bmm/logo_nc.gif');

}
