//===============================================================================
//* ファイル名：common.js
//* 名称：Java Script
//* 用途：HTMLファイルを動的に変化させる
//* 作成：Stephen
//* 年月日：2005年3月
//===============================================================================
function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

//*******************************************************************************
//* 関数名: init_child_w
//* 用途：画面読み込み時の動作(不正呼出時のリダイレクト)
//* 受取引数：なし
//* 戻り値：なし
//*******************************************************************************
function init_child_w() {
  //to avoid frame-prepared pages to open in the main window
    if (!self.opener){top.location='#'; }
}

//*******************************************************************************
//* 関数名: disp_list
//* 用途：参照用のポップアップウィンドーをサイズ、位置指定して表示
//* 受取引数：開くファイルのＵＲＬ、表題、表示画面の縦の幅、表示画面の横の幅
//* 戻り値：ポップアップウィンドウオブジェクト
//*******************************************************************************
function disp_list(url, name, height, width) {
    var str = "resizable=1,menubar=0,scrollbars=1,height=" + height + ",innerHeight=" + height;
    str += ",width=" + width + ",innerWidth=" + width;
    if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;
    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;
    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
    }
    return window.open(url, name, str);
}

//****************************************************************
//* 関数名: getNextElement
//* 用途：タブオーダーを判別して次のコントロールの値を返す
//* 受取引数：対象となるコントロール
//* 戻り値：次のコントロールオブジェクト
//****************************************************************
function getNextElement(field) {
  var fieldFound = false;
  var form = field.form;
  for (var e = 0; e < form.elements.length; e++) {
    if (fieldFound && form.elements[e].type != 'hidden')
  //if (fieldFound && (form.elements[e].type != 'hidden' || form.elements[e].type != 'image') && !form.elements[e].readOnly)
  if (fieldFound && (form.elements[e].type != 'hidden' && form.elements[e].type != 'image') && !form.elements[e].readOnly)
      break;
    if (field == form.elements[e])
      fieldFound = true;
  }
  return form.elements[e % form.elements.length];
}


//****************************************************************
//* 関数名: tabOnEnter
//* 用途：エンターキーによるタブ移動
//* 受取引数：対象のフィールドオブジェクト、イベント、動作モード、移動先
//* 戻り値：成功失敗
//****************************************************************
function tabOnEnter (field,evt,mode,targetObj) {
  var keyCode = document.layers ? evt.which : document.all ?evt.keyCode : evt.keyCode;
  var obj=getNextElement(field);
  if (keyCode != 13){return true;}
  else {
    switch(mode){
      case "inOrder":
        obj.focus();
        obj.select();
        break;
      case "jumpToTarget":
        targetObj.focus();
        //targetObj.select();
        break;
    }
    return false;
  }
}

//****************************************************************
//* 関数名: checkNum
//* 用途：数字以外の入力文字ブロック
//* 受取引数：なし
//* 戻り値：なし
//****************************************************************
function checkNum() {
  if((event.keyCode>57)|(event.keyCode<48)) {
      event.returnValue=false;
  }
}

//****************************************************************
//* 関数名: tabOnEnterNum
//* 用途：キーイベントを判別し、数字以外を無効にし、タブ送りして検索関数を呼ぶ
//* 受取引数：対象のフィールドオブジェクト、イベント、動作モード、成功時フォーカス先、失敗時フォーカス先
//* 戻り値：成功失敗
//****************************************************************
function tabOnEnterNum(field,evt,mode,success,fail) {
  var keyCode = document.layers ? evt.which : document.all ?evt.keyCode : evt.keyCode;
  if (keyCode != 13){checkNum();}
  else {
    var obj=getNextElement(field);
    switch(mode){
      case 'key'://キー項目　次のコントロールに飛んでレコード取得
        if (field.value=="") {
          alert("SEARCHのキーを入力して下さい。");
          fail.focus();
          return false;
        }
        else{
          execute("SEARCH");
          success.focus();
          return true;
        }
        break;
      case 'jumpToCmb'://次のコントロールがプルダウンであった場合の対応
        //次のコントロールに移動しても選択されたままになってしまうので、値を代入しなおして選択解除。
        field.value=field.value;
        obj.focus();
        break;
      default://次のコントロールに飛んでセレクト
        obj.focus();
        obj.select();
        break;
    }
    return false;
  }
}

//****************************************************************
//* 関数名: execute
//* 用途：登録処理を実行する
//* 受取引数：動作モード
//* 戻り値：なし
//****************************************************************
function execute(mode) {
  cansubmit=1;
  document.mainform.mode.value=mode;
  document.mainform.submit();
//  return true;
}

//****************************************************************
//* 関数名: tdmouseover
//* 用途：マウスオーバーでセルの色を変える
//* 受取引数：セル名、色コード
//* 戻り値：なし
//****************************************************************
function tdmouseover(itemID,color){
  itemID.style.backgroundColor=color;
}

//****************************************************************
//* 関数名: tdmouseout
//* 用途：マウスアウトでセルの色を元に戻す
//* 受取引数：セル名、色コード
//* 戻り値：なし
//****************************************************************
function tdmouseout(itemID,color){
  itemID.style.backgroundColor=color;
}

//****************************************************************
//* 関数名: window_open
//* 用途：新しいウィンドウを開く
//* 受取引数：新しく開くプログラム名
//* 戻り値：なし
//****************************************************************
function window_open(window_name){
  window.open(window_name,"new","resizable=no,status=no,scrollbars=yes,location=no,toolbar=no,width=600,height=450");
}

//****************************************************************
//* 関数名: window_open
//* 用途：新しいウィンドウを開く
//* 受取引数：新しく開くプログラム名
//* 戻り値：なし
//****************************************************************
function window_open2(window_name,name){
  window.open(window_name,name,"resizable=no,status=no,scrollbars=no,location=no,toolbar=no,width=320,height=320");
}

//****************************************************************
//* 関数名: window_open3
//* 用途：新しいウィンドウを開く
//* 受取引数：新しく開くプログラム名
//* 戻り値：なし
//****************************************************************
function window_open3(window_name,width,height){
  window.open(window_name,"new","resizable=no,status=no,scrollbars=no,location=no,toolbar=no,width=530,height=600");
}

function floatButton () {
if (document.all) {
document.all.topButton.style.pixelTop = document.body.scrollTop;
}
else if (document.layers) {
document.topButton.top = window.pageYOffset;
}
else if (document.getElementById) {
document.getElementById('topButton').style.top = window.pageYOffset + 'px';
   }
}
if (document.all)
window.onscroll = floatButton;
else
setInterval ('floatButton()', 100);

function initButton() {
if (document.all) {
document.all.topButton.style.pixelLeft = document.body.clientWidth - document.all.topButton.offsetWidth;
document.all.topButton.style.visibility = 'visible';
}
else if (document.layers) {
document.topButton.left = window.innerWidth - document.topButton.clip.width - 15;
document.topButton.visibility = 'show';
}
else if (document.getElementById) {
document.getElementById('topButton').style.left = (window.innerWidth - 35) + 'px';
document.getElementById('topButton').style.visibility = 'visible';
   }
}

//****************************************************************
//* 関数名: newwindow
//* 概要：新しいウィンドウを開き、画像を表示する
//* 引数：画像パス、画像名、ウィンドウサイズ
//* 戻り値：なし
//****************************************************************
function newwindow(title,count,features,code,number,data,mapless,print,object,object2){
  var others    = "";
  var start   = "img_bunkazai/"+code+"/"+code+"_"+number+"_l.jpg";
  NameData    = data.split("||");
  logo      = "img_bunkazai/"+code+"/"+code+"_logo.gif";
  map       = "img_bunkazai/"+code+"/map_"+code+"L.jpg";
  if(number=="map"){start=map;}
  map       = "<a href=\"javascript:;\" onClick=\"clickChange('"+ map +"');return false;\" border=\"0\"><img src=./img/tyaya/button_map.gif border=0></a> ";
  for(var i=0;i<count;i++){
  //各値を取り出す
  
  if(i==0){
  nwin = window.open(logo,title,features);
  nwin.document.open();
  nwin.document.write("<HTML><HEAD><TITLE>"+title+"</TITLE><script language=JavaScript1.2 src=./common/common.js></script>\n");
  nwin.document.write("<SCRIPT language=\"JavaScript\"><!--\n");
  nwin.document.write(" var n=0\n");
  nwin.document.write(" function clickChange(imageNum){\n");
  nwin.document.write(" if (document.images) document.myImage.src = imageNum;\n");
  nwin.document.write("}");
	nwin.document.write("//--></SCRIPT>\n");
	nwin.document.write(object);
	nwin.document.write(object2);
  nwin.document.write("<BODY>\n");
  nwin.document.write("<TABLE border=\"0\" align=\"center\" cellpadding=\"0 \"cellspacing=\"0\">\n");
  nwin.document.write("<TR><TD colspan=\"2\"><img src='"+logo+"'></TD></TR>\n");
  nwin.document.write("<TR><TD colspan=\"2\" height=10><hr></TD></TR>\n");
  if(mapless==1){nwin.document.write("<TR><TD colspan=\"2\" align=\"right\">"+map+"</TD></TR>\n");} 
  nwin.document.write("<TR><TD colspan=\"2\" align=center><IMG SRC="+start+" name=myImage>\n"); 
  nwin.document.write("</FORM>\n");
  }
  others+="<a href=\"javascript:;\" onClick=\"clickChange('img_bunkazai/"+code+"/"+code+"_0"+(i+1)+"_l.jpg');return false;\" border=\"0\">"+NameData[i]+"</a> ";
  }

  nwin.document.write("<TR><TD colspan=\"2\" align=center>"+others+"</TD></TR>\n");
  nwin.document.write("<TR><TD colspan=\"2\" height=10><hr></TD></TR>\n");
  nwin.document.write("<TR><TD colspan=\"2\" style=\"text-align:center;\">\n");
  nwin.document.write("<FORM NAME=imgform>\n");
  nwin.document.write(print+"<br><br>");
//  nwin.document.write("<INPUT TYPE=\"submit\" VALUE=\"閉じる\" onClick=\"window.close(); \">\n");
  nwin.document.write("<A HREF=javascript:window.close()><img src=\"./img/button_close.gif\" border=\"0\"></a>\n");
  nwin.document.write("</TD></TR>\n");
  nwin.document.write("</TABLE>\n");
  nwin.document.write("</BODY></HTML>\n");
  nwin.document.close();
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


//****************************************************************
//* 関数名: openWin
//* 概要：新しいウィンドウを開く。繰返し開かれる場合は同一ウィンドウに内容を表示する
//*　　　 （新しいウィンドウは開かずに内容のみ更新する）
//* 引数：ファイルパス
//* 戻り値：なし
//****************************************************************
function openWin(url) {
w = open(url, "yougo", "location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,left=0,top=0,width=720,height=600");
w.focus();
}

//****************************************************************
//* 関数名: openWin2
//* 概要：新しいウィンドウを開く。繰返し開かれる場合は同一ウィンドウに内容を表示する
//*　　　 （新しいウィンドウは開かずに内容のみ更新する）
//* 引数：ファイルパス
//* 戻り値：なし
//****************************************************************
function openWin2(url) {
w = open(url, "", "location=no,menubar=no,resizable=no,scrollbars=no,status=no,left=0,top=0,width=600,height=450");
w.focus();
}

function printWindow2() {
bV = parseInt(navigator.appVersion);
if (bV >= 4) window.print();
}

function local_print2(){ 
open('now_printing.html','_blank','width=210,height=0,menubar=no,toolbar=no');
 if(document.layers){ 
             // ページ設定 
 window.print(); 
 } 
 else{if(document.all){ 
   putSettings2() // set settings  // print and get settings when done 
var OLECMDID = 6;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 1 - open window
* 4 - Save As
*/
var PROMPT = 2; // 2 DONTPROMPTUSER 
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser); 
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = "";

//   factory.printing.Print(false, window); 
 }}
 value=print; 
} 

function putSettings2() { 
   factory.printing.header = "";        // Header 
   factory.printing.footer = "";        // footer 
   factory.printing.portrait = true;   // 用紙の向き(true:縦/false:横) 
   factory.printing.leftMargin = 0;     // 余白　左 
   factory.printing.topMargin = 0;      // 余白　上 
   factory.printing.rightMargin = 0;    // 余白　右 
   factory.printing.bottomMargin = 0;   // 余白　下 
 } 