//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
function initAct(){
if (tiAval){parent.iniciaActividade()}if ((tiTime) && (tiButtonTime)){paintButtonTime();}
loadMoney();
}
function loadMoney(){
totCentFixed = ce[ram_G[indexGame]];totEurosFixed = eu[ram_G[indexGame]];
$(".coin").each(function() {this.remove();});var tot=totEurosFixed+totCentFixed;var avMoney=tiC.slice();var totPaint=0;var newCoins=[];
for (i = values.length-1; i>-1; i--) {while (avMoney[i]>0 && values[i]+totPaint<=tot){var newCoin= $('<img class="coin" src="numDeci01_resources/media/'+m[i].substr(1)+'.gif"/>');newCoins.push(newCoin);totPaint=totPaint+values[i];avMoney[i]--;}}
for (i=0; i<newCoins.length;i++){$("#drop").append(newCoins[i]);} paintScore();
var newHtml="";if ($.trim(im[ram_G[indexGame]])){newHtml='<img id="imaL" class="imaLeft" alt="Ima" src="numDeci01_resources/media/'+im[ram_G[indexGame]]+'">';}
newHtml=newHtml+te[ram_G[indexGame]];$("#actText").html(newHtml);
if ($.trim(im[ram_G[indexGame]])) {$( "#imaL" ).css("cursor","pointer");$( "#imaL" ).click(function() {imaUp("numDeci01_resources/media/G" + im[ram_G[indexGame]])});}
$("#actText").css("minHeight",imaH[ram_G[indexGame]]);$(".buttonAu").remove();
if ($.trim(a1[ram_G[indexGame]])){$("#auDiv").append('<img class="buttonAu" src="numDeci01_resources/media/sound.png"/>');
$("audio").each(function(){this.pause();});document.getElementById(a1[ram_G[indexGame]]).play();$(".buttonAu").click(function(){document.getElementById(a1[ram_G[indexGame]]).play();});}
}
function imaUp(ima) {$("body").css("overflow", "hidden");var aW=$("#ardoraActCanvas").attr("width");var aH=$("#ardoraActCanvas").attr("height");$("#ardoraActCanvas").attr({"width": $(window).width(),"height": $(window).height()});document.getElementById("ardoraActCanvas").style.zIndex = 5;
document.getElementById("ardoraActCanvas").style["visibility"] = "visible";var alpha=0;var delta=0.03;var canvas = document.getElementById("ardoraActCanvas");var context = canvas.getContext("2d");context.beginPath();
context.fillStyle = "rgba(0, 0, 0, 0.25)";context.fillRect(0, 0, context.canvas.width, context.canvas.height);context.fill();var imageObj=new Image();
imageObj.onload = function() {var xCenterIma=($("#ardoraActCanvas").width()-imageObj.width)/2;var yCenterIma=($("#ardoraActCanvas").height()-imageObj.height)/2;context.beginPath();
context.shadowColor = "rgba(0,0,0,0.25)";context.shadowBlur=10;context.shadowOffsetX=10;context.shadowOffsetY=10;context.fill();context.beginPath();context.strokeStyle = "rgba(0,0,0,1)";
context.fillStyle = "rgba(255,255,255,1)";context.fillRect(xCenterIma-5,yCenterIma-5,imageObj.width+10,imageObj.height+10);context.fill();context.rect(xCenterIma-5,yCenterIma-5,imageObj.width+10,imageObj.height+10);
context.stroke();context.fill();context.shadowBlur=0;context.shadowOffsetX=0;context.shadowOffsetY=0;loop();
function loop() {alpha += delta;if (alpha <= 1) {context.clearRect(xCenterIma, yCenterIma, imageObj.width, imageObj.height);context.globalAlpha=alpha;context.drawImage(imageObj, xCenterIma, yCenterIma);requestAnimationFrame(loop);}}};
imageObj.src=ima;$("#ardoraActCanvas").css("cursor","pointer");$("#ardoraActCanvas").click(function() {document.getElementById("ardoraActCanvas").style.zIndex=0;document.getElementById("ardoraActCanvas").style["visibility"]="hidden";
canvas.width=canvas.width;$("body").css("overflow", "visible");$("#ardoraActCanvas").attr({"width":aW,"height":aH});});}
window.requestAnimationFrame=(function() {return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) {window.setTimeout(callback, 10000 / 60);};})();
function paintScore(){
$("#score").animate({marginTop:"150px"})
$("#scoreC").animate({marginTop:"150px"})
$("#scoreU").animate({marginTop:"150px"})
$("#score").html('<input type="text" id="inTotalEuros" name="inTotalEuros" placeholder="0,0">'+nameEuro);
$("input").keyup(function(){var val = $(this).val();if(isNaN(val)){
val = val.replace(/[^0-9\,]/g,"");if(val.split(",").length>2) val =val.replace(/\,+$/,"");
}$(this).val(val);});
$("#score").animate({marginTop:"-10px"})
$("#scoreC").animate({marginTop:"-10px"})
$("#scoreU").animate({marginTop:"-10px"})
}
function randomSort(){
for (i=0;i<ram_G.length;i++){var ind=Math.floor(Math.random()*ram_G.length);while (ram_G[ind]>-1) {ind++;if (ind>=ram_G.length){ind=0;}}ram_G[ind]=i;}
}
function isCorrect(){
var isCorrect = false;
var reply=$("#inTotalEuros").val().replace(",",".").split(".");totEuros=parseInt(reply[0])*1000;totCent=0;
if (reply.length>1){if (reply[1].length==1){totCent=parseInt(reply[1])*100;}else{totCent=parseInt(reply[1])*10;}}
if ((totCentFixed == totCent) && (totEurosFixed == totEuros)){isCorrect = true}
if (isCorrect) {totEuros=0;totCent=0;score=score+scoreInc;timeAct=timeAct+timeBon;successes++;indexGame++;if (indexGame >= ram_G.length) {showMessage("Ok");} else {loadMoney();}}
else{attempts++;score=score-scoreDec;if (tiAttempts) {if (attempts > attemptsMax) {showMessage("Attempts");} else {showMessage("Error");}} else {showMessage("Error");}}
}
function goTime(){clearInterval(timeInterval);showMessage("Time");}
function showSol(oldTypeGame){ 
}
function paintBack(){}
function ContaDWords(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;}
