/**
 * @author Julien
 */
$(document).ready(function(){
	
	$('#AcivationCode').keyup(function () {
		var crCode = $('#AcivationCode').val();
		if(crCode.length == 8) {
			$.ajax({
				type: "GET",
				cache:false,
				data: "code=" + $('#AcivationCode').val(),
				url: "/invites/checkCode",
				success: function(data){
					if(data == 'available'){
						$('#bad_msg').hide();
						$('#goodCode').slideDown('slow');
					}
					if(data == 'null'){
						$('#bad_msg').show();
						$('#bad_msg').val('wrong code');
					}
					if(data == 'use'){
						$('#bad_msg').show();
						$('#bad_msg').val('code already use');
					}
				}
			});
		}
	});
});

function login() {
	$.ajax({
		type: "GET",
		cache:false,
		data: "code=" + $('#AcivationCode').val(),
		url: "/invites/loginHomepage",
		success: function(data){
			$('.rounded').html(data);
		}
	});
}
	
function invitationRequest(){
	var email = $("#NewUserLogin").val();
	var reg = new RegExp('^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$', 'i');

	if(email != '' && reg.test(email)){
		$('#request-email-response').load('/invites/saveInvitationRequest?email='+email);
	}else{
		if ($('#error-message').length == 0) {
			$('#request-invite-button').prepend("<div style='color:red' id='error-message'>Please check your email</div>");
		}
	}
	
}

var receptionAppelAS3 = function (message) {
		       
   		embedHeight = parseInt(message)+40;
		$('.video-player embed').attr("height", embedHeight);
		var inviteblocHeight = embedHeight-30;
		$('.rounded').css("height", inviteblocHeight);
		
    return;
}
