var B = {

	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

	d : function(input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;

		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

		while (i < input.length) {

			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));

			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;

			output = output + String.fromCharCode(chr1);

			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}

		}

		output = B._u(output);

		return output;

	},

	_u : function(u) {
		var s = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while (i < u.length) {

			c = u.charCodeAt(i);

			if (c < 128) {
				s += String.fromCharCode(c);
				i++;
			} else if ((c > 191) && (c < 224)) {
				c2 = u.charCodeAt(i + 1);
				s += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			} else {
				c2 = u.charCodeAt(i + 1);
				c3 = u.charCodeAt(i + 2);
				s += String.fromCharCode(((c & 15) << 12)
						| ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return s;
	}

}

//----------------------------------------------------------------------

var done = false;

var T1 = "t1";
var T2 = "t2";
var T3 = "t3";

var start = 1;
var max = 100;
var curmax = 0;

var erg = 0;

var descr = {};
var type = {};
var ans = {};


descr["1"]="VGhlIEFkdmFuY2VkIEVuY3J5cHRpb24gU3RhbmRhcmQuIEFsdGhvdWdoIG90aGVyIEFFUyBjaGFsbGVuZ2VycyBoYXZlIGJlY29tZSBtb3JlIGNvbW1vbiB0byB1c2Uu";
type["1"]="dDE=";
ans["1"]="Mw==";
descr["2"]="U3ltbWV0cmljIGVuY3J5cHRpb24gaXMgbXVjaCBmYXN0ZXIgdGhhbiBhc3ltbWV0cmljIGVuY3J5cHRpb24sIGVzcGVjaWFsbHkgd2hlbiBtb3JlIHRoYW4ganVzdCBhIGZldyBraWxvYnl0ZXMgYXJlIGJlaW5nIGVuY3J5cHRlZC4=";
type["2"]="dDE=";
ans["2"]="MQ==";
descr["3"]="QSBwdWJsaWMga2V5IGlzIG9ubHkgcmFuZG9tIGJpbmFyeSBkYXRhIHdpdGhvdXQgYSBjbGVhciByZWxhdGlvbiB0byBhbiBpZGVudGl0eSBvciBwZXJzb24uIElkZW50aXR5IG1hbmFnZW1lbnQgcmVxdWlyZXMgYWRkaXRpb25hbCBlZmZvcnQgbGlrZSBjaGVja3N1bXMgdGhhdCBhcmUgZXhjaGFuZ2VkIGRpcmVjdGx5IG9yIFguNTA5djMgY2VydGlmaWNhdGVzIChlLmcuLCB1c2VkIGluIEhUVFBTL1NTTC9UTFMpLg==";
type["3"]="dDE=";
ans["3"]="Mg==";





function $(id) {
	return document.getElementById(id);
}

function submit2() {
	if (done || $("sp").value == "d") {
		alert("You already submitted this exam.");
		$("erg").innerHTML = "You already submitted this exam!";
		$("erg").style.color = "red";
		return;
	}

	for ( var ix = start; ix <= max; ix++) {
		elem = document.getElementById('' + ix);
		if (elem == null){
			curmax = ix - 1;
			break;
		}

		var runner = elem.id;
		var c = false;

		if(B.d(type[runner]) == T1) {
			var radios = elem.getElementsByTagName('input');
			c = false;

			for ( var i = 0, length = radios.length; i < length; i++) {
				if (radios[i].checked) {
					c = true;
					break;
				}
			}
			
			if(!c){
				alert("Please answer all questions!");
				$("erg").innerHTML = "Please answer all questions!";
				$("erg").style.color = "red";
				return;
			}
		}
	}//for					
	
	done = true;
	$("sp").value = "d"

	for ( var ix = start; ix <= max; ix++) {

		elem = document.getElementById('' + ix);

		if (elem == null) {
			break;
		}

		var runner = elem.id;

		var c = false;

		switch (B.d(type[runner])) {
		case T1:

			var radios = elem.getElementsByTagName('input');

			var a = B.d(ans[runner]).split(';');

			var x = [];

			for ( var i = 0, length = radios.length; i < length; i++) {
				x[i] = i;
			}

			c = true;

			for ( var i = 0; i < a.length; i++) {
				if (a[i] > radios.length)
					continue;

				x[a[i]] = -1;

				if (!radios[a[i]].checked) {
					c = false;
					break;
				}

			}

			if (c) {

				for ( var i = 0, length = x.length; i < length; i++) {
					if (x[i] < 0)
						continue;

					if (radios[i].checked) {
						c = false;
						break;

					}
				}

			}

			break;

		case T2:

			var tx = elem.getElementsByTagName('input')[0];
			c = (tx.value.trim().toLowerCase() == B.d(ans[runner]).trim().toLowerCase());

			break;

		default:
			alert("Unknown Error. Please report to support@hissenit.com");

		}

		if (c) {
			erg++;
			$(elem.id + "res").innerHTML = "Correct: "
					+ B.d(descr[runner]);
			$(elem.id + "res").style.color = "green";

		} else {
			$(elem.id + "res").innerHTML = "Wrong: "
					+ B.d(descr[runner]);
			$(elem.id + "res").style.color = "red";

		}

	}//for

	var perci = 0;
	if (curmax > 0) perci = Math.round((erg / curmax) * 100);

	$("erg").innerHTML = "Your result: " + perci + "% (" + erg + "/" + curmax + ")";
	$("erg").style.color = "";
	
	location.hash = 'sp';
	
	//SCORM

ScormProcessInitialize();

// Completion / Status
ScormProcessSetValue('cmi.core.lesson_status', 'completed');

// Score
ScormProcessSetValue("cmi.core.score.raw", perci);
ScormProcessSetValue("cmi.core.score.min", "0");
ScormProcessSetValue("cmi.core.score.max", "100");

if (perci >= 70) {
    ScormProcessSetValue("cmi.core.lesson_status", "passed");
} else {
    ScormProcessSetValue("cmi.core.lesson_status", "failed");
}

// Exit
ScormProcessSetValue("cmi.core.exit", "");

ScormProcessTerminate();

}//submit
