// ---------------------------------
// audio/video recorder functions
// ---------------------------------

var comment_type;

// - tabs

$(function() {

	$("#submit_button").click(function() {
		$("form#comment_form").submit(); 
	});

	$("#tab_txt").click(function() {
		$("#anonymous_alert").hide();
		$("#txt_comment").show();
		$("#audio_recorder").hide();
		$("#video_recorder").hide();
		$("#submit_button").val('Reactie versturen');
		$("#comment_message").html('');
		$("#submit_button").attr("disabled", false); 

		comment_type = 'txt';
	});

	$("#tab_audio").click(function() {
		$("#anonymous_alert").hide();
		$("#txt_comment").hide();
		$("#audio_recorder").show();
		$("#video_recorder").hide();				
		$("#submit_button").val('Audioreactie versturen');	
		$("#comment_message").html('');
		$("#submit_button").attr("disabled", true); 

		comment_type = 'audio';
	});

	$("#tab_video").click(function() {
		$("#anonymous_alert").hide();
		$("#txt_comment").hide();
		$("#audio_recorder").hide();
		$("#video_recorder").show();					
		$("#submit_button").val('Videoreactie versturen');		
		$("#comment_message").html('');
		$("#submit_button").attr("disabled", true); 

		comment_type = 'video';
	});

});

//- submit event

$(function() {

	$("#comment_form").submit( function(event)
	{
		var msg = '';

		if(logged_out) {

			$("form#comment_form .error").each(function() 
			{ 
				$(this).removeClass("error");
			});

			//	Check empties
		
			var empty	= false;
			
			$.each( comment_form_fields, function(i,n)
			{			
				if ( $("form#comment_form input[name='" + n + "']").val() == '' )
				{
					empty	= true;
					
					$("form#comment_form input[name='" + n + "']").addClass("error");
				}		
			});

		}

		if ( empty == true )
		{
			msg	+= "<p>Vul alle vereiste velden in.</p>";
			setTimeout('$("form#comment_form .error").each(function() { $(this).removeClass("error"); });', 2000);
			return false;
		}
		
		if(logged_out) {

			// check valid email	

			var email	= $("form#comment_form input[name='email']").val();
			var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		
			if (!filter.test(email)) {
				$("form#comment_form input[name='email']").addClass("error");
				setTimeout('$("form#comment_form input[name=\'email\']").removeClass("error");', 2000);
				return false;
			}
		}

		//	Show message
		
		if ( msg != '' )
		{
			return false;
		}

		return true;

	});
});

// - audio & videorecorder function

function btSavePressed(streamName,streamDuration,userId){
	
	var now = Date.parse(new Date());

	// audio
	if(comment_type == 'audio') 
	{ 
		$("form#comment_form input[name='audio_comment']").val(streamName);
		$("form#comment_form textarea[name='comment']").val(now);
		$("#comment_message").html('Je audio reactie is succesvol opgenomen. Klik op <b>audioreactie versturen</b> om hem te plaatsen of op <b>opnieuw opnemen</b> om een nieuwe opname te starten.');
		$("#submit_button").attr("disabled", false);
	}

	// video
	if(comment_type == 'video') 
	{ 
		$("form#comment_form input[name='video_comment']").val(streamName);
		$("form#comment_form textarea[name='comment']").val(now);
		$("#comment_message").html('Je videoreactie is succesvol opgenomen. Klik op <b>videoreactie versturen</b> om hem te plaatsen of op <b>opnieuw opnemen</b> om een nieuwe opname te starten.');
		$("#submit_button").attr("disabled", false);  
	}
}

// - video functions

function onFLVSaved(streamName,streamDuration,userId){ 
	// disabled
}

// other functions - not used atm

function btRecordPressed(){ 
	// disabled
}
function btStopPressed(appState){ 
	// disabled
}
function btPlayPressed(){ 
	// disabled
}

