//=========================================================================
//  関数名 : ---
//  引数   :
//  解説   :ログ解析用のスクリプト（040330大岡
//=========================================================================

var cc_tagVersion = "1.0";
var cc_accountID = "7380624430";
var cc_marketID =  "4";
var cc_protocol="http";
var cc_subdomain = "convctr";
if(location.protocol == "https:"){
  cc_protocol="https";
  cc_subdomain="convctrs";
}
var cc_queryStr = "?" + "ver=" + cc_tagVersion + "&aID=" + cc_accountID + "&mkt=" + cc_marketID +"&ref=" + escape(document.referrer);
var cc_imageUrl = cc_protocol + "://" + cc_subdomain + ".overture.com/images/cc/cc.gif" + cc_queryStr;
var cc_imageObject = new Image();
cc_imageObject.src = cc_imageUrl;

//=========================================================================
//  関数名 : ログアウト
//  引数   : url ＵＲＬ
//  解説   :
//=========================================================================
function log_out(url) {
  var wnd;
  var x,y;
  x = (screen.width-1024) / 2;
//  y = (screen.width-740) / 2;
  y = 0;
  wnd = window.open(url, "_blank", "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);
  self.window.close();
  wnd.focus();
}

//=========================================================================
//  関数名 : 公開画面に戻る
//  引数   :
//  解説   :
//=========================================================================
function home() {
  var wnd;
  var x,y;
  x = (screen.width-1024) / 2;
//  y = (screen.width-740) / 2;
  y = 0;
  wnd = window.open("../index.asp", "_blank", "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);
  self.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 = (screen.width-740) / 2;
  y = 0;

  //公開されていないページのときはＴＯＰページを表示する
  if(indication_flg != 0){
    wnd = window.open("../index.asp", "_blank", "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, "_blank", "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);
  }
  self.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 , "_blank", "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, "_blank", "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);
  }
  self.window.close();
  wnd.focus();

}
//=========================================================================
//  関数名 : HTML変換（font,em,u,strongは除く）
//  引数   :
//  解説   :
//=========================================================================
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 +([^&gt;]*)&gt;/g,"<FONT $1>");
  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();
}

//=========================================================================
//  関数名 : 操作説明表示
//  引数   :
//  解説   :
//=========================================================================
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, 偽の場合の評価値を指定します。
//         : 戻り値     O, 評価値を返します。
//  解説   : 評価結果によって、2 つの引数のうち 1 つを返す。
//         : 評価式 expr が真の場合は truepart 偽の場合は falsepart
//=========================================================================
function iif(expr, truepart, falsepart){
  if (expr) {
    return truepart;
  }else{
    return falsepart;
  }
}

//=========================================================================
//  関数名 : 「公開する」ボタン押下時
//  引数   :
//  解説   :
//=========================================================================
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";
      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";
        document.mainForm.submit();
      }
    }
  }
}
//=========================================================================
//  関数名 : 公開確認
//  引数   :
//  解説   :
//=========================================================================
function go_public2(cd, no, aspnm, cmt){
//alert("雛形→"+cd);
//alert("ページ→"+no);
//alert("コメント→"+cmt);
//alert("ASP名→"+aspnm);
  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";
//  document.mainForm.action=aspnm+".asp";
  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 のバイト長
// 解説  ：引数 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:数値と判定できない文字列
// 解説  ：引数 value が数値であるかどうかの真偽値を返す
//=========================================================================
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:全角文字を含んだ文字列
// 解説  ：引数 value が半角文字だけであるかどうかの真偽値を返す
//=========================================================================
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:半角文字を含んだ文字列
// 解説  ：引数 value が全角文字だけであるかどうかの真偽値を返す
//=========================================================================
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:日付以外
// 解説  ：引数 year, month, day が正しい日付であるかどうかの真偽値を返す
//=========================================================================
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, 秒
//       ：戻り値, O, true:時間値 false:時間以外
// 解説  ：引数 hour, minute, second が正しい時間であるかどうかの真偽値を返す
//=========================================================================
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));
}
