//Creado con Ardora - www.webardora.net
//bajo licencia Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)
//para otros usos contacte con el autor
var itemSel=1;var timeWrite;var aniPoint = 0;timeWrite = setInterval("paintLinePoint()", 100);
function initAct(){
if ((tiTime) && (tiButtonTime)){paintButtonTime();}for (i = 0; i < answers.length ; i++) {var nameDiv = "inputTxt" + (i + 1).toString();document.getElementById(nameDiv).value="";}if (tiAval){parent.iniciaActividade()}}
function randomSort(){var rand=0;var j=0;for (i = 0; i < doneB.length; i++) {rand = Math.floor(Math.random() * (doneB.length - 1));
if (doneB[rand] == "-1") {doneB[rand] = window.btoa(i);} else {j = rand;while (doneB[j] != "-1") {j++;if (j > answers.length - 1){j = 0;}}doneB[j]=window.btoa(i);}}}
function paintPoints(){var canvas = document.getElementById("ardoraActCanvasAnim"); canvas.style["visibility"]="visible"; canvas.width = canvas.width; var contexto = canvas.getContext("2d");
for (i = 0; i < doneA.length; i++) {if (doneA[i]=="0"){contexto.beginPath();contexto.fillStyle =colorSele;
contexto.arc(parseInt(panelWords(coorx[i])),parseInt(panelWords(coory[i])),4, 0 , 2 * Math.PI, false);contexto.fill();
contexto.strokeStyle =colorButton;contexto.lineWidth = 2;contexto.stroke();}else{contexto.beginPath();
contexto.fillStyle =colorButton;contexto.arc(parseInt(panelWords(coorx[i])),parseInt(panelWords(coory[i])),4, 0 , 2 * Math.PI, false);contexto.fill();
contexto.strokeStyle =colorSele;contexto.lineWidth = 2;contexto.font= "12px fontActi";
var metricsW = contexto.measureText(doneA[i]).width;var x=parseInt(panelWords(coorx[i]));var y=parseInt(panelWords(coory[i]))-12-5;
if (metricsW/2<x){x=x-metricsW/2;}else{x=10;}contexto.shadowColor = "black";contexto.shadowBlur = 5;contexto.shadowOffsetX = 3;contexto.shadowOffsetY = 3;
contexto.fillStyle =colorSele;contexto.fillRect(x-5,y-12-5,metricsW+10,12+10);contexto.fill();
contexto.shadowBlur=0;contexto.shadowOffsetX = 0;contexto.shadowOffsetY = 0;contexto.strokeStyle =colorButton;
contexto.lineWidth = 2;contexto.strokeRect(x-5,y-12-5,metricsW+10,12+10);
contexto.fillStyle =colorText;contexto.fillText(doneA[i],x,y);contexto.stroke();}}}
function paintLinePoint(){paintPoints();var canvas = document.getElementById("ardoraActCanvasAnim");var contexto = canvas.getContext("2d");var colorB;var colorL;aniPoint++;
if (aniPoint>3){aniPoint=0};if (aniPoint==0) { colorB=colorSele; colorL=colorBack;}
if (aniPoint==1) { colorB=colorButton; colorL=colorSele;}
if (aniPoint==2) { colorB=colorText; colorL=colorButton;} if (aniPoint==3) { colorB=colorBack; colorL=colorText;}
var orY=parseInt($("#txt"+itemSel).css("top"))+7+5;var orX=parseInt($("#txt"+itemSel).css("left"));var poS=atob(doneB[itemSel-1]);
var deX=parseInt(panelWords(coorx[poS]));var deY=parseInt(panelWords(coory[poS]));contexto.strokeStyle = colorB;contexto.lineCap= "round";contexto.lineWidth = 1;drawDashedLine(contexto, orX, orY, deX ,deY,[10,4]);
contexto.beginPath();contexto.fillStyle = colorB;contexto.arc(deX, deY, 4, 0, 2 * Math.PI, false);contexto.fill();contexto.strokeStyle = colorL;contexto.lineWidth = 2;contexto.stroke();}
function isCorrect(cell){
successes = 0;score=0;var correct=false; for (i = 0; i < answers.length ; i++) {var nameDiv = "inputTxt" + (i + 1).toString();var respu = $.trim(document.getElementById(nameDiv).value);
var solu=$.trim(answers[atob(doneB[i])]).replace("&#39;","'");correct=false;if (tiUD){if (respu.toUpperCase()==solu.toUpperCase()){ correct=true;}}else{if (respu==solu){correct=true;}}
if (correct){timeAct = timeAct + timeBon;score = score + scoreInc;successes++;doneA[atob(doneB[i])]=answers[atob(doneB[i])];}else{score = score - scoreDec;doneA[atob(doneB[i])]="0";itemSel=i+1;}}
if (successes==answers.length){clearInterval(timeWrite);paintPoints();showMessage("Ok");}else{attempts++;if (tiAttempts) {
if (attempts > attemptsMax) {showMessage("Attempts");} else {showMessage("Error");}} else {showMessage("Error");}}
}
function goTime(){clearInterval(timeInterval);showMessage("Time");}
function showSol(oldTypeGame){for (i = 0; i < doneA.length; i++) {doneA[i] = answers[i];}paintPoints(); }
function paintBack(){}
function panelWords(input) {var output = ""; var chr1, chr2, chr3 = ""; var enc1, enc2, enc3, enc4 = "";var i = 0;
var btest = /[^A-Za-z0-9\+\/\=]/g; if (btest.exec(input)) { alert("Invalid characters");} input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
do { enc1 = wordsStr.indexOf(input.charAt(i++)); enc2 = wordsStr.indexOf(input.charAt(i++)); enc3 = wordsStr.indexOf(input.charAt(i++)); enc4 = wordsStr.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);}
chr1 = chr2 = chr3 = ""; enc1 = enc2 = enc3 = enc4 = "";} while (i < input.length);return unescape(output);}
Array.prototype.in_array=function(){ for(var j in this){ if(this[j]==arguments[0]){return true;}}return false;}
