answer1 = "tralalala";
q = new Array();

q['q1'] = '6eb6cf6a1de53652b4610ee860f19205520ba37d';
q['q2'] = '90a63bf1cbc2f6669cc3eb236b1e786472d5fc9f';
q['q3'] = '9f05a64cf9e21ca47cd9a02afc014260f30c3c59';
q['q4'] = '88d4b8b2eba10dfc9de135cd84b43201a107c403';
q['q5'] = 'bfe6b7db42f46892ee193bb93bd9e5293e891573';
q['q6'] = 'fc231d832f80d88a37e286be5a494265e087e357';
q['q7'] = '0c4e39666d361a47b97c9b8dd47fe13c7bcf76a2';
q['q8'] = '4807b48dab3aca29c4bda96a00aebc0035c86430';
q['q9'] = '7146d81d2344ba5482e991d878b1403378410564';
q['q10'] = 'cadeb72ee674717470ce36f7fd7a5fc2c8a4a0cd';
q['q11'] = '3187e5683b167ffafd62066128fe52400773164f';
q['q12'] = '8b1b29e38ef90248e10aa8af4deb7336d5af6bcd';
q['q13'] = '73943eafc8c40a8b380f535ef76406f961e26374';
q['q14'] = '54e9349e179e3a8f5b4e6872a233697c2713537e';
q['q15'] = 'cc1c131fefb163de10cd1e2e1d186878cab1b0ca';
q['q16'] = '1b1602630a5c1320d445bd93e60f9be91748bf59';
q['q17'] = 'd0f98dfdff997477e60c4d8a5150a9c5e652e36c';
q['q18'] = '3fbef1972acd4abe004cae0d10d402991cb8749d';
q['q19'] = 'b46b6986727d1674c49580b6e469aab91da908c6';
q['q20'] = '78cf265c05a00abaa48cd0137655872eef11d67d';
q['q21'] = '968f4ead462812db1d2fdc19a4437e9df5860bd4';
q['q22'] = '6c1cee4def852ebdeacd37c37e07691c754de1fa';
q['q23'] = 'b23fc162e930b87a84a2199f31915b35fbc6938e';
q['q24'] = '3f2ff6a5bbd41b702ad41c6f04ba1b22c693d2e8';
q['q25'] = 'f08420db7db76227d56403774a4e55d5b53a7830';
q['q26'] = '9bd45ffcdbb290b53a2ed285bd518533528c7fac';
q['q27'] = 'a7ca31ad2f584470a537f3e34b086e828371da52';
q['q28'] = 'baeb5e1a7fd3bbe0e7d454f12a303a832177ee9d';
q['q29'] = '7fa1247035598987e1350f309ff9214a9c27eb62';
q['q30'] = '85b20d9009c25f898b732dd219c36710f80fa970';
q['q31'] = 'cf50b6ae4cb92a305a485555fa8dae214a0e11cc';
q['q32'] = '9c0a5ad378cea40944153323b59e68dfce455a2f';
q['q33'] = '756a34a92da7d9b5611f6ad2d80e0a7f16016ff8';



function checkQ(str) {
	if(sha1Hash(document.getElementById(str).value.toUpperCase()) == q[str])
	{
		validate1(str);
	}
	else
	{
		validate2(str);
	}
	
}
function validate1(qstr) {
	if(document.getElementById(qstr).disabled == false) {
	document.getElementById(qstr).disabled = true;
	document.getElementById(qstr).style.border = '2px solid #00FF00'; 
	document.getElementById('correct').innerHTML = document.getElementById('correct').innerHTML*1 + 1;
	}
}

function validate2(qstr) {
	if(document.getElementById(qstr).value=='') {
		document.getElementById(qstr).style.border = '1px solid #A5ACB2'; 
	}
	else
	{
	document.getElementById(qstr).style.border = '2px solid #FF0000'; 
	}
}


function sha1Hash(msg)
{
    // constants [4.2.1]
    var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];

    // PREPROCESSING 
 
    msg += String.fromCharCode(0x80);  // add trailing '1' bit to string [5.1.1]

    // convert string msg into 512-bit/16-integer blocks arrays of ints [5.2.1]
    var l = Math.ceil(msg.length/4) + 2;  // long enough to contain msg plus 2-word length
    var N = Math.ceil(l/16);              // in N 16-int blocks
    var M = new Array(N);

    for (var i=0; i<N; i++) {
        M[i] = new Array(16);
        for (var j=0; j<16; j++) {  // encode 4 chars per integer, big-endian encoding
            M[i][j] = (msg.charCodeAt(i*64+j*4)<<24) | (msg.charCodeAt(i*64+j*4+1)<<16) | 
                      (msg.charCodeAt(i*64+j*4+2)<<8) | (msg.charCodeAt(i*64+j*4+3));
        } // note running off the end of msg is ok 'cos bitwise ops on NaN return 0
    }
    // add length (in bits) into final pair of 32-bit integers (big-endian) [5.1.1]
    M[N-1][14] = ((msg.length-1) >>> 30) * 8;
    M[N-1][15] = ((msg.length-1)*8) & 0xffffffff;

    // set initial hash value [5.3.1]
    var H0 = 0x67452301;
    var H1 = 0xefcdab89;
    var H2 = 0x98badcfe;
    var H3 = 0x10325476;
    var H4 = 0xc3d2e1f0;

    // HASH COMPUTATION [6.1.2]

    var W = new Array(80); var a, b, c, d, e;
    for (var i=0; i<N; i++) {

        // 1 - prepare message schedule 'W'
        for (var t=0;  t<16; t++) W[t] = M[i][t];
        for (var t=16; t<80; t++) W[t] = ROTL(W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16], 1);

        // 2 - initialise five working variables a, b, c, d, e with previous hash value
        a = H0; b = H1; c = H2; d = H3; e = H4;

        // 3 - main loop
        for (var t=0; t<80; t++) {
            var s = Math.floor(t/20); // seq for blocks of 'f' functions and 'K' constants
            var T = (ROTL(a,5) + f(s,b,c,d) + e + K[s] + W[t]) & 0xffffffff;
            e = d;
            d = c;
            c = ROTL(b, 30);
            b = a;
            a = T;
        }

        // 4 - compute the new intermediate hash value
        H0 = (H0+a) & 0xffffffff;  // note 'addition modulo 2^32'
        H1 = (H1+b) & 0xffffffff; 
        H2 = (H2+c) & 0xffffffff; 
        H3 = (H3+d) & 0xffffffff; 
        H4 = (H4+e) & 0xffffffff;
    }

    //alert (H0.toHexStr() + H1.toHexStr() + H2.toHexStr() + H3.toHexStr() + H4.toHexStr());
    return H0.toHexStr() + H1.toHexStr() + H2.toHexStr() + H3.toHexStr() + H4.toHexStr();
}

//
// function 'f' [4.1.1]
//
function f(s, x, y, z) 
{
    switch (s) {
    case 0: return (x & y) ^ (~x & z);
    case 1: return x ^ y ^ z;
    case 2: return (x & y) ^ (x & z) ^ (y & z);
    case 3: return x ^ y ^ z;
    }
}

//
// rotate left (circular left shift) value x by n positions [3.2.5]
//
function ROTL(x, n)
{
    return (x<<n) | (x>>>(32-n));
}

//
// extend Number class with a tailored hex-string method 
//   (note toString(16) is implementation-dependant, and  
//   in IE returns signed numbers when used on full words)
//
Number.prototype.toHexStr = function()
{
    var s="", v;
    for (var i=7; i>=0; i--) { v = (this>>>(i*4)) & 0xf; s += v.toString(16); }
    return s;
}
function resetForm() {
	
	for(i=1;i<34;i++) {
	document.getElementById('q'+i).disabled = false;
	}
	document.forms[0].reset();
}

