﻿//图片等比例缩放
function DrawImage(objImg,maxWidth,maxHeight){ 
var img = new Image(); 
img.src = objImg.src; 
var hRatio; 
var wRatio; 
var Ratio = 1; 
var w = img.width; 
var h = img.height; 
wRatio = maxWidth / w; 
hRatio = maxHeight / h; 
if (maxWidth ==0 && maxHeight==0){ 
Ratio = 1; 
}else if (maxWidth==0){ 
if (hRatio<1) Ratio = hRatio; 
}else if (maxHeight==0){ 
if (wRatio<1) Ratio = wRatio; 
}else if (wRatio<1 || hRatio<1){ 
Ratio = (wRatio<=hRatio?wRatio:hRatio); 
} 
if (Ratio<1){ 
w = w * Ratio; 
h = h * Ratio; 
} 
objImg.height = h; 
objImg.width = w; 

if(h<=maxHeight)
{
  objImg.style.paddingTop=maxHeight-h;
}
if(w<=maxWidth)
{
objImg.style.paddingLeft=(maxWidth-w)/2;
objImg.style.paddingRight=(maxWidth-w)/2;
}
} 

//设为首页
function SetHome(obj,vrl){
      
    try
    {
            obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);					
    }
    catch(e)
    {
            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',vrl);
             }
    }
}
//加入收藏
function AddFavorite(sURL, sTitle)
{
    try
    {
            window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
            try
            {
                    window.sidebar.addPanel(sTitle, sURL, "");
            }
            catch (e)
            {
                    alert("加入收藏失败，请使用Ctrl+D进行添加");
            }
    }
}

