﻿


/*
Script: TabSwapper.OnChanges.js
	Extends Request and Request.HTML to automatically include a unique noCache value to prevent request caching.

License:
	http://www.clientcide.com/wiki/cnet-libraries#license
*/

/*		options: {
				checkDirty: false
			}, */
			
var TabSwapper = new Class ({
    Extends : TabSwapper,
    show: function(i){
        var cont = true;
	    if (this.options.checkDirty) {
            if ( this.isDirty ) {
                // check to see if the user wishes to continue
                if ( confirm("Changes have been made. Do you wish to continue and loose all changes.") ) {
                    this.isDirty = false;
                } else {
                    cont = false;
                }
            } 
	    }
	    if ( cont )
	        this.parent(i);
    },
    // override the addTab to add events to the inputs.
	addTab: function(tab, section, clicker, index) {
	    if ( this.options.checkDirty) {
	        this.isDirty = false;
            section.getElements('input').each( function (input) {
                input.addEvent('change', function(e) {
                    this.isDirty = true
                }.bind(this)); 
            }.bind(this));
            section.getElements('select').each( function (input) {
                input.addEvent('change', function(e) {
                    this.isDirty = true
                }.bind(this)); 
            }.bind(this));
            section.getElements('textarea').each( function (input) {
                input.addEvent('change', function(e) {
                    this.isDirty = true
                }.bind(this)); 
            }.bind(this));			    
        }
	    
	    this.parent(tab, section, clicker, index);
	}
});