home *** CD-ROM | disk | FTP | other *** search
/ Orthodox Religion Class (2nd Semester) / ReligieCls1Sem2.iso / js / Util.js < prev    next >
Encoding:
JavaScript  |  2015-03-24  |  21.7 KB  |  694 lines

  1. /**
  2.  * 
  3.  */
  4.  
  5.  
  6. function Util() {
  7. }
  8.  
  9. Util.prototype.setCheckImage = function(gameName,object,index,width,height) {
  10.     $("#gameStage").append("<img id='"+gameName+"checkImage"+index+"' class='chkImg' " +
  11.             "style=\"position:absolute;visibility:hidden;z-index:399;width:23:px;height:23px;" +
  12.             "top:"+(object.top+width)+"px;" +
  13.             "left:"+(object.left+height)+"px;\"" +
  14.             "src='"+imagesCommon.empty+"' />");
  15. };
  16.  
  17.  
  18. Util.prototype.setCheckImageScale = function(gameName,object,index,width,height) {
  19.     $("#gameStage").append("<img id='"+gameName+"checkImage"+index+"' class='chkImg' " +
  20.             "style=\"position:absolute;visibility:hidden;z-index:399;width:23:px;height:23px;" +
  21.             "top:"+((object.top+width)*scale*3)+"px;" +
  22.             "left:"+((object.left+height)*scale*3)+"px;\"" +
  23.             "src='"+imagesCommon.empty+"' />");
  24. };
  25. Util.prototype.setImageStyle = function(id,object) {
  26.     id.css("position","absolute");
  27.     if(object.top!=null)
  28.         id.css("top",object.top+"px");
  29.     if(object.left!=null)
  30.         id.css("left",object.left+"px");
  31.     if(object.width!=null)
  32.         id.css("width",object.width+"px");
  33.     if(object.height!=null)
  34.         id.css("height",object.height+"px");
  35.     if(object.src != null)
  36.         id.attr("src",(object.src=="empty")?imagesCommon.empty:object.src);
  37. };
  38.  
  39. Util.prototype.setImgStyleScale = function(id,object) {
  40.     id.css("position","absolute");
  41.     if(object.top!=null)
  42.         id.css("top",(object.top*scale*3)+"px");
  43.     if(object.left!=null)
  44.         id.css("left",(object.left*scale*3)+"px");
  45.     if(object.width!=null)
  46.         id.css("width",(object.width*scale*3)+"px");
  47.     if(object.height!=null)
  48.         id.css("height",(object.height*scale*3)+"px");
  49.     if(object.src != null)
  50.         id.attr("src",(object.src=="empty")?imagesCommon.empty:object.src);
  51. };
  52.  
  53. Util.prototype.resizeGameStage = function() {
  54.     $("#gameStage").css("-webkit-transform", "scale(" + (scale*3) + ")");
  55.     $("#gameStage").css("-webkit-transform-origin","0% 0%");
  56.     $("#gameStage").css("transform", "scale(" + (scale*3) + ")");
  57.     $("#gameStage").css("transform-origin","0% 0%");
  58.     $("#gameStage").css("-ms-transform", "scale(" + (scale*3) + ")");
  59.     $("#gameStage").css("-ms-transform-origin","0% 0%");
  60. };
  61.  
  62.  
  63. Util.prototype.storageResults = function(wrongAnswerCount, result) {
  64.     var localStorage = new MyLocalStorage();
  65.     var date = new Date();
  66.     var json = {};
  67.     json.time = date.getTime();
  68.     json.name = new MySessionStorage().getItem(gd.keys.userSession);
  69.     json.time = new Date().getTime();
  70.     json.pageNumber = result.page;
  71.     json.gameNumber = result.noExcercise;
  72.     json.totalItem = result.totalItem;
  73.     json.correctItem = result.totalItem - wrongAnswerCount;
  74.  
  75.  
  76.     var key = gd.keys.gameKey;
  77.     var keyEval = "";
  78.     if(result.type !== undefined){
  79.         key =  gd.keys.result;
  80.         keyEval = gd.keys.resultTemp;
  81.         json.totalItem*=5;
  82.     }
  83.     if( keyEval.length>0 ){
  84.         if(localStorage.getItem(getEvalKey(keyEval))==undefined){
  85.             json.id = 0;
  86.         }else{
  87.             json.id = JSON.parse(localStorage.getItem(getEvalKey(keyEval))).id;
  88.         }
  89.         json.correctItem *= 5;
  90.     }
  91.         
  92.     localStorage.setItem(key+date.getTime().toString(), JSON.stringify(json));
  93.     
  94.     
  95.     
  96.     
  97.     if( keyEval.length>0 ){
  98.         var jsonEvl = {};
  99.         jsonEvl["1"] = "";
  100.         jsonEvl["2"] = "";
  101.         jsonEvl["3"] = "";
  102.         jsonEvl["4"] = "";
  103.         jsonEvl[json.gameNumber] = json.correctItem;
  104.         
  105.         if(localStorage.getItem(getEvalKey(keyEval))==undefined){
  106.             jsonEvl.id = 0;
  107.             localStorage.setItem(getEvalKey(keyEval), JSON.stringify(jsonEvl));
  108.         }
  109.         var json1 = {};
  110.         json1 = localStorage.getItem(getEvalKey(keyEval));
  111.         logJson = JSON.parse(json1);
  112.         logJson[json.gameNumber] = json.correctItem;
  113.         if( keyEval.length>0 ){
  114.             localStorage.setItem(getEvalKey(keyEval), JSON.stringify(logJson));
  115.         }else{
  116.             localStorage.setItem((keyEval), JSON.stringify(logJson));    
  117.         }
  118.         var amount = 0;
  119.         for (var i = 0; i < 4; i++) {
  120.             if(logJson[i+1] != undefined){
  121.                  if(logJson[i+1]!==""){
  122.                      $("#divEvl" + i).html(logJson[i+1]);
  123.                      amount += logJson[i+1];
  124.                  }
  125.             }
  126.         }
  127.         $("#divEvl4").html(amount);
  128.     }
  129. };
  130. Util.prototype.getPageResultEval = function(currentPage){
  131.     
  132.     var keyEval= getEvalKey(gd.keys.resultTemp);
  133.     console.log(keyEval);
  134.     if(!(gd.isIe && $.cookie(keyEval)!=null) || !(!gd.isIe &&((keyEval) in localStorage))){
  135.     }else{
  136.         var json = {};
  137.         console.log(keyEval);
  138.         json = localStorage.getItem(keyEval);
  139.         logJson = JSON.parse(json);
  140.         var amount = 0;
  141.         for (var i = 0; i < currentPage.inputs.length-2; i++) {
  142.             if(logJson[i+1] != undefined){
  143.                  if(logJson[i+1]!==""){
  144.                      $("#divEvl" + i).html(logJson[i+1]);
  145.                      amount += logJson[i+1];
  146.                  };
  147.             };
  148.         }
  149.         $("#divEvl4").html(amount);
  150.     }
  151.     return true;
  152. };
  153. function getEvalKey(key){
  154.     return key + "-&;'+" + new MySessionStorage().getItem(gd.keys.userSession);
  155. }
  156. Util.prototype.checkRights = function(no){
  157.     if($("#divEvl" + no).html().length==0){
  158.         return false;    
  159.     }
  160.     alert("Acest exerci╚¢iu l-ai facut. Alege altul!");
  161.     return true;
  162. };
  163. Util.prototype.newEvl = function(){
  164.     var localStorage = new MyLocalStorage();
  165.     var json = {};
  166.     json = localStorage.getItem(getEvalKey(gd.keys.resultTemp));
  167.     logJson = JSON.parse(json);
  168.     for(var i=1;i<=4;i++){
  169.         if(logJson[i]===""){
  170.             alert("Nu ai terminat toate exerci╚¢iile!");
  171.             return false;
  172.         };
  173.     }
  174.     var jsonEvl = {};
  175.     jsonEvl["1"] = "";
  176.     jsonEvl["2"] = "";
  177.     jsonEvl["3"] = "";
  178.     jsonEvl["4"] = "";
  179.     jsonEvl.id = logJson.id+1;
  180.     
  181.     localStorage.setItem(getEvalKey(gd.keys.resultTemp), JSON.stringify(jsonEvl));
  182.     for (var i = 0; i <= 4; i++) {
  183.         $("#divEvl" + i).html("");
  184.     }
  185.     return true;
  186. };
  187.  
  188.  
  189.  
  190. Util.prototype.getResult = function() {
  191.     var localStorage = new MyLocalStorage();
  192.     $("#bodyDiv").append(
  193.             "<br><br><br><div id='tabs'><ul>"
  194.                     + "    <li><a href='#tabs-1'>Rezultate exerci╚¢ii</a></li>"
  195.                     + "    <li><a href='#tabs-2'>Rezultate evaluare</a></li>"
  196.                     + "    </ul></div>");
  197.     $("#tabs").tabs();
  198.     $('#tabs .ui-tabs-nav a[href="#tabs-1"], #tabs-1').addClass('status1');
  199.     $('#tabs .ui-tabs-nav a[href="#tabs-2"], #tabs-2').addClass('status2');
  200.     $("#tabs").append("<div id='tabs-2' style='width:1420px;height:700px;background;red'></div>");
  201.     $("#tabs").append("<div id='tabs-1' style='width:1420px;height:700px;'></div>");
  202.     $("#tabs").append("<button id='closeBtnResult'  class='close' " +
  203.             "style='position:absolute;top:5px;right:5px;z-index:2000;width:35px;height:35px;' ></button>");
  204.     
  205.     $("#tabs-2").append("<table id='tableResultEvaluation'>"
  206.             + "<thead id='resultTheadEvaluation'></thead></table>");
  207.     $("#resultTheadEvaluation").append(
  208.         $("<tr style='width:100%;background-color:rgb(230,152,83)'>")
  209.                 .append("<th>Nume</th>").append("<th>Data</th>").append(
  210.                         "<th>Pagina</th>").append("<th>Exerci╚¢iu</th>").append(
  211.                         "<th>Total<br>punctaj</th>").append("<th>Punctaj<br> ob╚¢inut</th>").append(
  212.                         "<th>Pagina</th>"));
  213.     
  214.     $("#tabs-1").append("<table id='tableResult'>"
  215.                             + "<thead id='resultThead'></thead><tfoot id='resultTfoot'></tfoot></table>");
  216.     $("#resultThead").append(
  217.             $("<tr style='background-color:rgb(230,152,83)'>").append(
  218.                     "<th>Nume</th>").append("<th>Data</th>").append(
  219.                     "<th>Pagina</th>").append("<th>Exerci╚¢iu</th>").append(
  220.                     "<th>Total<br> r─âspunsuri</th>").append("<th>R─âspunsuri<br> corecte</th>"));
  221.     $("#resultTfoot").append(
  222.             $("<tr style='background-color:rgb(230,152,83)'>").append(
  223.                     "<th>Nume</th>").append("<th>Data</th>").append(
  224.                     "<th>Pagina</th>").append("<th>Exerci╚¢iu</th>").append(
  225.                     "<th>Total<br> r─âspunsuri</th>").append("<th>R─âspunsuri<br> corecte</th>"));
  226.     var noEval = 0;
  227.     var index = 0;
  228.     if (gd.isIe === false) {
  229.         while(localStorage.key(index)!=null){
  230.             var key = localStorage.key(index++);
  231.             setTable(null, key);
  232.             noEval++;
  233.         }
  234.     } else {
  235.         $.each($.cookie(), function(key, value) {
  236.             setTable(value, key);
  237.         });
  238.     }
  239.     $('#tableResultEvaluation').DataTable({
  240.         "columnDefs" : [ {
  241.             "visible" : false,
  242.             "targets" : 6
  243.         } ],
  244.         "scrollY" : (noEval > 20) ? "540px" : "",
  245.         "scrollCollapse" : true,
  246.         "paging" : false,
  247.         "order" : [ [ 1, 'desc' ] ],
  248.         "oLanguage" : {
  249.             "sSearch" : "Caut─â _INPUT_ ",
  250.         },
  251.         "iDisplayLength" : 19,
  252.         "drawCallback" : function(settings) {
  253.             var last = null;
  254.             var amount = 0;
  255.             var amountT = 0;
  256.             var lastId = "idLast";
  257.             var lastIdT = "idLastT";
  258.             var api = this.api();
  259.             var rows = api.rows({page : 'current'}).nodes();
  260.             api.column(6, {page : 'current'}).data().each(function(group, i) {
  261.                 if (last !== group) {
  262.                     $('#' + lastId).html(amount);
  263.                     $('#' + lastIdT).html(amountT);
  264.                     lastId = "idLast" + i;
  265.                     lastIdT = "idLastT" + i;
  266.                     $(rows).eq(i).before('<tr style="background:rgba(217, 110, 49, 0.4);" >'+//#2EBBE0
  267.                             '<td  style="align:center;text-align:center;" colspan="4">Rezulate evaluare '+
  268.                                     (group*1+1)+'</td>'+
  269.                             '<td  style="align:center;text-align:center;" id='+ lastIdT + ' ></td>'+
  270.                             '<td  style="align:center;text-align:center;" id='+ lastId + ' ></td>'+
  271.                             '</tr>');
  272.                     last = group;
  273.                     amount = 0;
  274.                     amountT = 0;
  275.                     no = 0;
  276.                 }
  277.                 amount += rows[i].getElementsByTagName('td')[5].innerText * 1;
  278.                 amountT += rows[i].getElementsByTagName('td')[4].innerText * 1;
  279.             });
  280.             $('#' + lastId).html(amount);
  281.             $('#' + lastIdT).html(amountT);
  282.             }
  283.     });
  284.  
  285.     $('#tableResult tfoot th').each(
  286.             function() {
  287.                 var title = $('#tableResult thead th').eq($(this).index())
  288.                         .text();
  289.                 $(this).html(
  290.                         '<input type="text" style="width:200px" placeholder="Caut─â ' + title
  291.                                 + '" />');
  292.             });
  293.  
  294.     var table = $('#tableResult').DataTable({
  295.         "iDisplayLength" : 19,
  296.         "pagingType" : "full_numbers",
  297.         
  298.         "oLanguage" : {
  299.             "sSearch" : "Caut─â _INPUT_ ",
  300.             "oPaginate" : {
  301.                 "sFirst" : "Primul",
  302.                 "sLast" : "Ultimul",
  303.                 "sPrevious" : "Precedentul",
  304.                 "sNext" : "Urm─âtorul"
  305.             },
  306.         },
  307.         "order" : [ [ 1, "desc" ] ]
  308.     });
  309.     $("#tableResult tfoot input").on(
  310.             'keyup change',
  311.             function() {
  312.                 table.column($(this).parent().index() + ':visible').search(
  313.                         this.value).draw();
  314.             });
  315.  
  316.     
  317.     $("#tabs").css("left", "100px");
  318.     
  319.     $("#tabs").css("transform","scale(" + (3134 - 350) / 1400 + ")");
  320.     $("#tabs").css("-webkit-transform","scale(" + (3134 - 350) / 1400+ ")");
  321.     $("#tabs").css("-ms-transform","scale(" + (3134 - 350) / 1400+ ")");
  322.     $("#tabs").css("transform-origin", "-4% -20%");
  323.     $("#tabs").css("-webkit-transform-origin", "-4% -20%");
  324.     $("#tabs").css("-ms-transform-origin", "-4% -20%");
  325.     
  326.  
  327.     $('.dataTables_info').hide();
  328.     $('.dataTables_length').hide();
  329.     $("#tabs-2").css("display", "none");
  330.  
  331. };
  332.  
  333.  
  334. function setTable(value, key) {
  335.     json = {};
  336.     if (key.lastIndexOf(gd.keys.gameKey, 0) === 0) {
  337.         json = (gd.isIe === true) ? value : localStorage.getItem(key);
  338.         logJson = JSON.parse(json);
  339.         if (logJson.name == new MySessionStorage().getItem(gd.keys.userSession)) {
  340.             if (logJson.pageNumber != undefined)
  341.                 $("#tableResult").append(
  342.                     $("<tr>").append($("<td align=center>" + logJson.name + "</td>"))
  343.                              .append($("<td align=center>" + formatDate1(new Date(logJson.time))+ "</td>"))
  344.                              .append($("<td align=center>" + logJson.pageNumber+ "</td>"))
  345.                              .append($("<td align=center>" + logJson.gameNumber+ "</td>"))
  346.                              .append($("<td align=center>" + logJson.totalItem+ "</td>"))
  347.                              .append($("<td align=center>" + logJson.correctItem+ "</td>")));
  348.         }
  349.     }else{
  350.         if (key.lastIndexOf(gd.keys.result, 0) === 0) {
  351.             json = (gd.isIe === true) ? value : localStorage.getItem(key);
  352.             logJson = JSON.parse(json);
  353.             if (logJson.name == new MySessionStorage().getItem(gd.keys.userSession)) {
  354.                 if (logJson.pageNumber != undefined) {
  355.                     $("#tableResultEvaluation").append(
  356.                         $("<tr>").append($("<td align=center>" + logJson.name + "</td>"))
  357.                                 .append($("<td align=center>" + formatDate1(new Date(logJson.time))+ "</td>"))
  358.                                 .append($("<td align=center>" + logJson.pageNumber+ "</td>"))
  359.                                 .append($("<td align=center>" + logJson.gameNumber + "</td>"))
  360.                                 .append($("<td align=center>" + logJson.totalItem+ "</td>"))
  361.                                 .append($("<td align=center>" + logJson.correctItem+ "</td>"))
  362.                                 .append($("<td align=center>" + logJson.id+ "</td>")));
  363.                 }
  364.             }
  365.         }
  366.     }
  367. };
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375. function formatDate1(date) { 
  376.     var yyyy = date.getFullYear().toString();                                    
  377.     var mm = (date.getMonth()+1).toString(); // getMonth() is zero-based         
  378.     var dd  = date.getDate().toString();             
  379.     var getH =date.getHours().toString();
  380.     var getM = date.getMinutes().toString();
  381.     var getS = date.getSeconds().toString();
  382.     return yyyy + '-' + (mm[1]?mm:"0"+mm[0]) + '-' + (dd[1]?dd:"0"+dd[0])
  383.     +" "+(getH[1]?getH:"0"+getH[0]) +":"+(getM[1]?getM:"0"+getM[0])+":" + (getS[1]?getS:"0"+getS[0]);
  384. };   
  385.  
  386. Util.prototype.playAudio = function (parentElement, top, left, scaleAudioPlayer ,src){    
  387.     parentElement.append("<div id='temp'></div>");
  388.     $("#temp").append("<audio controls id='player1'" +
  389.             " style='display:none;position:absolute;z-index:100;widt:100px;'>" +
  390.             " <source src='' type='audio/mpeg'></audio>");
  391.     $("#temp").append(
  392.             "<div id='audioPlayerDiv' style='position:absolute;left:"+left+"px:top:"+top+"px'></div>");
  393.     
  394.     var dimBtn = 35;
  395.     $("#audioPlayerDiv").append(
  396.             "<img src='images/ramaSong.png' style='position:absolute;" +
  397.                     "height:120px;width:300px;top:"+top+"px;left:"+left+"px;'/>"+
  398.             
  399.             "<div id='stop' class='btn_stopPlayer'  style='position:absolute;background-size:cover;" +
  400.                     "height:"+dimBtn+"px;width:"+dimBtn+"px;top:"+(top+60)+"px;left:"+(left+40)+"px;'/>"+
  401.             "<div id='play' class='btn_playPlayer'  style='position:absolute;background-size:cover;" +
  402.                     "height:"+dimBtn+"px;width:"+dimBtn+"px;top:"+(top+60)+"px;left:"+(left+120)+"px;'/>"+
  403.             "<div id='pause' class='btn_pausePlayer' style='position:absolute;background-size:cover;" +
  404.                     "height:"+dimBtn+"px;width:"+dimBtn+"px;top:"+(top+60)+"px;left:"+(left+200)+"px;'/>"
  405.             );
  406.     
  407.     $('#player1').mediaelementplayer({
  408.         audioWidth: (1300*scale),
  409.         features: ['progress','current','duration','tracks']
  410.     });
  411.  
  412.     $(".mejs-controls").attr("style","position:absolute;z-index:1000;top:0px;");
  413.     $(".mejs-controls").css("width",230+"px");
  414.     $(".mejs-controls").css("top",(top+60)+"px");
  415.     $(".mejs-audio").css("left",(left-scale*690)+"px");
  416.     
  417.     $("#temp").css("-webkit-transform", "scale(" + (scaleAudioPlayer) + ")");
  418.     $("#temp").css("-webkit-transform-origin","0% 0%");
  419.     $("#temp").css("transform", "scale(" + (scaleAudioPlayer) + ")");
  420.     $("#temp").css("transform-origin","0% 0%");
  421.     $("#temp").css("-ms-transform", "scale(" + (scaleAudioPlayer) + ")");
  422.     $("#temp").css("-ms-transform-origin","0% 0%");
  423.     
  424.     
  425.     player1.setSrc(src);
  426.     //console.log(src);
  427.     
  428.     $("#play").click(function() {
  429.         if(!isActive)
  430.             return false;
  431.          player1.play();
  432.          $("#play").attr("disabled",true);
  433.          $("#pause").attr("disabled",false);
  434.          $("#stop").attr("disabled",false);
  435.      });
  436.      
  437.      $("#pause").click(function() {
  438.          player1.pause();
  439.          $("#play").attr("disabled",false);
  440.          $("#pause").attr("disabled",true);
  441.          $("#stop").attr("disabled",false);
  442.     });
  443.           
  444.      $("#stop").click(function() {
  445.          player1.setCurrentTime(0);
  446.          player1.pause();
  447.          $("#play").attr("disabled",false);
  448.          $("#stop").attr("disabled",true);
  449.          $("#pause").attr("disabled",true);
  450.     });
  451.      
  452. };
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469. Util.prototype.getRandomNumber = function(max) {
  470.     return Math.floor( (Math.random() * max) + 1);
  471. };
  472.  
  473. Util.prototype.suffleWordLetters = function(word){
  474.     return word.split('').sort(function(){return 0.5-Math.random();}).join('');
  475. };    
  476.  
  477. Util.prototype.getRandomNumber = function(max){
  478.     return Math.floor((Math.random()*max)+1);
  479. };
  480.  
  481. Util.prototype.getRandomNumberInterval = function(min,max){
  482.     return Math.floor((Math.random()*max)+min+1);
  483. };
  484.  
  485. /*Util.prototype.getRandomNumberInterval = function(min,max){
  486.     return Math.floor((Math.random()*(max-min))+min+1);
  487.     };*/ //pt. aleator
  488.  
  489.  
  490. Util.prototype.getRandomColor = function(){
  491.     return 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' 
  492.             + (Math.floor(Math.random() * 256)) + ')';
  493. };
  494.  
  495. Util.prototype.getRandomFont = function(){
  496.     var fonts = new Array("","Georgia, serif", "Palatino Linotype, Book Antiqua, Palatino, serif", 
  497.             "Times New Roman, Times, serif","Impact, Charcoal, sans-serif");
  498.             Util.prototype.getRandomNumber(fonts.length-1);
  499.     return fonts[Util.prototype.getRandomNumber(fonts.length-1)];
  500. };
  501.  
  502.  
  503. Util.prototype.getRandomFontStyle = function(){
  504.     var fontStyles = new Array("","normal");
  505.     return fontStyles[Util.prototype.getRandomNumber(fontStyles.length-1)];
  506. };
  507.  
  508.  
  509. Util.prototype.suffleArray = function(array){
  510.     var max = array.length;
  511.     for(var i=0;i<max;i++){
  512.         var random = new Util().getRandomNumber(max-i)-1;
  513.         b = array[random];
  514.         array[random] = array[max-i-1];
  515.         array[max-i-1] = b;
  516.     }    
  517.     return array;
  518. };
  519.  
  520. Util.prototype.suffleFirstNumber = function(max){
  521.     var array = new Array();
  522.     for(var i=0;i<max;i++){
  523.         array[i] = i; 
  524.     }
  525.     for(var i=0;i<max;i++){
  526.         var random = new Util().getRandomNumber(max-i)-1;
  527.         b = array[random];
  528.         array[random] = array[max-i-1];
  529.         array[max-i-1] = b;
  530.     }    
  531.     
  532.     return array;
  533. };
  534.  
  535. Util.prototype.getSoundWrong = function(nrWrong,maxChoose){
  536.     switch (nrWrong) {
  537.         case 1: return 1;
  538.         case 2: return 2;
  539.         case 3: return (maxChoose>4)?2:3;
  540.         default: return 3;
  541.     }
  542. };
  543. Util.prototype.validateInputNumber = function(element){
  544.     
  545.     element.keydown(function (e) {
  546.         // Allow: backspace, delete, tab, escape, enter and .
  547.         if ($.inArray(e.keyCode, [46, 8, 9, 27, 13]) !== -1 ||
  548.              // Allow: Ctrl+A
  549.             (e.keyCode == 65 && e.ctrlKey === true) || 
  550.              // Allow: home, end, left, right
  551.             (e.keyCode >= 35 && e.keyCode <= 39)) {
  552.             
  553.                  // let it happen, don't do anything
  554.                  return;
  555.         }
  556.         // Ensure that it is a number and stop the keypress
  557.         if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
  558.             
  559.             e.preventDefault();
  560.         }
  561.     });
  562. };
  563.  
  564. Util.prototype.validNumber = function(element){
  565.     
  566.     element.keydown(function (e) {
  567.         // Allow: backspace, delete, tab, escape, enter and .
  568.         if ($.inArray(e.keyCode, [46,8,9,27,13]) !== -1 ||
  569.              // Allow: Ctrl+A
  570.             (e.keyCode == 65 && e.ctrlKey === true) || 
  571.              // Allow: home, end, left, right
  572.             (e.keyCode >= 35 && e.keyCode <= 39)) {
  573.             
  574.                  // let it happen, don't do anything
  575.                  return;
  576.         }
  577.         // Ensure that it is a number and stop the keypress
  578.         if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
  579.             
  580.             e.preventDefault();
  581.         }
  582.     });
  583. };
  584.  
  585. Util.prototype.restrictKeyGCompare = function(element){
  586.     element.keydown(function (e) {
  587.         //alert(e.keyCode);
  588.         // Allow: backspace, delete, tab, escape, enter and .
  589.         if ($.inArray(e.keyCode, [46, 8, 9, 27, 13,  187,188,190]) !== -1 ||
  590.              // Allow: Ctrl+A
  591.             (e.keyCode == 65 && e.ctrlKey === true) || 
  592.              // Allow: home, end, left, right
  593.             (e.keyCode >= 35 && e.keyCode <= 39)) {
  594.                  // let it happen, don't do anything
  595.                  return;
  596.         }
  597.         // Ensure that it is a number and stop the keypress
  598.         if(!(e.shiftKey && ((e.keyCode == 190) || (e.keyCode == 188)))) {
  599.             e.preventDefault();
  600.         }
  601.         
  602.     });
  603. };
  604.  
  605.  
  606.  
  607.  
  608. Util.prototype.restrictKeyBooleanLetter = function(element){
  609.     
  610.     element.keydown(function (e) {
  611.         // Allow: backspace, delete, tab, escape, enter and .
  612.         if ($.inArray(e.keyCode, [46, 8, 9, 27, 13]) !== -1 ||
  613.              // Allow: Ctrl+A
  614.             (e.keyCode == 65 && e.ctrlKey === true) || 
  615.              // Allow: home, end, left, right
  616.             (e.keyCode >= 35 && e.keyCode <= 39)) {
  617.             
  618.                  // let it happen, don't do anything
  619.                  return;
  620.         }
  621.         // Ensure that it is a number and stop the keypress
  622.         if( ( e.keyCode!=65 )&&( e.keyCode!=70 )) {
  623.             e.preventDefault();
  624.         }
  625.     });
  626. };
  627.  
  628. Util.prototype.getRandomExp = function (count){
  629.     var util = new Util();
  630.     var numbers = [];var op;var a;var b;var d;
  631.     for(var i=0;i<16;i++){
  632.     op = util.getRandomNumber(2);
  633.     a = util.getRandomNumberInterval(10,98);
  634.     b = 0;
  635.     if(op==1){//+
  636.     b = util.getRandomNumberInterval(0,98-a);
  637.     }else{//-
  638.     b = -util.getRandomNumberInterval(0,a);
  639.     }
  640.     d = a + b;
  641.     numbers.push({a:a,op:((op==1)?"+":"-"),b:Math.abs(b),response:d});
  642.     }
  643.     return numbers;
  644.     };
  645.  
  646.     Util.prototype.getRandomExpComp = function (count){
  647.     var util = new Util();
  648.     var numbers = [];
  649.     var a,b,response;
  650.     var generateEqual = false;
  651.     for(var i=0;i<count;i++){
  652.     a = util.getRandomNumberInterval(10, 99);
  653.     b = util.getRandomNumberInterval(10, 99);
  654.     if(a>b){
  655.     response = ">";
  656.     }else{
  657.     if(a<b){
  658.     response = "<";
  659.     }else{
  660.     response = "=";
  661.     generateEqual = true;
  662.     }
  663.     }
  664.     numbers.push({a:a,b:b,response:response});
  665.     }
  666.     if(!generateEqual){
  667.     var no = util.getRandomNumber(count-1);
  668.     a = util.getRandomNumberInterval(10, 99);
  669.     numbers[no] = {a:a,b:a,response:"="};
  670.     }
  671.     return numbers;
  672.     };
  673.  
  674.  
  675.  
  676.  
  677.  
  678. Util.prototype.disabledGameButtons = function(){
  679.     $("#acasa").prop('disabled', true);
  680.     $("#ajutor").prop('disabled', true);
  681.     $("#verifica").prop('disabled', true);
  682.     $("#repeta").prop('disabled', true);
  683. };
  684. Util.prototype.enabledGameButtons = function(){
  685.     $("#acasa").prop('disabled', false);
  686.     $("#ajutor").prop('disabled', false);
  687.     $("#verifica").prop('disabled', false);
  688.     $("#repeta").prop('disabled', false);
  689. };
  690. Util.prototype.partialEnabledGameButtons = function(){
  691.     $("#acasa").prop('disabled', false);
  692.     $("#ajutor").prop('disabled', false);
  693.     $("#repeta").prop('disabled', false);
  694. };