/**
*信息街前台用的通用JS库
*作者：孙丹维
*日期：2009-09-27
*/
//按比例缩放图片<img src="/demoimg/wall7.jpg" onload="DrawImage(this,100,100)" border="0">
function DrawImage(ImgD,FitWidth,FitHeight){
   var image=new Image();
   image.src=ImgD.src;
   if(image.width>0 && image.height>0){
       if(image.width/image.height>= FitWidth/FitHeight){
           if(image.width>FitWidth){
               ImgD.width=FitWidth;
               ImgD.height=(image.height*FitWidth)/image.width;
           }else{
               ImgD.width=image.width;
               ImgD.height=image.height;
           }
       } else{
           if(image.height>FitHeight){
               ImgD.height=FitHeight;
               ImgD.width=(image.width*FitHeight)/image.height;
           }else{
               ImgD.width=image.width;
               ImgD.height=image.height;
           }
       }
   }
}
//对图片进行等比例缩放<img name="xx"  src="2.jpg" onload="img_resize(xx,100,500)">
function img_resize(imgname,widths,heights){ 
	var w; 
	var h; 
	//window.alert(picimg.width); 
	//window.alert(picimg.height); 
	w=imgname.width; 
	h=imgname.height; 
	if(imgname.width>widths){ 
		do 
		w=w-1; 
		while (w>widths) ; 

		s=w/imgname.width; 
		//window.alert(s); 
		imgname.width=w; 
		imgname.height=h*s; 
		h=imgname.height 
	} 
//window.alert(imgname.height); 
//window.alert(heights); 
	if(imgname.height>heights){ 
		do 
		h=h-1; 
		while (h>heights) ; 

		s=h/imgname.height; 
		//window.alert(s); 
		imgname.width=w*s; 
		imgname.height=heights; 
	} 
} 

//<img src="data.jpg" alt="" name="img1" id="img1" onload="setImgSize('img1',450,0);"/>  
function setImgSize(imgID,maxWidth,maxHeight)    
 {    
     var img = document.images[imgID];    
      if(maxWidth < 1)    
      {    
         if(img.height > maxHeight)    
         {    
             img.height = maxHeight;    
         }    
         return true;    
     }    
     if(maxHeight < 1)    
     {    
         if(img.width > maxWidth)    
         {    
             img.width = maxWidth;    
         }    
         return true;    
     }    
     if(img.height > maxHeight || img.width > maxWidth)    
     {    
         if((img.height / maxHeight) > (img.width / maxWidth))    
         {    
             img.height = maxHeight;    
         }    
         else    
         {    
             img.width = maxWidth;    
         }    
         return true;    
     }    
 }    

/**
使用如下方式调用
<IMG align=middle alt="come here" border=0 height=247 
      onmouseout=low(this) onmouseover=high(this)  style="FILTER: alpha(opacity=30)" src="ball.gif">

*/
function high(which2){
	theobject=which2;
	highlighting=setInterval("highlightit(theobject)",100);
}
function low(which2){
	clearInterval(highlighting);
	which2.filters.alpha.opacity=45;
}
function highlightit(cur2){
	if (cur2.filters.alpha.opacity<200) cur2.filters.alpha.opacity+=20;
	else if (window.highlighting);
	clearInterval(highlighting);
}

/**
*设置字体大小中，通常用于详细信息的展示页面。
调用:
<A href="javascript:setFontSize(16,'Content')">大</a> 
<A href="javascript:setFontSize(14,'Content')">中</a> 
<A href="javascript:setFontSize(12,'Content')">小</a>

要更改的文字:id=content是必须的
<DIV id=Content style="FONT-SIZE: 13px" align="center">
<p>一个超简单的新闻中设置字体大中小的例子</p>
</div>
*/
function setFontSize(size,contentid) 
{ 
	var obj=document.getElementById(contentid); 
	obj.style.fontSize=size+"px"; 
} 
/**
*首页标签效果用到
*/
        function SetTab(tab,id,cnt){
            var menus=document.getElementById(tab).getElementsByTagName("li");            
	        for(i=0;i<cnt;i++){	       
	            i==id?menus[i].className="on":menus[i].className="";
	            i==id?document.getElementById(tab+"-content"+i).className="block":document.getElementById(tab+"-content"+i).className="none";
            }
	    }

/**
*更换验证码图片
*/
function resetCheckCode(sname){
	var imgurl='/lib/validate_code.php?SESS_NAME='+sname;
	//alert(imgurl);
	var img = document.getElementById('picture_vcode');
	if (img!=null){
   		img.src=imgurl;
 	}
   return false;
}