var GTGBAtx = new ActiveXObject("GTGBClientAtx.GTBGClient");

function setupAuthenticathion(multi, first) {
	GTGBAtx.setServerPublicKey(document.input.serverCryptoKey.value);
	/*
	if(first == "true" && multi == 0) {
		GTGBAtx.createSessionKey();

	}
	if(multi != 0) {
		GTGBAtx.createSessionKey();
	}
	*/
	GTGBAtx.setChallenge(document.input.challenge.value);
	GTGBAtx.setChallengeToken(document.input.challengeToken.value);
	
}

function authenticatePAM(){
	var ISignWebAgent = null;
	try {
		ISignWebAgent = new ActiveXObject("ISign.WebAgent");
	}
	catch (e) {
		clickCount = "0";
		alert("Issac-File 또는 Isign-desktop이 설치되지 않았습니다.\n설치 위치: http://172.17.26.170/oac\n정보보안 : 4278, 4449");
		return;
	}		
	
	var res = "";
	if(ISignWebAgent.isLogined() == true) {
		res = GTGBAtx.makePAMParameter();
	} else {
		clickCount = "0";
		alert("ISSAC-FILE 또는 Isign Desktop에 로그인 하십시오!!!");
		return;
	}
	
	document.login.sessionKey.value =   GTGBAtx.getCryptoSessionKey();	
	document.login.parameters.value =  res;
	document.login.submit();
}

function loginIDPW(){
	if(document.input.userId == null || document.input.userId.value == "") {
		alert("ID를 입력해주십시오.");
		document.input.userId.focus();
		return;
	}	
	if(document.input.userPassword == null || document.input.userPassword.value == "") {
		alert("패스워드를 입력해주십시오.");
		document.input.userPassword.focus();
		return;
	}
	document.login.sessionKey.value = GTGBAtx.getCryptoSessionKey();
	document.login.parameters.value = GTGBAtx.makeIDPWParameter(document.input.userId.value, document.input.userPassword.value);
	document.login.submit();
}

function displayCard() {
	document.login.sessionKey.value = GTGBAtx.getCryptoSessionKey();
	document.login.parameters.value = GTGBAtx.makeSAMParameter(document.input.userId.value, document.input.cardNumber.value);
}

function loginSAM(){
	document.login.submit();
}

function successAuthentication(secureToken, sessionId, userInfo){
	GTGBAtx.setSecureToken(secureToken);
	
	GTGBAtx.setSessionId(sessionId);
	GTGBAtx.setUserInfo(userInfo);
}

function saveSecureToken(secureToken){
	var result = GTGBAtx.setSecureToken(secureToken);
}

function authorization(form) {
	form.Securesessionid.value=GTGBAtx.encryptSymm(GTGBAtx.getSessionId());
	form.Securetoken.value=GTGBAtx.getSecureToken();
	form.submit();
}

function checkAuthentication(form) {
	form.Securesessionid.value=GTGBAtx.getSessionId();
	form.Securetoken.value=GTGBAtx.getSecureToken();
	form.submit();
}

function challenge() {
	document.logout.submit();
}

function movePage() {
	document.moveForm.submit();
}

function checkSecureToken() {
	alert(GTGBAtx.getSecureToken());
	return GTGBAtx.getSecureToken();
}

function authenticatePAM_T(){
	var ISignWebAgent = null;
	try {
		ISignWebAgent = new ActiveXObject("ISign.WebAgent");
	}
	catch (e) {
		clickCount = "0";
		alert("Issac-File 또는 Isign-desktop이 설치되지 않았습니다.\n설치 위치: http://172.17.26.170/oac\n정보보안 : 4278, 4449");
		return;
	}
		
	var res = "";
	if(ISignWebAgent.isLogined() == true) {
		res = GTGBAtx.makePAMParameter();
	} else {
		clickCount = "0";
		alert("ISSAC-FILE 또는 Isign Desktop에 로그인 하십시오!!!");
		return;
	}
	
	document.pkiLogin.sessionKey.value =   GTGBAtx.getCryptoSessionKey();
	document.pkiLogin.parameters.value =  res;
	document.pkiLogin.submit();
}
