/***********************************
* 最优参数js
* auther:杨征<yangzheng@myhexin.com>
* Create:2011-07-11
************************************/

/**
 * 屏蔽错误
 * */
window.onerror = function (){
	return true;
};

/**
 * 参数设置的数据
 * */
var indexSets			= new Array();

/**
 * 指标参数原始设置
 * */
var indexInitSets		= new Array();

/**
 * 保存买卖点设置的数组对象
 * */
var checkArr			= new Array();

/**
 * 用户组
 * */
var ugroup				= '';

var advGoUrl			= '';

/**
 * 创建客户端js对象
 * */
try {
	var client = external.CreateObject('Util');
} catch (e) {
	var client = '';
}

try {
	var thsPassport = external.createObject('Passport');
	var client_userid = thsPassport.get('userid');
	var client_account = thsPassport.get('account');
} catch (e) {
	var client_userid = '';
	var client_account = '';
}

/**
 * 客户端版本号，如版本号是E027.90.10.0000，则得到79010
 * */
try {
	var version = client.getHxVer();
	if (version && version.length > 0) {
		version = version.split('.');
		var version0 = '';
		var version1 = '';
		var version2 = '';
		if (version[0] && version[0].length > 0) {
			version0 = version[0];
			version0 = version0.substr(3, 1);
		}
		
		if (version[1] && version[1].length > 0) {
			version1 = version[1];
		}
		
		if (version[2] && version[2].length > 0) {
			version2 = version[2];
		}
		
		version = version0 + version1 + version2;
	}
}catch (e) {
	var version = '';
}

/**
 * 初始化数据
 * */
var initInfo	= function () {
	/**
	 * 取客户端初始化接口
	 * 数据结构：userid;stockcode;period;当前的指标id{'name':'kdj','id':1706440};
	 * 所有的指标数据{'name':['macd', 'kdj', 'rsi'], 'id':[123, 1706440, 3148232]};
	 * 是否自定义参数;是否有最优参数;是否购买;最优参数k线买卖点显示标示;最优参数附图买卖点显示标示;
	 * 默认参数附图买卖点显示标示;是否ab股;股票名称；是否从最优参数标签进来
	 * */
	var clientInfo	= client.ParamSettingDlgInit();
	var tmp			= clientInfo.split(';');
	var info		= {};
	
	info.userid		= tmp[0];
	info.code		= tmp[1];
	info.period		= tmp[2];
	var indexs		= eval('(' + tmp[3] + ')');
	info.index		= indexs.id;
	info.indexName	= indexs.name;
	info.tabs		= eval('(' + tmp[4] + ')');
	info.isCustom	= parseInt(tmp[5]);
	info.hasBest	= tmp[6];
	info.isBuy		= tmp[7];
	info.isdkShow	= tmp[8];
	info.isdiShow	= tmp[9];
	info.isiShow	= tmp[10];
	info.isEvalua	= tmp[11];
	info.codeName	= tmp[12];
	info.isOptimal	= tmp[13];
	
	
	if (info.isCustom == 1) {
		$('#defaultParam').html('<input type="radio" id="defaultParamRadio" name="paramRadio"/><span>自定义参数</span>');
		$('#defaultCheck').hide();
		$('#restoreDefault').show();
	}

	if (typeof(info.tabs.name) != 'undefined') {
		for (var i in info.tabs.name) {
			indexSets['\'' + info.tabs.id[i] + '\'']	= new Array();
			if (info.tabs.name[i] == info.indexName) {
				$('#indexTabs').append('<li><a id="' + info.tabs.id[i] + '" href="javascript:void(0);" class="countulon">' + info.tabs.name[i] + '</a></li>');
			} else {
				$('#indexTabs').append('<li><a id="' + info.tabs.id[i] + '" href="javascript:void(0);" class="countul">' + info.tabs.name[i] + '</a></li>')
			}
		}
	}

	if (info.isdkShow == 1) {
		$('#kchart').attr('checked', 'checked');
	}

	if (info.isdiShow == 1) {
		$('#indexchart').attr('checked', 'checked');
	}

	if (info.isiShow == 1) {
		$('#dindexchart').attr('checked', 'checked');
	}
	
	/**
	 * 获取指标参数以及文本
	 * */
	info.params	= ParamSettingDlgGetIndexParam(info.index, info.period);
	
	checkArr['\'' + info.index + '\'']		= new Array();
	
	/**
	 * 取得用户组数据
	 * */
	var urlSearch	= location.search.split('ug=');
	if (typeof(urlSearch[1]) != 'undefined') {
		if (urlSearch[1].indexOf('&')) {
			var urlTmp	= urlSearch[1].split('&');
			if (typeof(urlTmp[0]) != 'undefined') {
				ugroup		= urlTmp[0];
			}
		}
	}
	
	
	date	= new Date();
	today	= date.getYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
	$.getScript('http://zycs.10jqka.com.cn/parameter/js/isconnect.js?' + today, function() {
        
	});
	
	return info;
};

/**
 * 取得参数设置的原始数据
 * */
var ParamSettingDlgGetIndexParam	= function (index, period) {
	var tmp		= client.ParamSettingDlgGetIndexParam(index, period);
	
	if (typeof(tmp) != 'undefined' && tmp != '') {
		var params	= eval('(' + tmp + ')');

		if(typeof(params) == 'object') {
			/**
			 * var params	= {'content':'DIFF：收盘价的Param#1天（短期)平滑移动平均值减去Param#2天（长期）平滑移动平均；\r\nDEA：DIFF的Param#3天平滑移动平均值\r\nMACD：2倍的（DIFF-DEA）。', 'param':[10,20,30], 'range':[[0, 30], [30, 50], [50, 60]]};
			 * */
			
			indexSets['\'' + index + '\'']	= params.param;
			indexInitSets					= params.param.slice(0);
			
			return params;
		}
	}
	return {};
};


/**
 * 重新初始化
 * */
var reInit	= function (index, name) {
	/**
	 * 取客户端初始化接口
	 * */
	var object		= {};
	object.index	= index;
	object.period	= info.period;
	var clientInfo2	= client.ParamSettingDlgInitForIndex(object);
	
	if (typeof(clientInfo2) != 'undefined' && clientInfo2 != '') {
		var tmp			= clientInfo2.split(';');
		info.index		= index;
		info.indexName	= name;
		info.isCustom	= tmp[0];
		info.hasBest	= tmp[1];
		info.isBuy		= tmp[2];
		info.isdkShow	= tmp[3];
		info.isdiShow	= tmp[4];
		info.isiShow	= tmp[5];
		info.isEvalua	= tmp[6];
		
		if (info.isCustom == 1) {
			$('#defaultParam').html('<input type="radio" id="defaultParamRadio" name="paramRadio"/><span>自定义参数</span>');
			$('#defaultCheck').hide();
		} else {
			$('#defaultParam').html('<input type="radio" id="defaultParamRadio" name="paramRadio"/><span>默认参数</span>');
			$('#defaultCheck').show();
		}

		if (info.isdkShow == 1) {
			$('#kchart').attr('checked', 'checked');
		} else {
			$('#kchart').attr('checked', false);
		}

		if (info.isdiShow == 1) {
			$('#indexchart').attr('checked', 'checked');
		} else {
			$('#indexchart').attr('checked', false);
		}

		if (info.isiShow == 1) {
			$('#dindexchart').attr('checked', 'checked');
		} else {
			$('#dindexchart').attr('checked', false);
		}
		
		/**
		 * 获取指标参数以及文本
		 * */
		info.params	= ParamSettingDlgGetIndexParam(info.index, info.period);

		checkArr['\'' + info.index + '\'']		= new Array();
	} else {
		Common.showMsg('切换指标失败');
	}
}


/**
 * 全局的数据信息对象
 * */
var info	= initInfo();

/**
 * 统计数据设置的数据对象
 * */
var statInfo	= {};
statInfo.ld		= 'client';
statInfo.nj		= 1;


(function () {
	
	/**
	 * 用户id
	 * */
	var userid				= 0;
	
	/**
	 * 指标
	 * */
	var index				= '';
	
	/**
	 * 股票代码
	 * */
	var stockCode			= '';
	
	/**
	 * 周期
	 * */
	var period				= '';
	
	/**
	 * 是否购买标志
	 * */
	var isBuy				= 0;
	
	/**
	 * 是否加载云计算页面标识
	 * */
	var isLoadEvaluHtml		= false;
	
	/**
	 * 是否有最优参数
	 * */
	var hasBestParam		= 1;
	
	/**
	 * 判断是否已经取得参数数据
	 * */
	var isGetParams			= false;
	
	
	/**
	 * 设置传入的参数
	 * */
	var init	= function () {
		this.userid		= info.userid;
		this.index		= info.index;
		this.period		= info.period;
		this.stockCode	= info.code;
		
		hasBestParam();
		
		if (this.hasBestParam == 1) {
			isBuy();
		}
	};
	
	/**
	 * 隐藏最优参数数据
	 * */
	var hiddenBestParam	= function () {
		$('#optimalParam').hide();
		$('#optimalParamRadio').attr('checked', false);
	};
	
	/**
	 * 改变指标操作
	 * */
	var changeIndex	= function (index) {
		info.index				= index;
		/**
		 * 重新设置测评数据标志位
		 * */
		this.isLoadEvaluHtml	= false;
	
		/**
		 * 重新初始化
		 * */
		init();
	};
	
	/**
	 * 是否有最优参数
	 * */
	var hasBestParam	= function () {
		this.hasBestParam	= info.hasBest;
	};
	
	/**
	 * 设置是否购买标志位
	 * */
	var isBuy	= function () {
		this.isBuy	= info.isBuy;
		return this.isBuy;
	};
	
	/**
	 * 取得参数设置数据
	 * */
	var getParamInfo	= function () {
		if (typeof(info.params.param) != 'undefined') {
			var count	= info.params.param.length;
			var content	= '';
			
			for (var i = 0; i < count; i++) {
				content	= info.params.content.replace('Param#' + (parseInt(i) + 1), '<span class="custom_input"><input id="p' + i + '" type="text" onkeyup="changeValueInput(\'' + i + '\', event)" value="' + info.params.param[i] + '" /><a href="javascript:void(0);" onmousedown="changeValue(\'' + i + '\', 1);" onmouseup="window.clearInterval(iTimerA);" onmouseout="if (typeof(iTimerA)  != \'undefined\' ) {window.clearInterval(iTimerA);}"  class="plus">+</a><a href="javascript:void(0);" onmousedown="changeValue(\'' + i + '\', -1);" onmouseup="window.clearInterval(iTimerA);" onmouseout="if (typeof(iTimerA) != \'undefined\' ) {window.clearInterval(iTimerA)};" class="minus">-</a></span>');
				content	= content.replace('\r\n', "</li><li>");
				content	= content.replace('<br >', "</li><li>");
				content	= content.replace('<BR >', "</li><li>");
				//content	= content.replace('<br >', "</li><li>");
				
				info.params.content	= content;
			}
			
			var content2 = info.params.content;
			if (content2.substring(0, 4) != '<li>') {
				info.params.content = '<li>' + info.params.content + '</li>';
			}
			
			$('#defaultParamInfo').empty().html(info.params.content);
			$('#defaultParamInfo').append('<li class="effect"><span class="gray">（改变一下参数值能立即查看效果）</span><a id="restoreDefault" href="javascript:void(0)" class="d-default" onclick="ParamSettingDlgResumeDefaultParam();" style="display:none;"></a></li>');
			
			if (info.isCustom == 1) {
				$('#restoreDefault').show();
			} else {
				$('#restoreDefault').hide();
			}
		} else {
			$('#defaultShow').hide();
		}
	};
	
	
	/**
	 * 显示流程
	 * */
	var showProcess		= function () {
		/**
		 * 是否有最优参数
		 * */
		if (this.hasBestParam == 1) {
			
			if (info.isOptimal == 1) {
				/**
				 * 从最优参数标签进来
				 * */
				$('#optimalParam').removeClass();
				$('#optimalParam').show();
				$('#optimalParamRadio').attr('checked', 'checked');
				$('#optimalShow').show();
				if (info.isBuy) {
					$('#optimalCheck').show();
				} else {
					$('#optimalCheck').hide();
				}
				
				$('#defaultParam').removeClass();
				$('#defaultParam').addClass('white');
				$('#defaultShow').hide();
				
			} else {
				/**
				 * 从默认参数标签进来
				 * */
				$('#defaultParam').removeClass();
				$('#defaultParamRadio').attr('checked', 'checked');
				$('#defaultShow').show();
				
				$('#optimalParam').removeClass();
				$('#optimalParam').addClass('white');
				$('#optimalShow').hide();
				
				getParamInfo();
			}
			
		} else {
			/**
			 * 只有默认参数
			 * */
			$('#defaultParam').removeClass();
			$('#defaultParamRadio').attr('checked', 'checked');
			$('#defaultShow').show();
			
			$('#optimalParam').hide();
			$('#optimalShow').hide();
			
			getParamInfo();
		}
	};
	
	/**
	 * 设置显示模式
	 * */
	var setShowParam	= function () {
		/**
		 * 点击切换指标
		 * */
		$('#indexTabs > li > a').click(function () {
			if ($(this).attr('class') != 'countulon') {
				/**
				 * 重新初始化
				 * */
				reInit($(this).attr('id'), $(this).html());
				
				$('#indexTabs li a').removeClass();
				$(this).addClass('countulon');
				indexSets['\'' + info.index + '\'']	= info.params.param;
				
				$('#defaultShow').hide();
				$('#optimalShow').hide();
				
				init();
				
				showProcess();
			}
		});
		
		/**
		 * 断网显示广告图片
		 * */
		if (typeof(connect) == 'undefined') {
			if (info.isBuy == 0) {
				$('#optimalShow').empty().html("<img src='img/outline.gif' />").show();
			}
		}
		
		showProcess();
		
		$('#tal > label').click(function () {
			if ($(this).attr('class') == 'white') {
				$('#tal > label').removeClass();
				$('#tal > label').addClass('white');
				$(this).toggleClass('white');
				
				var lableId = $(this).attr('id');
				$('#' + lableId + 'Radio').attr('checked', 'checked');
				
			}
			
			if ($(this).attr('id') == 'optimalParam') {
				init();
				
				$('#optimalShow').show();
				if (info.isBuy == 1) {
					$('#optimalCheck').show();
				} else {
					$('#optimalCheck').hide();
				}
				
				$('#defaultShow').hide();
				
				//统计
				TA.log({'id':'zy515' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
			} else {
				$('#defaultShow').show();
				if (info.isCustom == 1) {
					$('#defaultCheck').hide();
					$('#restoreDefault').show();
				} else {
					$('#defaultCheck').show();
					$('#restoreDefault').hide();
				}
				
				$('#optimalShow').hide();
				getParamInfo();
				
				//统计
				TA.log({'id':'zy516' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
			}
		});
	};
	
	
	/**
	 * 设置a标签的点击移除焦点
	 * */
	var setABlur	= function () {
		$('a').click(function (){
			$(this).blur();
		});
	};
	
	/**
	 * 初始化一些元素的点击事件，包括记录统计
	 * */
	var initItemClick = function () {
		/**
		 * 风格设置
		 * */
		$('#fgsz').click(function(){
			client.ParamSettingDlgStyleSetting(info.index);
			//统计
			TA.log({'id':'zy527' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
		});
		
		/**
		 * 指标说明
		 * */
		$('#indexExplain').click(function(){
			client.ParamSettingDlgFuncReadme(info.index);
			//统计
			TA.log({'id':'zy528' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
		});
		
		/**
		 * 确定按钮
		 * */
		$('#submit').click(function(){
			setParamsInfo();
				
			/**
			 * 判断是最优下的提交还是默认下的提交
			 * */
			if ($('#besttd_radio').attr('checked') == 'checked') {
				//统计
				TA.log({'id':'zy529' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
			} else {
				//统计
				TA.log({'id':'zy530' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
			}
		});
		
		/**
		 * 取消按钮
		 * */
		$('#cancel').click(function(){
			client.ParamSettingDlgCancel();
			Common.closeWin();
			
			/**
			 * 判断是最优下的提交还是默认下的提交
			 * */
			if ($('#besttd_radio').attr('checked') == 'checked') {
				//统计
				TA.log({'id':'zy531' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
			} else {
				//统计
				TA.log({'id':'zy532' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
			}
		});
		
	}
	
	
	
	$(document).ready(function (){
		init();
		setShowParam();
		setABlur();
		
		//初始化一些基本元素的点击事件
		initItemClick();
		
		try {
			//页面统计
			TA.log({'id':'zy005' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
		} catch (e) {
			
		}
	});

})();


/**
 * 设置买卖点标示数据
 * */
var setChart	= function (type, val) {

	if (type == 'default') {
		
		if ($('#dindexchart').attr('checked') == 'checked') {
			checkArr['\'' + info.index + '\'']['default'] = 1;
			//统计
			TA.log({'id':'zy517' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
		} else {
			checkArr['\'' + info.index + '\'']['default'] = 0;
			//统计
			TA.log({'id':'zy518' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
		}
	}

	if (type == 'best') {
		checkArr['\'' + info.index + '\'']['best']	= new Array();

		/**
		 * 设置日K线
		 * */
		if ($('#kchart').attr('checked') == 'checked') {
			checkArr['\'' + info.index + '\'']['best']['k']	= 1;
			//统计
			TA.log({'id':'zy519' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
		} else {
			checkArr['\'' + info.index + '\'']['best']['k']	= 0;
			//统计
			TA.log({'id':'zy520' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
		}
		
		/**
		 * 设置指标图
		 * */
		if ($('#indexchart').attr('checked') == 'checked') {
			checkArr['\'' + info.index + '\'']['best']['f']	= 1;
			//统计
			TA.log({'id':'zy521' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
		} else {
			checkArr['\'' + info.index + '\'']['best']['f']	= 0;
			//统计
			TA.log({'id':'zy522' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
		}
	}

};

/**
 * 改变指标参数的值
 * */
var changeValue	= function (id, val) {
	var value	= parseInt($('#p' + id).val()) + parseInt(val);
	
	var min		= parseInt(info.params.range[id][0]);
	var max		= parseInt(info.params.range[id][1]);

	if (value > max) {
		value	= max;
	} else if(value < min) {
		value	= min;
	}

	$('#p' + id).val(value);

	indexSets['\'' + $('.countulon').attr('id') + '\''][id]	= value;

	var inData		= {};
	inData.index	= parseInt(info.index);
	inData.period	= parseInt(info.period);
	inData.param	= indexSets['\'' + $('.countulon').attr('id') + '\''];

	client.ParamSettingDlgSetIndexParam(inData);

	iTimerA = window.setInterval('longPressChangeValue(\'' + id + '\',' + val + ')', 150);
	
	//统计
	if (id == 0 && val == 1) {
		TA.log({'id':'zy563' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
	} else if (id == 0 && val == -1) {
		TA.log({'id':'zy564' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
	} else if (id == 1 && val == 1) {
		TA.log({'id':'zy565' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
	} else if (id == 1 && val == -1) {
		TA.log({'id':'zy566' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
	} else if (id == 2 && val == 1) {
		TA.log({'id':'zy567' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
	} else if (id == 2 && val == -1) {
		TA.log({'id':'zy568' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
	}
	
};

/**
 * 通过input框改变参数值
 * */
var changeValueInput = function (id, event) {
	var keyCode = event.keyCode || event.which || event.charCode;
	
	var value	= $('#p' + id).val();
	if (value.length <= 0) {
		return;
	}
	
	var value = parseInt(value);
	
	var min		= parseInt(info.params.range[id][0]);
	var max		= parseInt(info.params.range[id][1]);

	if (isNaN(value)) {
		$('#p' + id).blur();
		Common.showMsg('此处只能输入数字，请重新输入');
		
		//统计
		if (id == 0) {
			TA.log({'id':'zy570' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
		} else if (id == 1) {
			TA.log({'id':'zy572' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
		} else if (id == 2) {
			TA.log({'id':'zy574' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
		}
		
		return;
	}
	
	
	if (value > max || value < min) {
		$('#p' + id).blur();
		Common.showMsg('该指标参数值范围是' + min + '-' + max + '，请重新输入');
		
		//统计
		if (id == 0) {
			TA.log({'id':'zy570' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
		} else if (id == 1) {
			TA.log({'id':'zy572' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
		} else if (id == 2) {
			TA.log({'id':'zy574' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
		}
		
		return;
	}

	$('#p' + id).val(value);

	indexSets['\'' + $('.countulon').attr('id') + '\''][id]	= value;

	var inData		= {};
	inData.index	= parseInt(info.index);
	inData.period	= parseInt(info.period);
	inData.param	= indexSets['\'' + $('.countulon').attr('id') + '\''];

	client.ParamSettingDlgSetIndexParam(inData);

	iTimerA = window.setInterval('longPressChangeValue(\'' + id + '\',' + val + ')', 150);

	//统计
	if (id == 0) {
		TA.log({'id':'zy569' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
	} else if (id == 1) {
		TA.log({'id':'zy571' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
	} else if (id == 2) {
		TA.log({'id':'zy573' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
	}

}


/**
 * 长按按钮时的响应
 * */
var longPressChangeValue	= function (id, val) {
	var value	= parseInt($('#p' + id).val()) + parseInt(val);

	var min		= parseInt(info.params.range[id][0]);
	var max		= parseInt(info.params.range[id][1]);

	if (value > max) {
		value	= min;
	} else if(value < min) {
		value	= max;
	}

	$('#p' + id).val(value);

	indexSets['\'' + $('.cur').attr('id') + '\''][id]	= value;

	var inData		= {};
	inData.index	= parseInt(info.index);
	inData.period	= parseInt(info.period);
	inData.param	= indexSets['\'' + $('.cur').attr('id') + '\''];
	
	client.ParamSettingDlgSetIndexParam(inData);
};


/**
 * 设置指标参数数据给客户端
 * */
var setParamsInfo	= function () {
	var param	= '';
	var inData	= {};
	
	/**
	 * 设置的买卖点显示标示数据
	 * */
	var point	= {};

	for (var k in checkArr) {
		
		if (typeof(checkArr[k]['default']) != 'undefined') {
			var len			= k.length;
			point.index		= parseInt(k.substr(1).substr(0, len - 2));
			point.period	= parseInt(info.period);
			point.stockcode	= info.code;
			point.bshow		= checkArr[k]['default'];

			client.ParamSettingDlgShowDefMinorCurveTradePoint(point);
		}

		if (typeof(checkArr[k]['best']) != 'undefined') {
			if (typeof(checkArr[k]['best']['k']) != 'undefined') {
				var len			= k.length;
				point.index		= parseInt(k.substr(1).substr(0, len - 2));
				point.period	= parseInt(info.period);
				point.stockcode	= info.code;
				point.bshow		= checkArr[k]['best']['k'];

				client.ParamSettingDlgShowOptMainCurveTradePoint(point);
			}

			if (typeof(checkArr[k]['best']['f']) != 'undefined') {
				var len			= k.length;
				point.index		= parseInt(k.substr(1).substr(0, len - 2));
				point.period	= parseInt(info.period);
				point.stockcode	= info.code;
				point.bshow		= checkArr[k]['best']['f'];

				client.ParamSettingDlgShowOptMinorCurveTradePoint(point);
			}
		}
	}

	Common.closeWin();
};


/**
 * 恢复默认参数
 * */
var ParamSettingDlgResumeDefaultParam	= function () {

	var result = eval('(' + client.ParamSettingDlgResumeDefaultParam(info.index) + ')');

	if (typeof(result) != 'undefined' && result != '') {
		for (var i in result) {
			$('#p' + i).val(result[i]);
		}

		$('#defaultParam').html('<input type="radio" id="defaultParamRadio" name="paramRadio" checked="checked"/><span>默认参数</span>');
		info.isCustom = 0;
		
		$('#defaultCheck').show();
		
	} else {
		Common.showMsg('恢默认参数失败');
	}
	
	//统计
	TA.log({'id':'zy523' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
};


var Common	= (function () {
	return {
		showMidDiv	: function(idname) {
			var isIE	= (document.all) ? true : false;
			var isIE6	= isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 6);
			var newbox	= document.getElementById(idname);

			newbox.style.zIndex		= "9999";
			newbox.style.display	= "block"
			newbox.style.position 	= !isIE6 ? "fixed" : "absolute";
			newbox.style.top 		= newbox.style.left	= "50%";
			newbox.style.marginTop 	= - newbox.offsetHeight / 2 + "px";
			newbox.style.marginLeft	= - newbox.offsetWidth / 2 + "px";
			newbox.style.display	= 'block';
		},

		hide	: function (id) {
			$('#' + id).hide();
			$('#mask').hide();
		},

		showMsg	: function (msg) {
			if (msg != '') {
				$('#mask').show();
				$('#messages').html(msg);
				Common.showMidDiv('msg');
			}
		},
		
		hideMsg : function (url) {
			$('#mask').hide();
			$('#msg2').hide();
			if (typeof(url) != 'undefined') {
				client.ParamSettingDlgDetailReport(url, 1);
				$('#mask').hide();

				//统计
				TA.log({'id':'zy503' + ugroup, 'ld': statInfo.ld, 'nj':statInfo.nj, 'version':version, 'client_userid':client_userid, 'client_account':client_account});
			} else {
				Common.showMidDiv('buyFailure');
			}
		},

		closeWin	: function () {
			window.location	= "hxa://hexin.exe 'opt=8&param='";
		}
	};
})();

