﻿/*=========================================================================
函    数：addCookie()
作    用：加入收藏夹
使用方法：
-------------------------------------------------------------------------*/
function  addCookie(){   //加入收藏夹
	var favorUrl = document.URL;
	var favorTitle = document.title
	if(document.all){
		window.external.addFavorite(favorUrl, favorTitle);
	}else if(window.sidebar){
		window.sidebar.addPanel(favorTitle,favorUrl,"");
	}
}
/*=========================================================================
函    数：setHomepage()
作    用：设置首页
使用方法：
-------------------------------------------------------------------------*/
function  setHomepage() {   //设置首页
	var favorUrl = document.URL;
	if(document.all){
		document.body.style.behavior = 'url(#default#homepage)';
		document.body.setHomePage(favorUrl);
	}else if(window.sidebar){
		if(window.netscape){
			try  {
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}catch(e){
				alert("该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入about:config,然后将项 signed.applets.codebase_principal_support值该为true");
			}
		}
		var  prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage', favorUrl);
	}
}
/*=========================================================================
函    数：reImg(obj,iw,ih)
作    用：图片等比缩放
使用方法：<img src="11.gif" width=100% height=100% onload="reImg(this,this.width,this.height)">
-------------------------------------------------------------------------*/
function reImg(obj,iw,ih) {
	var iwh=iw/ih;
	var image=new Image(); 
	image.src=obj.src; 
	var w=image.width,h=image.height,wh=w/h; 
	if(w<=0 || h<=0) return false; 
	if(wh>=iwh){ 
	   if(w>iw){ 
		   obj.width=iw; 
		   obj.height=iw/wh; 
	   }else{ 
		   obj.width=w; 
		   obj.height=h; 
	   } 
	}else{ 
	   if(h>ih){ 
	   obj.height=ih; 
	   obj.width=ih*wh; 
	   }else{ 
	   obj.width=w; 
	   obj.height=h; 
	   } 
	}
}

