// JavaScript Document
function Trim(nStr){return nStr.replace(/(^\s*)|(\s*$)/g, "");}
function isNull(obj,msg){
	if(msg!="Password")
		obj1=Trim(obj.value);
	else
		obj1=obj.value;
	if (obj1==""){
		alert("Oeps.... je hebt niet alles ingevuld!");
		obj.focus();
		return true;
	}else	
		return false;
}
function notEmail(obj,msg){
	var exp=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	if (!exp.test(obj.value)){
		//alert("Voer een geldige "+msg);
		alert("Oeps.... je hebt niet alles ingevuld!");
		obj.focus();
		return true;
	}else
		return false;
}
function notSelected(obj,msg){
	if (obj.options[obj.selectedIndex].value == ""){
		alert("Alsjeblieft selecteer de "+ msg);
		obj.focus();
		return true;
	}else
		return false;
}
function isLen(obj,siz,msg){
	if(msg!="Password")
		obj1=Trim(obj.value);
	else
		obj1=obj.value;
	if(obj1!=""){
		var strLen=obj.value;
		if(strLen.length < siz){
			alert(msg+" moet uit tenminste " + siz + " tekens bestaan");
			obj.focus();
			return true;  
		} 
	}else
		return false;
}
function isNotSame(obj1,obj2,msg1,msg2){
	if((Trim(obj1.value))!=(Trim(obj2.value))){
		alert(msg1+" en "+msg2+" zou moeten worden dezelfde ");
		obj2.focus();
		return true;
	}else
		return false;
}
function notChecked(obj,msg){
	checked = false;
	if(obj.length){
		for(i=0;i<obj.length;i++){
			if(obj[i].checked){
				checked = true;break;
			}
		}
	}else if(obj.checked)
		checked = true;
	if(!(checked)){
		//alert("Alsjeblieft selecteer de "+msg);
		alert("Oeps.... je hebt niet alles ingevuld!");
		if(obj.length)
			obj[0].focus();
		else
			obj.focus();
		return true;
	}
}
function notChecked_2(obj,msg){
	checked = false;
	if(obj.length){
		for(i=0;i<obj.length;i++){
			if(obj[i].checked){
				checked = true;break;
			}
		}
	}else if(obj.checked)
		checked = true;
	if(!(checked)){
		alert("Oeps.... je hebt niet alles ingevuld!");
		if(obj.length)
			obj[0].focus();
		else
			obj.focus();
		return true;
	}
}
function notChecked_1(obj,msg){
	checked = false;
	if(obj.length){
		for(i=0;i<obj.length;i++){
			if(obj[i].checked){
				checked = true;break;
			}
		}
	}else if(obj.checked)
		checked = true;
	if(!(checked)){
		alert("Maak eerst een keuze alsjeblieft."+msg);
		if(obj.length)
			obj[0].focus();
		else
			obj.focus();
		return true;
	}
}
function fnTel(obj,msg){
	exp = /^\+?[0-9+ -]*$/;
	if (!exp.test(obj.value)){
		//alert("Voer alleen numerieke waarden in "+msg);
		alert("Oeps.... je hebt niet alles ingevuld!");
		obj.focus();
		return true;
	}else
		return false;
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;
	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}
//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}
function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}
function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	//make image transparent
	changeOpac(0, imageid);
	//make new image
	document.getElementById(imageid).src = imagefile;
	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}
function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}
	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}
function pop_up(){
	var left = 0;
	var top = 0;
	var width=900;
	var height=500;	
	left=(screen.width > width) ?(screen.width-width)/2  :0;
	top=(screen.height > height)?((screen.height-height)/2) - 20:0;		
	window.open("voorwaarden.html","_blank","menu = 0,  left="+left+", top="+top+", height="+height+", width="+width+", toolbar=0, channelmode=0, scrollbars=1, resizable=0, fullscreen=0, ",false);
}
function bottom(){
	var str="";
	str+="<div class='clear'></div><div id='footer_main'><div id='main'><div id='footer_bg'>&copy; 2009 Tutornetwerk   |   <a href='javascript:pop_up()'>Voorwaarden</a></div></div></div>";
	document.write(str);
}
function fnValidateFAQ(){
	if(isNull(document.thisForm.txtName,"naam")){ return false; }
	if(isNull(document.thisForm.txtEmailAddress,"emailadres")){ return false; }
	if(notEmail(document.thisForm.txtEmailAddress,"emailadres")){ return false; }
	if(isNull(document.thisForm.txtQuestion,"Vraag")){ return false; }
}
function fnValidateJobs(){
	if(isNull(document.thisForm.txtName,"naam")){ return false; }
	if(isNull(document.thisForm.txtAddress,"adres")){ return false; }
	if(isNull(document.thisForm.txtEmail,"e-mailadres")){ return false; }
	if(notEmail(document.thisForm.txtEmail,"e-mailadres")){ return false; }
	if(isNull(document.thisForm.txtTel,"telefoonnummer")){ return false; }
	if(fnTel(document.thisForm.txtTel,"telefoonnummer")){ return false; }
	if(notChecked_2(document.thisForm.elements["chkSubject[]"],"")) return false;
	if(document.getElementById("hidSubjectCnt").value >1 ){
		for(i=0; i<document.getElementById("hidSubjectCnt").value; i++){
			var level = document.thisForm.elements["chkSubject[]"][i].value;
			if(document.thisForm.elements["chkSubject[]"][i].checked == true && document.getElementById("cmbLevel"+level).value == ''){
				alert("Oeps.... je hebt niet alles ingevuld!");
				document.getElementById("cmbLevel"+level).focus();
				return false;
			}
		}
	}else{
		var level = document.thisForm.elements["chkSubject[]"].value;
		if(document.thisForm.elements["chkSubject[]"].checked == true && document.getElementById("cmbLevel"+level).value == ''){
			alert("Oeps.... je hebt niet alles ingevuld!");
			document.getElementById("cmbLevel"+level).focus();
			return false;
		}	
	}
}
function fnValidateLogin(){
	if(isNull(document.thisForm.txtEmail,"emailadres")){ return false; }
	if(notEmail(document.thisForm.txtEmail,"emailadres")){ return false; }
	if(isNull(document.thisForm.txtPassword,"wachtwoord")){ return false; }
}
function open_win(page,width,height){
	var left = 0; var top = 0;	
	left=(screen.width > width) ?(screen.width-width)/2  :0;
	top=(screen.height > height)?((screen.height-height)/2) - 20:0;		
	window.open(page,"_blank","menu = 0,  left="+left+", top="+top+", height="+height+", width="+width+", toolbar=0, channelmode=0, scrollbars=1, resizable=0, fullscreen=0, ",false);
}
function fnValidateStudentRegister(order_id){
	if(notChecked(document.thisForm.elements['rdoPackage[]'],'kiezen minuten')){ return false };
	if(isNull(document.thisForm.txtName,"naam")){ return false; }
	if(isNull(document.thisForm.txtEmail,"email-adres")){ return false; }
	if(notEmail(document.thisForm.txtEmail,"email-adres")){ return false; }
	if(isNull(document.thisForm.txtClass,"schoolniveau en klas leerling")){ return false; }
	if(isNull(document.thisForm.txtPassword,"wachtwoord")){ return false; }
	if(isLen(document.thisForm.txtPassword,5,"Het wachtwoord")){ return false; }
	if(isNull(document.thisForm.txtConPassword,"Herhaal het wachtwoord")){ return false; }
  	if(isNotSame(document.thisForm.txtPassword,document.thisForm.txtConPassword,"wachtwoord","Herhaal het wachtwoord")){
      document.thisForm.txtConPassword.value="";
	  return false;	  
	}
	if(order_id == '')
	if(notChecked(document.thisForm.elements['chkTerms'],'voorwaarden')){ return false };
}
function fnValidateStudentProfile(){
	if(isNull(document.thisForm.txtName,"naam")){ return false; }
	if(isNull(document.thisForm.txtClass,"schoolniveau en klas leerling")){ return false; }
	if(isNull(document.thisForm.txtPassword,"wachtwoord")){ return false; }
	if(isLen(document.thisForm.txtPassword,5,"Het wachtwoord")){ return false; }
}
function fnValidatePurchasePackage(){
	if(notChecked(document.PurchaseForm.elements['rdoPackage[]'],'')){ return false };
}
function fnValidateTutorProfile(){
	if(isNull(document.thisForm.txtName,"naam")){ return false; }
	if(isNull(document.thisForm.txtAddress,"Adres")){ return false; }
	if(isNull(document.thisForm.txtPhone,"telefoonnummer")){ return false; }
	if(fnTel(document.thisForm.txtPhone,"telefoonnummer")){ return false; }
	if(isNull(document.thisForm.txtPassword,"wachtwoord")){ return false; }
	if(isLen(document.thisForm.txtPassword,5,"Het wachtwoord")){ return false; }
}
function fnShowContent(id){	
	opacity("idAllContent",100,0,500);
	setTimeout("fnShow("+id+")", 500);	
}
function fnShow(id){
	for(i=0; i<=3; i++){
		if(i == id){
			document.getElementById("content"+i).style.display = "block";
			document.getElementById("header"+i).className = "accordion_headings header_highlight";
		}else{
			document.getElementById("content"+i).style.display = "none";
			document.getElementById("header"+i).className = "accordion_headings";
		}
	}
	opacity("idAllContent",0,100,500);
}
function fnShowTutorContent(id){	
	opacity("idAllContent",100,0,500);
	setTimeout("fnShowTutorCont("+id+")", 500);	
}
function fnShowTutorCont(id){
	for(i=0; i<=3; i++){
		if(i == id){
			document.getElementById("content"+i).style.display = "block";
			document.getElementById("header"+i).className = "accordion_headings header_highlight";
		}else{
			document.getElementById("content"+i).style.display = "none";
			document.getElementById("header"+i).className = "accordion_headings";
		}
	}
	opacity("idAllContent",0,100,500);
}
function fnShowModeratorContent(id){	
	opacity("idAllContent",100,0,500);
	setTimeout("fnShowModerator("+id+")", 500);	
}
function fnShowModerator(id){
	for(i=0; i<=3; i++){
		if(i == id){
			document.getElementById("content"+i).style.display = "block";
			document.getElementById("header"+i).className = "accordion_headings header_highlight";
		}else{
			document.getElementById("content"+i).style.display = "none";
			document.getElementById("header"+i).className = "accordion_headings";
		}
	}
	opacity("idAllContent",0,100,500);
}
function fnValidateModeratorProfile(){
	if(isNull(document.thisForm.txtName,"naam")){ return false; }
	if(isNull(document.thisForm.txtPhone,"telefoonnummer")){ return false; }
	if(isNull(document.thisForm.txtAddress,"Adres")){ return false; }
	if(isNull(document.thisForm.txtPassword,"wachtwoord")){ return false; }
	if(isLen(document.thisForm.txtPassword,5,"Het wachtwoord")){ return false; }
}
var openMyModalSpecialOffer = function(){
	source = 'special_offer.php';
	modalWindow.windowId = "myModalSpecialOffer";
	modalWindow.width = 450;
	modalWindow.height = 366;
	modalWindow.content = "<iframe width='450' height='366' id='lightbox-iframe' frameborder='0' scrolling='no' allowtransparency='true' src='" + source + "'>&lt/iframe>";
	modalWindow.open();
};	
var closeMyModalSpecialOffer = function(){
	modalWindow.windowId = "myModalSpecialOffer";
	modalWindow.width = 495;
	modalWindow.height = 366;
	modalWindow.close();
};
function fnGo(){
	document.getElementById("idTutoredMinutes").innerHTML = '<br><br><img src="images/ajax-loader.gif" border="0" title="please wait, loading..."><br><br>'
	month = document.getElementById("cmbMonth").value;
	year = document.getElementById("cmbYear").value;
	var post_vars = {
		'type' 		: 'tutored_minutes',
		'cmbMonth'	: month,
		'cmbYear'	: year
	};
	$.post('ajax.php', post_vars,
			function(contents) {
				document.getElementById("idTutoredMinutes").innerHTML = contents;
			}
	);
}
function fnGoMissed(){
	document.getElementById("idMissedRequest").innerHTML = '<br><br><img src="images/ajax-loader.gif" border="0" title="please wait, loading..."><br><br>'
	month = document.getElementById("cmbMonthMissed").value;
	year = document.getElementById("cmbYearMissed").value;
	var post_vars = {
		'type' 			: 'missed_request',
		'cmbMonthMissed': month,
		'cmbYearMissed'	: year
	};
	$.post('ajax.php', post_vars,
			function(contents) {
				document.getElementById("idMissedRequest").innerHTML = contents;
			}
	);
}
function fnValidateGestbook(){
	if(isNull(document.thisForm.txtName,"naam")){ return false; }
	if(isNull(document.thisForm.txtEmail,"e-Mailadres")){ return false; }
	if(notEmail(document.thisForm.txtEmail,"e-Mailadres")){ return false; }
}
function fnValidateOrder(){
	if(notChecked(document.thisForm.elements["rdoPaymentType[]"],"Betalingstype")){ return false; }
}
function fnselectall(){
	obj = document.EmailForm.elements['chkSelect[]'];
	chkSelectAll = document.EmailForm.chkSelectAll;
	if(obj.length){
		if(chkSelectAll.checked == true){
			for(i=0;i<obj.length;i++){
				if(obj[i].checked == false){
					obj[i].checked = true;
				}
			}
		}else{
			for(i=0;i<obj.length;i++){
				if(obj[i].checked == true){
					obj[i].checked = false;
				}
			}
		}
	}else{
		if(chkSelectAll.checked == true){
			obj.checked = true;
		}else{
			obj.checked = false;
		}
	}		
}
function fnselect(){
	obj = document.EmailForm.elements['chkSelect[]'];
	chkSelectAll = document.EmailForm.chkSelectAll;
	if(obj.length){
		chkSelectAll.checked = true;
		for(i=0;i<obj.length;i++){
			if(obj[i].checked == false){
				chkSelectAll.checked = false;
				break;
			}
		}
	}else{
		if(obj.checked == true){
			chkSelectAll.checked = true;
		}else{
			chkSelectAll.checked = false;
		}
	}	
}
function fnValidateEmailForm(){
	if(isNull(document.EmailForm.txtFrom,"Van adres")) return false;
	if(notEmail(document.EmailForm.txtFrom,"Van adres")) return false;
	if(notChecked(document.EmailForm.elements['chkSelect[]'],'om adres')){ return false };
	if(isNull(document.EmailForm.txtSubject,"Onderwerp")) return false;
	document.EmailForm.action = "moderator_info.php?action=send_email";
	document.EmailForm.submit();
}
