function generate(len) {
    validchars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    var txt = '';
    
    while(txt.length < len) {
        random = Math.random() * validchars.length;
        num = Math.floor(random);
        char = validchars.charAt(num);
        txt = txt + char;
    }
    return txt;
}

function AutoPass(f,e) {
    document.forms[f].elements[e].value = generate(8);
}

function OpenWin(url,width,height) {

    Win_w = window.screen.width;
    Win_h = window.screen.height;

    if(width) {
        OpenWin_w = width;
    }
    else {
        OpenWin_w = Win_w / 3 * 2;
    }
    if(height) {
        OpenWin_h = height;
    }
    else {
        OpenWin_h = Win_h / 5 * 4;
    }
    
    OpenWin_x = parseInt(Win_w - OpenWin_w) / 2;
    OpenWin_y = parseInt(Win_h - OpenWin_h) / 2;

    window.open(url,'Win1','width='+OpenWin_w+',height='+OpenWin_h+',scrollbars=yes,resizable=yes,status=no,toolbar=no,left='+OpenWin_x+',top='+OpenWin_y);
}

function SubmitConfirm(num,com,reload) {
    if(confirm(com)) {
        window.document.forms[num].submit();
    }
    if(reload == 1) {
        URL = window.opener.location.href;
        window.opener.location.href = URL;
    }
}

function SubmitReload(num) {
    window.document.forms[num].submit();
    URL = window.opener.location.href;
    window.opener.location.href = URL;
}

function ColorPickUp(num) {
    
    if(navigator.appName == "Microsoft Internet Explorer") {
        window.document.forms[0].elements[num].onmouseup = GetXY_IE;
    }
    else {
        window.document.forms[0].elements[num].onmouseup = GetXY_NotIE;
    }
    
    function GetXY_IE() {
        OpenWin_x = event.screenX;
        OpenWin_y = event.screenY;
        window.open("color.php?num="+(num-1),"cpWin","width=255,height=170,location=no,menubar=no,status=no,toolbar=no,left="+OpenWin_x+",top="+OpenWin_y);
    }
    
    function GetXY_NotIE(evt){
        OpenWin_x = evt.screenX;
        OpenWin_y = evt.screenY;
        window.open("color.php?num="+(num-1),"cpWin","width=255,height=170,location=no,menubar=no,status=no,toolbar=no,left="+OpenWin_x+",top="+OpenWin_y);
    }
}

function ShowLayer(Layer,Top) {
        window.document.getElementById(Layer).style.visibility = "visible";
        window.document.getElementById(Layer).style.top = Top;
        window.document.getElementById(Layer).style.left = 50;
}
function HiddenLayer(Layer) {
    window.document.getElementById(Layer).style.visibility = "hidden";
}



function showHelp(e,name,posX,posY){
    
    var isMSIE = /*@cc_on!@*/false;
    
    if(document.all) e = event;
    
    var objHelpArea = document.getElementById(name);
    objHelpArea.style.display = 'block';
    objHelpArea.style.visibility = 'visible';
    
    // X方向ポジション
    var shiftX = posX;
    
    var posX = e.clientX + shiftX;
    
    objHelpArea.style.left = posX + 'px';
    
    // Y方向ポジション
    var scrollTop = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
    var shiftY = posY;
    
    if(e.clientY < Math.abs(shiftY)) {
        shiftY = -160;
    }
    var posY = e.clientY + scrollTop + shiftY;
    
    objHelpArea.style.top =  posY + 'px';
} 

function hideHelp(name) {
  window.document.getElementById(name).style.visibility = "hidden";
}

