var confirmType;

// typeRedundant
// Check if the passed type is the same as global confirmType.
// If so, return true.
// ==================================================
function typeRedundant(type) {
	// Some types SHOULD display a message after EVERY click;
	// if this is one of those, return false; the type is NOT redundant.
	switch (type) {
// =====================================================
// RFQ RESULTS
// -----------------------------------------------------
		// OEM
		case "pa_oem":
		// Overhaul Capability
		case "ohcap":

// =====================================================
// REPORT RESULTS
// -----------------------------------------------------
		// Unselecting reports from Select Enhanced Reports after
		// All Available Reports has been selected.
		case "unsel_rpt":
		
// =====================================================
// REPLY TO A CONTACT US MESSAGE
// -----------------------------------------------------
		// Unselecting reports from Select Enhanced Reports after
		// All Available Reports has been selected.
		case "emailReply":

// -----------------------------------------------------
			return false;
			break;

// =====================================================
		default:
			if (type == confirmType) {
				return true;
			}
			break;
	}
// =====================================================
}

// confirmCheck
// Present a confirm dialog after a checkbox is checked.
// ==================================================
function confirmCheck(elem, type) {
	// If the box is disabled by name, let it go.
	var isDis = elem.name.indexOf('_dis');
	// If they are CHECKING the box
	// AND the element is not disabled by name,
	// present the conf message.
	if (elem.checked && isDis == -1 && !typeRedundant(type)) {
		// Construct the conf message, based on 'type'.
		var message = confirmCheckMessage(type);
//		message += "\n\nAre you sure you want to do this?";
		confirmType = type;
		if (confirm(message)) {
			elem.checked = true;
		} else {
			elem.checked = false;
		}
	}
}

// confirmUnCheck
// Present a confirm dialog after a checkbox is unchecked.
// ==================================================
function confirmUnCheck(elem, type) {
	// If the box is disabled by name, let it go.
	var isDis = elem.name.indexOf('_dis');
	// If the box is currently dimmed, pass that along.
	var isDim = elem.className.indexOf('dim');

	// If they are CHECKING the box
	// AND the element is not disabled by name,
	// AND the element is dimmed,
	// present the conf message.
	if (!elem.checked && isDis == -1 && isDim > -1 && !typeRedundant(type)) {
		// Construct the conf message, based on 'type'.
		var message = confirmCheckMessage(type);
//		message += "\n\nAre you sure you want to do this?";
		confirmType = type;
		if (confirm(message)) {
			elem.checked = false;
			elem.className = "blur";
			// We can use this to run the next script; i.e., re-enabling the group.
			return true;
		} else {
			elem.checked = true;
			return false;
		}
	}
}
	
// confirmSelect
// Present a confirm dialog after a specific value is selected from a list.
// ==================================================
function confirmSelect(elem, checkValue) {

	if (elem.options[elem.selectedIndex].value == checkValue) {
		var message = confirmSelectMessage(checkValue);
		message += "Are you sure you want to do this?";

		// Construct the conf message, based on 'type'.
		if (!confirm(message)) {
			elem.selectedIndex = 0;
		} else {}
	}
}

// confirmCheckMessage
// Constructs the contextual portion of the confirmation message based on the passed type.
// ==================================================
function confirmCheckMessage(type) {
	// Construct the conf message, based on 'type'.
	var contextMessage;
	switch (type) {

// =====================================================
// REPORT_RES: ADDING REPORTS
// -----------------------------------------------------
		// A Select Report is being unchecked when All Available Reports is checked!  Oh no!
		case "unsel_rpt":
			contextMessage = "You have previously chosen to purchase All Available Reports for this part.\nDeselecting -this- report will -also- deselect the All Available Reports option.";
 			break;

// =====================================================
// RFQ RESULTS
// -----------------------------------------------------
		// OEM
		case "pa_oem":
			contextMessage = "Send RFQs to the selected Original Equipment Manufacturers (OEMs)?\nThese companies may not have inventory in stock.";
 			break;

		// Overhaul Capability
		case "ohcap":
			contextMessage = "Send RFQs to companies with the ability to overhaul this part?\nThese companies may not have inventory in stock.";
 			break;

// Coming Soon
// ----------------------------
		// Cage
		case "cage":
			contextMessage = "Send RFQs to manufacturers approved by the US Government?\nThese companies may no longer manufacturer this inventory or have it in stock.";
 			break;

		// Procurement History
		case "proc":
			contextMessage = "Send RFQs to companies that have sold inventory to the US Government in the past?\nThese companies may not maintain current inventory.";
 			break;

		// DRMS
		case "drms":
			contextMessage = "Send RFQs to companies that have purchased inventory from the US Government in the past?\nThese companies may not have inventory in stock.";
 			break;

// =====================================================
// DELETE FROM CART
// -----------------------------------------------------
		// Delete RFQs
		case "del_rfq":
			contextMessage = "Delete this RFQ?\nThis report will be selected for deletion and removed when you click Recalculate.\n";
			break;

		// Delete Reports
		case "del_rpt":
			contextMessage = "Delete this Report?\nThis report will be selected for deletion and removed when you click Recalculate.";
			break;

// =====================================================
// REPLY TO A CONTACT US MESSAGE
// -----------------------------------------------------
		case "emailReply":
			contextMessage = "Send these reply comments to the user?";
 			break;

// =====================================================
		default:
			return "";
	}
// =====================================================

	return contextMessage;
}

// confirmSelectMessage
// Constructs the contextual portion of the confirmation message based on the passed type.
// ==================================================
function confirmSelectMessage(type) {
	// Construct the conf message, based on 'type'.
	var contextMessage;
	switch (type) {

// =====================================================
// RFQ REQUEST TYPE: AOG
// -----------------------------------------------------
		case "AOG":
			contextMessage = "The AOG (Aircraft On Ground) Request Type requires the Tail Number.\nPlease enter the Tail Number in the Comments field.\nAOG requests without a Tail Number will be ignored!";
 			break;

// ============================

		default:
			return "";
	}

	return contextMessage + "\n\n";
}
