/***********************************************
 httpRequest関連
***********************************************/

function httpRequest( target_url, functionReference ){

    var httpObj = init();
    var httpTimerId;
    var httpTimeOutSecDefault = 20; // タイムアウトの秒数
    var httpTimeOutSec = 20; // タイムアウトの秒数

    httpObj.onreadystatechange = function() {
        if ( httpObj.readyState==4 ) {
            clearInterval(httpTimerId);
            if( httpObj.status==200 ) {
                functionReference( httpObj.responseText );
            } else {
                // alert(httpObj.status + ':' + httpObj.statusText);
                return false;
            }
        }
    }

    function init() {
        if(window.ActiveXObject){
            try {
                //MSXML2以降用
                httpObj = new ActiveXObject("Msxml2.XMLHTTP")
            } catch (e) {
                try {
                    //旧MSXML用
                    httpObj = new ActiveXObject("Microsoft.XMLHTTP") //[1]'
                } catch (e2) {
                    httpObj = false;
                }
            }
        } else if(window.XMLHttpRequest){
            //Win ie以外のXMLHttpRequestオブジェクト実装ブラウザ用
            httpObj = new XMLHttpRequest()
        } else {
            httpObj = false;
        }
        
        if (! httpObj) {
            httpObjGenerateFail();
        }

        return httpObj;
    }

    function httpObjGenerateFail() {
        alert('ご利用のブラウザでは、当サイトはご利用いただけません。');
        return false;
    }


    function timeoutCheck() {
        httpTimeOutSec --;
        if ( httpTimeOutSec <= 0 ) {
            clearInterval(httpTimerId);
            httpObj.abort();
            return false;
        }
    }


    this.doGet = function() {
        httpTimeOutSec = httpTimeOutSecDefault;
        httpTimerId = setInterval(timeoutCheck, 1000);
        httpObj.open("GET", target_url, true);
        httpObj.send(null);
    }

    this.doPost = function(body) {
        httpTimeOutSec = httpTimeOutSecDefault;
        httpTimerId = setInterval(timeoutCheck, 1000);
        httpObj.open("POST", target_url, true);
        httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        httpObj.send(body);
    }

}



/***********************************************
 イベント・DOM関連
***********************************************/
function addListener( elem, eventType, func, cap )
{
    if ( elem.addEventListener ) {
        elem.addEventListener( eventType, func, cap );
    } else if ( elem.attachEvent ) {
        elem.attachEvent( 'on' + eventType, func, cap );
    } else {
        alert('ご利用のブラウザでは、当サイトはご利用いただけません。');
        return false;
    }
}



/***********************************************
 画面効果
***********************************************/
var fadeOutTimer;
var fadeInTimer;

function fadeOutWindow(elem, opacityDefault, prev_func, next_func)
{
    var fadeOutOpacity = opacityDefault;
    var board = elem;

    var func_ref = function() {
        fadeOutOpacity = fadeOutOpacity - 10;
        if (fadeOutOpacity <= 0) {
            fadeOutOpacity = 0;
            clearInterval(fadeOutTimer);
            if (next_func) {
                next_func(board);
            }
        }
        board.style.filter = 'Alpha(opacity=' + fadeOutOpacity + ')';
        var non_ie_opacity = fadeOutOpacity / 100;
        board.style.mozOpacity = non_ie_opacity;
        board.style.opacity = non_ie_opacity;
    };

    if (prev_func) {
        prev_func(board);
    }

    fadeOutTimer = setInterval(func_ref, 100);
}

function fadeInWindow(elem, opacityDefault, prev_func, next_func)
{
    var fadeInOpacity = opacityDefault;
    var board = elem;

    var func_ref = function() {
        fadeInOpacity = fadeInOpacity + 10;
        if (fadeInOpacity >= 100) {
            fadeInOpacity = 100;
            clearInterval(fadeInTimer);
            if (next_func) {
                next_func(board);
            }
        }
        board.style.filter = 'alpha(opacity=' + fadeInOpacity + ')';
        var non_ie_opacity = fadeInOpacity / 100;
        board.style.mozOpacity = non_ie_opacity;
        board.style.opacity = non_ie_opacity;
    };

    if (prev_func) {
        prev_func(board);
    }

    fadeInTimer = setInterval(func_ref, 100);
}






