q = new Array();

q['q1'] = new Array('11244285fe72d6ed7e5cb9a0454e0f0320109716');
q['q2'] = new Array('dd6079a54e59d839aeafe5655eabcf44addf96da');
q['q3'] = new Array('e0ac5ea8ebd33009690d221fb208dfb4f537afa1');
q['q4'] = new Array('5eb35eabe54650725a4eee3fee94c0dfde84f09f');
q['q5'] = new Array('1a22b9b8fc3d7ec78e5a3160f526e84d7c1ac0e0');
q['q6'] = new Array('d712ef818d3865fa26c3fcfecbe3bff9fcec6000');
q['q7'] = new Array('8500a30f92bb3e0a52e05d2cea76b6678806aa4c');
q['q8'] = new Array('c99a4187127e63ff8523efa854730ca0d4645f12');
q['q9'] = new Array('6eedf21844e467d1ec3f589dd89373cea1531f91');
q['q10'] = new Array('808b4f9e54302ca020963d89c6d9598c066fa7d8');
q['q11'] = new Array('4f71b07dba77dee793dc74116d12079d32586a50');
q['q12'] = new Array('60a3b0d92321ab260081c46ff5fec7bc47009f6f');
q['q13'] = new Array('2a87f5f25de0560763fec970d75b67075836d88b');
q['q14'] = new Array('d1ab1ea5a551f6c18850e3ce1daee33bb90e1be9');
q['q15'] = new Array('09b7f1c6d05ac2e87469947f01ce4fd46c00be94');
q['q16'] = new Array('89f82144e54a2d28b2b8501d3e12b03ba9670027');
q['q17'] = new Array('e822513640baa5b760a15e75a84236d18c6e403a');
q['q18'] = new Array('018a2049e3289365b95dc4a20ea7ac4b50b18305');
q['q19'] = new Array('3609ea9be16d4355a7c5b48096e88dd06c08c5f5');
q['q20'] = new Array('5e8b0f1f0c5f0fa05619efa59db8d9edec2fd74d');
q['q21'] = new Array('63e38331b305d60f7b2640a1e14a14dcb60d7324');
q['q22'] = new Array('4bee586e43607709f9238d88f0ed0a427678121c');
q['q23'] = new Array('6c6e3a7a387e64a84759fb4a8226ba9cda1c2bdb');
q['q24'] = new Array('af6c59c504c3101b22345bb163beadb4d414b90a');
q['q25'] = new Array('244d550bf18801a972b2f3a27afb912b4675a68b');
q['q26'] = new Array('3a2033b35fde8d496bbe4d1df65ba164867c8311');
q['q27'] = new Array('d954043fbf02afd6f1b9b86e36394ce1d0937190');
q['q28'] = new Array('e325d232238e6446485992426ee71e47e9e2c4f3');
q['q29'] = new Array('b1e3c4467e913519cdbce5b4784aaa852335010f');
q['q30'] = new Array('dfa36897d0d79626c26c3a60bbf710ce93f678ec');
q['q31'] = new Array('e9e7616eca0393ea75e1bedad4cf1460243badf4');
q['q32'] = new Array('3f3b8e71aff364e0983afa08c584d7da66d0b041');
q['q33'] = new Array('a4af37c71f55b673158498af498abac834501c8d');
q['q34'] = new Array('51fc66c606844b7b4bf5a5e5b953e035a8f122d9');
q['q35'] = new Array('9f4ce4246ca49788a5b7ee60065d5b9214c4df8a');
q['q36'] = new Array('4d11beedca0ea46c207e0afbd72ba09be971ca3b');
q['q37'] = new Array('569bea285d70dda2218f89ef5454ea69fb5111ef');
q['q38'] = new Array('61c188090e1199874d6adf0d1b46e756fff21e30');
q['q39'] = new Array('1c01cb91fa1e56e85858b17bdd182d1adea241c0');
q['q40'] = new Array('8107c494bf0d151cc6c9c77a04632884477bc4f7');
q['q41'] = new Array('d532b556dfd01eeae96d5e60ab19ff200b4c053b');
q['q42'] = new Array('03b8a126d8f0c1f381ca5c129acc029d3c436ab0');
q['q43'] = new Array('7d346e6cf7534f3f4c02a8786cb9c1e0d327d4b5');
q['q44'] = new Array('7690b7ccb987f4b3f32d2b9e7e8a69db2d0ded02');
q['q45'] = new Array('34d5a1deaafb5257de89f8b5040b5099ba1d5d92');
q['q46'] = new Array('3a04c1912933194bd68d5fde5f9bf9330d909a90');
q['q47'] = new Array('25968f9d41d45aa8eeb513895e3579e8535d1dc4');
q['q48'] = new Array('979fe91b552588d71419b6db4374e114077d82d9');
q['q49'] = new Array('2b3c55d927cfb0c056334471b38ece06cc195ef1');
q['q50'] = new Array('d84a4097cf76a2c0541d441e8840a8f673f41ff5');
q['q51'] = new Array('76db3c18ccf5791b0d902bc7b29a848f84e6ba77');
q['q52'] = new Array('a64f61c784f54aff3e04261a400e285ee6e480b7');
q['q53'] = new Array('b88893c96c5a1f5773a5e75467682d7cd5d37765');
q['q54'] = new Array('7f0f487615b737136a512bbfa0123651cb181000');
q['q55'] = new Array('b6da39994cdaa07713db3e83033a3cecf269e168');
q['q56'] = new Array('6dd82305dbffc2e710d52bfa2bb84130307d2c8b');
q['q57'] = new Array('bcbf77bd08a3ce4eb2025929e8b4884267bd1602');
q['q58'] = new Array('9033e449539e4d8d5f2f63718e93194d7233fbb8');
q['q59'] = new Array('90e75d0087276528605b20340c004aaa6e67529d');
q['q60'] = new Array('31a57e4775fa69185ddc2fdbe860846ba2f6e439');
q['q61'] = new Array('6cad4d0ba752d1b451ce604353df45b15e0b93e5');
q['q62'] = new Array('0c93650ff8c7a193a02bd275f060f150fe78e015');
q['q63'] = new Array('1630b8c0c87f9f2bea7547c67314d11dcf3509d4');
q['q64'] = new Array('38215b1a93d1d8f5c5624f28d655a1cd859364b7');
q['q65'] = new Array('e2a4a924301ddb6f67d9dc5fd3d1fc0bedb59091');
q['q66'] = new Array('37a7446cdbd92d1b35af975de40d4f01914a84a7');
q['q67'] = new Array('d511260aedbe87f096a25f348f2b52f37e93bc47');
q['q68'] = new Array('4e07baf185f787919dec555408dcd0416a476ac9');
q['q69'] = new Array('24848d2e3bfdf1130b08de8770a4249128882cca');
q['q70'] = new Array('e75dd829360f17dde55d486516f0575c92eee459');
q['q71'] = new Array('9e135ba6fc99c0c06b1d9a6ef980b3e44c5f70a6');
q['q72'] = new Array('7e5b07d8bbb5e0a55b5d428476d4691b3ee97b4a');
q['q73'] = new Array('1d995e6f359121214fc621f6542cc9b184c1ac79');
q['q74'] = new Array('9713cad8d34bf70309cc35eef3cae9f7baa40217');
q['q75'] = new Array('69c56356363fe5d550f6246c4bef3d5ff3021f55');



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();
}