var s,cn,m,n,count;
s   = document.cookie;
cn  = "cookie_name=";
n   = s.indexOf(cn,0);
//str = navigator.appName.toUpperCase();
str = navigator.userAgent;
ref = document.referrer; 
host = location.host;
//dom = document.domain;

if (n != -1) {
  m = s.indexOf(";",n+cn.length);
  if (m == -1) m = s.length;
   count = s.substring(n+cn.length,m);
 }
  else { count = "0"; }

 if (ref.indexOf("/hanazukan") >= 0) { location.href ="stop.htm"; }
 // if (ref == '') { location.href ="no_direct.htm"; }

 if (str.indexOf("TencentTr") >= 0) { location.href ="stop.htm"; }
 if (str.indexOf("Crawler") >= 0) { location.href ="stop.htm"; }
 if (str.indexOf("NaverBot") >= 0) { location.href ="stop.htm"; }
 if (str.indexOf("Capture") >= 0) { location.href ="stop.htm"; }

 if (count >= 200) { location.href = "stop.htm"; }
 if (!navigator.cookieEnabled)  { location.href ="cookie.htm"; }


function chk() {
 cn = "cookie_name=";
 c_date = new Date();
 n = c_date.getTime() + 1000*60*60*2;
 c_date.setTime(n);
 kigen = c_date.toGMTString();
 count++;
 document.cookie = cn + count + "; expires=" + kigen;
}

 var myWin ='';
 var bf_img = '';
 var bfs_img = '';

// 参照(大）画像表示
function ref_disp(img,name,kname,re,w,h) {

  imgDir = img.split('/');
  imgDir = imgDir.reverse();
  img_file = imgDir[0];
  no = img_file.charCodeAt(0);

               if( no < 104 ) { img = 'AG~RL/' + img_file; } 
  if( no >= 104 && no < 107 ) { img = 'HJ~RL/' + img_file; } 
  if( no >= 107 && no < 109 ) { img = 'KL~RL/' + img_file; } 
  if( no >= 109 && no < 111 ) { img = 'MN~RL/' + img_file; } 
  if( no >= 111 && no < 115 ) { img = 'OR~RL/' + img_file; } 
  if( no == 115             ) { img = 'SS~RL/' + img_file; } 
              if( no >= 116 ) { img = 'TZ~RL/' + img_file; } 

   img = 'http://www.ootk.net/shiki/'+img;
   image=new Image();
   image.src=(img); 

  str = navigator.userAgent;
 
//   if (str.indexOf("Safari") < 0 && bf_img != img ) { 
//    image.onload = function() { subwin_disp(img,name,kname); }
//   }
//   else { subwin_disp(img,name,kname); }

   subwin_disp(img,name,kname); 

   bf_img = img;
}

// 参照イメージ表示
function subwin_disp(img,name,kname) { 

    wa = image.width; ha = image.height;
    wa = wa + 10; ha = ha + 32;
    if(wa < 20 ) { wa = 520; ha = 560; } 

 if(myWin !='')  { myWin.close(); }

  str = navigator.userAgent;
   if (str.indexOf("Firefox") < 0) { 
     x = event.screenX - wa - 200;
      if (x <1) { x = 1; }
     y = event.screenY - ha;
      if (y <1) { y = 1; }
    }
  else { x = 1; y = 1; }

  myWin=window.open('','参照','width='+wa+',height='+ha+',left='+x+',top='+y+',scrollbars=no');
  myWin.document.open();
  myWin.document.writeln('<HTML><HEAD><TITLE>'+ name +'</TITLE></HEAD>\n')
  myWin.document.writeln('<BODY bgcolor=#BBBBBB topmargin=4 leftmargin=4>\n')
  myWin.document.writeln('<CENTER>\n')
  myWin.document.writeln('<img src=' + img + ' border=0><font size=2><BR>\n')
  myWin.document.writeln(name +'（'+kname+'）</font>\n')
  myWin.document.writeln('<img src=close.gif border=0 onClick=\"window.close()\">\n')
  myWin.document.writeln('</BODY></HTML>')
  myWin.document.close();
  myWin.focus();
  return false;
 }

// コメント内参照画像表示
function img_disp(img) { 

  img = img.replace("1.","L1.");
  img = img.replace("2.","L2.");
  img = img.replace("3.","L3.");
  img = img.replace("4.","L4.");
  img = img.replace("5.","L5.");
  img = img.replace("6.","L6.");
  img = img.replace("7.","L7.");
  img = img.replace("8.","L8.");
  img = img.replace("9.","L9.");
   if (img.indexOf("L",0) == -1) { img = img.replace(".","L."); }
 
 no = img.charCodeAt(0);

               if( no < 104 ) { img = 'AG_L/' + img; } 
  if( no >= 104 && no < 107 ) { img = 'HJ_L/' + img; } 
  if( no >= 107 && no < 109 ) { img = 'KL_L/' + img; } 
  if( no >= 109 && no < 111 ) { img = 'MN_L/' + img; } 
  if( no >= 111 && no < 115 ) { img = 'OR_L/' + img; } 
  if( no == 115             ) { img = 'SS_L/' + img; } 
              if( no >= 116 ) { img = 'TZ_L/' + img; } 

   img = 'http://www.ootk.net/shiki/'+img;
   image=new Image();
   image.src= img;

   str = navigator.userAgent;
 
   if (str.indexOf("Safari") < 0 && bfs_img != img  ) { 
     image.onload = function() { subwin_Sdisp(img); }
   }
    else { subwin_Sdisp(img);  }

   bfs_img = img;
 }

// 参照画面（小）
function subwin_Sdisp(img) { 

   wa = image.width; ha = image.height;
   wa= wa+10; ha = ha+28;
   if(wa < 20 ) { wa = 400; ha = 430; } 

  if(myWin !='')  { myWin.close(); }
 
  str = navigator.userAgent;
   if (str.indexOf("Firefox") < 0) { 
   x = event.screenX - wa - 200;
     if (x <1) { x = 1; }
    y = event.screenY - ha;
      if (y <1) { y = 1; }
   }
  else { x = 1; y = 1; }

  myWin=window.open('','参照','width='+wa+',height='+ha+',left='+x+',top='+y+',scrollbars=no')
  myWin.document.open();
  myWin.document.writeln('<HTML><HEAD><TITLE>イメージ</TITLE>\n')
  myWin.document.writeln('</HEAD><BODY bgcolor=#888888 topmargin=4 leftmargin=4><center>\n')
  myWin.document.writeln('<img border=0 src='+img+'><BR>\n')
  myWin.document.writeln('<a href=# onClick=window.close();><img src=close.gif border=0></a>\n')
  myWin.document.writeln('</BODY></HTML>\n')
  myWin.document.close();
  myWin.focus();
  return false;
 }

// 画面クローズ
function win_closed(winVar) { 
 var ua = navigator.userAgent; 
  if( !!winVar ) 
   if( ( ua.indexOf('Gecko')!=-1 || ua.indexOf('MSIE 4')!=-1 || ua.indexOf('Opera')!=-1 ) 
     && ua.indexOf('Win')!=-1 ) 
    return winVar.closed; 
   else return typeof winVar.document  != 'object'; 
 else return true; 
} 