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);
}
//---------------------------------
function incCell(cell){
  var valor = cell.value;
  if      (valor==""   ) valor = "DO";
  else if (valor=="DO" ) valor = "RE";
  else if (valor=="RE" ) valor = "MI";
  else if (valor=="MI" ) valor = "FA";
  else if (valor=="FA" ) valor = "SOL";
  else if (valor=="SOL") valor = "LA";
  else if (valor=="LA" ) valor = "SI";
  else if (valor=="SI" ) valor = ""; 
  cell.value=valor;
  cell.className="empty";
}
//---------------------------------
function toHex(num){
  if      (num<= 9) return "" + num;
  else if (num==10) return "A";
  else if (num==11) return "B";
  else if (num==12) return "C";
  else if (num==13) return "D";
  else if (num==14) return "E";
  else if (num==15) return "F";
}
//---------------------------------
function getIdNote(note){
  if      (note == "DO"  ) return "1";
  else if (note == "RE"  ) return "2";
  else if (note == "MI"  ) return "3";
  else if (note == "FA"  ) return "4";
  else if (note == "SOL" ) return "5";
  else if (note == "LA"  ) return "6";
  else if (note == "SI"  ) return "7";
  else if (note == "DO#" ) return "8";
  else if (note == "RE#" ) return "9";
  else if (note == "FA#" ) return "A";
  else if (note == "SOL#") return "B";
  else if (note == "LA#" ) return "C";
  else                     return "0";
}
//---------------------------------
function validate(f,wheretogo){
  var numErrors = 0;
  var numEmpty  = 0;
  var total  = 0;
  var numfixed  = 0;
  for(fil=0; fil< 7; fil++){
    for(col=0; col< 7; col++){
      total++;
      var indCasella = fil* 7+col;
      var inputvar = eval("f.cas"+toHex(fil)+toHex(col));
      var idNote = getIdNote(inputvar.value);
      if (idNote!="0"){
        if (f.reduc.value.charAt(indCasella)=='0'){
          if ((""+f.soluc.value.charAt(indCasella)) != idNote){
            inputvar.className="err";
            numErrors++;
          } else {
            inputvar.className="ok";
          }
        } else numfixed++;
      } else numEmpty++;
    }
  }
  if (numEmpty==0 && numErrors == 0){
    location.href=wheretogo;
  } 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 +" notes per colˇlocar";
  } else if (numEmpty==1){
    document.getElementById('msg').innerHTML="Vas bé. Et queda només una nota per colˇlocar";
  }
}
//---------------------------------
function selectCasellaSongFirst(){
  if (navigator.appName.indexOf("Explorer") != -1) { 
    setTimeout('selectCasellaSong()', 500);
  } else {
    selectCasellaSong();
  }
}
//---------------------------------
function selectCasellaSong(){
  var tractat = false;
  for(fil=0; fil<7 && !tractat; fil++){
    for(col=0; col<7 && !tractat; col++){
      var indCasella = fil*7+col;
      if (indCasella==curCasellaSong){
        var inputvar = eval("document.graella.cas"+toHex(fil)+toHex(col));
        inputvar.className = "fix";
      } else if (indCasella>curCasellaSong){
        if (document.graella.melody.value.charAt(indCasella)=='1'){
          curCasellaSong = indCasella;
          var inputvar = eval("document.graella.cas"+toHex(fil)+toHex(col));
          inputvar.className = "melodycl";
          setTimeout('selectCasellaSong()', timeNotes[curIndNote]);
          curIndNote++;
          tractat =true;
        }
      }
    }
  }
}
//---------------------------------
  mint = 0;
  ysf  = 0;
  yf   = 0;
  yfp  = 0;
  ysc  = 0;
  yscp = 0;
  yc   = 0;
  yct  = 0;
  ycp  = 0;
  yn   = 0;
  ynp  = 0;
  yb   = 0;
  ybp  = 0;
  ybpp = 0;
  yr   = 0;
  curCasellaSong = -1;
  curIndNote = 0;
//---------------------------------
function calculaDurada(noutempo){
  mint = 60000/noutempo/16;
  ysf  = 1 * mint;
  yf   = 2 * mint;
  yfp  = 3 * mint;
  ysc  = 4 * mint;
  yscp = 6 * mint;
  yc   = 8 * mint;
  yct  = yc * 2 / 3;
  ycp  = 12 * mint;
  yn   = 16 * mint;
  ynp  = 24 * mint;
  yb   = 32 * mint;
  ybp  = 48 * mint;
  ybpp = 56 * mint;
  yr   = 64 * mint;
  curCasellaSong = -1;
  curIndNote = 0;
}
//---------------------------------

