/*global $, document */function webinar_sign_in() {
	var sJoinFirstName = $('#reg_user_fname').val();
	var sJoinLastName = $('#reg_user_lname').val();
	var sJoinEmail = $('#reg_user_email').val();
	
	if (sJoinFirstName === '') {
		$.prompt(oSiteMessages.tbn_alert_profile_enter_fname);
		return;
	}
	
	if (sJoinLastName === '') {
		$.prompt(oSiteMessages.tbn_alert_profile_enter_lname);
		return;
	}
	
	if (sJoinEmail === '') {
		$.prompt(oSiteMessages.tbn_alert_missing_email);
		return;
	}
	
	$.post('/join_ajax/signup_user', { sJoinFirstName : sJoinFirstName, sJoinLastName : sJoinLastName, sJoinEmail : sJoinEmail }, function(data) {
		if (data.sError) {
			$.prompt(data.sError);
			return;
		}
		
		if (data.sUserValid === 'Y') {
			location.reload()
		}
		
	}, 'json');
}


function check_quick_reg() {
	
	var quick_reg_email = ($('#quick_reg_email').val() === $('#quick_reg_email').data('default_value')) ? '' : $('#quick_reg_email').val();
	var quick_reg_email_conf = ($('#quick_reg_email_conf').val() === $('#quick_reg_email_conf').data('default_value')) ? '' : $('#quick_reg_email_conf').val();
	var quick_reg_passwd = $('#quick_reg_passwd').val();
	
	if (quick_reg_email === '') {
		$.prompt(oSiteMessages.tbn_alert_missing_email, {
			prompt_callback : function() {
				$('#quick_reg_email').focus();		
			}
		});
		
		return false;
	}
	

	if (quick_reg_email_conf === '') {
		$.prompt(oSiteMessages.tbn_alert_missing_email, {
			prompt_callback : function() {
				$('#quick_reg_email_conf').focus();		
			}
		});
		return false;
	}
	

	if (quick_reg_passwd === '') {
		$.prompt(oSiteMessages.tbn_alert_missing_password, {
			prompt_callback : function() {
				$('#quick_reg_passwd').show().focus().prev().hide();		
			}
		});
		return false;
	}


	if (!validate_email(quick_reg_email)) {
		$.prompt(oSiteMessages.tbn_alert_invalid_email, {
			prompt_callback : function() {
				$('#quick_reg_email').focus();		
			}
		});
		return false;
	}


	if (quick_reg_email != quick_reg_email_conf) {
		$.prompt(oSiteMessages.tbn_alert_emails_differ, {
			prompt_callback : function() {
				$('#quick_reg_email').focus();		
			}
		});
		return false;
	}
	
	$.post('/users_ajax/check_user_email_exists', { user_email : quick_reg_email }, function(data) {
		
		if (data.sError) {
			$.prompt(data.sError);
			return;
		}		
		
		if(data.iUserCount == 1) {
			var prompt_text = oSiteMessages.tbn_alert_account_exists;
			prompt_text = prompt_text.replace('<email>', quick_reg_email);
			
			$.prompt(prompt_text);
		} else {
			$.post('/users_ajax/quick_register', { 
				quick_reg_email : quick_reg_email,
				quick_reg_email_conf : quick_reg_email_conf,
				quick_reg_passwd : quick_reg_passwd
			}, function(data) {
				if (data.sError) {
					$.prompt(data.sError);
					return;
				}
			}, 'json');
		}
	}, 'json');
	
}


var quick_reg_conf = false;

$(document).ready(
	function() {
		
		$('.tbn_home_login').bind('keydown', function(e) {
			var iCode = e.charCode || e.keyCode;

			//if((iCode === 13) || (iCode === 108)) {
			if (iCode == '13') {
				user_login();
			}
		});
		
		$('#quick_reg_email').val(oSiteMessages.home_register_your_email);
		$('#quick_reg_email_conf').val(oSiteMessages.home_register_confirm_email);
		$('#quick_reg_passwd_txt').val(oSiteMessages.home_register_password);
		$('#home_register_btn').bind('click', check_quick_reg);
		
		
		if($('.home_fade_images').length == 1) {
			$('.home_fade_images').innerfade({
				speed : 750, 
				timeout : 4000, 
				type : 'sequence', 
				containerheight : '122px'
			});
		}
	}
);

