//广告对联类
//调用方式<div id="followDivTemp" style="display:none">test</div><script>the_Couplet	= new _Couplet('the_Couplet','followDivTemp');the_Couplet.addItem('followDiv1','document.body.clientWidth-112',20);the_Couplet.play();</ script>
function _Couplet() {
	this.source=null;  //复制的图层来源
	this.delta=0.8;    //缩放百分比
	this.closeB=false; //关闭状态

    this.self=arguments[0]; //引用自己的变量名
    var s_obj=arguments[1];
	var tmp_delta=arguments[2];
	var tmp_closeB=arguments[3];

    if(this.self==null || this.self=='') throw new Error(999,"请输入类变量名！");
	if(typeof(s_obj)=='object')  this.source=s_obj;
	else if(typeof(s_obj)=='string') {
	   try{
	      this.source=document.getElementById(s_obj);
	   }
	   catch(e){}
	}
	if(this.source==null) throw new Error(999,"请传入图层源！");
	if(typeof(tmp_delta)=='number') this.delta=tmp_delta;
	if(typeof(tmp_closeB)=='boolean') this.closeB=tmp_closeB;

	this.items	= [];
	this.addItem	= function(id,x,y/*,content*/){
	    var n_obj=null;
		try{
			n_obj=document.createElement("div");
			n_obj.innerHTML=this.source.innerHTML+"<div style=\"font-family:Webdings;font-size:11px;float:right;width:11px;height:12px;line-height:10px;padding-bottom:2px;padding-right:0px;margin-top:6px;margin-right:5px;border:solid 1px #a0a0a0;cursor:default;\" onMouseOut=\"this.style.cssText='font-family:Webdings;font-size:11px;float:right;width:11px;height:12px;line-height:10px;padding-bottom:2px;padding-right:0px;margin-top:6px;margin-right:5px;border:solid 1px #a0a0a0;cursor:default;';\" onMouseOver=\"this.style.cssText='font-family:Webdings;font-size:11px;float:right;width:11px;height:12px;line-height:10px;padding-bottom:2px;padding-right:0px;margin-top:6px;margin-right:5px;border:solid 1px #ff7628;cursor:hand;';\" onclick=\"try {"+this.self+".closeBanner();}catch(e){}\" title=\"关闭\">r</div>";
			n_obj.style.cssText='Z-INDEX: 10; POSITION: absolute;  width:110px;height:300px;left:'+(typeof(x)=='string'?eval(x):x)+';top:'+(typeof(y)=='string'?eval(y):y);

			document.body.insertAdjacentElement("afterBegin",n_obj);

		}
		catch(e){}

		var newItem				= {};
		newItem.object			= n_obj;
		newItem.x				= x;
		newItem.y				= y;

		this.items[this.items.length]		= newItem;
	}
	
	this.play	= function(){  
		setInterval(this.self+".loop_()",30);
    }

	this.loop_=function() {

		var collection= this.items;
		if(screen.width<=800 || this.closeB){
			for(var i=0;i<collection.length;i++){
				collection[i].object.style.display	= 'none';
			}
			return;
		}
		for(var i=0;i<collection.length;i++){
			var followObj		= collection[i].object;
			var followObj_x		= (typeof(collection[i].x)=='string'?eval(collection[i].x):collection[i].x);
			var followObj_y		= (typeof(collection[i].y)=='string'?eval(collection[i].y):collection[i].y);

			if(followObj.offsetLeft!=(document.body.scrollLeft+followObj_x)) {
				var dx=(document.body.scrollLeft+followObj_x-followObj.offsetLeft)*this.delta;
				dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
				followObj.style.left=followObj.offsetLeft+dx;
			}

			if(followObj.offsetTop!=(document.body.scrollTop+followObj_y)) {
				var dy=(document.body.scrollTop+followObj_y-followObj.offsetTop)*this.delta;
				dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
				followObj.style.top=followObj.offsetTop+dy;
			}
			followObj.style.display	= '';
		}

	}

	this.closeBanner=function() {
		this.closeB=true;
	}
}
///////////////////////////////////////////////////////////////////
//无组件请求url数据
//调用方式 <div id="displayDV"></div><script>MakeRequest('test1.aspx','displayDV');</ script>
//vb编码解码函数
document.write('<script'+' language=vbscript>\n');
document.write('Function URLEncoding(vstrIn)\n');
document.write('	strReturn = ""\n');
document.write('	For i = 1 To Len(vstrIn)\n');
document.write('		ThisChr = Mid(vStrIn,i,1)\n');
document.write('		If Abs(Asc(ThisChr)) < &HFF Then\n');
document.write('			strReturn = strReturn & ThisChr\n');
document.write('		Else\n');
document.write('			innerCode = Asc(ThisChr)\n');
document.write('			If innerCode < 0 Then\n');
document.write('				innerCode = innerCode + &H10000\n');
document.write('			End If\n');
document.write('			Hight8 = (innerCode And &HFF00)\\ &HFF\n');
document.write('			Low8 = innerCode And &HFF\n');
document.write('			strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)\n');
document.write('		End If\n');
document.write('	Next\n');
document.write('	URLEncoding = strReturn\n');
document.write('End Function\n');
document.write('\n');
document.write('Function bytes2BSTR(vIn,vIdx,vLen,disDiv)\n');
document.write('	bytes2BSTR=""\n');
document.write('	if vIdx<1 then exit function\n');
document.write('	if vLen<1 then exit function\n');
document.write('	if IsEmpty(disDiv) then exit function\n');
document.write('\n');
document.write('	strReturn = ""\n');
document.write('	full_len=LenB(vIn)\n');
document.write('	if vIdx+vLen-1>full_len then \n');
document.write('	   tmp_len=vIdx+vLen-full_len-1\n');
document.write('	   if tmp_len<vLen then \n');
document.write('	      vLen=vLen-tmp_len\n');
document.write('	   else \n');
document.write('	      exit function\n');
document.write('	   end if\n');
document.write('	end if \n');
document.write('\n');
document.write('	loopi=0\n');
document.write('	do while loopi<vLen\n');
document.write('		ThisCharCode = AscB(MidB(vIn,vIdx+loopi,1))\n');
document.write('		If ThisCharCode < &H80 Then\n');
document.write('			strReturn = strReturn & Chr(ThisCharCode)\n');
document.write('		Else\n');
document.write('			NextCharCode = AscB(MidB(vIn,vIdx+loopi+1,1))\n');
document.write('			strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))\n');
document.write('			loopi = loopi + 1\n');
document.write('		End If\n');
document.write('\n');
document.write('		loopi=loopi+1\n');
document.write('	loop\n');
document.write('\n');
document.write('	disDiv.setAttribute "idx",vIdx+loopi\n');
document.write('\n');
document.write('	bytes2BSTR = strReturn\n');
document.write('End Function\n');
document.write('<'+'/script>\n');
function XmlDataLoading(disDiv) {
   try {
      var txt=disDiv.innerText;
      if(txt.length>7 || txt=="") txt="数据载入中";
      else txt=txt+".";
      disDiv.innerHTML='<span style="FONT-SIZE: 12px">'+txt+'</span>';
   }
   catch(e) {}   
}
function MakeRequest() {
    var strUrl=arguments[0];     //url
	var displayDiv=arguments[1]; //关联div
	var method=arguments[2];	 //request method get post
	var params=arguments[3];	 //request params form post
	var js_load_over=arguments[4];  //load over exec javascript

    var disDiv=null;
    if(typeof(displayDiv)=="string") {
       if(displayDiv=="") return false;
       try {
          disDiv=document.getElementById(displayDiv);
       }
       catch(e){}
    }
    else disDiv=displayDiv;
    if(disDiv==null) return false;
    if(strUrl==null || strUrl=="") return false;
	if(method==null) method="";
	method=method.toUpperCase();
	if(method!="POST") method="GET";
	if(params=="") params=null;
	if(js_load_over==null) js_load_over='';
        
	disDiv.innerHTML='<span style="FONT-SIZE: 12px">数据载入中...</span>';
	//调入定时器
	var loadstatus=false;
	var load_interval=null;
	var data_interval=null;
	var load_doing_proc=function() {
	   XmlDataLoading(disDiv);
	}
		
	var http_request=null;
        
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } 
    else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
           try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) return false;
    load_interval=setInterval(load_doing_proc,200);
	disDiv.setAttribute('idx',1);
    
    http_request.onreadystatechange = function() {
       if(http_request.readyState == 4) {
           if(load_interval!=null) {
              clearInterval(load_interval);
              load_interval=null;
           }
           if (http_request.status == 200) {
		      var theBody="";
		      var load_data_interval=null;
		      var load_data_proc=function() {
			     var idx=parseInt(disDiv.getAttribute('idx'));
				 var isClear=true;
				 if(!isNaN(idx)) {
			        var outputBody=bytes2BSTR(http_request.responseBody,idx,4000,disDiv);
					XmlDataLoading(disDiv);
					theBody=theBody+outputBody;
					isClear=(outputBody=="");
				 }
				 if(load_data_interval!=null && isClear) {
				    clearInterval(load_data_interval);
					disDiv.innerHTML=theBody;
					try{
					   eval(js_load_over); //调入完成后执行javascript
					}
					catch(e){}
				 }
			  }
			  load_data_interval=setInterval(load_data_proc,5); //解码数据进度
           } 
           else {
              disDiv.innerHTML='<span style="FONT-SIZE: 12px">数据载入失败！</span>';
           }  
       }
    }
	try {
      http_request.open(method,URLEncoding(strUrl), true);
	  if(method=="POST") http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") ;
      http_request.send(params);
	}
	catch(e) {
	   disDiv.innerHTML='<span style="FONT-SIZE: 12px">'+e.description+'，无法载入数据！</span>';
       if(load_interval!=null) {
           clearInterval(load_interval);
           load_interval=null;
       }
	}
}
//////////////////////////////////////////////////////////
//从指定容器中获得flash对象
function GetAFlashInContainer(container_id) {
   var container_obj=null;
   if(typeof(container_id)=='object') container_obj=container_id;
   else{
      try {
	     if(container_id!='') container_obj=document.getElementById(container_id);
	  }
	  catch(e) {}
   }
   if(container_obj==null) return null;
   try {
      if(container_obj.tagName=='OBJECT' && container_obj.TotalFrames!=null && container_obj.TotalFrames>0) 
	     return container_obj; //is flash      
   }
   catch(e) {}

   for(var i=0;i<container_obj.children.length;i++) {
     try {
        if(container_obj.children[i].tagName=='OBJECT') {
	        if(container_obj.children[i].TotalFrames!=null && container_obj.children[i].TotalFrames>0) 
			  return container_obj.children[i]; //is flash
        }
		else {
		   var flash_obj=GetAFlashInContainer(container_obj.children[i]);
		   if(flash_obj!=null) return flash_obj;
		}
     }
     catch(e) {}
      
   }

   return flash_obj;

}
//js广告轮播
//指定的flash通过设定playtime属性来设置该flash的播放秒数
//调用方式
//<div id='testid'>
//<div>
//<object playtime="2000" ClassId="clsid:d27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" name="movie" width="760" height="100" id="movie">
//  <param name="movie" value="idx_images/060316-1.swf" />
//  <param name="quality" value="high" />
//  <embed src="idx_images/060316-1.swf" width="760" height="100" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="movie"></embed>
//</object>
//</div>
//<div>
//<object playtime="12000"  classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" name="movie1" width="760" height="100" id="movie1">
//  <param name="movie" value="idx_images/langting.swf" />
//  <param name="quality" value="high" />
//  <embed src="idx_images/langting.swf" width="760" height="100" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="movie"></embed>
//</object>
//</div>
//</div>
//<script>SetAdDoLoopPlay('testid',6000);</script>
function SetAdDoLoopPlay(dv_id,tm) {
   if(typeof(tm)!='number') {
      tm=parseInt(tm);
	  if(isNaN(tm)) tm=10000;
   }
   if(tm<1) tm=10000;

   var dv_obj=null;
   if(typeof(dv_id)=='object') dv_obj=dv_id;
   else{
      try {
	     if(dv_id!='') dv_obj=document.getElementById(dv_id);
	  }
	  catch(e) {}
   }
   if(dv_obj==null) alert('无法找到指定轮播广告的图层！');
   if(dv_obj.children.length<2) return;

   var play_i=0;
   var playObjMark=dv_obj.uniqueID+'_Obj';
   var playIMark=dv_obj.uniqueID+'_Pos';
   if(document[playIMark]==null || document[playObjMark]==null) {
      play_i=0;
	  document[playIMark]=0;
	  if(document[playObjMark]!=null) {
	    clearInterval(document[playObjMark]);
  	    document[playObjMark]=null;
	  }
   }
   else {
      play_i=parseInt(document[playIMark]);
	  if(isNaN(play_i)) play_i=0;
   }

   for(var i=0;i<dv_obj.children.length;i++) {
      try {
	     dv_obj.children[i].style.display=((play_i==i)?'block':'none');
	  }
	  catch(e) {}
   }

   var bak_play_i=play_i;

   play_i++;
   if(play_i>=dv_obj.children.length) play_i=0;

   var tm1=tm;
   try {
     var the_flash=GetAFlashInContainer(dv_obj.children[bak_play_i]);
     var tm1=parseInt(the_flash.getAttribute('playtime'));
	 if(isNaN(tm1)) tm1=tm;
	 else {
		the_flash.GotoFrame(0);
	    //the_flash.StopPlay();
	    the_flash.Play();
	 }
   }
   catch(e) {}

   //alert(tm1);
   if(document[playObjMark]!=null) {
     clearInterval(document[playObjMark]);
     document[playObjMark]=null;
   }      
   document[playObjMark]=setInterval('SetAdDoLoopPlay(\''+dv_id+'\','+tm+');',tm1);
   document[playIMark]=play_i;
}
//缩放图片
//调用方式 <img src="http://192.168.1.200/myhot/member_uf_image_read.html?src=57f1db20-e2c8-4268-91b8-b978e9af4c2f.jpg" onload="ScaleImage(true,100,200,this,'','')";>
function ScaleImage(tHand,cWidth,cHeight,ImgD,tUrl,tAlt){
  var image=new Image();
  image.src=ImgD.src;
  var scale_ret=ScaleFit(image.width,image.height,cWidth,cHeight);
  ImgD.width=scale_ret[0];
  ImgD.height=scale_ret[1];
  ImgD.alt=tAlt;
  if(tUrl=="") {
     ImgD.alt="点击查看全图！"; 
	 tUrl=ImgD.src;
  }
  ImgD.onclick=function() {
    try {
      var wnd=window.open("about:blank");
      wnd.document.open();
      wnd.document.write("<table width='100%' height='100%' border='0' cellpadding='0' cellspacing='0'><tr><td align='center' valign='middle'><img src='"+tUrl+"' border='0'></td></tr></table>");
      wnd.document.close(); 
	  wnd.focus();
    }
    catch (e){ 
    }
     
  }
  if(tHand) { //显示手装光标
     ImgD.onmouseover=function () {
	   this.style.cursor='hand';
	 }
  }
}
function ScaleFit(w,h,width,height) {
   var w_require_scale;
   var h_require_scale; 
   var width_div_height;
   var w_div_h;
   var ret=[];
   
   ret[0]=0;
   ret[1]=0;
   if(w > 0 && h > 0 && width>0 && height>0) {
       w_require_scale = (w > width);
       h_require_scale = (h > height);
       if(w_require_scale && h_require_scale) {
            width_div_height = width / height;
            w_div_h = w / h;
            if(w_div_h > width_div_height) {
                    ret[0] = width;
                    ret[1] = Math.round(ret[0] / w_div_h);
			}
            else {
                    ret[1] = height;
                    ret[0] = Math.round(ret[1] * w_div_h);
            }
       }
       else {
                if(w_require_scale) {
                    ret[0] = width;
                    ret[1] = Math.round(ret[0] * h / w);
				}
                else
                    if(h_require_scale) {
                        ret[1] = height;
                        ret[0] = Math.round(height * w / h);
					}
                    else   {  //不需缩放
                        ret[0] = w;
                        ret[1] = h;
                    }
            
       }
   }

   return ret;
}
