function pop(url) {window.open(url,'','scrollbars=yes,resizable=yes,width=700,height=500');};
function popsize(url,w,h) {window.open(url,'','scrollbars=yes,resizable=yes,width='+w+',height='+h);};
function viewprofile(fundurl){window.open(fundurl,'fundprofile','scrollbars=yes,resizable=yes,width=700,height=400');};
function passData(url, data) {windowHandle = window.open(url + '?' + data,'windowName','resizable=yes,scrollbars=yes,width=700,height=500');};

// AccAcc/EZLink window closer
function targetopener(mylink){
	if (window.opener.location.href) {
	   window.opener.location.href=mylink;
	   window.close();
	   return false;}
   return false; 
};

// AccAcc/EZLink contact form
function contact(usertype) {
	if (usertype == "sponsor") {
		window.open('https://harper1.icmarc.org/contactHelp.jsp?altId=70000','contact','scrollbars=yes,resizable=yes,width=600,height=400')
	}
	else {
		window.open('https://harper1.icmarc.org/contactHelp.jsp?altId=60000','contact','scrollbars=yes,resizable=yes,width=600,height=400')
	};
};

//sub menu hover effect for IE
sfHover = function() {
	var ispopup = document.getElementById("popup");
	if(! ispopup) {
		if (document.getElementById("sitemenu")) {
		var sfEls = document.getElementById("sitemenu").getElementsByTagName("li");
		for (var i=0; i<sfEls.length; i++) 
			{
			sfEls[i].onmouseover=function() {this.className+=" menuhover";}
			sfEls[i].onmouseout=function() { this.className="";}
			};
		}
	}
};
window.onload = sfHover;
/* cookies */
function populateSideBoxes() {
var pension = readCookie('Pension');
var retincome = readCookie('RetirementIncome');
var socialsec = readCookie('SocialSecurity');
var ratereturn = readCookie('RateReturn');
var onetime = readCookie('OneTimeExpense');	
var lifelength = readCookie('Longevity');
	
	if (ratereturn != null)
	{document.getElementById("advcontributionrate").innerHTML=ratereturn;}	
	if (socialsec != null)
	{document.getElementById("advsocialsecurity").innerHTML=socialsec;}		
	if (retincome != null)
	{document.getElementById("advretirementincome").innerHTML=retincome;}
	if (lifelength != null)
	{document.getElementById("advlongevity").innerHTML=lifelength;}
	if (onetime != null)
	{document.getElementById("advonetimeexpense").innerHTML=onetime;}
	if (pension != null)
	{document.getElementById("advpension").innerHTML=pension;}
};
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
};

function replaceSpace(entry) {
out = " "; // replace this
add = ""; // with this
temp = "" + entry; // temporary holder
};

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
};

function createLongevityCookie(longevityvalue)
{
	if(longevityvalue != null)
	{createCookie('Longevity', longevityvalue);}
	//set report card
	if (location.search.length > 0) 
	{window.opener.location.href=location.search.substring(1);}
	//document.getElementById("estimatepensioncheckbox").checked=true;
};

function createOneTimeExpenseCookie(onetimevalue)
{
	if(onetimevalue != null)
	{
		createCookie('OneTimeExpense', onetimevalue);
	}
	//set report card
	//document.getElementById("advonetimeexpense").innerHTML=onetimevalue;
	//document.getElementById("estimatepensioncheckbox").checked=true;
	if (location.search.length > 0) 
	{window.opener.location.href=location.search.substring(1);}
};

function createPensionCookie()
{
	var pensionvalue=document.getElementById("pensionBox").value;
	if(pensionvalue != null)
	{createCookie('Pension', pensionvalue);}
	//set report card
	document.getElementById("advpension").innerHTML=pensionvalue;
	//document.getElementById("estimatepensioncheckbox").checked=true;
};

function createRetirementIncomeCookie()
{
	var retirementincomevalue=document.getElementById("retirementIncomeBox").value;
	if(retirementincomevalue != null)
	{
		createCookie('RetirementIncome', retirementincomevalue);
	}
	//set report card
	document.getElementById("advretirementincome").innerHTML=retirementincomevalue;
	//document.getElementById("retirementexpensescheckbox").checked=true;
	if (location.search.length > 0) 
	{window.opener.location.href=location.search.substring(1);}
};

function createSocialSecurityCookie()
{
	var socialsecurityvalue=document.getElementById("socialSecurityBox").value;
	if(socialsecurityvalue != null)
	{
		createCookie('SocialSecurity', socialsecurityvalue);
	}
	//set report card
	document.getElementById("advsocialsecurity").innerHTML=socialsecurityvalue;
	//document.getElementById("estimatesscheckbox").checked=true;
};
function createRateReturnCookie()
{
	var ratereturnvalue=document.getElementById("rateReturnBox").value;
	if(ratereturnvalue != null)
	{
		temp = ratereturnvalue.split('%');
		createCookie('RateReturn', temp[0]);
	}
	//set report card
	document.getElementById("advcontributionrate").innerHTML=temp[0];
	//document.getElementById("estimatereturncheckbox").checked=true;
};

function formatCurrency(num)
 {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num);
};

function unformatCurrency( strValue ) {
  //var objRegExp = /,/g; //search for commas globally
  //replace all matches with empty strings
  var newstrvalue = String(strValue);
  x = newstrvalue.split(",");
  var nocommas="";
  for(var i = 0; i < x.length; i++)
  {
  	nocommas = nocommas+x[i];
  };
  var temp = new Array();
	temp = nocommas.split('.');
	tempnumber = Number(temp[0]);
  return tempnumber;
};

function checkForCookies()
{
/*	var totalsavings = readCookie('SimpleTotalSavings');
	var annualsavings= readCookie('SimpleAnnualSavings');
	var contributionrate= readCookie('SimpleContributionRate');
*/	var lifelength = readCookie('Longevity');
	var onetime= readCookie('OneTimeExpense');	
	var monthlyretincome = readCookie('MonthlyRetirementIncome');
	var pension= readCookie('Pension');	
	var socialsecurity = readCookie('SocialSecurity');
	var advtotalsavings= readCookie('AdvancedTotalSavings');	
	var advannualsavings = readCookie('AdvancedAnnualSavings');
	var advcontributionrate= readCookie('AdvancedContributionRate');	
	
/*    if (totalsavings != null)
	{
		document.getElementById("rcsavingsneeded").innerHTML=totalsavings;
	}
	if (annualsavings != null)
	{
		document.getElementById("rcannualsavings").innerHTML=annualsavings;
	}
	if (contributionrate != null)
	{
		document.getElementById("rccontributionrate").innerHTML=contributionrate;
	}
*/	if (lifelength != null)
	{document.getElementById("advlongevity").innerHTML=lifelength;}
	if (onetime != null)
	{document.getElementById("advonetimeexpense").innerHTML=onetime;}
	if (monthlyretincome != null)
	{document.getElementById("advretirementincome").innerHTML=monthlyretincome;}
	if (pension != null)
	{document.getElementById("advpension").innerHTML=pension;}
	if (socialsecurity != null)
	{document.getElementById("advsocialsecurity").innerHTML=socialsecurity;}
	if (advtotalsavings != null)
	{document.getElementById("advsavingsneeded").value=advtotalsavings;}
	if (advannualsavings != null)
	{document.getElementById("advannualsavings").value=advannualsavings;}
	if (advcontributionrate != null)
	{document.getElementById("advcontributionrate").value=advcontributionrate;}
};
