
$(document).ready(function(){
	
	  if ($.browser.msie) {
	    $('#password').keydown(function(e){
	    	if (e.keyCode == 13) {
	    		$("#inlogForm").submit();
		      }
	    });
	  }
	  
	$('.logout').click(function() {
		$.ajax({
			   type: "GET",
			   url: "/ajax/logout.php",
			   data: "logout=1",
			   success: function(msg){
			  	if (msg == 1) {
					window.location = "/home_1.html"
				}
			}
		});
	});
	
	$("#inlogForm").submit(function(){
		
		username = $("#username").val();
		password = $("#password").val();
		
		if(!username || !password) {
			$("#loginmessage").html("Voer je gebruikersnaam en wachtwoord in.");
			$("#loginmessage").show();
			return false;
		}
		
		$.ajax({
		   type: "POST",
		   url: "/ajax/login.php",
		   data: "username="+username+"&password="+password,
		   success: function(msg){
			
		  	if (msg == 1) {
				window.location = "/page_100967.html";
			}
			if (msg == 2) {
				$("#loginmessage").html("De opgegeven combinatie van gebruikersnaam en wachtwoord is ongeldig. Probeer het opnieuw.");
				$("#loginmessage").show();
			}	
			if (msg == 3) {
				$("#loginmessage").html("De opgegeven gebruikersnaam is uitgeschreven.");
				$("#loginmessage").show();
			}
			if (msg == 9) {
				$("#loginmessage").html("Het is tijdelijk niet mogelijk om in te loggen.");
				$("#loginmessage").show();
			}
		  	if (msg == 4) {
				window.location = "/voor_ouders_7.html";
			}
		   }
		});
		return false;
	});	
});










isGecko = false;

function ndWriteAnchorLinks() {

	 var h4s = document.getElementsByTagName("H4");
	 var indexObj = document.getElementById("anchorlinks");
	 var str = "";
	 
	 if (h4s.length > 0) {
	 
	  str = "<UL>";
	  
	  for (var i = 0; i< h4s.length; i++) {
	  
	   title = h4s[i].innerHTML;
	   title = title.replace(/<[^>]+>/g,""); //remove tags
	   
	   //add anchor before the H2
	   if(isGecko) {
	    //Mozilla
	    newNode = document.createElement("A");
	    newNode.setAttribute("ID", "anchor" + i)
	    newNode.setAttribute("NAME", "anchor" + i)
	    h4s[i].parentNode.insertBefore(newNode,h4s[i]);
	   } else {
	    //IE
	    h4s[i].insertAdjacentHTML("BeforeBegin","<a name='anchor"+i+"'></a>");
	   }
	   
	    // list item
	    str += "<LI><a href='#anchor" + i + "'>" + title + "</a></LI>";
	   
	   indexObj.innerHTML = str;
	  }
	 
	   str += "</UL>";
	  
	 }
 }

function ndPopup(aTag, pWidth, pHeight, scrollbars) {
	//This function is supposed to be called from the a-tag with valid href-attribute
	//If pWidth and pHeight are given, the popup will assume them as width and height
	if (!pWidth) pWidth=600; if (!pHeight) pHeight=500;
	if (top.ndCMSPopup && !top.ndCMSPopup.closed && top.ndCMSPopup.close) top.ndCMSPopup.close();
	if(scrollbars) var scrollbars = ",scrollbars=1";
	top.ndCMSPopup = top.open(aTag, "ndCMSPopup", "width="+pWidth+",height="+pHeight+",resizable=no,menubar=0"+scrollbars);
	top.ndCMSPopup.focus();
	return false;
}

function checkSearchForm (){
	
	var vreemdeKarakters = '� & { } " < � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � ';
	
	var keyword = document.getElementById("keyword").value;
	
	if(vreemdeKarakters.indexOf(keyword) != -1){
		alert("U mag geen vreemde karakters gebruiken in de zoekveld");
		document.getElementById("keyword").focus();
		return false;
	}
	
}

function doLogin() {
	
	/*
	username = $("#username").val();
	password = $("#password").val();
	
	if(!username || !password) {
		$("#loginmessage").html("Voer je gebruikersnaam en wachtwoord in.");
		$("#loginmessage").show();
		return false;
	}
	
	$.ajax({
	   type: "POST",
	   url: "/ajax/login.php",
	   data: "username="+username+"&password="+password,
	   success: function(msg){
	   
		
			alert(msg);
			return false;
			
	  	if (msg == 1) {
			window.location = "/page_100967.html";
		}
		if (msg == 2) {
			$("#loginmessage").html("De opgegeven combinatie van gebruikersnaam en wachtwoord is ongeldig. Probeer het opnieuw.");
			$("#loginmessage").show();
		}	
		if (msg == 3) {
			$("#loginmessage").html("De opgegeven gebruikersnaam is uitgeschreven.");
			$("#loginmessage").show();
		}
	  	if (msg == 4) {
			window.location = "/voor_ouders_7.html";
		}
	   }
	});
	*/
}


function checkFlashPlayer(){
	var embeds = document.getElementById("content").getElementsByTagName("EMBED");
	
	if (embeds.length > 0) { // Als er swf bestanden in de pagina zijn
		
		// Major version of Flash required
		var requiredMajorVersion = 9;
		// Minor version of Flash required
		var requiredMinorVersion = 0;
		// Revision of Flash required
		var requiredRevision = 0;
		//Detect Browser
		var browserName=navigator.appName;
		
		//alert(browserName)
		
		if (AC_FL_RunContent == 0) {
			alert("This page requires AC_RunActiveContent.js.");
		} 
		else {
			var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
			if(!hasRightVersion) {  // Als er geen flash player is
				/*
				if (browserName=="Microsoft Internet Explorer"){
 					//IE
					var downloadLink = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0';
				}else{
					//FF
					var downloadLink = 'http://fpdownload.macromedia.com/get/flashplayer/current/install_flash_player.exe';
				}
				*/
				var downloadLink = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0';
				AC_FL_RunContent(
					'codebase', downloadLink,
					'width', '',
					'height', '',
					'src', '',
					'quality', 'high',
					'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
					'align', 'middle',
					'play', 'true',
					'loop', 'true',
					'scale', 'showall',
					'wmode', 'window',
					'devicefont', 'false',
					'id', 'viral5',
					'bgcolor', '#ffffff',
					'name', 'viral5',
					'menu', 'true',
					'allowFullScreen', 'false',
					'allowScriptAccess','always',
					'movie', '',
					'salign', ''
				); 
				
			}
		}
	}
}


function checkMemberLoginForm() {
	if (document.getElementById("username").value == "") {
		alert("Voer uw naam in.");
		document.getElementById("username").focus();
		return false;
	}
	
	if (document.getElementById("password").value == "") {
		alert("Voer uw inlogcode in.");
		document.getElementById("password").focus();
		return false;
	}
}

function checkEmailForm() {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var email = document.getElementById("email").value;
	if(reg.test(email) == false) {
		alert('Voer een (geldig) email adres in alstublieft.');
		return false;
	}
}

function checkQuestionForm() {
	if (document.getElementById("question").value == "") {
		alert("Voer een vraag in alstublieft.");
		document.getElementById("question").focus();
		return false;
	}
}

function mail_question() {
	
	var question = $("#question").val();
	var referrer = $("#referrer").val();
	
	if (!question) {
		$("#question_message").html("Voer een vraag in alstublieft.");
		$("#question_message").show();
		return false;
	}
	
	$.ajax({
	   type: "POST",
	   url: "/ajax/mail_question.php",
	   data: "question="+question+"&referrer="+referrer,
	   success: function(msg){
	   
		if (msg == 1) {
			$("#question_message").html("De vraag is verstuurd.");
			$("#question").html("");
			$("#question_message").show();
		}	
		if (msg == 2) {
			$("#question_message").html("Er ging iets mis. Probeer het nogmaals.");
			$("#question").html("");
			$("#question_message").show();
		}
	   }
	});
}



function loadStartdayPortlet() {
	$.getJSON("/ajax/startdag_get.php", null,
	   function(data){
		if(data.code == "error") {
			$("#numDays").html(data.message);
			$("#moveDayLink").hide();
		} else {
			$("#moveDayLink").show();
			$("#numDays").html(data.message);
		}
	   });
	
};

function setStartDay() {
	//move startday 1 day back
	$.getJSON("/ajax/startdag_set.php", null,
	   function(data){
			if(data.code=="ok") {
				//refresh
				loadStartdayPortlet();	
			}
	   });
};


