function isIE()  
{  
	if(window.ActiveXObject || "ActiveXObject" in window){
		return true;
	}
   return false;
} 

var infoSecNetSign ;
/* 引入签名控件 *///cab/
function importSignObject(basePath) {
	
	if(isIE()==false && (clickItem=='2' || clickItem=='4' || clickItem=='5'))
	{
		alert(PAGES_ALERT_CHNGBROWSER);
		return;
	}
    var signObject = signObjectFactory(basePath + "cab/");
	
    $(signObject).appendTo('body');
    //document.write(signObject);
	infoSecNetSign = document.getElementById("BoccSign");
	try{
		infoSecNetSign.NSSetDigestArithmetic("1.3.14.3.2.26");
		infoSecNetSign.NSSetCodePage("936");
	}catch(e)
	{
		//alert(PAGES_ALERT_CHNGBROWSER);
	}
}
/* 生成签名控件 */
function signObjectFactory(signFileDir) {
	var navPlatform = getNavigatorPlatform();
	if(navPlatform == 'Win32') {
		signFileName = 'NetSign20.cab';
		signClassId = "B3B938C4-4190-4F37-8CF0-A92B0A91CC77";
	}else if(navPlatform == 'Win64') {
		signFileName = 'NetSign20_64.cab';
		signClassId = 'AA6BA3FC-3428-4443-B7AB-D2A85AF20250';
	}
	var signObject = '<div style="display:none">';
	signObject += '<OBJECT id=BoccSign style="WIDTH: 0px; HEIGHT: 0px" ';
	signObject += 'codeBase=' + signFileDir + signFileName + '#version=2,0,59,4 ';
	signObject += 'classid=clsid:' + signClassId + ' VIEWASTEXT></OBJECT></div>';
	
 	signObject += '<div id="infosign" style="display:none">';
	signObject += '<OBJECT id=InfoSecNetSign1 style="WIDTH: 0px; HEIGHT: 0px" codeBase='+signFileDir+'NetSign.cab#version=1,8,23,5 data=DATA:application/x-oleobject;BASE64,xDi5YpBBN0+M8KkrCpHMdwADAABMWQAA/wIAAA== classid=clsid:62B938C4-4190-4F37-8CF0-A92B0A91CC77  VIEWASTEXT width="864" height="29">';
	signObject += '</OBJECT>';
	signObject += '</div>';
	
	return signObject;
}
/* 获取浏览器类型 */
function getNavigatorPlatform() {
	if(navigator.userAgent.indexOf("WOW64") > -1) {
		return "Win32";
	}
	if(navigator.platform.indexOf("Win64") > -1 ) {
		return "Win64";
	}else {
		return "Win32";
	}
}

/* 签名 （Attached方式）*/
function attachedSign(source) {
	var defaultSignerDN = "OU=Customers,OU=BANKCOMM,O=BANKCOMM CA,C=CN";//生产
	
	if(isIE()==false)
	{
		alert(PAGES_ALERT_CHNGBROWSER);
		return;
	}
	infoSecNetSign.NSSetPlainText(source);
	if(infoSecNetSign.errorNum!=0) {
		alert("返回值〔"+infoSecNetSign.errorNum+"〕\n"+infoSecNetSign.errMsg);
		return ;
	}
	var sign = infoSecNetSign.NSAdvanceAttachedSign(defaultSignerDN);
	
    if(infoSecNetSign.errorNum != 0){
    	var oldSign = $('#InfoSecNetSign1').get(0);
    	oldSign.NSSetPlainText(source);  
    	sign = oldSign.NSAttachedSign(defaultSignerDN); 
    	
    	return sign;
    }
    /*
	if(infoSecNetSign.errorNum!=0) {
		alert("返回值〔"+infoSecNetSign.errorNum+"〕\n" + infoSecNetSign.errMsg+"\n底层返回值("+infoSecNetSign.errorCode+")");
		return ;
	}*/
	return sign;
}

/* 签名 （detachedSign方式）*/
function detachedSign(source) {
	var sign = infoSecNetSign.NSDetachedSign(source, "");
	if(infoSecNetSign.errorNum!=0) {
		alert("返回值〔"+infoSecNetSign.errorNum+"〕\n" + infoSecNetSign.errMsg+"\n底层返回值("+infoSecNetSign.errorCode+")");
		return ;
	}
	return sign;
}