var dsPhotos;
var obs = new Object();
obs.doc = document;
obs.onPostLoad = function(notifier, data)
{
	if(typeof(dsPhotos.data[0].info) == "undefined"){
		var emptyRegion = document.getElementById('emptyRegion');
		if(emptyRegion){
			emptyRegion.style.display = 'block';
		}	
		
	}
	else{
		var emptyRegion = document.getElementById('emptyRegion');
		if(emptyRegion){
			emptyRegion.style.display = 'none';
		}	
		var showPhotosMail = document.getElementById('thumbnails');
		showPhotosMail.style.display = 'block';


	}
};

obs.onDataChanged = function(notifier, data)
{

};

var observer = { onPostUpdate: function(notifier, data) 			
{ 
		//check readiness
	var readinessId = document.getElementById('readiness_id');
	var chkReadiness = document.getElementById('chkReadiness');
	
	if(readinessId){
	
		if(parseInt(readinessId.value) > 0){
			//checked
			if(chkReadiness){
				chkReadiness.checked = true;
				openReadiness(chkReadiness);
			}			
		}
	}
	var showPhotosMail = document.getElementById('thumbnails');
		showPhotosMail.style.display = 'block';
	var showEnBut = document.getElementById('showEnButton');
	if(showEnBut != null){
		showEnBut.style.display = dsPhotos.data[0].info.english;
	}
} 

};
function loadPage(page){
	switch(page){
		case "serie":
			
			
			dsPhotos = new Spry.Data.JSONDataSet(null, { path: "dia", subPaths: ["dias", "info"] },  {useCache:false});	
			dsPhotos.addObserver(obs);
			

			
			Spry.Data.Region.addObserver("thumbnails", observer);			

		break;
		
		case "faq":
			dsPhotos = new Spry.Data.JSONDataSet(null, {path: "info"}, {useCache:false});
			dsPhotos.url = "data.php?type=faq";
			dsPhotos.loadData();
			//dsPhotos.addObserver(obs);
		break;	
	}
	
	
}
//var dsPhotos;

function loadFaq(id){
	
	dsPhotos.url = 'data.php?type=faq&content_id=' + id;
	dsPhotos.loadData();
}

function PasswordForget(){

}


function openSerie(diaId){
	
	var url = 'data.php?id=' + diaId + '&type=diaoverview';
	//Spry.Utils.loadURL('get', url, false, openSerieCallBack, null);
	//dsPhotos = new Spry.Data.XMLDataSet("galleries/{dsGalleries::@base}{dsGalleries::@file}", "gallery/photos/photo");
	dsPhotos.url = url;
	
	//dsPhotos = new Spry.Data.JSONDataSet("data.php?id=213&type=diaoverview", { path: "a.a" }, {useCache:false});
	dsPhotos.loadData();

	dsPhotos.addObserver(obs);
	
}

function showDias(ses_id, dia_id, number, language,pupil){
	var sHeight = this.screen.availHeight;
	var sWidth = this.screen.availWidth;
	if(typeof(number) == "undefined"){
		number = 0;
	}
	if(typeof(language) == "undefined"){
		language = "nl";
	}
	if(typeof(pupil) == "undefined"){
		pupil = 0;
	}
	
	var location = 'diaviewer.php?PHPSESSID=' + ses_id + '&dia_id=' + dia_id + '&number=' + number + '&sHeight=' + sHeight + '&sWidth=' + sWidth + '&language=' + language + '&pupil='+pupil;
 
	var diawindow = window.open(location, 'dia', 'fullscreen=yes, resizable=no,scrollbars=no,status=no'); // 'fullscreen=no, resizable=yes,scrollbars=yes,status=yes');
  	if(window.focus){
		diawindow.focus();
	}
}

function openReadiness(elem){
	var readinessElem = document.getElementById('readinessField');
	if(readinessElem){
		if(elem.checked){
			readinessElem.style.display = 'block';			
		}
		else{
			readinessElem.style.display = 'none';
		}
	
	}
}

function saveReadiness(session, serieId){
	var url = 'data.php?PHPSESSID=' + session + '&type=readiness&serie_id=' + serieId;
	frmOpts = new Object();
	frmOpts.headers = { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" };
	frmOpts.postData = "";
	var inpFromTime = document.getElementById('FromTime');
	var inpToTime = document.getElementById('ToTime');
	if(inpFromTime){
		if(inpFromTime.value != ''){
			frmOpts.postData += "&fromTime=" + inpFromTime.value;
		}
		else{
			alert('Er is geen begintijd opgegeven');
			inpFromTime.focus();
		}
	}
	if(inpToTime){
		if(inpToTime.value != ''){
			frmOpts.postData += "&toTime=" + inpToTime.value;
		}
		else{
			alert('Er is geen eindtijd opgegeven');
			inpToTime.focus();
		}
	}	
	
	
	Spry.Utils.loadURL('POST', url, true, updateReadiness, frmOpts);
}

function OpenAccountForm(){		
	
	var divAccount = document.getElementById('AccountForm');
	
	if(divAccount.style.display != 'none' && divAccount.style.display != "")
	{
		divAccount.style.display = 'none';
	}
	else
	{		
		divAccount.style.display = 'inline';
		
		document.registration.username.focus();
		document.registration.username.select();		
	}	
}

function renewPasword(){
	var oldUserName = document.registration.oldUserName.value;
	var userName = document.registration.username.value; 		
	var passwd = document.registration.newpassword.value;
	var conpasswd = document.registration.confirmpassword.value;
	var oldPasswd = document.registration.oldpassword.value;
	var spMessage = document.getElementById('message');
	if(passwd != '' && oldPasswd == ''){
		spMessage.innerHTML = 'Voor een nieuw wachtwoord dient u uw oude wachtwoord op te geven';
	}	
	else{
		if(conpasswd != passwd){
			
			
			spMessage.innerHTML = 'Uw wachtwoorden komen niet overeen';
			document.registration.confirmpassword.value = '';
			document.registration.confirmpassword.focus();
		}
		else{
			frmOpts = new Object();
			frmOpts.headers = { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" };
			frmOpts.postData = "";
			if(oldUserName != ''){
				frmOpts.postData +="&oldUserName=" + oldUserName;
			}
			if(userName != ''){
				frmOpts.postData += "&userName=" + userName;
			}
			if(passwd != ''){
				frmOpts.postData +="&passWord=" + passwd;
			}
			if(oldPasswd != ''){
				frmOpts.postData +="&oldPassword=" + oldPasswd;
			}
	
			var url = "data.php?type=pwd";;
			
			Spry.Utils.loadURL('POST', url, true, updatePassword, frmOpts);
		}
	}
}

var updatePassword = function(req){
	var spMessage = document.getElementById('message');
	spMessage.innerHTML = req.xhRequest.responseText;
}

var updateReadiness = function(req){
	alert( req.xhRequest.responseText);
}

