//home javascript
var intdays = 366;
var now = new Date();
now.setTime(now.getTime() + intdays * 24 * 60 * 60 * 1000);
var cookie_path = "/"; //"/" as root
var cookie_domain = document.domain; //"www.ameriprise.com"

function getCookie(name) {
    var re = new RegExp(name + "=([^;]+)");
    var value = re.exec(document.cookie);
    return (value != null) ? unescape(value[1]) : null;
}

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((path) ? "; path=" + path : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// simple popup
function doPopup(url) {
    var w = arguments[1] ? arguments[1] : 565;
    var h = arguments[2] ? arguments[2] : 525;
    // this *should* work, but it won't unless we explicitly check for 0
    var scr = arguments[3] == 0 ? arguments[3] : 1;
    var name = "popup";
    var args = "toolbar=0,scrollbars="+scr+",location=0,statusbar=0,menubar=0,resizable=0,width="+w+",height="+h+",left=10,top=10"
    if (typeof(popupWin) != "object"){
        popupWin = window.open(url,name,args);
    } else {
        if (!popupWin.closed){
            popupWin.location.href = url;
        } else {
        popupWin = window.open(url, name,args);
        }
    }
    popupWin.focus();
}

// IE incorrectly displays alt text on mouseover for images, kill it.
function suppressAltTxt(){ 
    var imgNodeList = document.body.getElementsByTagName("img");
    for (var i=0; i < imgNodeList.length; i++) {
        imgNodeList[i].setAttribute("alt", "");
    }
}

// sets table cells to have normalized width, regardless of how many columns.
function doCellNormalize() {
    var tableNodes = document.getElementsByTagName("table");
    if( tableNodes == "undefined" || tableNodes == null ){ return; }
    var thNodes = null;
    for (var i=0; i < tableNodes.length; i++) { 
	    var cellWidth = getPercentage( getNodeLength( tableNodes[i] ) );
        for (var j=0; j < thNodes.length; j++) {
            thNodes[j].style.width = cellWidth + "%";
        }
    }
    function getNodeLength(tblNode){
        var tableNode = tblNode;
        thNodes = tableNode.getElementsByTagName("th");
        return thNodes.length;
    }
    function getPercentage(lgth){
        return Math.floor(100 / lgth);
    }
}

// flash detection. if flash, display flash launcher image, else, nothing.
function checkFlash(){
    if( document.getElementById("right-flash-launcher") && detectFlash() ){
        document.getElementById("right-flash-launcher").style.display="block";
    }
}

// initialize when we have a DOM
function init(){
    if(browserFilter.Opera){ setNavWidth('listroot','img'); }
    doNavOnState();
    doNavEffects('listroot','li','ul');
    if(browserFilter.IE5up){ suppressAltTxt(); }
    doCellNormalize();
    checkFlash();
}
window.onload=init;

