// init functions
$(document).ready(function() {
	//alert("when document is ready is launching");
	//hide all unnecessary form fields
	hideSpouse();
	hideChildren();
	
	//set default values for spouse form fields (until they are unhidden)
	setSpouseSentinels();
	
	//set default values for children fields (until they are unhidden)
	setChildrenSetinels();	
	
	// on select element spouse change (yes or no...)
	$('#ProspectSpouseList').change(function() {
		if ($('select#ProspectSpouseList option:selected').val() == 0) {
			clearSpouseSentinels();
			showSpouse();
		} else {
			setSpouseSentinels();
			hideSpouse();
		}
	});
	
	// on select element children change (yes or no...)
	$('#ProspectChildrenList').change(function() {
		if ($('#ProspectChildrenList').val() == 0) {
			//hide children
			hideChilda();
			hideChildb();
			hideChildc();
			hideChildd();
			hideChilde();
			hideChildf();
			
			//set sentinels
			setChildsenta();
			setChildsentb();
			setChildsentc();
			setChildsentd();
			setChildsente();
			setChildsentf();
			
		} else if ($('#ProspectChildrenList').val() == 1) {
			//hide children
			showChilda();
			
			hideChildb();
			hideChildc();
			hideChildd();
			hideChilde();
			hideChildf();
			
			//set sentinels
			clearChilda();
			
			setChildsentb();
			setChildsentc();
			setChildsentd();
			setChildsente();
			setChildsentf();
		} else if ($('#ProspectChildrenList').val() == 2) {
			//hide children
			showChilda();
			showChildb();
			
			hideChildc();
			hideChildd();
			hideChilde();
			hideChildf();
			
			//set sentinels
			clearChilda();
			clearChildb();
			
			setChildsentc();
			setChildsentd();
			setChildsente();
			setChildsentf();
		} else if ($('#ProspectChildrenList').val() == 3) {
			//hide children
			showChilda();
			showChildb();
			showChildc();
			
			hideChildd();
			hideChilde();
			hideChildf();

			//set sentinels
			clearChilda();
			clearChildb();
			clearChildc();
			
			setChildsentd();
			setChildsente();
			setChildsentf();
		} else if ($('#ProspectChildrenList').val() == 4) {
			//hide children
			showChilda();
			showChildb();
			showChildc();
			showChildd();
			
			hideChilde();
			hideChildf();

			//set sentinels
			clearChilda();
			clearChildb();
			clearChildc();
			clearChildd();
			
			setChildsente();
			setChildsentf();
		} else if ($('#ProspectChildrenList').val() == 5) {
			//hide children
			showChilda();
			showChildb();
			showChildc();
			showChildd();
			showChilde();
			
			hideChildf();

			//set sentinels
			clearChilda();
			clearChildb();
			clearChildc();
			clearChildd();
			clearChilde();
			
			setChildsentf();
		} else if ($('#ProspectChildrenList').val() == 6) {
			//hide children
			showChilda();
			showChildb();
			showChildc();
			showChildd();
			showChilde();
			showChildf();

			//set sentinels
			clearChilda();
			clearChildb();
			clearChildc();
			clearChildd();
			clearChilde();
			clearChildf();
		}
		//uncover the wrapper div after exposing only what is necessary, so that there is no on screen flashing
		showChildren();
	});
})


function hideSpouse() {
	$("#spouseSection").hide();
}
function showSpouse() {
	$("#spouseSection").show();
}
function hideChildren() {
	$("#childrenSection").hide();
}
function showChildren() {
	$("#childrenSection").show();
}

//only change values that haven't been changed away 
function setSpouseSentinels() {
	if (trim($("#ProspectSpousefirstname").val()) == "") {
		$("#ProspectSpousefirstname").val("-1");
	}
	if (trim($("#ProspectSpouselastname").val()) == "") {
		$("#ProspectSpouselastname").val("-1");
	}
	if (($("#ProspectSpousesex").val() != 1) || ($("#ProspectSpousesex").val() != 2)) {
		$("#ProspectSpousesex").val("-1");
	}
	if (trim($("#ProspectSpouseage").val()) == "") {
		$("#ProspectSpouseage").val("-1");
	}
	if (trim($("#ProspectSpouseheight").val()) == "") {
		$("#ProspectSpouseheight").val("-1");
	}
	if (trim($("#ProspectSpouseweight").val()) == "") {
		$("#ProspectSpouseweight").val("-1");
	}
	if (($("#ProspectSpousetobacco_").val() != 0) || ($("#ProspectSpousetobacco_").val() != 1)) {
		$("#ProspectSpousetobacco_").val("0");
	}
	//alert("Spouse's Sentinels were set");
}

function clearSpouseSentinels() {
	if ($("#ProspectSpousefirstname").val() == "-1") {
		$("#ProspectSpousefirstname").val("");
	}
	if ($("#ProspectSpouselastname").val() == "-1") {
		$("#ProspectSpouselastname").val("");
	}
	if (($("#ProspectSpousesex").val() != 1) || ($("#ProspectSpousesex").val() != 2)) {
		$("#ProspectSpousesex").val("");
	}
	if ($("#ProspectSpouseage").val() == "-1") {
		$("#ProspectSpouseage").val("");
	}
	if ($("#ProspectSpouseheight").val() == "-1") {
		$("#ProspectSpouseheight").val("");
	}
	if ($("#ProspectSpouseweight").val() == "-1") {
		$("#ProspectSpouseweight").val("");
	}
	if (($("#ProspectSpousetobacco_").val() != 0) || ($("#ProspectSpousetobacco_").val() != 1)) {
		$("#ProspectSpousetobacco_").val("0");
	}
}

// set child sentinel values
function setChildrenSetinels() {
	setChildsenta();
	setChildsentb();
	setChildsentc();
	setChildsentd();
	setChildsente();
	setChildsentf();
}
function setChildsenta() {
	if (trim($("#ProspectAchildage").val()) == "") {
		$("#ProspectAchildage").val("-1");
	}
	if (($("#ProspectAchildsex").val() != 0) || ($("#ProspectAchildsex").val() != 1)) {
		$("#ProspectAchildsex").val("-1");
	}
}
function setChildsentb() {
	if (trim($("#ProspectBchildage").val()) == "") {
		$("#ProspectBchildage").val("-1");
	}
	if (($("#ProspectBchildsex").val() != 0) || ($("#ProspectBchildsex").val() != 1)) {
		$("#ProspectBchildsex").val("-1");
	}
}
function setChildsentc() {
	if (trim($("#ProspectCchildage").val()) == "") {
		$("#ProspectCchildage").val("-1");
	}
	if (($("#ProspectCchildsex").val() != 0) || ($("#ProspectCchildsex").val() != 1)) {
		$("#ProspectCchildsex").val("-1");
	}
}
function setChildsentd() {
	if (trim($("#ProspectDchildage").val()) == "") {
		$("#ProspectDchildage").val("-1");
	}
	if (($("#ProspectDchildsex").val() != 0) || ($("#ProspectDchildsex").val() != 1)) {
		$("#ProspectDchildsex").val("-1");
	}
}
function setChildsente() {
	if (trim($("#ProspectEchildage").val()) == "") {
		$("#ProspectEchildage").val("-1");
	}
	if (($("#ProspectEchildsex").val() != 0) || ($("#ProspectEchildsex").val() != 1)) {
		$("#ProspectEchildsex").val("-1");
	}
}
function setChildsentf() {
	if (trim($("#ProspectFchildage").val()) == "") {
		$("#ProspectFchildage").val("-1");
	}
	if (($("#ProspectFchildsex").val() != 0) || ($("#ProspectFchildsex").val() != 1)) {
		$("#ProspectFchildsex").val("-1");
	}
}

// clear Child sentinel values
function clearChilda() {
	if ($("#ProspectAchildage").val() == "-1") {
		$("#ProspectAchildage").val("");
	}
	if (($("#ProspectAchildsex").val() != 0) || ($("#ProspectAchildsex").val() != 1)) {
		$("#ProspectAchildsex").val("");
	}
}
function clearChildb() {
	if ($("#ProspectBchildage").val() == "-1") {
		$("#ProspectBchildage").val("");
	}
	if (($("#ProspectBchildsex").val() != 0) || ($("#ProspectBchildsex").val() != 1)) {
		$("#ProspectBchildsex").val("");
	}
}
function clearChildc() {
	if ($("#ProspectCchildage").val() == "-1") {
		$("#ProspectCchildage").val("");
	}
	if (($("#ProspectCchildsex").val() != 0) || ($("#ProspectCchildsex").val() != 1)) {
		$("#ProspectCchildsex").val("");
	}
}
function clearChildd() {
	if ($("#ProspectDchildage").val() == "-1") {
		$("#ProspectDchildage").val("");
	}
	if (($("#ProspectDchildsex").val() != 0) || ($("#ProspectDchildsex").val() != 1)) {
		$("#ProspectDchildsex").val("");
	}
}
function clearChilde() {
	if ($("#ProspectEchildage").val() == "-1") {
		$("#ProspectEchildage").val("");
	}
	if (($("#ProspectEchildsex").val() != 0) || ($("#ProspectEchildsex").val() != 1)) {
		$("#ProspectEchildsex").val("");
	}
}
function clearChildf() {
	if ($("#ProspectFchildage").val() == "-1") {
		$("#ProspectFchildage").val("");
	}
	if (($("#ProspectFchildsex").val() != 0) || ($("#ProspectFchildsex").val() != 1)) {
		$("#ProspectFchildsex").val("");
	}
}

function showChilda() {
	$("#child1fields").show();
}
function hideChilda() {
	$("#child1fields").hide();
}

function showChildb() {
	$("#child2fields").show();
}
function hideChildb() {
	$("#child2fields").hide();
}

function showChildc() {
	$("#child3fields").show();
}
function hideChildc() {
	$("#child3fields").hide();
}

function showChildd() {
	$("#child4fields").show();
}
function hideChildd() {
	$("#child4fields").hide();
}

function showChilde() {
	$("#child5fields").show();
}
function hideChilde() {
	$("#child5fields").hide();
}

function showChildf() {
	$("#child6fields").show();
}
function hideChildf() {
	$("#child6fields").hide();
}
