// overlay
$(function() {
	$("#overlay").overlay({
		close: 'a.close' ,

		speed: 50,
		// start exposing when overlay starts to load
		onBeforeLoad: function() {
			
			// this line does the magic. it makes the background image sit on top of the mask
			this.getBackgroundImage().expose({opacity: 0.75 ,color: '#000000'});
		}, 
				
		// when overlay is closed take the expose instance and close it as well
		onClose: function() {
			$.expose.close();
		}
	});
});

// define function that opens the overlay
function openOverlay() {
	
	// get access to the overlay API
	var api = $("#overlay").overlay();

	// call it's open() method		
	api.load();			
}

/* Hide TAF */
function showTAF() {
	$('#TAF').show();
}

function hideTAF() {
	$('#TAF').hide();
}


/* Save test day functions **************************************************/

/* Show reminder form */
function showReminder() {
	$('#reminder').show();
}

/* Hide reminder form */
function hideReminder() {
	$('#reminder').hide();
}

/**
* This function is called by the flash app
*
* @param	String	testDate	Date on which the remindermail should be sent. Format d(d)-m(m)-yyyy
*
* It should cover all further handling.
*/
function saveTestDay(testDate, testInDays) {
	if(testDate != '') {
	
		// Show reminder form
		$('#reminder').show();
		
		// Split the date to dd, mm, yyyy
		/*var arrDate = new Array();
		arrDate = testDate.split('-');
		
		var dateDay = arrDate[0];
		var dateMonth = arrDate[1];
		var dateYear = arrDate[2];*/
		
		// Set in form
		$('#reminderDate').val(testDate);
		
		// Show number of days
		testInDays = parseInt(testInDays) + 1;
		
		$('#numberDays').html(testInDays);
	}
}

/*
* Send the reminder mail via ajax. The ajax call does some checks too.
**/
function saveReminder() {

	var name = $('#reminderYourName').val();
	var email = $('#reminderYourEmail').val();
	var testDate = $('#reminderDate').val();
		
	// Reset error classes
	 $('#labelReminderYourName').removeClass('error');
	 $('#labelReminderYourEmail').removeClass('error');
	
	// Ajax it
	$.ajax({
		type: "POST",
		url: "include/functions.ajax.php",	
		data: "name="+name+"&email="+email+"&date="+testDate+"&ajaxAction=saveReminder",		
		success: function(msg){
		//alert(msg);
			// Process return value
			var arrResult = msg.split('|||');
			if (arrResult[0] == 'OK') {	// Everything OK. Result saved.
				$('#reminderReplaceableContent').html('<strong>Je e-mailadres is opgeslagen.<br>U ontvangt binnenkort een herinneringsmail.</strong>');			
			}else if(arrResult[0] == 'ERROR') {	// An error occured.
				// Split all error fields and make 'em red
				var arrErrors = arrResult[1].split('||');
				var errLength = (arrErrors.length)-1;
				for(var i=0;i<errLength;i++) {
					$('#'+arrErrors[i]).addClass('error');
				}
			}
		}
	});
}
