//#### 2009-09-04 ★２度押し防止 By Onishi↓
//フォームのdisabled制御
function dis(formName,objName,flg) {
  objForm = eval("document."+formName);
  var el = document.getElementsByTagName("a");
  if(objName == "all"){
  	for(i=0;i<objForm.length;i++){
	  	if(objForm[i].type.toLowerCase() == "button" || objForm[i].type.toLowerCase() == "submit"){
        objForm[i].disabled = flg;
			}
  	}
	  for (var i=0, len=el.length; i<len; i++) {
	    el[i].removeAttribute('href');
	  }
  }else{ 
    for(i=0;i<objForm.length;i++){
     	if(objForm[i].type == objName){
       	objForm[i].disabled = flg;
      }else if(objForm[i].name == objName){
        objForm[i].disabled = flg;
      }
    }
  }
}
//#### 2009-09-04 ★２度押し防止 By Onishi↑

// ログアウト
// 引数: url ＵＲＬ
function log_out(url) {
  var wnd;
  var x,y;
  x = (screen.width-1024) / 2;
  y = 0;
  wnd = window.open(url, "index", "dependent=yes, hotkeys=yes, location=yes, menubar=yes, resizable=yes, scrollbars=yes, status=yes, titlebar=yes, toolbar=yes, directories=yes, fullscreen=no, width=1024, height=740, left="+x+", top="+y+", ",true);
 (window.open('','_self').opener=window).close();
  wnd.focus();
}

//#### 2009-10-05 ログアウト処理改善(大林組) By Matsumoto↓
// ログアウト(大林組)
// 引数   : url ＵＲＬ
function log_out2(url) {
  if(confirm('ログアウトをして画面を閉じますがよろしいですか？')==true){
    document.mainForm.action = url;
    document.mainForm.submit();
//    window.close();
	}
}
//#### 2009-10-05 ログアウト処理改善(大林組) By Matsumoto↑

// 公開画面に戻る
function home() {
  var wnd;
  var x,y;
  x = (screen.width-1024) / 2;
  y = 0;
  wnd = window.open("../index.asp", "index", "dependent=no, hotkeys=no, location=yes, menubar=yes, resizable=yes, scrollbars=yes, status=yes, titlebar=yes, toolbar=yes, directories=yes, fullscreen=no, width=1024, height=740, left="+x+", top="+y+", ",false);
 (window.open('','_self').opener=window).close();
  wnd.focus();
}

// 「編集終了」ボタン押下時
// 引数: patten_cd      雛形
//     : page_no        ページNo
//     : indication_flg 表示有無(2:公開前非表示）
function edit_end(patten_cd, page_no, indication_flg){
  var wnd;
  var x,y;
  x = (screen.width-1024) / 2;
  y = 0;
  //公開されていないページのときはＴＯＰページを表示する
  if(indication_flg != 0){
    wnd = window.open("../index.asp", "index", "dependent=no, hotkeys=no, location=yes, menubar=yes, resizable=yes, scrollbars=yes, status=yes, titlebar=yes, toolbar=yes, directories=yes, fullscreen=no, width=1024, height=740, left="+x+", top="+y+", ",false);
  } else {
    wnd = window.open("../index.asp?patten_cd="+patten_cd+"&page_no="+page_no, "index", "dependent=no, hotkeys=no, location=yes, menubar=yes, resizable=yes, scrollbars=yes, status=yes, titlebar=yes, toolbar=yes, directories=yes, fullscreen=no, width=1024, height=740, left="+x+", top="+y+", ",false);
  }
 (window.open('','_self').opener=window).close();
  wnd.focus();
}

// 「編集終了」ボタン押下時
// 引数: patten_cd      雛形
//     : page_no        ページNo
//     : indication_flg 表示有無(2:公開前非表示）
function home2(url, patten_cd, page_no, indication_flg){
  var wnd;
  var x,y;
  x = (screen.width-1024) / 2;
  y = 0;
  //公開されていないページのときはＴＯＰページを表示する
  if(indication_flg != 0){
    wnd = window.open(url , "index", "dependent=no, hotkeys=no, location=yes, menubar=yes, resizable=yes, scrollbars=yes, status=yes, titlebar=yes, toolbar=yes, directories=yes, fullscreen=no, width=1024, height=740, left="+x+", top="+y+", ",false);
  } else {
    wnd = window.open(url + "?patten_cd="+patten_cd+"&page_no="+page_no, "index", "dependent=no, hotkeys=no, location=yes, menubar=yes, resizable=yes, scrollbars=yes, status=yes, titlebar=yes, toolbar=yes, directories=yes, fullscreen=no, width=1024, height=740, left="+x+", top="+y+", ",false);
  }
 (window.open('','_self').opener=window).close();
  wnd.focus();
}

// HTML変換（font,em,u,strongは除く）
// 引数:str 変換文字列
function htmle(str) {
  str = str.replace(/</g,"&lt;");
  str = str.replace(/>/g,"&gt;");
  // STRONG 対応
  str = str.replace(/&lt; *STRONG *&gt;/gi,"<STRONG>");
  str = str.replace(/&lt; *\/ *STRONG *&gt;/gi,"<\/STRONG>");
  // EM 対応
  str = str.replace(/&lt; *EM *&gt;/gi,"<EM>");
  str = str.replace(/&lt; *\/ *EM *&gt;/gi,"<\/EM>");
  // U 対応
  str = str.replace(/&lt; *U *&gt;/gi,"<U>");
  str = str.replace(/&lt; *\/ *U *&gt;/gi,"<\/U>");
  // BR 対応
  str = str.replace(/&lt; *BR *&gt;/gi,"<BR>");
  // FONT 対応
  str = str.replace(/&lt; *FONT +([^&]*(&+(g|g[^&t][^&]*|[^&g][^&]*))*)&gt;/g,"<FONT $1>");
  str = str.replace(/&lt; *\/ *FONT *&gt;/g,"<\/FONT>");
  // A 対応
  str = str.replace(/&lt; *A +([^&]*(&+(g|g[^&t][^&]*|[^&g][^&]*))*)&gt;/g,"<A $1>");
  str = str.replace(/&lt; *\/ *A *&gt;/g,"<\/A>");
  str = str.replace(/<A href=&quot;([^>]*)&quot;>/g, "<A href=\"$1\">");
  return str;
}

// バージョン情報表示
function version(){
  var x,y;
  var wnd;
  x = (screen.width - 350) / 2;
  y = (screen.height - 180) / 2;
  wnd = window.open("../window/version.asp", "version", "left="+x+", top="+y+", width=350, height=180, scrollbars=no,location=no,menubar=no, status=no");
  wnd.focus();
}

// 操作説明表示
// 引数: url ＵＲＬ
function manual(url){
  var x,y;
  var wnd;
  x = (screen.width - 900) / 2;
  y = 5;
  wnd = window.open(url, "manual", "left="+x+", top="+y+", width=900, height=740,location=yes,menubar=yes,personalbar=yes,resizable=yes,scrollbars=yes,status=yes,titlebar=yes,toolbar=yes");
  wnd.focus();
}

// 素材集表示（ココシカギャラリーのリンク）
function sozai(){
  var x,y;
  var wnd;
  x = (screen.width - 900) / 2;
  y = 5;
  wnd = window.open("http://coco.cococica.com/gallery/index.asp", "sozai", "left="+x+", top="+y+", width=900, height=740,location=yes,menubar=yes,personalbar=yes,resizable=yes,scrollbars=yes,status=yes,titlebar=yes,toolbar=yes");
  wnd.focus();
}

// 評価値変換
// 引数: expr,      I, 評価式
//     : truepart,  I, 真の場合の評価値
//     : falsepart, I, 偽の場合の評価値
// 戻り値:評価値を返す
function iif(expr, truepart, falsepart){
  if (expr) {
    return truepart;
  }else{
    return falsepart;
  }
}

// 「公開する」ボタン押下時
// 引数: cd             雛型
//     : no             ページNO
//     : aspnm          ASPファイル名
//     : flg            表示有無
//     : censor         確認有無(0:なし，1:通知のみ，2:あり)
//     : competence     0:サイト管理者 1:ページ管理者
function go_public(cd, no, aspnm, flg, censor, competence){
  var x,y;
  var wnd;
  if(flg == 2){
    alert("先に上位ページを公開して下さい。");
  } else {
    //サイト管理者の場合
    if(competence==0){
      document.mainForm.patten_cd.value = cd;
      document.mainForm.page_no.value = no;
      document.mainForm.target="_self";
      document.mainForm.method="post";
      document.mainForm.mode.value = "update";
      document.mainForm.action=aspnm+".asp";
//#### 2009-09-04 ★２度押し防止 By Onishi↓
			dis("mainForm","all",true);
//#### 2009-09-04 ★２度押し防止 By Onishi↑
      document.mainForm.submit();
    }else{
      //ページ管理者の場合
      if(censor == 1 || censor == 2){
        x = (screen.width - 740) / 2;
        y = (screen.height - 650) / 2;
        wnd = window.open("../window/public_comment.asp?cd="+cd+"&no="+no+"&aspnm="+aspnm, "公開確認", "left="+x+", top="+y+", width=740, height=650, scrollbars=yes,location=no, menubar=no, status=yes, resizable=yes");
        wnd.focus();
      } else {
        document.mainForm.patten_cd.value = cd;
        document.mainForm.page_no.value = no;
        document.mainForm.target="_self";
        document.mainForm.method="post";
        document.mainForm.mode.value = "update";
        document.mainForm.action=aspnm+".asp";
//#### 2009-09-04 ★２度押し防止 By Onishi↓
				dis("mainForm","all",true);
//#### 2009-09-04 ★２度押し防止 By Onishi↑
        document.mainForm.submit();
      }
    }
  }
}

// 公開確認２
// 引数: cd      雛型
//     : no      ページNO
//     : aspnm   ASPファイル名
//     : cmt     コメント
function go_public2(cd, no, aspnm, cmt){
  document.mainForm.patten_cd.value = cd;
  document.mainForm.page_no.value = no;
  document.mainForm.target="_self";
  document.mainForm.method="post";
  document.mainForm.public_comment.value = cmt;
  document.mainForm.mode.value = "update";
//#### 2009-09-04 ★２度押し防止 By Onishi↓
	dis("mainForm","all",true);
//#### 2009-09-04 ★２度押し防止 By Onishi↑
  document.mainForm.submit();
}

// 新しいウインドウの表示
function openNewWin(url, name, w, h, status){
  var url_href = location.href;
  var url_path = location.pathname;
  if (w == ""){
     w = 600;
  }
  if (h == ""){
     h = 400;
  }
  if (status == ""){
     status = no;
  }
  return window.open(url, name , "resizable=yes, scrollbars=yes, menubar=no, location=no, width=" + w + ",  height=" + h + ", status");
}

// ページの切り替え
function movepage(page) {
  document.pageForm.page.value = page;
  document.pageForm.disp_page.value = page;
  document.pageForm.submit();
}

// オブジェクト個数の取得
function getlength(obj) {
  if (obj) {
    if (obj.name == undefined && obj.id == undefined) {
      return obj.length;
    } else {
      return 1;
    }
  } else {
    return 0;
  }
}

// オブジェクトの取得
function getobject(obj, i) {
  if (obj.name == undefined && obj.id == undefined) {
    return obj[i];
  } else {
    return obj;
  }
}

// バイト長の取得
// 引数：value,  I, 処理の対象となる式
//     ：戻り値, O, value のバイト長
function getByte(value) {
  var narrow = 'abcdefghijklmnopqrstuvwxyz'
             + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
             + '1234567890'
             + '!"#$%&\'()-=^~\\|@`[{;+:*]},<.>/?_ '
             + 'ｱｲｳｴｵｶｷｸｹｺｻｼｽｾｿﾀﾁﾂﾃﾄﾅﾆﾇﾈﾉﾊﾋﾌﾍﾎﾏﾐﾑﾒﾓﾔﾕﾖﾗﾘﾙﾚﾛﾜｦﾝｧｨｩｪｫｯｬｭｮﾞﾟ｢｣､｡･';
  var len = 0;
  var i;
  // 定義した半角文字列にない文字を２バイト文字としてバイト長を求める
  for (i = 0; i < value.length; i++) {
    if (narrow.indexOf(value.charAt(i)) >= 0) {
      len++;
    } else {
      len += 2;
    }
  }
  return len;
}

// 数値判定
// 引数  ：value,   I, 判定する文字列
//       ：decimal, I, 有効な小数点の桁数
//       ：minus,   I, 負の値を有効とするかどうか(true:有効 false:無効)
//       ：戻り値,  O, true:数値文字列 false:数値と判定できない文字列
function isNumeric(value, decimal, minus) {
  var idx_decimal;
  var idx_minus;
  var tmp_value;
  var i;
  // 既定値を設定する
  if (decimal == 'undefined') { decimal = 0; }
  if (minus   == 'undefined') { minus   = false; }
  // 処理の対象となる式を文字列式に変換する
  value += '';
  // 空文字の場合は無効とする
  if (value == '') {
    return false;
  // 無効な文字が含まれていれば無効とする
  } else if (value.match(/[^0123456789\.\-]/)) {
    return false;
  }
  // 小数点が含まれている場合
  idx_decimal = value.indexOf('.');
  if (idx_decimal >= 0) {
    // 以下の場合は無効とする
    // ・小数点以下を無効とする場合
    // ・先頭に小数点がある場合
    // ・最後に小数点がある場合
    // ・小数点が２つ以上ある場合
    // ・小数点以下の桁数が有効桁数外の場合
    if (decimal <= 0 || idx_decimal == 0 || idx_decimal == value.length - 1 || value.indexOf('.', idx_decimal + 1) >= 0 || value.length - idx_decimal - 1 > decimal) {
      return false;
    }
  }
  // マイナス記号が含まれている場合
  idx_minus = value.indexOf('-');
  if (idx_minus >= 0) {
    // 以下の場合は無効とする
    // ・負の値を無効とする場合
    // ・先頭以外にマイナス記号がある場合
    // ・マイナス記号が２つ以上ある場合
    if (!minus || idx_minus > 0 || value.indexOf('-', idx_minus + 1) >= 0) {
      return false;
    }
  }
  return true;
}

// 半角文字判定
// 引数  ：value,  I, 判定する文字列
//       ：戻り値, O, true:半角文字列 false:全角文字を含んだ文字列
function isNarrow(value) {
  var narrow = 'abcdefghijklmnopqrstuvwxyz'
             + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
             + '1234567890'
             + '!"#$%&\'()-=^~\\|@`[{;+:*]},<.>/?_ '
             + 'ｱｲｳｴｵｶｷｸｹｺｻｼｽｾｿﾀﾁﾂﾃﾄﾅﾆﾇﾈﾉﾊﾋﾌﾍﾎﾏﾐﾑﾒﾓﾔﾕﾖﾗﾘﾙﾚﾛﾜｦﾝｧｨｩｪｫｯｬｭｮﾞﾟ｢｣､｡･';
  var i;
  // 定義した半角文字列にない文字が含まれている場合は半角文字列ではないとする
  for (i = 0; i < value.length; i++) {
    if (narrow.indexOf(value.charAt(i)) < 0) {
      return false;
    }
  }
  return true;
}

// 全角文字判定
// 引数  ：value,  I, 判定する文字列
//       ：戻り値, O, true:全角文字列 false:半角文字を含んだ文字列
function isWide(value) {
  var narrow = 'abcdefghijklmnopqrstuvwxyz'
             + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
             + '1234567890'
             + '!"#$%&\'()-=^~\\|@`[{;+:*]},<.>/?_ '
             + 'ｱｲｳｴｵｶｷｸｹｺｻｼｽｾｿﾀﾁﾂﾃﾄﾅﾆﾇﾈﾉﾊﾋﾌﾍﾎﾏﾐﾑﾒﾓﾔﾕﾖﾗﾘﾙﾚﾛﾜｦﾝｧｨｩｪｫｯｬｭｮﾞﾟ｢｣､｡･';
  var i;
  // 定義した半角文字列にある文字が含まれている場合は全角文字列ではないとする
  for (i = 0; i < value.length; i++) {
    if (narrow.indexOf(value.charAt(i)) >= 0) {
      return false;
    }
  }
  return true;
}

// 日付判定
// 引数  ：year,   I, 年
//       ：month,  I, 月
//       ：day,    I, 日
//       ：戻り値, O, true:日付値 false:日付以外
function isDate(year, month, day) {
  // 年を判定する
  year = parseInt(year, 10);
  if (isNaN(year)) {return false;}
  if (year < 100) {return false;}
  // 月を判定する
  month = parseInt(month, 10);
  if (isNaN(month)) {return false;}
  if (month < 1 || month > 12) {return false;}
  // 日を判定する
  day = parseInt(day, 10);
  if (isNaN(day)) {return false;}
  if (day < 1 || day > 31) {return false;}
  // 各月ごとの日を判定する
  if (month == 2) {
    if (day > 29) {return false;}
    if (day == 29 && (year % 4 != 0 || year % 100 == 0 && year % 400 != 0)) {return false;}
  }
  else if (month == 4 || month == 6 || month == 9 || month == 11) {
    if (day > 30) {return false;}
  }
  return true;
}

// 時間判定
// 引数  ：hour,   I, 時
//       ：minute, I, 分
//       ：second, I, 秒
// 戻り値: true:時間値 false:時間以外
function isTime(hour, minute, second) {
  // 時を判定する
  hour = parseInt(hour, 10);
  if (isNaN(hour)) {return false;}
  if (hour < 0 || hour > 23) {return false;}
  // 分を判定する
  minute = parseInt(minute, 10);
  if (isNaN(minute)) {return false;}
  if (minute < 0 || minute > 59) {return false;}
  // 秒を判定する
  second = parseInt(second, 10);
  if (isNaN(second)) {return false;}
  if (second < 0 || second > 59) {return false;}
  return true;

}

// 左スペース除去
// 引数:str
function LTrim(str) {
   var whitespace = new String("　\x20\t\n\r\xa0");
   var s = new String(str);
   if (whitespace.indexOf(s.substr(0, 1)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.substr(j, 1)) != -1)
         j++;
      s = s.substr(j, i);
   }
   return s;
}

// 右スペース除去
// 引数:str
function RTrim(str) {
   var whitespace = new String("　 \t\n\r\xa0");
   var s = new String(str);
   if (whitespace.indexOf(s.substr(s.length-1, 1)) != -1) {
      var i = s.length - 1;
      while (i >= 0 && whitespace.indexOf(s.substr(i, 1)) != -1)
         i--;
      s = s.substr(0, i+1);
   }
   return s;
}

// スペース除去
// 引数:val
function Trim(val) {
  return RTrim(LTrim(val));
}
