q = new Array();

q['q1'] = new Array('f7e3e36665201430f924846ce394935e49548276');
q['q2'] = new Array('73c0563205ebb4e55bf5430aae19edb05e279fed');
q['q3'] = new Array('49685e07ad4dad1d1474303554e469ef0eff023a');
q['q4'] = new Array('f337e280df2c35f9a86098d96042664364713c8d');
q['q5'] = new Array('b4301e4bc1aea642ab9bac2f13320083b9e9ae36');
q['q6'] = new Array('8bd9c6f09ef9b2b55d98efcebd29eb0f1af1ec0d');
q['q7'] = new Array('862c392394a35867d46749d555174fdb0cbf2aff');
q['q8'] = new Array('c3188c7635b818654ada48c365b20d19ac5c7469');
q['q9'] = new Array('80fa3c26f02ec9dee66e31a19f48b9798a6eee76');
q['q10'] = new Array('cf8cace5df9f82a6c37ea5865f878fb6f377d511');
q['q11'] = new Array('15c8dc07948ebfcfa668ee5548e77dcc7e1f2287');
q['q12'] = new Array('21817509c49db8c5faed26133ca79eb7dc394d66');
q['q13'] = new Array('095292871a28c2f2c292750f8a6313adafce4a15');
q['q14'] = new Array('1a1dda8300d783892278f344ae9217cfc87b5990');
q['q15'] = new Array('5216f20be98365ce4eee6d4a56114fb91ab1864d', 'f066ba915098e7067296f39f9f5e297060b6d712');
q['q16'] = new Array('3cf77200e188a361d288b88d0f093a32f52ca23d');
q['q17'] = new Array('43e83f6b86494d14f738c1f3c04e36084233f73d');
q['q18'] = new Array('0ea8073bb871809be6b8423498442f15f9402153');
q['q19'] = new Array('28485df6a658e5bfce21fff03045b95cff46d8d4');
q['q20'] = new Array('70a500b888cf2ff7286cddead1b03cb58a61b78e');
q['q21'] = new Array('cfe851492e312b21475de893647cda0e99ae3268');
q['q22'] = new Array('82b9d6b030c97138013965ec98296d6cf1adb32d', '442031c64803b2abc1aee7829adda610ff772251');
q['q23'] = new Array('a4ff8cca124e8b36168988392562fc8c7c40b1a2');
q['q24'] = new Array('685ce049172c89f23778ae9b90dcf16285745a28');
q['q25'] = new Array('8a0491c6de0b4afe4f637f69f500ce52ca391f4e');
q['q26'] = new Array('61e49403be2b4a6ade1b35bbd6c8d959bfd100a8', '0bdcc8f4a8b02f74d69a9ecf143cf15f28f98cfc');
q['q27'] = new Array('a9eaa9fa5f1f0125b76ef02de1714030297b4983');
q['q28'] = new Array('cc0190bead5d9682c074a9b6264fb1766fda0fb0');
q['q29'] = new Array('9eca3015c86dbd200470961616e5fa54137ba84e');
q['q30'] = new Array('8dc2c4c787b3b9eb002822b2e6d94d54a0c47e0b');
q['q31'] = new Array('0adfcec059632162aac689263bbb112f553c9db8');
q['q32'] = new Array('ee37af256aec8115ed120506905a1e998622a92f');
q['q33'] = new Array('cc25b41c832fab3d561b0e7fafb2012a730a8a08');
q['q34'] = new Array('f5c907de2bacfbd6c184a6dc731688b698938a4e');
q['q35'] = new Array('0022f5497e68df34e7843e5e2d35e40fed3c9d40');
q['q36'] = new Array('4d452fcbc0bb90467886ac9e40c86074bebbbc01');
q['q37'] = new Array('791f453b11abfc962d39a85553bb907108f185ff', '6c9a7582c6065b410d96f15e56647406bd51399d');
q['q38'] = new Array('01df4078b3da5c88a2f9fdd0406ba386240c3b63', 'e8bf5fc0b2dadcd075cecceda97d27fcc6ee0e74');
q['q39'] = new Array('3da077eb8abbbba3ea63d0b0181401afcabc4b19');
q['q40'] = new Array('0221f25947d5001185dae6ba8e7fcc03b52600b5');
q['q41'] = new Array('4e80d67f1c6853e7c47c4065626b4d218981a67c');
q['q42'] = new Array('18468f918f31f23f45afd9a962b49ee29169fc6e', '5200bdfc01a139a753c6eb52ee1911cadd069dd9');
q['q43'] = new Array('0ddb3dddd7c97aa63a856968edeb605cb3676244');
q['q44'] = new Array('3b933848d5c89874b1354f2f68468372c3726083');
q['q45'] = new Array('d785944f0d0f78b66f099f28f9224d4f3c23a402');
q['q46'] = new Array('b16aec1a89783a4731e365e5141b1078456853d3');
q['q47'] = new Array('46c9b13c6891d709724dda8b38695d062f7e4355');
q['q48'] = new Array('552b091d29cbd3174db70f3bfe692939765af2db');
q['q49'] = new Array('8f216ba94758334c0e7a7389c58e41e54718d3f7');
q['q50'] = new Array('7aae989fa7324d35d97a83be812110536edbcdc5');
q['q51'] = new Array('ada68f5ba64d006002285699e0544c9a81ebb40b');
q['q52'] = new Array('0c3c49626b8a51e4e87251061f5bdae395d377a6');
q['q53'] = new Array('f78a231168d7cd4726840e1fb3c335c365d0fdad');
q['q54'] = new Array('63e0d00f888600160b1820b6aa4b2773145323a8');
q['q55'] = new Array('f9f507d644a1ec652a4030a3747d59c69a6ef1fd');
q['q56'] = new Array('d6ab95a7d2cd1f8728b313b6f290a25b8cb4c121');
q['q57'] = new Array('5238e1a1711b8050fdb587277b9891908d8b7dfc');
q['q58'] = new Array('f286caf7723b9baf47958136a07118594c590a88');
q['q59'] = new Array('8b9acfd3800c7c96ee033537dca755a10045764e');
q['q60'] = new Array('2c064c1d2a50ffd945cc70f7bfc81629926d4d3a');
q['q61'] = new Array('f993e19ea284438bab67e27482f4779e5a0e8e4d');
q['q62'] = new Array('42cc720826aad993ebeb4126202c63abe7ffd4fb');
q['q63'] = new Array('e007d7d28eca8ef0d978442ff45e96b1facbfd0d', 'e007d7d28eca8ef0d978442ff45e96b1facbfd0d');
q['q64'] = new Array('0362bfa489228b5aadbf197c118c008aeda9ba3d');
q['q65'] = new Array('79d46d92ca6d70237e02572e7f16fd514343c997');
q['q66'] = new Array('ecd48efd68d46c703fc60d67348b73eebedbfe7e');
q['q67'] = new Array('a8e7246b3cc4fcb35076a23b5772b4dc149ace35', 'd22c8842eabbc0694eedbb013779efaffbf419c7', '472134df4b68350d9143ad2ed1f7c131d812daa5');
q['q68'] = new Array('51d6d90635e78bf662c9a354c50415ed3efc10ac');
q['q69'] = new Array('0a512b1d79972fc4e52967eeb5135475241305e1');
q['q70'] = new Array('918aa498307c0f5f1417fc6ebe31a949951a554a');
q['q71'] = new Array('fb45f622e526eee51a010b2205940bf4206f459b');
q['q72'] = new Array('883b08efaafb67a763242292b75d482de7133165');
q['q73'] = new Array('654d6f6e31171678ae1d6a7f13eb7bc8a616bcdf');
q['q74'] = new Array('2db29e637d3b073a5c5f851ff375a6e8e713f783');
q['q75'] = new Array('465f390c24c8e90722451c7ea5ce0085301648e1');
q['q76'] = new Array('e53188b6635c69136f2ce37d09586ea9b80ed70d');
q['q77'] = new Array('5313ce4fa080c9c6d66d4dd07d7d4aa66e6b0940');
q['q78'] = new Array('bad53cc9e1822ea093ed2b57212d09350ff961e5');
q['q79'] = new Array('e71a0463e75d83c70ec93c24087a8f77903ab4e3');
q['q80'] = new Array('dc2576719e904b1a07b7c189ebca5064befd2065');
q['q81'] = new Array('925f70115a1c1c06e43e9363cd147463dbd385da');



function simplifica(msg) {
	
	var str=msg.toUpperCase();
	str=str.replace(/ /g,'');			
	str=str.replace(/\,/g,'');			
	str=str.replace(/\./g,'');			
	str=str.replace(/\-/g,'');			
	str=str.replace(/\'/g,'');			
	str=str.replace(/\:/g,'');			
	str=str.replace(/\(/g,'');			
	str=str.replace(/\)/g,'');	
	str=str.replace(/\?/g,'');			
	str=str.replace(/\¿/g,'');			
	str=str.replace(/\!/g,'');			
	str=str.replace(/\¡/g,'');							
	str=str.replace(/Á/g,'A');
	str=str.replace(/É/g,'E');
	str=str.replace(/Í/g,'I');
	str=str.replace(/Ó/g,'O');
	str=str.replace(/Ú/g,'U');
	
	
	return str;
	
}  


function mirar(str) {

var ok=0;
for (x in q[str])
{
	if(sha1Hash(simplifica(document.getElementById(str).value)) == (q[str][x]) 	)
	{
		
		ok=1;
	}
}  


	if(ok)
	{
		validar1(str);
	}
	else
	{
		validar2(str);
	}
	
}

function carga() { 
	
	for (var i=1; i<76; i++) {		
		str='q'+i;	
		document.getElementById(str).style.border = '1px solid #A5ACB2';
		document.getElementById(str).disabled = false;
	} 
} 


function validar1(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 validar2(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;
    }

    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<76;i++) {
	document.getElementById('q'+i).disabled = false;
	}
	document.forms[0].reset();
}