jiyiri.register_namespace('jiyiri.page.common.widget');

/* jiyiri.require_once('jiyiri.date.SolarLunarHelper'); */
/* jiyiri.require_once('jiyiri.date.Output'); */
/* jiyiri.require_once('jiyiri.helper.net.Ajax'); */
/* jiyiri.require_once('jiyiri.helper.eventhelper.EventHelper'); */
/* jiyiri.require_once('jiyiri.helper.json.JSON'); */
jiyiri.require_once('jiyiri.page.common.commondialog');

( function() {
	var Header = Class.create();
	Header._instance = null;
	Header.GetInstance = function() {
		if (null === Header._instance) {
			Header._instance = new Header();
		}
		return Header._instance;
	};
	Header.prototype = {
		initialize : function() {
			this._header_widget_info = null;
		},
		init_show : function() {
			//this._process_date();
			this._process_login_status();
			
		},
		show_shopping_cart:function()
		{
			var info = this._header_widget_info;
			if(!info.IsLogined)
			{
				jiyiri.page.common.CommonDialog.login('cart');
			}
			else
			{
				location.href= __APP__ + '/Cart/CartList';
			}
		},
		/**
		 * deprate
		 */
		_process_date : function() {
			var today_solar = jiyiri.date.DateObject.GetToday(true);
			var today_lunar = jiyiri.date.DateObject.GetToday(false);
			var today_lunar_str = jiyiri.date.Output.to_string(today_lunar,'农历#M#月#D#');
			var today_solar_str = today_solar.Year + '年' + today_solar.Month + '月' + today_solar.Day + '日'
            var weekday_str = jiyiri.date.Output.weekday_string(today_solar);

            //$('header-today-weekday').innerHTML = weekday_str;
            $('header-today-solar').innerHTML = today_solar_str;
            $('header-today-lunar').innerHTML = today_lunar_str;
		},
		_process_shopping_cart:function()
		{
			var info = this._header_widget_info;
			var count = info.ShoppingCartCount;
			$('header_shopping_cart_count').innerHTML = '(共有' + count + '件商品)';
		},
		_process_login_status : function() {
			jiyiri.helper.net.Ajax.get_tp('DataInterface',
					'GetHeaderWidgetInfo', null,
					jiyiri.helper.eventhelper.EventHelper
							.create_callback_function(this,
									'_load_widget_data_complete'));
		},
		_load_widget_data_complete : function(response) {
			var info = jiyiri.helper.json.JSON.parse(response.responseText);
			this._header_widget_info = info;
			this._show_login_status();
		},
		_show_login_status : function() {
			var info = this._header_widget_info;
			var html = '';
			if (!info.IsLogined) {
				html += '<a href="javascript:void(0);" onclick="javascript:jiyiri.page.common.CommonDialog.login(\'reminder\');">登录</a>';
				html += ' | ';
				html += '<a href="javascript:void(0);" onclick="javascript:jiyiri.page.common.CommonDialog.regist(\'reminder\');">注册</a>';
			} else {
				html += '<a href="'+ __APP__+ '/User/SetupBasic">设置</a>';
				html += ' | '
				html += '<a href="' + __APP__ + '/User/Protal">用户中心</a>';
				html += ' | ';
				//html += '<a href="'+ __APP__+ '/User/SetupBasic">设置</a>';
				//html += ' | '
				//html += '<a href="'+ __APP__+ '/UserOrderCenter/Lists">订单管理</a>';
				//html += ' | '
				//html += '<a href="'+ __APP__+ '/UserCardCenter/">我的贺卡</a>';
				//html += ' | '
				html += '<a href="'+ __APP__ + '/User/Logout">退出</a>';
			}
			//html = '<li class="utilityBorder"><!----></li>' + html + '<li class="utilityBorder"><!----></li>';

			$('header-login-status').innerHTML = html;

			this._process_shopping_cart();
		}
	};

	/* 命名空间注册 */
	jiyiri.page.common.widget.Header = Header;
})();