// used by dspLinkYourSite.cfm
function copyToClipboard(theField) {
	var ff=document.getElementById(theField);

	ff.focus();
	ff.select();

	// createTextRange() is IE only.  let's not throw errors in other browsers, m'kay?'
	if (navigator.appName.indexOf('Internet Explorer') > 0) {
		therange=ff.createTextRange();
		therange.execCommand("Copy");
	}
}

// used by dspLinks.cfm
function showHideDiv(divID) {
	if (document.getElementById(divID).style.display=="block") {
		document.getElementById(divID).style.display="none";
	} else {
		document.getElementById(divID).style.display="block";
	}
}

/************************* Application Quote Calculator Functions *************************/

	function QCcboxActions(coverageID, displayQty, premium, displayCode, qty, isChecked) {
		if (displayQty) {
			QCenableQty(coverageID, isChecked);
		}
		QCupdateDependency(coverageID, displayQty, isChecked);
		QCcalculateTotals(coverageID, premium, qty, isChecked);
		if (displayCode == 'P++') {
			QCupdatePlatinumPlusOptions(isChecked);
		}
	}

	function QCcalculateTotals(coverageID, val, qty, isChecked) {
		var prevQty = document.getElementById('cvg' + coverageID + '_qty');
		var prevSubTotal = document.getElementById('optionsPrice').innerHTML;

		if (isChecked) {
			if (prevQty.value != qty) {
				thisQty = qty - prevQty.value;
			} else {
				thisQty = qty;
			}
			subTotal = parseFloat(prevSubTotal) + parseFloat((val * thisQty));
			prevQty.value = qty;

		} else {
			subTotal = parseFloat(prevSubTotal) - parseFloat(val * prevQty.value);
			prevQty.value = 1;
		}

		document.getElementById('optionsPrice').innerHTML	= subTotal.toFixed(2);
		grandTotal 	= parseFloat(document.getElementById('planPremium').innerHTML) + parseFloat(document.getElementById('optionsPrice').innerHTML);
		document.getElementById('totalPrice').innerHTML 	= grandTotal.toFixed(2);
	}

	function QCupdateDependency(coverageID, displayQty, isChecked) {
		for (var i=0; i<dependencyArray[coverageID].length; i++) {
			thisCheckbox = document.getElementById('price' + dependencyArray[coverageID][i]);	// the dependent checkbox
			if (isChecked) {
				thisCheckbox.disabled	= false;
			} else {
				premium = thisCheckbox.value;
				if (thisCheckbox.checked) {
					QCcalculateTotals(dependencyArray[coverageID][i], premium, 0, false);
				}
				thisCheckbox.checked	= false;
				thisCheckbox.disabled	= true;
				if (displayQty) {
					QCenableQty(coverageID, false);
				}
			}
		}
	}

	function QCenableQty(coverageID, isChecked) {
		if (isChecked) {
			document.getElementById('qty' + coverageID).disabled = false;
		} else {
			document.getElementById('qty' + coverageID).selectedIndex = 0;
			document.getElementById('qty' + coverageID).disabled = true;
		}
	}

	function QCupdatePlatinumPlusOptions(isChecked) {
		var PPIDArray = PPIDList.split(',');
		for (var i=0; i<PPIDArray.length; i++) {
			if (isChecked) { // the user has selected the P++ option
				if (document.getElementById('price'+ PPIDArray[i]).checked) {
					document.getElementById('price' + PPIDArray[i]).checked = false;
					QCcalculateTotals(PPIDArray[i], document.getElementById('price' + PPIDArray[i]).value, 0, false);	// update calculator
				}
				document.getElementById('price' + PPIDArray[i]).disabled = true;
			} else {	// the user has deselected the P++ option
				document.getElementById('price' + PPIDArray[i]).disabled = false;
			}
		}
	}
	
/************************* Application Quote Calculator Functions *************************/