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;
}

 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];

   it = img_file.substring(0,1) ;
   it = it.replace(/[a-g]/,"AG");
   it = it.replace(/[h-j]/,"HJ");
   it = it.replace(/[k-l]/,"KL");
   it = it.replace(/[m-n]/,"MN");
   it = it.replace(/[o-r]/,"OR");
   it = it.replace(/s/,"SS");
   it = it.replace(/[t-z]/,"TZ");

   img = '../../shiki/' + it + '~RL/' + img_file;
   image=new Image();
   image.src=(img); 

   subwin_disp(img,name,kname);

}

// 参照イメージ表示
function subwin_disp(img,name,kname) { 

    str = navigator.userAgent;
    var x = 1;
    var y = 1;

    wa = image.width; ha = image.height;
    wa = wa + 10; ha = ha +42;
    if(wa < 20 ) { wa = 520; ha = 560; } 

 if(myWin !='')  { myWin.close(); }

 if (str.indexOf("Gecko") < 0) { x = event.screenX - wa - 200; }
     if (x <1) { x = 1; }
 if (str.indexOf("Gecko") < 0) { y = event.screenY - ha + 100; }
     if (y <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 onContextmenu=\"return false\" >\n')
  myWin.document.writeln('<CENTER>\n')
  myWin.document.writeln('<img src=' + img + ' border=0><font size=2><BR><span style=\"height:16\">\n')
  myWin.document.writeln(name +'（'+kname+'）</span>\n')

  ua = navigator.userAgent; 
  if(ua.indexOf('Safari') < 0 || ua.indexOf('Chrome') > 0) {
    myWin.document.writeln('<br><a href=# onClick=\"window.close()\"><img src=close.gif border=0></a>\n')
   }
   else { myWin.document.writeln('<br><img src=x.gif>') }
  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."); }
 
   it = img.substring(0,1) ;
   it = it.replace(/[a-g]/,"AG");
   it = it.replace(/[h-j]/,"HJ");
   it = it.replace(/[k-l]/,"KL");
   it = it.replace(/[m-n]/,"MN");
   it = it.replace(/[o-r]/,"OR");
   it = it.replace(/s/,"SS");
   it = it.replace(/[t-z]/,"TZ");

   img = 'http://www.ootk.net/shiki/' + it + '_L/' + img;
   image=new Image();
   image.src=(img); 
   subwin_Sdisp(img);

 }

// 参照画面（小）
function subwin_Sdisp(img) { 

    str = navigator.userAgent;
    var x = 1;
    var y = 1;
   wa = image.width; ha = image.height;
  if (str.indexOf("Gecko") >= 0) { wa = image.naturalWidth; ha = image.naturalHeight; }
 
  wa= wa+10; ha = ha+28;
   if(wa < 20 ) { wa = 400; ha = 440; } 

  if(myWin !='')  { myWin.close(); }

 if (str.indexOf("Gecko") < 0) { x = event.screenX - wa - 280; }
     if (x <1) { x = 1; }
 if (str.indexOf("Gecko") < 0) { y = event.screenY - ha + 100; }
     if (y <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>')
  myWin.document.writeln('</HEAD><BODY bgcolor=#AAAAAA topmargin=4 leftmargin=4><center>')
  myWin.document.writeln('<img border=0 src='+img+'><BR>')
   ua = navigator.userAgent; 
  if(ua.indexOf('Safari') < 0 || ua.indexOf('Chrome') > 0) {
    myWin.document.writeln('<a href=# onClick=\"window.close()\"><img src=close.gif border=0></a>\n')
   }
   else {
    myWin.document.writeln('<img src=x.gif>')
   }
  myWin.document.writeln('</BODY></HTML>')
  myWin.document.close();
  myWin.focus();
  return false;
 }

// 画面クローズ
function win_closed(winVar) { 
 var ua = navigator.userAgent; 
  if( !!winVar ) 
   if( ( ua.indexOf('Apple')!=-1 || ua.indexOf('MSIE 4')!=-1 ) 
     && ua.indexOf('Win')!=-1 ) 
    return winVar.closed; 
   else return typeof winVar.document  != 'object'; 
 else return true; 
} 

