﻿function fAddFavorite(sTitle, sURL){ 
    if(document.all)
    {
        window.external.AddFavorite(sURL, sTitle); 
    }
    else
    {
        window.sidebar.addPanel(sTitle, sURL, "");
    }
}

/// 获取URL参数
function UrlSearch() 
{
   var name, value; 
   var str = location.href; //取得整个地址栏
   var num = str.indexOf("?");
   str = str.substr(num+1); //取得所有参数
   var arr = str.split("&"); //各个参数放到数组里
   for(var i = 0; i < arr.length; i++)
   { 
        num = arr[i].indexOf("="); 
        if(num > 0)
        { 
            name = arr[i].substring(0, num);
            value = arr[i].substr(num + 1);
            this[name] = value;
        } 
    } 
} 

/// 图片等比缩放：img=资源（通常指定this），iWidth=最大宽带，iHeight=最大高度
function DrawImage(img, iWidth, iHeight)
{
    var image = new Image();
    image.src = img.src;
    if(image.width > 0 && image.height > 0)
    {
        var rate = (iWidth / image.width < iHeight / image.height) ? iWidth / image.width : iHeight / image.height;
        if(rate <= 1)
        {　
            img.width = image.width * rate;
            img.height = image.height * rate;
        }
        else
        {
            img.width = image.width;
            img.height = image.height;
        }
    }
}

/// 设置某个控件的焦点：resId=控件ID
function SetFocus(resId)
{
	if (event.keyCode==13)
	{
		window.document.getElementById(resId).focus();
	}
}

/// 在指定窗口中打开连接
function OpenNewWindow(href,target)
{
    var frm = document.createElement("form");
    frm.method = "post";
    if (target != null && target != "")
        frm.target = target;
    frm.action = href;
    document.body.appendChild(frm);
    frm.submit();
}

