var clicked = false;
var popup   = null;

function vraagOmEnquete() {
	document.getElementById('loader').style.display="none";
	document.getElementById('popup').style.display="";
	document.title= "M.I.N. - Vragenlijst";
	window.resizeTo(700,450);
	window.moveTo(screen.width / 2 -350, screen.height / 2 -225);
	if(document.body.addEventListener){
		alert('Management Instituut nodigt u uit om een enquete uit te voeren.');
	}
	window.focus();
}

function beginEnquete() {
	window.open(monitorURL,"survey",'width=' + (screen.width-100) + ', height=' + (screen.height-100) + ', top=50, left=50,toolbar=yes, location=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes');
	stopVragen();
}

function stopVragen() {
	createCookie('min_popup', 'hide', 21);
	window.close();
}

function initialzeNarrowCoach(e) {
    tagname = e.srcElement.tagName;
    if (tagname  =="INPUT" |  tagname=="SELECT" | tagname=="TEXTAREA" ) {
         return;    
    }
    laadpopup();
    clicked = true;
}

function laadpopup(){
    popup = window.open('http://www.managementinstituut.nl/vragenlijst.php', 'logoff','width=250, height=50, left=100, top=100, screenX=100, screenY=100,toolbar=no, location=yes, status=no, menubar=no, scrollbars=yes, resizable=yes', false);
    popup.blur();
}

function initPopup(){
	if (readCookie('min_popup')!='hide') {
		var b = document.getElementsByTagName('body');
		for(var i=0;  i<b.length;  i++) {           
			if (b[i].addEventListener)                
			{ 
				b[i].addEventListener("click", initialzeNarrowCoach, false);
			}            
			else                
			{ 
				b[i].attachEvent('onclick',initialzeNarrowCoach);
			}
		}
	}
}

function createCookie(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=/";
}

function readCookie(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 eraseCookie(name) {
	createCookie(name,"",-1);
}

function checkparent()  {
	try {
		if(!opener.window){
			vraagOmEnquete();
			return;
		}else{
			if(opener.window.document.location.toString().match('http://www.managementinstituut.nl/')==false) {
				vraagOmEnquete();
				return;
			}
		}
	}
	catch (e) {
		vraagOmEnquete();
		return;
	}
setTimeout("checkparent();",500);
}

function pageunload(){
	checkparent();
}

