function EstEIDModuleLoadFormGetPath() {
	return document.getElementById("esteidmodloadform").path.value;
}
function EstEIDModuleLoadFormSetPath(path) {
	document.getElementById("esteidmodloadform").path.value = path;
}

function EstEIDModuleUnloadFormGetName() {
	return document.getElementById("esteidmodunloadform").name.value;
}
function EstEIDModuleUnloadFormSetName(name) {
	return document.getElementById("esteidmodunloadform").name.value = name;
}


/* Mozilla PKCS#11 functions */
function EstEIDLoadModule() {
	var module_path = EstEIDModuleLoadFormGetPath();
	var module_name = "opensc-pkcs11";
	var PKCS11_PUB_READABLE_CERT_FLAG = 0x1<<28;
	var flags = PKCS11_PUB_READABLE_CERT_FLAG;
	var res = 0;
	res = pkcs11.addmodule(module_name, module_path, flags, 0);
	
	if ( res >= 0) {
		/* Do nothing */
	} else if ( res  == -2 ) {
		window.alert("Lisamine katkestatud kasutaja poolt!\nCancelled by the user!");
	} else if ( res == -5 ) {
		window.alert("Moodulit  \"" + module_path + "\" ei leitud!\nModule \"" + module_path + "\" was not found!");
	} else if ( res == -10 ) {
		window.alert("Moodul nimega \"" + module_name + "\" on juba laetud!\nModule \"" + module_name + "\" is already installed!");
	} else {
		window.alert("Tundmatu viga " + res);
	}
}

function EstEIDUnloadModule() {
	var module_name = EstEIDModuleUnloadFormGetName();
	var res = 0;
	res = pkcs11.deletemodule(module_name);
	if ( res >= 0) {
		/* Do nothing */
	} else if ( res  == -2 ) {
		window.alert("Lisamine katkestatud kasutaja poolt!\nCancelled by the user!");
	} else if ( res == -4 ) {
		window.alert("Moodulit nimega \"" + module_name + "\" ei leitud!!\nModule \"" + module_name + "\" was not found!");
	} else {
		window.alert("Tundmatu viga " + res);
	}
}

