//
// Displays form for editing contact form
// configuration.
//
function display_edit_contact_form(block_id)
{
    set_form_field('form_contact', FLD_BLOCK_ID, block_id);
    set_form_field('form_contact', 'action', 'ajax_update_block_contact');
    set_form_field('form_contact', 'title', $('#mblock_title_'+block_id).html());
                    
    $('#button_del_contact').show();
}

//
// Send contact form.  
//
// Used for adding / editing contact form.
//
function send_edit_contact_form()
{
    var title = get_form_field('form_contact', 'title');
    var block_id = get_form_field('form_contact', FLD_BLOCK_ID);
    
    if (title == '')
    {
        my_alert('all field are must');
        return false;
    }

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

    ajax(data, code, "", "button_contact", "saving_contact");

    return false;
}

//
// Deletes contact block.
//
function del_block_contact()
{
    var title = $('#mblock_title_'+block_id).html();
    
    if (confirm(translate('should I delete the form') + ' ' + title))
    {
        document.forms['form_contact'].action.value = 'ajax_del_block_contact';
        var block_id = get_form_field('form_contact', FLD_BLOCK_ID);
        var data = $('#form_contact').serialize();
        var code = "hide_block("+block_id+");";
        code += "close_modals();"
        ajax(data, code);
    }

    return false;
}

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


//
// Generates contact form HTML.
//
function gen_html_contact(block_id, config)
{
    var html = '';
    
    html += '<form id="form_'+block_id+'" name="form_'+block_id+'" class="block_contact" action="'+get_url_action()+'" method="post">'
    
    html += '<input type="hidden" name="action" value="contact" />';
    html += '<input type="hidden" name="'+FLD_PAGE_ID+'" value="'+PAGE_ID+'" />';
    
    html += '<div class="form_item">'; 
    html += '<label>'+translate('name')+'</label>'; 
    html += '<input type="text" name="name" alt="must" onfocus="$(\'#msg_'+block_id+'\').html(\'\')" />'; 
    html += '</div>'; 
    
    html += '<div class="form_item">'; 
    html += '<label>'+translate('email')+'</label>'; 
    html += '<input type="text" name="email" class="ltr" alt="must" onfocus="$(\'#msg_'+block_id+'\').html(\'\')" />'; 
    html += '</div>'; 
    
    html += '<div class="form_item">'; 
    html += '<label>'+translate('phone')+'</label>'; 
    html += '<input type="text" name="phone" class="ltr" alt="must" onfocus="$(\'#msg_'+block_id+'\').html(\'\')" />'; 
    html += '</div>'; 
    
    html += '<div class="form_item">'; 
    html += '<label>'+translate('content')+'</label>'; 
    html += '<textarea name="text" alt="must" onfocus="$(\'#msg_'+block_id+'\').html(\'\')"></textarea>'; 
    html += '</div>'; 
    
    html += '<div class="form_item big">'; 
    html += '<label>&nbsp;</label>'; 
    html += '<button id="button_'+block_id+'" onclick="send_bform('+block_id+'); return false;">'+translate('send')+'</button>'; 
    html += '<img id="saving_'+block_id+'" class="image_saving hidden" src="'+CSS_IMAGE_SAVING+'" />'; 
    html += '<p id="msg_'+block_id+'"></p>'; 
    html += '</div>'; 
    
    html += '</form>';
    
    return html; 
}
