var cal_arrMark; // 放置标记的数组
var stock_hold, stock_self;
var stock_hold_hash, stock_self_hash;

function load_stocklist()
{
	stock_self_hash = new Object();
	stock_hold_hash = new Object();
	try
	{
		stock_self = client_stock_selflist(0);
		if (stock_self != null)
		{
			for (var i = 0; i < stock_self.length; i++)
			{
				stock_self[i].FullCode = stock_self[i].Market
					+ stock_self[i].StockCode;
				stock_self_hash[stock_self[i].FullCode] = 1;
			}
		}

		/*
		 * var StockDataInfo = client_wt_holdstocks( "ExchangeNum|StockCode" ,
		 * "StockCode" , 3 , 1 , 10000 ) ; StockDataInfo = [ {"ExchangeNum":
		 * '1', "StockCode": '600000'}, {"ExchangeNum": '1', "StockCode":
		 * '600019'}, {"ExchangeNum": '2', "StockCode": '000002'},
		 * {"ExchangeNum": '2', "StockCode": '000009'} ] if( StockDataInfo ==
		 * null || StockDataInfo.length == 0 ) return;
		 * 
		 * stock_hold = new Array(); for( var i=0 ; i<StockDataInfo.length ;
		 * i++ ) { var pObj = new Object() ; pObj.Market = "SH" ; if(
		 * StockDataInfo[i]["ExchangeNum"] != undefined &&
		 * (StockDataInfo[i]["ExchangeNum"] == "2" ||
		 * StockDataInfo[i]["ExchangeNum"] == "4" ) ) { pObj.Market = "SZ" ; }
		 * pObj.StockCode = StockDataInfo[i]["StockCode"] ; pObj.FullCode =
		 * pObj.Market + pObj.StockCode; stock_hold.push(pObj); }
		 */

		if (stock_self == null)
			stock_self = new Array();
		if (stock_hold == null)
			stock_hold = new Array();
	}
	catch (e)
	{
		_trace("出错(GetHoldStockList()):" + e.message);
		return;
	}
}

/*
 * function refresh_holdstocks(s1) {
 * 
 * var strStkNames = "" ; var strStkHoldAmount = "" ; var strOtherAmount = 0.0 ;
 * var fTotalProfit = 0.0 ; //总计盈利
 * 
 * //取得前100个持仓的商品 var StockDataInfo = client_wt_holdstocks(
 * "ExchangeNum|ExchangeName|StockCode|StockName|InBalance|MarketVal" ,
 * "MarketVal" , 2 , 1 , 1000 ) ; var iCurStockNo = 1 ; var totalamount = 0;
 * for( var p=0 ; StockDataInfo!=null && p<StockDataInfo.length ; p++ ) { if(
 * StockDataInfo[p]["MarketVal"] == undefined ) continue ; //无效数据
 * 
 * var tmpStkName = StockDataInfo[p]["StockName"] ;
 * 
 * var tmpStkData = parseFloat(StockDataInfo[p]["MarketVal"]) ; if(
 * isNaN(tmpStkData) ) continue ; totalamount += tmpStkData;
 * 
 * if( iCurStockNo >= 10 ) strOtherAmount += tmpStkData ; else { strStkNames +=
 * tmpStkName + "," ; strStkHoldAmount += tmpStkData.toString() + "," ; }
 * if(StockDataInfo[p]["InBalance"] != undefined ) { var tmpF =
 * parseFloat(StockDataInfo[p]["InBalance"]) ; if( !isNaN(tmpF) ) fTotalProfit +=
 * tmpF ; }
 * 
 * iCurStockNo++ ; }
 * 
 * if( strStkNames.length > 0 ) { if( strOtherAmount > 0 ) //含有其他的 { strStkNames +=
 * "其他" ; strStkHoldAmount += strOtherAmount.toString() ; } else { strStkNames =
 * strStkNames.substring(0,strStkNames.length-1) ; strStkHoldAmount =
 * strStkHoldAmount.substring(0,strStkHoldAmount.length-1) ; }
 * 
 * $("#holdstocksvalue") .text(totalamount.toString()) ; $("#holdstocksprofit")
 * .text(fTotalProfit.toString()) ; if( fTotalProfit<0 ) {
 * $("#holdstocksprofit") .removeClass("highlight2") .addClass("highlight3"); }
 * else { $("#holdstocksprofit") .removeClass("highlight3")
 * .addClass("highlight2"); }
 * 
 * var data = { key: { values: strStkNames }, serial: [ { values:
 * strStkHoldAmount } ] }; var style = { margin: 5, legend: { dock: "right",
 * align: "center", margin: "0,15", keywidth:1.5 }, chart: { unit: "元", slice:
 * "1", scale: 1, pieheight: 0, labelformat: "{2} ({1})\n{0}{3}", labelfont: {
 * fontsize: "12", font: "Arial, 宋体" } } }; chart_pie('holdstockschart', 280,
 * 220, style, data); } else { $("#holdstocks").text("没有持仓"); } }
 */

function load_zytz(data)
{
	if (data == null)
	{
		$('#zytz').html(__html_msg_nodata);
		return;
	}

	var count = $(data).find('I').length;
	if (count == 0)
	{
		$('#zytz').html(__html_msg_nodata);
		return;
	}

	var html = "<table id='table_zytz_headline' border=0 class='table_news'>";
	var first = true;
	var count = 0;
	$(data).find('I').each(
		function()
		{
			var thisrow = $(this);
			var seq = thisrow.attr('SNO');
			var title = thisrow.attr('Title');
			var datetags = thisrow.attr('BookTime').split(' ');

			if (first)
			{
				first = false;
				if (typeof(thisrow.text()) != "undefined")
				{
					var brief = thisrow.text();
					if (brief != null && brief != "")
					{
						if (brief.length > 90)
							brief = brief.substr(
								0, 50
							) + "...";
						html += "<tbody><tr class='zytz_highlight' onclick='write_log(\"84\",\"重要提示\");html_msgbox_iframe(\"正文\",\""
							+ msg_contenturl.replace(
								"[M:MSGSNO]", seq
							)
							+ "\")'>"
							+ "<td width=78%><div class='longtext'>"
							+ title
							+ "</div></td>"
							+ "<td width=22% class='ar'>"
							+ datetags[0].substr(
								5, 5
							)
							+ "</td></tr></tbody>"
							+ "<tfoot><tr><td colspan=2 class='newsbrief'>"
							+ brief
							+ " [<a href='javascript:write_log(\"84\",\"重要提示\");html_msgbox_iframe(\"正文\",\""
							+ msg_contenturl.replace(
								"[M:MSGSNO]", seq
							)
							+ "\")'>全文</a>]"
							+ "</td></tr></tfoot></table>"
							+ "<table id='table_zytz' border=0 class='table_news'>";
						count = 3;
						return;
					}
				}
			}

			html += "<tr onclick='write_log(\"84\",\"重要提示\");html_msgbox_iframe(\"正文\",\""
				+ msg_contenturl.replace(
					"[M:MSGSNO]", seq
				)
				+ "\")'>"
				+ "<td width=78%><div class='longtext' title='"
				+ title
				+ "'>"
				+ title
				+ "</div></td>"
				+ "<td width=22% class='ar'>" + datetags[0].substr(
					5, 5
				) + "</td></tr>";
			count++;
			if (count >= 9)
				return false;
		}
	);
	html += "</table>";
	$('#zytz').html(html);

	html_table_rowhover(
		'table_zytz_headline', 'news_hover'
	);
	html_table_rowhover(
		'table_zytz', 'news_hover'
	);
}

function load_jrtt(data)
{
	if (data == null)
	{
		$('#news_jrtt').html(__html_msg_nodata);
		return;
	}

	var count = $(data).find('I').length;
	if (count == 0)
	{
		$('#news_jrtt').html(__html_msg_nodata);
		return;
	}

	var html = "<table id='table_jrts_headline' border=0 class='table_news'>";
	var first = true;
	var count = 0;
	$(data).find('I').each(
		function()
		{
			var thisrow = $(this);
			var seq = thisrow.attr('Seq');
			var title = thisrow.attr('Title');
			var datetags = thisrow.attr('BookDate').split(' ');
			var datatag = datetags[0].substr(
				4, 2
			) + "-" + datetags[0].substr(
				6, 2
			);

			if (first)
			{
				first = false;
				if (typeof(thisrow.attr('PContent')) != "undefined")
				{
					var brief = thisrow.attr('PContent');
					if (brief != null && brief != "")
					{
						if (brief.length > 90)
							brief = brief.substr(
								0, 65
							) + "...";
						html += "<tbody><tr class='jrtt_highlight' onclick='write_log(\"82\",\"今日头条\");html_msgbox_iframe(\"正文\",\""
							+ G_STR_WEBROOT
							+ "/sd/h/HotNews/"
							+ seq
							+ ".htm\")'>"
							+ "<td><div class='longtext'>"
							+ title
							+ "</div></td></tr></tbody>"
							+ "<tfoot><tr><td colspan=2 class='newsbrief'>"
							+ brief
							+ " [<a href='javascript:write_log(\"82\",\"今日头条\");html_msgbox_iframe(\"正文\",\""
							+ G_STR_WEBROOT
							+ "/sd/h/HotNews/"
							+ seq
							+ ".htm\")'>全文</a>]"
							+ "</td></tr></tfoot></table>"
							+ "<table id='table_jrts' border=0 class='table_news' width='100%'>";
						count = 3;
						return;
					}
				}
			}

			if (thisrow.attr('Source') != "")
				title = '[' + thisrow.attr('Source') + '] ' + title;
			html += "<tr onclick='write_log(\"82\",\"今日头条\");html_msgbox_iframe(\"正文\",\""
				+ G_STR_WEBROOT
				+ "/sd/h/HotNews/"
				+ seq
				+ ".htm\")'>"
				+ "<td width=85%><div class='longtext' title='"
				+ title
				+ "'>"
				+ title
				+ "</div></td>"
				+ "<td width=15% class='ar'>"
				+ datatag
				+ "</td></tr>";
			count++;
			if (count >= 9)
				return false;
		}
	);
	html += "</table>";
	$('#news_jrtt').html(html);

	html_table_rowhover(
		'table_jrts_headline', 'headline_jrtt'
	);
	html_table_rowhover(
		'table_jrts', 'news_hover'
	);
}

var zxg_today = new Array();
function __show_zxg_today(pageindex)
{
	var pagecount = Math.ceil(zxg_today.length / 5);
	if (pageindex < 0)
		pageindex = pagecount;
	else if (zxg_today.length <= (pageindex - 1) * 5)
		pageindex = pagecount;

	var html = "<table id='table_zxg_today' border=0 class='xxpl_table'>";
	for (var i = (pageindex - 1) * 5; i < pageindex * 5; i++)
	{
		if (i >= zxg_today.length)
			break;
		var seq = zxg_today[i]["seq"];
		var title = zxg_today[i]["title"];
		// var datetag = zxg_today[i]["datetag"];

		html += "<tr onclick='write_log(\"83\",\"信息披露\");html_msgbox_iframe(\"正文\",\""
			+ G_STR_WEBROOT
			+ "/sd/h/TodayBulletin/"
			+ seq
			+ ".htm\")'>"
			+ "<td width=100%><div class='longtext' title='"
			+ title
			+ "'>"
			+ title + "</div></td></tr>";
	}
	html += "</table>";
	$('#zxg_today_list').html(html);
	html_table_rowhover(
		'table_zxg_today', 'rowhover'
	);

	if (zxg_today.length > 5)
	{
		html_paging(
			'zxg_today_pager', {
				"pagesize"	: 5,
				"rowcount"	: zxg_today.length
			}, pageindex, __show_zxg_today
		);
	}
}
function load_zxg_today(data)
{
	if (data == null)
	{
		$('#zxg_today_list').html("自选股今日提示无数据");
		return;
	}

	zxg_today = new Array();
	$(data).find('I').each(
		function()
		{
			var thisrow = $(this);
			var market = thisrow.attr('M');
			var code = thisrow.attr('C');
			var fullcode = market + code;
			if (typeof(stock_self_hash[fullcode]) == "undefined")
				return;

			var row = new Object();
			row["seq"] = thisrow.attr('S');
			row["title"] = thisrow.attr('T');
			var datetags = thisrow.attr('B').split(' ');
			row["datatag"] = datetags[0].substr(
				4, 2
			) + "-" + datetags[0].substr(
				6, 2
			);
			zxg_today.push(row);
		}
	);

	if (zxg_today.length == 0)
	{
		$('#zxg_today_list').html("自选股今日提示无数据");
		return;
	}
	__show_zxg_today(1);
}

var zxg_future = new Array();
var zxg_files = 0;
var zxg_files_count = 0;
var zxg_future_show = false;
function __show_zxg_future(pageindex)
{
	zxg_future_show = false;

	var pagecount = Math.ceil(zxg_future.length / 5);
	if (pageindex < 0)
		pageindex = pagecount;
	else if (zxg_future.length <= (pageindex - 1) * 5)
		pageindex = pagecount;

	var html = "<table id='table_zxg_future' border=0 class='xxpl_table'>";
	for (var i = (pageindex - 1) * 5; i < pageindex * 5; i++)
	{
		if (i >= zxg_future.length)
			break;
		// var seq = zxg_future[i].seq;
		var title = zxg_future[i].title;

		// var datetag = zxg_future[i].datetag;
		// datetag = datetag.substr(
		// 0, 4
		// ) + "-" + datetag.substr(
		// 4, 2
		// ) + "-" + datetag.substr(
		// 6, 2
		// );

		html += "<tr><td width=100%><div class='longtext' title='" + title
			+ "'>" + title + "</div></td></tr>";
		// + "<td width=25% class='ar'>" + datetag + "</td></tr>";
	}
	html += "</table>";
	$('#zxg_future_list').html(html);

	if (zxg_future.length > 5)
	{
		html_paging(
			'zxg_future_pager', {
				"pagesize"	: 5,
				"rowcount"	: zxg_future.length
			}, pageindex, __show_zxg_future
		);
	}
}
function load_zxg_future(data)
{
	if (data == null)
	{
		if (zxg_files_count >= zxg_files)
			$('#zxg_future').html(__html_msg_nodata);
		return;
	}

	$(data).find('I').each(
		function()
		{
			var thisrow = $(this);
			var market = thisrow.attr('M');
			var code = thisrow.attr('S');
			var fullcode = market + code;
			if (typeof(stock_self_hash[fullcode]) == "undefined")
				return;

			var row = new Object();
			row.title = thisrow.attr('N') + "：" + thisrow.text();
			if (typeof(thisrow.attr('H')) != "undefined"
				&& thisrow.attr('H') != "")
				row.title += "(" + thisrow.attr('H') + ")";
			row.datetag = thisrow.attr('D');
			zxg_future.push(row);
		}
	);

	if (zxg_future.length == 0)
	{
		if (zxg_files_count >= zxg_files)
			$('#zxg_future').html(__html_msg_nodata);
		return;
	}

	zxg_future = zxg_future.sort(
		function(a, b)
		{
			return parseInt(a.datetag) - parseInt(b.datetag);
		}
	);
	if (!zxg_future_show)
	{
		zxg_future_show = true;
		setTimeout(
			"__show_zxg_future(1);", 500
		);
	}
}

function calendar_selectday(pDate)
{
	// calendar_selectmonth();

	var seldate = new Date(pDate.replace(
		"-", "/"
	));
	var yy = seldate.getFullYear();
	var mm = seldate.getMonth() + 1;
	var dd = seldate.getDate();
	var titleStr = yy + "年";
	var urlPara = yy;

	if (mm < 10)
	{
		titleStr += "0" + mm.toString() + "月";
		urlPara += "0" + mm.toString();
	}
	else
	{
		titleStr += mm.toString() + "月";
		urlPara += mm.toString();
	}

	if (dd < 10)
	{
		titleStr += "0" + dd.toString() + "日";
		urlPara += "0" + dd.toString();
	}
	else
	{
		titleStr += dd.toString() + "日";
		urlPara += dd.toString();
	}

	html_msgbox_iframe(
		"股市日历：" + titleStr, "calendarhint.htm?d=" + urlPara
	);
}

function calendar_selectmonth()
{
	if (stock_self.length == 0)
		return;

	var calobj = $("#calendar_day");
	year = parseInt(calobj.attr("year"));
	month = parseInt(calobj.attr("month"));

	var url = "";
	if (month < 10)
	{
		url = G_STR_WEBROOT + "/sd/i/" + year + "/S0" + month + ".xml";
	}
	else
	{
		url = G_STR_WEBROOT + "/sd/i/" + year + "/S" + month + ".xml";
	}

	ajax_load_xml(
		url, function(data)
		{
			if (data == null)
				return;

			var self_mark = new Object();
			$(data).find('I').each(
				function()
				{
					var fullcode = $(this).attr('S');
					if (typeof(stock_self_hash[fullcode]) == "undefined")
						return;

					var days = $(this).text().split(",");
					for (var i = 0; i < days.length; i++)
					{
						var day = days[i];
						if (day.substr(
							0, 1
						) == '0')
							day = day.substr(1);
						if (typeof(stock_self_hash[fullcode]) != "undefined")
							self_mark[day] = "1";
					}
				}
			);

			$('#calendar_day .calendar_body td').each(
				function()
				{
					var text = $(this).text();
					if (text == "")
						return;

					if (typeof(self_mark[text]) != "undefined")
					{
						$(this).addClass('selfstock');
						return;
					}
				}
			);
		}
	);
}

// 装载一个月的日历
var lastyear = 0,
	lastmonth = 0;
function calendar_load(year, month)
{
	if (lastyear == year && lastmonth == month)
	{
		calendar_refresh();
		return;
	}
	lastyear = year;
	lastmonth = month;

	cal_arrMark = new Array();

	var bNeedCache = false;
	var curDate = new Date();
	if (curDate.getFullYear == year && (curDate.getMonth() + 1) == month)
	{
		bNeedCache = true;
	}
	var cachekey = "HOMEPAGE_CALENDAR_ENV_" + month.toString();
	if (bNeedCache)
	{
		var pHisData = client_cache_get(cachekey);
		if (pHisData != null)
		{
			$(pHisData).find('I').each(calendar_oneitem);
			// 刷新日历
			calendar_refresh();
			calendar_stockinfo(
				year, month
			);
			return;
		}
	}

	var url = "";
	if (month < 10)
	{
		url = G_STR_WEBROOT + "/sd/i/" + year + "/I0" + month + ".xml";
	}
	else
	{
		url = G_STR_WEBROOT + "/sd/i/" + year + "/I" + month + ".xml";
	}

	ajax_load_xml(
		url, function(data)
		{
			if (data == null)
				return;
			if (bNeedCache)
				client_cache_set(
					cachekey, data, 60 * 15
				); // 15分钟取一次数据
			$(data).find('I').each(calendar_oneitem);
			// 刷新日历
			calendar_refresh();
			calendar_stockinfo(
				year, month
			);
		}
	);
}

function calendar_stockinfo(year, month)
{
	var bNeedCache = false;
	var curDate = new Date();
	if (curDate.getFullYear == year && (curDate.getMonth() + 1) == month)
	{
		bNeedCache = true;
	}
	var cachekey = "HOMEPAGE_CALENDAR_STK_" + month.toString();
	if (bNeedCache)
	{
		var pHisData = client_cache_get(cachekey);
		if (pHisData != null)
		{
			$(data).find('I').each(TradeOneStockDateItem);
			// 刷新日历
			calendar_refresh();
			return;
		}
	}

	var url = "";
	if (month < 10)
	{
		url = G_STR_WEBROOT + "/sd/i/" + year.toString() + "/S0"
			+ month.toString() + ".xml";
	}
	else
	{
		url = G_STR_WEBROOT + "/sd/i/" + year.toString() + "/S"
			+ month.toString() + ".xml";
	}

	ajax_load_xml(
		url, function(data)
		{
			if (data == null)
				return;
			if (bNeedCache)
				client_cache_set(
					cachekey, data, 60 * 15
				); // 15分钟取一次数据
			$(data).find('I').each(calendar_oneitem_stock);
			// 刷新日历
			calendar_refresh();
		}
	);
}

function calendar_oneitem()
{
	var item = $(this);

	var pObj = new Object();
	pObj.D = item.attr("D");
	pObj.T = item.text();
	if (typeof(pObj.D) == "undefined")
		return;

	var tmpDay = 0;
	var tmpDayStr = pObj.D.substring(6);
	if (tmpDayStr.substring(
		0, 1
	) == "0")
	{
		tmpDay = parseInt(tmpDayStr.substring(1));
	}
	else
	{
		tmpDay = parseInt(tmpDayStr);
	}

	// 添加一个新内容
	var pDay = new Object();
	pDay.day = tmpDay;
	pDay.DataType = 1;
	pDay.Data = pObj.D;
	pDay.SelfStockList = "";
	pDay.HoldStockList = "";
	cal_arrMark.push(pDay);
	return;
}

function calendar_refresh()
{
	$('#calendar_day .calendar_body td')
		.removeClass('holdstock')
		.removeClass('selfstock')
		.removeClass('DataType_ImportEvent');
	if (cal_arrMark == null || cal_arrMark.length == 0)
		return;

	var daytds = new Array();
	$('#calendar_day .calendar_body td').each(
		function()
		{
			if (parseInt($(this).text()) > 0)
				daytds[parseInt($(this).text())] = $(this);
		}
	);

	for (var pp = 0; pp < cal_arrMark.length; pp++)
	{
		var todaytd = daytds[cal_arrMark[pp].day];
		if (typeof(daytds[cal_arrMark[pp].day]) == "undefined")
			continue;

		if (cal_arrMark[pp].HoldStockList != null
			&& cal_arrMark[pp].HoldStockList.length > 0) // 有持仓股
		{
			todaytd.addClass("holdstock");
		}
		else if (cal_arrMark[pp].SelfStockList != null
			&& cal_arrMark[pp].SelfStockList.length > 0) // 有自选股
		{
			todaytd.addClass("selfstock");
		}
		if (cal_arrMark[pp].DataType == 1) // 重大事项
		{
			todaytd.addClass("DataType_ImportEvent");
		}
	}
}

function calendar_oneitem_stock()
{
	var $Item = $(this);
	var mkStkCode = $Item.attr("S");
	var dValue = $Item.text();

	for (var i = 0; i < stock_self.length; i++)
		if (stock_self[i].FullCode == mkStkCode)
			calendar_mark_addstock(
				mkStkCode, dValue, 1
			);

	for (var i = 0; i < stock_hold.length; i++)
		if (stock_hold[i].FullCode == mkStkCode)
			calendar_mark_addstock(
				mkStkCode, dValue, 2
			);
}

function calendar_mark_addstock(mkStockCode, DateStr, flag)
{
	if (DateStr == null || DateStr.length == 0)
		return;
	var lsDay = DateStr.split(",");
	var i;

	for (i = 0; lsDay != null && i < lsDay.length; i++)
	{
		var icurdatestr = lsDay[i];
		if (icurdatestr.substring(
			0, 1
		) == "0")
			icurdatestr = icurdatestr.substring(1);
		var iCurDate = parseInt(icurdatestr);
		if (cal_arrMark != null)
		{
			for (var pp = 0; pp < cal_arrMark.length; pp++)
			{
				if (cal_arrMark[pp].day == iCurDate)
				{
					found = true;
					if (flag == 1) // 自选股
					{
						if (cal_arrMark[pp].SelfStockList == null
							|| cal_arrMark[pp].SelfStockList.length == 0)
						{
							cal_arrMark[pp].SelfStockList = mkStockCode;
						}
						else
						{
							cal_arrMark[pp].SelfStockList = cal_arrMark[pp].SelfStockList
								+ "," + mkStockCode;
						}
					}
					else
					// 持仓股
					{
						if (cal_arrMark[pp].HoldStockList == null
							|| cal_arrMark[pp].HoldStockList.length == 0)
						{
							cal_arrMark[pp].HoldStockList = mkStockCode;
						}
						else
						{
							cal_arrMark[pp].HoldStockList = cal_arrMark[pp].HoldStockList
								+ "," + mkStockCode;
						}
					}
					break;
				}
			}// for
		}
	}// for
}// func

// +---------------------------------------------------
// | 当前登录用户
// +---------------------------------------------------
var SysUser = [];
function sysUserInit()
{
	if (SysUser instanceof Array && SysUser.length > 0)
	{
		return SysUser;
	}
	SysUser = getSysUser();
	return SysUser;
}

function getSysUserId()
{
	sysUserInit();
	if (SysUser.length > 0)
	{
		return SysUser[0];
	}
	throw 'Get userid error!';
}

function getQsId()
{
	sysUserInit();
	if (SysUser.length > 2)
	{
		return SysUser[2];
	}
	throw 'Get qsid error!';
}
// ---------------用户 券商 当前登录信息 结束-------------------------

// +---------------------------------------------------
// | 动态网页ajax加载
// +---------------------------------------------------
function ajax_load(url, async, callback)
{
	var req = ql_httprequest_get();
	var callbackfn = callback;
	req.onreadystatechange = function()
	{
		if (req.readyState == 4)
		{
			if (req.status == 200)
			{
				callbackfn(req.responseText);
				req = null;
			}
		}
	};
	var callURL = ajax_url_random(url);
	req.open(
		'GET', callURL, async
	);
	req.send();
}
function ajax_url_random(url)
{
	if (url.indexOf('?') > 0)
	{
		url += '&_rand=' + Math.random();
	}
	else
	{
		url += '?_rand=' + Math.random();
	}
	return url;
}
var $newsDetail = null;
function loadTG()
{
	$newsDetail = $("#newsdetail").clone(true);
	$("#newsdetail").remove();
	// var urlQs = debugLocalUrl+"inter/qs/baseinfo.do?qsid="+getQsId();
	var urlQs = G_TGPATH() + "inter/qs/baseinfo.do?qsid=" + getQsId();
	ajax_load(
		urlQs, true, loadQsInfo
	);
	loadNoticePage(1);
}
function loadQsInfo(data)
{
	if (data)	{
		var jsonData = eval("(" + data + ")");
		if (jsonData.hasOwnProperty("banner"))
		{
			var bannerAddr = jsonData["banner"];
			if (typeof bannerAddr == "string")
			{
				var htmlInfo = "";
				if (bannerAddr.startWith("http://"))
				{
					bannerAddr = bannerAddr.substring(bannerAddr.indexOf(
						"/", 7
					) + 1);
				}
				var url = "";
				var urltemp = "";								
				if (jsonData.hasOwnProperty("url") && jsonData["url"])
				{
					url = jsonData["url"];
					urltemp = url;
					if (!url.startWith("http://")&& !url.startWith("https://"))
					{
						urltemp = "http://" + url;
					}
				}
				htmlInfo += '<a';
				if(url !=""){
					htmlInfo += ' href="'+urltemp+'" target="_blank" ';
				}
				htmlInfo += ' class="a_bigImg" onfocus="this.blur();">';
				htmlInfo += '<img src="'+G_ATTACHPATH() + bannerAddr+'?t='+(new Date()).valueOf()+'" width="950" height="110" />';
				htmlInfo += '</a>';
				$("#bannerImg").removeClass("changeBox_a1");	
				$("#bannerImg").html(htmlInfo);						
			}
			else if (isArray(bannerAddr))
			{
				var htmlInfo = "";
				for(var i=0;i<bannerAddr.length;i++){
					var banner = bannerAddr[i].path;
					if(banner == ""){
						continue;
					}
					if (banner.startWith("http://"))
					{
						banner = banner.substring(banner.indexOf(
							"/", 7
						) + 1);
					}
					var url = bannerAddr[i].url;
					if (!url.startWith("http://") && !url.startWith("https://"))
					{
						url = "http://" + url;
					}
					
					htmlInfo += '<a';
					if(bannerAddr[i].url !=""){
						htmlInfo += ' href="'+url+'" target="_blank" ';
					}
					htmlInfo += ' class="a_bigImg" onfocus="this.blur();">';
					htmlInfo += '<img src="'+G_ATTACHPATH()+banner+'?t='+(new Date()).valueOf()+'" width="950" height="110" />'	;
					htmlInfo += '</a>';
				}
				htmlInfo += '<ul class="ul_change_a2">';
				for(var i=0;i<bannerAddr.length;i++){
						htmlInfo += '<li><span>'
						htmlInfo += (i+1);
						htmlInfo += '</span></li>';
				}
				htmlInfo += '</ul>';
				
				$("#bannerImg").addClass("changeBox_a1");	
				$("#bannerImg").html(htmlInfo);
				$('#bannerImg .a_bigImg').soChange({
					thumbObj:'#bannerImg .ul_change_a2 span',
					thumbNowClass:'on',
					changeTime:10000
				});
			}
		}

		if (jsonData.hasOwnProperty("ad"))
		{
			var ad = jsonData["ad"];
			if (typeof ad == "string")
			{
				var htmlInfo = "";
				if (ad.startWith("http://"))
				{
					ad = ad.substring(ad.indexOf(
						"/", 7
					) + 1);
				}
				htmlInfo += '<img src="'+G_ATTACHPATH() + ad+'?t='+(new Date()).valueOf()+'" width="278" height="240" />'
				$("#adImg").html(htmlInfo);	
			}
			else if (isArray(ad))
			{
				var htmlInfo = "";
				for(var i=0;i<ad.length;i++){
					var adPath = ad[i].path;
					if(adPath == ""){
						continue;
					}
					if(adPath != ""){
						if (adPath.startWith("http://"))
						{
							adPath = adPath.substring(adPath.indexOf(
								"/", 7
							) + 1);
						}
						var url = ad[i].url;
						if (!url.startWith("http://") && !url.startWith("https://"))
						{
							url = "http://" + url;
						}
						htmlInfo += '<a'
						if(ad[i].url !=""){
							htmlInfo += ' href="'+url+'" target="_blank" '
						}
						htmlInfo += ' class="a_bigImg" onfocus="this.blur();">'
						htmlInfo += '<img src="'+G_ATTACHPATH()+adPath+'?t='+(new Date()).valueOf()+'" width="278" height="240" />'
						htmlInfo += '</a>'
					}
				}
				htmlInfo += '<ul class="ul_change_a2">';
				for(var i=0;i<ad.length;i++){
						htmlInfo += '<li><span>'
						htmlInfo += (i+1);
						htmlInfo += '</span></li>';
				}
				htmlInfo += '</ul>';
				$("#adImg").html(htmlInfo);
				$('#adImg .a_bigImg').soChange({
					thumbObj:'#adImg .ul_change_a2 span',
					thumbNowClass:'on',
					changeTime:10000
				});
			}
		}
		var introduction = jsonData["introduction"];
		$("#dd_introduction").html(introduction);
		$("#dd_introduction_info").click(
			function()
			{
				$newsDetail.find("#detailDate").text("");
				$newsDetail.find("#detailTitle").text("营业部介绍");
				$newsDetail.find("#contentHtml").html(introduction);
				html_msgbox_text(
					"正文", $newsDetail.css(
						"display", "block"
					)[0].outerHTML
				);
				newsstyle_default();
			}
		);
	}
}

String.prototype.startWith = function(s)
{
	if (s == null || s == "" || this.length == 0 || s.length > this.length)
		return false;
	if (this.substr(
		0, s.length
	) == s)
		return true;
	else
		return false;
	return true;
};

var pSize = 7,
	noticeCount = 0;
var pidxTemp = 1;
function loadNoticePage(pIdx)
{
	if (noticeCount > 0 && pIdx < 0)
	{
		pIdx = Math.ceil(noticeCount / pSize);
	}
	pidxTemp = pIdx;
	// var urlNotice =
	// debugLocalUrl+"inter/qs/noticesperpage.do?qsid="+getQsId()+"&psize="+
	// pSize +"&pidx="+pIdx;
	var urlNotice = G_TGPATH() + "inter/qs/noticesperpage.do?qsid=" + getQsId()
		+ "&psize=" + pSize + "&pidx=" + pIdx;
	ajax_load(
		urlNotice, true, loadNotice
	);
}

function loadNotice(data)
{
	if (!data)
	{
		$('#noticeList').html(__html_msg_nodata);
		return;
	}
	else
	{
		var jsonData = eval("(" + data + ")");
		noticeCount = jsonData.total;
		if (noticeCount == 0 || noticeCount == undefined)
		{
			$('#noticeList').html(__html_msg_nodata);
			return;
		}
		else
		{
			var lis = '';
			var list;
			var title = '';
			var today = new Date();

			for (var i = 0; i < jsonData.list.length; i++)
			{
				list = jsonData.list[i];
				title = list.title;
				if (title.length > 16)
				{
					title = title.substring(
						0, 16
					);
				}

				var showNewLabel = false;
				if (!list.hasOwnProperty("newSign"))
				{
					var adddate = new Date(Date.parse(list.adddate.replace(
						/-/g, "/"
					)));
					var dates = today.getTime() - adddate.getTime(); // 时间差的毫秒数
					// 计算出相差天数
					var days = Math.floor(dates / (24 * 3600 * 1000));

					// 5天之内的公告显示为NEW
					if (days < 5)
					{
						showNewLabel = true;
					}
				}
				else if (list.newSign == "1")
				{
					showNewLabel = true;
				}

				if (showNewLabel)
					lis += '<dd onclick="getNoticeDetail('
						+ list.seq
						+ ');"><p title="'
						+ list.title
						+ '">'
						+ title
						+ '<img src="img/icon_new.gif" /></p><em>'
						+ list.adddate
							.substring(list.adddate.indexOf("/") + 1)
							.replace(
								"/", "-"
							) + '</em></dd>';
				else
					lis += '<dd onclick="getNoticeDetail('
						+ list.seq
						+ ');"><p title="'
						+ list.title
						+ '">'
						+ title
						+ '</p><em>'
						+ list.adddate
							.substring(list.adddate.indexOf("/") + 1)
							.replace(
								"/", "-"
							) + '</em></dd>';

			}
			$('#noticeList').html(lis);
		}
	}
	
	if (noticeCount > pSize)
	{
		html_paging(
			'div_noticePager', {
				"pagesize"	: pSize,
				"rowcount"	: noticeCount
			}, pidxTemp, loadNoticePage
		);
	}
}

function getNoticeDetail(seq)
{
	// var urlNoticeDetail =
	// debugLocalUrl+"inter/qs/noticedetail.do?qsid="+getQsId()+"&seq="+ seq;
	var urlNoticeDetail = G_TGPATH() + "inter/qs/noticedetail.do?qsid="
		+ getQsId() + "&seq=" + seq;
	ajax_load(
		urlNoticeDetail, false, loadNoticeDetail
	);
}
function loadNoticeDetail(data)
{
	if (data)
	{
		var jsonData = eval("(" + data + ")");
		if (jsonData.scd == undefined)
		{
			$newsDetail.find("#detailTitle").text(jsonData.title);
			$newsDetail.find("#detailDate").text("发布日期：" + jsonData.adddate);
			$newsDetail.find("#contentHtml").html(jsonData.content);
			//图片路径更换
			var img = $newsDetail.find("#contentHtml").find("img");
			for(var i=0; i<img.length;i++){
				var imgObj = $(img[i]);
				var src = imgObj.attr("src");
				if(src.lastIndexOf (":") != -1 && src.lastIndexOf ("http://") == -1){
					src = src.substring(src.lastIndexOf (":") + 1);
					imgObj.attr("src" ,G_ATTACHPATH() + src);
				}
			}
			
			html_msgbox_text(
				"正文", $newsDetail.css(
					"display", "block"
				)[0].outerHTML
			);
			newsstyle_default();
		}
		else
		{
			if (jsonData.scd == "-10")
				alert("该条信息已删除");
		}
	}
}

function isArray(val)
{
	return Object.prototype.toString.apply(val) === '[object Array]';
}