﻿google.load('search', '1');
var oSearch;
function cse(query) {

    var sFormDiv = document.getElementById("searchForm");
    var leftScDiv = document.getElementById("leftSearchControl");
    var rightScDiv = document.getElementById("rightSearchControl");
    var sNoResuts = "No search results – try again";

    // create a left, right search control
    // create a custom search form
    this.leftControl = new google.search.SearchControl();
    this.rightControl = new google.search.SearchControl();
    this.searchForm = new google.search.SearchForm(false, sFormDiv);

    this.leftControl.setResultSetSize(GSearch.LARGE_RESULTSET);
    this.rightControl.setResultSetSize(GSearch.LARGE_RESULTSET);
    this.leftControl.setLinkTarget(GSearch.LINK_TARGET_BLANK);
    this.rightControl.setLinkTarget(GSearch.LINK_TARGET_BLANK);


    // bind clear and submit functions
    this.searchForm.setOnSubmitCallback(this, cse.prototype.onSubmit);

    var searcher;
    var options;
    // configure left control
    // Site Restrict to CSE ID for All
    var cseId = "004386210800957627105:eu_uoizew1c";
    searcher = new google.search.WebSearch();
    options = new google.search.SearcherOptions();
    searcher.setSiteRestriction(cseId, null);
    options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
    searcher.setUserDefinedLabel("Search Results");
    this.leftControl.addSearcher(searcher, options);

    // configure right control
    //
    // Video Search
    searcher = new google.search.VideoSearch();
    options = new google.search.SearcherOptions();
    this.rightControl.addSearcher(searcher, options);
    //Image Search
    searcher = new google.search.ImageSearch();
    searcher.setUserDefinedLabel("Images");
    options = new google.search.SearcherOptions();
    this.rightControl.addSearcher(searcher, options);
    //Book Search
    searcher = new google.search.BookSearch();
    searcher.setUserDefinedLabel("Books");
    options = new google.search.SearcherOptions();
    this.rightControl.addSearcher(searcher, options);
    //Blog Search
    searcher = new google.search.BlogSearch();
    options = new google.search.SearcherOptions();
    this.rightControl.addSearcher(searcher, options);
    //News Search
    searcher = new google.search.NewsSearch();
    options = new google.search.SearcherOptions();
    searcher.setSiteRestriction(cseId, "News");
    searcher.setUserDefinedLabel("News");
    this.rightControl.addSearcher(searcher, options);
    //Patent Search
    searcher = new google.search.PatentSearch();
    searcher.setUserDefinedLabel("Patents");
    options = new google.search.SearcherOptions();
    this.rightControl.addSearcher(searcher, options);
    //People Search
    searcher = new google.search.WebSearch();
    options = new google.search.SearcherOptions();
    searcher.setSiteRestriction(cseId, "People");
    searcher.setUserDefinedLabel("People");
    this.rightControl.addSearcher(searcher, options);
    //Technology Search
    searcher = new google.search.WebSearch();
    options = new google.search.SearcherOptions();
    searcher.setSiteRestriction(cseId, "Technology");
    searcher.setUserDefinedLabel("Technology");
    this.rightControl.addSearcher(searcher, options);
    //Statistics Search
    searcher = new google.search.WebSearch();
    options = new google.search.SearcherOptions();
    searcher.setSiteRestriction(cseId, "Statistics");
    searcher.setUserDefinedLabel("Statistics");
    this.rightControl.addSearcher(searcher, options);
    //Government Search
    searcher = new google.search.WebSearch();
    options = new google.search.SearcherOptions();
    searcher.setSiteRestriction(cseId, "Government");
    searcher.setUserDefinedLabel("Government");
    this.rightControl.addSearcher(searcher, options);
    //Personal Finance Search
    searcher = new google.search.WebSearch();
    options = new google.search.SearcherOptions();
    searcher.setSiteRestriction(cseId, "Personal Finance");
    searcher.setUserDefinedLabel("Personal Finance");
    this.rightControl.addSearcher(searcher, options);
    //Resources Search
    searcher = new google.search.WebSearch();
    options = new google.search.SearcherOptions();
    searcher.setSiteRestriction(cseId, "Resources");
    searcher.setUserDefinedLabel("Resources");
    this.rightControl.addSearcher(searcher, options);
    //Wikipedia Search
    searcher = new google.search.WebSearch();
    options = new google.search.SearcherOptions();
    searcher.setSiteRestriction("wikipedia.org");
    searcher.setUserDefinedLabel("Wikipedia");
    this.rightControl.addSearcher(searcher, options);
    //Amazon Search
    searcher = new google.search.WebSearch();
    options = new google.search.SearcherOptions();
    searcher.setSiteRestriction("www.amazon.com");
    searcher.setUserDefinedLabel("Amazon");
    this.rightControl.addSearcher(searcher, options);
    //eBay Search
    searcher = new google.search.WebSearch();
    options = new google.search.SearcherOptions();
    searcher.setSiteRestriction("ebay.com");
    searcher.setUserDefinedLabel("eBay");
    this.rightControl.addSearcher(searcher, options);
    //EntreOasis Search
    searcher = new google.search.WebSearch();
    options = new google.search.SearcherOptions();
    searcher.setSiteRestriction("www.entreoasis.com");
    searcher.setUserDefinedLabel("EntreOasis");
    this.rightControl.addSearcher(searcher, options);
    //GoVenture Search
    searcher = new google.search.WebSearch();
    options = new google.search.SearcherOptions();
    searcher.setSiteRestriction(cseId, "GoVenture_");
    searcher.setUserDefinedLabel("GoVenture");
    this.rightControl.addSearcher(searcher, options);
    //All Search (no refinements)
    searcher = new google.search.WebSearch();
    //options = new gooogle.search.SearcherOptions();
    searcher.setUserDefinedLabel("All Internet");
    this.rightControl.addSearcher(searcher);

    this.rightControl.setNoResultsString(sNoResuts);
    this.leftControl.setNoResultsString(sNoResuts);
   


    // draw the left and right controls
    // the right control is drawn in tabbed mode
    var drawOptions = new google.search.DrawOptions();
    drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
    drawOptions.setInput(sFormDiv);

    var drawOptionsL = new google.search.DrawOptions();
    drawOptionsL.setInput(sFormDiv);


    this.leftControl.draw(leftScDiv, drawOptionsL);
    this.rightControl.draw(rightScDiv, drawOptions);
    
    try{
        if (query.length > 0) {
            document.getElementById("rightContent").style.display = "none";
            document.getElementById("rightTitle").style.display = "block";
            document.getElementById("leftTitle").style.display = "block";
            if (query && query != "") {
                this.leftControl.execute(query);
                this.rightControl.execute(query);
                var oForm = document.getElementsByTagName('input');
                oForm[1].value = query;
            }
            return false;
        }
    }catch(e){}


}

cse.prototype.onSubmit = function(form) {
    var q = form.input.value;
    if (q.length > 0) {
        document.getElementById("searchErr").style.display = "none";
        document.getElementById("rightContent").style.display = "none";
        document.getElementById("rightTitle").style.display = "block";
        document.getElementById("leftTitle").style.display = "block";
        //document.getElementById("top-right-content").style.display = "none";
        //document.getElementById("top-right").appendChild("searchForm");
        if (q && q != "") {
            this.leftControl.execute(q);
            this.rightControl.execute(q);
        }
        return false;
    }else{
        document.getElementById("searchErr").style.display = "block";
        return false;
    }

}

cse.prototype.search = function(query) {
    this.leftControl.execute(query);
    this.rightControl.execute(query);
    return false;
}

function OnLoad() {
    var query = window.location.search.substring(1); ;
    // if url contains query, execute that query
    if (query != null) {
        var keywords = query.split("q=");
        oSearch = new cse(keywords[1]);
    } else {
       oSearch = new cse();
    }
}
google.setOnLoadCallback(OnLoad, true);

/*function setLocalSearch() {
    delete oSearch;
    oSearch = new cse(null, "Sydney");
    
    
}*/

/**
* namedWindow(iParam)
* This function opens a new, empty window. Note that if you want Google, Yahoo! and MSN spiders to follow the link,
* you should always use a link of the form <a href="myLink" onclick="!namedWindow(iParam)">Link text</a> -- this will
* also allow JavaScript-disabled clients and ones with popup prevention to follow the link (although in the launching window).
* (You don't want to have your onclick event simply return false because if a popup prevention plugin like Google's prevents
* the window from opening, you want the link to be able to open regardless.)
* By default, the new window created by namedWindow()is named (i.e., multiple calls will appear in the same window),
* but this property can be overridden (see below). 
* Legal syntaxes:
* <a href="http://foo.com/bar/" onclick = "return !namedWindow('http://foo.com/bar/')">Link text</a>
* (opens a full-sized window with default featureset -- see function definition, below)
* <a href="http://foo.com/bar/"
*     onclick = "return !namedWindow({url:'http://foo.com/bar/',name:'Baz',width:300,height:300})">Link text</a>
* (Note that in this second syntax, any default variables not overridden in the object literal passed as a parameter
* to this function will retain the values assigned when objProps is first created in the first line of the function body.)
* **** IMPORTANT: **** The value for the 'name' parameter in this function must ONLY include alphanumeric characters or underscore,
* or else the function will break!!! (Specified by the second parameter restrictions of JavaScript's window.open() method)
* **********************************
* If you want to create a new window without a variable name so that it opens a new window each time (i.e., window.open(myLink, '', featureList),
* then include the pair name: '' (empty string) in the object literal, i.e.,
* onclick="namedWindow({url: 'http://some.url', name: '', width: 750, height:400})"
* By default the window featureset is the same as that for the old newWindow_full function
* ('toolbar=yes,location=yes,directories=yes,menubar=yes,scrollbars=yes,width=800,height=600') with left and top (or screenX and screenY)
* each set to 50.
* For replacing legacy calls:
* newWindow featureset = 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes'
* newPdfWindow featureset =
* 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=auto,resizable=no,width=780,height=590,left=50,top=50'
* and a specified windowName.
* newWindow_contact featureset = 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes' with left and top each set to 40,
* default width 560, and default height 420.
* newWindow_movie featureset =
* 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=yes,status=no' with default width 639 and default height 477,
* and width and height explicitly called, in that order. (Left and top are both set to 100.)
* newWindow_help featureset = 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes' with width and height explicitly specified
* and no left/top settings.
* newWindow_newsletter featureset = 'toolbar=yes,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,width=620,height=500'
* with no left/top settings. Make the URL into a GET request to http://www.goventure.net/site/products/live/fwd.cfm and append
* "?d=" + the issue's URL + "&i=" + the page name you want the Activity Tracker to record for hit-count purposes.
* newWindow_trial featureset = 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=620,height=420'
* with left and top set to 40.
* newWindow_tools featureset = 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes' with left, top, width, and height
* explicitly passed as args in that order.
* For all VOwindow functions (see newWindow_VO) the featureset is
* 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=no,width=640,height=480'
* (the original script had the resizable label misspelled as "resizeable" so it didn't work)
*/
function namedWindow(iPropertiesObjectOrUrl) {
    var objProps = {
        url: 'about:blank',
        name: 'fullWindow',
        toolbar: 'no',
        location: 'no',
        directories: 'no',
        menubar: 'no',
        scrollbars: 'yes',
        width: 800,
        height: 600
    };
    var arrWindowFeatures = new Array("toolbar", "location", "directories", "menubar", "scrollbars", "width", "height");

    if (navigator.appName.indexOf("Microsoft") > -1) {
        isMSIE = true;
        objProps.leftName = 'left';
        objProps.topName = 'top';
        //    	winStats=winStats+'left=50,top=50';
    } else {
        isMSIE = false;
        objProps.leftName = 'screenX';
        objProps.topName = 'screenY';
        //		winStats=winStats+'screenX=50,screenY=50';
    }
    arrWindowFeatures.splice(arrWindowFeatures.length, 0, objProps.leftName, objProps.topName);
    objProps.leftVal = '50';
    objProps.topVal = '50';

    var strWindowFeatures = "";

    if (typeof (iPropertiesObjectOrUrl) == "string") {
        // treat as URL
        objProps.url = iPropertiesObjectOrUrl;

    } else if (typeof (iPropertiesObjectOrUrl) == "object") {
        // treat as properties object
        objProps.url = iPropertiesObjectOrUrl.url;
        for (var x = 0; x < arrWindowFeatures.length; x++) {
            if (eval("iPropertiesObjectOrUrl." + arrWindowFeatures[x])) {
                eval("objProps." + arrWindowFeatures[x] + " = iPropertiesObjectOrUrl." + arrWindowFeatures[x]);
            }
        }
        if (iPropertiesObjectOrUrl.screenX && typeof (iPropertiesObjectOrUrl.screenX) != "undefined") {
            objProps.leftVal = iPropertiesObjectOrUrl.screenX;
        } else if (iPropertiesObjectOrUrl.left && typeof (iPropertiesObjectOrUrl.left) != "undefined") {
            objProps.leftVal = iPropertiesObjectOrUrl.left;
        }
        if (iPropertiesObjectOrUrl.screenY && typeof (iPropertiesObjectOrUrl.screenY) != "undefined") {
            objProps.topVal = iPropertiesObjectOrUrl.screenY;
        } else if (iPropertiesObjectOrUrl.top && typeof (iPropertiesObjectOrUrl.top) != "undefined") {
            objProps.topVal = iPropertiesObjectOrUrl.top;
        }
        objProps[objProps.leftName] = objProps.leftVal;
        objProps[objProps.topName] = objProps.topVal;
        if (iPropertiesObjectOrUrl.name) {
            objProps.name = iPropertiesObjectOrUrl.name;
        }
    }
    for (var x = 0; x < arrWindowFeatures.length; x++) {
        strWindowFeatures += (objProps[arrWindowFeatures[x]] === '' ? '' :
		                        (strWindowFeatures.length == 0 ? '' : ',') + arrWindowFeatures[x] + '=' + objProps[arrWindowFeatures[x]]);
    }
    if (objProps.hasOwnProperty('status')) {
        strWindowFeatures += (objProps['status'] === '' ? '' :
		                        (strWindowFeatures.length == 0 ? '' : ',') + 'status=' + objProps['status']);
    }
    strWindowFeatures += (iPropertiesObjectOrUrl['resizable'] === '' ? '' :
		                        (strWindowFeatures.length == 0 ? '' : ',') + 'resizable=' + iPropertiesObjectOrUrl['resizable']);
    // alert(strWindowFeatures);
    var windowRef = window.open(objProps.url, objProps.name, strWindowFeatures);
    return windowRef;
}
