/* Just a simple script define various small functions.
 */

/* Simple function that uses the ajax_translate page to let
   Plone manage the translation of some strings.
 */
ajax_translate = function(msg) {
    var res = '';
    jq.ajax({url: 'ajax_translate?msg=' + msg,
		success: function(d) {
		             res = d;
	                 },
		async: false});

    return res;
};

bind_improvement_inline_edit = function($) {
    /* Bindings for JobPerformance edit. */
    here = window.location;

    $('div#improvement-areas').pyproxy('click',
				       here +'/jq_show_improvement_edit_form');
    $('form.inlineForm input[name=improvement-save]').pyproxy('click',
							      here + '/jq_hide_improvement_edit_form',
							      '#improvement-areas-edit');
    
    $('form.inlineForm input[name=improvement-cancel]').pyproxy('click',
								here + '/jq_hide_improvement_edit_form');	
};

/* Hides messages which have the 'no_js_warning' class.*/
hide_no_js = function() {
	jq('.no_js_warning').remove();
}

jq(document).ready(function() {
    /* Fix display bug when bad files are submitted in employee edit page.*/
    jq('#archetypes-fieldname-idScan.error, #archetypes-fieldname-portrait.error').append('<div class="visualClear"></div>');

    bind_improvement_inline_edit(jQuery);
    hide_no_js();

    /* Display or hide spinner when a Ajac call is performed.*/
    jQuery('#kss-spinner').ajaxStart(
	function() {
	    $(this).show();
	});

    /* Display or hide spinner when a Ajac call is performed.*/
    jQuery('#kss-spinner').ajaxStop(
	function() {
	    $(this).hide();
	    hide_no_js();
	});
});