(function()
{
	GSM_PROFILE = ({
	is_error:false,
	
	updateProfile: function()
	{				
		if(!this.is_error)
		{
			GSM_LOADER.show("Saving your account");
			var param = this.getParam();
			
			jQuery.ajax({
				type:'post',
				data:param,
				url:'/account/update-profile',
				success: function(rs)
				{
					GSM_LOADER.hideWithMsg(rs);
				}
						
			});
						
		}
	},


	createProfile: function()
	{				
		if(!this.is_error)
		{
			GSM_LOADER.show("Creating your account");
			var param = this.getParam();
			
			jQuery.ajax({
				type:'post',
				data:param,
				url:'/account/create-profile',
				success: function(rs)
				{
					GSM_LOADER.hideWithMsg(rs);
				}
						
			});
						
		}
	},
	
	getParam: function()
	{
		var param = 'email_address='+escape(jQuery("#email_address").val());
		param += '&password='+escape(jQuery("#password").val());
		param += '&first_name='+escape(jQuery("#first_name").val());
		param += '&last_name='+escape(jQuery("#last_name").val());
		param += '&a_email_address='+escape(jQuery("#a_email_address").val());
		param += '&phone_number='+escape(jQuery("#phone_number").val());
		param += '&store_name='+escape(jQuery("#store_name").val());
		param += '&address='+escape(jQuery("#address").val());
		param += '&city='+escape(jQuery("#city").val());
		param += '&zip='+escape(jQuery("#zip").val());
		param += '&country='+escape(jQuery("#country").val());
		param += '&state='+escape(jQuery("#state").val());
		param += '&mobile_phone_number='+escape(jQuery("#mobile_phone_number").val());
		param += '&clientid='+escape(jQuery("#clientid").val());
		return param;	
	},

	setStateField: function(country, state)
	{
		GSM_LOADER.show("Loading content...");
		var param = 'country='+escape(country)+'&state='+escape(state);
		
		jQuery.ajax({
			type:'post',
			data:param,
			url:'/account/set-statecombo',
			success: function(rs)
			{
				GSM_LOADER.hide(10);
				jQuery("#stateCombo").html(rs);
				jQuery("#stateComboTr").fadeIn(300);
			}
					
		});
	},
	
	setStateField_withoutlogin: function(country, state)
	{
		GSM_LOADER.show("Loading content...");
		var param = 'country='+escape(country)+'&state='+escape(state);
		
		jQuery.ajax({
			type:'post',
			data:param,
			url:'/account/set-statecombowithoutlogin',
			success: function(rs)
			{
				GSM_LOADER.hide(1000);
				jQuery("#stateCombo").html(rs);
				jQuery("#stateComboTr").fadeIn(300);
				
			}
					
		});
	}
	
	});

})(jQuery);

jQuery(document).ready(function()
{
	jQuery("#profile_edit_frm INPUT").bind("keyup click",function(e)
	{ 
		if(e.keyCode == 13)
		{
			GSM_PROFILE.updateProfile();  
		}
		else
		{
			GSM_MSG.hide(10);
		} 
	});
	
	jQuery("#profile_new_frm INPUT").bind("keyup click",function(e)
	{ 
		if(e.keyCode == 13)
		{
			GSM_PROFILE.createProfile();  
		}
		else
		{
			GSM_MSG.hide(10);
		} 
	});
		
});


