




function makeArray(n) { 
this.length = n; for (i = 0; i < n; i++) { this[i] = null } }
 var Number = new makeArray(20);
 var Check = new makeArray(20);
 var WavNO = new makeArray(20);
 var Card = new makeArray(20);
 var Voice = new makeArray(10);
 var SelectNO = new makeArray(1);
 var waitflag = 1;
 var timeflag =1;
 var MaxNO = 10;
 var joywave = new makeArray(MaxNO);
 var renzokuflag=0;
 var watchreset =0;
 var picadd =0;
 var picname = new makeArray(10);
 i=0;
 while(i<10){
     picname[i]=new Image();
     picname[i].src="images/"+i+".jpg";
     i++;
 }
var laugh = new Image();
    laugh.src = "images/laugh.gif";
var blue = new Image();     
    blue.src = "images/blue.gif";







function getCookie(key,  tmp1, tmp2, xx1, xx2, xx3) {
    tmp1 = " " + document.cookie + ";";
    xx1 = xx2 = 0;
    len = tmp1.length;
    while (xx1 < len) {
        xx2 = tmp1.indexOf(";", xx1);
        tmp2 = tmp1.substring(xx1 + 1, xx2);
        xx3 = tmp2.indexOf("=");
        if (tmp2.substring(0, xx3) == key) {
            return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
        }
        xx1 = xx2 + 1;
    }
    return("");
}
function setCookie(key, val, tmp) {
    tmp = key + "=" + escape(val) + "; ";
    document.cookie = tmp;
}










     i=1;
     while(i<MaxNO+1){
        joywave[i] ="waves/" + i+ ".wav";
        i++;
     }
function d_src_wav(xx,yy){
if (navigator.appName.indexOf("Netscape") < 0){
   document.all["SND"+xx].src =joywave[yy];
   }
}

function d_src_w_d(xx){
if (navigator.appName.indexOf("Netscape") < 0){
   document.all["SND"+xx].src ="";
   }
}

function d_src(xx,yy){
  if(xx == 1){
    document.NO1.src =picname[yy].src;
  }
  if(xx == 2){
    document.NO2.src =picname[yy].src;
  }
  if(xx == 3){
    document.NO3.src =picname[yy].src;
  }
  if(xx == 4){
    document.NO4.src =picname[yy].src;
  }
  if(xx == 5){
    document.NO5.src =picname[yy].src;
  }
  if(xx == 6){
    document.NO6.src =picname[yy].src;
  }
  if(xx == 7){
    document.NO7.src =picname[yy].src;
  }
  if(xx == 8){
    document.NO8.src =picname[yy].src;
  }
  if(xx == 9){
    document.NO9.src =picname[yy].src;
  }
  if(xx == 10){
    document.NO10.src =picname[yy].src;
  }
  if(xx == 11){
    document.NO11.src =picname[yy].src;
  }
  if(xx == 12){
    document.NO12.src =picname[yy].src;
  }
  if(xx == 13){
    document.NO13.src =picname[yy].src;
  }
  if(xx == 14){
    document.NO14.src =picname[yy].src;
  }
  if(xx == 15){
    document.NO15.src =picname[yy].src;
  }
  if(xx == 16){
    document.NO16.src =picname[yy].src;
  }
  if(xx == 17){
    document.NO17.src =picname[yy].src;
  }
  if(xx == 18){
    document.NO18.src =picname[yy].src;
  }
  if(xx == 19){
    document.NO19.src =picname[yy].src;
  }
  if(xx == 20){
    document.NO20.src =picname[yy].src;
  }

}
function d_src_blue(xx){
  if(xx == 1){
    document.NO1.src =blue.src;
  }
  if(xx == 2){
    document.NO2.src =blue.src;
  }
  if(xx == 3){

    document.NO3.src =blue.src;
  }
  if(xx == 4){
    document.NO4.src =blue.src;
  }
  if(xx == 5){
    document.NO5.src =blue.src;
  }
  if(xx == 6){
    document.NO6.src =blue.src;
  }
  if(xx == 7){
    document.NO7.src =blue.src;
  }
  if(xx == 8){
    document.NO8.src =blue.src;
  }
  if(xx == 9){
    document.NO9.src =blue.src;
  }
  if(xx == 10){
    document.NO10.src =blue.src;
  }
  if(xx == 11){
    document.NO11.src =blue.src;
  }
  if(xx == 12){
    document.NO12.src =blue.src;
  }
  if(xx == 13){
    document.NO13.src =blue.src;
  }
  if(xx == 14){
    document.NO14.src =blue.src;
  }
  if(xx == 15){
    document.NO15.src =blue.src;
  }
  if(xx == 16){
    document.NO16.src =blue.src;
  }
  if(xx == 17){
    document.NO17.src =blue.src;
  }
  if(xx == 18){
    document.NO18.src =blue.src;
  }
  if(xx == 19){
    document.NO19.src =blue.src;
  }
  if(xx == 20){
    document.NO20.src =blue.src;
  }

}
function d_src_laugh(xx){
  if(xx == 1){
    document.NO1.src =laugh.src;
  }
  if(xx == 2){
    document.NO2.src =laugh.src;
  }
  if(xx == 3){
    document.NO3.src =laugh.src;
  }
  if(xx == 4){
    document.NO4.src =laugh.src;
  }
  if(xx == 5){
    document.NO5.src =laugh.src;
  }
  if(xx == 6){
    document.NO6.src =laugh.src;
  }
  if(xx == 7){
    document.NO7.src =laugh.src;
  }
  if(xx == 8){
    document.NO8.src =laugh.src;
  }
  if(xx == 9){
    document.NO9.src =laugh.src;
  }
  if(xx == 10){
    document.NO10.src =laugh.src;
  }
  if(xx == 11){
    document.NO11.src =laugh.src;
  }
  if(xx == 12){
    document.NO12.src =laugh.src;
  }
  if(xx == 13){
    document.NO13.src =laugh.src;
  }
  if(xx == 14){
    document.NO14.src =laugh.src;
  }
  if(xx == 15){
    document.NO15.src =laugh.src;
  }
  if(xx == 16){
    document.NO16.src =laugh.src;
  }
  if(xx == 17){
    document.NO17.src =laugh.src;
  }
  if(xx == 18){
    document.NO18.src =laugh.src;
  }
  if(xx == 19){
    document.NO19.src =laugh.src;
  }
  if(xx == 20){
    document.NO20.src =laugh.src;
  }

}

function watchset(){
  if(watchreset == 1){
	setTimeout("watchset()", 1000);
	playsecond ++;
	document.form1.watch.value = playsecond; 
  }
}

function Back(){
     f=SelectNO[0];
     g=SelectNO[1];
     d_src_laugh(f);
     d_src_laugh(g);
     waitflag=0;
}

function Blue(){
     f=SelectNO[0];
     g=SelectNO[1];
     d_src_blue(f);
     d_src_blue(g);
     waitflag=0;

}

function renzoku(rflag){
   if(rflag == 0){
       renzokuflag =1;
   }else{
       renzokuflag =0;
   }
}

function main(ImgNO){
if((waitflag == 0) && (Card[ImgNO]==-1)){
    Card[ImgNO] = Number[ImgNO];
    k=1;
    j=0;  
    while(k<21){
      if((Card[k] >-1)&&(Card[k]<10)){
         SelectNO[j] = k;
         j++;
      }
      k++;
    }

    if(j>1){
       if(Card[SelectNO[0]] ==Card[SelectNO[1]]){
           Voice[Card[ImgNO]] = 0;
           Card[SelectNO[0]] = 10;
           Card[SelectNO[1]] = 10
           waitflag=1;
           xx=ImgNO;
           yy=Number[ImgNO]+picadd;
           d_src(xx,yy);
           setTimeout("Blue()",700);

           m=1;
           while(m<21){
              n=0;
              if(Card[m] <10){
                  n++;
                  break;
               }
               m++;
            }
            if(n == 0){
               timeflag =2;
               waitflag =1;
               watchreset=0; 
               j=document.form1.tryno.value;
               setCookie("Tryno",j);
               setCookie("load",1);

               document.form1.T_H.value = 1;
               document.form1.submit();
            }
       } else{
           Voice[Card[SelectNO[0]]] =WavNO[Card[SelectNO[0]]+1];
           Voice[Card[SelectNO[1]]] =WavNO[Card[SelectNO[1]]+1];
           p=Card[ImgNO];
           Card[SelectNO[0]] = -1;
           Card[SelectNO[1]] = -1
           waitflag=1;
           yy=Voice[p];
           d_src_wav(p,yy);
           xx=ImgNO;
           yy=Number[ImgNO]+picadd;

           d_src(xx,yy);
           setTimeout("Back()",700);
           document.form1.laughn.value ++;
           }

    } if(j==1){
         if(Number[ImgNO]>-1){
           xx=ImgNO;
           yy=Number[ImgNO]+picadd;
           d_src(xx,yy);
         }else{
            g=ImgNO;
            d_src_blue(g);

         }
    }
   }
   return false;
}

function timer(){
    if(timeflag ==1){
     if(renzokuflag==1){
      i=0;
      while(i<10){
        if(Voice[i]>0){
             yy=Voice[i];
             d_src_wav(i,yy);
        }
        i++;
      }
     }
    setTimeout("timer()",1500);
 } 
 }

function waiter(){
      d_src_laugh(topNO);
      topNO++;
      if(topNO<21){
         setTimeout("waiter()",50);
      }else{
         timeflag=1;
         waitflag=0;
         timer();
         playsecond=-1;
         watchreset=1;
         watchset();
      }
}

function startx(){
if(timeflag==0 || timeflag==2){
   watchreset=0;
   document.form1.watch.value = 0;
   document.form1.tryno.value = 1;
 
   timeflag=3;
   waitflag=1;
   i=1;
   while(i<11){
        Card[i] = -1;
        i++;
   }

   topNO=1;
   waiter();

   i=1;
   while(i<21){
      Number[i]=-1;
      WavNO[i]=-1;
      i++;
   }

   i=1;
   while(i<21){
      xxx = Math.floor(Math.random() * 10);
      k=1;
      j=0;
      while(k<i){
          if(Number[k] == xxx){
               j++;
          }
          k++;
      }    
      if(j<2){
          Number[i]=xxx;
          i++;
     }

   }
   i=1;
   string_x ="A";
   while(i <21){
      string_x = string_x  + Number[i];
      i++;
   }
   setCookie("StringX", string_x);

   i=1;
   while(i<11){
      xxx = Math.floor(Math.random() * MaxNO)+1;
      k=1;
      j=0;
      while(k<i){
          if(WavNO[k] == xxx){
               j++;
          }
          k++;
      }
      if(j == 0){
               WavNO[i]=xxx;
      i++;
      }
   }

   i=0;
   while(i<11){
         Voice[i]=-1;
      i++;
   }

  }
 }
 
function retry(){
if((timeflag==0 || timeflag==2)&&(Number[1]>-1)){
   watchreset=0;
   document.form1.watch.value = 0;
   document.form1.tryno.value ++;
   document.form1.laughn.value = 0;

   timeflag=3;
   waitflag=1;
   topNO=1;
   waiter();
      
   i=0;
   while(i<11){
         Voice[i]=-1;
      i++;
   }
   
  }
 }
 
function resetx(){
 if(timeflag<2){
   tourokuflag =0;
   watchreset=0;
      i=1;
   while(i<21){
       Card[i] = -1;
       d_src_blue(i);
      i++;
   }
   i=1;
   while(i<11){
       Voice[i]=-1;
       d_src_w_d(i);
      i++;
   }
    
   timeflag =2;
   waitflag =1;
   
   document.form1.watch.value = 0;
   document.form1.laughn.value = 0;
   document.form1.T_H.value = 0;

 }
}


