/*
 * 财付通密码输入相关处理函数:使用公司QQEDIT控件
 */
function CQQEdit()
{ 
  //是否使用QQEDIT控件 
  this.m_bUseFlag = true;
  //QQEDIT控件版本
  //控件GUID
  //this.m_sClassid = "clsid:D151948A-F3F3-41FE-BE76-07C64ACE8B53";//"clsid:E787FD25-8D7C-4693-AE67-9406BC6E22DF";
   this.m_sVersion = "1,1,0,4"; 
  //控件GUID
  this.m_sClassid = "clsid:E787FD25-8D7C-4693-AE67-9406BC6E22DF";

  //控件路径
  this.m_sLocate = "https://www.tenpay.com/download/qqedit.cab";
  
	this.CheckValid = CQQEdit_CheckValid;
	this.Reload = CQQEdit_Reload;
	
	this.GetStrongPasswd = CQQEdit_GetStrongPasswd;
	this.GetRsaPassword = CQQEdit_GetRsaPasswd;
	this.GetRsaPassword2 = CQQEdit_GetRsaPasswd2;
	this.GetShaPassword = CQQEdit_GetSha1Passwd;
	
	this.GetTmFrmVcd = CQQEdit_GetTmFrmVcd;
	this.GetTmFrmNumStr= CQQEdit_GetTmFrmNumStr;
	//绘出控件
	this.Draw = CQQEdit_Draw;
	
}
function CQQEdit_GetTmFrmNumStr(str)
{
  var res="";
  for(i=0;i<str.length;i++)
  {
    res += "3";
    res += str.substring(i,i+1);
  }
  return res;
}
function CQQEdit_GetTmFrmVcd(vcd)
{
  var tm = "12345678";
  if(vcd.length != 4)
  {
    tm += "901234567890";
  }
  else
  {  
    for(i=0 ;i <4;i++)
    {
      var tmp = vcd.charCodeAt(i).toString();
      if(tmp.length != 3)
        tm += "0" ;
        tm += tmp;
    }
  }
  return tm;
}

function CQQEdit_Draw(idname, tabindex, other)
{
  var strObj;
  strObj = "<OBJECT id=\"" + idname + "\" ";
  strObj+= "classid=\"" + this.m_sClassid + "\" ";
  strObj+= " codebase=\"" + this.m_sLocate + "#Version=" + this.m_sVersion + "\" viewastext";
  
  if(tabindex)
  	strObj+=" tabindex=\"" + tabindex + "\"";

	if(other)
		strObj+=" " + other;
  
  strObj+= " height=22 width=159></OBJECT>";
  document.write(strObj);
  
  try{
	  
		if(document.getElementById(idname).Mode==null){
				document.write("<img src=\"/zft/images/logind.gif\"><a href=\"/download/qqedit.exe\"><font style=\"font-size:12px\" color=ff6600>无法输入登录密码？");
				document.write("请点此安装安全控件后刷新");
			}
		} catch(er) {}
}
function CQQEdit_GetSha1Passwd(ctl,seed)
{
  ctl.SetSalt(seed);
  shap = ctl.GetSha1Value();
  return  shap;
}
function CQQEdit_GetRsaPasswd(ctl,seed)
{
  ctl.SetSalt(seed);
  rsap = ctl.GetRsaPassword();
  return rsap;
}
function CQQEdit_GetRsaPasswd2(ctl,seed)
{
  ctl.SetSalt(seed);
  rsap = ctl.GetRsaPassword2();
  return rsap;
}
//沿用历史
function CQQEdit_GetStrongPasswd(ctl,seed)
{
  ctl.SetSalt(seed);
  shap = ctl.GetSha1Value();
  rsap = ctl.GetRsaPassword();
  return (seed + shap + rsap);
}

function CQQEdit_CheckValid(ctl)
{
	try//因为高版本控件不支持GetPasswordInfo
	{
		var inf = ctl.GetPasswordInfo();
		if(inf & 1)
		{
			alert("安全校验码失效，请刷新页面。");
			this.Reload();
			return false;
		}
		return true;
	}
	catch(exp)
	{
	  return true; 
	}
}
function CQQEdit_Reload()
{
	window.location.reload();	
}

var g_CQQEdit = null;

if(g_CQQEdit == null)
	g_CQQEdit = new CQQEdit();
