//入力情報破棄制御フラグ
var changeFlg = false;
//DOUBLE CLICK制御フラグ
var doubleClickFlg = false;
//定時変数
var errTimer;

var asciiF5 = 116;  
var asciiF6 = 117;

/**
 * 画面サブミット
 */
function doSubmit(actionmode) {
    document.getElementById("ActionMode").value = actionmode;
    document.forms[0].submit();
}

/**
* 入力情報破棄制御
*
*/
function doChange(flg) {
    if (flg == "change") {
        changeFlg = true;
    }
}


var textarea_maxlen = { isMax: function(objId) {
var textarea = document.getElementById(objId);
    var max_length = textarea.maxLength;
    if (textarea.value.length > max_length) {
        //textarea.value = textarea.value.substring(0, max_length); 
    }
},
    disabledRightMouse: function() { document.oncontextmenu = function() { return false; } },
    enabledRightMouse: function() { document.oncontextmenu = null; }
};

/**
* Httpオブジェクト取得。
*/
function createXmlHttpRequest() {
    var xmlhttp;
    try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) {
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlhttp = new XMLHttpRequest();
            }
            catch (e) { }
        }
    }
    return xmlhttp;
}

/**
* 画面をReflashする。
*/
function Reconnect(url) {
    var xmlhttp = createXmlHttpRequest();
    xmlhttp.open('POST', url, true);
    xmlhttp.send(null);
}

function keyHandler(evt) {    
    var oEvent = window.event || evt;
    var nKeyCode = oEvent.keyCode || oEvent.which;
    var bIsFunctionKey = false;
    if(oEvent.keyCode==asciiF5 || oEvent.keyCode==asciiF6 || (oEvent.ctrlKey && oEvent.keyCode==82)) {
        bIsFunctionKey = oEvent.keyCode;
    }  
    var sChar = String.fromCharCode(nKeyCode).toUpperCase();    
    var oTarget = (oEvent.target) ? oEvent.target : oEvent.srcElement;
    var sTag = oTarget.tagName.toLowerCase();
    var sTagType = oTarget.getAttribute("type");
    var bRet = true;
    if(sTagType != null) {
        sTagType = sTagType.toLowerCase();
    }    
    if(bIsFunctionKey) {
        bRet = false;
    }
    if(!bRet) {
        try {
                oEvent.returnValue = false;    
                oEvent.cancelBubble = true;    
                if(document.all) {
                    oEvent.keyCode   =   0;    
                } else {
                    oEvent.preventDefault();    
                    oEvent.stopPropagation();    
                }    
        } catch(ex) {    
        }    
    }    
    return   bRet;    
}

function showMenu() {
    document.oncontextmenu = function(){return true;}
}

function hideMenu() {
    document.oncontextmenu = function(){return false;}
}

function formatDate(ctlId) {
    var year, month, day;
    var value = document.getElementById(ctlId).value;
    if (value != null && value != "") {
        var md = value.split("/");
        if (md.length == 2) {
            year = new Date().getFullYear();
            month = md[0].length < 2 ? "0" + md[0] : md[0];
            day = md[1].length < 2 ? "0" + md[1] : md[1];
        } else if (md.length == 3) {
            year = new Date().getFullYear();
            year = md[0];
            month = md[1].length < 2 ? "0" + md[1] : md[1];
            day = md[2].length < 2 ? "0" + md[2] : md[2];
        }

        var temp = new Date(year, month - 1, day);
        if (temp != null
                && parseInt(temp.getFullYear(), 10) == parseInt(year, 10)
                && parseInt(temp.getMonth() + 1, 10) == parseInt(month, 10)
                && parseInt(temp.getDate(), 10) == parseInt(day, 10)) {

            value = year + "/" + month + "/" + day;

        } else {
            alert("納品日付の入力が不正です。");
            value = "";
        }
    }

    document.getElementById(ctlId).value = value;
}

function doCancel(msg, btnId) {
    if (confirm(msg)) {
        document.getElementById("ActionMode").value = "CANCEL";
        document.getElementById(btnId).click();
    }

    return true;
}

function getClientOS() {
    var os, uAgent = navigator.userAgent;
    // Windows系
    if (uAgent.match(/Win(dows )?NT 6\.1/)          // Windows 7 の処理
        || uAgent.match(/Win(dows )?NT 6\.0/)       // Windows Vista の処理
        || uAgent.match(/Win(dows )?NT 5\.2/)       // Windows Server 2003 の処理
        || uAgent.match(/Win(dows )?(NT 5\.1|XP)/)  // Windows XP の処理
        || ua.match(/Win(dows)? (9x 4\.90|ME)/)     // Windows ME の処理
        || ua.match(/Win(dows )?(NT 5\.0|2000)/)    // Windows 2000 の処理
        || ua.match(/Win(dows )?98/)                // Windows 98 の処理
        || ua.match(/Win(dows )?NT( 4\.0)?/)        // Windows NT の処理
        || ua.match(/Win(dows )?95/)                // Windows 95 の処理
        
        ) {
        os = "WIN"; 			
    }
    else if (ua.match(/Mac|PPC/)) {
        // Macintosh
        os = "MAC"; 			
    }
    else {
        // UNIX系
        os = "UNIX"	
    }
}

function showSWF(pass, width, height, id) {
    var show = ""
    show += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'"
    show += " codebase='https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'"
    show += " width=" + width
    show += " height=" + height
    show += " title=" + id
    show += " align='middle'>\n"
    show += "<param name='allowScriptAccess' value='sameDomain' />\n"
    show += "<param name='movie' value=" + pass + " />\n"
    show += "<param name='quality' value='high' />\n"
    show += "<param name='scale' value='noscale' />\n"
    show += "<param name='bgcolor' value='#ffffff' />\n"
    show += "<param name='wmode' value='transparent' />\n"
    show += "<embed src=" + pass
    show += " quality='high' scale='noscale' salign='t' bgcolor='#ffffff'"
    show += " width=" + width + " height=" + height
    show += " name=" + id + " align='middle' allowScriptAccess='sameDomain' wmode='transparent'" 
    show += " type='application/x-shockwave-flash' pluginspage='https://www.macromedia.com/go/getflashplayer' />\n"
    show += "<noembed></noembed>\n"
    show += "</object>";
    document.write(show);
}

function sleep(numberMillis) {
    var now = new Date();
    var exitTime = now.getTime() + numberMillis;
    while (true) {
        now = new Date();
        if (now.getTime() > exitTime) return;
    }
}

function wincolse(isConfirm, msg) {
    var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    var s;
    (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
    (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
    (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
    (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
    (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
    
    if(Sys.ie){
        var b_version = navigator.appVersion;
        var version = b_version.split(";");
        var trim_Version = version[1].replace(/[ ]/g, "");
        if(trim_Version == "MSIE6.0") {
            closeie6(isConfirm, msg);
        } else {
            closeie7(isConfirm, msg);
        }
    } else {
        window.close();
    }
}

function closeie6(isConfirm, msg) {
    if (isConfirm) {
        if (confirm(msg)) {
            window.opener = null;
            window.close();
        }
    } else {
        window.opener = null;
        window.close();
    }
}

function closeie7(isConfirm, msg) {
    if (isConfirm) {
        if (confirm(msg)) {
            window.open('', '_top')
            window.top.close();
        }
    } else {
        window.open('', '_top')
        window.top.close();
    }
}

function doAction(id) {
    $(id).click();
}

