// JavaScript Document
var Registration = 
{
	submitUrl: '',
	cancelUrl: '',
	termsUrl:'',
	guideUrl:'',
	redirectUrl: '',
	
	referredClicked: function()
	{
		if($U.checked('chkReferred'))
		{
			$('tr.referral').fadeIn('fast', function()
			 {
				 $U.focus('txtReferralCode');
			 });
		}
		else
		{
			$('tr.referral').fadeOut();
			$('input.referral').val('');
		}
	},
	
	dataSubmitted: function()
	{
		$U.showProgress();
		
		$.post(Registration.submitUrl, $('#frmRegistration').fastSerialize(), function(data)
		{
			//alert(data);
			
			var response = toJsonObj(data);
			
			if(response.succeed)
			{
				if(Registration.redirectUrl == '')
				{
					$('#spnRegisterName').html($('#txtFirstName').val());
					
					$U.hideProgress();
					
					$('#divRegistration').slideUp('fast', function()
				   {
					   $('#divResult').slideDown('fast');
				   });
				}
				else
				{
					document.location = Registration.redirectUrl;
				}
			}
			else
			{
				$U.showResponse('message', response);
			}
			
			scroll(0,0);
		});
		
		return false;
	},
	
	showTerms:function()
	{
		$U.showModal('terms',{width:500});
		return false;
	},
	
	showServices:function()
	{
		$U.showModal('services',{width:500});
		return false;
	},
	
	dispose: function()
	{
		
	},
	
	init: function()
	{
		$('tr.referral, #divResult, #message, #terms, #services').hide();
		
		var dt = new Date();
		var yearRange = '1910:' + dt.getFullYear();
		$('input.cal').calendar({'speed':'', yearRange: yearRange});
		
		$('#chkReferred').bind('click', Registration.referredClicked);
		$('#frmRegistration').bind('submit', Registration.dataSubmitted);
		$('#lnkTerms').bind('click', function()
		 {
			window.open(Registration.termsUrl, 'TermsConditions', 'resizable=yes,location=no,menubar=no,scrollbars=yes,status=no,toolbar=yes,fullscreen=no,dependent=no,width=600,height=500');
			return false;
		 });
		$('#lnkServices').bind('click', function()
		 {
			 window.open(Registration.guideUrl, 'ServicesGuide', 'resizable=yes,location=no,menubar=no,scrollbars=yes,status=no,toolbar=yes,fullscreen=no,dependent=no,width=600,height=500');
			 
			 return false;
		 });
		$('#btnCancel').bind('click', function()
	    {
		   document.location = Registration.cancelUrl;
	    });
		//$(document).bind('unload', Registration.dispose);
	}
}