﻿var comPopupWin;

//フォームのLoad処理window.attachEvent("onload",com_fncOnLoad);
function com_fncOnLoad() {
    //画面が完全に表示した後に実行する    setTimeout('com_fncOnLoadSub();',0);
}
function com_fncOnLoadSub() {
    //history.forward();
}

//フォームのKeyDown処理document.attachEvent("onkeydown",com_fncOnKeyDown);
function com_fncOnKeyDown() {
    //F5キーを無効にする 2008/10/27 Add
	if (event.keyCode == '116') {
	    event.keyCode = null;
		return false;
	}

	//Enterキーでタブ移動する	if (event.keyCode == '13') {
		//フォーカスがボタンの場合にもEnterキー移動		//if (event.srcElement.tagName.toLowerCase() == 'input') {
		//	if (event.srcElement.type.toLowerCase() == 'submit') {
		//		return true;
		//	}
	    //}
	    if (event.srcElement.tagName.toLowerCase() == 'textarea') {
	        return true;
	    }    
		event.keyCode = 9;
	}
	
	//Backspaceキーを無効にする
	if (event.keyCode == '8') {
		//フォーカスが入力欄の場合はBackspace有効(ボタン以外)
		if (event.srcElement.tagName.toLowerCase() == 'input') {
			if (event.srcElement.type.toLowerCase() != 'submit') {
				return true;
			}
		}
		//フォーカスが入力欄(複数行)の場合はBackspace有効
	    if (event.srcElement.tagName.toLowerCase() == 'textarea') {
			return true;
		}
		return false;   
	}
}

function com_fncShowAlert(pMsg) {
    //画面が完全に表示した後に実行する    setTimeout('com_fncShowAlertSub("' + escape(pMsg) + '");',0);
}
function com_fncShowAlertSub(pMsg) {
    alert(unescape(pMsg));
}

window.attachEvent("onbeforeunload",com_fncOnBeforeUnload);
function com_fncOnBeforeUnload() {
   //ポップアップウィンドウを閉じる
    if (comPopupWin) {
        if (!comPopupWin.closed) {
            comPopupWin.close();  
        }  
    }
}

function com_fncKeyDownClick(pCtrl) {
	if (event.keyCode == 13) {
		pCtrl.click();
		return false;
	}
}

//数値のみであるかチェック
function com_fncIsNumericOnly(pValue) {
    var lString = pValue + '';
    if (lString.match(/[\D]/g)) {
        return false;
    } else {
        return true;
    }
}    

//ウィンドウ内部の幅を取得function com_fncGetClientWidth() {
    //IE標準モード    if (document.documentElement.clientWidth) {
        return document.documentElement.clientWidth;
    }

    //IE互換モード    if (document.body.clientWidth) {
        return document.body.clientWidth;
    }
}

//ウィンドウ内部の高さを取得function com_fncGetClientHeight() {
    //IE標準モード    if (document.documentElement.clientHeight) {
        return document.documentElement.clientHeight;
    }

    //IE互換モード    if (document.body.clientHeight) {
        return document.body.clientHeight;
    }
}

//ウィンドウ内部の幅を取得function com_fncGetScrollWidth() {
    //IE標準モード    if (document.documentElement.scrollWidth) {
        return document.documentElement.scrollWidth;
    }

    //IE互換モード    if (document.body.scrollWidth) {
        return document.body.scrollWidth;
    }
}

//ウィンドウ内部の高さを取得function com_fncGetScrollHeight() {
    //IE標準モード    if (document.documentElement.scrollHeight) {
        return document.documentElement.scrollHeight;
    }

    //IE互換モード    if (document.body.scrollHeight) {
        return document.body.scrollHeight;
    }
}

function com_fncSetValue(pCtrl, pValue) {
    if (pCtrl.tagName.toLowerCase() == 'input') {
        pCtrl.value = pValue;
    } else if (pCtrl.tagName.toLowerCase() == 'span') {
        pCtrl.innerText = pValue;
    }
}

function com_fncEditSize(pPixel) {
    var lStr = '';
    for(var lIdx = 0; lIdx <= pPixel.length - 1; lIdx++) {
        var lChr = pPixel.charAt(lIdx);
        if (com_fncIsNumericOnly(lChr)) {
            lStr = lStr + lChr;
        }
    }
    
    return lStr * 1;
}

function com_fncGetMaxWidth(pId, pOffset) {
    var lCtrl = document.getElementById(pId);
    var lSize = com_fncGetClientWidth() - com_fncEditSize(lCtrl.style.left) - pOffset;
    return lSize + 'px';
}

function com_fncGetMaxHeight(pId, pOffset) {
    var lCtrl = document.getElementById(pId);
    var lSize = com_fncGetClientHeight() - com_fncEditSize(lCtrl.style.top) - pOffset;
    return lSize + 'px';
}

function com_fncSetImage(pUrl) {
    event.srcElement.style.backgroundImage = 'url(' + pUrl + ')'; 
}
