var LogServerCount = {
	TYPE_VIEW   : 1,
	TYPE_CLICK  : 2,
	sessionName : 'ganji_uuid',
	rootUrl     : 'http://logserver.ganji.com/count/count.html',
	sourceTable : {
		adm                : 'adm', //广告
		sticky             : 'sticky', //自助置顶
		keyword_search     : 'ks', //关键词搜索点击统计 source_code=ks|[category_id]&source_id=[keyword]
		save_search_design : 'ssd', //保存搜索条件点击统计 source_code=ssd|[category_id]&source_id=
		favorite_search    : 'fs', //收藏的搜索条件点击统计 source_code=fs|[category_id]&source_id=
		visit_history      : 'vh', //浏览过的帖子点击统计 source_code=vh|[category_id]&source_id=
		same_kind          : 'sk', //同类型的信息点击统计 source_code=sk|[category_id]&source_id=
		same_price         : 'sp', //同价位的信息点击统计 source_code=sp|[category_id]&source_id=
		save_post		   : 'st',  //收藏帖子的点击统计 source_code=st|[category_id]&source_id=
		index_count_big_red_list   : 'icbrl',  //统计切换城市点击量 source_code=icbrl&source_id=bj
		index_count_list   : 'icl',  //统计切换城市点击量 source_code=icl&source_id=bj
		index_count_select : 'ics',  //统计切换城市点击量 source_code=ics&source_id=sh
		index_count_search : 'icsh',  //统计切换城市点击量 source_code=icsh&source_id=domain
		fang_list_tab_count: 'fltc',  //房产列表页tab点击量统计  source_code=fltc&source_id=
        fang_3day_count    : 'f3c',     //房产列表最近3天
        fang_no_message    : 'fnm',     //房产列表没数据“点击查看“点击统计
        fang_multi_area	   : 'fma', //房产多地标选择点击量统计 source_code=fma|category_id&source_id=&type=2
        fang_save_search   : 'fss', //房产保存搜索条件点击量统计 source_code=fss|category_id&source_id=&type=2
        fang_save_search_condition : 'fssc', //房产保存的搜索条件统计 source_code=fssc|[category_id]&source_id=[keyword]&type=1
        fang_rent_post_button : 'frpb', //出租房发布按钮AB测试统计
		get_password : 'gpwd', // 找回密码
		ajax_register : 'areg', // ajax注册
		ershouche_list_count   : 'eac', // 二手车个人转让列表页"点击查看一周内的商家车源"点击统计
		pub_select_link_count  : 'pslc', // 登录用户在发帖的选择信息类别页面最近两次发帖的类别点击统计  
		tuan_show_more         : 'more' , // 团购点击查看更多统计
		tuan_abtest            : 'tuanabt', // 团购AB测试访问统计
		tuan_setfav            : 'tuansetfav', // 团购点击加入收藏
		search_person_post:"spp",		// 全站查询个人信息    刘建明  source_code=spp&source_id=(1 or 2 )   
		wanted_list_sms_link:"wlsl",		// 全职招聘列表页短信订阅链接点击统计 zhoufan <zhoufan@staff.ganji.com>
        secondmarket_ab_test:'sm', //北京二手 列表页二行显示和一行显示统计，详细页显示电话号码和不显示电话号码统计
        detail_ditu_click:"ddc", //详情页地图点击统计
        school_days_click:'sdc', //开学赶集日招商页面广告点击统计
        category_search_words : 'csw', //大类选择页面类别搜索关键词统计
    	jingdong_click: 'jd', //京东广告点击统计
		jiayuan_click:'jy', //世纪佳缘点击统计
		wanted_search_words:'wsw', //全职招聘发布页类别搜索关键词统计
		sns_click : 'sc', //发布成功页面sns分享链接统计
		findjob_save_click : 'fjsc', //求职简历“保存到本地”点击统计
		mingqi_click : 'mingqi'	//名企招聘点击统计
	},

	getSessionId : function() 
	{
		var val = null, cookieArr;

		if (document.cookie && document.cookie != '') {
			cookieArr = document.cookie.match(new RegExp("(^| )"+LogServerCount.sessionName+"=([^;]*)(;|$)"));
			if(cookieArr != null) {
				val = decodeURIComponent(cookieArr[2]);
			}
		}

		return val ? val : '';
	},

	getUrl : function(sourceCode, sourceId, type, params)
	{
		var url = LogServerCount.rootUrl;
		url += url.indexOf('?') == -1 ? '?' : '&';		
		url += 'source_code=' + encodeURIComponent(sourceCode);
		url += '&source_id=' + encodeURIComponent(sourceId);
		url += '&type=' + (parseInt(type) != LogServerCount.TYPE_CLICK ? LogServerCount.TYPE_VIEW : LogServerCount.TYPE_CLICK);
		url += '&session_id=' + LogServerCount.getSessionId();
		if (params) {
			if (typeof params == 'string') {
				url += '&' + params;
			}
			else if (typeof params == 'object') {
				for (var i in params) {
					url += '&' + encodeURIComponent(i) + '=' + encodeURIComponent(params[i]);
				}				
			}
		}
		return url;

		$.getJSON(url+'&callback=?', function(data){});
	},

	getJSON : function(sourceCode, sourceId, type, params)
	{
		var url = LogServerCount.getUrl(sourceCode, sourceId, type, params);
		$.getJSON(url + '&callback=?', function(data){});
	},

	getSourceCode : function(key)
	{
		if (!LogServerCount.sourceTable[key]) {
			alert('不存在指定的key:"' + key + '"');
			return '';
		}

		var args = [].splice.call(arguments, 0, arguments.length);
		args[0] = LogServerCount.sourceTable[key];

		return args.join('|');
	},

	//自助置顶帖子点击统计 city_id:城市唯一id, major_category_id:一级小类唯一id
	stickyCount : function(post_id, city_id, major_category_id)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('sticky', city_id, major_category_id), post_id, 2);
	},

	//关键词搜索点击统计 category_id:大类唯一id, keyword:搜索关键词
	keywordSearchCount : function(category_id, keyword)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('keyword_search', category_id), keyword, 2);
	},

	//保存搜索条件点击统计 category_id:大类唯一id
	saveSearchDesignCount : function(category_id)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('save_search_design', category_id), '', 2);
	},

	//收藏的搜索条件点击统计 category_id:大类唯一id
	favoriteSearchCount : function(category_id)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('favorite_search', category_id), '', 2);
	},

	//浏览过的帖子点击统计 category_id:大类唯一id
	visitHistoryCount : function(category_id)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('visit_history', category_id), '', 2);
	},

	//收藏帖子的点击统计 category_id:大类唯一id
	savePostCount : function(category_id)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('save_post', category_id), '', 2);
	},

	//同类型的信息点击统计 category_id:大类唯一id
	sameKindCount : function(category_id)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('same_kind', category_id), '', 2);
	},

    /** {{{切换城市的城市点击统计 indexCountBigRedList domain:城市domain
     * @param  domain
     */
	indexCountBigRedList : function(domain)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('index_count_big_red_list'), domain, 2);
	},
    //}}}
    /** {{{切换城市的城市点击统计 indexCountList domain:城市domain
     * @param  domain
     */
	indexCountList : function(domain)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('index_count_list'), domain, 2);
	},
    //}}}
    /** {{{切换城市的城市点击统计 indexCountSelect
     * @param domain:城市domain
     */
	indexCountSelect : function(domain)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('index_count_select'), domain, 2);
	},
    //}}}
    /** {{{ 切换城市的城市点击统计 indexCountSearch
     * @param domain:城市domain
     */
	indexCountSearch : function(domain)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('index_count_search'), domain, 2);
	},
    //}}}
    /** {{{ 出租房列表tab点击数 fangListTabCount
     */
	fangListTabCount : function(category_id,agent)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('fang_list_tab_count',category_id), agent, 2);
	},
    //}}}
    /** {{{ 出租房列表tab点击数 fang3DayCount
     */
	fang3DayCount : function(category_id)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('fang_3day_count',category_id), '', 2);
	},
    //}}}
    /** {{{ 出租房列表tab点击数 fang3DayCount
     */
	fangNoMessage : function(category_id)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('fang_no_message', category_id), '', 2);
	},
    //}}}
	
	//房产列表页统计多地标点击数
	fangMultArea : function(category_id)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('fang_multi_area', category_id), '', 2);
	},
	
	fangSaveSearch : function(category_id)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('fang_save_search', category_id), '', 2);
	},
	
	fangSaveSearchCondition : function(category_id, condition)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('fang_save_search_condition', category_id), condition);
	},

	//同价位的信息点击统计 category_id:大类唯一id
	samePriceCount : function(category_id)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('same_price', category_id), '', 2);
	},
	
	userAjaxRegister : function() {
		LogServerCount.getJSON(LogServerCount.getSourceCode('ajax_register'), '', '');
	},
	
	userGetPassword : function() {
		LogServerCount.getJSON(LogServerCount.getSourceCode('get_password'), '', '');
	},
	
	//二手车个人转让列表页"点击查看一周内的商家车源"点击统计
	ershoucheListCount : function(domain)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('ershouche_list_count', domain), '', 2 );
	},
	
	//登录用户在发帖的选择信息类别页面最近两次发帖的类别点击统计
	pubSelectLinkCount : function(type)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('pub_select_link_count'), type, 2 );
	},
	
	//团购点击查看更多
	tuanShowMore : function(action)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('tuan_show_more'), action, 2 );
	},
	// 团购AB测试访问统计
	tuanABTest : function(action)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('tuan_abtest'), action, 1);
	},
	// 团购点击加入收藏
	tuanSetFav : function(action)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('tuan_setfav'), action, 2);
	},
	//详情页地图点击统计
	detailDituClick : function(action)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('detail_ditu_click'), action, 2 );
	},
	
	// 全站查询个人信息统计
	// @id 1. /site/u/  页面刷新统计
	// @id 2. /site/u/  点击查询按钮统计
	searchPersonPostCount : function(id)
	{
		var type=1;
		if( id > 1)
				type = 2; 
		LogServerCount.getJSON(LogServerCount.getSourceCode('search_person_post'), id, type );
	},
	
	/**
	 * 全职招聘列表页短信订阅链接点击统计
	 */
	wantedListSmsLinkCount : function()
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('wanted_list_sms_link'), '', 2 );
	},
    /**北京二手 列表页二行显示和一行显示统计，详细页显示电话号码和不显示电话号码统计
	 * ab:0为两行不显示 1为两行显示 2为一行不显示 3为一行显示 
	 * source_id:0为列表页 1为详情页
	 */
	secondmarket_ab_test : function(category_id,ab,source_id,type)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('secondmarket_ab_test',category_id,ab), source_id, type);
	},
	
	rent_post_button_ab_test : function(userType)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('fang_rent_post_button'), userType, 2);
	},
	
	schoolDaysAdClick : function(domain, adType)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('school_days_click', domain), adType, 2);
	},
	
	categorySearchWords : function(word)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('category_search_words'), word, 2);
	},
	
	jingdongAdClickCount : function(category_id)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('jingdong_click'), category_id, 2);
	},
	jiayuanLinkClickCount : function(type)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('jiayuan_click'), type, 2);
	},
	wantedSearchWords : function(word,type)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('wanted_search_words', word), type, 2);
	},
	
	snsClick : function(type, name)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('sns_click', type), name, 2);
	},
	findjobSaveCount : function(post_id, city_id, major_category_id)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('findjob_save_click', city_id, major_category_id), post_id, 2);
	},
	mingqiClick : function(id)
	{
		LogServerCount.getJSON(LogServerCount.getSourceCode('mingqi_click'), id, 2);
	}
};
