function UrlDecode(str)
{
	str = str.replace(new RegExp('\\+','g'),' ');
	return unescape(str);
}

function UrlEncode(str)
{
	str = escape(str);
	str = str.replace(new RegExp('\\+','g'),'%2B');
	return str.replace(new RegExp('%20','g'),'+');
}

function GetCookie(name)
{
	var array = document.cookie.split(";");
	for (var i=0; i < array.length; i++)
	{
		var kvp = array[i].split("=");
		
		var j = 0;
		for (; j < kvp[0].length; j++)
		{
			if (kvp[0].charAt(j) != ' ')
				break;
		}
		
		if (name == kvp[0].substr(j))
			return kvp[1];
	}
	return "";
}

function SetCookie(name, value, expireMinutes, path)
{
	var path = "";
	if (arguments.length == "4")
		path = ";path=" + arguments[3];
		
	var expireDate = new Date();
	expireDate.setMinutes(expireDate.getMinutes() + expireMinutes);
	document.cookie = name + "=" + value + ";expires=" + expireDate.toUTCString() + path;
}

function GetEvent()
{
	if (navigator.product != "Gecko")
		return window.event;
		
	func = GetEvent.caller;
	while (func != null)
	{
		var arg0 = func.arguments[0];
		if(arg0)
		{
			if ((arg0.constructor == Event || arg0.constructor == MouseEvent) || (typeof(arg0) == "object" && arg0.preventDefault && arg0.stopPropagation))
			{
				return arg0;
			}
		}
		func=func.caller;
	}
	return null;
}

function SetHome()
{
	var url = "";
	if (arguments.length == 1)
		url = arguments[0]
	else
		url = document.domain;
		
	if (document.all)
	{
        document.body.style.behavior = "url(#default#homepage)";
		if (!document.body.isHomePage(url))
			document.body.setHomePage(url);
	}
	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',url);
    }	
}

function AddFavorite()
{
	var title = document.title
	var url = document.location.href
	if (window.sidebar)
	{
		window.sidebar.addPanel(title, url, "");
	}
	else if (window.opera && window.print)
	{
		var mbm = document.createElement("A");
		mbm.setAttribute("rel", "sidebar");
		mbm.setAttribute("href", url);
		mbm.setAttribute("title", title);
		mbm.click();
	}
	else if (document.all)
	{
		window.external.AddFavorite( url, title);
	}
}

function CopyToClipboard(txt)
{ 
	if(window.clipboardData)  
	{ 
		window.clipboardData.clearData(); 
		window.clipboardData.setData("Text", txt); 
	} 
	else if(navigator.userAgent.indexOf("Opera") != -1)  
	{
		window.location = txt; 
	}  
	else if (window.netscape)  
	{
		try  
		{ 
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
		}  
		catch (e)  
		{ 
			alert("您的firefox安全限制限制您进行剪贴板操作，请在地址栏中输入“about:config”将“signed.applets.codebase_principal_support”设置为“true”之后重试"); 
			return false; 
		} 
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard); 
		if (!clip) 
		  return; 
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable); 
		if (!trans) 
		  return; 
		trans.addDataFlavor('text/unicode'); 
		var str = new Object(); 
		var len = new Object(); 
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); 
		var copytext = txt; 
		str.data = copytext; 
		trans.setTransferData("text/unicode",str,copytext.length*2); 
		var clipid = Components.interfaces.nsIClipboard; 
		if (!clip) 
		  return false; 
		clip.setData(trans,null,clipid.kGlobalClipboard); 
	} 
}
