var daidx=-2;//-4/停播;-3/单次播放;-2/2组单次，1组循环播放;-1/循环播放;>=0指定广告播放
var daids='';
var daseq=false;//广告播放顺序为随机，是主要模式，当广告为播放2组时，可以为顺序
var currdawh;//当前处理广告的尺寸
var DAplaylist='3,4,5,6,7,8';
var DAplaylist2='0,1,2';//仅参加一次循环的广告
function daplay(wh){
  currdawh=wh;
  //广告源控制
  if(DAplaylist==''){dahtml(-1);/*无广告源-播放默认广告*/return;}
  if(daidx>=0){dahtml(daidx);return;}
  if(daidx<=-4){dahtml(-1);/*禁播广告-播放默认广告*/return;}
  //---广告源控制
  var vDApc=getCookie('DAplayCatch');
  //来自cookie的广告序列无内容流程
  if(vDApc==''){
    if(daidx==-2){vDApc=','+DAplaylist2+',';daseq=true;}
    else vDApc=','+DAplaylist+',';
    setCookie('DAplayCatch',vDApc,1);
  }
  if(vDApc==','){
  if(daidx==-1){vDApc=','+DAplaylist+',';setCookie('DAplayCatch',vDApc,1);}
  else{
    var cylclec=getCookie('cylclec');
      if(cylclec=='') cylclec=0;
      cylclec=parseInt(cylclec);//document.write('('+cylclec+')')
    if(cylclec<10){ //展示10轮随机广告位一个大循环
    var cylcleckv=(cylclec+1)+'';
    setCookie('cylclec',cylcleckv);
    if(daidx==-3){dahtml(-1);/*禁循环=播放默认广告*/return;}
    if(daidx==-2){vDApc=','+DAplaylist+',';setCookie('DAplayCatch',vDApc,1);}
    }else{
    if(daidx==-2){
      setCookie('cylclec','0');//使cylclec前置一个数位
      vDApc=','+DAplaylist2+',';
      setCookie('DAplayCatch',vDApc,1);
      daseq=true;
    }else{
      setCookie('cylclec','1');
      vDApc=','+DAplaylist+',';
      setCookie('DAplayCatch',vDApc,1);
    }
    }
  }
  }
  //---来自cookie的广告序列无内容流程
  var midp,stap,endp;
  if(daseq) stap=0; //顺序
  else{ //随机
  midp=parseInt(Math.random()*(vDApc.length-1));
  if(vDApc.substr(midp,1)==',') stap=midp;
  else stap=vDApc.substr(0,midp).lastIndexOf(',');
  }
  endp=vDApc.indexOf(',',stap+1);
  daids=vDApc.substring(stap,endp+1);
  var iidx=parseInt(daids.substring(1,daids.length-1));
  vDApc=vDApc.replace(daids,',');
  setCookie('DAplayCatch',vDApc,1);
  //document.write('|'+daseq+'|'+stap+'|');
  dahtml(iidx);
}
function dahtml(idx){
  var adstr='';
  idx=parseInt(idx);
  switch(idx){
   case 0 :
google_ad_client = "pub-5640767184663422";
google_ad_width = 200;
google_ad_height = 200;
google_ad_format = "200x200_as";
google_ad_type = "image";
google_ad_channel = "6861118267";
document.write('<'+'script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"><'+'/script>');
      break;
   case 1 :
google_ad_client = "pub-5640767184663422";
google_ad_width = 200;
google_ad_height = 200;
google_ad_format = "200x200_as";
google_ad_type = "text";
google_ad_channel = "6861118267";
google_color_border = "F0F0F0";
google_color_bg = "F0F0F0";
document.write('<'+'script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"><'+'/script>');
      break;
   case 2 :
      adstr=''//空广告位
      break;
   case 3 :
      adstr='<div class="divvmid"><div><p style="font-family:黑体;font-size:16px;"><a href="http://www.endad.com/stp/class/220/5018334.htm" target=_blank>寻找2009最具人气的手机</a></p></div></div>';
      break;
   case 4 :
      adstr='<div class="divvmid"><div><p style="font-family:黑体;font-size:16px;"><a href="http://www.endad.com/stp/class/507/1539089.htm" target=_blank>做网店代理享受睡觉都挣钱的乐趣</a></p></div></div>';
      break;
   case 5 :
      adstr='<div class="divvmid"><div><p style="font-family:黑体;font-size:16px;"><a href="http://www.endad.com/stp/class/607/1717402.htm" target=_blank>巡洋舰摩托车体验风驰电掣的感觉</a></p></div></div>';
      break;
   case 6 :
      adstr='<div class="divvmid"><div><p style="font-family:黑体;font-size:16px;"><a href="http://www.endad.com/stp/class/605/4820462.htm" target=_blank>超时空疤毋痕，真女人俱乐部</a></p></div></div>';
      break;
   case 7 :
      adstr='<div class="divvmid"><div><p style="font-family:黑体;font-size:16px;"><a href="http://www.endad.com/stp/class/1117/5003551.htm" target=_blank>移动警务通号卡绝对有型有款的套餐</a></p></div></div>';
      break;
   case 8 :
      adstr='<div class="divvmid"><div><p style="font-family:黑体;font-size:16px;"><a href="http://www.endad.com/stp/class/526/5043138.htm" target=_blank>私人贷款，无担保无抵押，提前享受生活的乐趣</a></p></div></div>';
      break;
   default:
     //if(currdawh=='200x200'){adstr='200x200-default';break;}
     //if(currdawh=='200x138'){adstr='200x138-default';break;}
      adstr='<div class="divvmid"><div><p style="font-family:黑体;font-size:16px;"><A href="http://www.endad.com/stp/class/615/1766042.htm" target=_blank>整量二手车吧巨便宜！奔驰奥拓应有尽有，走私罚没绝对实惠！不买也要比比</A></p></div></div>';
  }
  if(adstr!='') document.write(adstr);
}
