/** ===================================================================
 * BTC基本処理
 * 2006-08-18 ファイル名変更
 * Created by fwtomo
 * Updated by $Author: fwtomo $
 * Copyright (C) BT Company Ltd
 * ==================================================================== */
var actAp = new Array( "&activitytype=10&tradetype=10&businesstype=10&purpose0=10", "&activitytype=10&tradetype=10&businesstype=20&purpose0=10", "&activitytype=10&tradetype=20&purpose0=10", "&activitytype=20&tradetype=10&businesstype=10&purpose0=10", "&activitytype=20&tradetype=10&businesstype=20&purpose0=10", "&activitytype=20&tradetype=20&purpose0=10", "&activitytype=30", "&activitytype=40", "&activitytype=50", "&activitytype=60", "&activitytype=70&tradetype=10&businesstype=10&purpose0=10", "&activitytype=70&tradetype=10&businesstype=20&purpose0=10", "&activitytype=70&tradetype=20&purpose0=10", "&activitytype=80", "&activitytype=90", "&activitytype=100" );
var revCheck = new Array();

function MM_openScheduleWindow(theURL){
    MM_openBrWindow(theURL,'schedule','scrollbars=yes,width=600,height=600');
}
function MM_openReportWindow(theURL){
    MM_openBrWindow(theURL,'report','scrollbars=yes,width=720,height=650');
}
function MM_openAccountWindow(theURL){
    MM_openBrWindow(theURL,'account','scrollbars=yes,width=400,height=650');
}
function MM_openCustomerWindow(theURL){
    MM_openBrWindow(theURL,'customer','scrollbars=yes,width=500,height=550');
}
function MM_openBusinessWindow(theURL){
    MM_openBrWindow(theURL,'business','scrollbars=yes,width=640,height=600');
}
function MM_openHistoryWindow(theURL){
    MM_openBrWindow(theURL,'history','scrollbars=yes,width=500,height=550');
}
function MM_openComHistoryWindow(theURL){
    MM_openBrWindow(theURL,'comhistory','scrollbars=yes,width=500,height=600');
}
function MM_openUserWindow(theURL){
    MM_openBrWindow(theURL,'user','scrollbars=yes,width=500,height=400');
}
function MM_openCycleWindow(theURL){
    MM_openBrWindow(theURL,'cycle','scrollbars=yes,width=500,height=500');
}
function MM_openEnvironmentWindow(theURL){
    MM_openBrWindow(theURL,'user','scrollbars=yes,width=500,height=600');
}
function MM_openSelectWindow(theURL,name,width,height){
    var opt = 'scrollbars=yes,width=' + width + ',height=' + height;
    MM_openBrWindow(theURL,name,opt);
}
function MM_openBusinessSelectWindow(theURL){
    var params = new Array(
            document.getElementById( "decisionyear" ),
            document.getElementById( "decisionmonth" ),
            document.getElementById( "decisionday" )
    );
    var param = "";
    for( var i=0; i<params.length; i++ ){
        param = joinPrameter( param, params[i] );
    }
    MM_openBrWindow(theURL+'&'+param,'bussel','scrollbars=yes,width=600,height=600');
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
    var addParam = getCParam( adUprm );
    var wo1;
    wo1=window.open(theURL+addParam,winName,features+",status=yes");
    wo1.focus();
}
function MM_openWindowActFix(theURL,openType,no) {
    if( no < 0 ){
        addparam = '';
    }else{
        addparam = actAp[no];
    }
    MM_openBrWindowSp(theURL+"&regist=y",'schedule','scrollbars=yes,width=600,height=600',addparam,openType);
}
function MM_openBrWindowSp(theURL,winName,features,addparam,openType) { //v2.0
    var addParam = getCParam( adUprm );
    if( openType == "other" ){
        var wo1;
        wo1=window.open(theURL+addParam+addparam,winName,features+",status=yes");
        wo1.focus();
    }else{
        window.location.replace( theURL+addParam+addparam );
    }
}

function MM_openHelpWindow(theURL) { //v2.0
    MM_openBrWindow("view.php?adj=1&url="+theURL,"help","scrollbars=yes,width=600,height=400");
}

function getCParam( param ){
    if( document.cookie ){
        var cookies = document.cookie.split( "; " );
        for( var i=0; i<cookies.length; i++ ){
            var str = cookies[i].split( "=" );
            if( !isEmpty( param ) && ( str[0] == param ) ){
                return( "&" + unescape( cookies[i] ) );
            }
        }
    }
}

//Btc 処理関数
function send( fm ){
    fm.csbt.value = "changed";
    fm.submit();
}

function pageRequest( param ){
    parent.location.href = "./?" + param;
}

function mypageSend( fm, param, val ){
    param.value = val;
    fm.submit();
}

function mypageRequest( param ){
    location.href = "?" + param;
}

function popWindow( winName, url ){
    win = window.open( url, winName );
    win.focus();
}

function checkSubmit( fm, button, needName ){
    var add = "";
    if( needName ){
        add = getCheckNameData();
        if( isEmpty( add ) ){
            alert( '項目が選択されていません' );
            button.blur();
            return false;
        }
    }
    return true;
}

function checkCommit( fm, button, needName ){
	var add = "";
    if( needName ){
        add = getCheckNameData();
        if( isEmpty( add ) ){
            alert( '項目が選択されていません' );
            return false;
        }
    }
    //フォーム送信時のチェック
    if( confirm( add + '本当に削除していいですか？' ) ){
        button.value = "削　除";
        fm.submit();
    }else{
        alert( '削除処理をキャンセルしました' );
        return false;
    }
}
function checkCommitLink( url, needName, cb ){
    var add = "";
    if( needName ){
        add = getCheckNameData();
        if( isEmpty( add ) ){
            alert( '項目が選択されていません' );
            return false;
        }
    }
    if( confirm( add + '本当に削除していいですか？' ) ){
        if( isEmpty( cb ) ){
            location.href = url;
        }else{
            cb( url, checkCommitLink.arguments[2], checkCommitLink.arguments[3], checkCommitLink.arguments[4], checkCommitLink.arguments[5], checkCommitLink.arguments[6] );
        }
        return true;
    }else{
        alert( '削除処理をキャンセルしました' );
        return false;
    }
}

function popupClose(){
    if( window.opener.fm ){
        if( window.opener.fm.srch ){
            window.opener.fm.srch.click();
        }else{
            window.opener.fm.submit();
        }
    }else{
        window.opener.document.location = window.opener.document.URL;
    }
    window.close();
}

function selectOption( selectName ){
    document.fm.ajax.value = selectName;
    document.fm.submit();
}

function isEmpty( variable ){
    if( ( variable == undefined ) || ( variable == null ) || ( variable == "" ) ){
        return true;
    }
    return false;
}

function commitLink( url ){
    location.href = url;
}

function joinPrameter( paramStr, obj ){
    if( isEmpty( obj ) ){
        return paramStr;
    }
    if( paramStr != "" ){
        paramStr += "&";
    }
    paramStr += obj.name + "=" + obj.value;
    return paramStr;
}

function getMyElement( id ){
    return document.getElementById( id );
}

function getOpnerElement( id ){
    return window.opener.document.getElementById( id );
}

function getDomElement( id, flag ){
    if( flag == "p" ){
        return getOpnerElement( id );
    }else{
        return getMyElement( id );
    }
}

function setZeroStr( num, max ){
    var ret = "";
    var mod = num;
    var work;
    var base;
    for( var i=max-1; 0<=i; i-- ){
        base = Math.pow( 10, i );
        work = parseInt( mod / base );
        ret += String( work );
        mod -= base * work;
    }
    return ret;
}

function lineOver( id ){
    setLineColor( id, "selectBody" );
}

function lineOut( id, color ){
    setLineColor( id, color );
}

function setLineColor( id, color ){
    var contents = getMyElement( id );
    contents.className = color;
}

function reverseCheckBox( id ){
    var element = getMyElement( id );
    if( element ){
        element.click();
    }
}

function reverseCheckBoxWithName( id, name ){
    return clickReverseCheckBoxWithName( id, name, true );
}

function clickReverseCheckBoxWithName( id, name, needClick ){
    var element = getMyElement( id );
    if( element ){
        if( needClick ){
            element.click();
        }
        if( element.checked ){
            for( var i=0; i<revCheck.length; i++ ){
                if( revCheck[i] == name ){
                    return;
                }
            }
            revCheck.push( name );
        }else{
            var newArray = Array();
            for( var i=0; i<revCheck.length; i++ ){
                if( revCheck[i] == name ){
                    continue;
                }
                newArray.push( revCheck[i] );
            }
            revCheck = newArray;
        }
    }
}

function getCheckNameData(){
	var ret = "";
	for( var i=0; i<revCheck.length; i++ ){
		ret += "「" + revCheck[i] + "」\n";
	}
	if( ret != "" ){
		ret += "\n";
	}
	return ret;
}


;
