﻿var searchControl;
window.onload = function() 
{
    onLoad();
}

function onLoad() 
{
     searchControl = new GSearchControl();

     var webSrearch = new GwebSearch();
     webSrearch.setUserDefinedLabel("web");
     searchControl.addSearcher(webSrearch);

//     var siteSearch = new GwebSearch();
//     siteSearch.setUserDefinedLabel("OfirYaron.com");
//     siteSearch.setSiteRestriction("OfirYaron.com");
//     searchControl.addSearcher(siteSearch);

//     var blogsSrearch = new GblogSearch();
//     blogsSrearch.setUserDefinedLabel("weblogs");
//     searchControl.addSearcher(blogsSrearch);

     var drawOptions = new GdrawOptions();
     drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
     drawOptions.setInput(document.getElementById('query'));
     searchControl.draw(document.getElementById("searchcontrol"), drawOptions);

     GSearch.getBranding(document.getElementById("google"));
}

var query = null;
var helpContent = null;
var helpButton = null;
document.onkeydown = function(event) { kd(event); };
var searched = false;

function kd(e) 
{
     if (!e) e = event;
     if (query == null)
     query = document.getElementById('query');
     if (e.keyCode == 27) 
     {
         query.value = '';
         searchControl.clearAllResults();
     }
     query.focus();
}

function toggleHelp() 
{
     if (helpContent == null)
        helpContent = document.getElementById('helpContent');
     if (helpButton == null)
        helpButton = document.getElementById('helpButton');
     if (helpContent.style.display == 'none') 
     {
        helpContent.style.display = '';
        helpButton.innerHTML = 'hide help';
     } 
     else 
     {
         helpContent.style.display = 'none';
         helpButton.innerHTML = 'help';
     }
}

function SendEmail(id) {
    $.ajax({
        type: "POST",
        url: "/Home/SendEmail",
        data: "addressId=" + id,
        success: function(html) {
            location = html;
        }
    });
}
