// This script is intended for use with a minimum of Netscape 4 or IE 4.

//Function Name : TraversingAddEmp
//Purpose : The Function is used to Handle Enter key press for Add Employee Screen

/*function TraversingEmployee()
{
	var strActiveElement='';
	var tabObj = document.getElementById("tabHSACalculator"); 
	
	// Help buttons are not taken care.
	// Need to take care when coding for help "?" Buttons
	
	if(tabObj.selectedIndex==0)
	{
		pContHSA = window.document.getElementById('imgContinuetoHSA');
		if(pContHSA != null)
		{
			strActiveElement='imgContinuetoHSA';
		}
	}
	
	if(tabObj.selectedIndex==1)
	{	
		pContMUse = window.document.getElementById('imgContinuetoMedicalUse');
		if(pContMUse != null)
		{
			strActiveElement='imgContinuetoMedicalUse';
		}
	}
	
	if(tabObj.selectedIndex==2)
	{
		pEstSavings = window.document.getElementById('imgEstimateSavings');
		if(pEstSavings != null)
		{
			strActiveElement='imgEstimateSavings';
		}	
	}
		
	return HandleEnterKey(strActiveElement);
	
}*/

function TraversingEmployee(aParDefaultActiveElement)
{
	var strActiveElement;
	strActiveElement='';

	if (aParDefaultActiveElement!='')
		strActiveElement=aParDefaultActiveElement;
		
	if  (window.document.activeElement.id=='imgBacktoCurrPlan')
		strActiveElement='imgBacktoCurrPlan';
		
	if  (window.document.activeElement.id=='imgBacktoHSAPlan')
		strActiveElement='imgBacktoHSAPlan';
		
	return HandleEnterKey(strActiveElement);
}


// Open form in a new window

function OpenPrint()
{
	//window.open("PrintEmployeeHSA.aspx");
	MM_openBrWindow('PrintEmployeeHSA.aspx','','scrollbars=yes,width=775,height=475,left=90,top=70,menubar=yes,resizable=yes');
	return true;
}

function ValidateControls1()
{
  	var txtCMPPObj=document.getElementById("txtCurrentMonthlyPlanPremium")
  	var valString='';
   	
   	valString = valString + "txtCurrentMonthlyPlanPremium~Employee Monthly Plan Premium";
	
	
	// To check for mandatory fields
	if (CheckMandatoryFields(valString) == false)
		return false;
		
	if (isFloat(txtCMPPObj) == false)
	{
		alert("Employee Monthly Plan Premium");
		txtCMPPObj.focus();
		return false;
	}		
	return true;
}

function ValidateControls1Radio()
{
	if (ValidateControls1()==true)
		window.document.frmEmployeeCurrentPlan.submit();
	else
	{
		document.getElementById("rbtnCurrPlan").checked = true;
		return false;	
	}
}

function BackValidateControls2() 
{
	var txtHSAMonPlanPreObj = document.getElementById("txtHSAMonthlyPlanPremium")
	var txtHSAContObj = document.getElementById("txtHSACont")
	var txtMarginalTaxRateObj = document.getElementById("txtMarginalTaxRate");

	if (txtHSAMonPlanPreObj.value == '' && txtHSAContObj.value == '' && txtMarginalTaxRateObj.value == '')
		return true;

	if (txtHSAMonPlanPreObj.value != '')
		if (isFloat(txtHSAMonPlanPreObj) == false)
		{
			alert("Please enter a valid Monthly Plan Premium");
			txtHSAMonPlanPreObj.focus();
			return false;
		}	
	if(txtHSAContObj.value != '')
		if (isFloat(txtHSAContObj)==false)
		{
			alert("Please enter a valid Monthly HSA Contribution");
			txtHSAContObj.focus();	
			return false;
		}
	
	if(checkMarginalTaxRate() == false)
		return false;
	 
	return true;
}

function checkMarginalTaxRate()
{
	var txtMarginalTaxRateObj = document.getElementById("txtMarginalTaxRate");
	if(txtMarginalTaxRateObj.value != '')
		if(isFloat(txtMarginalTaxRateObj)==false)
		{
			alert ("Please enter a valid Marginal Tax Rate.");
			txtMarginalTaxRateObj.focus();
			return false;
		}	
	
	if((txtMarginalTaxRateObj.value < 0) || (txtMarginalTaxRateObj.value > 100)) 
	{
		alert ("Please enter a valid Marginal Tax Rate.");
		txtMarginalTaxRateObj.focus();
		return false;
	}
}

var reFloat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/

function isFloat (s)
{   
	if (isEmpty(s)) 
		if (isFloat.arguments.length == 1) 
			return false;
		else 
			return (isFloat.arguments[1] == true);

    return reFloat.test(s.value)
}

function isEmpty(s)
{   
	return ((s == null) || (s.length == 0))
}

function BackValidateControls2Radio() 
{
	if(BackValidateControls2() == true)
		window.document.frmEmployeeHSAPlan.submit();
	else
	{
		document.getElementById("rbtnHSAPlan").checked = true;
		return false;		
	}
	return true;
}

function ValidateControls2() 
{
   	
	var txtHSAMonPlanPreObj=document.getElementById("txtHSAMonthlyPlanPremium");
	var txtHSAContObj=document.getElementById("txtHSACont");
	var ddlCoverageObj = document.getElementById("ddlCoverage");
	var ddlHSADeductibleObj = document.getElementById("ddlHSADeductible");
	var ddlHSAMaxOutOfPocketObj = document.getElementById("ddlHSAMaxOutOfPocket");

  	var valString='';
  	
   	valString = valString + "txtHSAMonthlyPlanPremium~Monthly Plan Premium";
   	valString = valString + ",txtHSACont~HSA Contribution";
    valString = valString + ",txtMarginalTaxRate~Marginal Tax Rate";
				
	// To check for mandatory fields
  
	if (CheckMandatoryFields(valString)==false)
		return false;
	
	if (isFloat(txtHSAMonPlanPreObj)==false)
	{
		alert("Please enter a valid Monthly Plan Premium");
		txtHSAMonPlanPreObj.focus();
		return false;
	}	
		
    if (isFloat(txtHSAContObj)==false)
    {
		alert("Please enter a valid Monthly HSA Contribution");
		txtHSAContObj.focus();	
		return false;
	}	
	  
	if(checkMarginalTaxRate() == false)
		return false;
	
	if(ddlCoverageObj.selectedIndex == 0)
	{
		alert("Please select a valid coverage type");
		ddlCoverageObj.focus();
		return false;
	}
		
	if(ddlCoverageObj.selectedIndex == 1 && ddlHSADeductibleObj.selectedIndex > 4)
	{
		alert("Please enter Deductible value less than or equal to $2,500.");
		ddlHSADeductibleObj.focus();
		return false; 	
	}
	
	if(ddlHSAMaxOutOfPocketObj.selectedIndex == 0)
	{
		alert("Please select a valid Maximum Out Of Pocket");
		ddlHSAMaxOutOfPocketObj.focus();
		return false; 		
	}
	
	return true;
}
	

function ValidateControls2Radio()
{
	if (ValidateControls2()==true)
		window.document.frmEmployeeHSAPlan.submit();
	else
	{
		document.getElementById("rbtnHSAPlan").checked = true;
		return false;	
	}
}

function ValidateControls3()
{ 
	
	var txtOutOfPocCostObj=document.getElementById("txtOutOfPocketCost")
	var valString='';
	
	var txtNumofVisitstoDoctorObj = document.getElementById("txtNumofVisitstoDoctor");
	var txtNumofGenericPresObj = document.getElementById("txtNumofGenericPres");
	var txtNumofBrandNamePresObj = document.getElementById("txtNumofBrandNamePres");
	
	valString = valString + "txtNumofVisitstoDoctor~How many times do you expect to visit the doctor next year? ";
	valString = valString + ",txtNumofGenericPres~How many generic prescriptions per month?";
	valString = valString + ",txtNumofBrandNamePres~How many brand name prescriptions per month?";
	valString = valString + ",txtOutOfPocketCost~What are your out of pocket costs in excess of co-pays?"; 
	
	// To check for mandatory fields
	if (CheckMandatoryFields(valString) == false)
		return false;
	  
	
	if (isPInteger(txtNumofVisitstoDoctorObj) == false)
	{
		alert("Please enter valid number of visits to the Doctor");
		txtNumofVisitstoDoctorObj.focus();
		return false;
	}	  
	 
	if (isPInteger(txtNumofGenericPresObj) == false)
	{
		alert("Please enter valid Number of Generic Prescriptions");
		txtNumofGenericPresObj.focus();
		return false;
	}	  
	
	if (isPInteger(txtNumofBrandNamePresObj) == false)
	{
		alert("Please enter valid Number of Generic Prescriptions");
		txtNumofBrandNamePresObj.focus();
		return false;
	}
	  
	if(isFloat(txtOutOfPocCostObj) == false)
	{
		alert("Please enter valid out of pocket costs in excess of co-pays");
		txtOutOfPocCostObj.focus();
		return false;
	}	
	
	return true;
}

function ValidateControls3Radio()
{
	if (ValidateControls3() == true)
		window.document.frmEmployeeMedicalUse.submit();
	else
	{
		document.getElementById("rbtnMedUse").checked = true;
		return false;	
	}
}

function BackValidateControls3()
{ 
	var txtOutOfPocCostObj=document.getElementById("txtOutOfPocketCost")
	var txtNumofVisitstoDoctorObj = document.getElementById("txtNumofVisitstoDoctor");
	var txtNumofGenericPresObj = document.getElementById("txtNumofGenericPres");
	var txtNumofBrandNamePresObj = document.getElementById("txtNumofBrandNamePres");
	
	if(txtNumofVisitstoDoctorObj.value != '')
	{
		if (isPInteger(txtNumofVisitstoDoctorObj) == false)
		{
			alert("Please enter valid number of visits to the Doctor");
			txtNumofVisitstoDoctorObj.focus();
			return false;
		}	  
	 }

	if(txtNumofGenericPresObj.value != '')
		if (isPInteger(txtNumofGenericPresObj) == false)
		{
			alert("Please enter valid Number of Generic Prescriptions");
			txtNumofGenericPresObj.focus();
			return false;
		}	  

	if(txtNumofBrandNamePresObj.value != '')
		if (isPInteger(txtNumofBrandNamePresObj) == false)
		{
			alert("Please enter valid Number of Generic Prescriptions");
			txtNumofBrandNamePresObj.focus();
			return false;
		}

	if(txtOutOfPocCostObj.value != '')
		if(isFloat(txtOutOfPocCostObj) == false)
		{
			alert("Please enter valid out of pocket costs in excess of co-pays");
			txtOutOfPocCostObj.focus();
			return false;
		}	
	
	return true;
}

function BackValidateControls3Radio()
{
	if(BackValidateControls3() == true)
		window.document.frmEmployeeMedicalUse.submit();
	else
	{
		document.getElementById("rbtnMedUse").checked = true;
		return false;		
	}
	return true;
}

var reInteger = /^\d+$/

function isPInteger(s)
{   
	if (isEmpty(s))	
		if (isPInteger.arguments.length == 1) 
			return false;
		else 
			return (isPInteger.arguments[1] == true);
   else if(reInteger.test(s.value) == true)
		if(s.value > 0)
			return true;
		else
			return false;
	else
		return false;
}

/*function clientValidateDeductible(s, e)
{
	var ddlCoverageObj = document.getElementById("ddlCoverage");
	var ddlHSADeductibleObj = document.getElementById("ddlHSADeductible");
	
	if(ddlCoverageObj.selectedIndex == 1 && ddlHSADeductibleObj.selectedIndex > 4)
		e.IsValid = false;
	else
		e.IsValid = true;		
}*/