/* Checkbox - All Check機能 */
function checkUnCheck(chk, chkAll) {
	if(chk.length > 1) {
		for (i = 0; i < chk.length; i++)
			chk[i].checked = chkAll.checked;
	} else {
		chk.checked = chkAll.checked;
	}
}

/* 試用設定を除いた全選択 Checkbox - All Check機能 */
function NoTry_checkUnCheck(chk, chkAll) {
	if(chk.length > 1) {
		for (i = 0; i < chk.length; i++)
			if(!chk[i].disabled) {
				chk[i].checked = chkAll.checked;
			}
	} else {
		if(!chk.disabled) {
			chk.checked = chkAll.checked;
		}
	}
}

function Watch(form) {
    now = new Date();
    year = now.getYear();
    month = now.getMonth()+1;
    day = now.getDate();
    hour = now.getHours();
    minute = now.getMinutes();
    second = now.getSeconds();
    if (year < 1000) { year += 1900}
    if (hour < 10) { hour = '0' + hour}
    if (minute < 10) { minute = '0' + minute}
    if (second < 10) { second = '0' + second}
    form.time.value = hour + ':' + minute;
	setTimeout("Watch(" + form + ")",1000);
}

/* ヘルプ表示 */
var iframe;
function showHelpBox()
{
	var helpbox = document.getElementById('helpBox');
	if(!!helpbox) {
		if (helpbox.className == "dispNone") {
			helpbox.className = "";
		} else {
			helpbox.className = "dispNone";
		}
		/*if (helpbox.style.display == 'none')
			helpbox.style.display = 'block';
		else
			helpbox.style.display = 'none';*/
	}

	/*ヘルプボックスの高さ取得
	var helpDivObj = ibodyframe.document.getElementById('helpBox');
	var helpHeight = helpDivObj.clientHeight;
	iframe = document.getElementsByTagName("IFRAME")[0];
	var height = iframe.style.height;
	height = height.substr(0, height.length - 2)
	iframe.style.height = eval(height) + eval(helpHeight) + "px";
	*/
}

/* iFrameの自動サイズ調整機能-onloadにより使用 */
function fixFrameSize() {
	var body = document.body;

	if (window.parent) {
		var width = body.scrollWidth;
		var height = body.scrollHeight;
		iframe = window.parent.document.getElementsByTagName("IFRAME")[0];
		//iframe.style.width = width;

		iframe.style.height = height + 50 + "px";

		iframe.scrolling = "no";
	}
}

/* 数字のみ、英単語のみ入力*/
function pressedChar(event) {
	var code = 0;
	if (event.charCode === 0) {	// Firefox, Safari control code
		code = 0;
	} else if (!event.keyCode && event.charCode) {	// Firefox
		code = event.charCode;
	} else if (event.keyCode && !event.charCode) {	// IE
		code = event.keyCode;
	} else if (event.keyCode == event.charCode) {	// Safari
		code = event.keyCode;
	}
	if (32 <= code && code <= 126) {	// ASCII文字の範囲内
		return String.fromCharCode(code);
	} else {
		return null;
	}
}
function numberonly(event) {
	var char = pressedChar(event);
	if (char && !char.match(/\d/)) {
		return false;
	} else {
		return true;
	}
}
function wordonly(event) {
	var char = pressedChar(event);
	if (char && !char.match(/\w/)) {
		return false;
	} else {
		return true;
	}
}

function goPage(target) {
	location.href=target;
}

function isTelnum(text) {
    if (text.match(/^[0-9#*]+$/) || text == "") {
        return true;
    } else {
        return false;
    }
}
function isNum(text) {
    if (text.match(/^[0-9]+$/) || text == "") {
        return true;
    } else {
        return false;
    }
}

// 2010.09.24 ikeya
// メールアドレスに使用できない文字のチェック
function isAlphaNum(text) {
	if(text.match(/^[0-9,a-z,A-Z,_,\.,-,@]+$/)) return true;
	return false;
}

/****************************************************************
* 機　能： 入力された値が日付でYYYY-MM-DD形式になっているか調べる
* 引　数： datestr　入力された値
* 戻り値： 正：true　不正：false
****************************************************************/
function ckDate(datestr){
	// 正規表現による書式チェック
	if(!datestr.match(/^\d{4}\-\d{2}\-\d{2}$/)){
	    return false;
	}
	var vYear = datestr.substr(0, 4) - 0;
	var vMonth = datestr.substr(5, 2) - 1; //Javascriptは、0-11で表現
	var vDay = datestr.substr(8, 2) - 0;
	// 月,日の妥当性チェック
	if(vMonth >= 0 && vMonth <= 11 && vDay >= 1 && vDay <= 31){
		var vDt = new Date(vYear, vMonth, vDay);
		if(isNaN(vDt)){
			return false;
        }else if(vDt.getFullYear() == vYear && vDt.getMonth() == vMonth && vDt.getDate() == vDay){
            return true;
        }else{
            return false;
        }
    }else{
        return false;
    }
}

function num3Format(str){
	var temp1 = (new String(str)).split(".")[0].match(/./g).reverse().join("");
	temp1 = temp1.replace(/(\d{3})/g,"$1,");
	temp1 = temp1.match(/./g).reverse().join("").replace(/^,/,"");
	if(!!(new String(str)).split(".")[1]) temp1 = temp1 +"."+ str.split(".")[1];
	return temp1;
}

String.prototype.trim = function() {
	return this.replace(/^[ ]+|[ ]+$|^[　]+|[　]+$/g, '');
};

/**
 * 全角であるかをチェック
 *
 * @param チェックする値
 * @return 1 : 全角 / 0 : 全角以外
 * @author 小阪 <s.kosaka@widetec.com>
 */
function chkIsFullwidth(value) {
  for (var i = 0; i < value.length; ++i) {
    var c = value.charCodeAt(i);
    if(value == "\n" || value == " " || value == "\r") // Space, 改行は無効
    	return 2;
    //  半角カタカナは不許可
    if (c < 256 || (c >= 0xff61 && c <= 0xff9f)) {
    	return 0;
    }
  }
  return 1;
}

/**
 * 文字列のバイト数を取得
 * 全角を2バイト、半角を1バイトとしてカウントします。
 *
 * @param バイトを取得する値
 * @return 取得したバイト数
 * @author 小阪 <s.kosaka@widetec.com>
 */
function getByteOfString(value) {
  var count = 0;
  var rtn = -1;
  for ( var i = 0; i < value.length; ++i ) {
    var sub = value.substring(i, i + 1);
    if( sub != " ") {
    	rtn = chkIsFullwidth(sub);
	    //全角の場合２バイト追加。
	    if( rtn == 1 ){ //全額
	    	count += 2;
	  	} else if( rtn == 0) {
	  		count += 1;
	    }
    }
  }
  return count;
}

//2010.09.02 ikeya
// 機種依存文字のチェック追加
/**
 * 文字列に機種依存文字が含まれているかチェック
 *
 * @param チェックする文字列
 * @return true:なし false:あり
 * @author 池谷 智美 <t.ikeya@widetec.com>
 */
function isErrWordCheck(entry) {
    var result;
    result = entry.match(/[;^<>\\%+'\"|ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹ∟∮⊿①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳〝〟㈱㈲㈹㊤㊥㊦㊧㊨㌃㌔㌘㌢㌣㌦㌧㌫㌶㍉㍊㍍㍑㍗㌍㌻㍻㍼㍽㍾㎎㎏㎜㎝㎞㎡㏄№㏍℡￤]+/);
    if(result) {
        return false; 
    } else {
    	return true;
    }
}
