//-------------------------------------------------------------------------------------
//共通関数
//-------------------------------------------------------------------------------------

/*
 *  メッセージを返す
 */
function fnc_getmsg(){
  return g_msg[Math.floor(Math.random() * g_msg.length)];
}
 

/*
 *  選択ボックスに選択肢を追加
 */
function fnc_addselect( p_cmb, p_value, p_text ){
  p_cmb.length++;
  p_cmb.options[ p_cmb.length - 1].value = p_value ;
  p_cmb.options[ p_cmb.length - 1].text  = p_text;
}

/*
 *  選択ボックスを初期化
 */
function fnc_clearselect( p_cmb){
  p_cmb.length = 0;
}


/*
 *  タグ名から内容を取り出す
 */
function fnc_getElement(p_obj,p_tag){

  var v_elmt = p_obj.getElementsByTagName(p_tag) ;

  if (v_elmt.length == 0) {
    return '';
  }
  
  if (v_elmt[0].firstChild == null){
    return '';
  }

  return v_elmt[0].firstChild.nodeValue ;

}

/*
 *  fromA座標取り出し
 */
function fnc_pointstring(p_point){
  var v_ret = p_point.substr(1,p_point.length - 1);
  return v_ret ;
}

/*
 * 「,」を付加
*/
function addComma(p_value) {
  var v_text = "" + p_value;
  var v_point = v_text.indexOf(".");
  if (v_point < 0) {
    v_point = v_text.length;
  }
  var v_ret = v_text.substring(v_point, v_text.length);
  for (var i = 0; i < v_point; i++) {
    var v_com = v_text.substring(v_point - 1 - i, v_point - 1 - i + 1);
    if (v_com < "0" || v_com > "9") {
      v_ret = v_text.substring(0, v_point - i) + v_ret;
        break;
    }
    if (i > 0 && i % 3 == 0) {
      v_ret = "," + v_ret;
    }
    v_ret = v_com + v_ret;
  }
  return v_ret;
}

/*
 * 数値にﾌｫｰｶｽが入ったとき
*/
function inForcusNumberNoDef(p_textbox,p_len) {

  p_textbox.value = p_textbox.value.replace(/,/g,"");
  p_textbox.maxLength=p_len;

  if (p_textbox.value==""){
    p_textbox.value = " ";
  }

  p_textbox.select();

}

/*
 * 数値からﾌｫｰｶｽがなくなったとき
*/
function outForcusNumberNoDef(p_textbox,p_len) {

  p_textbox.value = delNoNumber(p_textbox.value);

  if (p_textbox.value == ""){
    p_textbox.value = " ";
  }

  p_textbox.value = addComma(p_textbox.value);
  p_textbox.maxLength=p_len;

}

/*
 *数字以外を削除する
*/
function delNoNumber(p_value){
  var v_cnt = 0;
  var v_ret = "";
  for (i=p_value.length-1; i>=0; i--) {
/*
    if (p_value.charAt(i) == '-' && i==0 ){
      v_ret = p_value.charAt(i) + v_ret;
    }
*/
    /*
    if (!isNaN(p_value.charAt(i))){
      v_ret = p_value.charAt(i) + v_ret;
    }
    */
    if (!isNaN(p_value.charAt(i)) && p_value.charAt(i) != ' ' ){
      v_ret = p_value.charAt(i) + v_ret;
    }

  }

  return v_ret ;
}

