function roundnumber(n, d)
{
    n = n - 0;
    if (d == null) d = 2;
    var f = Math.pow(10, d);
    n += Math.pow(10, - (d + 1));
    n = Math.round(n * f) / f;
    n += Math.pow(10, - (d + 1));
    n += '';
    return d == 0 ? n.substring(0, n.indexOf('.')) :  n.substring(0, n.indexOf('.') + d + 1);
}

function popUp(URL)
{
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=660,left = 0,top = 0');");
}

function popWin(URL, width, height)
{
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + width + ",height=" + height + ",left = 0,top = 0');");
}

function setCellColor(theCell, thePointerColor)
{
    if (thePointerColor == '' || typeof(theCell.style) == 'undefined') {
	   return false;
	}
    theCell.style.backgroundColor = thePointerColor;
    return true;
}

function collapseBox(boxid)
{
	if(document.getElementById(boxid).style.display=='block') document.getElementById(boxid).style.display='none';
	else document.getElementById(boxid).style.display='block';
}

function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

sfHover = function()
{
    /***
    alert('!!!');
    var sfEls = document.getElementById("nav").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover = function() {
            if (first_level_menu != '' && sub_menu_active != '') {
                var tag = document.getElementById(first_level_menu);
                tag.className = tag.className.replace(new RegExp(" sfhover\\b"), "");
                alert(tag.className);
            }
            this.className+=" sfhover";
        }
        sfEls[i].onmouseout = function() {
            this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }
    ***/
}

function show_top_sub_menu(id)
{
    if (first_level_menu != '' && id != first_level_menu) {
        hide_top_sub_menu(first_level_menu, id);
        current_active_menu = id;
    }
    var cmenu = top_menu_sides[ id ];
    var sub_id = 'sub_' + id;
    var table_tag = document.getElementById('top_menu_table');
    if (cmenu[0] > 0) {
        var tag = document.getElementById(id);
        var submenu = document.getElementById(sub_id);
        var left_tag = document.getElementById(cmenu[1]);
        var right_tag = document.getElementById(cmenu[2]);
        tag.className = id + ' child_active';
        left_tag.className = cmenu[1];
        right_tag.className = cmenu[2];
        left_tag.src = '/images/' + cmenu[3] + '.gif';
        right_tag.src = '/images/' + cmenu[4] + '.gif';
        if (navigator.appVersion.toLowerCase().indexOf("msie") != -1) {
            submenu.className = 'submenu_show_ie';
        } else {
            submenu.className = 'submenu_show';
        }
        tag.style.zIndex = 100;
        submenu.style.zIndex = 1;
    }
}

function hide_top_sub_menu(id, current)
{
     current_active_menu = current;
    var cmenu = top_menu_sides[ id ];
    var sub_id = 'sub_' + id;
    if (cmenu[0] > 0) {
        var tag = document.getElementById(id);
        var submenu = document.getElementById(sub_id);
        var left_tag = document.getElementById(cmenu[1]);
        var right_tag = document.getElementById(cmenu[2]);
        tag.className = 'child';
        left_tag.className = 'empty';
        right_tag.className = 'empty';
        left_tag.src = '/images/clear.gif';
        right_tag.src = '/images/clear.gif';
        submenu.className = 'submenu_hidden';
    }
    if (current_active_menu == id) {
        current_active_menu = '';
    }
    if (first_level_menu != '' && current_active_menu == '') {
        show_top_sub_menu(first_level_menu);
    }
    if (first_level_menu != '' && first_level_menu != id) {
        // show_top_sub_menu(first_level_menu);
    }

}

function init_top_menu()
{
    if (first_level_menu != '') {
        show_top_sub_menu(first_level_menu);
    }
}

function LaunchCalc(Name)
{
    myCalc = "http://gateway.fundsxpress.com/calculators/" + Name +".html";
    window.open(myCalc,'myCalculator','width=600,height=450,resizable=yes,scrollbars=yes');
}
function openHomeWindow()
{
	newHomeWindow=window.open("http://www.c2commerce.com/c2calculators/bow/homeafford.asp","Home","status=yes,width=540,height=450,scrollbars=yes,menubar=yes");
	if (navigator.appVersion.toLowerCase().indexOf("msie") != -1 && parseInt(navigator.appVersion) <= 4 && navigator.appVersion.toLowerCase().indexOf("msie 5.0") == -1)
	{
		//Older versions of IE can't handle the focus
	}
	else newHomeWindow.focus();
}
function openCollegeWindow()
{
	newCollegeWindow=window.open("http://www.c2commerce.com/c2calculators/bow/college.asp","College","status=yes,width=540,height=450,scrollbars=yes,menubar=yes");
	if (navigator.appVersion.toLowerCase().indexOf("msie") != -1 && parseInt(navigator.appVersion) <= 4 && navigator.appVersion.toLowerCase().indexOf("msie 5.0") == -1)
	{
		//Older versions of IE can't handle the focus
	}
	else newCollegeWindow.focus();
}
function openRentWindow()
{
	newRentWindow=window.open("http://www.c2commerce.com/c2calculators/bow/rentvsbuy.asp","Rent","status=yes,width=540,height=450,scrollbars=yes,menubar=yes");
	if (navigator.appVersion.toLowerCase().indexOf("msie") != -1 && parseInt(navigator.appVersion) <= 4 && navigator.appVersion.toLowerCase().indexOf("msie 5.0") == -1)
	{
		//Older versions of IE can't handle the focus
	}
	else newRentWindow.focus();
}
function openRetireWindow()
{
	newRetireWindow=window.open("http://www.c2commerce.com/c2calculators/bow/retire.asp","Retire","status=yes,width=540,height=450,scrollbars=yes,menubar=yes");
	if (navigator.appVersion.toLowerCase().indexOf("msie") != -1 && parseInt(navigator.appVersion) <= 4 && navigator.appVersion.toLowerCase().indexOf("msie 5.0") == -1)
	{
		//Older versions of IE can't handle the focus
	}
	else newRetireWindow.focus();
}