var RecaptchaVerified = false;

function LoadSoundOffForm()
{
	$.post('/home/getsoundoffform/1', {}, function(data) {
			$('div#soundOffDiv').html(data.html);
			BindSoundOffForm();
	}, 'json');
}

function CaptchaCheck(callBackFunction)
{
	Boxy.load('/main/recaptcha',
			{
				modal:true,
				unloadOnHide:true,
				title:'Please Enter the Code Below',
				afterHide: function() {
					if(RecaptchaVerified)
						callBackFunction();
				}
			});				
}

function CaptchaSuccess()
{
	Boxy.get('#captchaFrame').hide();
	RecaptchaVerified = true;
}

// Bind the submit event of the form and process the json response
function BindSoundOffForm()
{
	$('form#soundOffForm').ajaxForm({
		dataType: 'json',
		beforeSubmit: function() {
			if(!RecaptchaVerified)
			{
				var u13Status = $('[name=U13]').val();
				
				if(u13Status == 'true')
				{							
					$('#soundOffForm').submit(function() {
						return false;
					});
					
					$('.U13Remove').hide();
					$('.U13Add').show();
				
					Boxy.alert('Thank you for your interest in sounding off.  As we are committed to protecting your privacy, we are unable to accept your registration. However, we invite you to continue browsing the site without posting.');

					return false;
				}

				CaptchaCheck(function() {
					$('form#soundOffForm').submit()
				});
				return false;
			}
			return true;
		},
		success: function(data) {
			if(data.success)
			{
				Boxy.alert(data.message);
				$('#soundOffDiv').html(data.html);
				BindSoundOffForm();
			}
			else
			{
				Boxy.alert(data.message);
			}
		}
	});	
}

function GetU13()
{
	SONYMUSIC_COPPA_13.updateForm($('#U13Form'));
}

function BindEmailRegisterForm()
{
	$('form#emailRegisterForm').ajaxForm({
		dataType: 'json',
		beforeSubmit: function() {
			if(!RecaptchaVerified)
			{
				var u13Status = $('[name=U13]').val();
				
				if(u13Status == 'true')
				{							
					$('#emailRegisterForm').submit(function() {
						return false;
					});
					
					$('.U13Remove').hide();
					$('.U13Add').show();
				
					Boxy.alert('Thank you for your interest in registering.  As we are committed to protecting your privacy, we are unable to accept your registration. However, we invite you to continue browsing the site without posting.');

					return false;
				}

				CaptchaCheck(function() {
					$('form#emailRegisterForm').submit()
				});
				return false;
			}
			return true;
		},
		success: function(data) {
			if(data.success)
			{
				$('form#emailRegisterForm').fadeOut();
				Boxy.alert("Thank you! Will email you a reminder for the launch.");
			}
			else
			{
				Boxy.alert(data.message);
			}
		}
	});	
}

$(document).ready(function(){
	GetU13();
	BindSoundOffForm();
	BindEmailRegisterForm();
	
	$.post('/main/updatestream');
});