﻿ //==========================================================================
//Trim()
String.prototype.trim = function() {
	return (this.replace(/^\s+|\s+$/g,""));
}
//Ltrim()
String.prototype.ltrim = function() {
	return (this.replace(/^\s*/,""));
}
//Rtrim()
String.prototype.rtrim = function() {
	return (this.replace(/\s*$/,""));
}
//Clipboard
String.prototype.copyClipboard = function () {
	if (!document.all) return; // IE only
	window.clipboardData.setData("Text",this);
}
//escape
String.prototype.encodeUrl = function (){ 
	return escape(this);
} 
//unescape
String.prototype.decodeUrl = function (){ 
	return unescape(this);
}
//getquery('id',0)
function getQuery(name,defaultValue) { 
	var vStr = defaultValue ;
	search = document.location.search.toLowerCase();
	search = search.substring(1,search.length);
	
	var arr=search.split("&");
	for(i=0;i<arr.length;i++)	{
	    var temp=arr[i].split("="); 
	    if (temp[0]==name) {
	        vStr  = temp[1]; 
	        break;
	    }
	}	
	return vStr;	 
}
//getquerystring(top.document.location.search,'id')
function getQueryString(search,name) { 
	var vStr="";
	search = search.toLowerCase();
	search = search.substring(1,search.length);
	
	var arr=search.split("&");
	for(i=0;i<arr.length;i++)	{
	    var temp=arr[i].split("="); 
	    if (temp[0]==name)	 {
	        vStr  = temp[1]; 
	        break;
	    }
	}	
	return vStr;	 
}

//Favorite
function addFavorite(url,title) {
    try {
        if(url==null)  url = document.location.href;
        if(title==null) title = document.title;        
        if (document.all){  
            window.external.addFavorite(url, title);  
        }else if (window.sidebar){  
            window.sidebar.addPanel(title, url, "");  
        }
    
    }catch(e)  { 
        alert("加入收藏失败，请使用Ctrl+D进行添加"); 
    }   
}

//home
function setHome(obj)
{
    var url = document.location.protocol + "//" + document.location.hostname ;
	if (document.all){  
        document.body.style.behavior = 'url(#default#homepage)';  
        document.body.setHomePage(url);  
    }else if (window.sidebar){  
        if (window.netscape){  
            try {  
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
            }catch (e) {  
                alert("该操作被浏览器拒绝");  
            }  
        }  
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);  
        prefs.setCharPref('browser.startup.homepage', vrl);  
    }
}
//Cookie
function getCookie(name) {
    var cookie_start = document.cookie.indexOf(name);
    var cookie_end = document.cookie.indexOf(";", cookie_start);
    if(cookie_start == -1){
        return "";
    }else{
      var length = cookie_end > cookie_start ? cookie_end : document.cookie.length;   
      var val =  document.cookie.substring(cookie_start + name.length + 1,length);   
      return  unescape(val);
    }
} 
function setCookie(cookieName, cookieValue, seconds, path, domain, secure) {       
    var expires = new Date();
    expires.setTime(expires.getTime() + seconds);
    document.cookie = escape(cookieName) + '=' + escape(cookieValue)
    + (expires ? '; expires=' + expires.toGMTString() : '')
    + (path ? '; path=' + path : '/')
    + (domain ? '; domain=' + domain : '')
    + (secure ? '; secure' : '');
}
function deleteCookie(name){
    var date = new Date();
    date.setTime(date.getTime() - 10000);
    document.cookie = name + "=a; expires=" + date.toGMTString();
}
function showHidden(id){    
    var obj = document.getElementById(id);
    if(obj) obj.style.display =obj.style.display=="none"?"":"none";
}



