//关注列表js
//var basepath=G_TGPATH;//文件路径基地址
var G_StockCode = new Object(); //具体股票的关注信息
var stockFocusAllObj;//股票关注所有信息
var AllUserState;//获取当前经纪人所有用户在线状态
var userinfo=[];//用户在线状态
var StockCode="";//股票市场代码
var xmlhttps;//异步刷新用对象
var REFRESHTIME = 0;//刷新间隔已分钟为单位
var result = null;//返回结果
//取出数据源
function loadData(){
	userinfo = getSysUser();
	result = null;
	var xmlHttp=null;	
	try{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");	   
	}catch (e){
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");		
	}
	var rdata = G_TGPATH();
	if (rdata == "")
	{
		return {};
	}
	var url = rdata +"/file/stockFocus.do?bid=" + userinfo[0] + "&qsid=" + userinfo[2] + "&time="+new Date().getTime();
	xmlHttp.open("GET",url,false);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.send();
	var data=xmlHttp.responseText;		
	result = eval('('+ data +')');  
	try{
		return result;
	}finally{
		data = null;
		url = null;
		xmlHttp = null;
	}
}

//----------------------------------------------------
// 工具的方法
//----------------------------------------------------
function getRequest()
{
	var xmlhttp = null;
	if (window.XMLHttpRequest)
	{
		// code for all new browsers
		xmlhttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		// code for IE5 and IE6
		xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
	}
	if(!xmlhttp)
	{
		throw 'request object initialize fail!';
	}
	try{
		return xmlhttp;
	}finally{
		xmlhttp = null;
	}
}


function ajax_load(url, async, callback,args)
{
	var req = getRequest();
	var callURL = url;//ajax_url_random(url);
	var callbackfn = callback;
	req.open('GET', callURL, async);
	req.onreadystatechange = function()
	{
		if(req.readyState==4)
		{
			if(req.status == 200)
			{
				callbackfn(req.responseText,args);
				callbackfn = null;
				req = null;
			}
		}
	};
	req.send(null);
	callURL = null;
	if (async == false)
	{
		callbackfn = null;
		req = null;
	}
}

//获取经纪人的用户列表
//type=1全部,2名字id,3名字和在线状态
function loadCustomer(type,qsid,bid){
	result = null;
	var sqsid = qsid;//券商编号
	var sbid = bid;//经纪人编号
	
	if (qsid == null || qsid == "") //如果传入的券商ID不为空则认为直接从远程获取信息，跳过检查本地缓存
	{
		userinfo = getSysUser();
		sqsid = userinfo[2];
		sbid = userinfo[0];
		var odata = client_data_load("MC:" + type.toLowerCase() + ":" + sqsid.toLowerCase() + ":" + sbid.toLowerCase(),"0");
		if (odata != null)
		{
			var now = new Date();
			var df=(now.getTime()-odata.TimeStamp.getTime())/60/1000; 
			if (df < REFRESHTIME)
			{
				AllUserState = eval('('+ odata.dValue +')');  					
				LoadFile();//加载json数据文件
				LoadInvestorDate();
				df = null;
				now = null;
				odata = null;
				sbid = null;
				sqsid = null;
				return ;		
			}
		}
	}
	var rdata = G_TGPATH();
	if (rdata == "")
	{
		return {};
	}
	var url = rdata +"/inter/qurcustomerlist.do?qsid=" + sqsid + "&bid=" + sbid + "&type=" + type + "&time="+new Date().getTime();
	var fnsetPageData = setPageData;
	var args = {};
	args.sqsid = sqsid;
	args.type = type;
	args.sbid = sbid;
	ajax_load(url,true,fnsetPageData,args);
	args = null;
	//fnsetPageData = null;
	url = null;
	odata = null;
	sbid = null;
	sqsid = null;
}
//回调函数，获得从服务器回发的文档信息并显示在disp层中
function setPageData(data,args){
	if (args.sqsid != null || args.sqsid != "") //如果传入的券商ID不为空则认为直接从远程获取信息，跳过保存本地缓存
	{		
		client_data_save("MC:" + args.type.toLowerCase() + ":" + args.sqsid.toLowerCase() + ":" + args.sbid.toLowerCase(),"1",data,"0");
	} 	
	AllUserState = eval('('+ data +')');  		
	LoadFile();//加载json数据文件
	LoadInvestorDate();
	args.sqsid = null;
	args.type = null;
	args.sbid = null;
}


//装载关注股票信息数据
function load_UserData(mk,code)
{
	StockCode=mk+code;
	loadCustomer("3","","");//获取用户在线状态和姓名
}
//加载所有股票关注信息
function load_stockFocusData()
{
	stockFocusAllObj = loadData();//读取json数据
}
//读取经纪人
function getSysUser()
{
	var obj = client_core_interface();
	var ret = obj.r("G_SYS_UserName", "");
	try{
		return ret.split("\r\n");
	}finally{
		ret = null;
		obj = null;
	}
}
//加载json数据文件
function LoadFile()
{	
	//取某只股票关注信息	
	var stockFocusObj = stockFocusAllObj[StockCode];//正常		
	var stockFocus = new Object();	
	if(stockFocusObj!=undefined || stockFocusObj!=null)
	{		
		stockFocus.UserCount = stockFocusObj.b;//关注人数			
		//详细信息
		var details = stockFocusObj.c;
		for(var i=0; i<details.length; i++)
		{		
			var obj = details[i];
		 	var tmpstates = Get_CustomerStates(obj.ca).split(",");//用户名称
		 	
			obj.id = obj.ca;	//用户id		
			obj.zy = obj.cc;    //用户自选标记
			obj.count = obj.cb;	//用户关注次数	
			
			obj.name = tmpstates[0];    //用户姓名
			obj.Status = tmpstates[1];	//用户是否在线		
		}		
		stockFocus.users=details;
		G_StockCode=stockFocus;	
	}
	else
	{
		G_StockCode=null;
	}
	
}

//获取客户状态（名字，在线状态）
function Get_CustomerStates(custumerID){
	var CustomerName=custumerID+",0";//默认值
	if(AllUserState.length>0)
	{
		for (var i=0; i < AllUserState.length; i++)
		{
			var brokerid = (AllUserState[i].id).toLowerCase();
			var tmpnm = AllUserState[i].nm;			
			if(custumerID.toLowerCase() == brokerid)
			{
				CustomerName = tmpnm + ","+AllUserState[i].ol;			
				break;
			}			
		}
	}	
	return CustomerName;
}
//获取当前视图对应商品信息
function getCurrStock()
{
	var obj = client_core_interface();
	var data=obj.r("G_View_PrevNextStock","O");	
	try{
		return data;
	}finally{
		data = null;
		obj = null;
	}
}

// 取消息中心版本
function ShowVersion()
{
	var obj = client_core_interface();
	var data = obj.r("G_MSG_VERSION","");
	try{
		return data;
	}finally{
		data = null;
		obj = null;
	}
}
//邮件中心跳转
function OpenMailCenter(param)
{
	var obj = client_core_interface();
	var data = obj.r("S_MSG_OPENMAINWND",param);
	data = null;
	obj = null;
}