/*****************************************************
不同语言合并为一个payform.js文件，
不同的语言信息字符串统一在前面定义，变量名为Name_Lang
格式，其中Lang为（CN，BIG5，KR）一种，如MSG_INPUT_PI_TOPAY_CN
在payform.js加载时执行GetAllMsgs()代码进行信息字符初始化
*****************************************************/

/*****************************************************
定义全局变量
*****************************************************/
var intClickCount 	= 0;
var intRet		= -1;
var strPayMsg 		= "";
var blnParamOK 		= false;
var IsActiveX		= true;

var timeButton;             /*定时器返回的变量*/
//var PayInfo = "";           /*保存控件刷卡成功后的加密信息*/
var GetLastResultCount = 0;

//表单提交目的URL
var strIPERURL		= "/cgi-bin/checkPI.cgi";
var strIPBIURL		= "/cgi-bin/xmpbi.cgi";
var strEPERURL		= "/cgi-bin/epos/eposcheckPI.cgi";
var strEPBIURL		= "/cgi-bin/epos/eposxmpbi.cgi";
var strCSIPERURL	= "/cgi-bin/v31/checkPIE.cgi";
var strCSEPERURL	= "/cgi-bin/v31/epos/eposcheckPIE.cgi";
var strFundURL		= "/cgi-bin/Fund/GetFVPI.cgi";
var strYPERURL		= "/cgi-bin/upcard/doyper.cgi"; 
var strEPOSYPERURL	= "/cgi-bin/upcard/epos/doyper.cgi";
var strYECRURL    	= "/cgi-bin/upcard/doyecr.cgi"; 
var strYPBIURL    	= "/cgi-bin/upcard/doypbi.cgi"; 
var strYCPWURL		= "/cgi-bin/upcard/doycpw.cgi";
var strYTBIURL		= "/cgi-bin/upcard/doytbi.cgi";
var strVPERURL		= "/cgi-bin/v31/va/vacheckpi.cgi"; 
var strVPBIURL		= "/cgi-bin/v31/va/vaxmpbi.cgi"; 
var strBatchVPERURL	= "/cgi-bin/v31/va/vacheckpibatch.cgi"; 

//好易联卡
var strSPERURL		= "/cgi-bin/svccard/dosper.cgi";
var strSPBIURL		= "/cgi-bin/svccard/smpbi.cgi";

//DC积分卡
var strDCPERURL		= "/cgi-bin/dccard/dccheckpi.cgi";
var strDCPBIURL		= "/cgi-bin/dccard/dcxmpbi.cgi";

//ActiveX控件参数
var strReturnUrl 	= "";
var strSessionKey	= "";
var strPGInKey		= "";
var strMerNo		= "";
var strTermNo		= "";
var strPayNo		= "";
var strPlainText	= "";
var strPGAmount		= "";
var strCardNo		= "";
var strIdNo		= "";
var strSelectBankURL 	= "";

//ActiveX控件下载URL
var strComYPERUrl	= "https://www.gnetpg.com/download/security_control_download.exe";
var strComYCPWUrl	= strComYPERUrl;
var strComIPERUrl	= strComYPERUrl;
var strComEPOSUrl	= "https://www.gnetpg.com/download/epos_download.exe";
var strComVPERUrl   = "http://www.gnete.com:555/download/ePass2000-FT11-THX-CSAir.zip";


//插件使用的代码类别
var Code_Display;
//需要显示的信息
var CHECKVALUE_MSGS;	//array
var MSG_CHECKVALUE_ERROR;
var MSG_INPUT_PI_TOPAY;
var MSG_INPUT_DATA_INVALID;
var MSG_PARAMETER_GET_FAIL;
var MSG_THANKS_USING_CHINAPAY;
var MSG_TRANS_TIMEOUT;
var MSG_INPUT_TRANSSN;
var MSG_INSERT_USBKEY;
var MSG_CERT_SELECT_ERROR;
var MSG_SIGN_ERROR;
var MSG_SIGN_OK_TO_SUBMIT;
var MSG_EPOS_VERSION_ERROR;
var MSG_PLEASE_USE_CARD;
var MSG_CANCEL_ORDER;
var MSG_NOT_INSTALL_PLUGIN;
var MSG_CLICK_AND_DOWNLOAD;

//简体中文
var CHECKVALUE_MSGS_CN = new Array(
				-1, "参数aa长度错误",
				0, " ",
				1, "帐号长度错误，12-19位！",
				2, "帐号含非法字符！",
				3, "有效期长度错误，4位！",
				4, "有效期含非法字符！",
				5, "卡有效期月份错误！",
				6, "卡有效期月份错误！",
				7, "卡有效期月份错误！",
				8, "密码长度错误，4-6位！",
				9, "证件号码长度错误，6-18位！",
				10, "证件号码含非法字符！",
				11, "易办事授权号长度错误，最长8位！",
				12, "易办事授权号有非数字字符！",
				13, "新密码不匹配！",
				14, "新密码和旧密码相同！",
				15, "密码中含有非数字字符！"
				);

var MSG_CHECKVALUE_ERROR_CN = "系统出现异常，请与技术人员联系：tech@gnete.com，谢谢！( %1 )";
var MSG_INPUT_PI_TOPAY_CN	= "请输入支付信息，再点击执行支付键！";
var MSG_INPUT_DATA_INVALID_CN = "您输入了非法字符，请检查数据有效性后再提交！";
var MSG_PARAMETER_GET_FAIL_CN = "交易参数获取失败！";
var MSG_THANKS_USING_CHINAPAY_CN = "谢谢使用网付通 CHINAPAY！";
var MSG_TRANS_TIMEOUT_CN = "交易会话超时,将关闭处理！";
var MSG_INPUT_TRANSSN_CN = "请输入支付流水号！";
var MSG_INSERT_USBKEY_CN = "请插入您的USB KEY！";
var MSG_CERT_SELECT_ERROR_CN = "证书指定失败！";
var MSG_SIGN_ERROR_CN = "计算签名失败！";
var MSG_SIGN_OK_TO_SUBMIT_CN = "生成数字签名成功！点击确认后系统将向额度支付系统发送交易请求...";
var MSG_EPOS_VERSION_ERROR_CN = "错误：\n\t%1\t\n\n请检查EPOS控件是否为最新版本。";
var MSG_PLEASE_USE_CARD_CN = "请先刷卡";
var MSG_CANCEL_ORDER_CN = "真的要撤消此笔订单吗？";
var MSG_NOT_INSTALL_PLUGIN_CN = "对不起，您尚未安装所需控件程序！";
var MSG_CLICK_AND_DOWNLOAD_CN = "请点击此处下载安装...";
var MSG_CONFIRM_STOP_EPOS_CN = "真的要停止刷卡吗？";


//繁体中文
var CHECKVALUE_MSGS_BIG5 = new Array(
				-1, "把计aa岿粇",
				0, " ",
				1, "眀腹岿粇12-19",
				2, "眀腹獶猭才",
				3, "Τ戳岿粇4",
				4, "Τ戳獶猭才",
				5, "Τ戳る岿粇",
				6, "Τ戳る岿粇",
				7, "Τ戳る岿粇",
				8, "盞絏岿粇4-6",
				9, "谍ン腹絏岿粇6-18",
				10, "谍ン腹絏獶猭才",
				11, "快ㄆ甭舦腹岿粇程8",
				12, "快ㄆ甭舦腹Τ獶计才",
				13, "穝盞絏ぃで皌",
				14, "穝盞絏㎝侣盞絏",
				15, "盞絏いΤ獶计才"
				);

var MSG_CHECKVALUE_ERROR_BIG5 = "╰参瞷奢盽叫蒓м砃羛╰tech@gnete.com谅谅( %1 )";
var MSG_INPUT_PI_TOPAY_BIG5	= "叫块や獺翴阑磅︽や龄";
var MSG_INPUT_DATA_INVALID_BIG5 = "眤块獶猭才叫浪琩计誹Τ┦矗ユ";
var MSG_PARAMETER_GET_FAIL_BIG5 = "ユ把计莉ア毖";
var MSG_THANKS_USING_CHINAPAY_BIG5 = "谅谅ㄏノ蝗羛や蔍闽";
var MSG_TRANS_TIMEOUT_BIG5 = "ユ穦杠禬,盢闽超矪瞶";
var MSG_INPUT_TRANSSN_BIG5 = "叫块や瑈腹";
var MSG_INSERT_USBKEY_BIG5 = "叫础眤USB KEY";
var MSG_CERT_SELECT_ERROR_BIG5 = "谍﹚ア毖";
var MSG_SIGN_ERROR_BIG5 = "璸衡篕璶ア毖";
var MSG_SIGN_OK_TO_SUBMIT_BIG5 = "计帽ネΘΘ翴阑谔粄╰参盢肂や╰参祇癳や叫―...";
var MSG_EPOS_VERSION_ERROR_BIG5 = "岿粇\n\t%1\t\n\n叫浪琩EPOS北ン琌程穝セ";
var MSG_PLEASE_USE_CARD_BIG5 = "叫";
var MSG_CANCEL_ORDER_BIG5 = "痷璶篗掸璹虫盾";
var MSG_NOT_INSTALL_PLUGIN_BIG5 = "癸ぃ癬眤﹟ゼ杆蔍硄祘";
var MSG_CLICK_AND_DOWNLOAD_BIG5 = "叫翴阑矪更杆...";
var MSG_CONFIRM_STOP_EPOS_BIG5 = "真的要停止刷卡吗？";

//韩文
var CHECKVALUE_MSGS_KR = new Array(
				-1, "DATA aa 磊府 荐 俊矾 涝聪促!",
				0, " ",
				1, "拌谅锅龋 磊府 荐甫 肋给 涝仿窍看嚼聪促. 磊府 荐绰 12-19鳖瘤 涝聪促!",
				2, "拌谅锅龋俊 厚沥惑利牢 巩磊 何龋啊 涝仿 登菌嚼聪促!",
				3, "肋给 涝仿等 蜡瓤扁埃 拜侥涝聪促!",
				4, "蜡瓤矫埃 瘤沥俊 厚沥惑利牢 巩磊 何龋啊 器窃登绢 乐嚼聪促!",
				5, "肋给 涝仿等 蜡瓤扁埃 拜侥涝聪促!",
				6, "肋给 涝仿等 蜡瓤扁埃 拜侥涝聪促!",
				7, "肋给 涝仿等 蜡瓤扁埃 拜侥涝聪促!",
				8, "箭磊 4-6父 荤侩且 荐 乐嚼聪促!",
				9, "林刮锅龋/脚盒刘锅龋啊 肋给 涝仿 登菌嚼聪促!",
				10, "林刮锅龋/脚盒刘锅龋俊 厚沥惑利牢 何龋啊 器窃档绢 乐嚼聪促!",
				11, "弥绊 8磊府 箭磊父 荤侩且 荐啊 乐嚼聪促!",
				12, "老仿锅龋俊 箭磊啊 酒囱 巩磊何龋啊 涝仿 登菌嚼聪促!",
				13, "货肺款 厚剐锅龋啊 悼老 窍瘤 臼嚼聪促!",
				14, "货肺款 菩胶况靛客 扁粮 菩胶况靛啊 悼老钦聪促!",
				15, "厚剐锅龋俊 箭磊啊 酒囱 巩磊何啊 器钦 登绢 乐嚼聪促!"
				);

var MSG_CHECKVALUE_ERROR_KR = "矫胶袍捞 厚惑利牢 惑炔捞 惯积窍看栏骨肺 浚柳聪绢客 楷遏秦林矫扁 官而聪促. tech@gnete.com, 皑荤钦聪促!( %1 )";
var MSG_INPUT_PI_TOPAY_KR	= "搬力 沥焊甫 涝仿 饶 搬力窍扁 窜眠甫 喘矾 林绞矫坷!";
var MSG_INPUT_DATA_INVALID_KR = "厚沥惑利牢 巩磊何龋甫 涝仿 窍看嚼聪促. 涝仿窍脚 DATA甫 犬牢 窍脚 饶 促矫 柳青 秦林绞矫坷!";
var MSG_PARAMETER_GET_FAIL_KR = "芭贰 皋矫瘤 罐酒 坷扁啊 角菩窍看嚼聪促!";
var MSG_THANKS_USING_CHINAPAY_KR = "??夼槟?荃髯 CHINAPAY！";
var MSG_TRANS_TIMEOUT_KR = "搬犁 矫埃捞 瘤车栏骨肺 摧扁 贸府啊 邓聪促!";
var MSG_INPUT_TRANSSN_KR = "搬力 锅龋甫 涝仿 窍绞矫坷!";
var MSG_INSERT_USBKEY_KR = "USB-KEY甫 踩酒 林绞矫坷!";
var MSG_CERT_SELECT_ERROR_KR = "牢刘辑 瘤沥捞 角菩窍看嚼聪促!";
var MSG_SIGN_ERROR_KR = "哪腔磐 沥八 角菩窍看嚼聪促!";
var MSG_SIGN_OK_TO_SUBMIT_KR = "?懋?伲哝圜圜晚！锩???艇???峪颞荃艇??彡芜娑?洗...";
var MSG_EPOS_VERSION_ERROR_KR = "涝聪促：\n\t%1\t\n\n EPOS窜富扁 菩摹橇肺弊伐捞 弥脚滚傈牢瘤 犬牢 秦林绞矫坷.";
var MSG_PLEASE_USE_CARD_KR = "墨靛甫 快急 避绢 林绞矫坷!";
var MSG_CANCEL_ORDER_KR = "林巩阑 秒家窍矫摆嚼聪鳖?";
var MSG_NOT_INSTALL_PLUGIN_KR = "了价钦聪促. Epos窜富扁 焊救 橇肺弊伐阑 汲摹窍瘤 臼疽嚼聪促!";
var MSG_CLICK_AND_DOWNLOAD_KR = "?锩?螽??涮?...";
var MSG_CONFIRM_STOP_EPOS_KR = "真的要停止刷卡吗？";



/*===================================================================================*/
//初始化信息字符串常量，勿删除此行，否则无法在正常显示错误或提示信息
	GetAllMsgs();


/*****************************************************
根据当前页面的字符集设定所有的显示文字信息
*****************************************************/
function GetAllMsgs()
{
	var strCharSet;		//字符集
	var strPageLang;	//语言类型
	
	//取当前页面的字符集，根据字符集设置相应的语言类型
	strCharSet = document.charset.toLowerCase();
	if ((strCharSet == "gb2312") || (strCharSet == "gbk"))
	{
		strPageLang = "CN";
	} else if (strCharSet == "big5") {
		strPageLang = "BIG5";
	} else if (strCharSet == "euc-kr") {
		strPageLang = "KR";
	} else {
		strPageLang = "CN";
	}
	
	//根据语言类型设置插件显示的语言
	if (strPageLang == "CN")
	{
		Code_Display = "GB";
	} else if (strPageLang == "BIG5"){
		Code_Display = "BIG5";
	} else {
		Code_Display = "Eng";
	}

	//取得所有信息变量的值	
	CHECKVALUE_MSGS = eval("CHECKVALUE_MSGS" + "_" + strPageLang);
	MSG_CHECKVALUE_ERROR = eval("MSG_CHECKVALUE_ERROR" + "_" + strPageLang);
	MSG_INPUT_PI_TOPAY = eval("MSG_INPUT_PI_TOPAY" + "_" + strPageLang);
	MSG_INPUT_DATA_INVALID = eval("MSG_INPUT_DATA_INVALID" + "_" + strPageLang);
	MSG_PARAMETER_GET_FAIL = eval("MSG_PARAMETER_GET_FAIL" + "_" + strPageLang);
	MSG_THANKS_USING_CHINAPAY = eval("MSG_THANKS_USING_CHINAPAY" + "_" + strPageLang);
	MSG_TRANS_TIMEOUT = eval("MSG_TRANS_TIMEOUT" + "_" + strPageLang);
	MSG_INPUT_TRANSSN = eval("MSG_INPUT_TRANSSN" + "_" + strPageLang);
	MSG_INSERT_USBKEY = eval("MSG_INSERT_USBKEY" + "_" + strPageLang);
	MSG_CERT_SELECT_ERROR = eval("MSG_CERT_SELECT_ERROR" + "_" + strPageLang);
	MSG_SIGN_ERROR = eval("MSG_SIGN_ERROR" + "_" + strPageLang);
	MSG_SIGN_OK_TO_SUBMIT = eval("MSG_SIGN_OK_TO_SUBMIT" + "_" + strPageLang);
	MSG_EPOS_VERSION_ERROR = eval("MSG_EPOS_VERSION_ERROR" + "_" + strPageLang);
	MSG_PLEASE_USE_CARD = eval("MSG_PLEASE_USE_CARD" + "_" + strPageLang);
	MSG_CANCEL_ORDER = eval("MSG_CANCEL_ORDER" + "_" + strPageLang);
	MSG_NOT_INSTALL_PLUGIN = eval("MSG_NOT_INSTALL_PLUGIN" + "_" + strPageLang);
	MSG_CLICK_AND_DOWNLOAD = eval("MSG_CLICK_AND_DOWNLOAD" + "_" + strPageLang);
	MSG_CONFIRM_STOP_EPOS = eval("MSG_CONFIRM_STOP_EPOS" + "_" + strPageLang);

	return true;
	
}

/*****************************************************
翻译Applet/ActiveX返回的错误信息
*****************************************************/
function GetPlugInRetMsg(intRetCode)
{
	
	var strRetMsg;
	strRetMsg = CHECKVALUE_MSGS[(intRetCode+1)*2+1];
	if (strRetMsg == null)
	{
		strRetMsg = MSG_CHECKVALUE_ERROR.replace("%1", intRetCode);
	}
	return (strRetMsg);
}

/*****************************************************
检查PlugIn类型
*****************************************************/
function CheckPlugInType()
{
	var strUserAgent = window.navigator.userAgent;
	var strAppName = window.navigator.appName;
	var strAppVersion  = window.navigator.appVersion;
	
	var IsIE = (strUserAgent.indexOf("MSIE")>-1);
	var IsNS = (strAppName.indexOf("Netscape")>-1);
	if (IsIE)
	{
		IsActiveX = true;
	}
	else
	{
		IsActiveX = false;
	}
}

/*****************************************************
获取交易参数
*****************************************************/
function GetTrxParam(){
	try
	{
		strReturnUrl 	= window.parent.document.frmMyForm.txtRETURNURL.value;
		strSessionKey	= window.parent.document.frmMyForm.txtSESSIONPARA.value;
		strPGInKey	= window.parent.document.frmMyForm.txtAPPLETPARA.value;
		strMerNo	= window.parent.document.frmMyForm.txtMERNO.value;
		strTermNo	= window.parent.document.frmMyForm.txtTERMNO.value;
		strPayNo	= window.parent.document.frmMyForm.txtPAYNO.value;
		strPGAmount	= window.parent.document.frmMyForm.txtPGAMOUNT.value;
		strPGAmount 	= "0000000000000000".slice(0, 16-strPGAmount.length) + strPGAmount;
		strCardNo	= window.parent.document.frmMyForm.txtCARDNO.value;
		strIdNo		= window.parent.document.frmMyForm.txtIDNO.value;
		strSelectBankURL= strReturnUrl.replace("GNETPGRcv.asp", "SelectBank.asp");
		strPlainText    = strMerNo + strTermNo + strPayNo + strPGAmount + strSessionKey;
		return true;
	}
	catch(ex)
	{
		alert(MSG_PARAMETER_GET_FAIL + "\n\n" + ex.description);	
		return false;
	}
}

/*****************************************************
禁用右键
*****************************************************/
//document.onmousedown=handlemouse;
//document.onkeydown=handlekey;

function handlemouse()
{
	if (event.button!=1)
	{
		alert(MSG_THANKS_USING_CHINAPAY); 
		return false;
	}
}
function handlekey()
{
	if (event.keyCode==93 || event.keyCode==121)
	alert(MSG_THANKS_USING_CHINAPAY);
}

/*****************************************************
交易超时处理函数
*****************************************************/
/*
window.history.forward(1); 
setTimeout("TimeOut()",1800000);
*/
function TimeOut(){
	alert(MSG_TRANS_TIMEOUT);

	window.close();
}	


/*****************************************************
预载图片函数
*****************************************************/
function MM_preloadImages() {
	var d=document; 
	if(d.images){ 
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
		for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0){ 
				d.MM_p[j]=new Image; 
				d.MM_p[j++].src=a[i];
			}
	}
}


/*****************************************************
TAB卡选择函数
*****************************************************/
function SelCard(n,m)
{
	for(i=0;i<=m;i++) 
	{
		document.getElementById('BL_'+i).src='/Images/b_l.gif';
		document.getElementById('BC_'+i).background='/Images/b_c.gif';
		document.getElementById('BR_'+i).src='/Images/b_r.gif';
		document.getElementById('MAIN_'+i).style.display="none";
		document.getElementById('BC_'+i).className='card_Normal';
	}
	document.getElementById('BL_'+n).src='/Images/cb_l.gif';
	document.getElementById('BC_'+n).background='/Images/cb_c.gif';
	document.getElementById('BR_'+n).src='/Images/cb_r.gif';
	document.getElementById('MAIN_'+n).style.display="";
	document.getElementById('BC_'+n).className='card_Selected';
}

var lastSelectd=0;

function setLastSelected(idx){
	lastSelectd=idx;
}

function SelCard2(n,m)
{
	document.getElementById('bb_'+lastSelectd).style.backgroundImage="url(/Images/bubg"+m + ".gif)"; //当前按钮的底图
	document.getElementById('MAIN_'+lastSelectd).style.display="none";//隐藏按钮对应的表格
	document.getElementById('bb_'+lastSelectd).className='card_Normal';//变换字体的颜色
	var html=document.getElementById('bb_'+lastSelectd).innerHTML;
	document.getElementById('bb_'+lastSelectd).innerHTML=html.substring(1,html.length);	//减去按钮文字前面的小圆点
	document.getElementById('bb_'+n).style.backgroundImage="url(/Images/cbubg"+m + ".gif)";//替换当前按钮的底图
	document.getElementById('MAIN_'+n).style.display="";//显示按钮对应的表格
	document.getElementById('bb_'+n).className='card_Selected';//变换字体的颜色
	if(navigator.appName.indexOf("Explorer") > -1){ //判断不同的浏览器
		document.getElementById('bb_'+n).innerHTML="&bull;"+ document.getElementById('bb_'+n).innerText;//添加按钮文字前面的小圆点（IE浏览器）		
	} else{
		document.getElementById('bb_'+n).innerHTML="&bull;"+ document.getElementById('bb_'+n).textContent;//添加按钮文字前面的小圆点（FireFox和NC浏览器）		
	}

	lastSelectd=n;
}

/*****************************************************
显示指定的内容
*****************************************************/
function DispCard(CardName,DispFlag)
{
	if(DispFlag)
	{
		document.getElementById(CardName).style.display="";
	}
	else{
		document.getElementById(CardName).style.display="none";
	}
}

/*****************************************************
TAB卡选择函数
*****************************************************/
function secCard(n)
{
	for(i=0;i<secTable.cells.length;i++) 
	{
		secTable.cells[i].className="cardNormal";
	}
	secTable.cells[n].className="cardSelected";
	for(i=1;i<secTable.cells.length;i=i+2) 
	{
		secTable.cells[i].className="cardSpace";
	}
	secTable.cells[n+1].className="cardSpaceLeft";
	secTable.cells[3].className="cardSpaceLast";
}

/*****************************************************
TAB窗体选择函数
*****************************************************/
function secBoard(n)
{
	for(i=0;i<mainTable.tBodies.length;i++)
	{
		mainTable.tBodies[i].style.display="none";
	}
	mainTable.tBodies[n].style.display="";
}

/*****************************************************
根据本页面的实际尺寸调整IFRAME的大小
*****************************************************/
function ResizeIFrameSize(cFrameName)
{
	if(window.parent.document.getElementById(cFrameName) && document.getElementById('bdBody'))
	{
		var pageHeight = document.getElementById('bdBody').scrollHeight+30;
		if(pageHeight<=215)
		{
			pageHeight=215;
		}
		window.parent.document.getElementById(cFrameName).height=pageHeight;
	}	
}


/*****************************************************
检测异常字符
*****************************************************/
function CheckString(str)
{
	var c;
	var nErrChar;
	nErrChar = str.search(/[^A-Za-z0-9(){}]\-/); //正则表达式。匹配任何非字字符(括号除外)。
	return nErrChar;	
}

/*****************************************************
根据浏览器类型显示银行卡支付控件
*****************************************************/
function ShowIPERPlugIn()
{
	blnParamOK = GetTrxParam();
	
	CheckPlugInType();

	if (IsActiveX)
	{
		ShowIPERActiveX();
	}
	else
	{
		ShowIPERApplet();
	}
		
	CheckPlugIn("ComIPER",strComIPERUrl);
}

/*****************************************************
显示银行卡支付ActiveX控件
*****************************************************/
function ShowIPERActiveX()
{
	document.write("<OBJECT id=\"ComIPER\" width=\"300\" height=\"170\" classid=\"clsid:2BFAA61B-5C83-4865-8281-D8BDBF863061\" codebase=\"/PlugIn/PG_ATL.cab#version=1,0,0,14\">");
	document.write("<PARAM NAME=\"aa\" VALUE="+ strPGInKey +">");
	document.write("<PARAM NAME='codedisplay' value='" + Code_Display + "'>");
	document.write("</OBJECT>");
	document.write("<input type=\"hidden\" name=\"msg\" value=\"\">");
	document.write("<input type=\"hidden\" name=\"session\" value="+ strSessionKey + ">");
}

/*****************************************************
显示银行卡支付Applet控件
*****************************************************/
function ShowIPERApplet()
{
	document.write("<applet id=\"ComIPER\" code=\"Piform.class\" archive =\"/PlugIn/Piform.jar\" width=\"281\" height=\"170\">");
	document.write("<PARAM NAME=\"aa\" VALUE="+ strPGInKey +">");
	document.write("<PARAM NAME=\"left\" VALUE=460>");
	document.write("<PARAM NAME=\"top\" VALUE=210>");
	document.write("<PARAM NAME='codedisplay' value='" + Code_Display + "'>");
	document.write("</applet>");
	document.write("<input type=\"hidden\" name=\"msg\" value=\"\">");
	document.write("<input type=\"hidden\" name=\"session\" value="+ strSessionKey +">");
}

/*****************************************************
根据浏览器类型显示基金支付控件
*****************************************************/
function ShowFundPlugIn()
{
	blnParamOK = GetTrxParam();
	
	CheckPlugInType();

	if (IsActiveX)
	{
		ShowFundActiveX();
	}
	else
	{
		ShowFundApplet();
	}
		
	CheckPlugIn("ComIPER",strComIPERUrl);
}

/*****************************************************
显示基金支付ActiveX控件
*****************************************************/
function ShowFundActiveX()
{
	document.write("<OBJECT id='ComIPER' width='280' height='150' classid='clsid:7738573A-D66D-4002-8500-3F7A0E12E105' codebase='/PlugIn/PGFundATL.cab#version=1,0,0,6'>");
	document.write("<PARAM NAME='aa' value='" + strPGInKey + "'>");
	document.write("<PARAM NAME='card' value='"+ strCardNo + "'>");
	document.write("<PARAM NAME='idcard' value='" + strIdNo + "'>");
	document.write("<PARAM NAME='ybs' value='FALSE'>")
	document.write("</OBJECT>");
	document.write("<input type=\"hidden\" name=\"msg\" value=\"\">");
	document.write("<input type=\"hidden\" name=\"session\" value="+ strSessionKey + ">");
}

/*****************************************************
显示基金支付Applet控件
*****************************************************/
function ShowFundApplet()
{
	document.write("<applet id='ComIPER' width='280' height='150' code='Fund.class' archive ='/PlugIn/Fund.jar'>");
	document.write("<PARAM NAME='aa' VALUE="+ strPGInKey +">");
	document.write("<PARAM NAME='card' VALUE="+ strCardNo +">");
	document.write("<PARAM NAME='idcard' VALUE="+ strIdNo +">");
	document.write("<PARAM NAME='left' VALUE=450>");
	document.write("<PARAM NAME='top' VALUE=200>");
	document.write("</applet>");
	document.write("<input type='hidden' name='msg' value=''>");
	document.write("<input type='hidden' name='session' value="+ strSessionKey + ">");
}

/*****************************************************
显示易行卡支付控件
*****************************************************/
function ShowYPERActiveX()
{
	blnParamOK = GetTrxParam();

	document.write("<OBJECT id=\"ComYPER\" width=\"280\" height=\"70\" classid=\"clsid:8CFEC00F-7A38-4199-A6E9-BD73DC652978\" codebase=\"/PlugIn/PGCsATL.cab#version=1,0,0,7\">");
	document.write("<PARAM NAME=\"aa\" value='" + strPGInKey + "'>");
	document.write("<PARAM NAME=\"yxcard\" value=\"true\">");
	document.write("</OBJECT>");
	document.write("<input type=\"hidden\" name=\"msg\" value=\"\">");
	document.write("<input type=\"hidden\" name=\"session\" value="+ strSessionKey + ">");

	CheckPlugIn("ComYPER",strComYPERUrl);
}


/*****************************************************
显示易行卡密码修改控件
*****************************************************/
function ShowYCPWActiveX()
{
	blnParamOK = GetTrxParam();
	
	document.write("<OBJECT id=\"ComYCPW\" width=\"280\" height=\"150\" classid=\"clsid:8CFEC00F-7A38-4199-A6E9-BD73DC652978\" codebase=\"/PlugIn/PGCsATL.cab#version=1,0,0,7\">");
	document.write("<PARAM NAME=\"aa\" value='" + strPGInKey + "'>");
	document.write("<PARAM NAME=\"yxcard\" value=\"true\">");
	document.write("<PARAM NAME=\"changepwd\" value=\"true\">");
	document.write("</OBJECT>");
	document.write("<input type=\"hidden\" name=\"msg\" value=\"\">");
	document.write("<input type=\"hidden\" name=\"session\" value="+ strSessionKey + ">");
	
	CheckPlugIn("ComYCPW",strComYCPWUrl);
}


/*****************************************************
显示易行卡EPOS控件
*****************************************************/
function ShowEPOSActiveX()
{
	blnParamOK = GetTrxParam();
	
	document.write("<OBJECT id=\"ComEPOS\" width=\"240\" height=\"100\" classid=\"clsid:51760700-863C-417C-856A-18A40D50E07B\">");
	document.write("<PARAM NAME='codedisplay' value='" + Code_Display + "'>");
	document.write("</OBJECT>");
	document.write("<input type=\"hidden\" name=\"msg\" value=\"\">");
	
	CheckPlugIn("ComEPOS",strComEPOSUrl);
}

/*****************************************************
显示虚拟帐户控件
*****************************************************/
function ShowVPERActiveX()
{
	blnParamOK = GetTrxParam();

    document.write("<OBJECT id=\"FTComVPER\" width=\"0\" height=\"0\" classid=\"clsid:B494F2C1-57A7-49F7-A7AF-0570CA22AF80\" VIEWASTEXT>");
	document.write("</OBJECT>");
    
    CheckPlugIn("FTComVPER",strComVPERUrl);
}

/*****************************************************
显示储值卡（SVC）支付ActiveX控件
*****************************************************/
function ShowSPERActiveX()
{
	document.write("<OBJECT id=\"ComIPER\" width=\"300\" height=\"170\" classid=\"clsid:2BFAA61B-5C83-4865-8281-D8BDBF863061\" codebase=\"/PlugIn/PG_ATL.cab#version=1,0,0,14\">");
	document.write("<PARAM NAME=\"aa\" VALUE="+ strPGInKey +">");
	document.write("<PARAM NAME='codedisplay' value='" + Code_Display + "'>");
	document.write("<PARAM NAME='IsSVC' value='true'>");
	document.write("</OBJECT>");
	document.write("<input type=\"hidden\" name=\"msg\" value=\"\">");
	document.write("<input type=\"hidden\" name=\"session\" value="+ strSessionKey + ">");
}

/*****************************************************
检查ActiveX控件是否能正常显示
*****************************************************/
function CheckPlugIn(objID,strComUrl)
{
	var blnRet = false;
	try
	{
		if (IsActiveX)
		{
			blnRet=(eval("document." + objID + ".object") != null);
		}
		else
		{
			blnRet=(eval("document." + objID + ".object") != undefined);
		}

	}
	catch(e)
	{
		blnRet = false;
	}
	
	if(!blnRet)
	{
		document.write("<br><br><table id='NONINSTALLMSG' width=90% bgcolor=#E39F00 border=0 cellpadding=0 cellspacing=1>");
		document.write("<tr bgcolor=#FFCF60 height=40><td class=ppsmalltext align=center>" + MSG_NOT_INSTALL_PLUGIN + "<br><a href="+strComUrl+" onclick=document.getElementById('NONINSTALLMSG').style.display='none'; target=_blank>"+ MSG_CLICK_AND_DOWNLOAD +"</a></td></tr>");
		document.write("</table>");	
	}
}

/*****************************************************
执行交易，采用普通加密插件
*****************************************************/
function DoNormalTrans(p_ActionURL)
{		
	window.status = "";
	iRet=document.ComIPER.checkvalue();
	if(iRet==0)
	{
		if (IsActiveX)
		{
			strPayMsg=document.ComIPER.sendinfo;
		}
		else
		{
			strPayMsg=document.ComIPER.sendinfo();
		}

		//判断加密结果数据的合法性
		if (CheckString(strPayMsg) != -1)
		{
			window.alert(MSG_INPUT_DATA_INVALID);
			return;
		}
		if (strPayMsg==""||strPayMsg==null) 
		{
			window.alert(MSG_INPUT_PI_TOPAY);
		}
		else
		{
	  		document.PayMsgForm.msg.value=strPayMsg;
	  		if (intClickCount==0)
	  		{
				window.parent.document.getElementById('IPBIImg').src="/Images/proc_wait.gif";
				document.PayMsgForm.action=p_ActionURL;
				document.getElementById('btnPay').disabled = true;
				document.PayMsgForm.submit();
			}
	  		intClickCount=intClickCount+1;
	  	}
	 }  
	 else
	 {
		//向用户提示出错信息		
		var errmsg = GetPlugInRetMsg(iRet);
	 	window.status = errmsg;
	 	alert(errmsg);
	 }
}


/*****************************************************
执行银行卡手输卡号消费交易
*****************************************************/
function DoIPER()
{		
	window.status = "";
	iRet=document.ComIPER.checkvalue();
	if(iRet==0){
		if (IsActiveX)
		{
			strPayMsg=document.ComIPER.sendinfo;
		}
		else
		{
			strPayMsg=document.ComIPER.sendinfo();
		}

		//判断加密结果数据的合法性
		if (CheckString(strPayMsg) != -1)
		{
			window.alert(MSG_INPUT_DATA_INVALID);
			return;
		}
		if (strPayMsg==""||strPayMsg==null) 
		{
			window.alert(MSG_INPUT_PI_TOPAY);
		}
		else
		{
	  		document.PayMsgForm.msg.value=strPayMsg;
	  		if (intClickCount==0)
	  		{
				window.parent.document.getElementById('IPERImg').src="/Images/proc_wait.gif";
				document.PayMsgForm.action=strIPERURL;
				document.getElementById('btnpay').disabled = true;
				document.PayMsgForm.submit();
				document.PayMsgForm.disabled = true;
			}
	  		intClickCount=intClickCount+1;
	  	}
	 }  
	 else
	 {
		//向用户提示出错信息		
		var errmsg = GetPlugInRetMsg(iRet);
	 	window.status = errmsg;
	 	alert(errmsg);
	 }
}

/*****************************************************
执行银行卡查询交易
*****************************************************/
function DoIPBI()
{		
	window.status = "";
	iRet=document.ComIPER.checkvalue();
	if(iRet==0){
		if (IsActiveX)
		{
			strPayMsg=document.ComIPER.sendinfo;
		}
		else
		{
			strPayMsg=document.ComIPER.sendinfo();
		}

		//判断加密结果数据的合法性
		if (CheckString(strPayMsg) != -1)
		{
			window.alert(MSG_INPUT_DATA_INVALID);
			return;
		}
		if (strPayMsg==""||strPayMsg==null) 
		{
			window.alert(MSG_INPUT_PI_TOPAY);
		}
		else
		{
	  		document.PayMsgForm.msg.value=strPayMsg;
	  		if (intClickCount==0)
	  		{
				window.parent.document.getElementById('IPBIImg').src="/Images/proc_wait.gif";
				document.PayMsgForm.action=strIPBIURL;
				document.getElementById('btnquery').disabled = true;
				document.PayMsgForm.submit();
			}
	  		intClickCount=intClickCount+1;
	  	}
	 }  
	 else
	 {
		//向用户提示出错信息		
		var errmsg = GetPlugInRetMsg(iRet);
	 	window.status = errmsg;
	 	alert(errmsg);
	 }
}

/*****************************************************
执行银行卡手输卡号消费交易
*****************************************************/
function DoFund()
{		
	window.status = "";
	iRet=document.ComIPER.checkvalue();
	if(iRet==0){
		if (IsActiveX)
		{
			strPayMsg=document.ComIPER.sendinfo;
		}
		else
		{
			strPayMsg=document.ComIPER.sendinfo();
		}

		//判断加密结果数据的合法性
		if (CheckString(strPayMsg) != -1)
		{
			window.alert(MSG_INPUT_DATA_INVALID);
			return;
		}
		if (strPayMsg==""||strPayMsg==null) 
		{
			window.alert(MSG_INPUT_PI_TOPAY);
		}
		else
		{
	  		document.PayMsgForm.msg.value=strPayMsg;
	  		if (intClickCount==0)
	  		{
				window.parent.document.getElementById('IPERImg').src="/Images/proc_wait.gif";
				document.PayMsgForm.action=strFundURL;
				document.getElementById('btnpay').disabled = true;
				document.PayMsgForm.submit();
			}
	  		intClickCount=intClickCount+1;
	  	}
	 }  
	 else
	 {
		//向用户提示出错信息		
		var errmsg = GetPlugInRetMsg(iRet);
	 	window.status = errmsg;
	 	alert(errmsg);
	 }
}

/*****************************************************
执行易行卡手输卡号消费交易
*****************************************************/
function DoYPER()
{		
	window.status = "";
	iRet=document.ComYPER.checkvalue();
	if(iRet==0){
		strPayMsg=document.ComYPER.sendinfo;

		//判断加密结果数据的合法性
		if (CheckString(strPayMsg) != -1)
		{
			window.alert(MSG_INPUT_DATA_INVALID);
			return;
		}
		if (strPayMsg==""||strPayMsg==null) 
		{
			window.alert(MSG_INPUT_PI_TOPAY);
		}
		else
		{
	  		document.PayMsgForm.msg.value=strPayMsg;
	  		if (intClickCount==0)
	  		{
				window.parent.document.getElementById('YPERImg').src="/Images/proc_wait.gif";
				document.PayMsgForm.action=strYPERURL;
				document.getElementById('btnpay').disabled = true;
				
				document.getElementById('btndoecr').disabled = true;
				document.PayMsgForm.submit();
			}
	  		intClickCount=intClickCount+1;
	  	}
	 }  
	 else
	 {
		//向用户提示出错信息		
		var errmsg = GetPlugInRetMsg(iRet);
	 	window.status = errmsg;
	 	alert(errmsg);
	 }
}

/*****************************************************
执行南航手输卡号消费交易
*****************************************************/
function DoCSIPER()
{		
	window.status = "";
	iRet=document.ComIPER.checkvalue();
	if(iRet==0){
		if (IsActiveX)
		{
			strPayMsg=document.ComIPER.sendinfo;
		}
		else
		{
			strPayMsg=document.ComIPER.sendinfo();
		}

		//判断加密结果数据的合法性
		if (CheckString(strPayMsg) != -1)
		{
			window.alert(MSG_INPUT_DATA_INVALID);
			return;
		}
		if (strPayMsg==""||strPayMsg==null) 
		{
			window.alert(MSG_INPUT_PI_TOPAY);
		}
		else
		{
	  		document.PayMsgForm.msg.value=strPayMsg;
	  		if (intClickCount==0)
	  		{
				window.parent.document.getElementById('IPERImg').src="/Images/proc_wait.gif";
				document.PayMsgForm.action=strCSIPERURL;
				document.getElementById('btnpay').disabled = true;
				document.PayMsgForm.submit();
			}
	  		intClickCount=intClickCount+1;
	  	}
	 }  
	 else
	 {
		//向用户提示出错信息		
		var errmsg = GetPlugInRetMsg(iRet);
	 	window.status = errmsg;
	 	alert(errmsg);
	 }
}

/*****************************************************
执行南航EPOS消费交易
*****************************************************/
function DoCSEPER()
{
	var PayInfo;
	
	PayInfo=document.all.ComEPOS.LastResult;
	if(PayInfo.length < 256)
	{
		alert(MSG_PLEASE_USE_CARD);
		return false;
	}
	
	document.PayMsgForm.msg.value = PayInfo;
	
	document.PayMsgForm.action=strCSEPERURL;
	window.parent.document.getElementById('EPERImg').src="/Images/proc_wait.gif";
	
	document.PayMsgForm.submit();
	document.PayMsgForm.disabled = true;
	return true;
	
}

/*****************************************************
执行易行卡EPOS消费交易
*****************************************************/
function DoEPOSYPER()
{
	
	var PayInfo;
	
	PayInfo=document.all.ComEPOS.LastResult;
	if(PayInfo=="")
	{
		alert(MSG_PLEASE_USE_CARD);
		return false;
	}
	
	document.PayMsgForm.msg.value = PayInfo;
	
	document.PayMsgForm.action=strEPOSYPERURL;
	window.parent.document.getElementById('YPERImg').src="/Images/proc_wait.gif";
	
	document.PayMsgForm.submit();
	return true;
	
}

/*****************************************************
执行银行卡EPOS消费交易
*****************************************************/
function DoEPER()
{
	var PayInfo;
	
	/*
	//用GetLastResultCount判断是否事件函数已经调用过DoEPER函数
	if(GetLastResultCount > 0)
	{
		clearInterval(timeButton);
		return false;
	}
	GetLastResultCount++;
	*/
    
	PayInfo = document.all.ComEPOS.LastResult;
	
	if(PayInfo.length < 256)
	{
		alert(MSG_PLEASE_USE_CARD);
		return false;
	}
	
	document.PayMsgForm.msg.value = PayInfo;
	
	document.PayMsgForm.action=strEPERURL;
	window.parent.document.getElementById('EPERImg').src="/Images/proc_wait.gif";
	
	document.PayMsgForm.submit();
	document.PayMsgForm.disabled = true;
	return true;

}

/*****************************************************
执行银行卡EPOS查询交易
*****************************************************/
function DoEPBI()
{
	var PayInfo;
	
	/*
	//用GetLastResultCount判断是否事件函数已经调用过DoEPER函数
	if(GetLastResultCount > 0)
	{
		clearInterval(timeButton);
		return false;
	}
    GetLastResultCount++;
    */
    
    PayInfo = document.all.ComEPOS.LastResult;
    
    if(PayInfo.length < 256)
	{
		alert(MSG_PLEASE_USE_CARD);
		return false;
	}
    
    document.PayMsgForm.msg.value = PayInfo;

    document.PayMsgForm.action=strEPBIURL;
	window.parent.document.getElementById('EPERImg').src="/Images/proc_wait.gif";

	//alert(document.PayMsgForm.msg.value);
	document.PayMsgForm.submit();
	document.PayMsgForm.disabled = true;
	return true;

}

/*****************************************************
执行易行卡订单撤消交易
*****************************************************/
function DoYECR()
{
	var cMsg = MSG_CANCEL_ORDER;
	if(confirm(cMsg))
	{
		window.parent.document.getElementById('YPERImg').src="/Images/proc_wait.gif";				
		document.PayMsgForm.action=strYECRURL;
		document.PayMsgForm.ECRNO.value=strSessionKey;
		document.getElementById('btnpay').disabled = true;
		document.getElementById('btndoecr').disabled = true;
		document.PayMsgForm.submit();
	}
}


/*****************************************************
执行易行卡余额查询交易
*****************************************************/
function DoYPBI()
{		
	window.status = "";
	intRet=document.ComYPER.checkvalue();
	if(intRet==0){
		strPayMsg=document.ComYPER.sendinfo;

		//判断加密结果数据的合法性
		if (CheckString(strPayMsg) != -1)
		{
			window.alert(MSG_INPUT_DATA_INVALID);
			return;
		}
		if (strPayMsg==""||strPayMsg==null) 
		{
			window.alert(MSG_INPUT_PI_TOPAY);
		}
		else
		{
	  		document.PayMsgForm.msg.value=strPayMsg;
	  		if (intClickCount==0)
	  		{
				window.parent.document.getElementById('YPBIImg').src="/Images/proc_wait.gif";
				document.PayMsgForm.action=strYPBIURL;
				document.getElementById('btnquery').disabled = true;
				document.PayMsgForm.submit();
			}
	  		intClickCount=intClickCount+1;
	  	}
	 }  
	 else
	 {
		//向用户提示出错信息
		
		var errmsg = GetPlugInRetMsg(intRet);
	 	window.status = errmsg;
	 	alert(errmsg);
	 }
}

/*****************************************************
执行易行卡密码修改交易
*****************************************************/
function DoYCPW()
{
	var Ret;
	Ret = document.ComYCPW.ChangePassWord();
	
	if(Ret != 0)
	{
		var errmsg = GetPlugInRetMsg(Ret);
		alert(errmsg);
	}
	else
	{
		strPayMsg = document.ComYCPW.sendinfo;
		
		//判断加密结果数据的合法性
		if (CheckString(strPayMsg) != -1)
		{
			window.alert(MSG_INPUT_DATA_INVALID);
			return;
		}
		if (strPayMsg==""||strPayMsg==null) 
		{
			window.alert(MSG_INPUT_PI_TOPAY);
		}
		else
		{
	  		document.PayMsgForm.msg.value=strPayMsg;
	  		if (intClickCount==0)
	  		{
				window.parent.document.getElementById('YCPWImg').src="/Images/proc_wait.gif";
				document.PayMsgForm.action=strYCPWURL;
				document.getElementById('btnCPWD').disabled = true;
				document.PayMsgForm.submit();
			}
	  		intClickCount=intClickCount+1;
	  	}
	}

}


/*****************************************************
执行易行卡订单查询交易
*****************************************************/
function DoYTBI()
{	
	var txtTranSSN=document.PayMsgForm.txtTranSSN.value;
	if(txtTranSSN=="")
	{
		window.alert(MSG_INPUT_TRANSSN);
		document.PayMsgForm.txtTranSSN.focus();
		return -1;
	}
	else
	{
		window.parent.document.getElementById('YTBIImg').src="/Images/proc_wait.gif";
		document.PayMsgForm.action=strYTBIURL;
		document.getElementById('btnYTBI').disabled = true;
		document.PayMsgForm.submit();
		return 0;
	}
}

/*****************************************************
EPOS终端初始化
*****************************************************/
function DoEPOSInit()
{
	var intRet;
	var termInfo;
	
	
	//检测终端状态
	intRet = document.all.ComEPOS.CheckCommStat();
	if (intRet != 0)
	{
		alert(document.all.ComEPOS.LastResult);
		return false;
	}
	
	//检测终端信息
	intRet = document.all.ComEPOS.GetTermInfo();
	if(intRet != 0)
	{
		alert(document.all.ComEPOS.LastResult);
		return false;
	}
	else
	{
		termInfo = document.all.ComEPOS.LastResult;
	}
		
	if (termInfo.charAt(5) == '0' )
	{
		//没有密码键盘，显示软键盘，并扩展网页高度
		window.parent.document.getElementById('YPERForm').height=350;
		document.all.ComEPOS.height = 300;
	}
	
	GetEPOSData();
}

/*停止刷卡*/
function DoEPOSStop()
{
	if(confirm(MSG_CONFIRM_STOP_EPOS)){
		document.all.ComEPOS.stop();
		document.PayMsgForm.btnDoPay.disabled = false;
	}
}

/************************************************************
功能：定时检查是否已经加密处理完毕且“提交支付”的按钮没有变为有效
************************************************************/
function CheckLastResult()
{
	var PayInfo;
    //用GetLastResultCount判断是否事件函数已经调用过DoEPER函数
    //if(GetLastResultCount > 0)
    //{
    //    clearInterval(timeButton);
    //    return;
    //}
    /*
    PayInfo = document.all.ComEPOS.LastResult;
    
    //只有返回加密信息，长度才会超过256字节  
    if(PayInfo.length >= 256)
	{
        clearInterval(timeButton);
        DoEPER();
	}
	*/
}

/*****************************************************
获取EPOS终端刷卡信息
*****************************************************/
function GetEPOSData()
{
	var intRet;
	
	if (!CheckParams())
	{
		return false;
	}
	
	//获取支付信息
	//第二个参数是主密钥索引，取值范围1-32
	try
	{
		intRet = document.all.ComEPOS.GetPayInfo(strSessionKey, 1, strPGInKey, strPGAmount, 15);
	}catch(ex)
	{
		//alert("错误：\n\t" + ex.description + "\t\n\n请检查EPOS控件是否为最新版本。");
		alert(ERROR_EPOS_VERSION.replace("%1", ex.description));
	}
	
	if(intRet != 0)
	{
		alert(document.all.ComEPOS.LastResult);
		
		return false;
	}
	document.PayMsgForm.btnDoPay.disabled = true;

	//开始刷卡后启动定时器来检测控件是否已经返回加密的信息
	//timeButton=setInterval("CheckLastResult()",1000);

  return true;
}

/*****************************************************
计算虚账的交易数据，签名数据放在txtSignCode中

modified by lvjing 2006.09.26 
    (1)对FT的USB Key的兼容
    
*****************************************************/
function DoVASign(p_PlainText)
{
    var objCtrlFT; 
	var strSignedMsg = "";
    var strErrMsg = "";
    var strPlainText = p_PlainText;
    
    objCtrlFT = document.all.FTComVPER;
    
    window.status = "";
    
    //检查Key是否在线
    if (objCtrlFT.IsOnline != 0)
	{
	    alert(MSG_INSERT_USBKEY);
	    return false;
    }
        
    //指定证书
    if (objCtrlFT.SetCertResult != 0)
	{
		alert(MSG_CERT_SELECT_ERROR);
		return false;
	}
    
    //得到证书序列号
    var strCertSN = objCtrlFT.GetCertSerial;
    //取固定长（32字节）的证书序列号
    strCertSN = strCertSN.concat("                                ").slice(0,32);
    
    //在序列号后面增加明文信息
	strPlainText = strCertSN + strPlainText;
    if (objCtrlFT.SignResult(strPlainText) != 0)
	{
		alert(MSG_SIGN_ERROR);
		return false;
	}
	    
    strSignedMsg = objCtrlFT.GetSignature;
    
    document.all.txtMsg.value = strPlainText;       //签名成功后在明文前面增加了证书序列号
    document.all.txtSignCode.value = strSignedMsg;
    
    //alert(document.all.txtMsg.value);
    
    alert(MSG_SIGN_OK_TO_SUBMIT);

	return true;
}

/*****************************************************
执行虚拟帐户消费交易
*****************************************************/
function DoVPER()
{		
	var blnRet=false;
	document.all.txtSession.value 	= strSessionKey;
	document.all.txtSignCode.value 	= strPlainText;
	blnRet=DoVASign(strPlainText);
	if(blnRet)
	{
		window.parent.document.getElementById('VPERImg').src="/Images/proc_wait.gif";
		document.PayMsgForm.action=strVPERURL;
		document.getElementById('btnpay').disabled = true;
		document.PayMsgForm.submit();
	}
}

/*****************************************************
对本批次的支付数据进行签名，得到的多笔订单的支付明文数据与签名数据
保存于msg和signcode域中，同时填写ordercount域

written by Chenzi at 2007.1.25
    
*****************************************************/
function DoBatchVASign_old()
{
    var objCtrlFT; 
	var strLocSignedMsg = "";
    var strErrMsg = "";
    var strLocPlainText = "";
    var ix,iy;
    
    document.all.txtMsg.value = "";
    document.all.txtSignCode.value = "";
    
    //获取支付数据各元素
	var strLocSessionKey	= window.parent.document.frmMyForm.txtSESSIONPARA.value;
	var strLocMerNo			= window.parent.document.frmMyForm.txtMERNO.value;
	var strLocTermNo		= window.parent.document.frmMyForm.txtTERMNO.value;

	//获取批量支付数据(多个订单)
    var nOrderCount		= eval(window.parent.document.frmMyForm.txtOrderCount.value);
	var strPayNos		= window.parent.document.frmMyForm.txtPAYNO.value;
	var strPGAmounts	= window.parent.document.frmMyForm.txtPGAMOUNT.value;

	//分隔为相应的数组
	var arrPayNos		= strPayNos.split("|");
	var arrPGAmounts	= strPGAmounts.split("|");
	
	//定义支付明文数据数组及签名数据数组
	var arrPlainTexts	= new Array(nOrderCount);
	var arrSignedCodes	= new Array(nOrderCount);
	for(ix=0; ix<nOrderCount; ix++)
	{
		arrPlainTexts[ix] = strLocMerNo + strLocTermNo + arrPayNos[ix] + arrPGAmounts[ix] + strLocSessionKey;
		//arrPlainTexts[ix] = "aasdfasdfas2q41234234" + arrPlainTexts[ix];
		//alert((ix+1) + "\t" + arrPlainTexts[ix].length + "\t" + arrPlainTexts[ix]);
	}

    objCtrlFT = document.all.FTComVPER;
    
    window.status = "";
    
    //检查Key是否在线
    if (objCtrlFT.IsOnline != 0)
	{
	    alert(MSG_INSERT_USBKEY);
	    return false;
    }
        
    //指定证书
    if (objCtrlFT.SetCertResult != 0)
	{
		alert(MSG_CERT_SELECT_ERROR);
		return false;
	}
    
    //得到证书序列号
    var strCertSN = objCtrlFT.GetCertSerial;
    //取固定长（32字节）的证书序列号
    strCertSN = strCertSN.concat("                                ").slice(0,32);
    
    //在序列号后面增加明文信息
	for(ix=0; ix<nOrderCount; ix++)
	{
		arrPlainTexts[ix] = strCertSN + arrPlainTexts[ix];
		//alert((ix+1) + "\t" + arrPlainTexts[ix].length + "\t" + arrPlainTexts[ix]);
	}
    
    //依次对多个支付数据进行签名，签名失败则退出
    window.status = "请稍等......";
    //document.all.lblProcessingMsg.style.display = "";
	for(ix=0; ix<nOrderCount; ix++)
	{
	    if (objCtrlFT.SignResult(arrPlainTexts[ix]) != 0)
		{
			alert(MSG_SIGN_ERROR);
			return false;
		}
		arrSignedCodes[ix] = objCtrlFT.GetSignature;
	}
	
	//将支付明文数据及签名数据组合成串并设置到相应的域中
	for(ix=0; ix<nOrderCount; ix++)
	{
		document.all.txtMsg.value += arrPlainTexts[ix] + "|";
		document.all.txtSignCode.value += arrSignedCodes[ix] + "|";
	}
	document.all.txtOrderCount.value = nOrderCount;

    //alert(document.all.txtMsg.value);
    //alert(document.all.txtSignCode.value);
    
    alert(MSG_SIGN_OK_TO_SUBMIT);

	return true;
}

/*****************************************************
对本批次的支付数据进行签名，得到的多笔订单的支付明文数据与签名数据
保存于msg和signcode域中，同时填写ordercount域
被签名的明文数据格式为：
用户证书序列号（32字节）+商户号（15字节）+终端号（8字节）+唯一ID（19字节）+支付明细信息（最长662字节）

支付明细信息(payment_detail)存放批量支付的信息，包含：订单数量（2字节）、商户订单号（20字节）、终端流水号（6字节）、交易金额（12字节）、响应码（2字节）
其中，订单数量（2字节）放在payment_detail的头两个字节，剩下的为各笔交易信息数据

各数据域采用紧凑格式，单笔交易信息长度为40字节，格式如下：
商户订单号（20字节）+终端流水号（6字节）+交易金额（12字节）+响应码（2字节）

请求报文中响应码为空格，响应报文中响应码为该交易的结果

最多可存放16笔交易信息

written by Chenzi at 2007.6.11
*****************************************************/
function DoBatchVASign()
{
    var objCtrlFT; 
    var strErrMsg = "";
    var ix,iy;
    
    document.all.txtMsg.value = "";
    document.all.txtSignCode.value = "";
    
    //获取支付数据各元素
	var strLocSessionKey	= window.parent.document.frmMyForm.txtSESSIONPARA.value;
	var strLocMerNo			= window.parent.document.frmMyForm.txtMERNO.value;
	var strLocTermNo		= window.parent.document.frmMyForm.txtTERMNO.value;

	//获取批量支付数据(多个订单)
    var nOrderCount		= eval(window.parent.document.frmMyForm.txtOrderCount.value);
	var strMerOrderNos	= window.parent.document.frmMyForm.txtMERORDERNO.value;
	var strPayNos		= window.parent.document.frmMyForm.txtPAYNO.value;
	var strPGAmounts	= window.parent.document.frmMyForm.txtPGAMOUNT.value;
	
	if (nOrderCount>10)
	{
		alert("订单数据太大！");
		return false;
	}

	//分隔为相应的数组:商户订单号数组、交易流水号数组、交易金额数组
	var arrMerOrderNos	= strMerOrderNos.split("|");
	var arrPayNos		= strPayNos.split("|");
	var arrPGAmounts	= strPGAmounts.split("|");
	
	//临时变量
	var strTemp;
	
	//定义支付明细信息、被签名明文信息、签名信息
	var strLocPlainText = "";
	var strLocPayDetail = "";
	var strLocSignedMsg = "";
	
	//为响应码保留两位
	var strLocRespCode = "  ";
	
	strLocPlainText = strLocMerNo.concat("               ").slice(0,15) 
						+ strLocTermNo.concat("        ").slice(0,8) 
						+ strSessionKey.concat("                   ").slice(0,19);
	for(ix=0; ix<nOrderCount; ix++)
	{
		strLocPayDetail += arrMerOrderNos[ix].concat("                    ").slice(0,20) 
							+ arrPayNos[ix].concat("      ").slice(0,6) 
							+ arrPGAmounts[ix].concat("            ").slice(0,12)
							+ strLocRespCode;
	}
    //格式化订单数量
    strTemp = "00".concat(nOrderCount.toString());
    strTemp = strTemp.substring(strTemp.length, strTemp.length-2);
    
    //订单数量+订单明细信息
    strLocPayDetail = strTemp.concat(strLocPayDetail);

	//交易头信息+订单明细信息
	strLocPlainText = strLocPlainText.concat(strLocPayDetail);

    objCtrlFT = document.all.FTComVPER;
    
    window.status = "";
    
    //检查Key是否在线
    if (objCtrlFT.IsOnline != 0)
	{
	    alert(MSG_INSERT_USBKEY);
	    return false;
    }
        
    //指定证书
    if (objCtrlFT.SetCertResult != 0)
	{
		alert(MSG_CERT_SELECT_ERROR);
		return false;
	}
    
    //得到证书序列号
    var strCertSN = objCtrlFT.GetCertSerial;
    //取固定长（32字节）的证书序列号
    strCertSN = strCertSN.concat("                                ").slice(0,32);
    
    //在序列号后面增加明文信息
	strLocPlainText = strCertSN.concat(strLocPlainText);
    
    //进行签名，签名失败则退出
    window.status = "请稍等......";
    //document.all.lblProcessingMsg.style.display = "";
    if (objCtrlFT.SignResult(strLocPlainText) != 0)
	{
		alert(MSG_SIGN_ERROR);
		return false;
	}
	strLocSignedMsg = objCtrlFT.GetSignature;
	
	//将支付明文数据及签名数据组合成串并设置到相应的域中
	document.all.txtMsg.value = strLocPlainText;
	document.all.txtSignCode.value = strLocSignedMsg;
	document.all.txtOrderCount.value = nOrderCount;

    //alert(document.all.txtMsg.value);
    //alert(document.all.txtSignCode.value);
    
    window.status = "";
    alert(MSG_SIGN_OK_TO_SUBMIT);

	return true;
}


/*****************************************************
执行批量支付--虚拟帐户消费交易
*****************************************************/
function DoBatchVPER()
{		
	var blnRet=false;
	document.all.txtSession.value 	= strSessionKey;
	document.all.txtMsg.value = "";
	document.all.txtSignCode.value 	= "";
	blnRet=DoBatchVASign();
	if(blnRet)
	{
		window.parent.document.getElementById('VPERImg').src="/Images/proc_wait.gif";
		document.PayMsgForm.action = strBatchVPERURL;
		document.getElementById('btnpay').disabled = true;
		document.PayMsgForm.submit();
	}
}

/*****************************************************
执行虚拟帐户查询交易
*****************************************************/
function DoVPBI()
{		
	var blnRet=false;
	document.all.txtSession.value 	= strSessionKey;
	document.all.txtSignCode.value 	= strPlainText;
	blnRet=DoVASign(strPlainText);
	if(blnRet)
	{
		window.parent.document.getElementById('VPBIImg').src="/Images/proc_wait.gif";
		document.PayMsgForm.action=strVPBIURL;
		document.getElementById('btnpay').disabled = true;
		document.PayMsgForm.submit();
	}
}

/*****************************************************
检测EPOS参数是否正确
*****************************************************/
function CheckParams()
{
	if (!blnParamOK)
	{
		return false;
	}
	try
	{
		if (strPGInKey.indexOf("<!--")>=0)
		{
			alert(MSG_PARAMETER_GET_FAIL);
			return false;
		}
		if (strSessionKey.indexOf("<!--")>=0)
		{
			alert(MSG_PARAMETER_GET_FAIL);
			return false;
		}
		if (strPGAmount.indexOf("<!--")>=0)
		{
			alert(MSG_PARAMETER_GET_FAIL);
			return false;
		}
		return true;
	}
	catch(e)
	{
		alert(MSG_PARAMETER_GET_FAIL);		
		return false;
	}
}

/*****************************************************
重选银行
*****************************************************/
function SelectBank()
{
	window.parent.document.frmMyForm.action = strSelectBankURL;
	window.parent.document.frmMyForm.submit();
}


/*****************************************************
根据浏览器类型显示银行卡支付控件
*****************************************************/
function ShowSPERPlugIn()
{
	blnParamOK = GetTrxParam();
	
	CheckPlugInType();

	if (IsActiveX)
	{
		ShowSPERActiveX();
	}
	else
	{
		ShowSPERApplet();
	}
		
	CheckPlugIn("ComIPER",strComIPERUrl);
}


/*****************************************************
执行储值卡（SVC）手输卡号消费交易
*****************************************************/
function DoSPER()
{		
	window.status = "";
	iRet=document.ComIPER.checkvalue();
	if(iRet==0){
		if (IsActiveX)
		{
			strPayMsg=document.ComIPER.sendinfo;
		}
		else
		{
			strPayMsg=document.ComIPER.sendinfo();
		}

		//判断加密结果数据的合法性
		if (CheckString(strPayMsg) != -1)
		{
			window.alert(MSG_INPUT_DATA_INVALID);
			return;
		}
		if (strPayMsg==""||strPayMsg==null) 
		{
			window.alert(MSG_INPUT_PI_TOPAY);
		}
		else
		{
	  		document.PayMsgForm.msg.value=strPayMsg;
	  		if (intClickCount==0)
	  		{
				window.parent.document.getElementById('IPERImg').src="/Images/proc_wait.gif";
				document.PayMsgForm.action=strSPERURL;
				document.getElementById('btnpay').disabled = true;
				document.PayMsgForm.submit();
			}
	  		intClickCount=intClickCount+1;
	  	}
	 }  
	 else
	 {
		//向用户提示出错信息		
		var errmsg = GetPlugInRetMsg(iRet);
	 	window.status = errmsg;
	 	alert(errmsg);
	 }
}	

/*****************************************************
执行储值卡（SVC）查询交易
*****************************************************/
function DoSPBI()
{		
	window.status = "";
	iRet=document.ComIPER.checkvalue();
	if(iRet==0){
		if (IsActiveX)
		{
			strPayMsg=document.ComIPER.sendinfo;
		}
		else
		{
			strPayMsg=document.ComIPER.sendinfo();
		}

		//判断加密结果数据的合法性
		if (CheckString(strPayMsg) != -1)
		{
			window.alert(MSG_INPUT_DATA_INVALID);
			return;
		}
		if (strPayMsg==""||strPayMsg==null) 
		{
			window.alert(MSG_INPUT_PI_TOPAY);
		}
		else
		{
	  		document.PayMsgForm.msg.value=strPayMsg;
	  		if (intClickCount==0)
	  		{
				window.parent.document.getElementById('IPBIImg').src="/Images/proc_wait.gif";
				document.PayMsgForm.action=strSPBIURL;
				document.getElementById('btnquery').disabled = true;
				document.PayMsgForm.submit();
			}
	  		intClickCount=intClickCount+1;
	  	}
	 }  
	 else
	 {
		//向用户提示出错信息		
		var errmsg = GetPlugInRetMsg(iRet);
	 	window.status = errmsg;
	 	alert(errmsg);
	 }
}

/*****************************************************
执行DCCARD查询交易
*****************************************************/
function DoDCPBI()
{		
	DoNormalTrans(strDCPBIURL);
}

/*****************************************************
执行DCCARD消费交易
*****************************************************/
function DoDCPER()
{
	DoNormalTrans(strDCPERURL);
}


///////////////////////////////////////////////////////////////////////////////
//判断当前商户是否易办事
function CheckEBankUnion()
{
	var yes
	if (document.all.lblMerName.innerText == "银联易办事") 
//	if ( (document.all.lblMerName.innerText == "银联易办事")
//	|| (document.all.lblMerName.innerText == "广州嘉喜商务有限公司") )
	{
		document.all.lblMerName.innerText = "          银联易办事";
		yes = true;
	}
	else
	{
		yes = false;
	}
	return yes;
}

//判断是否能向商户发扩展信息
function CheckExtMsgEnabled()
{
	var Enabled = false;
	if ( (document.all.lblMerName.innerText == "银联易办事")
	|| (document.all.lblMerName.innerText == "广州韵峰物业管理有限公司") )
	{
		Enabled = true;
	}
	
	return Enabled;
}

//设置向商户发送的扩展信息
function EnableExtMsg(enable)
{
	if (enable)
	{
		var msg = "cardno:" + document.all.txtCardNo.value;
		msg += "|issbank:" + document.all.txtISSBank.value;
		msg += "|issbankname:" + document.all.txtISSBankName.value;
		msg += "|authno:" + document.all.txtAuthNo.value;
		msg += "|terminalno:" + document.all.txtTerminalNo.value;
		document.all.txtExtMsg.value = msg;
		document.all.txtExtMsg.disabled = false;
	}
	else
	{
		document.all.txtCardNo.disabled = true;
		document.all.txtISSBank.disabled = true;
		document.all.txtISSBankName.disabled = true;
		document.all.txtAuthNo.disabled = true;
		document.all.txtTerminalNo.disabled = true;
		document.all.txtExtMsg.disabled = true;
	}
}

