//グローバル変数の定義
var httpObj;               // HTTP通信用オブジェクト
var timerId;               // HTTP通信用タイマーオブジェクト
var timeout_sec = 10;      // HTTP通信タイムアウト秒数
var fadeout_opacity = 70;  // 子ウィンドウの不透明度初期値
var fadeout_timer;  

// 子ウィンドウを閉じる
function closeChildWindow() {
    var board = document.getElementById('board');
    var ua = navigator.userAgent;
    if(ua.indexOf("Opera") >= 0) {
        board.style.visibility = 'hidden';
        return;
    }
    var func_ref = function() {
        fadeout_opacity = fadeout_opacity - 10;
        if(fadeout_opacity <= 0) {
            clearInterval(fadeout_timer);
            board.style.visibility = 'hidden';
            fadeout_opacity = 70;
        }
        board.style.filter = 'alpha(opacity=' + fadeout_opacity + ')';  // Internet Explorer用
        var non_ie_opacity = fadeout_opacity / 100;
        board.style.mozOpacity = non_ie_opacity;              // FireFox用
        board.style.opacity = non_ie_opacity;                 // Safari用
    };
    fadeout_timer = setInterval(func_ref, 100);
}

// 子ウィンドウを開く
function openChildWindow(gid) {
    var board = document.getElementById('board');
    board.style.left = event.clientX + 'px';
    board.style.top = event.clientY + 'px';
    board.style.visibility = 'visible';

    // 透明度を変更する
    board.style.filter = 'alpha(opacity=95)';  // Internet Explorer用
    board.style.mozOpacity = 0.7;              // FireFox用
    board.style.opacity = 0.7;                 // Safari用

    // タイマーをセット
    timerId = setInterval('timeoutCheck()', 1000);
    
    requestStr="";
    requestStr+="&gid="+gid;
    requestStr+="&act=tabelog";
    httpObj = createXMLHttpRequest(displayData);
    if (httpObj){
        httpObj.open("POST",'./bs\_index.php',true);
        httpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        httpObj.send(requestStr);
    }

}
function displayData(){
    if((httpObj.readyState==4)&&(httpObj.status==200)){
        var result = decodeURIComponent(httpObj.responseText);
        var a = result.split(",");
        result = a[0];
        result += '<hr size="1"><p>関連施設</p><ul>';
        for( var i = 1; i< a.length; i++ ){
        	if (a[i]<1){break;}
            result += '<li>施設名:　<a href="./sp_index.php\?act=d&gid='+a[i];
            i++;
            result += '" target="new">'+a[i];
            i++;
            result += '</a><br/>住所:　'+a[i];
            i++;
            result +='<br/>TEL:　'+a[i]+'</li>';
        }
        result += '</ul>';
        document.getElementById('wincontent').innerHTML = '<p>'+result+'</p>';

        // 透明度を変更する
        board.style.filter = 'alpha(opacity=95)';  // Internet Explorer用
        board.style.mozOpacity = 0.7;              // FireFox用
        board.style.opacity = 0.7;                 // Safari用
    }
}

// HTTPタイムアウト処理
function timeoutCheck() {
    timeout_sec --;
    if(timeout_sec <= 0) {
        // タイマーをストップする
        clearInterval(timerId);
        // HTTPリクエストを中断する
        httpObj.abort();
        // エラーダイアログを表示
        //alert('タイムアウトです。');
        return false;
    }
}



function createXMLHttpRequest(cbFunc){
    var XMLhttpObject = null;
    try{
        XMLhttpObject = new XMLHttpRequest();
    }catch(e){
    try{
        XMLhttpObject = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            XMLhttpObject = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(e){
            return null;
        }
    }
}
if (XMLhttpObject) XMLhttpObject.onreadystatechange = cbFunc;
    return XMLhttpObject;
}

