//=============================================
// utility.js
//
//
// David Yang (yangjh@doe2e.com)
// 2002.2.20
//=============================================








var newWindow = null;

document.onreadystatechange = init_page;

function init_page()
{
	if (document.readyState != 'complete') return;

	var oDTSpan = document.all.dtSPAN;
	var iIntervalID = "";
	if (oDTSpan) {
		iIntervalID = window.setInterval("time_refresh()", 1000);
	}
	else {
		window.clearInterval(iIntervalID);
	}
}

function time_refresh()
{
	var oTimer = document.all.dtSPAN;
	var oDate = new Date();
	var sDateTime;
	var sDate = "";
	var sYear = "";
	var iMonth = "";
	var iDay = "";
	var iHours = "";
	var iMinutes = "";
	var iSeconds = "";
	var iFormat = parseInt(oTimer.DATEFORMAT);

	switch (iFormat) {
	case 0:
		sYear = oDate.getFullYear() + "年";
		iMonth = oDate.getMonth() + 1;
		iMonth = iMonth + "月";
		iDay = oDate.getDate() + "日" + " ";
		sDate = sYear + iMonth + iDay + "";

		iHours = oDate.getHours() + "";
		iMinutes = oDate.getMinutes() + "";
		if (iMinutes.length == 1) {
			iMinutes = "0" + iMinutes;
		}
		iSeconds = oDate.getSeconds() + "";
		if (iSeconds.length == 1) {
			iSeconds = "0" + iSeconds;
		}
		break;
	case 1:
		iMonth = oDate.getMonth() + 1;
		iMonth = iMonth + "月";
		iDay = oDate.getDate() + "日" + " ";
		sDate = iMonth + iDay + "";

		iHours = oDate.getHours();
		iMinutes = oDate.getMinutes() + "";
		if (iMinutes.length == 1) {
			iMinutes = "0" + iMinutes;
		}
		iSeconds = oDate.getSeconds() + "";
		if (iSeconds.length == 1) {
			iSeconds = "0" + iSeconds;
		}
		break;
	case 2:
		iMonth = oDate.getMonth() + 1;
		iMonth = iMonth + "月";
		iDay = oDate.getDate() + "日" + " ";
		sDate = iMonth + iDay + "";

		iHours = oDate.getHours() + ""
		iMinutes = oDate.getMinutes() + ""
		if (iMinutes.length == 1) {
			iMinutes = "0" + iMinutes;
		}
		iSeconds = "";
		break;
	case 3:
		sYear = oDate.getFullYear() + "年";
		iMonth = oDate.getMonth() + 1;
		iMonth = iMonth + "月";
		iDay =  oDate.getDate() + "日";
		sDate = sYear + iMonth + iDay + "";

		iHours = "";
		iMinutes = "";
		sSeconds = "";
		break;
	case 4:
		iMonth = oDate.getMonth() + 1;
		iMonth = iMonth + "月";
		iDay = oDate.getDate() + "日";
		sDate = iMonth + iDay + "";

		iHours = "";
		iMinutes = "";
		iSeconds = "";
		break;
	}
	sDateTime = sDate;
	if (iHours != "") {
		sDateTime = sDateTime + iHours;
	}
	if (iMinutes != "") {
		sDateTime = sDateTime + ":" + iMinutes;
	}
	if (iSeconds != "") {
		sDateTime = sDateTime + ":" + iSeconds;
	}
	
	oTimer.innerText = sDateTime;
}

function hasAccessRights(sType, oID)
{
	var xmlhttp;
	var xmldom;

	var sURL = document.location.protocol + "//" + document.location.hostname + "/js/car.asp";
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	if (xmlhttp) {
		xmlhttp.open("GET", sURL, false);
		xmltext = "<object>\n"
		xmltext = xmltext + "<objecttype>" + sType + "</objecttype>\n"
		xmltext = xmltext + "<id>" + oID + "</id>\n"
		xmltext = xmltext + "</object>"

		xmldom = new ActiveXObject("Microsoft.XMLDOM");
		if (xmldom) {
			xmldom.loadXML(xmltext);
			xmlhttp.send(xmldom);

			xmldom = xmlhttp.responseXML;
			var oNode = xmldom.selectSingleNode("result");
			var oNodeCode;
			var oNodeMsg;
			if (oNode && oNode.hasChildNodes) {
				oNodeCode = oNode.firstChild;
				oNodeMsg = oNode.lastChild;
			}
			if (oNodeCode.text == '0') {
				return true;
			}
		}
	}
	return false;
}

function checkAccessRights(oAnchor, sType, oID, sLink)
{
	var xmlhttp;
	var xmldom;
	var fDeny;

//	var agt = navigator.userAgent.toLowerCase();
//	if (agt.indexOf("msie 6.0") < 0) {
//		// lower than msie 6.0, using <IFrame></IFrame>
//		for (var i = 0; i < document.all.length; i++) {
//			var e = document.all[i];
//			if (e.tagName == "IFRAME" && (e.name == "g_frmCAR" || e.id == "g_frmCAR")) {
//				//......
//			}
//		}
//	}
//	else {
		var sURL = document.location.protocol + "//" + document.location.hostname + "/js/car.asp";
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		xmldom = new ActiveXObject("Microsoft.XMLDOM");

		xmlhttp.open("GET", sURL, false);

		xmltext = "<object>\n"
		xmltext = xmltext + "<objecttype>" + sType + "</objecttype>\n"
		xmltext = xmltext + "<id>" + oID + "</id>\n"
		xmltext = xmltext + "</object>"

		xmldom.loadXML(xmltext);
		xmlhttp.send(xmldom);

		xmldom = xmlhttp.responseXML;
		var oNode = xmldom.selectSingleNode("result");
		var oNodeCode;
		var oNodeMsg;
		if (oNode && oNode.hasChildNodes) {
			oNodeCode = oNode.firstChild;
			oNodeMsg = oNode.lastChild;
		}

		fDeny = parseInt(oNodeCode.text);
//	}

	if (fDeny != 0) {
		alert("您没有访问该对象的权限!");
		event.returnValue = false;
		return;
	}

	oAnchor.href = sLink;
}

function fnGetFxNews()
{
	var e = dpFrame;
	var vNews = null;
	var vTrend = null;

	for (var i = 0; i < e.document.all.length; i++) {
		var ie = e.document.all[i];
		if (ie.tagName == 'MARQUEE' && ie.id == 'fxNews') {
			vNews = ie;
		}
		if (ie.tagName == 'MARQUEE' && ie.id == 'fxTrend') {
			vTrend = ie;
		}
	}

	if (document.all.m_fxNews && vNews != null && vTrend != null) {
		document.all.m_fxNews.innerHTML = vNews.innerText + '&nbsp;&nbsp;' + vTrend.innerText;
	}
	//document.all.m_fxTrend.innerHTML = vTrend.innerText;

}

function openMe(sURL)
{
	if (! newWindow || newWindow.closed) {
		newWindow = window.open(sURL, "survey", "toolbar,resizable,scrollbars,dependent,width=400,height=320");
	}
	else {
		newWindow.location.replace(sURL);
		newWindow.focus();
	}
}

function newWin(sURL)
{
	window.open(sURL, "newWin", "toolbar=no,resizable,scrollbars,dependent,width=400,height=280");
}
