
/*
 * Functions to show a "loading" message for AJAX pages 
 */

// Show indicator for loading pages
function pageLoading(container) {
	// This function must be fast - as the "page loaded" event can sneak in under it!
	// not that javascript is theaded, right... right?
	// Especially on IE!! Consider it broken on IE.

	// update container with loading message
	var obj = document.getElementById(container);
	obj.style.cursor = 'wait';
	obj.innerHTML = '&nbsp;<img src="/images/loading.gif" alt=""/>';
}

// Page is loaded
function pageLoaded(container) {
	document.getElementById(container).style.cursor = 'default';
	// "loading" message is overwritten by contents
}


//function update_description(description_span) {
//
//  var deferred = dojo.xhrPost({
//    url: '/componentdescriptionjoins/ajaxaddcomponentdescription',
//    handleAs: 'json',
//    form: description_span,
//    timeout: 2000, //Time in milliseconds
//    handle: function(response, ioArgs){
//              if(response instanceof Error){
//                if(response.dojoType == 'cancel'){
//                  alert('Request cancelled.');
//                }else if(response.dojoType == 'timeout'){
//                  alert('Request timed out.');
//                }else{
//                  alert("An error occurred saving the value");
//                }
//              } else {
//                if (response.result == "success") {
//                  $(description_span).innerHTML = response.description;
//                  $(description_span).parentNode.visualEffect("Highlight");
//                } else {
//                  alert("An error occurred saving the value");
//                }
//              }
//            }
//  });
//  return false;
//}



Ext.ns('Ext.ux.form');
Ext.ux.form.XCheckbox = Ext.extend(Ext.form.Checkbox, {
     submitOffValue:'false'
    ,submitOnValue:'true'

    ,onRender:function() {

        this.inputValue = this.submitOnValue;

        // call parent
        Ext.ux.form.XCheckbox.superclass.onRender.apply(this, arguments);

        // create hidden field that is submitted if checkbox is not checked
        this.hiddenField = this.wrap.insertFirst({tag:'input', type:'hidden'});

        // support tooltip
        if(this.tooltip) {
            this.imageEl.set({qtip:this.tooltip});
        }

        // update value of hidden field
        this.updateHidden();

    } // eo function onRender

    /**
     * Calls parent and updates hiddenField
     * @private
     */
    ,setValue:function(v) {
        v = this.convertValue(v);
        this.updateHidden(v);
        Ext.ux.form.XCheckbox.superclass.setValue.apply(this, arguments);
    } // eo function setValue

    /**
     * Updates hiddenField
     * @private
     */
    ,updateHidden:function(v) {
        v = undefined !== v ? v : this.checked;
        v = this.convertValue(v);
        if(this.hiddenField) {
            this.hiddenField.dom.value = v ? this.submitOnValue : this.submitOffValue;
            this.hiddenField.dom.name = v ? '' : this.el.dom.name;
        }
    } // eo function updateHidden

    /**
     * Converts value to boolean
     * @private
     */
    ,convertValue:function(v) {
        return (v === true || v === 'true' || v == 1 || v === this.submitOnValue || String(v).toLowerCase() === 'on');
    } // eo function convertValue

}); // eo extend

// register xtype
Ext.reg('xcheckbox', Ext.ux.form.XCheckbox);