function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
    for(i=0; i<a.length; i++)
      if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//---------------------------------
function openCredits(){
  var w = window.open('credits.htm', "sidokucredits", "width=310,height=200");
}
//---------------------------------
function openWindow(url,nom,wi,he,scroll){
  var w = window.open(url, nom, "width=" + wi +",height=" + he+",scrollbars="+scroll);
}
//---------------------------------
var indImgs = new Array(new Array(0, 0, 0, 0),	
                        new Array(0, 0, 0, 0),	
                        new Array(0, 0, 0, 0),	
                        new Array(0, 0, 0, 0));
//---------------------------------
function incCell(row, col){
  indImgs[row-1][col-1] = (indImgs[row-1][col-1]+1) % 5;
  nomimg = "document.graella.img" + row+col;
  img=eval(nomimg);
  if (indImgs[row-1][col-1]==0) img.src="images/simbn"+getNumImg(indImgs[row-1][col-1])+".gif";
  else img.src="images/simbb"+getNumImg(indImgs[row-1][col-1])+".gif";
}
//---------------------------------
function validate(f){
  var numErrors = 0;
  var numEmpty  = 0;
  var total  = 0;
  var numfixed  = 0;
  for(fil=1; fil< 5; fil++){
    for(col=1; col< 5; col++){
      total++;
      var indCasella = (fil-1)*4+(col-1);
      nomimg = "document.graella.img" + fil + col;
      img=eval(nomimg);
      var idNote = indImgs[fil-1][col-1];
      if (f.reduc.value.charAt(indCasella)=='0'){
        if (idNote!=0){
          if ((""+f.soluc.value.charAt(indCasella)) != ''+idNote){
            img.src="images/simbv"+getNumImg(indImgs[fil-1][col-1])+".gif";
            numErrors++;
          } else {
            img.src="images/simbg"+getNumImg(indImgs[fil-1][col-1])+".gif";
          }
        } else numEmpty++;
      } else numfixed++;
    }
  }
  if (numEmpty==0 && numErrors == 0){
    document.getElementById('msg').innerHTML="Felicitats! Sidoku resolt";
  } else if (numfixed+numEmpty == total){
    document.getElementById('msg').innerHTML="Omple les caselles fent click al damunt";
  } else if (numErrors>1) {
    document.getElementById('msg').innerHTML="Hi ha " + numErrors +" errors a la graella";
  } else if (numErrors==1) {
    document.getElementById('msg').innerHTML="Hi ha 1 error a la graella";
  } else if (numEmpty>1){
    document.getElementById('msg').innerHTML="Vas bé. Et queden " + numEmpty +" símbols per colˇlocar";
  } else if (numEmpty==1){
    document.getElementById('msg').innerHTML="Vas bé. Et queda només un símbol per colˇlocar";
  }
}

