function frmQuoteFinderPDFSuccess() {
	var msg = "Please read this important information about your quote:\n";
	msg += "The quote(s) is not a binding contract between you and Sanford Health Plan.  You must complete and sign an Application for elite1 Individual Health Insurance to apply for coverage.\n";
	msg += "Actual rates may vary based on health conditions, which family members are approved for coverage and on your selection of plan type.";
	return confirm(msg);
}
function frmQuoteFinderPDFFailure() {
	alert("You must select a deductible and at least one person to generate a PDF.");
}

function frmQuoteFinderFailure(el) {
	var msg = "There is a problem with the form.";
	if (el)
		msg += "\n\nDebug info: ERROR on "+el;
	alert(msg);
}

// As items are selected, we want to keep track of that so we can validate against it.
function qfToggleQuantity(el, target) {
	var curNum = document.getElementById(target).value;
	var num = 0;
	if (curNum) { num = parseInt(curNum); }
	(el.checked) ? num += 1 : num -= 1;
	if (num == 0) { num = ""; }
	document.getElementById(target).value = num;
}

// Recursively search the DOM through parentNodes until you find a hidden one.
function isHidden(el) {
	if (el.nodeType == 1) {
		if ((el.style.display !== "none") || (el.style.display == "")) {
			status = false;
			el = el.parentNode;
			isHidden(el);
		} else { status = true; }
	}
	
	return status;
}

// Validate the form (frm is the ID) looking for form elements with a class of "required".
// Only validate them if they're not hidden.
// Pass an optional msg string that will display in an alert if problems arise.
function qfValidate(frm, onfail, onsuccess) {
	var status = true;
	if (!onfail) { onfail = ""; }
	if (!onsuccess) { onsuccess = ""; var success = true; } else { var success = false; }
	var offs = "";
	var req = getElementsByClass("required",document.getElementById(frm),'*');
	
/*
	if (req.length > 0) {
		for (i=0; i<req.length; i++){
			if ((req[i].value == "") && (isHidden(req[i]) == "false" || isHidden(req[i]) == false)) {
				req[i].style.backgroundColor = "#D00";
				offs += req[i].id + "|";
				status = false;
			} else { req[i].style.backgroundColor = "#FFF"; }
		}
	}
*/
	if (document.getElementById("IsSelf")){
		var IsSelf = document.getElementById("IsSelf");
		var IsSelfFirstName = document.getElementById("IsSelfFirstName");
		if (IsSelf.checked == true && IsSelfFirstName.value.length < 1) { status = false; }
	}
	if (document.getElementById("IsSpouse")){
		var IsSpouse = document.getElementById("IsSpouse");
		var IsSpouseFirstName = document.getElementById("IsSpouseFirstName");
		if (IsSpouse.checked == true && IsSpouseFirstName.value.length < 1) { status = false; }
	}
	var Zip = document.getElementById("Zip");
	if (Zip.value.length != 5) { status = false; }

	if ((status == false) && (onfail.length > 0)) { eval(onfail+"(offs)"); }
	if ((status == true) && (onsuccess.length > 0)) { success = eval(onsuccess+"()"); }

	return (status && success);
}

// Hide all divs of the class "qf-details"
function qfHideDetails() {
	var chkName = "";
	var divs = getElementsByClass("qf-details",document,"div");

	for (i = 0; i < divs.length; i++) {
		chkName = divs[i].id.substring(0, divs[i].id.indexOf("Details"));
		toggleDisplay(divs[i],document.getElementById(chkName).checked);
	}
}

// Remove this specific Child clone
function qfRemoveChild(ch) {
	var child = document.getElementById(ch);
	var num = document.getElementById("IsChildrenQuantity").value;
	var newNum = parseInt(num)-1;

	if (child) {
		var parent = child.parentNode;
		parent.removeChild(child);
		document.getElementById("IsChildrenQuantity").value = newNum;
	}
	var fsets = document.getElementById("IsChildrenDetails").getElementsByTagName("fieldset");
	for (i=0; i<fsets.length; i++){
		fsets[i].id = "IsChildrenDetails_"+(i+1);
		fsets[i].getElementsByTagName("legend")[0].innerHTML = 'Dependent '+(i+1);
		var newHTML = fsets[i].innerHTML.replace(/_\d/g, "_"+(i+1));
		fsets[i].innerHTML = newHTML;
	}
}

// Clone the Child
function qfAddChildren() {
	var set = document.getElementById("IsChildrenDetails_1");
	var num = document.getElementById("IsChildrenQuantity").value;
	var newSet = set.cloneNode(false);
	var newNum = 1+parseInt(num);
	
	newSet.id = "IsChildrenDetails_"+newNum;
	newSet.innerHTML = set.innerHTML.replace(/_1/g, "_"+newNum);
	newSet.innerHTML = newSet.innerHTML.replace(/value=\"*\w*\"*\s/gi, " ");
	newSet.innerHTML = newSet.innerHTML.replace(/selected/gi, " ");
	newSet.getElementsByTagName("legend")[0].innerHTML = 'Dependent '+newNum;
	
	set.parentNode.appendChild(newSet);
	document.getElementById("IsChildrenQuantity").value = newNum;
}

// All initial functions we want to call
function qfInit() {
	qfHideDetails();
}

// Add our initiation to the onLoad event of the body
addLoadEvent(qfInit);