// JavaScript Document

//讀取AD廣告參數資料
function Get_AD_Area( AreaID, ZoneName ) {
  //定義參數
  var AD_Id = "";
  //var AD_Sec = "";
  var AD_Sec = "60";
  
  $.ajax({
    url: 'http://www.wagame.com.tw/ADCenter_Data/AD_GetXML.asp?AreaID=' + AreaID,
    //type: 'GET',
    dataType: "xml", //強制定義取得的檔案格式為XML
    error: function(xhr) {
      //alert('Ajax Request 發生錯誤');
    },
    success: function(xml){
      $(xml).find("ADXML").each(function(){
        AD_Id = $(this).find("id").text();
        AD_Sec = $(this).find("Sec").text();
      });
	  if ( AD_Id != "" ) {
        Get_AD_Area_Html( AreaID, AD_Id, AD_Sec, ZoneName );
      }
    }
  });
}

//依照編號讀取廣告區塊的HTML
function Get_AD_Area_Html( AreaID, AD_Id, AD_Sec, ZoneName ) {
  var AD_ZoneName = '#' + ZoneName;
  
  $.ajax({
    url: 'http://www.wagame.com.tw/ADCenter_Data/AD_GetADHtml.asp?ID=' + AD_Id,
	async: true,
    //type: 'GET',
    dataType: "html", //強制定義取得的檔案格式為XML
    error: function(xhr) {
      //alert('Ajax Request 發生錯誤');
	  //$( AD_ZoneName ).html( 'Ajax Request 發生錯誤' );
	  setTimeout(function(){
		Get_AD_Area( AreaID, ZoneName );
	  }, ( 60 * 1000) );
    },
    success: function(AD_Html) {
      $( AD_ZoneName ).html( AD_Html );
	  setTimeout(function(){
		Get_AD_Area( AreaID, ZoneName );
	  }, ( AD_Sec * 1000) );
    }
  });
}
