
      sauve=""; 
      sauve3 = new Array();
      finalizado="false";
      primero="true";
      var teclat;
			
      function drawcase() {
         if (finalizado=="false") {
	         tmp = sauve.id.split("-");
	         //mem = sauve3[tmp[0]*9+tmp[1]]+""; 
	         mem = sauve3[tmp[2]]+"";
	         if(mem=="undefined")
	          mem="";
	         if(mem=="") 
	           tmp2 = "&nbsp;";
	         else {
	            if(mem.length==1) 
	            	tmp2 = "<font color=green >"+mem+"</font>";
	            else {
	               tmp2 = "<table cellspacing=0 cellpadding=0 border=1>";
	               for(i=0;i<2;i++) {
	                  tmp2+="<tr>";
	                  for(j=0;j<4;j++) {
	                     t = i*4+j;
	                     tmp2+="<td class=f7>"+String.fromCharCode(mem.charCodeAt(t))+"</td>";
	                  }
	                  tmp2+="</tr>";
	               }
	               tmp2 += "</table>";
	            }
	         }
	         sauve.innerHTML = tmp2;
         }
         
      }

      function drawgrid() {
         tmp = sauve.id.split("-");
         //mem = sauve3[tmp[0]*9+tmp[1]]+""; 
         mem = sauve3[tmp[2]]+"";
         if(mem=="undefined") 
         		mem="";
         //alert(sauve3);		
         for(i=1;i<10;i++) {
            ch = String.fromCharCode(i+48);
            
            if(mem.indexOf(ch)>=0) 
            	var kk= document.getElementById("j"+i).style.background="yellow";
            else 
            	var kk= document.getElementById("j"+i).style.background="";
         }
      }

      function soluce() {
         tmp = sauve.id.split("-");
         //sauve3[tmp[0]*9+tmp[1]]=sauve.s;
         sauve3[tmp[2]]=tmp[3];
         drawcase(); 
         drawgrid();
      }
			function guardar() {
         drawcase(); 
         drawgrid();
         teclat.style.visibility="hidden";
      }


      function jugar(lacase) {
         //if(sauve!="")
         // sauve.style.background="";
        if (primero=="true"){
        	primero="false";
          IniciarCrono();
        }
         
         if (finalizado=="false"){
         	blanquejatot();
         	sauve=lacase;
         	lacase.style.background="yellow";
         	teclat = document.getElementById("teclat");
         	tmp = sauve.id.split("-");
         	
         	drawgrid();
         	teclat.style.visibility="visible";
         }
         else{
         	alert( "Juego finalizado, Inicie un nuevo juego");
         }
      }
      
      
      function blanquejatot(){
      	 for (var t=1;t<=9;t++) {
      	     	
	      	for (var i=0;i<document.getElementById("taula"+t).rows.length;i++) {
	      	     	
	      		var rowElem = document.getElementById("taula"+t).rows[i];
	    	
	  		for (var j=0;j<rowElem.cells.length;j++) {
	   		 
	      			tmp = rowElem.cells[j].id.split("-");
	      			if (tmp[4]!="XX"){
	      				rowElem.cells[j].style.background="";
	      			}
	      				
	   
	      		}
	  
	      	}
  	  }
      
      }
      function solucionatot() {
        finalizado="true";
        errores =0;
        DetenerCrono();
        blanquejatot();
        teclat = document.getElementById("teclat");
        teclat.style.visibility="hidden";
        for (var t=1;t<=9;t++) {
      	      	for (var i=0;i<document.getElementById("taula"+t).rows.length;i++) {
	      		var rowElem = document.getElementById("taula"+t).rows[i];
	    			for (var j=0;j<rowElem.cells.length;j++) {
	   			tmp = rowElem.cells[j].id.split("-");
	      			mem = sauve3[tmp[2]]+"";
	      			if(mem=="undefined") mem="";
	      			title='clica para jugar' 
	      			if (tmp[4]!="XX"){
	      				rowElem.cells[j].onclick=' ';
	      				rowElem.cells[j].title='Juego finalizado'
	      			 	if ( tmp[3]!=mem){
	      					rowElem.cells[j].style.background="red";
	      					rowElem.cells[j].innerHTML=tmp[3];
	      					errores ++;
	      				}
	      			}
	      				
	   
	      		}
	  
	      	}
  	}
  	
  	if (errores=="0")
  		alert("FELICIDADES !!!! ha finalizado el sudoku");
  	else {
  		alert("Hay "+ errores +" errores. Vuelva a iniciar un nuevo juego");
  	}

      }
      
      
	function comprovatot() {
        var textos="";
         	teclat = document.getElementById("teclat");
        	teclat.style.visibility="hidden";
      	  	for (var t=1;t<=9;t++) {
      	     	
	      		for (var i=0;i<document.getElementById("taula"+t).rows.length;i++) {
	      	     	
	      		var rowElem = document.getElementById("taula"+t).rows[i];
	    	
	  		for (var j=0;j<rowElem.cells.length;j++) {
	   		 
	      			//textos = rowElem.cells[j].id +"|" ;
	      			tmp = rowElem.cells[j].id.split("-");
	      			mem = sauve3[tmp[2]]+"";
	      			if(mem=="undefined") mem="";
	      			
	      			
	      			if (tmp[4]!="XX" && tmp[3]!=mem){
	      				//alert(tmp[3]+"<>"+mem+ "--->"+rowElem.cells[j].id)
	      				rowElem.cells[j].style.background="red";
	      			}
	      				
	   
	      		}
	  
	      	}
  	}
  	    

      }
      function store(n) {
         tmp = sauve.id.split("-");
         ch = String.fromCharCode(n+48);
         //mem = sauve3[tmp[0]*9+tmp[1]]+""; 
         mem = sauve3[tmp[2]]+"";
         if(mem=="undefined") mem="";
         t = mem.indexOf(ch)
         if(t>=0) { 
         	t2 = mem.split(""); 
         	t2[t]=""; 
         	mem = t2.join(""); 
         	}
         else 
         	mem+=ch;
         //sauve3[tmp[0]*9+tmp[1]]=mem;
         sauve3[tmp[2]]=mem;
         drawcase(); 
         drawgrid();
         teclat = document.getElementById("teclat");
         //teclat.style.visibility="hidden";
      }
   
