var changed = false;

function setChange() {
	changed = true;
	return;
}	
				
function getChange() {
	return changed;
}		

function href(targetLocation) {
	if (getChange() == true) {

		var currentAssessment, dirMSPI, dirPVIPS, dirRPP, dirSIS, msgWarning;

		currentAssessment = document.location;
		dirMSPI = /MSPI\.getTestQuestion/;
		dirPVIPS = /PVIPS\.getQuestion/;
		dirRPP = /residencyPreferenceProfile\.getFactorGroup/
		dirRPP2 = /residencyPreferenceExercise\.getFactorGroup/
		dirSIS = /specialtyIndecisionScale\.getQuestion/;

		if (dirMSPI.test(currentAssessment)) {
			msgWarning = "You have chosen to quit before completing the MSPI.\n\nYour responses will be saved and you can return later to complete the assessment.";
		}
		
		else if (dirPVIPS.test(currentAssessment)) {
			msgWarning = "You have chosen to quit before completing the PVIPS assessment.\n\nIf you quit now, your responses will not be saved and you will have to start over.";
		}

		else if ((dirRPP.test(currentAssessment)) || (dirRPP2.test(currentAssessment))) {
			msgWarning = "You have chosen to quit before completing your Residency Preference Profile.\n\nIf you quit now, your responses will not be saved and you will have to start over.";
		}
		
		else if (dirSIS.test(currentAssessment)) {
			msgWarning = "You have chosen to quit before completing the SIS assessment.\n\nIf you quit now, your responses will not be saved and you will have to start over.";
		}
		if (msgWarning != "") {
		   Ext.MessageBox.show({
	           title: 'Quit Confirmation',
	           msg: msgWarning,
    	       buttons: {ok: 'Quit', cancel: 'Cancel'},
			   closable: false,
	           fn: confirmQuit,
			   scope: {'targetLocation': targetLocation},
	           icon: Ext.MessageBox.WARNING
    	   });
		}

		else location.href = targetLocation;
	}
	
	else location.href = targetLocation;
}

function confirmQuit(btn, targetLocation) {
    if (btn == "ok") {
		location.href = this.targetLocation;
    }
}