var SEARCH_PARAM = "";//検索条件パラメータ

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function createXMLHttpRequest () {
    var XMLHttpObject = null;
    try {
        XMLHttpObject = new XMLHttpRequest ();
    } catch (e) {
        try {
            XMLHttpObject = new ActiveXObject ("Msxm12.XMLHTTP");
        } catch (e) {
            try {
                XMLHttpObject = new ActiveXObject ("Microsoft.XMLHTTP");
            } catch (e) {
                return null;
            }
        }
    }
    return XMLHttpObject;
}


var flagRyokinDetail = new Array(false, false, false);
var optionStr = '';
var resultStr = '';
var hilightStr = '';
var tokaiBanner = '';
var intelligentMsg = '';

var autoEtcListinerUrlStr = new Array('','','');
var autoEtcResultSum = new Array('','','');
var autoEtcResultSumOld = new Array('','','');
var autoEtcResultDetail = new Array('','','');
var jointedRouteStr = new Array('','','');
var sapaTotalCount = new Array('','','');
var underRoad = new Array('','','');
var flagSyakai1010010 = new Array('','','');
var specialCautionMsg = "";

function showInit () {
	tokaiBanner = '';
	intelligentMsg = '';
    var gif = "dc_loading_" + (Math.ceil(Math.random() * 4) || 1) + ".gif";
    document.getElementById('outOption').innerHTML = '<table><tr><td class=title>'
    + (location.hostname == "dc.kousokubiyori.jp" ? '<img src="http://support.kousokubiyori.jp/sys/util.ConditionLog' + SEARCH_PARAM + '&url=' + location.pathname + '" style="display:none;">' : '')
    + '</td><td></td></tr></table>';
    document.getElementById('outHilight').innerHTML = '<table style="width: 100%"><tr><td style="text-align: center;"></td></tr></table>';
    document.getElementById('outResult').innerHTML = '<div class="searchResult"><table class="searchResultTitle" width="100%"><tr><td></td></tr></table><table class="searchResultCase" width="100%"><tr><td style="text-align: center;"><img src="/dc/dc_images/' + gif + '"></td></tr></table>';
}

function showOption () {
    var xmlhttp = createXMLHttpRequest ();
    if (xmlhttp) {
		xmlhttp.open ("get", '/sys/lb/ajaxCommunicator.SearchOptionListener' + SEARCH_PARAM, true);
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById('outOption').innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.send (null);
    }
}


function showResult (url) {
    var xmlhttp = createXMLHttpRequest ();
    if (xmlhttp) {
        if(url != undefined && url.length > 0){
            xmlhttp.open ("get", url, true);
        }else{
            xmlhttp.open ("get", '/sys/lb/ajaxCommunicator.IcRouteSearchListener' + SEARCH_PARAM + '&detail=true', true);
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                //optionStr = xmlhttp.responseText.substring(xmlhttp.responseText.indexOf('<OPTION>') + 8, xmlhttp.responseText.indexOf('</OPTION>'));
                resultStr = xmlhttp.responseText.substring(xmlhttp.responseText.indexOf('<RESULT>') + 8, xmlhttp.responseText.indexOf('</RESULT>'));
                hilightStr = xmlhttp.responseText.substring(xmlhttp.responseText.indexOf('<HILIGHT>') + 9, xmlhttp.responseText.indexOf('</HILIGHT>'));
                //tokaiBanner = xmlhttp.responseText.substring(xmlhttp.responseText.indexOf('<BANNER_TOKAI>') + 14, xmlhttp.responseText.indexOf('</BANNER_TOKAI>'));
				if (xmlhttp.responseText.indexOf('<!--INTELLIGENT') != -1) {
	                intelligentMsg = xmlhttp.responseText.substring(xmlhttp.responseText.indexOf('<!--INTELLIGENT') + 15, xmlhttp.responseText.indexOf('/INTELLIGENT-->'));
				}
				for(var i = 0;i < 3;i++){
	                autoEtcListinerUrlStr [i] = xmlhttp.responseText.substring(xmlhttp.responseText.indexOf('<AUTO_ETC' + i + '>') + 11, xmlhttp.responseText.indexOf('</AUTO_ETC' + i + '>'));
	                jointedRouteStr [i] = xmlhttp.responseText.substring(xmlhttp.responseText.indexOf('<!--JOINTED_ROUTE_' + i + '-->') + 22, xmlhttp.responseText.indexOf('<!--/JOINTED_ROUTE_' + i + '-->'));
				}
				
                //document.getElementById('outOption').innerHTML = optionStr;
                document.getElementById('outHilight').innerHTML = hilightStr;
                document.getElementById('outResult').innerHTML = resultStr;

                //--20080821start
                for(var j = 0; j < 3; j++){
                    getAutoEtcResult (j);
                }
                //--20080821end

                showSpecialCaution();

                if (document.getElementById('campaign')) {
                    document.getElementById('campaign').style.display = 'block';
                    autoCloseCampaign ();
                }
            }
        }
        xmlhttp.send (null);
    }
}


function getAutoEtcResult (index) {
    if (autoEtcListinerUrlStr [index].indexOf('null') == -1) {
        var xmlhttp2 = createXMLHttpRequest ();
        if (xmlhttp2) {
            xmlhttp2.open ("get", autoEtcListinerUrlStr [index], true);
            xmlhttp2.onreadystatechange = function () {
                if (xmlhttp2.readyState == 4 && xmlhttp2.status == 200) {
                    autoEtcResultDetail [index] = xmlhttp2.responseText;
					document.getElementById('RyokinDetail_' + index).innerHTML = autoEtcResultDetail [index];
                    autoEtcResultSum [index] = autoEtcResultDetail [index].substring(autoEtcResultDetail [index].indexOf('<!--EtcSUM') + 10, autoEtcResultDetail [index].indexOf('/EtcSUM-->'));
                    document.getElementById('RyokinEtcSum_' + index).innerHTML = autoEtcResultSum [index];
                    autoEtcResultSumOld [index] = autoEtcResultDetail [index].substring(autoEtcResultDetail [index].indexOf('<!--EtcSUMOld') + 13, autoEtcResultDetail [index].indexOf('/EtcSUMOld-->'));
                    //document.getElementById('RyokinEtcSumOld_' + index).innerHTML = autoEtcResultSumOld [index];
                    sapaTotalCount [index] = autoEtcResultDetail [index].substring(autoEtcResultDetail [index].indexOf('<!--SAPATOTALCOUNT') + 18, autoEtcResultDetail [index].indexOf('/SAPATOTALCOUNT-->'));
                    document.getElementById('SapaTotalCount_' + index).innerHTML = sapaTotalCount [index];
                    underRoad [index] = autoEtcResultDetail [index].substring(autoEtcResultDetail [index].indexOf('<!--UNDERROAD') + 13, autoEtcResultDetail [index].indexOf('/UNDERROAD-->'));
                    //--仙台道注意書
                    if(xmlhttp2.responseText.indexOf('<!--INCLUDE_SENDAI-->') > -1){showSpecialCaution('includeSendai');}
                    //--八王子注意書                    
                    if(xmlhttp2.responseText.indexOf('<!--INCLUDE_HACHIOUJI-->') > -1){showSpecialCaution('includeHachiouji');}
                    
					if(autoEtcResultDetail [index].substring(autoEtcResultDetail [index].indexOf('<!--CAUTION_SYAKAI1010010') + 25, autoEtcResultDetail [index].indexOf('/CAUTION_SYAKAI1010010-->')) == 'true'
                        && document.getElementById('syakai1010010').innerHTML.length == 0){
                        document.getElementById('syakai1010010').innerHTML = '<div class="outLine">【東名上り線　東京料金所での深夜割引の拡大について】</div>ご利用時は30％割引の料金が表示されますが、ご請求時には50％割引の料金にて請求させていただきます。<br /><br />';
                        document.getElementById('hrefEdit').href = document.getElementById('hrefEdit').href.substring(0, document.getElementById('hrefEdit').href.indexOf('?highlightList=') + 15)
                            + ',syakai1010010,'
                            + document.getElementById('hrefEdit').href.substring(document.getElementById('hrefEdit').href.indexOf('?highlightList=') + 15);
                    }
					document.getElementById('JointedRoute_' + index).innerHTML = jointedRouteStr [index];
					document.getElementById('UnderRoad_' + index).innerHTML = underRoad [index];
                }
				//if (index == 0) {
				//	showAutoEtc (0);
				//}
            }
            xmlhttp2.send (null);
        }
    }
}


function showSpecialCaution () {
	showSpecialCaution(param);
}
function showSpecialCaution (param) {
//ここから変更します---------------------------------------------------------
    var qr = SEARCH_PARAM;
//ここまで変更しました-------------------------------------------------------
    var sic = qr.substring(qr.indexOf("s_rd_cd=") + 8, qr.indexOf("s_rd_cd=") + 12) + qr.substring(qr.indexOf("s_ic_cd=") + 8, qr.indexOf("s_ic_cd=") + 11);
    var eic = qr.substring(qr.indexOf("e_rd_cd=") + 8, qr.indexOf("e_rd_cd=") + 12) + qr.substring(qr.indexOf("e_ic_cd=") + 8, qr.indexOf("e_ic_cd=") + 11);
    var year = qr.substring(qr.indexOf("optYr=") + 6, qr.indexOf("optYr=") + 10);
    var month = qr.substring(qr.indexOf("optMnth=") + 8, qr.indexOf("optMnth=") + 10).replace("&", "");//桁無し
    var day = qr.substring(qr.indexOf("optDyOfMnth=") + 12, qr.indexOf("optDyOfMnth=") + 14).replace("&", "");//桁無し
    var hour = qr.substring(qr.indexOf("optHr=") + 6, qr.indexOf("optHr=") + 8).replace("&", "");//桁無し
    var minute = qr.substring(qr.indexOf("optMnt=") + 7, qr.indexOf("optMnt=") + 9).replace("&", "");//桁無し
    var msg = "";
    
    //インテリジェント
   	if(intelligentMsg.length > 0) {
        msg += "<div>" + intelligentMsg + "</div>";
     }    
    //関空
    if (sic=="2949090" || eic=="2949090") {
        msg += "<div>関空連絡橋の通行料金は往復の金額です。</div>";
    }
    //飛騨河合PA
    if (sic=="1830096" || eic=="1830096"){
        msg += "<div>飛騨河合PAスマートICは社会実験終了に伴い、2008年11月30日（日）21時にて閉鎖いたします。</div>";
    }    
    //日光宇都宮道路
    if (sic.indexOf("210A")==0 || eic.indexOf("210A")==0) {
        msg += "<div>日光宇都宮道路は、閑散期（12月〜4月）では通行料金が異なります。<br />詳しくは<a href=\"http://www.totidoko.or.jp/ryoukin/index.html\" target=\"_brank\">栃木県道路公社のホームページ</a>でご確認ください。</div>";
    }
    //仙台南・仙台松島
    	if(param == 'includeSendai'){
        msg += "<div>仙台南部道路、仙台松島道路は「休日特別割引」が適用されない区間です。<br />そのため、上限1,000円とは別に通行料金が必要となります。<br />ドライブコンパスでは、当該区間の料金を「大都市部」に表示しております。</div>";
     }
    //八王子通行止め
    	if(param == 'includeHachiouji'){
        msg += "<div>2/16（火）夜18時から翌朝6時まで中央道夜間通行止が実施されます。詳しくは<a href=\"http://dc.kousokubiyori.jp/dc/info/100209chuo.html\" target=\"_blank\">こちら</a>でご確認ください。<!--"+sic+eic+year+month+day+hour+minute+"--></div>";
     }
    //東九州道
    if (sic=="1302140" || eic=="1302140" || sic=="1302150" || eic=="1302150"){
        msg += "<div>東九州自動車道　西都IC〜宮崎西IC間は、9月24日 9時から11月22日 9時までの間、道路改良工事のため通行止めとなります。</div>";
    }
    //東名富士川SA
    if (sic=="1010105" || eic=="1010105"){
        msg += "<div>富士川SAスマートICは、1月18日0時から3月18日15時までの間、改良工事のため閉鎖となります。<br />3月18日15時再開により名古屋方面入り口も開通し、全方向でご利用が可能になります。</div>";
    }
    //北陸南条SA
    if (sic=="1080345" || eic=="1080345"){
        msg += "<div>南条SAスマートICの敦賀方面出入口は、3月28日(日) 午前6時開通となります。</div>";
    }
    
    //北陸道（東海北陸開通記念割引対応）
    var sIcKanazawa = false;
    var eIcKanazawa = false;
    if (sIcKanazawa || eIcKanazawa) {
        if ((sIcKanazawa && (
        (eic.indexOf("1830")==0 && eic <= "1830095") || (eic.indexOf("1011")==0 && eic <= "1011300") || (eic.indexOf("1010")==0 && eic >= "1010220") || (eic.indexOf("1101")==0 && eic >= "1101215") || (eic=="1900330") || eic.indexOf("224D")==0
        )) || (eIcKanazawa &&(
        (sic.indexOf("1830")==0 && sic <= "1830095") || (sic.indexOf("1011")==0 && sic <= "1011300") || (sic.indexOf("1010")==0 && sic >= "1010220") || (sic.indexOf("1101")==0 && sic >= "1101215") || (sic=="1900330") || sic.indexOf("224D")==0
        ))) {
            msg += "<div>本検索では通常料金及びETC割引適用料金ともに東海北陸道全線開通記念割引料金をご案内しています。<br />但し、米原JCT経由のルートでは本検索結果にかかわらず、東海北陸道全線開通記念割引の対象外となり、割引適用の無い料金が課金されますのでご注意ください。</div>";
        }
    }
    if (msg.length > 0 && msg != specialCautionMsg && document.getElementById("specialCaution") != null) {
        document.getElementById("specialCaution").style.visibility = "visible";
        document.getElementById("specialCautionMsg").innerHTML = msg;
		specialCautionMsg = msg;
    }
}


function hiddenUnderRoad(){
    document.getElementById('underRoad').innerHTML='';
}

function showHideAutoEtc (index) {

    if (flagRyokinDetail [index]) {
        hideAutoEtc (index);
        document.getElementById('RyokinDetail_' + index).className = '';
    } else {
        showAutoEtc (index);
        document.getElementById('RyokinDetail_' + index).className = 'detail';
    }
}
 

function hideAutoEtc (index) {
//    document.getElementById('RyokinDetail_' + index).innerHTML = '';
    document.getElementById('JointedRoute_' + index).style.display = 'block';
    document.getElementById('UnderRoad_' + index).style.display = 'none';
    flagRyokinDetail [index] = false;
	document.getElementById('sw_' + index).innerHTML='<a href="Javascript:void (0);showAutoEtc (' + index + ');" class="btnOpen"></a>';
    document.getElementById('RyokinDetail_' + index).style.display = 'none';
	if(index > 0)
		document.getElementById('textNone_' + index).style.display='none';        
}

        
function showAutoEtc (index) {
	
    flagRyokinDetail [index] = true;
//    document.getElementById('RyokinDetail_' + index).innerHTML = autoEtcResultDetail [index];
    document.getElementById('JointedRoute_' + index).style.display = 'none';
    document.getElementById('UnderRoad_' + index).style.display = 'block';
	document.getElementById('sw_' + index).innerHTML='<a href="Javascript:void (0);hideAutoEtc (' + index + ');" class="btnClose"></a>';
    document.getElementById('RyokinDetail_' + index).style.display = 'inline';
	if(index > 0)
	    document.getElementById('textNone_' + index).style.display='block';        
}

function openWindow(url){
    window.name = 'opener';var cautionWindow = window.open(url, 'cautionWindow', 'width=900px, height=900px,scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,location=yes,status=yes,scrollbars=yes');cautionWindow.focus ();
}
function openPrintWindow(url){
    window.name = 'opener';var printWindow = window.open(url, 'printWindow', 'width=680px,height=400px,scrollbars=yes,resizable=yes,menubar=yes,toolbar=no,scrollbars=yes');printWindow.focus ();
}
var miniWinId = '';
function showMiniWin(_id, event) {
    if (miniWinId.length > 0 && document.getElementById(miniWinId))
        document.getElementById(miniWinId).style.display = 'none';
    document.getElementById(_id).style.display = 'block';
    miniWinId = _id;
}
function hideMiniWin(_id, event) {
    if (event == undefined)
        return;
    var r = event.relatedTarget || event.toElement;
    if (!document.getElementById(_id) || r.id != _id)
        document.getElementById(_id).style.display = 'none';
}
function hideMiniWinSelf(div, event) {
    var r = event.relatedTarget || event.toElement;
    if (r && !contains (r, div))
        div.style.display = 'none';
}
function contains (node, parentNode) {
    while (node && node != parentNode)
        node = node.parentNode;
    return Boolean (node);
}

function printPage () {
    if (navigator.userAgent.indexOf('MSIE')!=-1) {
        if (confirm('「インターネットオプション」−＞「詳細設定」−＞「背景の色とイメージを印刷する」を選択すると、より見易い印刷が可能です。\n設定を変更せずに、印刷を開始しますか？')) {
            window.print();
			alert('画面右上「・・・必ずお読みください」は別ウィンドウを開いて印刷してください。');
        }
    } else {
        window.print();
		alert('画面右上「・・・必ずお読みください」は別ウィンドウを開いて印刷してください。');
    }
    void(0);
}
function printPage2 () {
    if (navigator.userAgent.indexOf('MSIE')!=-1) {
        if (confirm('「インターネットオプション」−＞「詳細設定」−＞「背景の色とイメージを印刷する」を選択すると、より見易い印刷が可能です。\n設定を変更せずに、印刷を開始しますか？')) {
            window.print();
        }
    } else {
        window.print();
    }
    void(0);
}


var timer;
var campaignCnt = -1;
function autoCloseCampaign () {
    campaignCnt ++;
    if (campaignCnt == 0) {
        timer = setInterval("autoCloseCampaign()",3000);
    } else {
        clearInterval(timer);
        if (campaignCnt <= 1 && navigator.userAgent.indexOf('MSIE') != -1) {
            Transition (2);
            setInterval("void(0)",200);
        } else {
            document.getElementById('campaign').style.display='none';
        }
    }
    //alert(campaignCnt);
}
function Transition(pattern) {
    document.getElementById('campaign').style.visibility = 'visible';
    document.getElementById('campaign').style.filter = "revealTrans(duration=0.2, transition=" + pattern + ")";
    document.getElementById('campaign').filters[0].Apply();
    document.getElementById('campaign').style.visibility = 'hidden';
    document.getElementById('campaign').filters[0].Play(); 
}
function showCampaign () {
    document.getElementById('campaign').style.visibility = 'visible';
    document.getElementById('campaign').style.display = 'block';
    void(0);
}
function hideCampaign () {
    document.getElementById('campaign').style.visibility = 'hidden';
    document.getElementById('campaign').style.display = 'none';
    void(0);
}
