﻿(function(){
	y=window._={
		get:function(b,c){c=c||document;if(typeof b==="string")b=c.getElementById(b);return b},
		/*getN:function(s,o){o=o||document;return o.getElementsByName(s)},*/
		onload:function(b){var c=window.onload;window.onload=typeof window.onload!="function"?b:function(){c();b()}},
		init:function(e,b,d){b=b||{};d=d||{};for(var c in d)e[c]=b[c]||b[c]==0?b[c]:d[c]},
		bind: function(o, f) { return function() { return f.apply(o, arguments) } },
		getN: function(s, o) {o = o || document;return o.getElementsByName(s)},
		getValue:function(e){var d=[];e=_.getN(e);for(var c,f=0;f<e.length;f++){c=e[f];var b=c.tagName.toLowerCase();if(b=="input"){b=c.type;if(b=="text"||b=="hidden"||b=="password"||(b=="checkbox"||b=="radio")&&c.checked)d.push(c.value)}else if(b=="select"){b=c.options.length;for(var g=0;g<b;g++)c.options[g].selected==true&&d.push(c.value)}else b=="textarea"&&d.push(c.value)}return d.length?d.join(","):""}
		
	};
})();

String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, "") };
String.prototype.format1 = function() { for (var a = arguments.length, b = this; a; ) b = b.replace(RegExp("\\{" + --a + "\\}", "g"), arguments[a]); return b };
String.prototype.format = function() { var args = arguments; return this.replace(/\{(\d+)\}/g, function(m, i) { return args[i]; }); };
String.prototype.trimStart = function(a) { a || (a = "\\s+"); return this.replace(RegExp("^(" + a + ")+", "g"), "") };
String.prototype.trimEnd = function(a) { a || (a = "\\s+"); return this.replace(RegExp("(" + a + ")+$", "g"), "") };

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;
            }
        }
    }
}

function AddFavorite(sTitle) {
    sURL = location.href;

    try {
        window.external.addFavorite(sURL, sTitle);
    } catch (e) {
        try {
            window.sidebar.addPanel(sTitle, sURL, "");
        } catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

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("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [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);
        }
    }
}   

