// CustomizeGoogle Version 0.76
// http://cg.smir.de/

// Begin File "cg_browser.xul.js"
function do_customizegoogle(e) {
    var href = document.location.href;
    var text = "";

    // Google
    if (!(/\.(js|css|xml|rss|pdf)$/.test(href)) && !(/complete\/search/.test(href)) && ( /^http[s]?:\/\/.*?\.(google|googleproxy)\.[a-z\.]+\//.test(href) || /^http:\/\/(64\.233\.161\.99|64\.233\.161\.104|64\.233\.161\.105|64\.233\.161\.147|64\.233\.167\.99|64\.233\.167\.104|64\.233\.167\.147|64\.233\.171\.99|64\.233\.171\.104|64\.233\.171\.105|64\.233\.171\.147|64\.233\.179\.99|64\.233\.179\.99|64\.233\.183\.99|64\.233\.183\.104|64\.233\.185\.99|64\.233\.185\.104|64\.233\.187\.99|64\.233\.187\.104|64\.233\.189\.104|66\.102\.7\.104|66\.102\.7\.105|66\.102\.7\.147|66\.102\.9\.104|66\.102\.11\.104|216\.239\.37\.104|216\.239\.37\.105|216\.239\.37\.147|216\.239\.39\.104|216\.239\.53\.104|216\.239\.57\.98|216\.239\.57\.104|216\.239\.57\.105|216\.239\.57\.147|216\.239\.59\.104|216\.239\.59\.105|216\.239\.63\.104|66\.249\.81\.99)\//.test(href) )) {

        // Load filters
        var filterlist = cg_getPref("string","extensions.customizegoogle.misc.filterlist","");
        filterlist = filterlist.replace(/\s/g, " ");
        filterlist = filterlist.replace(/'/g, "\\'");
        //var filterlist = '';

        var disable = href.match(/#disable-userscript$/);

        text += "CustomizeGoogle.showAdPreviews();\n";

        // Google web search
        if (href.match(/^http:\/\/[^\/]+\/(search|cse|custom|unclesam|linux|bsd|mac|microsoft|intl)/)) {
			// only if necessarry
			if (!disable) {
                if (cg_getPref("bool","extensions.customizegoogle.web.remove-ads",false)) {
                    text += "CustomizeGoogle.removeSponsoredLinksById(new Array('tpa1','tpa2','tpa3','spa1','mbEnd','tads'));\n";
                    text += "CustomizeGoogle.removeSponsoredLinksRight();\n";
                    text += "CustomizeGoogle.removeInternalAds();\n";
                }
                if (cg_getPref("bool","extensions.customizegoogle.web.search-links",true)) {
                    text += "CustomizeGoogle.addOtherWebSearches('"+cg_createUrls('websearch')+"');\n";
                }
            }
            if (cg_getPref("bool","extensions.customizegoogle.web.removeclicktrack",true)) {
                text += "CustomizeGoogle.removeUrlClickTrack();\n";
            }
            if (cg_getPref("bool","extensions.customizegoogle.web.filter",true)) {
                text += "CustomizeGoogle.filterWebsitesFromSearch('"+filterlist+"','"+cg_getPref("string","extensions.customizegoogle.misc.filtercolor", "#aaaaaa")+"');\n";
            }
            if (cg_getPref("bool","extensions.customizegoogle.web.save",false)) {
                text += "CustomizeGoogle.addBookmarks('"+cg_getPref("string","extensions.customizegoogle.web.save-handler", "bookmark")+"');\n";
            }
            if (cg_getPref("bool","extensions.customizegoogle.web.counter",false)) {
                text += "CustomizeGoogle.addCountSearchResults();\n";
            }
            if (cg_getPref("bool","extensions.customizegoogle.web.history",false)) {
                text += "CustomizeGoogle.addWayBackMachine();\n";
            }
            if (cg_getPref("bool","extensions.customizegoogle.web.favicons",false)) {
				text += "CustomizeGoogle.addFavicons();\n";
			}
            if ("en-US" == 'zh-CN') {
                text += "CustomizeGoogle.bypassChineseFirewall();\n";
            }
        }
        // only if necessarry
		if (!disable) {
			// Google web search
			if (href.match(/^http:\/\/[^\/]+\/search/)) {
				if (cg_getPref("bool","extensions.customizegoogle.web.auto-page",false)) {
					text += "CustomizeGoogle.addAutoPager();\n";
				}
			}
			if ((href.match(/^http:\/\/[^\/]+\/$/) || href.match(/^http:\/\/[^\/]+\/(search|custom|firefox|webhp|unclesam|linux|bsd|mac|microsoft|ig)/))) {
				if (cg_getPref("bool","extensions.customizegoogle.web.focus",false)) {
					text += "CustomizeGoogle.addSearchFieldFocus();\n";
				}
				if (cg_getPref("bool","extensions.customizegoogle.web.suggest",true)) {
					text += "CustomizeGoogle.addGoogleSuggest();\n";
				}
			}
		}

        // Google image search
        if (href.match(/^http:\/\/[^\/]+\/images/)) {
            // only if necessarry
            if (!disable) {
                if (cg_getPref("bool","extensions.customizegoogle.images.image-links",true)) {
                    text += "CustomizeGoogle.addOtherImageSearches('"+cg_createUrls('imagesearch')+"');\n";
                }
                if (cg_getPref("bool","extensions.customizegoogle.images.auto-page",false)) {
                    text += "CustomizeGoogle.addAutoPager();\n";
                }
            }
            if (cg_getPref("bool","extensions.customizegoogle.images.rewrite-links",true)) {
                text += "CustomizeGoogle.pointLinksToImages();\n";
            }
        }

        // Google Blog search
		if (href.match(/^http:\/\/[^\/]+\/blogsearch/)) {
			if (cg_getPref("bool","extensions.customizegoogle.blogs.blog-links",true)) {
				text += "CustomizeGoogle.addOtherBlogSearches('"+cg_createUrls('blogsearch')+"');\n";
			}
			if (cg_getPref("bool","extensions.customizegoogle.blogs.removeclicktrack",false)) {
				text += "CustomizeGoogle.removeUrlClickTrack();\n";
			}
		}

        // Google Groups
        if (href.match(/^http:\/\/[^\/]+\/group\//)) {
            if (cg_getPref("bool","extensions.customizegoogle.groups.remove-ads",false)) {
                text += "CustomizeGoogle.removeSponsoredLinksFrame();\n";
            }
        }
        if (href.match(/^http:\/\/[^\/]+\/groups/)) {
            if (cg_getPref("bool","extensions.customizegoogle.groups.remove-ads",false)) {
                text += "CustomizeGoogle.removeSponsoredLinksRight();\n";
            }
        }

        // Google News
        if (href.match(/^http:\/\/[^\/]+\/news/)) {
            if (cg_getPref("bool","extensions.customizegoogle.news.news-links",true)) {
                text += "CustomizeGoogle.addOtherNewsSearches('"+cg_createUrls('newssearch')+"');\n";
            }
        }
        if (href.match(/^http:\/\/[^\/]+\/(news|nwshp)/) || href.match(/^http:\/\/news\.google\./)) {
            if (cg_getPref("bool","extensions.customizegoogle.news.filter",false)) {
                text += "CustomizeGoogle.filterWebsitesFromNews('"+filterlist+"');\n";
            }
            if (cg_getPref("bool","extensions.customizegoogle.news.filter",false)) {
				text += "CustomizeGoogle.filterWebsitesFromNews('"+filterlist+"','"+cg_getPref("string","extensions.customizegoogle.misc.filtercolor", "#aaaaaa")+"');\n";
			}
        }

        // Google Shopping
        if (href.match(/^http:\/\/[^\/]+\/(froogle|products)/)) {
			if (cg_getPref("bool","extensions.customizegoogle.froogle.remove-ads",false)) {
				text += "CustomizeGoogle.removeSponsoredLinksProducts();\n";
			}
			if (cg_getPref("bool","extensions.customizegoogle.froogle.products-links",true)) {
				text += "CustomizeGoogle.addOtherProductSearches('"+cg_createUrls('productsearch')+"');\n";
			}
		}

        // Reader
		if (href.match(/^http:\/\/[^\/]+\/reader/)) {
			if (cg_getPref("bool","extensions.customizegoogle.reader.secure",false)) {
				text += "CustomizeGoogle.secureGoogle();\n";
			}
		}

        // Notebook
		if (href.match(/^http:\/\/[^\/]+\/notebook/)) {
			//if (cg_getPref("bool","extensions.customizegoogle.reader.secure",false)) {
				//text += "CustomizeGoogle.secureGoogle();\n";
			//}
		}

		// History
		if (href.match(/^http:\/\/[^\/]+\/(history|bookmarks)/)) {
			if (cg_getPref("bool","extensions.customizegoogle.history.secure",false)) {
				text += "CustomizeGoogle.secureGoogle();\n";
			}
		}

        // Google Answers
        if (href.match(/^http:\/\/[^\/]+\/answers/)) {
            if (cg_getPref("bool","extensions.customizegoogle.answers.remove-ads",false)) {
                text += "CustomizeGoogle.removeSponsoredLinksFrame();\n";
            }
        }

        // Google Book Search
        if (href.match(/^http:\/\/[^\/]+\/(print|books)/)) {
            if (cg_getPref("bool","extensions.customizegoogle.print.remove-ads",false)) {
                text += "CustomizeGoogle.removeSponsoredLinksRight();\n";
                text += "CustomizeGoogle.removeSponsoredLinksPrint();\n";
                text += "CustomizeGoogle.removeSponsoredLinksById(new Array('buy','buy_content'));\n";
            }
            if (cg_getPref("bool","extensions.customizegoogle.print.restore-menu",true)) {
                text += "CustomizeGoogle.restoreGooglePrint();\n";
            }
            if (cg_getPref("bool","extensions.customizegoogle.print.book-links",true)) {
                text += "CustomizeGoogle.addOtherBookReviews('"+cg_createUrls('booksearch')+"');\n";
            }
        }

        // Google Calendar
        if (href.match(/^http:\/\/[^\/]+\/calendar/)) {
            if (cg_getPref("bool","extensions.customizegoogle.calendar.secure",false)) {
                text += "CustomizeGoogle.secureGoogle();\n";
            }
        }

        // Google Video Search
    	if (href.match(/^http:\/\/[^\/]+\/videosearch/)) {
			if (cg_getPref("bool","extensions.customizegoogle.video.video-links",true)) {
				text += "CustomizeGoogle.addOtherVideoSearches('"+cg_createUrls('videosearch')+"');\n";
			}
		}

        // Gmail
        if (href.match(/^http[s]?:\/\/g?mail\.google\.[a-z\.]+\/(g?mail|hosted|a\/)/)) {
			if (cg_getPref("bool","extensions.customizegoogle.gmail.secure",true)) {
				text += "CustomizeGoogle.secureGoogle();\n";
			}
			if (cg_getPref("bool","extensions.customizegoogle.gmail.remove-ads",false)) {
				// Gmail 1.0
        		text += "CustomizeGoogle.removeSponsoredLinksByIdGmail(new Array('ra','rc','rp','rb'));\n";
				// Gmail 2.0
				text += "CustomizeGoogle.removeSponsoredLinksGmail();\n";
			}
			if (cg_getPref("bool","extensions.customizegoogle.gmail.hidespam",false)) {
				text += "CustomizeGoogle.hideGmailSpam('"+stringbundle.getString("gmail-spam")+"');\n";
			}
			if (cg_getPref("bool","extensions.customizegoogle.gmail.monospace",false)) {
				text += "CustomizeGoogle.useMonoSpaceFont();\n";
			}
			if (cg_getPref("bool","extensions.customizegoogle.gmail.hidechat",false)) {
				// Gmail 1.0
				text += "CustomizeGoogle.hideID('nb_2');\n";
				// Gmail 2.0
				text += "CustomizeGoogle.hideClass('a3hTGd');\n";
			}
			if (cg_getPref("bool","extensions.customizegoogle.gmail.hideinvite",false)) {
				text += "CustomizeGoogle.hideID('nb_1');\n";
				text += "CustomizeGoogle.hideID('ip');\n";
				// Gmail 2.0
				text += "CustomizeGoogle.hideClass('I94Sdc');\n";
			}
		}

        // Google Maps
        if (href.match(/^http:\/\/[^\/]+\/(local|maphp)/) || href.match(/^http:\/\/(local|maps)\.google\.[a-z\.]+\//)) {
            if (cg_getPref("bool","extensions.customizegoogle.local.remove-ads",false)) {
                text += "CustomizeGoogle.removeSponsoredLinksLocal();\n";
            }
        }

        // Docs & Spreadsheets
        if (href.match(/^http:\/\/(docs|spreadsheets)\.google\.[a-z\.]+\//)) {
		    if (cg_getPref("bool","extensions.customizegoogle.docs.secure",false)) {
                text += "CustomizeGoogle.secureGoogle();\n";
            }
        }

        // Cookies
        if (href.match(/^http:\/\/[^\/]+\/(search)/)) {
		    if (cg_getPref("bool","extensions.customizegoogle.misc.anonymizeUID",false)) {
                text += "CustomizeGoogle.anonymizeGoogleUID();\n";
            }
        }
        if (href.match(/google\.[a-z\.]+\//)) {
			if (cg_getPref("bool","extensions.customizegoogle.cookies.enableDefaultPreferences",false)) {
				text += "CustomizeGoogle.defaultPreferences(";
				if (cg_getPref("bool","extensions.customizegoogle.cookies.enableSafeSearch",false)) {
					text += "'" + cg_getPref("string","extensions.customizegoogle.cookies.SafeSearch","") + "',";
				} else { text += "'',";	}
				if (cg_getPref("bool","extensions.customizegoogle.cookies.enableSearchLanguage",false)) {
					if (cg_getPref("string","extensions.customizegoogle.cookies.searchAnyOrSelected","any")=="any") {
						text += "'empty',";
					} else {
						text += "'" + cg_getPref("string","extensions.customizegoogle.cookies.searchLanguage","") + "',";
					}
				} else { text += "'',";	}
				if (cg_getPref("bool","extensions.customizegoogle.cookies.enableInterfaceLanguage",false)) {
					text += "'" + cg_getPref("string","extensions.customizegoogle.cookies.interfaceLanguage","") + "',";
				} else { text += "'',";	}
				if (cg_getPref("bool","extensions.customizegoogle.cookies.enableResultsPerPage",false)) {
					text += "'" + cg_getPref("string","extensions.customizegoogle.cookies.ResultsPerPage","") + "',";
				} else { text += "'',";	}
				if (cg_getPref("bool","extensions.customizegoogle.cookies.enableResultsWindow",false)) {
					text += "'" + (cg_getPref("bool","extensions.customizegoogle.cookies.OpenSearchResultsInNewWindow",false)?"1":"empty") + "',";
				} else { text += "'',";	}
				if (cg_getPref("bool","extensions.customizegoogle.cookies.enableSuggest",false)) {
					text += "'" + (cg_getPref("bool","extensions.customizegoogle.cookies.suggest",false)?"1":"empty") + "'";
				} else { text += "''";	}
				text += ");\n";
			}
		}
    }
    // Google Cache
	if (href.match(/\/search\?q=cache:/)) {
		if (cg_getPref("bool","extensions.customizegoogle.cache.continue",false)) {
			text += "CustomizeGoogle.cacheContinue();\n";
		}
	}
    if (!(/\.(js|css|xml|rss|pdf)$/.test(href))) {
        if (cg_getPref("bool","extensions.customizegoogle.misc.removeGoogleAnalytics",false)) {
            text += "CustomizeGoogle.anonymizeGoogleAnalytics();\n";
        }
    }

    if (text.length > 0) {
        try {
            eval( text );
        } catch (e ) {}
    }
}
function cg_getPref(aPrefType, aPrefString, aDefaultValue){
    aPrefString = str_replace( "extensions.customizegoogle.", "", aPrefString );

    try {
      switch(aPrefType) {
        case "bool":
          if( !isBoolean( cgPrefs[aPrefString] ) )
            return aDefaultValue;

          return cgPrefs[aPrefString];
        case "int":
          return parseInt( cgPrefs[aPrefString] );
        case "localizedstring":
        case "color":
        case "string":
        default:
          return cgPrefs[aPrefString];
      }
    } catch(e) {
      return aDefaultValue;
    }
}
function cg_createUrls(type) {
    var s = '';
    for( var i in cg_urls )
    {
        if( cg_urls[i].type == type )
            s += '<a href="'+cg_urls[i].url+'">'+cg_urls[i].name+'</a>, ';
    }
    if (s.length > 0) {
        s = s.substring(0,s.length-2);
    }
    return s;
}

var googlecustomized = false;

window.addEventListener("load", function() {
    if( !googlecustomized ) {
        googlecustomized = true;
        do_customizegoogle();
    }
}, false);

// End File "cg_browser.xul.js"

// Begin File "cg_javascript.js"
// BEGIN changed by Smir

var get_search_form = function() {
    var val = document.evaluate("//form[contains(@action, '/search')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue ||
              document.evaluate("//form[contains(@action, '/custom')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue ||
              document.evaluate("//form[contains(@action, '/unclesam')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue ||
              document.evaluate("//form[contains(@action, '/linux')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue ||
              document.evaluate("//form[contains(@action, '/bsd')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue ||
              document.evaluate("//form[contains(@action, '/mac')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue ||
              document.evaluate("//form[contains(@action, '/microsoft')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    return val;
};

// END changed by Smir

var get_random_id = function(size) {
    var chars = new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
    var id = '';
    for (var i=0;i<size;++i) {
        id += chars[Math.round(Math.random()*(chars.length-1))];
    }
    return id;
};
var selectAllNodes = function(doc, context, xpath) {
   var nodes = doc.evaluate(xpath, context, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
   var result = new Array( nodes.snapshotLength );
   for (var x=0; x<result.length; x++) {
      result[x] = nodes.snapshotItem(x);
   }
   return result;
};

var createLinks = function() {
    var googFonts = selectAllNodes(document, document.body, "//FONT[contains(@color,'#008000')]");
    var googLinks = selectAllNodes(document, document.body, "//A[contains(@href,'/imgres?imgurl=')][contains(@href,'&imgrefurl=')]");

    for (var x=0; x<googLinks.length; x++) {
        var target = googLinks[x].getAttribute("target");
        if (!target) {
            target = "";
        }

        // /imgres?imgurl=http://www.apnakarachi.com/entertainment/model/test.asp%3Fpic%3D1%26id%3Dkiziman&imgrefurl=http://www.apnakarachi.com/entertainment/model/model.asp%3Ffn%3Dviewprofile.asp%26id%3Dkiziman%26mw%3Du&h=447&w=301&sz=26&tbnid=Qcn-IrmRofMJ:&tbnh=124&tbnw=83&hl=en&start=5&prev=/images%3Fq%3Dtest%2Binurl:asp%26svnum%3D100%26hl%3Den%26lr%3D%26safe%3Doff%26sa%3DN
        var gmatch   = googLinks[x].href.match( /\/imgres\?imgurl\=(.*?)\&imgrefurl\=/ );
        var urlmatch = googLinks[x].href.match(/\&imgrefurl\=(.*?)\&h=/);
        if (googFonts[x].innerHTML.length==0) {
            googFonts[x].innerHTML = "...";
        }

        if (gmatch) {
            googFonts[x].innerHTML="<a href=\""+unescape(urlmatch[1])+"\" target=\""+target+"\">"+googFonts[x].innerHTML+"</a>";
            googLinks[x].setAttribute("class", "ext");

            // make compatible with piclens
            // googLinks[x].href = unescape(gmatch[1]);
            //googLinks[x].setAttribute('onclick', "document.location.href='" + unescape(gmatch[1]) + "';return false;")
            googLinks[x].setAttribute('onmouseup', "this.href='" + unescape(gmatch[1]) + "';return true;")
        }
    }
};

// start auto scroll
var startNr;
var itemsQuantity;
var storageContainer;
var query;
var requested;

var Remain = {
    valueOf : function() {
        var sc = document.documentElement.scrollTop; //document.body.scrollTop;
        var wh = window.innerHeight ? window.innerHeight : document.body.clientHeight;
        var total = (document.body.scrollHeight - wh);
        return total - sc;
    }
};

var watch_scroll = function() {
    var self = arguments.callee;
    if (Remain < 500) {
        do_request();
    }
};

var do_request = function() {
    if (requested == startNr) return;
    requested = startNr;

    var iframe = document.createElement("iframe");
    iframe.width = document.body.clientWidth;
    iframe.height = 1;
    iframe.style.margin = "0 0 0 -10000px";
    iframe.style.position = "absolute";
    iframe.style.top = 0;
    iframe.style.left = 0;
    document.body.appendChild(iframe);
    iframe.addEventListener("load", function() {
        // delay this for opera 9.5...
        window.setTimeout( function() {
            var isNextExist = iframe.contentDocument.evaluate("//div[@id='nn']", iframe.contentDocument.body, null, 9, null).singleNodeValue || iframe.contentDocument.evaluate("//span[@id='nn']", iframe.contentDocument.body, null, 9, null).singleNodeValue  || document.evaluate("//span[@class='csb ch']/parent::a", document, null, 9, null).singleNodeValue;;
			var list = iframe.contentDocument.evaluate("//li[@class='g']", iframe.contentDocument.body, null, 6, null);
            if (list.snapshotLength==0) {
				// if images
                list = iframe.contentDocument.evaluate("//div[@id='ImgContent']/table/tbody/tr", iframe.contentDocument.body, null, 6, null);
            }

            for (var i = 0; i < list.snapshotLength; i++) {
				var oldNode = list.snapshotItem(i);
				var newNode = document.importNode(oldNode,true);
				storageContainer.appendChild(newNode);
			}
            if (!!isNextExist) {
                startNr += itemsQuantity;
            } else {
                // add option to remove filter
                var removefilter = iframe.contentDocument.evaluate("//a[contains(@href,'filter=0')]/parent::i/parent::p", iframe.contentDocument.body, null, 9, null).singleNodeValue;
                if (removefilter) {
                    storageContainer.appendChild(removefilter);
                }
                var n = storageContainer;
                do {
                    while (n.nextSibling) {
                        n = n.nextSibling;
                        if (n.tagName != 'SCRIPT' && n.id != 'navbar' && n.id != 'nav' && n.style) n.style.display = 'block';
                    }
                    n = n.parentNode;
                } while (n);

            }
            iframe.src = "";
            document.body.removeChild(iframe);
        }, 200 );
    }, false);
    iframe.src = "http://"+location.host+location.pathname+query.replace(/start=\d*/,"start=" + startNr) + "#disable-userscript";
};
// end autoscroll


var CustomizeGoogle = {

	t: function(name) {
		try {
			return cg_textarr[name];
		} catch (e) {
			return name;
		}
	},

	truncateURL: function(url, maxChars) {
		if (url.length <= maxChars) return url;
		var newurl = "";
		for (var i = 0; i <= url.length; i+= maxChars + 1) {
			newurl += url.substring(i, i+maxChars);
			if (i+maxChars <= url.length)
				newurl += "<wbr>";
		}
		return newurl;
	},

    addAutoPager: function() {
        window.onresize = function() { return true; }
        var next = document.evaluate("//div[@id='nn']/parent::a", document, null, 9, null).singleNodeValue || document.evaluate("//span[@id='nn']/parent::a", document, null, 9, null).singleNodeValue || document.evaluate("//span[@class='csb ch']/parent::a", document, null, 9, null).singleNodeValue;
		// web search || image search
		storageContainer = document.evaluate("//li[@class='g']/parent::ol", document, null, 9, null).singleNodeValue || document.evaluate("//div[@id='ImgContent']/table/tbody", document, null, 9, null).singleNodeValue;

        // if next page and result
		if(next && storageContainer) {
			query = next.href.substr(next.href.indexOf("?"));
			startNr = (query.match(/start=(\d*)/))[1] - 0;
			var tmp = query.match(/num=(\d*)/);
			itemsQuantity = tmp ? (tmp[1] - 0) : 10;
			watch_scroll();
            document.addEventListener( "scroll", watch_scroll, false );
			var n = storageContainer;
            do {
                while (n.nextSibling) {
                    n = n.nextSibling;
                    if (n.style) n.style.display = 'none';
                }
                n = n.parentNode;
            } while (n);
            var navbar = document.getElementById('navbar') || document.getElementById('nav');
            if (navbar) navbar.style.display = 'none';
        }
	},

	addGlobalStyle: function(css) {
    	var style = document.createElement("style");
	    style.type = "text/css";
        style.innerHTML = css;
        document.getElementsByTagName('head')[0].appendChild(style);
	},

    cacheContinue: function() {
		var curl = window.location.href;
		var res = selectAllNodes(document, document.body.childNodes[1], ".//a[@href]");
		if (!document.title.match(/^cache/)) {
			for (var x=0; x<res.length; x++) {
				if (res[x].protocol == 'http:' || res[x].protocol == 'https:') {
					res[x].href = curl.replace(/cache:.*?\+/,'cache:'+encodeURIComponent(res[x].href)+'+');
				}
			}
		} else {
			var match = curl.match(/cache:(.*?)\+/);
			if (match) {
				window.location.href = decodeURIComponent(match[1]);
			}
		}
	},

    removeInternalAds: function() {
		var toolbar = document.evaluate("//a[contains(@href,'http://tools.google.com/firefox')]/ancestor::table[@cellpadding='9'][@border='0']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
	    if (toolbar) {
			toolbar.parentNode.removeChild(toolbar);
	    }
	},


	removeSponsoredLinksById: function(ids) {
		for(var i = 0; i < ids.length; i++) {
	    	var ad = document.getElementById(ids[i]);
			while (ad && ad.parentNode) {
				ad.parentNode.removeChild(ad);
				ad = document.getElementById(ids[i]);
			}
		}
	},

	removeSponsoredLinksByIdGmail: function(ids) {
		for(var i = 0; i < ids.length; i++) {
	    	var ad = document.getElementById(ids[i]);
			if (ad && ad.parentNode && (ad.parentNode.className == 'rh' || ad.parentNode.className == 'rhs')) {
				ad.parentNode.removeChild(ad);
			}
		}
	},

    removeSponsoredLinksGmail: function(ids) {
		this.addGlobalStyle('.slwyWc { display: none !important }');
	},

	removeSponsoredLinksFrame: function() {
		this.addGlobalStyle('iframe[name="google_ads_frame"] { display: none ! important }');
	},

	isRegExp: function(filter) {
		return filter.match(/^\/.+\/[i]?$/);
	},

	convertToRegExp: function(pattern) {
		var s = new String(pattern);
		var res = new String("^");
		for (var i = 0 ; i < s.length ; i++) {
			switch(s[i]) {
		        case '*' :
		          res += ".*";
		             break;
		        case '.' :
		        case '?' :
		        case '^' :
		        case '$' :
		        case '+' :
		        case '{' :
		        case '[' :
		        case '|' :
		        case '(' :
		        case ')' :
		        case ']' :
		           res += "\\" + s[i];
		           break;
		        case '\\' :
		           res += "\\\\";
		           break;
		        case ' ' :
		           // Remove spaces from URLs.
		           break;
		        default :
		           res += s[i];
		           break;
		     }
	     }
		 return res + '$';
	},

    removeSponsoredLinksRight: function() {
		var ra = document.evaluate("//table[@align=\"right\"][contains(@width, '25%')][@border=\"0\"]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
	    if (ra) {
			ra.parentNode.removeChild(ra);
	    } else {
			// update 2008-03-13
			ra = document.evaluate("//table[@align=\"right\"][contains(@width, '30%')][@border=\"0\"]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
		    if (ra) {
				ra.parentNode.removeChild(ra);
	    	}
		}
	},

	removeSponsoredLinksProducts: function() {
		var res = selectAllNodes(document, document.body, "//table[contains(@width, '100%')][@bgcolor=\"#e5ecf9\"]");
		for (var x=0; x<res.length; x++) {
			res[x].parentNode.removeChild(res[x]);
		}

		var fr = document.evaluate("//table[@align=\"right\"][@bgcolor=\"#ffffff\"][@border=\"0\"][@cellspacing=\"0\"][@cellpadding=\"0\"]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
		if (fr) {

			fr.parentNode.removeChild(fr);
		}
	},

	removeSponsoredLinksLocal: function() {
		var s = document.createElement("style");
		s.setAttribute("type","text/css");
 		s.innerHTML=(".ads{display: none !important;}");
		document.body.appendChild(s);
	},

	removeSponsoredLinksPrint: function() {
        var ra = document.evaluate("//table[@class='lads']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
	    if (ra) {
			ra.parentNode.removeChild(ra);
	    }
        var ta = document.evaluate("//td[@class='btblinks']/ancestor::table[@style='margin-bottom: 0.8em;']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
	    if (ta) {
			ta.parentNode.removeChild(ta);
		}
    	var ad = document.getElementById('bottom_ad');
		if (ad) {
			ad.parentNode.removeChild(ad);
		}
	},

    hideGmailSpam: function(spamname) {
		if (spamname) {
			spamname = spamname.replace(/^\s*|\s*$/g,"");
			this.addGlobalStyle('#ds_spam b {visibility: hidden;}');
			this.addGlobalStyle('#ds_spam b::before {content: "'+spamname+'"; visibility: visible; font-weight: normal;}');
			this.addGlobalStyle("span#ds_spam b,.ACpQre a[href$='#spam']{visibility:hidden;}span#ds_spam b::before,.ACpQre a[href$='#spam']::before{content:'"+spamname+"';visibility:visible;font-weight:400;text-decoration:underline;}");
		}
	},

    hideID: function(id) {
		var s = document.createElement("style");
		s.setAttribute("type","text/css");
 		s.innerHTML=("#" + id + "{display: none !important;}");
		document.body.appendChild(s);
	},

    hideClass: function(id) {
		this.addGlobalStyle("." + id + "{display: none !important;}");
	},

	useMonoSpaceFont: function() {
 		this.addGlobalStyle(".mb, .tb, .compose .mi, div.msg, .ArwC7c, .iE5Yyc {font-family: MonoSpace !important; font-size: 90% !important; }");
	},

    addOtherWebSearches: function(urls) {
        var header = document.evaluate("//table[@class='t bt'][contains(@width, '100%')][@cellspacing='0'][@cellpadding='0']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue || document.evaluate("//div[@class='bb bt t']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue || document.evaluate("//div[@id='ssb']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
	    if (!header) return;
        if (!document.gs || !document.gs.q) return;
		var q = encodeURIComponent(document.gs.q.value);
        var q2 = escape(document.gs.q.value);
		if (!q) return;
	    var other = document.createElement('div');
		other.setAttribute("style", "font-size:small;padding:4px 0 0 0;");
		if (document.cookie && document.cookie.match(/:NW=1:/)) {
			urls = urls.replace(/a href/ig, "a target=nw href");
		}
		other.innerHTML = this.t("try_search") + ' ' + urls.replace(/\[QUERY\]/g, q).replace(/\[QUERYISO88591\]/g, q2);
    	header.parentNode.insertBefore(other, header.nextSibling);
	},

    addOtherImageSearches: function(urls) {
	    var table = document.evaluate("//table[@class='t bt'][contains(@width, '100%')][@cellspacing='0'][@cellpadding='0']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
		if (!table) return;
		if (!document.gs || !document.gs.q) return;
	    var q = encodeURIComponent(document.gs.q.value);
		var q2 = escape(document.gs.q.value);

		if (document.cookie.match(/:NW=1:/)) {
			urls = urls.replace(/a href/ig, "a target=nw href");
		}

	    var other = document.createElement('div');
		other.setAttribute("style", "font-size:small;padding:4px 0 0 0;");
		other.innerHTML = this.t("try_search") + ' ' + urls.replace(/\[QUERY\]/g, q).replace(/\[QUERYISO88591\]/g, q2);

		table.parentNode.insertBefore(other, table.nextSibling);
	},

	addOtherBlogSearches: function(urls) {
	    var table = document.evaluate("//table[@class='ttt'][contains(@width, '100%')][@cellspacing='0'][@cellpadding='0']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
		if (!table) return;
		if (!document.gs || !document.gs.q) return;
	    var q = encodeURIComponent(document.gs.q.value);
		var q2 = escape(document.gs.q.value);

		if (document.cookie.match(/:NW=1:/)) {
			urls = urls.replace(/a href/ig, "a target=nw href");
		}

	    var other = document.createElement('div');
		other.setAttribute("style", "font-size:small;padding:4px 0 0 0;");
		other.innerHTML = this.t("try_search") + ' ' + urls.replace(/\[QUERY\]/g, q).replace(/\[QUERYISO88591\]/g, q2);

		table.parentNode.insertBefore(other, table.nextSibling);
	},

	addOtherVideoSearches: function(urls) {
	    var table = document.evaluate("//table[@id='resultsheadertable']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
		if (!table) return;
		if (!document.f || !document.f.q) return;
	    var q = encodeURIComponent(document.f.q.value);
		var q2 = escape(document.f.q.value);
		if (document.cookie.match(/:NW=1:/)) {
			urls = urls.replace(/a href/ig, "a target=nw href");
		}

	    var other = document.createElement('div');
		other.setAttribute("style", "font-size:small;padding:4px 0 4px 5px;");
		other.innerHTML = this.t("try_search") + ' ' + urls.replace(/\[QUERY\]/g, q).replace(/\[QUERYISO88591\]/g, q2);

		table.parentNode.insertBefore(other, table.nextSibling);
	},

	addOtherVideoSearches: function(urls) {
        var table = document.evaluate("//table[@id='resultsheadertable']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
		if (!table) return;
		if (!document.f || !document.f.q) return;
	    var q = encodeURIComponent(document.f.q.value);
		var q2 = escape(document.f.q.value);
		if (document.cookie.match(/:NW=1:/)) {
			urls = urls.replace(/a href/ig, "a target=nw href");
		}

	    var other = document.createElement('div');
		other.setAttribute("style", "font-size:small;padding:4px 0 4px 5px;");
		other.innerHTML = this.t("try_search") + ' ' + urls.replace(/\[QUERY\]/g, q).replace(/\[QUERYISO88591\]/g, q2);

		table.parentNode.insertBefore(other, table.nextSibling);
	},

	addOtherNewsSearches: function(urls) {
        var table = document.evaluate("//font[@class='ks']/ancestor::table[@cellspacing='0'][@cellpadding='0'][@border='0'][contains(@width,'100%')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
	    if (!table) return;
		if (!document.gs || !document.gs.q) return;
	    var q = encodeURIComponent(document.gs.q.value);
		var q2 = escape(document.gs.q.value);

		if (document.cookie.match(/:NW=1:/)) {
			urls = urls.replace(/a href/ig, "a target=nw href");
		}

	    var other = document.createElement('div');
		other.setAttribute("style", "font-size:small;padding:4px 0 4px 5px;");
		other.innerHTML = this.t("try_search") + ' ' + urls.replace(/\[QUERY\]/g, q).replace(/\[QUERYISO88591\]/g, q2);

	    table.parentNode.insertBefore(other, table.nextSibling);
	},

	addOtherProductSearches: function(urls) {
        var table = document.evaluate("//table[@id='ps-titlebar'][@cellspacing='0']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
		if (!table) return;
		var frm = document.gs || document.f;
		if (!frm || !frm.q) return;

	    var q = encodeURIComponent(frm.q.value);
		var q2 = escape(frm.q.value);

		if (document.cookie.match(/:NW=1:/)) {
			urls = urls.replace(/a href/ig, "a target=nw href");
		}

	    var other = document.createElement('div');
		other.setAttribute("style", "font-size:small;padding:4px 0 4px 5px;");
		other.innerHTML = this.t("try_search") + ' ' + urls.replace(/\[QUERY\]/g, q).replace(/\[QUERYISO88591\]/g, q2);

	    table.parentNode.insertBefore(other, table.nextSibling);
	},

    addFavicons: function() {
		var list = document.evaluate("//li[@class='g']/descendant::h3/a", document, null, 6, null);
		for (var i=0; i < list.snapshotLength; ++i) {
        	var a = list.snapshotItem(i);

			var url = "data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%10%00%00%00%10%08%06%00%00%00%1F%F3%FFa%00%00%00%19tEXtSoftware%00Adobe%20ImageReadyq%C9e%3C%00%00%00%EDIDATx%DA%A4%93K%0A%830%10%86'%A1%1B%1F%E0%CA%13%E8%D6%95'%D1%A5%97%F4%1C%0A%5Dy%02%2F%E0%0B%1F%08%82%25%A1%13%F2%B2%B5t%60H%C8%FC%FF7%1A%1Dr%9E'%FC%13%0F%DC%94e%99%EA%C5y%9E%C1%F7%7D%BE%CF%B2%EC%F9%11%F0%16)%C5m%DB%C0q%1CX%D7%15%9A%A6I%93%241%20T%3F%60b%CCeY%F8%99%EB%BA%10E%11%B4m%9B~%05%5C%05%83%84ah%BC%AA%00%DC%B9L%06%D1u%E2%0E%A6i%B2%9A%AA%AA%E2%2B!%04(%A5P%D75%E4yn%02%C6q%B4%02%E28%E6f%CC%20%08%ECO%D0%F7%BDa%F6%3C%8Fw%C5%EE%2C%F6%7D%B7%03%BA%AES%0AhB%00%A6%AE%13%80a%18%D4%CF%23%99q%B5%E9%04%E08%0E%C5%2Cw%C5%D4u%97%FF%81l%92%BB%DB%82%DA%CC%F2z%7B%98X%14E%F1%F34%92%7F%C7%F9%25%C0%00%F6%19T%09%A3%B3%D1%A8%00%00%00%00IEND%AEB%60%82";
			if (a.href.match(/\/interstitial\?url=/)) {
				url = "data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%10%00%00%00%10%08%06%00%00%00%1F%F3%FFa%00%00%00%04gAMA%00%00%AF%C87%05%8A%E9%00%00%00%19tEXtSoftware%00Adobe%20ImageReadyq%C9e%3C%00%00%02OIDAT8%CB%A5%93%CBK%94a%14%C6%1F%BF%D4%09%95%E9SA%9C%11oc%8A%94%AB%886%E1%C6.PD%04C%8B%C4%0B%B8%EA%82%F4%17D%10%15%D5%A2%CD%40%ABZx%C1h1%E0N%10%8C%A2%22%A4%85C%8DN%A9%A3%98%3Av%19%9D%14%9Df%E6%7D%CF%F3%B6%B0%BE%19%B36uv%EF%E1%9C%DFy%0E%EFy%F2%8C1%F8%9F%C8%FF%3D!%B7%AF4%D0%98vCv%91%AC%24%09%92%9FH%F6S8d%DF%E9%8F%E6%D6%E7%E5*P%B7.%FB%0DM%60%2B%AF%D0S%D8%B0%1F%F9n%F7v~c%1D%C9H%04Vr%7D%85%94%DE%8A%FBO%82%BB%00%99%9B%97%FC%86%ECKW%D4%14%1755Bb%0B%60l%01%00%60yj%60yk%B11%15Aj%FA%DD%16E%BA%AB%1F%0C%07%1D%40%FA%C6E%1F%C9%17%99%CA%1AoqS%132%AFF%01%00E%D7%1E%02%006%AF%F7%004(l%3D%89%F5%F0%246%23%131!%5B%F7%3F%1A%99%B3%00%40Dw%24-W%B6%D9%18%18fW%A3%26D%1B%24%C7F%E0n%3E%00SR%EE%D5Ju%00%80%05%00Z%EBNWc%23di%1E%86%06%14%03%A3%B9%03%40%25%90%0C%91%9E%8Bb_s%0B%94R%9D%B9%80%AA%02%DB%86%5E%9C%87%D1t%26%3A%3F%93!Dm%E7S%B3Q%14%D8e%D0JWe%01J%C3%88q%1A%7FMT%D3%E1%EC%0A%EA'D%08%08%A1%B5B%8E%02%B5%9C%8E%AF%C1%F2%D4%3ARE%11%DF_%8Eas%F8%B13%9D%8A%C8%AF%AEC2%1E%87Vz9W%C1%C0%B7%F0%5B%EC%F1%D69%C5%A2%08w%CFU%94%9C%BB%00*B4!B%B8%EA%7C%F8%12z%03%AD%F5%80%03PJ%0DfVc%B1%C4d%18Em%A7%1C%C8Z%E0%1EV%03w!%B2%FD%B6O%9F%C1%D7p%08%89%C5%99%98%D6zp%C7!Mu%1E%F3S%A4%CF%3Ex%A4%B8%B4%B9%05%A9%F99%A4f%A30%C6%C0U%EF%83%AB%DE%87x8%84%8F%AFG%B7Hv%B7%3D%7D%1F%DCu%CA%A1%F3G%FDB%06%F6%96y%3D%E5-%87%E0%B2Ka%0C%90J%AC%E1%F3%C48%12K%B3%2B%24%7B%8F%3F%FB%10%FC%A3%17%00%60%FC%EC%E1%06%92%ED%14v%91%B2%D3L%E4%D0%89%E73%7F7%D3%BF%C4%0F%95%D1%AFLj%05%EB%FF%00%00%00%00IEND%AEB%60%82";
			}

			var img    = new Image();
			img.src    = url;
			img.setAttribute("style","height:16px;width:16px;border:0;padding-top:2px;padding-right:4px;display:block;float:left;");
			a.parentNode.parentNode.insertBefore(img, a.parentNode.nextSibling);
			(function(a,img){
			if (!a.href.match(/^https/) && !a.href.match(/\/interstitial\?url=/)) {
				var url = "http://"+a.href.split('/')[2]+"/favicon.ico";
				var tmpimg = new Image();
				tmpimg.addEventListener("load",function() { img.src = url; },false);
				tmpimg.src = url;
			}
			})(a,img);
		}
	},

	removeUrlClickTrack: function() {
		var match = null;
		var a = selectAllNodes(document,document.body,"//a[@href]");
		for (var y=0; y<a.length; y++) {
			// if internal
			match = a[y].href.match(/^http:\/\/[^\/]*google\.[a-z\.]+\/(aclk|pagead|url).+?(url|q|adurl)=(http[s]?:[^&]+)/i);
			if (match) {
				a[y].href = unescape(match[3]);
			}
			// if external
			if (a[y].href.match(/^(http|https|ftp):\/\//) && !a[y].href.match(/google\.[a-z\.]+\//)) {
				a[y].onmousedown = function() { return true; }
			}
		}
		// sneaky google sometimes bypass the above, this will fix it
		window.clk = function() { };
	},

    showAdPreviews: function() {
		var match = null;
		var a = selectAllNodes(document, document.body, "//a");
		for (var y=0; y<a.length; y++) {
			match = a[y].href.match(/^http:\/\/[^\/]*google\.[a-z\.]+\/(pagead|url).+?(q|adurl)=(http[s]?:[^&]+)/i);
			if (match) {
				a[y].onmouseover = function() { };
			}

		}
		var td = selectAllNodes(document, document.body, "//td[@onmouseover='return ss()']");
		for (var y=0; y<td.length; y++) {
			td[y].onmouseover = function() { };
		}
		td = selectAllNodes(document, document.body, "//td[@onmouseover='return true']");
		for (var y=0; y<td.length; y++) {
			td[y].onmouseover = function() { };
		}
	},

	filterWebsitesFromSearch: function(preflist,color) {

        var prefarr = preflist.split(/\s+/);
		var l = new Array();
        for (var i=0;i< prefarr.length;i++) {
			var cg_regexp = null;
			if (!this.isRegExp(prefarr[i])) {
				cg_regexp = new RegExp(this.convertToRegExp(prefarr[i]), "i");
			} else {
				cg_regexp = new RegExp(prefarr[i].replace(/^\/(.+)\/[i]?$/, "($1)"), "i");
			}
			l[l.length] = cg_regexp;
	  	}

	  var re = null;
	  var match = null;
      var res = selectAllNodes(document, document.body, "//li[@class='g']");
	  for (var x=0; x<res.length; x++) {
		var a = document.evaluate(".//a", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
		if (!a) continue;
		var lnk = a.href;

		match = lnk.match(/^(http:\/\/www\.google|\/url).+?q=(.+)(&|&amp;)e=/i);
		if (match) {
			lnk = unescape(match[2]);
		}

        var nobr = document.evaluate(".//span[@class='gl']", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue || document.evaluate(".//nobr/font", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue || document.evaluate(".//nobr", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
		if (nobr) {
			nobr.innerHTML = nobr.innerHTML + ' - ';

		    var newa = document.createElement('a');
		    newa.setAttribute("href", "javascript:void(0);");
			newa.setAttribute("cg_filter", lnk);
			newa.setAttribute("class", "fl");
			if (document.cookie.match(/:NW=1:/)) {
				newa.setAttribute("target", "nw");
			}
			newa.innerHTML = this.t("filter");
			nobr.appendChild(newa);
		}

		if (l && l.length > 0) {
		  for (var i=0;i< l.length;i++) {
            if (lnk.match(l[i])) {
			  var np = document.createElement('li');

			  var npa = document.createElement('a');
			  npa.setAttribute("href", lnk);
			  npa.setAttribute("style", "color:"+color+";text-decoration:none;");
			  npa.setAttribute("title", this.t("filter_match"));
              npa.setAttribute("class", "l");
			  npa.innerHTML = lnk;
			  np.appendChild(npa);

              if (document.cookie.match(/:NW=1:/)) {
				np.setAttribute("target", "nw");
			  }
			  np.setAttribute("class", "g");
			  np.setAttribute("style", "font-size:small;margin-left:5px;");
			  res[x].parentNode.replaceChild(np, res[x]);
			  break;
			}
		  }
		}
	  }
	},

	filterWebsitesFromNews: function(preflist, color) {

        var prefarr = preflist.split(/\s+/);
		var l = new Array();
        for (var i=0;i< prefarr.length;i++) {
			var cg_regexp = null;
			if (!this.isRegExp(prefarr[i])) {
				cg_regexp = new RegExp(this.convertToRegExp(prefarr[i]), "i");
			} else {
				cg_regexp = new RegExp(prefarr[i].replace(/^\/(.+)\/[i]?$/, "($1)"), "i");
			}
			l[l.length] = cg_regexp;
	  	}

	  var re = null;
	  var match = null;
  	  var res = selectAllNodes(document, document.body, "//table[@cellspacing='7'][@cellpadding='2'][@border='0'][@valign='top']");
	  for (var x=0; x<res.length; x++) {
		var counter = selectAllNodes(document, res[x], ".//a");
		if (!counter || counter.length > 2) continue;

		var a = document.evaluate(".//a", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
		if (!a) continue;
		var lnk = a.href;

		match = lnk.match(/^(http:\/\/www\.google|\/url).+?q=(.+)(&|&amp;)e=/i);
		if (match) {
			lnk = unescape(match[2]);
		}

		var nobr = document.evaluate(".//nobr/font", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue || document.evaluate(".//nobr", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
		if (nobr) {
		    var span = document.createElement('span');
			span.innerHTML = ' - ';
			nobr.appendChild(span);
		    var newa = document.createElement('a');
		    newa.setAttribute("href", "javascript:void(0);");
			newa.setAttribute("cg_filter", lnk);
			newa.setAttribute("class", "fl");
			newa.innerHTML = this.t("filter");
			nobr.appendChild(newa);
		}

		if (l && l.length > 0) {
		  for (var i=0;i< l.length;i++) {
	        if (lnk.match(l[i])) {
			  var np = document.createElement('div');

			  var npa = document.createElement('a');
			  npa.setAttribute("href", lnk);
			  npa.setAttribute("style", "color:"+color+";text-decoration:none;");
			  npa.setAttribute("title", this.t("filter_match"));
			  npa.innerHTML = lnk;
			  np.appendChild(npa);

			  np.setAttribute("style", "font-size:small;margin-left:8px;");
			  res[x].parentNode.replaceChild(np, res[x]);
			  break;
			}
		  }
		}
	  }
	},

	addWayBackMachine: function() {
	  var match = null;
  	  var res = selectAllNodes(document, document.body, "//li[@class='g']");
	  for (var x=0; x<res.length; x++) {
		var a = document.evaluate(".//a", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
		if (!a) continue;

		var lnk = a.href;

		match = lnk.match(/^(http:\/\/www\.google|\/url).+?q=(.+)(&|&amp;)e=/i);
		if (match) {
			lnk = unescape(match[2]);
		}

        var nobr = document.evaluate(".//span[@class='gl']", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue || document.evaluate(".//nobr/font", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue || document.evaluate(".//nobr", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
		if (nobr) {
			nobr.innerHTML = nobr.innerHTML + ' - ';

		    var newa = document.createElement('a');
		    newa.setAttribute("href", "http://web.archive.org/web/*/" + lnk);
			newa.setAttribute("class", "fl");

			if (document.cookie.match(/:NW=1:/)) {
				newa.setAttribute("target", "nw");
			}

			newa.innerHTML = this.t("history");
			nobr.appendChild(newa);
		}
	  }
	},

	addBookmarks: function(handler) {

	  if (!document.gs || !document.gs.q) return;
	  var q = encodeURIComponent(document.gs.q.value);
	  if (!q) return;

	  var match = null;
      var res = selectAllNodes(document, document.body, "//li[@class='g']");
	  for (var x=0; x<res.length; x++) {
		var a = document.evaluate(".//a", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
		if (!a) continue;

		var lnk = a.href;
		var title = a.innerHTML.replace(/<[^>]+>/g,"");

		match = lnk.match(/^(http:\/\/www\.google|\/url).+?q=(.+)(&|&amp;)e=/i);
		if (match) {
			lnk = unescape(match[2]);
		}

        var nobr = document.evaluate(".//span[@class='gl']", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue || document.evaluate(".//nobr/font", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue || document.evaluate(".//nobr", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
		if (nobr) {

			nobr.innerHTML = nobr.innerHTML + ' - ';

		    var newa = document.createElement('a');
			newa.setAttribute("class", "fl");

			switch (handler){
				case "del.icio.us":
					newa.setAttribute("href", "http://del.icio.us/post?title=" + encodeURIComponent(title) + "&url=" + encodeURIComponent(lnk) + "&encoding=UTF-8&tags=" + q);
					break;
				case "furl":
					newa.setAttribute("href", "http://www.furl.net/storeIt.jsp?t=" + encodeURIComponent(title) + "&u=" + encodeURIComponent(lnk) + "&encoding=UTF-8&tags=" + q);
					break;
				case "digg":
					newa.setAttribute("href", "http://digg.com/submit?phase=2&url=" + encodeURIComponent(lnk) + "&encoding=UTF-8&tags=" + q);
					break;
				case "spurl":
					newa.setAttribute("href", "http://www.spurl.net/spurl.php?v=3&title=" + encodeURIComponent(title) + "&url=" + encodeURIComponent(lnk) + "&encoding=UTF-8&tags=" + q);
					break;
				case "simpy":
					newa.setAttribute("href", "http://simpy.com/simpy/LinkAdd.do?title=" + encodeURIComponent(title) + "&href=" + encodeURIComponent(lnk) + "&encoding=UTF-8&v=6&tags=" + q);
					break;
				case "blinklist":
					newa.setAttribute("href", "http://www.blinklist.com/index.php?Action=Blink/addblink.php&Description=&Url=" + encodeURIComponent(lnk) + "&Title=" + encodeURIComponent(title) + "&encoding=UTF-8&Tag=" + q);
					break;
				case "yahoo-myweb":
					newa.setAttribute("href", "http://synergy2.search.yahoo.com/myresults/bookmarklet?u=" + encodeURIComponent(lnk) + "&t=" + encodeURIComponent(title) + "&encoding=UTF-8&Tag=" + q);
					break;
				case "google":
					newa.setAttribute("href", "http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=" + encodeURIComponent(lnk) + "&title=" + encodeURIComponent(title));
					break;
				case "ma.gnolia":
					newa.setAttribute("href", "http://ma.gnolia.com/bookmarklet/popup/add?url=" + encodeURIComponent(lnk) + "&title=" + encodeURIComponent(title) + "&description=");
					break;
				case "reddit":
					newa.setAttribute("href", "http://reddit.com/submit?url=" + encodeURIComponent(lnk));
					break;
				default:
					newa.setAttribute("href", "javascript:void(0);");
					newa.setAttribute("cg_url", lnk);
					newa.setAttribute("cg_title", title);
			}

			if (document.cookie.match(/:NW=1:/)) {
				newa.setAttribute("target", "nw");
			}

			newa.innerHTML = this.t("save");
			nobr.appendChild(newa);
		}
	  }
	},

	restoreGooglePrint: function() {
	    var cleardots = document.evaluate("//img[contains(@src, 'images/cleardot.gif')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
	    var cleardot, i, div, theimg;
	    for(cleardot = null, i = 0; (cleardot = cleardots.snapshotItem(i)); i++) {
			div = cleardot.parentNode;
			if (div.nodeName != "DIV") {
		    	div = div.parentNode;
			}
			theimg = getComputedStyle(div, '').backgroundImage;
			theimg = theimg.replace(/url\((.*?)\)/g, "$1");
			cleardot.style.border = "none";
			cleardot.src = theimg;
	    }

	    document.oncontextmenu = null;
	},

	addOtherBookReviews: function(urls) {
	    var table = document.evaluate("//table[@bgcolor='#e5ecf9'][contains(@width,'100%')][@border='0'][@cellpadding='1'][@cellspacing='0']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
		if (!table) return;
		if (!document.gs || !document.gs.q) return;
	    var q = encodeURIComponent(document.gs.q.value);
		var q2 = escape(document.gs.q.value);
		if (!q) return;

		if (document.cookie.match(/:NW=1:/)) {
			urls = urls.replace(/a href/ig, "a target=nw href");
		}

	    var other = document.createElement('div');
	    var s = '<span style="font-size:small;padding:4px 0 4px 5px;">' + this.t("try_search") + ' ';
		s += urls.replace(/\[QUERY\]/g, q).replace(/\[QUERYISO88591\]/g, q2);
	    s += '</span>';
    	other.innerHTML = s;
	    table.parentNode.insertBefore(other, table.nextSibling);
	},

	addGoogleSuggest: function() {
        // only add suggest if it is not there already
		if (!document.body.innerHTML.match(/google\.ac\.i\(document/)) {
            var f = get_search_form();
            if (!f || !f.q || !f.btnG) return;
            if (!window.google)	window.google={};
            if (!window.google.y || !window.google.y.first) window.google.y={first:[]};
			window.setTimeout(function(){var xjs=document.createElement('script');
			xjs.src='/extern_js/f/CgJlbiswCjgILCswGDgDLA/n0F1jOU587s.js';
			document.getElementsByTagName('head')[0].appendChild(xjs)},0);
			window.google.y.first.push(function(){window.google.ac.i(f,f.q,'','')})
            f.q.setAttribute("autocomplete", "off");
        }
	},

	pointLinksToImages: function() {
		createLinks();
		window.addEventListener("resize", createLinks, true);
    },

    secureGoogle: function() {
		if (window.location.href.match(/^http:/)) {
			window.location.href = window.location.href.replace(/^http:/, 'https:');
	    }
    },
    anonymizeGoogleUID: function() {
		if (location.host.match(/google\..+$/)) {
			var domain = location.host.match(/google\..+$/)[0];
			var parts  = document.cookie.split('; ');
			var c = null;
			for(var i=0; c=parts[i]; ++i) {
				if(c.match(/^PREF=/)) {
					document.cookie = c.replace(/ID=\w+:/,'ID='+get_random_id(16)+':') + '; domain=.' + domain + '; path=/; expires=Mon, 01 Jan 2038 00:00:00 GMT';
				}
			}
		}
	 },

	defaultPreferences: function(FF,LR,LD,NR,NW,SG) {
		var domain = location.host.match(/google\..+$/)[0];
		var parts  = document.cookie.split('; ');
		var c = null;

		for(var i=0; c=parts[i]; ++i) {
			// if pref cookie
			if (c.match(/^PREF=/)) {
				// parse cookie
				var namevalues = c.match(/^PREF=(.*)/)[1].split(':');
				var hash   = new Object();
				for(var j=0; j < namevalues.length; j++) {
					var pair = namevalues[j].split('=');
					hash[pair[0]] = pair[1];
				}

				// if valid cookie
				if (hash['ID'] && hash['TM'] && hash['LM'] && hash['S']) {

					var modified = false;

					// SafeSearch: 4 = Off, 1 = Strict, empty = Moderate
					// if set but should be empty
					if (FF && hash['FF'] && FF == 'empty') {
						hash['FF'] = '';
						modified = true;
					// if set but not should be empty
					}  else if (FF && hash['FF'] && FF != hash['FF'] && FF != 'empty') {
						hash['FF'] = FF;
						modified = true;
					// if not set and should not be empty
					} else if (FF && !hash['FF'] && FF != 'empty') {
						hash['FF'] = FF;
						modified = true;
					}

					// Search only for pages written in these language(s)
					// if set but should be empty
					if (LR && hash['LR'] && LR == 'empty') {
						hash['LR'] = '';
						modified = true;
					// if set but not should be empty
					}  else if (LR && hash['LR'] && LR != hash['LR'] && LR != 'empty') {
						hash['LR'] = LR;
						modified = true;
					// if not set and should not be empty
					} else if (LR && !hash['LR'] && LR != 'empty') {
						hash['LR'] = LR;
						modified = true;
					}

					// Display Google tips and messages in this language
					if (LD && (!hash['LD'] || LD != hash['LD'])) {
						hash['LD'] = LD;
						modified = true;
					}

					// Display X results per page
					if (NR && (!hash['NR'] || NR != hash['NR'])) {
						hash['NR'] = NR;
						modified = true;
					}

					// Open search results in a new browser window.
					// if set but should be empty
					if (NW && hash['NW'] && NW == 'empty') {
						hash['NW'] = '';
						modified = true;
					// if set but not should be empty
					}  else if (NW && hash['NW'] && NW != hash['NW'] && NW != 'empty') {
						hash['NW'] = NW;
						modified = true;
					// if not set and should not be empty
					} else if (NW && !hash['NW'] && NW != 'empty') {
						hash['NW'] = NW;
                        modified = true;
					}

					// Use Google Suggest
					// if set but should be empty
					if (SG && SG == 'empty' && (!hash['SG'] || hash['SG'] != '0')) {
						hash['SG'] = '0';
						modified = true;
					// if set but not should be empty
					}  else if (SG && SG == '1' && (hash['SG'])) {
						hash['SG'] = '';
						modified = true;
					}

					// if any changes
					if (modified) {
						var newpref = "PREF=";
						// keep order
						newpref += 'ID' + '=' + hash['ID'] + ':';
						// prefs
						for (key in hash) {
							if (key != 'ID' && key != 'S' && hash[key]) {
								newpref += key + '=' + hash[key] + ':';
							}
						};
						// keep order
						newpref += 'S'  + '=' + hash['S'];
						document.cookie = newpref + '; domain=.' + domain + '; path=/; expires=Mon, 01 Jan 2038 00:00:00 GMT';
						window.location.href = window.location.href;
					}
				}
				// else invalid cookie
				return;
			}
		}
	},

    addCountSearchResults: function() {
		var x, i, p, s=0, n=0, R=/start=([^&]*)/;
		if ((x=R.exec(document.location.search)) && x[1]) s = n = parseInt(unescape(x[1]),10);
		var res = selectAllNodes(document, document.body, "//li[@class='g']/descendant::a[@class='l']");
		for (i=0;i<res.length;++i) {
			var tn = document.createElement("span");
			tn.innerHTML = ++n + ". ";
		    //var tn = document.createTextNode(++n + ". ");
			tn.setAttribute("style", res[i].getAttribute("style"));
			res[i].parentNode.insertBefore(tn, res[i]);
		};
	},

    anonymizeGoogleAnalytics: function() {
		var parts  = document.cookie.split('; ');
		var c = null;
		for(var i=0; c=parts[i]; ++i) {
			var match = c.match(/^(__utm[a-z])=/);
			if (match) {
				var d = document.domain;
				if (d.substring(0,4)=="www.") {
					d=d.substring(4,d.length);
				}
				document.cookie = match[1] + '=; domain=' + d + '; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT';
			}
		}
	},

	bypassChineseFirewall: function() {
		// The Chinese Firewall filters infomation on the internet
		// Google cache is disabled by the supervisor
		// This method bypass the firewall by rewriting the links
		var match = null;
		var a = selectAllNodes(document, document.body, "//a[contains(@href, 'search?q=cache')]");
		for (var y=0; y<a.length; y++) {
			a[y].href = a[y].href.replace(/q=cache/, "&q=cache");
		}
	},

	addSearchFieldFocus: function() {
		var f = get_search_form();
		if (!f || !f.q) return;
		window.addEventListener("load", function() {f.q.focus();}, false);
	}
};
// End File "cg_javascript.js"

// Begin File "cg_urls.rdf.js"
function cg_URL( strType, strName, strUrl )
{
    this.name  = strName;
    this.url   = strUrl;
    this.type  = strType;
}
var cg_urls = new Array();
i = 0;
cg_urls[i++] = new cg_URL( "websearch", "Yahoo", "http://search.yahoo.com/search?p=[QUERY]&amp;ei=UTF-8" );
cg_urls[i++] = new cg_URL( "websearch", "Alpha", "http://au.alpha.yahoo.com/search/web?p=[QUERY]" );
cg_urls[i++] = new cg_URL( "websearch", "Ask", "http://web.ask.com/web?q=[QUERY]" );
cg_urls[i++] = new cg_URL( "websearch", "AllTheWeb", "http://www.alltheweb.com/search?q=[QUERY]&amp;cs=utf-8" );
cg_urls[i++] = new cg_URL( "websearch", "Live", "http://search.msn.com/results.aspx?q=[QUERY]" );
cg_urls[i++] = new cg_URL( "websearch", "Lycos", "http://search.lycos.com/default.asp?query=[QUERY]" );
cg_urls[i++] = new cg_URL( "websearch", "Technorati", "http://www.technorati.com/cosmos/search.html?url=[QUERY]" );
cg_urls[i++] = new cg_URL( "websearch", "Feedster", "http://www.feedster.com/search.php?q=[QUERY]" );
cg_urls[i++] = new cg_URL( "websearch", "Wikipedia", "http://en.wikipedia.org/wiki/Special:Search?search=[QUERY]&amp;go=go" );
cg_urls[i++] = new cg_URL( "websearch", "Bloglines", "http://www.bloglines.com/search?t=1&amp;q=[QUERY]" );
cg_urls[i++] = new cg_URL( "websearch", "Altavista", "http://www.altavista.com/web/results?q=[QUERY]" );
cg_urls[i++] = new cg_URL( "websearch", "A9", "http://a9.com/[QUERY]" );
cg_urls[i++] = new cg_URL( "moviesearch", "Rotten Tomatoes", "http://www.rottentomatoes.com/search/search.php?searchby=movies&amp;search=[QUERY]" );
cg_urls[i++] = new cg_URL( "moviesearch", "Metacritic", "http://www.metacritic.com/search/process?ty=1&amp;ts=[QUERY]" );
cg_urls[i++] = new cg_URL( "moviesearch", "Yahoo Movies", "http://movies.yahoo.com/mv/search?p=[QUERY]" );
cg_urls[i++] = new cg_URL( "moviesearch", "Movies.com", "http://search.movies.go.com/movieSearch?search=[QUERY]" );
cg_urls[i++] = new cg_URL( "moviesearch", "IMDb", "http://www.imdb.com/find?q=[QUERY];tt=on;mx=20" );
cg_urls[i++] = new cg_URL( "newssearch", "Yahoo", "http://news.search.yahoo.com/search/news/?p=[QUERY]" );
cg_urls[i++] = new cg_URL( "newssearch", "Ask", "http://news.ask.com/news?q=[QUERY]" );
cg_urls[i++] = new cg_URL( "newssearch", "AllTheWeb", "http://www.alltheweb.com/search?cat=news&amp;q=[QUERY]" );
cg_urls[i++] = new cg_URL( "newssearch", "Live", "http://search.msn.com/news/results.aspx?q=[QUERY]" );
cg_urls[i++] = new cg_URL( "newssearch", "Lycos", "http://search.lycos.com/default.asp?tab=news&amp;query=[QUERY]" );
cg_urls[i++] = new cg_URL( "newssearch", "Sky News", "http://search.sky.com/search/skynews/results/1,,,00.html?QUERY=[QUERY]" );
cg_urls[i++] = new cg_URL( "newssearch", "CNN", "http://search.cnn.com/pages/search.jsp?query=[QUERY]" );
cg_urls[i++] = new cg_URL( "newssearch", "Feedster", "http://www.feedster.com/search.php?q=[QUERY]" );
cg_urls[i++] = new cg_URL( "newssearch", "Daypop", "http://www.daypop.com/search?q=[QUERY]" );
cg_urls[i++] = new cg_URL( "newssearch", "Bloglines", "http://www.bloglines.com/search?t=1&amp;q=[QUERY]" );
cg_urls[i++] = new cg_URL( "weathersearch", "Yahoo", "http://weather.yahoo.com/search/weather2?p=[QUERY]" );
cg_urls[i++] = new cg_URL( "weathersearch", "Ask", "http://web.ask.com/web?q=weather+[QUERY]" );
cg_urls[i++] = new cg_URL( "weathersearch", "Netscape", "http://channels.netscape.com/ns/weather/c_select2.jsp?where=[QUERY]" );
cg_urls[i++] = new cg_URL( "weathersearch", "CNN", "http://weather.cnn.com/weather/search?wsearch=[QUERY]" );
cg_urls[i++] = new cg_URL( "weathersearch", "USA Today", "http://asp.usatoday.com/weather/CityForecast.aspx?source=both&amp;txtSearchCriteria=[QUERY]" );
cg_urls[i++] = new cg_URL( "weathersearch", "Ameriwx", "http://www.wxforecasts.com/ameriwx/ameriwx.php?pands=[QUERY]" );
cg_urls[i++] = new cg_URL( "weathersearch", "Weather Underground", "http://www.wunderground.com/cgi-bin/findweather/getForecast?query=[QUERY]" );
cg_urls[i++] = new cg_URL( "weathersearch", "Weather.com", "http://www.weather.com/search/enhanced?where=[QUERY]" );
cg_urls[i++] = new cg_URL( "weathersearch", "AccuWeather", "http://wwwa.accuweather.com/us-city-list.asp?zipcode=[QUERY]" );
cg_urls[i++] = new cg_URL( "booksearch", "NYTimes", "http://topics.nytimes.com/top/features/books/bookreviews/?s=closest&amp;match=all&amp;query=[QUERY]" );
cg_urls[i++] = new cg_URL( "booksearch", "ReviewScout", "http://www.reviewscout.com/[QUERY]" );
cg_urls[i++] = new cg_URL( "booksearch", "Amazon.com", "http://www.amazon.com/exec/obidos/redirect?link_code=ur2&amp;camp=1789&amp;creative=9325&amp;tag=&amp;path=external-search%3Fsearch-type=ss%26keyword=[QUERY]%26index=books" );
cg_urls[i++] = new cg_URL( "booksearch", "Barnes&amp;Noble", "http://search.barnesandnoble.com/booksearch/results.asp?WRD=[QUERY]" );
cg_urls[i++] = new cg_URL( "booksearch", "Blackwells", "http://bookshop.blackwell.com/bobus/scripts/home.jsp?action=search&amp;source=3246694795&amp;type=keywords&amp;term=[QUERY]" );
cg_urls[i++] = new cg_URL( "productsearch", "Yahoo Shopping", "http://shopping.yahoo.com/search?p=[QUERY]" );
cg_urls[i++] = new cg_URL( "productsearch", "MySimon", "http://search.mysimon.com/search?qt=[QUERY]" );
cg_urls[i++] = new cg_URL( "productsearch", "CNET Shopper", "http://shopper-search.cnet.com/search?q=[QUERY]" );
cg_urls[i++] = new cg_URL( "productsearch", "NexTag", "http://www.nextag.com/serv/main/buyer/OutPDir.jsp?search=[QUERY]" );
cg_urls[i++] = new cg_URL( "productsearch", "StreetPrices", "http://www.streetprices.com/x/search.cgi?query=[QUERY]" );
cg_urls[i++] = new cg_URL( "productsearch", "Shopping.com", "http://www.shopping.com/xFS?KW=[QUERY]" );
cg_urls[i++] = new cg_URL( "productsearch", "eBay", "http://search.ebay.com/search/search.dll?query=[QUERY]" );
cg_urls[i++] = new cg_URL( "imagesearch", "Yahoo", "http://images.search.yahoo.com/search/images?p=[QUERY]" );
cg_urls[i++] = new cg_URL( "imagesearch", "Ask", "http://pictures.ask.com/pictures?q=[QUERY]" );
cg_urls[i++] = new cg_URL( "imagesearch", "AllTheWeb", "http://www.alltheweb.com/search?cat=img&amp;q=[QUERY]" );
cg_urls[i++] = new cg_URL( "imagesearch", "Live", "http://search.msn.com/images/results.aspx?q=[QUERY]" );
cg_urls[i++] = new cg_URL( "imagesearch", "PicSearch", "http://www.picsearch.com/search.cgi?q=[QUERY]" );
cg_urls[i++] = new cg_URL( "imagesearch", "Ditto", "http://www.ditto.com/searchResults.asp?ss=[QUERY]" );
cg_urls[i++] = new cg_URL( "imagesearch", "Creatas", "http://www.creatas.com/searchResults.aspx?searchString=[QUERY]" );
cg_urls[i++] = new cg_URL( "imagesearch", "FreeFoto", "http://www.freefoto.com/search.jsp?queryString=[QUERY]" );
cg_urls[i++] = new cg_URL( "imagesearch", "WebShots", "http://www.webshots.com/search?query=[QUERY]" );
cg_urls[i++] = new cg_URL( "imagesearch", "NASA", "http://nix.larc.nasa.gov/search?qa=[QUERY]" );
cg_urls[i++] = new cg_URL( "imagesearch", "Flickr", "http://www.flickr.com/photos/search/text:[QUERY]" );
cg_urls[i++] = new cg_URL( "imagesearch", "deviantART", "http://search.deviantart.com/?q=[QUERY]&amp;section=browse&amp;qh=boost%3Apopular+age_sigma%3A24h+age_scale%3A5" );
cg_urls[i++] = new cg_URL( "imagesearch", "Photobucket", "http://photobucket.com/images/search/[QUERY]" );

cg_urls[i++] = new cg_URL( "videosearch", "YouTube", "http://www.youtube.com/results?search_query=[QUERY]" );
cg_urls[i++] = new cg_URL( "videosearch", "Yahoo", "http://video.yahoo.com/video/search?p=[QUERY]" );
cg_urls[i++] = new cg_URL( "videosearch", "Metacafe", "http://www.metacafe.com/tags/[QUERY]/" );
cg_urls[i++] = new cg_URL( "videosearch", "IFILM", "http://www.ifilm.com/search?query=[QUERY]" );
cg_urls[i++] = new cg_URL( "videosearch", "Revver", "http://one.revver.com/find/keywords/[QUERY]" );
cg_urls[i++] = new cg_URL( "videosearch", "Dailymotion", "http://www.dailymotion.com/visited/search/[QUERY]" );

// End File "cg_urls.rdf.js"

// Begin File "cg_web_texts.js"
// Load texts
cg_textarr = new Array();
cg_textarr["try_search"]    = "Try your search on";
cg_textarr["find_reviews"]  = "Find more reviews at";
cg_textarr["find_news"]     = "Find more news at";
cg_textarr["find_forecasts"]= "Find more forecasts at";
cg_textarr["find_products"] = "Find more products at";
cg_textarr["filter"]        = "Filter";
cg_textarr["filter_match"]  = "This URL matched one of your CustomizeGoogle filters.";
cg_textarr["origin_image"]  = "Origin Image";
cg_textarr["origin_page"]   = "Origin Page";
cg_textarr["history"]       = "History";
cg_textarr["save"]          = "Save";
cg_textarr["gmail-spam"]    = "Spam";
// End File "cg_web_texts.js"

// Begin File "smir_common.js"
function str_replace( search, replace, subject ) {
    if( typeof subject != "string" )
        return subject;

    if( replace.indexOf( search ) != -1 ) {
        alert("invalid str_replace!");
        return subject;
    }

    var secure = 0;
    while( subject.indexOf( search ) != -1 && secure++ < 1000 )
        subject = subject.substring( 0, subject.indexOf( search ) ) + subject.substring( subject.indexOf( search ) + search.length, subject.length );

    if( secure == 1000 )
        alert( "maybe an infinite loop in str_replace..." );

    return subject;
}

function str_repeat( input, multiplier ) {
    var strReturn = "";
    for( var i=0; i<multiplier; ++i )
        strReturn += input;
    return strReturn;
}

function in_array( needle, haystack, strict ) {
    for( var i in haystack ) {
        if( haystack[i] == needle && (!strict || typeof needle == typeof haystack[i] ) )
            return true;
    }
    return false;
}

function isFunction( obj ) {
    return typeof obj == "function";
}
function isBoolean( obj ) {
    return typeof obj == "boolean";
}
function isString( obj ) {
    return typeof obj == "string";
}

function isVar( obj ) {
    return typeof obj != "undefined" && typeof obj != "function";
}
// End File "smir_common.js"


