var OfflineFee = (function(){
	var layout = $('#offlineFee'),
		//offlineFeeBtn = $('.offlineFeeBtn'),
		confirmBtn = layout.find('.confirm'),
		qixian = layout.find('select'),
		closeBtn = layout.find('.pur5_mask_close'),
		fee = layout.find('.fee'),
		isShow, isSubmit,
		source;
		
	return {
		init: function(){
			var self = this;
			confirmBtn.click(function(){
				self.submit();
			});
			
			qixian.change(function(){
				fee.text(this.value);
			});
		},
		show: function(sourceStr){
			if(isShow) return false;
			isShow = true;
			
			source = sourceStr;
			$.ajax({
				url: pur5.Cfg.GBHOSTSOFT + 'offline/offlinePay.asp',
				dataType: 'json',
				data: {
					action: 'price',
					source: source,
					token: pur5.Cfg.token
				},
				success: function(Result){
					qixian.html('');
					$.each(Result.values, function(key, val){
						qixian.append(
							'<option value="' + val + '">' + key + '</option>'
						);
					});
					
					qixian.triggerHandler('change');
					
					pur5.Pages.alert(layout[0]);
				},
				error: function(jqXhr, textStatus){
					ajaxError('读取托管缴费价格', jqXhr, textStatus);
				},
				complete: function(){
					isShow = false;
				}
			});
		},
		submit: function(){
			if(isSubmit) return false;
			isSubmit = true;
			
			var self = this
			var month = qixian.find(':selected').text().match(/^(\d+)/)[1];
			
			$.ajax({
				url: pur5.Cfg.GBHOSTSOFT + 'offline/offlinePay.asp',
				dataType: 'json',
				data: {
					action: 'buy',
					months: month,
					source: source,
					token: pur5.Cfg.token
				},
				success: function(Result){
					if(Result.message == ''){
						alert('续费成功！');
						closeBtn.triggerHandler('click');
						if(source == 'taobao'){
							TaobaoOffline.getList();
						}else if(source2 = 'paipai'){
							PaiPaiOffline.getList();
						}
					}else{
						alert(Result.message);
					}
				},
				error: function(jqXhr, textStatus){
					ajaxError(source + '离线托管缴费', jqXhr, textStatus);
				},
				complete: function(){
					isSubmit = false;
				}
			});
		}
	}
})();
$(function(){
	$.include('scripts/', 'inc/function.js', function(){
		OfflineFee.init();
	});
});