q = new Array();
q['q1'] = new Array('d435d227acdb11f14a3e85d34439bfa0a8023337' );
q['q2'] = new Array('171f58e7da694b7989343ce3d4f1cbfc01ea39b2' );
q['q3'] = new Array('50775f61733bc2b182f19a372163819ecd44ae02' );
q['q4'] = new Array('0c99e48f0b696b55e85623a9dc0138fe0420f507' );
q['q5'] = new Array('fe5087ab73488178f29a54ccc771b95622228645' );
q['q6'] = new Array('776e9803155b5c01862fc9896162f3327a6b70c9' );
q['q7'] = new Array('6c628f9321e363e3b9f05ef03ee49ebc886bcbe5' );
q['q8'] = new Array('55eb9fcee496c15cca2f26d1bb086422a7711085' );
q['q9'] = new Array('7434fa918f1cff45a2f9455ad4b6d3de9edd5560' );
q['q10'] = new Array('9e860df9caf4f036299cfdf03ad9728daa4e3cd3' );
q['q11'] = new Array('1becce5b2dc47f604a679f89bf2a97d4060508da' );
q['q12'] = new Array('93c299be6f3057b4a153f401b391dc14a073ea19' );
q['q13'] = new Array('53610791abe85e000f5df149e60306c2ec5ea505' );
q['q14'] = new Array('0d8ce0983e0ce3368729de0b95d8e152ab7d449f', '8e2562a2d2110ff5d94d19c62a869adb75349a83' );
q['q15'] = new Array('e4d9e37ce52cbc8c3150181b7e26631c80db9956' );
q['q16'] = new Array('4bff5f7633123c65d77ee3e247db1396ba06c3c0' );
q['q17'] = new Array('e31f4d79f4640566e72f9bcfb96d96aa2a85167b' );
q['q18'] = new Array('d8eef117c9af1835e28444ffe4dc9debf3988f47' );
q['q19'] = new Array('81f0ef452f69baccfc279aef1d8df70731c37bff' );
q['q20'] = new Array('c2c65542fa44b16ec9ec587a8562b2f097c38b07', 'ad4d98816f10229f0b156349e74a086c4cf8ca59' );
q['q21'] = new Array('b959594f803c0062fd72d2324842be15d07e523e', 'd17bb082e04f08a5f47e5f92f26b8d0ba2b800de' );
q['q22'] = new Array('bd9ce3f4a1fcb8ab8e691d3a97042c4619da3813' );
q['q23'] = new Array('1dde546fadabaf98af98ab944c9b9a600c3905fc', 'b0667c7bd3f77f09b501f5439a15d5af327ec17f' );
q['q24'] = new Array('07cdb47207929275bd004244640e417a7ece49e7', '55ada3237a95708a7494e319e9f6bb27a59fb55e' );
q['q25'] = new Array('e012cd1fc15761edb8af53d2344e2ebe81c73b15' );
q['q26'] = new Array('f6398ee58ffeb0ab0968d1ffcbf3f47baf25c261' );
q['q27'] = new Array('9e02ed8a30163457ea917cfdf1331b5b6e5508b8' );
q['q28'] = new Array('92fa9b095a075c9cdff821d27f9b056758c6134b' );
q['q29'] = new Array('c6e960b7debb634e430ef9113e82784e0d3214a3' );
q['q30'] = new Array('e5adb6eab148ddbcb894ff63719d4b1190dccd22' );
q['q31'] = new Array('4e48a785c736a7d16c64795d7276f255b5e2d913' );
q['q32'] = new Array('3244f2aad9c4c8637f587602be7c9f2e6ded347d' );
q['q33'] = new Array('27504be6cef69208c49423134665ae3899bc9f3d' );
q['q34'] = new Array('5100f2082761f8b57f516f5c0b7207415181ae59' );
q['q35'] = new Array('3aa47e4c3871d2113ed1c8206ad7853d2322d008' );
q['q36'] = new Array('c9f172799fd003089d7339657d875f6c44c6ce0b' );
q['q37'] = new Array('3ac1a9cf977ca7638ac2018f47c484fd59852409' );
q['q38'] = new Array('dc1b9b4bb07d1464277843f034100c63208665b6' );
q['q39'] = new Array('a61904b3345f6e9eef3ff49f12c0b029f61a1b77' );
q['q40'] = new Array('dc25fdc51ea081673e62b5853f16dc8e64e96d9e' );
q['q41'] = new Array('10a6a782e2ef6a8c7f116828265053f0295ccc7f' );
q['q42'] = new Array('6cad4d0ba752d1b451ce604353df45b15e0b93e5', '6cad4d0ba752d1b451ce604353df45b15e0b93e5', '5e3695cea2a4a709f50a3e14508d5535259c5f8e' );
q['q43'] = new Array('f5b1a1f9ccec6a2038937bd3b83875d0177161b4' );
q['q44'] = new Array('1a2a8e341a26a2f4617019ac598347fd0befab33' );
q['q45'] = new Array('61c509bdde263ed88cdbaf17e28a88ccc7e8d04d' );
q['q46'] = new Array('1acab325521b0a08863c5eb967acd76b98e12b28' );
q['q47'] = new Array('99a34c442cd77be3e284883ca3dee06708e985a4' );
q['q48'] = new Array('c1f5708b358be720e1f5320c45a274ae645cd588' );
q['q49'] = new Array('4df8d1aed1b4f961c4e7e18a65c45ee3603e8e96' );
q['q50'] = new Array('6edf1aaf8c81e0598039286b9e6992ae3059dc07' );
q['q51'] = new Array('7be084229079946530cfaebe168eac4be80397c2' );
q['q52'] = new Array('26b0d5ffd0c17330bed9e82c550b40fd1cb4fb85' );
q['q53'] = new Array('c5396097625d7b56008d09d9f2a36def73917baa' );
q['q54'] = new Array('262f3cf8bf346640567d5f9e6a3ae9951358a6f0', '2c1ff16fa0818e85eacae28a9ffb54fd15f35e2f' );
q['q55'] = new Array('e91b1fba966c3fd75462931a3a1ff7486cc54ee9' );
q['q56'] = new Array('631327641ac93aef8f1f2b968805f91b530484ac' );
q['q57'] = new Array('becc8f3b93302c6c594dc504c4e3b3c783cd1b89' );
q['q58'] = new Array('be314a133a0cd3f3b3be29d3762997a0586c0181' );
q['q59'] = new Array('0719bab4885ce378169b85c8a940196c1ca2be70' );
q['q60'] = new Array('e6825b70bcde4bb11e71e231e4ae7498a361a457' );
q['q61'] = new Array('7158147cbc5191220c56aeece91b7b72b54997c9' );
q['q62'] = new Array('f1949038def843c653e14c9a18dfcbce35b796d5' );
q['q63'] = new Array('5e988ad379fbbd3560e245223ec896dab527eec3' );
q['q64'] = new Array('2a0b61e787d15c77c387bdd11a8f9097a1aaf42f' );
q['q65'] = new Array('7e2d2126a172486786eb71af100f9127acc28c1d' );
q['q66'] = new Array('481e116ff1ad577d4316c3f567cdbd9b8362500a' );
q['q67'] = new Array('8f655d58467e691dbbbe09382a590e909182d646' );
q['q68'] = new Array('10a6a11107992106c967c14c2e9ff3d8affce4a9' );
q['q69'] = new Array('26b0d5ffd0c17330bed9e82c550b40fd1cb4fb85' );
q['q70'] = new Array('8f655d58467e691dbbbe09382a590e909182d646' );
q['q71'] = new Array('6f7e1377add1b8d45a32dd2a6997886d61bb59bb' );
q['q72'] = new Array('78c234dd70238917a0d7e567a3e352a250f5ee22' );
q['q73'] = new Array('2819564933f74df675792fb50e9264d80374a005' );
q['q74'] = new Array('38143106d494f25f8b03922e9d4706c8d9798386' );
q['q75'] = new Array('09d791c2ca07b3dbca411f9476025f990dabe449' );
q['q76'] = new Array('f0b2c06502a9ed8153bad38a8fa1aa67eed6febc' );
q['q77'] = new Array('aaa4e62d0fab8a3479baf7b2ffe2b5756fad461e' );
q['q78'] = new Array('3ff51451250db0e61e5735cbd7695ccdc24c06b6' );
q['q79'] = new Array('21ffd16cd4312a0366a65c80c8626128230b1387' );
q['q80'] = new Array('ff3e36cdd9fda9f189f86cb4a620c2f35ee0bfe3' );
q['q81'] = new Array('ec84a73225d5a2382f07a9a49cda95e9bb40034b' );
q['q82'] = new Array('890bc58f18c0ae59e7a8682c3000c68decdca0b6' );
q['q83'] = new Array('6827be022b7dfd3e5c50b4794a8f86a4665a00c8' );
q['q84'] = new Array('dbdcece8dc6f2195faa3aa60fb29cf8d899494b1' );
q['q85'] = new Array('2450654ea84b56c4d71eeec2bf29da20619770ef' );
q['q86'] = new Array('d124b2387157452e6423044ab212e34d1bfd3442' );
q['q87'] = new Array('3ad549d62e868c0ccaefd9c0d8c8bb7f87da009f' );

 
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,'');							
	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<=87; i++) {		
		str='q'+i;	
		document.getElementById(str).style.border = '1px solid #A5ACB2';
		document.getElementById(str).disabled = false;

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