//
// Displays form for adding / editing contact form.
//
function display_add_contact_form()
{
    set_form_field('form_contact', FLD_BLOCK_ID, '');
    set_form_field('form_contact', 'action', 'ajax_add_block_contact');
    set_form_field('form_contact', 'title', '');
                    
    $('#button_del_contact').hide();
}

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();"
    code += "$('#am_btn_contact').hide();";

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

    return false;
}

//
// Deletes contact block.
//
function del_block_contact()
{
    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();"
    code += "$('#am_btn_contact').show();";
    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="unid_contact" />';
    html += '<input type="hidden" name="'+FLD_PAGE_ID+'" value="'+PAGE_ID+'" />';
    
    html += '<div class="form_item">'; 
    html += '<input type="text" name="name" value="'+translate('name')+'" alt="must" onfocus="$(\'#msg_'+block_id+'\').html(\'\'); clear_field(this, \''+translate('name')+'\');" onblur="reset_field(this, \''+translate('name')+'\');" />'; 
    html += '</div>'; 
    
    html += '<div class="form_item">'; 
    html += '<input type="email" name="email" value="'+translate('email')+'" class="ltr" alt="must" onfocus="$(\'#msg_'+block_id+'\').html(\'\'); clear_field(this, \''+translate('email')+'\');" onblur="reset_field(this, \''+translate('email')+'\');" />'; 
    html += '</div>'; 
    
    html += '<div class="form_item">'; 
    html += '<input type="text" name="phone" value="'+translate('phone')+'" class="ltr" alt="must" onfocus="$(\'#msg_'+block_id+'\').html(\'\'); clear_field(this, \''+translate('phone')+'\');" onblur="reset_field(this, \''+translate('phone')+'\');" />'; 
    html += '</div>'; 
    
    html += '<div class="form_item">'; 
    html += '<textarea name="text" style="height: 100px;" alt="must" onfocus="$(\'#msg_'+block_id+'\').html(\'\'); clear_field(this, \''+translate('content')+'\');" onblur="reset_field(this, \''+translate('content')+'\');">'+translate('content')+'</textarea>'; 
    html += '</div>'; 
    
    html += '<div class="form_item">'; 
    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; 
}

