function checkNumeric(inputForm,inputBoxID)
{
	var re_Int = /^[0-9\,]+$/;
	if (re_Int.test(document.forms[inputForm].elements[inputBoxID].value))
	{
		var re_Digits = /^\d+$/;
		if (re_Digits.test(toNumber(inputForm,inputBoxID)))
			return true;
		else
			return false;
	}
	else
		return false;
}

function toNumber(inputForm,inputBoxID)
{
	var inString = new String();
	inString = document.forms[inputForm].elements[inputBoxID].value;
	var searchResult = inString.indexOf(",");

	while (searchResult != -1)
	{
		inString = inString.replace(",","");
		searchResult = inString.indexOf(",");
	}

	searchResult = inString.indexOf("$");

	while (searchResult != -1)
	{
		inString = inString.replace("$","");
		searchResult = inString.indexOf("$");
	}

	return parseFloat(inString);
}

function checkMaxLimit(inputForm,inputBoxID)
{
	if ((inputBoxID == "QE_AIN") || (inputBoxID == "QE_BE") || (inputBoxID == "QE_MD") || (inputBoxID == "QE_CC"))
	{
		if (toNumber(inputForm,inputBoxID) > 30000000)
			return false;
		else
			return true;
	}
	else if ((inputBoxID == "childtuition1") || (inputBoxID == "childtuition2") || (inputBoxID == "childtuition3") || (inputBoxID == "childtuition4") || (inputBoxID == "childtuition5") || (inputBoxID == "childtuition6") || (inputBoxID == "childtuition7") || (inputBoxID == "childtuition8") || (inputBoxID == "childtuition9") || (inputBoxID == "childtuition10"))
	{
		if (toNumber(inputForm,inputBoxID) > 100000)
			return false;
		else
			return true;
	}
	else
		return true;
}

function displayEdit(inputForm,inputBoxID,CalcAYDFlag)
{
	if (document.forms[inputForm].elements[inputBoxID].value == "NaN")
		document.forms[inputForm].elements[inputBoxID].value = 0;

	if (document.forms[inputForm].elements[inputBoxID].value == " ")
		document.forms[inputForm].elements[inputBoxID].value = "";
	else
	if (document.forms[inputForm].elements[inputBoxID].value == "")
	{
		document.forms[inputForm].elements[inputBoxID].style.border = "1px solid #77a8da";
		document.forms[inputForm].elements[inputBoxID].value = 0;
	}
	else
	{
		var inputValue = toFormatNumber(toNumber(inputForm,inputBoxID));
		document.forms[inputForm].elements[inputBoxID].style.border = "1px solid #77a8da";
		document.forms[inputForm].elements[inputBoxID].value = inputValue;
	}

	if ((inputBoxID == "childtuition1") || (inputBoxID == "childtuition2") || (inputBoxID == "childtuition3") || (inputBoxID == "childtuition4") || (inputBoxID == "childtuition5") || (inputBoxID == "childtuition6") || (inputBoxID == "childtuition7") || (inputBoxID == "childtuition8") || (inputBoxID == "childtuition9") || (inputBoxID == "childtuition10"))
		if (CalcAYDFlag == null)
			recalculateCollegeCost();
		else
			recalculateCollegeCost('N');
	else
	{
		if (CalcAYDFlag == null)
			calculateLICoverage();
		else
			calculateLICoverage('N');
	}
}

function validateText(e,inputForm,inputBoxID,CalcAYDFlag)
{
	var keypressed = window.event ? e.keyCode : e.which;
	if ((keypressed == 9) || (keypressed == 144))
		return true;

	var clearinput = false;
	if (((keypressed == 46) || (keypressed == 8)) && (document.forms[inputForm].elements[inputBoxID].value == ""))
		clearinput = true;

	var validInput = true;

	if ((checkNumeric(inputForm,inputBoxID)) || clearinput)
	{
		if ((checkMaxLimit(inputForm,inputBoxID)) || clearinput)
			if ((inputBoxID == "childtuition1") || (inputBoxID == "childtuition2") || (inputBoxID == "childtuition3") || (inputBoxID == "childtuition4") || (inputBoxID == "childtuition5") || (inputBoxID == "childtuition6") || (inputBoxID == "childtuition7") || (inputBoxID == "childtuition8") || (inputBoxID == "childtuition9") || (inputBoxID == "childtuition10"))
				if (CalcAYDFlag == null)
					recalculateCollegeCost();
				else
					recalculateCollegeCost('N');
			else
			{
				if (CalcAYDFlag == null)
					calculateLICoverage();
				else
					calculateLICoverage('N');
			}
		else
		{
			document.forms[inputForm].elements[inputBoxID].style.border = "red thin inset";
			document.forms[inputForm].elements[inputBoxID].value = " ";
			document.forms[inputForm].elements[inputBoxID].focus();
			if ((inputBoxID == "QE_AIN") || (inputBoxID == "QE_BE") || (inputBoxID == "QE_MD") || (inputBoxID == "QE_CC"))
				alert("The field highlighted in red must be a dollar amount $30,000,000 or less.");
			else
				alert("The college tuition field highlighted in red must be a dollar amount $100,000 or less.");
			validInput = false;
		}
	}
	else
	{
		document.forms[inputForm].elements[inputBoxID].style.border = "red thin inset";
		document.forms[inputForm].elements[inputBoxID].value = " ";
		document.forms[inputForm].elements[inputBoxID].focus();
		alert("The field highlighted in red must contain a number entered in a dollar amount");
		validInput = false;
	}

	clearMessagingAreas();

	return validInput;
}

function clearMessagingAreas()
{
	if ((document.getElementById('AYD_Messaging_Area1')) ||
	    (document.getElementById('AYD_Messaging_Area2')) ||
	    (document.getElementById('QE_Messaging_Area')))
	{
		document.getElementById('AYD_Messaging_Area1').style.display = 'none';
		document.getElementById('AYD_Messaging_Area1').style.visibility = 'hidden';
		document.getElementById('AYD_Messaging_Area2').style.display = 'none';
		document.getElementById('AYD_Messaging_Area2').style.visibility = 'hidden';
		document.getElementById('QE_Messaging_Area').style.display = 'none';
		document.getElementById('QE_Messaging_Area').style.visibility = 'hidden';
	}
}

function getQStringCoverageAmount(qString)
{
	var NeedsAmount = toNumber("liqeForm","QE_LIN");
	var AYDAmount = toNumber("aydcForm","totalAYDCoverage");
	var DiffAmount = NeedsAmount - AYDAmount;

	if (qString.length > 0)
	{
		if (NeedsAmount > 0)
		{
			var FormatNeedsAmount = toFormatNumber(NeedsAmount);
			return (qString + "&ca=" + FormatNeedsAmount + "&uca=" + NeedsAmount);
		}
		else
			return qString;
	}
	else if (NeedsAmount > 0)
	{
		var FormatNeedsAmount = toFormatNumber(NeedsAmount);
		return ("?ca=" + FormatNeedsAmount + "&uca=" + NeedsAmount);
	}
	else
		return "";

}

function checkCoverageAmount(qString)
{
	var id;
	if (document.getElementById('lierelatedBox').style.visibility == 'visible')
		id = 'Est';
	else
		id = 'AYD';

	var NeedsAmount = toNumber("liqeForm","QE_LIN");
	var AYDAmount = toNumber("aydcForm","totalAYDCoverage");
	var DiffAmount = NeedsAmount - AYDAmount;

	if (id == 'Est')
	{
		if (NeedsAmount == 0)
		{
			document.getElementById('QE_Messaging_Area').style.display = 'block';
			document.getElementById('QE_Messaging_Area').style.visibility = 'visible';
			document.getElementById('AYD_Messaging_Area1').style.display = 'none';
			document.getElementById('AYD_Messaging_Area1').style.visibility = 'hidden';
			document.getElementById('AYD_Messaging_Area2').style.display = 'none';
			document.getElementById('AYD_Messaging_Area2').style.visibility = 'hidden';
			document.all['QECAQuoteDiv'].innerHTML = "Do you want to proceed to " + constructURLLinkWithTags('/view/page/13036',qString,'Get a Quote','<B><U>','</U></B>') + " and enter an amount?";
			document.getElementById('QECAQuoteDiv').style.display = 'block';
			document.getElementById('QECAQuoteDiv').style.visibility = 'visible';
		}
		else if (((NeedsAmount > 0) && (NeedsAmount < 100000)) || (NeedsAmount > 30000000))
			window.location="/view/page/10262" + getQString();
		else
			window.location="/view/page/13036" + getQStringCoverageAmount(qString);
	}
	else if (DiffAmount == 0)
	{
		if (((NeedsAmount > 0) && (NeedsAmount < 100000)) || (NeedsAmount > 30000000))
			window.location="/view/page/10262" + getQString();
		else if (AYDAmount > 0)
		{
			document.getElementById('AYD_Messaging_Area2').style.display = 'block';
			document.getElementById('AYD_Messaging_Area2').style.visibility = 'visible';
			document.getElementById('AYD_Messaging_Area1').style.display = 'none';
			document.getElementById('AYD_Messaging_Area1').style.visibility = 'hidden';
			document.getElementById('QE_Messaging_Area').style.display = 'none';
			document.getElementById('QE_Messaging_Area').style.visibility = 'hidden';
			document.all['AYDCA2QuoteDiv'].innerHTML = "Otherwise, proceed to " + constructURLLinkWithTags('/view/page/13036',getQStringCoverageAmount(qString),'Get a Quote','<B><U>','</U></B>');
			document.getElementById('AYDCA2QuoteDiv').style.display = 'block';
			document.getElementById('AYDCA2QuoteDiv').style.visibility = 'visible';
		}
		else
		{
			document.getElementById('AYD_Messaging_Area1').style.display = 'block';
			document.getElementById('AYD_Messaging_Area1').style.visibility = 'visible';
			document.getElementById('AYD_Messaging_Area2').style.display = 'none';
			document.getElementById('AYD_Messaging_Area2').style.visibility = 'hidden';
			document.getElementById('QE_Messaging_Area').style.display = 'none';
			document.getElementById('QE_Messaging_Area').style.visibility = 'hidden';
			document.all['AYDCA1QuoteDiv'].innerHTML = "Otherwise, proceed to " + constructURLLinkWithTags('/view/page/13036',qString,'Get a Quote','<B><U>','</U></B>') + " and enter an amount.";
			document.getElementById('AYDCA1QuoteDiv').style.display = 'block';
			document.getElementById('AYDCA1QuoteDiv').style.visibility = 'visible';
		}
	}
	else if (((NeedsAmount > 0) && (NeedsAmount < 100000)) || (NeedsAmount > 30000000))
		window.location="/view/page/10262" + getQString();
	else if (NeedsAmount > 0)
		window.location="/view/page/13036" + getQStringCoverageAmount(qString);
}
