//*** onAIRinfomationXMLparse Async ***//
function getOnAIRinfXML_async(){
  try{
      var http = new JKL.ParseXML("/js/getonair.php");
      if ( !http ) return false;

      http.async( getOnAIRinf );
      http.parse();

  } catch(e){
      return e.description;
  }
}

var flg13 = 0;
var flg19 = 0;
var flg00 = 0;

function getOnAIRinf( data ){
  try{
      var prmID = "OAScrollBox";
      if ( !data.data ){
          //document.getElementById(prmID).innerHTML = "本日の出演予定はありません。";
          document.getElementById(prmID).innerHTML = "メンテナンス中";
          return false;
      }
      var objData = data.data.rows;
      var dataRecord = objData.length;
      var rsltHTML = "<ul>";

      if ( !dataRecord ){
          rsltHTML = Make_OnAIRhtml( objData );
      } else{
          for(i = 0; i < dataRecord; i++){
              rsltHTML += Make_OnAIRhtml( objData[i] );
          }
      }
      rsltHTML += "</ul>"
      document.getElementById(prmID).innerHTML = rsltHTML;

  } catch(e){
      //document.getElementById(prmID).innerHTML = e.description;
      //document.getElementById(prmID).innerHTML = "parse error";
      document.getElementById(prmID).innerHTML = "メンテナンス中";
  }
}

function Make_OnAIRhtml( prmData ){
  try{
      var rtnHTML = "";
      with ( prmData ){
        wkSTime = stime["#text"];
        wkSTime = (wkSTime.substr(0, 2) - 0) + wkSTime.substr(2, 3);
        if ( type["#text"] == 8 ){
            wkSTime += "配信開始";
        } else if( id_c["#text"] == 34 ){
            //20090630	if ( stime["#text"] >= "13:00:00" && stime["#text"] <= "15:30:00" ){
            if ( stime["#text"] >= "12:00:00" && stime["#text"] <= "15:30:00" ){
                if ( flg13 == 1 ){
                    if ( stime["#text"] == "15:30:00" ) flg13 = 0;
                    return rtnHTML;
                }
                flg13 = 1;
                if ( stime["#text"] != "15:30:00" ){
                    wkSTime += "～15:30 30分おきに放映";
                } else{
                    flg13 = 0;
                }
            }
            //20090630	if ( stime["#text"] >= "19:00:00" && stime["#text"] <= "23:30:00" ){
            if ( stime["#text"] >= "18:00:00" && stime["#text"] <= "23:30:00" ){
                if ( flg19 == 1 ){
                    if ( stime["#text"] == "23:30:00" ) flg19 = 0;
                    return rtnHTML;
                }
                flg19 = 1;
                if ( week["#text"] == 5 || week["#text"] == 6 ){
                    if ( stime["#text"] != "22:30:00" ) wkSTime += "～22:30 30分おきに放映";
                } else{
                    if ( stime["#text"] != "23:30:00" ) wkSTime += "～23:30 30分おきに放映";
                }
                if ( stime["#text"] == "23:30:00" ) flg19 = 0;
            }
            if ( stime["#text"] >= "00:00:00" && stime["#text"] <= "03:30:00" ){
                if ( flg00 == 1 ){
                    if ( stime["#text"] == "03:30:00" ) flg00 = 0;
                    return rtnHTML;
                }
                flg00 = 1;
                if ( stime["#text"] != "03:30:00" ){
                    wkSTime += "～3:30 30分おきに放映";
                } else{
                    flg00 = 0;
                }
            }
        } else if ( stime["#text"] != etime["#text"] ){
            wkETime = etime["#text"];
            wkETime = (wkETime.substr(0, 2) - 0) + wkETime.substr(2, 3);
            if ( stime["no"] != 1 ){
              wkSTime += "～" + wkETime;
            } else {
              now = new Date();
              var wkHMS = now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
              if ( stime["#text"] > wkHMS ){
                wkSTime += "～" + wkETime;
              } else {
                wkSTime = "出演中!! ～" + wkETime;
              }
            }
        } else {
            wkSTime += "頃";
        }
        rtnHTML += "<li><span class=\"date\">" + wkSTime;
        rtnHTML += "</span>[" + media["#text"] + "]&nbsp;" + name["#text"];

	wkCname = cname["#text"];
	wkUrl1 = url1["#text"];
	if ( wkCname.indexOf(",", 0) != -1 ){
	    aryCname = wkCname.split(",");
	    aryUrl1 = wkUrl1.split(",");
	    for (j = 0; j < aryCname.length; j++){
		rtnHTML += "<a href=\"" + aryUrl1[j];
		rtnHTML += "\" class=\"cast\">" + aryCname[j] + "</a>";
	    }
	    rtnHTML += "</li>";
	} else {
          if ( !wkUrl1 ){
            rtnHTML += "&nbsp;&nbsp;&nbsp;" + wkCname + "</li>";
          } else {
            rtnHTML += "<a href=\"" + wkUrl1;
            rtnHTML += "\" class=\"cast\">" + wkCname + "</a></li>";
          }
        }
      }
      return rtnHTML;
  } catch(e){
      return "";
  }
}

try{
  getOnAIRinfXML_async();
/*
  if (window.addEventListener) { //for W3C DOM
    window.addEventListener("load", getOnAIRinfXML_async, false);
  } else if (window.attachEvent) { //for IE
    window.attachEvent("onload", getOnAIRinfXML_async);
  }
*/
} catch(e){
}

