function InitializePage()
{
	//clear all the fields in the Individual Plan Rate 
	//Calculator page
	
	//do the text fields first
	document.Form1.SelfAge.value = "";
	document.Form1.SpouseAge.value = "";
	document.Form1.ZipCode.value = "";
	
	//now do the drop down lists
	document.Form1.SelfSex.selectedIndex = 0;
	document.Form1.SpouseSex.selectedIndex = 0;
	document.Form1.Children.selectedIndex = 0;
	document.Form1.EffectiveDate.selectedIndex = 0;
	document.Form1.Smoker.selectedIndex = 0;
	
	//let's finish up by selecting the check boxes
	document.Form1.DeanCopay.checked = true;
	document.Form1.Dean500.checked = true;
	document.Form1.Dean1000.checked = true;
	document.Form1.Dean1500.checked = true;
	document.Form1.Dean2000.checked = true;

	
	//set the focus on the initial form element
	document.Form1.SelfAge.focus();
}


function PrintQuote()
{
	window.print();
}

function CloseWindow()
{
	window.close();
}

function resizeprintpage()
{
	window.resizeTo(760,800);
}


function isnumber()
{

	 if(event.keyCode == 8)
	 {
		//do nothing
	 }
	 //numbers have KeyCodes between 48 to 57
	 else if(event.keyCode < 48 || event.keyCode > 57)
	 { 
	 	alert("Only digits allowed.");
	 	event.returnValue = false;
	 }
}


function CheckForm()
{
	
	 
	var blnPass = true;
	
	if (document.Form1.SelfAge.value == "")
	{
		alert("You must enter your age.");
		blnPass= false;
		document.Form1.SelfAge.focus();
	}
	else if (document.Form1.SelfAge.value < 18 || document.Form1.SelfAge.value > 64)
	{
		alert("You must be between the ages of  18 to 64 to be covered under this product.");
		blnPass= false;
		document.Form1.SelfAge.focus();
	}
	else if (document.Form1.SpouseAge.value == "" && document.Form1.SpouseSex.options[document.Form1.SpouseSex.selectedIndex].value != 0)
	{
		alert("You did not specify your spouses age.");
		blnPass= false;
		document.Form1.SpouseAge.focus();
	}
	else if (document.Form1.SpouseAge.value >= 18 && document.Form1.SpouseAge.value <= 64  && document.Form1.SpouseSex.options[document.Form1.SpouseSex.selectedIndex].value == 0)
	{
		alert("You did not specify your spouses sex.");
		blnPass= false;
		document.Form1.SpouseSex.focus();
	}
	else if ((document.Form1.SpouseAge.value < 18 || document.Form1.SpouseAge.value > 64)  && document.Form1.SpouseSex.options[document.Form1.SpouseSex.selectedIndex].value != 0)
	{
		alert("Your spouse must be between the ages of  18 to 64 to be covered under this product.");
		blnPass= false;
		document.Form1.SpouseAge.focus();
	}
	else if ((document.Form1.SpouseSex.options[document.Form1.SpouseSex.selectedIndex].value == 1 && document.Form1.SelfSex.options[document.Form1.SelfSex.selectedIndex].value == 1) || (document.Form1.SpouseSex.options[document.Form1.SpouseSex.selectedIndex].value == 2 && document.Form1.SelfSex.options[document.Form1.SelfSex.selectedIndex].value == 2))
	{
		alert("Unmarried couples may apply for the individual plan separately.");
		blnPass= false;
		document.Form1.SpouseSex.focus();
	}
	else if ((document.Form1.Children.options[document.Form1.Children.selectedIndex].value != 0) && (!(document.Form1.childAge0)))
	{
		alert("Please reset Child data for correct quote");
		blnPass= false;
		document.Form1.Children.selectedIndex = 0;
		document.Form1.Children.focus();
	}
	else if (document.Form1.ZipCode.value.length != 5)
	{
		alert("You must enter your 5-digit zipcode."); 
		blnPass = false;
		document.Form1.ZipCode.focus();
	}
	else if (!document.Form1.Dean500.checked &&
			 !document.Form1.Dean1000.checked &&
			 !document.Form1.Dean1500.checked &&
			 !document.Form1.Dean2000.checked &&
			 !document.Form1.Dean5000.checked &&
			 !document.Form1.DeanCopay.checked)
	{
		alert("You must select at least one benefit option to get a quote on."); 
		blnPass = false;
	}
	 
	
	
	
	 if (blnPass)
	 {
		document.Form1.submit();
	}
	
}

function insertChildren(inputElement)
{
	//create a variable to hold our new table
	var newTable;
	
	//get the number of children selected
	var numberOfChildren = inputElement.value;
	
	//if the new number of chillin' is zero, make the table go away
	if(numberOfChildren == 0)
	{
		//don't show a table, just replace the div with another one
		newTable = DIV({'id': 'elemChildren'});	
	}
	else
	{
		//get the array of arrays with the row data	
		var rows = getRowData(numberOfChildren);
		
		newTable = TABLE({'class': 'text-body', 'id': 'elemChildren'},
    	THEAD({'class': 'text-body'}, row_display(["Child", "Age", "Sex"])),
    	TBODY({'class': 'text-body'}, map(row_display, rows)),
		TFOOT({'class': 'text-body'}, row_display([""])));
		
	}
		
	
	//swap our new table for the div tag
	swapDOM('elemChildren', newTable);

}


function getRowData(numberOfChildren)
{
	//create our array of children
	var arraysOfRowData = new Array(numberOfChildren);
	
	//alert("numberOfChildren = " + numberOfChildren);
		
	//for each element in the array, create another array (multi-dimensional)
	for(i=0;i<numberOfChildren;i++)
	{
		//alert("Initializing the array = " + i);
		arraysOfRowData[i] = new Array(3);
	}
	
	//loop through the array, adding our row data
	for(i=0;i<numberOfChildren;i++)
	{
		arraysOfRowData[i][0] = "Child " + (i + 1) + ": ";
		arraysOfRowData[i][1] = getChildAgeDDL(i);
		arraysOfRowData[i][2] = getChildSexDDL(i);
	}
		
	//return our multi-dimensional array
	return arraysOfRowData;
}


function getChildSexDDL(number)
{
	return SELECT({"name":"childSex"+number}, 
			   OPTION({"value":"Female"}, "F"), 
			   OPTION({"value":"Male"}, "M"));
}

function getChildAgeDDL(number)
{
	return SELECT({"name":"childAge"+number}, 
			   	OPTION({"value":"0"}, "<1"), 
			   	OPTION({"value":"1"}, "1"),
			   	OPTION({"value":"2"}, "2"),
			   	OPTION({"value":"3"}, "3"),
			   	OPTION({"value":"4"}, "4"),
			   	OPTION({"value":"5"}, "5"),
			   	OPTION({"value":"6"}, "6"),
			   	OPTION({"value":"7"}, "7"),
			   	OPTION({"value":"8"}, "8"),
			   	OPTION({"value":"9"}, "9"),
			   	OPTION({"value":"10"}, "10"),
			   	OPTION({"value":"11"}, "11"),
			   	OPTION({"value":"12"}, "12"),
			   	OPTION({"value":"13"}, "13"),
			   	OPTION({"value":"14"}, "14"),
			   	OPTION({"value":"15"}, "15"),
			   	OPTION({"value":"16"}, "16"),
			   	OPTION({"value":"17"}, "17"),
			   	OPTION({"value":"18"}, "18"),
			   	OPTION({"value":"19"}, "19"),
				OPTION({"value":"20"}, "20"),
			   	OPTION({"value":"21"}, "21"),
			   	OPTION({"value":"22"}, "22"),
				OPTION({"value":"23"}, "23"),
				OPTION({"value":"24"}, "24"),
			   	OPTION({"value":"25"}, "25"));
}


row_display = function (row) 
{
    //return TR(null, map(partial(TD, null), row));
	return TR(null, map(partial(TD, null), row));
}






