/*
	1. HpbImgFind: Imageオブジェクトを探します  function HpbImgFind(doc, imgName)
    2. HpbImgSwap: 画像を入れ換えます  function HpbImgSwap(imgName, imgSrc)
    3.  カンマ削除関数  function DelComma(val) 
	4.  カンマ挿入関数  function InsComma(val)
	5.  カンマ挿入関数の表示  PrintInsComma(Ins)
    6.  function sum_total(value1,value2,value3)
	7.  固定桁数項目情報取得  function fillString(pstrValue, pintLength, pchrFillChar, pintAlign)
*/

history.forward();

var swImg; swImg=new Array;
// HpbImgPreload: 画像のプリロードを行ないます
function HpbImgPreload()
{
  var appVer=parseInt(navigator.appVersion);
  var isNC=(navigator.userAgent.indexOf('Mozilla') && (appVer >= 4)); // Netscape Navigator 4.0 or later
  var isIE=(navigator.userAgent.indexOf('MSIE')    && (appVer >= 4)); // Internet Explorer  4.0 or later
  if (isNC || isIE)
  {
    if (document.images)
    {
      var imgName = HpbImgPreload.arguments[0];
      var cnt;
      swImg[imgName] = new Array;
      for (cnt = 1; cnt < HpbImgPreload.arguments.length; cnt++)
      {
        swImg[imgName][HpbImgPreload.arguments[cnt]] = new Image();
        swImg[imgName][HpbImgPreload.arguments[cnt]].src = HpbImgPreload.arguments[cnt];
      }
    }
  }
}

// HpbImgFind: Imageオブジェクトを探します
function HpbImgFind(doc, imgName)
{
  for (var i=0; i < doc.layers.length; i++)
  {
    var img = doc.layers[i].document.images[imgName];
    if (!img) img = HpbImgFind(doc.layers[i], imgName);
    if (img) return img;
  }
  return null;
}
// HpbImgSwap: 画像を入れ換えます
function HpbImgSwap(imgName, imgSrc)
{
  var appVer=parseInt(navigator.appVersion);
  var isNC=(navigator.userAgent.indexOf('Mozilla') && (appVer >= 4)); // Netscape Navigator 4.0 or later
  var isIE=(navigator.userAgent.indexOf('MSIE')    && (appVer >= 4)); // Internet Explorer  4.0 or later
  if (isNC || isIE)
  {
    if (document.images)
    {
      var img = document.images[imgName];
      if (!img) img = HpbImgFind(document, imgName);
      if (img) img.src = imgSrc;
    }
  }
}

// カンマ削除関数
function DelComma(val) {
    var reval = val.replace(/,/g,"");
    if(chk_Num(reval)){
        return reval;
    }else{
        return val;
    }
}



// カンマ挿入関数
function InsComma(val) {
    var reval  = '';
    var h_val  = DelComma(val)
    var len    = h_val.length;
    var pmsw   = 0;
    if(!(chk_Num(h_val))){
        return val;
    }
    
    // マイナス時、符号を取り除く
    if(parseInt(h_val,10) < 0){
        pmsw = 1;
        len--;
        h_val = h_val.substr(1,len);
    
    }
    while (len > 3) {
        len   -= 3;
        reval = h_val.substr(len, 3) + (reval != '' ? ',': '') + reval;
    }
    reval = h_val.substr(0, len) + (reval != '' ? ',': '') + reval;
    
    // 値をマイナスに戻す
    if(pmsw){
        reval = "-" + reval;
    }
    
    return reval;
}


/**
 * カンマ挿入関数の表示
 *
 */
function PrintInsComma(Ins) {
    if (Ins != null) {
        document.write(InsComma(String(Ins)));
    }
}


function sum_total(value1,value2,value3){
    if((value1 == "") && (value2 == "") && (value3 == "")){
        return "";
    }
    
    var item1 = DelComma(value1);
    var item2 = DelComma(value2);
    var item3 = DelComma(value3);
    if(!(chk_Num(item1,item2,item3))){
        return "";
    }

    item1 = parseInt(item1);
    item2 = parseInt(item2);
    item3 = parseInt(item3);
    
    var total = (item1 ? item1 : 0) + (item2 ? item2 : 0) + (item3 ? item3 : 0);
    
    return InsComma(String(total));
}


// 固定桁数項目情報取得
// @param pstrValue 処理対象文字列
// @param pintLength 指定された桁数
// @param pchrFillChar fill character（半角スペース，0）
// @param pintAlign 方式(0:左, 1:右)
// @return 処理後の文字列

function fillString(pstrValue, pintLength, pchrFillChar, pintAlign)
{
    if (pstrValue == null) {
        pstrValue = "";
    }
    var len = pstrValue.length;
    var i;
    var fillStr;
    fillStr = pstrValue;
    if (pintAlign == 1) { //右
        for (i = 0; i < pintLength - len; i++) {
            fillStr = pchrFillChar + fillStr
        }
    } else { //左
        for (i = 0; i < pintLength - len; i++) {
            fillStr += pchrFillChar
        }

    }

    return fillStr;
}

// Numericチェック
function chk_Num(){
    // 引数がなければfalseを返す
    if((n = chk_Num.arguments.length) == 0){
        return false;
    }
    for(i = 0;i < n;i++){
        // 最初の一文字目(マイナス対応)
        if(chk_Num.arguments[i] &&
           chk_Num.arguments[i].charAt(0) != '-' &&
           isNaN(parseInt(chk_Num.arguments[i].charAt(0)))){
                return false;
        }
        for(j = 1;j < chk_Num.arguments[i].length;j++){
            if(isNaN(parseInt(chk_Num.arguments[i].charAt(j)))){
                return false;
            }
        }
    }
    return true;
}

// confirmメッセージを表示する
function inputConfirmBack(strUrl) {
    if (confirm("入力された内容は破棄されます。よろしいですか？")) {
      window.location = strUrl;
    }
}

// トップページへ戻る
function topPageBack(strUrl) {
    window.location = strUrl;
}

// H21年定期審査対応機能追加 START
function Interrupt(strUrl) {
	if(confirm("申請処理を中断しますか？\n「中断」するとこれまでに入力した情報が消去されます。\n消去してはじめからやり直す場合は、「OK」をクリック、元に戻る場合は「キャンセル」をクリックしてください。")) {
		
		// トップ画面へ遷移
		topPageBack(strUrl);
	}
	return;
}

function Aligntoright(obj) {
    if (navigator.userAgent.indexOf('MSIE') >= 0) {
        // ieの場合
//        var range = obj.createTextRange();
//        range.moveStart("character",obj.value.length);
//        range.collapse(true);
//        range.select();
//    	obj.dir = "rtl";
    } else if (navigator.userAgent.indexOf('Mozilla') >= 0) {
        // firefoxの場合
    }
}

function Clear (id){
    var uagent =navigator.userAgent;
    if(uagent.indexOf('MSIE') >= 0){
        var newFileInput = id.cloneNode(false);
        newFileInput.onchange = id.onchange; // events are not cloned.
        id.parentNode.replaceChild(newFileInput, id);
    }else if(uagent.indexOf('Mozilla') >= 0){
        id.value="";
    }
 }

// H21年定期審査対応機能追加 END
