function ObjectAD() {
  /* Define Variables*/
  this.ADID        = 0;
  this.ADType      = 0;
  this.ADName      = "";
  this.ImgUrl      = "";
  this.ImgWidth    = 0;
  this.ImgHeight   = 0;
  this.FlashWmode  = 0;
  this.LinkUrl     = "";
  this.LinkTarget  = 0;
  this.LinkAlt     = "";
  this.Priority    = 0;
  this.CountView   = 0;
  this.CountClick  = 0;
  this.InstallDir  = "";
  this.ADDIR       = "";
  this.ADIntro     = "";
  this.EndTime    =""
}

function MoveZoneAD(_id) {
  /* Define Common Variables*/
  this.ID          = _id;
  this.ZoneID      = 0;
  this.ZoneName    = "";
  this.ZoneWidth   = 0;
  this.ZoneHeight  = 0;
  this.ShowType    = 1;
  this.DivName     = "";
  this.Div         = null;
  this.RunObj      = null;
  this.zoneActive  = "False";
  

  /* Define Unique Variables*/
  this.Left        = 0;
  this.Top         = 0;
  this.Delta       = 0.15;

  /* Define Objects */
  this.AllAD       = new Array();
  this.ShowAD      = null;

  /* Define Functions */
  this.AddAD       = MoveZoneAD_AddAD;
  this.GetShowAD   = MoveZoneAD_GetShowAD;
  this.Show        = MoveZoneAD_Show;
  this.Move        = MoveZoneAD_Move;

}

function MoveZoneAD_AddAD(_AD) {
  if(this.zoneActive!="True"){
      return ;
  }
  var strDate=_AD.EndTime;
  var splitArray=strDate.split("-"); 
  var enddate=  new Date(splitArray[0],splitArray[1]-1,splitArray[2]); 
  var datenow=new Date();
  if(datenow>enddate)
  {
    document.writeln("该广告已经过期!");
    return  ;
  }  
  this.AllAD[this.AllAD.length] = _AD; 
}

function MoveZoneAD_GetShowAD() {
  if (this.ShowType > 1) {
    this.ShowAD = this.AllAD[0];
    for (var i = 0; i < this.AllAD.length; i++) {
        if(this.AllAD[i].Priority > this.ShowAD.Priority){
            this.ShowAD = this.AllAD[i];
        }
    }
    return;
  }
  var num = this.AllAD.length;
  var sum = 0;
  for (var i = 0; i < num; i++) {
    sum = sum + this.AllAD[i].Priority;
  }
  if (sum <= 0) {
    if(num >= 1){
      this.ShowAD = this.AllAD[0];
    }
    return ;
  }
  var rndNum = Math.random() * sum;
  i = 0;
  j = 0;
  while (true) {
    j = j + this.AllAD[i].Priority;
    if (j >= rndNum) {break;}
    i++;
  }
  this.ShowAD = this.AllAD[i];
}

function MoveZoneAD_Show() {
  if (!this.AllAD) {
    return;
  } else {
    this.GetShowAD();
  }

  if (this.ShowAD == null) return false;
  this.DivName = "MoveZoneAD_Div" + this.ZoneID;
  if (!this.ShowAD.ImgWidth) this.ShowAD.ImgWidth = this.ZoneWidth
  if (!this.ShowAD.ImgHeight) this.ShowAD.ImgHeight = this.ZoneHeight
  if (this.ShowAD.ADDIR=="") this.ShowAD.ADDIR = "IMS_AD"
  if (navigator.appName == "Netscape") {
    document.write("<layer id='" + this.DivName + "' top='" + this.Top + "px' width='" + this.ZoneWidth + "px' height='" + this.ZoneHeight + "px'><layer style='text-align:right; border-right:1px solid #000000;border-top:1px solid #000000;border-left:1px solid #000000;'><img onclick={clearInterval("+this.ID+".RunObj);document.getElementById('"+this.DivName+"').style.display='none';} src='"+objAD.InstallDir+"/IMS_Img/dialog/wg_1.gif'></layer><layer>" + AD_Content(this.ShowAD) + "</layer></layer>");
  } else {
    document.write("<div id='" + this.DivName + "' style='position:absolute; visibility:visible; z-index:1; width:" + this.ZoneWidth + "px; height:" + this.ZoneHeight + "px; left:" + this.Left + "px;top:" + this.Top + "px'><div style='text-align:right; border-right:1px solid #000000;border-top:1px solid #000000;border-left:1px solid #000000;'><img onclick={clearInterval("+this.ID+".RunObj);document.getElementById('"+this.DivName+"').style.display='none';} src='"+objAD.InstallDir+"/IMS_Img/dialog/wg_1.gif'></div><div>" + AD_Content(this.ShowAD) + "</div></div>");
  }
  if (this.ShowAD.CountView) {
    document.write ("<script src='" + this.ShowAD.InstallDir + this.ShowAD.ADDIR + "/      Admin_ADCount.aspx?Action=View&ADID=" + this.ShowAD.ADID + "'></script>")
  }
  this.Div = document.getElementById(this.DivName);
  this.RunObj = setInterval(this.ID + ".Move()", 10);
}

function MoveZoneAD_Move() {
  if (this.Div.offsetLeft != (document.documentElement.scrollLeft + this.Left)) {
    var dx = (document.documentElement.scrollLeft + this.Left - this.Div.offsetLeft) * this.Delta;
    dx = (dx > 0 ? 1 :  - 1) * Math.ceil(Math.abs(dx));
    this.Div.style.left = this.Div.offsetLeft + dx+"px";
  }

  if (this.Div.offsetTop != (document.documentElement.scrollTop + this.Top)) {
    var dy = (document.documentElement.scrollTop + this.Top - this.Div.offsetTop) * this.Delta;
    dy = (dy > 0 ? 1 :  - 1) * Math.ceil(Math.abs(dy));
    this.Div.style.top = this.Div.offsetTop+dy+"px";
  }
  this.Div.style.display = '';
}

function AD_Content(o) {
  var str = "";
  var strDate=o.EndTime;
  var date=   Date.parse(strDate);
  var datenow=new Date();
  if(datenow>date)
  {
    return str;
  }
 if (o.ADType == 1 || o.ADType == 2) {
   /*    o.ImgUrl = o.ImgUrl.toLowerCase()
 if (o.InstallDir.indexOf("http://") != - 1) o.ImgUrl = o.InstallDir.substr(0, o.InstallDir.length - 1) + o.ImgUrl;*/
    if (o.ImgUrl.indexOf(".swf") !=  - 1) {
      str = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0'";
      str += " name='AD_" + o.ADID + "' id='AD_" + o.ADID + "'";
      str += " width='" + o.ImgWidth + "'";
      str += " height='" + o.ImgHeight + "'";
      if (o.style) str += " style='" + o.style + "'";
      if (o.extfunc) str += " " + o.extfunc + " ";
      str += ">";
      str += "<param name='movie' value='" + o.ImgUrl + "'>";
      if (o.FlashWmode == 1) str += "<param name='wmode' value='Transparent'>";
      if (o.play) str += "<param name='play' value='" + o.play + "'>";
      if (typeof(o.loop) != "undefined") str += "<param name='loop' value='" + o.loop + "'>";
      str += "<param name='quality' value='autohigh'>";
      str += "<embed ";
      str += " name='AD_" + o.ADID + "' id='AD_" + o.ADID + "'";
      str += " width='" + o.ImgWidth + "'";
      str += " height='" + o.ImgHeight + "'";
      if (o.style) str += " style='" + o.style + "'";
      if (o.extfunc) str += " " + o.extfunc + " ";
      str += " src='" + o.ImgUrl + "'";
      if (o.FlashWmode == 1) str += " wmode='Transparent'";
      if (o.play) str += " play='" + o.play + "'";
      if (typeof(o.loop) != "undefined") str += " loop='" + o.loop + "'";
      str += " quality='autohigh'"
      str += " pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash'></embed>";
      str += "</object>";
    } else if (o.ImgUrl.indexOf(".gif") !=  - 1 || o.ImgUrl.indexOf(".jpg") !=  - 1 || o.ImgUrl.indexOf(".jpeg") !=  - 1 || o.ImgUrl.indexOf(".bmp") !=  - 1 || o.ImgUrl.indexOf(".png") !=  - 1) {
      if (o.LinkUrl) {
        if (o.CountClick) o.LinkUrl = o.InstallDir + o.ADDIR + "/Admin_ADCount.aspx?Action=Click&ADID=" + o.ADID
        str += "<a href='" + o.LinkUrl + "' target='" + ((o.LinkTarget == 0) ? "_self" : "_blank") + "' title='" + o.LinkAlt + "'>";
      }
      str += "<img ";
      str += " name='AD_" + o.ADID + "' id='AD_" + o.ADID + "'";
      if (o.style) str += " style='" + o.style + "'";
      if (o.extfunc) str += " " + o.extfunc + " ";
      str += " src='" + o.ImgUrl + "'";
      if (o.ImgWidth) str += " width='" + o.ImgWidth + "'";
      if (o.ImgHeight) str += " height='" + o.ImgHeight + "'";
      str += " border='0'>";
      if (o.LinkUrl) str += "</a>";
    }
  } else if (o.ADType == 3 || o.ADType == 4) {
    str = o.ADIntro
  } else if (o.ADType == 5) {
    str = "<iframe id='" + "AD_" + o.ADID + "' marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no width=100% height=100% src='" + o.ADIntro + "'>wait</iframe>";
  }
  return str;
}

    var ZoneAD_23 = new  MoveZoneAD("ZoneAD_23");
ZoneAD_23.ZoneID      = 23;
ZoneAD_23.ZoneWidth   =468;
ZoneAD_23.ZoneHeight  = 160;
ZoneAD_23.ShowType    =1;
ZoneAD_23.Left    =15;
ZoneAD_23.Top    =200;
ZoneAD_23.Delta    =0.015;
ZoneAD_23.zoneActive    ="True";
//恒浪网络==By 林子：不允许修改，否则出错，谢谢！==

//-----------------------开始好又多
 var objAD = new ObjectAD();
objAD.ADID           =11;
objAD.ADType         =1;
objAD.ADName         = "好又多";
objAD.ImgUrl         = "/AD/UploadAdpic/2009090210514196.jpg";
objAD.ImgWidth       = 150;
objAD.ImgHeight      = 150;
objAD.FlashWmode     = 0;
objAD.ADIntro        = "asdsasad";
objAD.LinkUrl        = "http://baidu.com";
objAD.LinkTarget     = 0;
objAD.LinkAlt        = "百度";
objAD.Priority       = 1;
objAD.CountView      = 1;
objAD.CountClick     = 0;
objAD.EndTime ="2009-10-2";
objAD.InstallDir     ="http://localhost/";
objAD.ADDIR          ="AD"; 
ZoneAD_23.AddAD(objAD);
//-----------------------结束好又多





//-----------------------开始dd
 var objAD = new ObjectAD();
objAD.ADID           =12;
objAD.ADType         =1;
objAD.ADName         = "dd";
objAD.ImgUrl         = "/AD/UploadAdpic/2009090215131288.jpg";
objAD.ImgWidth       = 0;
objAD.ImgHeight      = 0;
objAD.FlashWmode     = 0;
objAD.ADIntro        = "";
objAD.LinkUrl        = "http://";
objAD.LinkTarget     = 0;
objAD.LinkAlt        = "";
objAD.Priority       = 1;
objAD.CountView      = 1;
objAD.CountClick     = 0;
objAD.EndTime ="2009-10-2";
objAD.InstallDir     ="http://localhost/";
objAD.ADDIR          ="AD"; 
ZoneAD_23.AddAD(objAD);
//-----------------------结束dd
ZoneAD_23.Show();

