//
// Displays form for adding / editing google search form.
//
function display_add_google_search_form()
{
    set_form_field('form_google_search', FLD_BLOCK_ID, '');
    set_form_field('form_google_search', 'action', 'ajax_add_block_google_search');
    set_form_field('form_google_search', 'title', '');
                    
    $('#button_del_google_search').hide();
}

function display_edit_google_search_form(block_id)
{
    set_form_field('form_google_search', FLD_BLOCK_ID, block_id);
    set_form_field('form_google_search', 'action', 'ajax_update_block_google_search');
    set_form_field('form_google_search', 'title', $('#mblock_title_'+block_id).html());
                    
    $('#button_del_google_search').show();
}

//
// Send google search edit form.  
//
// Used for adding / editing google search form.
//
function send_edit_google_search_form()
{
    var title = get_form_field('form_google_search', 'title');
    var block_id = get_form_field('form_google_search', FLD_BLOCK_ID);
    
    if (title == '')
    {
        my_alert('all field are must');
        return false;
    }

    var is_add_action = get_form_field('form_google_search', 'action') == 'ajax_add_block_google_search';
    
    var data = $("#form_google_search").serialize();
    
    var code = is_add_action ? "display_media_blocks_sw_mode(%%%);" : "update_block_title("+block_id+", %%%.title);";
    code += "close_modals();"
    code += "$('#am_btn_search').hide();";

    ajax(data, code, "", "button_google_search", "saving_google_search");

    return false;
}

//
// Deletes google search block.
//
function del_block_google_search()
{
    var title = $('#mblock_title_'+block_id).html();
    
    document.forms['form_google_search'].action.value = 'ajax_del_block_google_search';
    var block_id = get_form_field('form_google_search', FLD_BLOCK_ID);
    var data = $('#form_google_search').serialize();
    var code = "hide_block("+block_id+");";
    code += "close_modals();"
    code += "$('#am_btn_search').show();";
    ajax(data, code, '', 'button_del_google_search', 'saving_del_google_search');

    return false;
}

// **********************************************************
//
//   The following functions relate to the behaviour of 
//   google search form, and not the the block itself.
//
// **********************************************************


//
// Generates contact form HTML.
//
function gen_html_google_search(block_id)
{
    var html = '';
    
    html += '<form id="form_'+block_id+'" name="form_'+block_id+'" method="get" action="http://www.google.co.il/custom" target="_top">' // name="form_search_site" 

    html += '<input type="hidden" name="domains" value="'+SITE_URL+'"></input>';
    html += '<input type="hidden" name="client" value="pub-4052287860632490"></input>';
    html += '<input type="hidden" name="forid" value="1"></input>';
    html += '<input type="hidden" name="ie" value="utf-8"></input>';
    html += '<input type="hidden" name="oe" value="utf-8"></input>';
    html += '<input type="hidden" name="cof" value="GALT:#0066CC;GL:1;DIV:#999999;VLC:336633;AH:center;BGC:FFFFFF;LBGC:FFFFFF;ALC:0066CC;LC:0066CC;T:000000;GFNT:666666;GIMP:666666;FORID:1"></input>';
    html += '<input type="hidden" name="hl" value="iw"></input>';

    html += '<input type="hidden" name="sitesearch" value="'+SITE_URL+'" id="ss1"></input>'; // Original radio field, transformed into hidden fields.

    html += '<input type="text" name="q" maxlength="40" id="sbi" style="direction: '+translate('dir')+';"></input>';
    html += '<input class="submit" type="submit" name="sa" value="'+translate('Search')+'" dir="rtl" id="sbb" style="border: 0 !important;"></input>';

    html += '</form>';
    
    return html; 
}

