var HsaCalenderYearLimitCollection = new Array();
function HsaCalenderYearLimit(_year, _MACS,_MACF, _CUC, _MADS, _MADF, _MOPS, _MOPF, _IsDefault)
{
    this.Year = _year;
    this.MACS = _MACS;
    this.MACF = _MACF;
    this.CUC = _CUC;
    this.MADS = _MADS;
    this.MADF = _MADF;
    this.MOPS = _MOPS;
    this.MOPF = _MOPF;
    this.IsDefault = _IsDefault;
}

function parseHsaCalenderYearLimitCollection()
{
	try //Internet Explorer
	{
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	}
	catch(e)
	{
		try //Firefox, Mozilla, Opera, etc.
		{
			xmlDoc=document.implementation.createDocument("","",null);
		}
		catch(e)
		{
			return;
		}
	}
	xmlDoc.async=false;
	xmlDoc.load("sa_hsa_year_limit.xml");
	
	var xmlLimits = xmlDoc.getElementsByTagName("limits")[0].getElementsByTagName("limit");
	for(var i=0;i<xmlLimits.length;i++)
	{
		var xmlLimit = xmlLimits[i];
		HsaCalenderYearLimitCollection.push(
			new HsaCalenderYearLimit(
				parseInt(xmlLimit.getElementsByTagName("year")[0].childNodes[0].nodeValue,10)
				,parseInt(xmlLimit.getElementsByTagName("MACS")[0].childNodes[0].nodeValue,10)
				,parseInt(xmlLimit.getElementsByTagName("MACF")[0].childNodes[0].nodeValue,10)
				,parseInt(xmlLimit.getElementsByTagName("CUC")[0].childNodes[0].nodeValue,10)
				,parseInt(xmlLimit.getElementsByTagName("MADS")[0].childNodes[0].nodeValue,10)
				,parseInt(xmlLimit.getElementsByTagName("MADF")[0].childNodes[0].nodeValue,10)
				,parseInt(xmlLimit.getElementsByTagName("MOPS")[0].childNodes[0].nodeValue,10)
				,parseInt(xmlLimit.getElementsByTagName("MOPF")[0].childNodes[0].nodeValue,10)
				,xmlLimit.getElementsByTagName("isDefault")[0].childNodes[0].nodeValue == "true"?true:false
			)
		);
	}
}

function GetHsaCalenderYearLimit(year)
{
    if (year < 2008)  
    {
        year = 2008;
    }
    for (var i=0;i< HsaCalenderYearLimitCollection.length;i++)
    {
        if(HsaCalenderYearLimitCollection[i].Year == year)
        {
            return HsaCalenderYearLimitCollection[i];
        }
    }
}

function FormatCurrency(money)
{
    var strMoney = "" + money;
    re = /(\d{1,3})(?=(\d{3})+(?:$|\.))/g;
    strMoney = strMoney.replace(re,"$1,");
    return "$" + strMoney;
}