// JavaScript Document By Jack

/*
* 操作XML文件，避免不存在的节点抛出异常
*/
function CXml(indat)
{
//	alert(typeof(indat));
if(typeof(indat) == "string")
{
this.m_xmlObj  = new ActiveXObject("Microsoft.XMLDOM");
//		alert(indat);
this.m_xmlObj.loadXML(indat);
}
else if(typeof(indat) == "object")
{
this.m_xmlObj = indat;
}
else
{
throw new Error("CHttpRequest 返回一个不能识别的对象.");
}
this.GetValue = CXml_GetValue;
this.GetNodes = CXml_GetNodes;
this.GetChildValue = CXml_GetChildValue;
this.GetChildNodes = CXml_GetChildNodes;
this.GetParentNode = CXml_GetParentNode;
this.GetAttValue = CXml_GetAttValue;
}
function CXml_GetValue(node_name)
{
var res;
try
{
res = this.m_xmlObj.getElementsByTagName(node_name)[0].firstChild.data
}
catch(ex)
{
res = "";
}
return res;
}
function CXml_GetNodes(node_name)
{
var res;
try
{
res = this.m_xmlObj.getElementsByTagName(node_name);
}
catch(ex)
{
res = "";
}
return res;
}
function CXml_GetChildNodes(node,node_name)
{
var res;
try
{
res = node.getElementsByTagName(node_name);
}
catch(ex)
{
res = "";
}
return res;
}
function CXml_GetChildValue(node, child_node_name)
{
var res;
try
{
res = node.getElementsByTagName(child_node_name)[0].firstChild.data
}
catch(ex)
{
res = "";
}
return res;
}
function CXml_GetParentNode(node)
{
var res;
try
{
res = node.parentNode;
}
catch(ex)
{
res = "";
}
return res;
}
function CXml_GetAttValue(node, att_name)
{
var res = "";
try
{
for(var i=0; i<node.attributes.length; i++)
{
if(node.attributes[i].nodeName == att_name)
{
res = node.attributes[i].nodeValue;
break;
}
}
}
catch(ex)
{
res = "";
}
return res;
}/* ----------------------------------------------------------------
* 封装XMLHttpRequest对象,提供一致的接口供系统其他模块使用
* CHttpRequest.js
* gaussgao 20060518
* ----------------------------------------------------------------
XMLHttpRequest 对象方法 方法 描述
abort()
停止当前请求
getAllResponseHeaders()
作为字符串返问完整的headers
getResponseHeader("headerLabel")
作为字符串返问单个的header标签
open("method","URL"[,asyncFlag[,"userName"[, "password"]]])
设置未决的请求的目标 URL, 方法, 和其他参数
send(content)
发送请求
setRequestHeader("label", "value")
设置header并和请求一起发送
XMLHttpRequest 对象属性 属性 描述
onreadystatechange
状态改变的事件触发器
readyState
对象状态(integer):
0 = 未初始化
1 = 读取中
2 = 已读取
3 = 交互中
4 = 完成
responseText 	1
服务器进程返回数据的文本版本
responseXML 	2
服务器进程返回数据的兼容DOM的XML文档对象
status
服务器返回的状态码, 如：404 = "文件末找到" 、200 ="成功"
statusText
服务器返回的状态文本信息
*/
/*功能:创建对象,并设置属性
*/
function CHttpRequest(fCallback,mode,restype)
{
//创建对象
this.m_HttpRequest = createXMLHttpRequest();
//属性
this.m_bAsyncFlag = mode;
if( restype )
this.m_iResType	= restype;
else
this.m_iResType	= 2;	//responseXml
//方法
this.Post = CHttpRequest_Post;
this.Get  = CHttpRequest_Get;
this.m_fCallBack = fCallback;
}
function CHttpRequest_Get(dst,para)
{
var now = new Date();
var rnd = Math.floor(Math.random() * 100000);
var ptm = now.getSeconds().toString()+rnd.toString()+now.getMinutes().toString();
para += "&ptm="+ptm.toString();
var http = this;
function tm_back()
{
if(http.m_HttpRequest.readyState == 4)
{
if(http.m_HttpRequest.status == 200)
{
if(http.m_iResType == 1)
http.m_fCallBack(4,200,http.m_HttpRequest.responseText);
else
http.m_fCallBack(4,200,http.m_HttpRequest.responseXML);
}
else
{
http.m_fCallBack(4,http.m_HttpRequest.status,null);
}
}
else
{
http.m_fCallBack(http.m_HttpRequest.readyState,null,null);
}
}
this.m_HttpRequest.onreadystatechange = tm_back;
this.m_HttpRequest.open("GET",dst+"?"+para,this.m_bAsyncFlag);
this.m_HttpRequest.setRequestHeader("Content_Type","application/x-www-form-urlencoded;charset=GB2312");
this.m_HttpRequest.setRequestHeader("Cache-Control","no-cache");
this.m_HttpRequest.send("");
}
function CHttpRequest_Post(dst,para)
{
var http = this;
function tm_back()
{
if(http.m_HttpRequest.readyState == 4)
{
if(http.m_HttpRequest.status == 200)
{
if(http.m_iResType == 1)
http.m_fCallBack(4,200,http.m_HttpRequest.responseText);
else
http.m_fCallBack(4,200,http.m_HttpRequest.responseXML);
}
else
{
http.m_fCallBack(4,http.m_HttpRequest.status,null);
}
}
else
{
http.m_fCallBack(http.m_HttpRequest.readyState,null,null);
}
}
this.m_HttpRequest.onreadystatechange = tm_back;
this.m_HttpRequest.open("POST",dst,this.m_bAsyncFlag);
this.m_HttpRequest.setRequestHeader("Content_Length",para.length);
this.m_HttpRequest.setRequestHeader("Content_Type","application/x-www-form-urlencoded;charset=GB2312");
//this.m_HttpRequest.setRequestHeader("Content_Type","text/xml;charset=GB2312");
this.m_HttpRequest.send(para);
}
function getXMLPrefix()
{
if (getXMLPrefix.prefix)
return getXMLPrefix.prefix;
var prefixes = ["MSXML3", "MSXML2", "MSXML", "Microsoft"];
var obj, obj2;
for(var i = 0; i < prefixes.length; i++)
{
try
{
//Attempt to create an XmlHttp object using the current prefix
obj = new ActiveXObject(prefixes[i] + ".XmlHttp");
return getXMLPrefix.prefix = prefixes[i];
}
catch (ex)
{};
}
throw new Error("您没有安装XML解析器,请使用INTERNET EXPLORE 5以上的浏览器.");
}
function createXMLHttpRequest()
{
try
{
// Attempt to create it "the Mozilla way"
if (window.XMLHttpRequest)
{
return new XMLHttpRequest();
}
// Guess not - now the IE way
if (window.ActiveXObject)
{
return new ActiveXObject(getXMLPrefix() + ".XmlHttp");
}
}
catch (ex)
{
alert(ex.message);
};
return false;
}
//examples
/*-------------------------------------------------------
//回调函数:执行状态,返回码,返回内容
function CallBack_Test(state,sts,str)
{
switch(state)
{
case 0://initting
case 1://reading
case 2://readed
case 3://interact
alert(state);
break;
case 4://complete
switch(sts)
{
case 200://success
alert(str);break;
case 404://notfound
alert(sts);
default:
break;
}
default:
break;
}
}
//执行过程
function GetTest()
{
var http = new CHttpRequest(CallBack_Test,false,1);
http.Get("/test.xml","a=1&b=2");
}
GetTest();
-------------------------------------------------------------*/


function initPage()
{
	if(getCookie("uin") != null && getCookie("uin") != "")
	{
		$SW("td_hasLogin");
		$HE("td_noLogin");
		var _uin = 	getCookie("uin");
		$("span_Uin").innerHTML = _uin;
		
		//调用cgi		
		$("div_historyList").innerHTML = "数据加载中...";
		getHistory();
	}
}

/*取得历史记录开始*/
function getHistory()
{
	var paras="";
	var http = new CHttpRequest(doHistory,true,2);
	http.Get("http://action.tenpay.com/cgi-bin/cj/queryprize.cgi?tid=query_res_lottery&t=" + timestamp(), paras);
	//http.Get("http://action.tenpay.com/cgi-bin/cj/test.cgi?t=" + timestamp(), paras);
	//http.Get("http://action.tenpay.com/cj/1.txt", paras);
}

function doHistory(state,sts,str)
{
	switch(state)
	{
	case 0://initting			
	case 1://reading
	case 2://readed
	case 3://interact
		break;
	case 4://complete
		switch(sts)
		{
		case 200://success
			showHistory(str);
			break;			
		case 404://notfound
		default:
			break;
		}
	default:
		break;
	}
}

function showHistory(str)
{
	var _arrInfo = new Array();
	_arrInfo[0] = "华硕EeePC701";
	_arrInfo[1] = "Sony PSP";
	_arrInfo[2] = "苹果Ipod";
	_arrInfo[3] = "卡西欧手表";
	_arrInfo[4] = "瑞士军刀";
	_arrInfo[5] = "ZIPPO打火机";
	_arrInfo[6] = "对讲机";
	_arrInfo[7] = "快易典";
	_arrInfo[8] = "财付通挎包";
	_arrInfo[9] = "10Q币";
	_arrInfo[10] = "5Q币";
	_arrInfo[11] = "2Q币";
	_arrInfo[12] = "1Q币";
	_arrInfo[13] = "2008年9位靓号";
	_arrInfo[14] = "http://ffo.qq.com/act/a20080325lj/";
	_arrInfo[15] = "http://speed.qq.com/act/a20080331ty";
	_arrInfo[16] = "http://cf.qq.com/web200804/info/cdkey.htm";
	_arrInfo[17] = "暂无中奖信息。";
	var objXml = new CXml(str);
	var _list = objXml.GetValue("everlotteryinfo");
	var _re = "";
	if(_list != "")
	{
		var _item = _list.split("|");
		
		for(var i = 0;i < _item.length; i++)
		{
			if(_item[i] != "")
			{
				if(_item[i].length > 2 && _item[i].substr(0,5) == "cdkey")
				{
					//判断cdkey
					var _keyno = _item[i].split("_")[1];
					var _keycontent = _item[i].split("_")[2];
					_re += _keycontent + " <a href=\""+ _arrInfo[_keyno - 1] +"\" target=\"_blank\">使用</a><br />";
				}
				else
				{
					_re += _arrInfo[parseInt(_item[i]) - 1] + "<br />";	
				}
			}
		}
	}
	else
	{
		_re = "暂无中奖信息。";	
	}
	
	$("div_historyList").innerHTML = _re;
	//取出奖品列表
}
/*取得历史记录结束*/


//window.onload = initPage;

function closeLayer()
{
	$HE("show-ticket");
	$HE("bg-filter");
}

function show_login()
{
	location.href = "http://action.tenpay.com/cgi-bin/common/portallogin.cgi?tmstmp="+ timestamp() +"&resulturl=http://action.tenpay.com/cj/choujiang.html";
}

function payOneCent()
{
	var _d = document.createElement("DIV");
	_d.innerHTML = "<form id=\"frm_PayOneCent\" action=\"http://action.tenpay.com/cgi-bin/cj/prize.cgi\" method=\"post\"><input name=\"tid\" type=\"hidden\" value=\"prize_charge\" /><input name=\"product\" type=\"hidden\" value=\"YW10NEWF109_01\" /></form>";
	document.body.appendChild(_d);
	
	$("frm_PayOneCent").submit();
}

var wclose = function()
{
	//window.opener=null;
	//window.open('','_self');
	//window.close();
	location.href = "choujiang.html";
}

var flashWin = function()
{
	history.go(0);	
}

var al = function(s)
{
	alert(s);
}

