var item = null;

function fade_in(item) {
    item.animate({height: 'show', opacity: 'show'}, 'fast');
}

function fade_out(item) {
    item.animate({height: 'hide', opacity: 'hide'}, 'fast');
}

function toggle(identifier) {
    var item = $(identifier);
    var shown = $(identifier+':visible').size();
    var text = $('.addhide');

    if (identifier == null || item == null) {
        window.alert("Error: Expected element not found.");
        return;
    }

    if (!shown) {
        text.html('hide');
        item.animate({height: 'show', opacity: 'show'}, 'fast');
    } else {
        text.html('add');
        item.animate({height: 'hide', opacity: 'hide'}, 'fast');
    }
}

function validate_menu() {
    var mitem = $('#cmp_menu');

    $.post("/validate_menu", { menu: mitem.val(), cmp_id: $('#cmp_id').val() },
      function(data){
        if (data.success == false) {
            window.alert('Error on IVR: ' + data.err);
            return;
        }
        $('#menu').animate({height:'hide', opacity:'hide'}, 'fast');

        $.get("/call?cmp_id=" + $('#cmp_id').val() + "&fields=" + data.fields, null,
          function(data) {
            $('#menu_test_call').html(data);
          }, "html");
        $('#menu_test_call').animate({height:'show', opacity:'show'}, 'fast');

      }, "json");
}
