jiyiri.register_namespace('jiyiri.page.invitefriend');

/* jiyiri.require_once('jiyiri.ui.dateinputer'); */
jiyiri.require_once('jiyiri.page.common.remindercategoryselector');
/* jiyiri.require_once('jiyiri.ui.Beautifier'); */
/* jiyiri.require_once('jiyiri.ui.ValidateImage'); */
/* jiyiri.require_once('jiyiri.helper.htmlelementhelper.htmlelementhelper'); */
/* jiyiri.require_once('jiyiri.helper.net.Form'); */
/* jiyiri.require_once('jiyiri.helper.eventhelper.eventhelper'); */
/* jiyiri.require_once('jiyiri.helper.validatehelper.data_validate'); */

( function() {

	/* Codes Start Here */
	var InputBirthdayUnloginedPage = Class.create();
	InputBirthdayUnloginedPage._insatance = null;
	InputBirthdayUnloginedPage.GetInstance = function() {
		if (null == InputBirthdayUnloginedPage._instance) {
			InputBirthdayUnloginedPage._instance = new InputBirthdayUnloginedPage();
		}
		return InputBirthdayUnloginedPage._instance;
	};
	InputBirthdayUnloginedPage.prototype = {
		initialize : function() {
			this._page_info = null;

			this._submit_button = $('submit_button');
			this._birthday_category_area = $('category_selector');

			this._date_inputer = new jiyiri.ui.DateInputer($('solarbtn'),
					$('lunarbtn'), $('date_y'), $('date_m'), $('date_d'),
					$('date_issolar'));
			this._birthday_category_selector = new jiyiri.page.common.ReminderCategorySelector(
					this._birthday_category_area,
					jiyiri.page.common.ReminderCategorySelector.ShowMode.SYSTEM_ONLY,
					jiyiri.page.common.ReminderCategorySelector.DataType.BIRTHDAY);

			this._submit_button.onclick = jiyiri.helper.eventhelper.EventHelper
					.create_callback_function(this, '_submit');

		},
		init_show : function(page_info) {
			this._page_info = page_info;

			this._date_inputer.show();
			this._birthday_category_selector.load_and_show();
			jiyiri.ui.ValidateImage.GetInstance().init_show(
					$('validate_image_ctl'), $('validate_image_reload_link'));
			jiyiri.ui.Beautifier.radio();
		},
		_submit : function() {
			this._hide_err();
			var name = $F('name');
			var sex = jiyiri.helper.htmlelementhelper.HTMLElementHelper
					.get_radio_value('sex');

			var birthday_y = this._date_inputer.get_year();
			var birthday_m = this._date_inputer.get_month();
			var birthday_d = this._date_inputer.get_day();
			var birthday_issolar = this._date_inputer.get_issolar();

			var category_rst = this._birthday_category_selector.get_result();

			if (category_rst.IsNone) {
				target_category = -11;
			} else {
				target_category = category_rst.SelectedCategory.Id;
			}

			var validate_image_code = $F('validate_image_code');

			var param = new jiyiri.helper.net.Parameter();
			param.add_param('name', name);
			param.add_param('sex', sex);
			param.add_param('birthday_y', birthday_y);
			param.add_param('birthday_m', birthday_m);
			param.add_param('birthday_d', birthday_d);
			param.add_param('birthday_issolar', birthday_issolar);
			param.add_param('target_category', target_category);
			param.add_param('validate_image_code', validate_image_code);
			param.add_param('key', this._page_info.InviteKey);

			if (this._check_form(param.get_params())) {
				jiyiri.helper.net.Form.post_tp('InviteFriend',
						'SaveVisitorBirthday', param);
			}

		},
		_check_form : function(param) 
		{
			var name = '';
			var birthday_m = 0;
			var birthday_d = 0;
			for (var i = 0; i < param.length; i++) 
			{
				if( param[i].Key == 'name' )
				{
					var name = param[i].Value;
				}
				if( param[i].Key == 'birthday_m' )
				{
					var birthday_m = param[i].Value;
				}
				if( param[i].Key == 'birthday_d' )
				{
					var birthday_d = param[i].Value;
				}
			}
			
			if(!jiyiri.helper.validatehelper.DataValidater.CheckEmpty( name ))
			{
				this._show_err('请填写提醒姓名');
				return false;
			}
			if(birthday_m == 0)
			{
				this._show_err('请选择日期');
				return false;
			}
			if(birthday_d == 0)
			{
				this._show_err('请选择日期');
				return false;
			}
			
			return true;
		},
		_show_err:function(msg)
		{
			Element.show('erronotice');
			$('erronotice').innerHTML = msg;
		},
		_hide_err:function()
		{
			Element.hide('erronotice');
		}
	};

	/* Codes End Here */

	/* Register Start Here */
	jiyiri.page.invitefriend.InputBirthdayUnloginedPage = InputBirthdayUnloginedPage;
	/* Register End Here */
})();
