//When adding new CSS classes that resize themselves, add a
//new element to the classPixelSizes associative array, using
//the following format:
//
//classPixelSizes["XXXX"] = YYYY;
//
//where XXXX = the new CSS class name
//      YYYY = the difference in font pixel size between the
//             new CSS class and the "bodytext" class

var classPixelSizes = new Array();
classPixelSizes["bodytext"] = 0;
classPixelSizes["subhead"] = 0;
classPixelSizes["headline"] = 1;
classPixelSizes["charts"] = -1;
classPixelSizes["bold11"] = -1;
classPixelSizes["chartsheaders"] = -1;
classPixelSizes["chartsrowone"] = -1;
classPixelSizes["faqsubhead"] = 0;
classPixelSizes["indexlink"] = 0;
classPixelSizes["bodysubhead"] = 4;

var bodyDOM;
var elements = new Array();
var indexCounter = 0;

function buildBodyDOMArray() {
    if (!document.getElementsByTagName) {
        return;
    }
    var bodyObjs = document.getElementsByTagName("body");
    bodyDOM = buildChildrenArray(bodyObjs[0]);
}

function buildChildrenArray(element) {
	//We only need to get elements with classes and form input fields.
	var elementNodeName = element.nodeName.toLowerCase();
	if (element.className || elementNodeName == "input" || elementNodeName == "select" || elementNodeName == "textarea") {
		elements[indexCounter++] = element;
	}
	
	var children = element.childNodes;
	if (children && children.length) {
		for (var i = 0; i < children.length; i++) {
			buildChildrenArray(children[i]);
		}
	}
	return elements;
}

function preloadImages(the_images_array) {
	for(var loop = 0; loop < the_images_array.length; loop++) {
   		var an_image = new Image();
		an_image.src = the_images_array[loop];
	}
}

function showLayer(layerName) {
	if ((layerName != "") || (layerName != null)) {
		eval(layerRef+'"'+layerName+'"'+styleSwitch+'.visibility="visible"');
    }
}

function hideLayer(layerName) {
    if ((layerName !="") || (layerName !=null)) {
		eval(layerRef+'"'+layerName+'"'+styleSwitch+'.visibility="hidden"');
	}
}

function sety(layerName,menutop) {
	if ((navigator.userAgent.indexOf("Mac") != -1)&&(navigator.userAgent.indexOf("MSIE") != -1)) {
		menutop=70;
	} //if
	else if ((navigator.userAgent.indexOf("Mac") != -1)&&(navigator.userAgent.indexOf("Mozilla") != -1)) {
      	menutop=70;
    } //else if
	else {
		menutop=70;
	}  //else
	if ((layerName !="") || (layerName !=null)) {
		eval(layerRef+'"'+layerName+'"'+styleSwitch+'.top='+menutop);
	}
}

function sety_tab(layerName,menutop_tab) {
	if ((navigator.userAgent.indexOf("Mac") != -1)&&(navigator.userAgent.indexOf("MSIE") != -1)) {
		menutop_tab=30;
	} //if
	else if ((navigator.userAgent.indexOf("Mac") != -1)&&(navigator.userAgent.indexOf("Mozilla") != -1)) {
		menutop_tab=30;
	} //else if
	else {
		menutop_tab=50;
	}  //else

	if ((layerName !="") || (layerName !=null)) {
		eval(layerRef+'"'+layerName+'"'+styleSwitch+'.top='+menutop_tab);
	}
}

function ndeSetTextSize(chgsize,rs) {
    if (!document.getElementsByTagName) {
        return;
    }

    var i;
    var startSize;
    var newSize;
    var currentSize = parseInt(ndeGetDocTextSize(bodyDOM));

    if (!currentSize) {
        currentSize = 12;
    }

    switch (chgsize) {
        case 'incr':
            newSize = currentSize + 1;
            break;

        case 'decr':
            newSize = currentSize - 1;
            break;

        case 'reset':        // Not currently used but might be someday.
            if (rs) {newSize = rs;} else {newSize = 12;}
            break;

        default:             // Read default size from cookie
            newSize = parseInt(ndeReadCookie("nde-textsize", true));
            if (!newSize) {
                newSize = currentSize;
            }
            break;
    }

    if (newSize < 10) {
        newSize = 10;
    }

    if (newSize > 13) {
        newSize = 13;
    }

    for (i = 0; i < bodyDOM.length; i++) {
        if (bodyDOM[i].className && typeof classPixelSizes[bodyDOM[i].className] != "undefined" && classPixelSizes[bodyDOM[i].className] != null) {
            bodyDOM[i].style.fontSize = classPixelSizes[bodyDOM[i].className] + newSize + "px";
        }
    }

    ndeCreateCookie("nde-textsize", newSize, 365, true);

    if (typeof adjustContainerDiv == "function") {
        adjustContainerDiv();
    }
	
	if (typeof adjustFundInfoContainerDiv == "function") {
		adjustFundInfoContainerDiv();
	}

}


function ndeGetDocTextSize(bodyDOM) {
    if (!document.getElementsByTagName) {
        return 0;
    }

    var i;
    var size = 0;
    var body = null;

    for (i = 0; i < bodyDOM.length; i++) {
        if (bodyDOM[i].className && bodyDOM[i].className == "bodytext") {
            body = bodyDOM[i];
            break;
        }
    }

	if (body != null) {
		if (body.style && body.style.fontSize) {
		    size = body.style.fontSize;
		} else if (typeof(getComputedStyle) != 'undefined') {
		    size = getComputedStyle(body,'').getPropertyValue('font-size');
		} else if (body.currentStyle) {
		    size = body.currentStyle.fontSize;
		}
	}
    return size;
}

function ndeCreateCookie(name,value,days,useLang) {

    var langString = useLang ? ndeGetLang() : "";

    var cookie = name + langString + "=" + value + ";";

    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        cookie += " expires=" + date.toGMTString() + ";";
    }
    cookie += " path=/";

    document.cookie = cookie;
}

function ndeReadCookie(name, useLang) {

    var langString = useLang ? ndeGetLang() : "";

    var nameEQ = name + langString + "=";
    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 ndeGetLang() {

    var langString = "";

    if (document.documentElement){
        langString = document.documentElement.lang;
        if (langString != ""){
          langString = "-" + langString;
        }
    }
    return langString;
}

function toggleLeftNav(id) {
	var subId = "sub" + id;
	var plusMinusId = id + "plusminus";
	var subObjRef;
	var plusMinusObjRef;
	var displayOnStr;
	if (document.getElementById) {
		subObjRef = document.getElementById(subId);
		plusMinusObjRef = document.getElementById(plusMinusId);
		displayOnStr = "block";
	} else if (document.all && document.all.item) {
		subObjRef = document.all.item(subId);
		plusMinusObjRef = document.all.item(plusMinusId);
		displayOnStr = "";
	} else {
		return;
	}
	if (!subObjRef || !plusMinusObjRef) { return; }
	if (!subObjRef.style || !plusMinusObjRef.src) { return; }
	if (subObjRef.style.display == "none") {
		subObjRef.style.display = displayOnStr;
		plusMinusObjRef.src = "/images/main/icons/minus.gif"; // NEED TO HARDCODE IMAGE PATH HERE BECAUSE JS DOESNT HAVE ACCESS TO PATH TO IMAGES VARIABLE.
	} else {
		subObjRef.style.display = "none";
		plusMinusObjRef.src = "/images/main/icons/plus.gif"; // NEED TO HARDCODE IMAGE PATH HERE BECAUSE JS DOESNT HAVE ACCESS TO PATH TO IMAGES VARIABLE.
	}
}

function adjustFormElements() {
    if (!document.getElementsByTagName) {
        return;
    }
    for (i = 0; i < bodyDOM.length; i++) {
		if (!bodyDOM[i].nodeName || !bodyDOM[i].style) {
			continue;
		}
		
		var bodyDOMNodeName = bodyDOM[i].nodeName.toLowerCase();
		var bodyDOMType = null;
		
		if (bodyDOM[i].type) {
			bodyDOMType = bodyDOM[i].type.toLowerCase();
		}
		
        if (bodyDOMNodeName == "input" && (bodyDOMType == "text" || bodyDOMType == "password")) {
		
            if (bodyDOM[i].className && bodyDOM[i].className == "search") {
                bodyDOM[i].style.fontSize = "10px";
                bodyDOM[i].style.fontFamily = "Verdana, Arial, Helvetica, Geneva, sans-serif";
                bodyDOM[i].style.display = "inline";
                bodyDOM[i].style.padding = "1px";
                bodyDOM[i].style.border = "1px solid #999966";
                bodyDOM[i].style.height = "15px"; // WAS 14px
                bodyDOM[i].style.width = "93px"; // WAS 77px
            } else if (bodyDOM[i].className && bodyDOM[i].className == "rightnavlogin") {
                bodyDOM[i].style.fontSize = "8pt";
                bodyDOM[i].style.fontFamily = "Verdana, Arial, Helvetica, sans-serif";
                bodyDOM[i].style.display = "inline";
                bodyDOM[i].style.padding = "1px";
                bodyDOM[i].style.border = "1px solid #999966";
            } else if (bodyDOM[i].className && bodyDOM[i].className == "noborderinput") {
                bodyDOM[i].style.fontSize = "8pt";
                bodyDOM[i].style.fontFamily = "Verdana, Arial, Helvetica, sans-serif";
                bodyDOM[i].style.display = "inline";
                bodyDOM[i].style.padding = "1px";
                bodyDOM[i].style.borderStyle = "none";
            } else {
                bodyDOM[i].style.fontSize = "8pt";
                bodyDOM[i].style.fontFamily = "Verdana, Arial, Helvetica, sans-serif";
                bodyDOM[i].style.display = "inline";
                bodyDOM[i].style.padding = "1px";
                bodyDOM[i].style.border = "1px solid #333333";
            }
			
        } else if (bodyDOMNodeName == "select") {
		
            bodyDOM[i].style.fontSize = "8pt";
            bodyDOM[i].style.fontFamily = "Verdana, Arial, Helvetica, sans-serif";
			
        } else if (bodyDOMNodeName == "textarea") {
		
            bodyDOM[i].style.fontSize = "8pt";
            bodyDOM[i].style.fontFamily = "Verdana, Arial, Helvetica, sans-serif";
            bodyDOM[i].style.display = "inline";
            bodyDOM[i].style.padding = "1px";
            bodyDOM[i].style.border = "1px solid #333333";
            bodyDOM[i].style.width = "100%";
            bodyDOM[i].style.overflow = "auto";
			
        }
	}
}

function strongOption(option, value) {
    if (opener != null) {
        var win = opener;
    }
    else {
        var win = top;
    }
    win.gotoOptions(option, value);
}
