// Changing database names 
$(function(){
	
		function onMigrationSourceChanged(){
			if($('select#type').val() == 1){
                hideFogbugz();
                hideBaseCamp();
                showBugTrackers();
                $('input#url').val("jdbc:mysql://localhost/mantis?autoReconnect=true");
			} else if($('select#type').val() == 2){
				$('input#url').val("jdbc:mysql://localhost/bugzilla?autoReconnect=true");
				hideBaseCamp();
                hideFogbugz();
                showBugTrackers();
            } else if($('select#type').val() == 3){
                hideFogbugz();
                hideBugTrackers();
                showBaseCamp();                
            } else if($('select#type').val() == 4){
                hideBaseCamp();
                hideBugTrackers();
                showFogbugz();
            }
		}
		
		function showBaseCamp(){
            enableFieldsInDiv($('div#iBasecamp'));
			$('div#iBasecamp').removeClass('hide');
		}
		
		function hideBaseCamp(){
			$('div#iBasecamp').addClass('hide');
			disableFieldsInDiv($('div#iBasecamp'));
		}

        function showFogbugz(){
            enableFieldsInDiv($('div#iFogbugz'));
			$('div#iFogbugz').removeClass('hide');
		}

		function hideFogbugz(){
			$('div#iFogbugz').addClass('hide');
			disableFieldsInDiv($('div#iFogbugz'));
		}

        function showBugTrackers(){
            enableFieldsInDiv($('div#iBugTrackers'));
			$('div#iBugTrackers').removeClass('hide');
		}

		function hideBugTrackers(){
			$('div#iBugTrackers').addClass('hide');
			disableFieldsInDiv($('div#iBugTrackers'));
		}

        function onMigrationPerformed(){
            $('div#dlgMigration').removeClass('hide');
            $('div#dlgMigration').modal();
            $('form#migration').submit();
        }

        $('select#type').bind('change',onMigrationSourceChanged);

        $('input#btnMigration').bind('click', onMigrationPerformed);
});