// pharmacy flow control--especially to handle back button (jea:8/29/00)
// depends on cookies.js

// strings of valid referers named after page
// assumes "pharmacy_[name].asp"
// use empty string for no referer check
var start = "";
var patient_select = "";
var patient_profile = "patient_profile,patient_select,verify_order,medical_profile";
var medical_profile = "";
var delivery = "delivery,checkout,patient_profile,patient_select";
var payment = "";
var insurance = "insurance,payment";
var scrips = "scrips,payment,insurance,verify_order";
var checkout = "";
var verify_order = "";

// retrieve short page name
var re = /pharmacy_(.+)\.asp$/i;
var aMatch = re.exec(location.pathname);
var sThisPage = aMatch[1];

if (allowRefer(eval(sThisPage))) {
	setCookie("FLOW",sThisPage,"");
} else {
	alert('Using the back button to edit information may create duplicate entries.\nUse the "Edit" buttons on the verify page to change information.');
	history.go(1);
}

// does this page allow referring page (jea:8/29/00)
// returns boolean -------------------------------------------------------
function allowRefer(sReferList) {
	if (sReferList != "") {
		// compare referer to those allowed	
		var sReferPage = getCookie("FLOW");
		if (sReferPage == "verify_order" ||
		   (sReferPage == "medical_profile" && sThisPage == "patient_profile")) {
			// verify and return from med must be in edit mode
			if (getQS("act") != "edit") { return false;	}
		}
		re = new RegExp(sReferPage);
		return re.test(sReferList) ? true : false;
	}
	// no referer check
	return true;
}



