

browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
var b, b2, br;
if (browserName == "Netscape" && browserVer ==3) {
	version = "yes";
	br = "no";
	if(navigator.userAgent.indexOf("Firefox",0) >= 0) {
		b = "ns";
		b2 = "ff";
	}
}
else if (browserName == "Netscape" && browserVer >=4) {
	version = "yes";
	br = "NS4";
	b = "ns";
	if(navigator.userAgent.indexOf("Firefox",0) >= 0) {
		b2 = "ff";
	}
}
else if (browserName == "Microsoft Internet Explorer" && browserVer >=4){
	version = "yes"
	br = "IE4";
	b = "ie";
}
else {
	version ="no";
	br = "no";
}

function OpenEditor(obj) {
	sContent = obj.value;
	document.htmleditor.Content.value = sContent;
	document.htmleditor.FormField.value = obj.name;
	DisplayWindow = window.open('','DisplayWindow','toolbar=no,scrollbars=yes,width=800,height=550,resizable=yes');
	document.htmleditor.target = "DisplayWindow";
	document.htmleditor.submit();
}

function CheckNumber(e) {
	var key;
	var keychar;
	var reg;
	
	if(window.event) {
		key = window.event.keyCode; 
	}
	else if(e.which) {
		key = e.which; 
	}
	else {
		return true;
	}
	iCode = String.fromCharCode(key);
	if (isNaN(iCode) && iCode != "." && iCode != "-" && key != 8) {
		return false;
	}
	else {
		return true;
	}
}

function CheckPhoneNumber(e) {
	var key;
	var keychar;
	var reg;
	
	if(window.event) {
		key = window.event.keyCode; 
	}
	else if(e.which) {
		key = e.which; 
	}
	else {
		return true;
	}
	iCode = String.fromCharCode(key);
	if (isNaN(iCode) && iCode != "+" && iCode !=" " && key != 8) {
		return false;
	}
	else {
		return true;
	}
}

function isEmail(str) {
	// are regular expressions supported?
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,4})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}
function stripSpaces(obj) {
	var str = obj;
	var newstr = "";
	
    for (var i = 0; i < str.length; i++) {
		if (str.charAt(i) == " ") {}
		else {
	   		newstr = newstr + str.charAt(i);
		}
    }
	return newstr;
}

function ClearFrm(obj, txt) {
	if (obj.value == txt)
		obj.value = "";
}

function strip(strIn, sType) {
	var newstr = "";
	if (sType == "sp") {
		var Chars = " ";
	}
	else {
		var Chars = "0123456789";
	}
	
    for (var i = 0; i < strIn.length; i++) {
		if (sType == "int") {
	    	if (Chars.indexOf(strIn.charAt(i)) == -1) {}
			else {
		   		newstr = newstr + strIn.charAt(i);
			}
		}
		else {
			if (Chars.indexOf(strIn.charAt(i)) == -1) {
		   		newstr = newstr + strIn.charAt(i);
			}
		}
    }
	return newstr;
}

function SubRollOverRow(oTr, c) {
	if (b == "ie") {
		if (!oTr.contains(window.event.fromElement)) {oTr.bgColor=c;}
	}
	else {
		if (!oTr.style) {
          oTr.style={};
        }
		oTr.style["backgroundColor"]=c;
	}
}

function SubRollOutRow(oTr, c) {
	if (b == "ie") {
		if (!oTr.contains(window.event.toElement)) {oTr.bgColor=c;}
	}
	else {
		if (!oTr.style) {
          oTr.style={};
        }
		oTr.style["backgroundColor"]=c;
	}
}

function highlightRow(el, trid) {
	tr = new getObj(trid);
	if (el.checked) {
		iSel = CheckCompare();
		if (iSel > 3) {
			alert("Please only choose up to three funds to compare.");
			el.checked = false;
		}
		else {
			if (!(tr.obj.className.indexOf('odd') == -1) ) {
				tr.obj.className = tr.obj.className.replace('odd', 'checkedrow');
			}
			else if (!(tr.obj.className.indexOf('even') == -1) ) {
				tr.obj.className = tr.obj.className.replace('even', 'checkedrow');
			}
			else {
				tr.obj.className += ' checkedrow';
			}
		}
	}
	else {
		tr.obj.className = "";
	}
}

function CheckCompare() {
	formblock= document.getElementById('comparefrm');  
	forminputs = formblock.getElementsByTagName('input');
	iSel = 0;
	for (i = 0; i < forminputs.length; i++) {    // regex here to check name attribute - stupid PHP arrays...   
		var regex = new RegExp("FundID", "i");    
		if (regex.test(forminputs[i].getAttribute('name'))) {   
			if (forminputs[i].checked) iSel++;
		}  
	}
	return iSel;
	
}

function DoCompare() {
	iSel = CheckCompare();
	if (iSel == 0) {
		alert("Please choose up to three funds to compare.");
	}
	else if (iSel > 3) {
		alert("Please only choose up to three funds to compare.");
	}
	else {
		document.comparefrm.submit();
	}
}

function PopWindow(strPage) {
	NewWindow = window.open(strPage,'DisplayWindow','toolbar=no,scrollbars=yes,width=500,height=550,resizable=yes');
	if (window.focus) {NewWindow.focus()}
	return false;
}

function WindowOpen(strPage) {
	NewWindowObj = window.open(strPage,'DisplayWindow','toolbar=no,scrollbars=yes,width=500,height=550,resizable=yes');
	NewWindowObj.focus();
}

function NewWindow(strPage, iW, iH, sName) {
	NewWindowObj = window.open(strPage,sName,'toolbar=no,scrollbars=yes,width=' + iW + ',height=' + iH + ',resizable=yes');
	NewWindowObj.focus();
}

function GetAddr(sAddr, sDom) {
	document.location.href = "mailto: " + sAddr + "@" + sDom;
}

function Jumpform(isWindow) {
	iSel = document.JumpForm.URL.selectedIndex;
	sURL = document.JumpForm.URL[iSel].value;
	if (sURL != '') {
		if (isWindow) {
			WindowOpen(sURL);
		}
		else {
			document.location.href = sURL;
		}
	}
	return false;
}



var DHTML = (document.getElementById || document.all || document.layers);

function getObj(name) {
	if (document.getElementById) {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if (document.layers) {
	 	this.obj = document.layers[name];
	 	this.style = document.layers[name];
	}
}

function getIndexedObj(rawObjName, indexedName) {
	//This is here to handle getting the right related object.  For example, footer__1 under table__1
	var indexedObjName = getIndexedName(rawObjName, indexedName);
	//see if we can use getObj(indexedObjName) here somehow...
	if (document.getElementById) {
		this.obj = document.getElementById(indexedObjName);
		this.style = document.getElementById(indexedObjName).style;
	}
	else if (document.all) {
		this.obj = document.all[indexedObjName];
		this.style = document.all[indexedObjName].style;
	}
	else if (document.layers) {
	 	this.obj = document.layers[indexedObjName];
	 	this.style = document.layers[indexedObjName];
	}
}

function getIndexedName(rawObjName, indexedName){
	var iSepPos = indexedName.indexOf("__");
	var indexedObjName;
	if(iSepPos > -1){
		var iReportID = indexedName.substr(iSepPos + 2);
		return rawObjName + "__" + iReportID;
	} else {
		return rawObjName;
	}
}
	
function changeCol(col, obj) {
	if (!DHTML) return;
	var x = new getObj(obj);
	x.style.color = col;
}

function toggleDiv(obj) {
	if (!DHTML) return;
	var x = new getObj(obj);
	//alert(x.style.display);
	x.style.display = (x.style.display == "none")? "block":"none";
}
		
function MoveField(strDir, obj) {
	selectLength = obj.length;
	menuNum = obj.selectedIndex;
	if (version=="no") {
		return;
	}
	else {
		k = 1;
		first = 0;
	}
	if (strDir == 'Up') {
		if (menuNum == first) {
			return;
		}
		else {
			fieldText = obj.options[menuNum-1].text;
			fieldValue = obj.options[menuNum-1].value;
		}
	}
	else {
		if (menuNum == selectLength-k) {
			return;
		}
		else {
			fieldText = obj.options[menuNum].text;
			fieldValue = obj.options[menuNum].value;
		}
	}
	for (i = first; i <= selectLength-k; i++) {
		if (strDir == 'Up') {
			if (i == menuNum-1) {
				obj.options[i].text = obj.options[i+1].text;
				obj.options[i].value = obj.options[i+1].value;
			}
			else if (i == menuNum) {
				obj.options[i].text = fieldText;
				obj.options[i].value = fieldValue;
			}
			else {
				obj.options[i].text = obj.options[i].text;
				obj.options[i].value = obj.options[i].value;
			}
		}
		else {
			if (i == menuNum) {
				obj.options[i].text = obj.options[i+1].text;
				obj.options[i].value = obj.options[i+1].value;
			}
			else if (i == menuNum+1) {
				obj.options[i].text = fieldText;
				obj.options[i].value = fieldValue;
			}
			else {
				obj.options[i].text = obj.options[i].text;
				obj.options[i].value = obj.options[i].value;
			}
		}
		obj.options[i].selected = false;
	}
	if (strDir == 'Up') {
		obj.options[menuNum - 1].selected = true;
	}
	else {
		obj.options[menuNum + 1].selected = true;
	}
}

function AllocateField(objFrom, objTo) {
	selectLength = objTo.length;
	availLength = objFrom.length;
	if (version=="no") {
		return;
	}
	else {
		k= 1;
		first = 0
	}
	a = first;
	
	menuNum = objFrom.selectedIndex;
	if (menuNum == -1) {
		return;
	}
	fieldText = objFrom.options[menuNum].text;
	fieldValue = objFrom.options[menuNum].value;
	
	for (i = first; i <= availLength-k; i++) {
		if (i != menuNum) {
			objFrom.options[a].text = objFrom.options[i].text;
			objFrom.options[a].value = objFrom.options[i].value;
			a = a + 1;
		}
	}
	objFrom.options[a] = null;
	if (menuNum == a && a != 0) {
		objFrom.options[a-1].selected = true;
	}
	for (i = first; i <= selectLength-k; i++) {
		objTo.options[i].text = objTo.options[i].text;
		objTo.options[i].value = objTo.options[i].value;
		objTo.options[i].selected = false;
	}
	objTo.options[i] = new Option("");
	objTo.options[i].text = fieldText;
	objTo.options[i].value = fieldValue;
	objTo.options[i].selected = true;
}
	
function MoveAll(objFrom, objTo) {
	selectLength = objTo.length;
	availLength = objFrom.length;
	if (version=="no") {
		return;
	}
	else {
		k= 1;
		first = 0
	}
	
	for (i = first; i <= availLength-k; i++) {
		objTo.options[selectLength+i] = new Option("");
		objTo.options[selectLength+i].text = objFrom.options[i].text;
		objTo.options[selectLength+i].value = objFrom.options[i].value;
		
		
	}
	for (i = availLength-k; i >= 0 ; i--) {
		objFrom.options[i] = null;
	}
}

function disableEnterKey(e){
	var key;
	if(window.event)
		key = window.event.keyCode;     //IE
	else
		key = e.which;     //firefox
	if(key == 13)
		return false;
	else
		return true;
}
function CheckSearchForm() {
	obj = document.searchfrm;
	if (obj.Search.value == '') {
		alert("Please enter a term to search for.");
		return false;
	}
	return true;
}
	
function cbFieldDisable(cbID) {
	var cbEl = document.getElementById(cbID);
	for ( var i=1; i < arguments.length; i++ ) {
		if (typeof arguments[i] == 'string') {
			var target = document.getElementById(arguments[i]);
			target.disabled = !cbEl.checked;
		}
	}
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function number_format(n, decimals, sep) {
		sep = sep || "."; // Default to period as decimal separator
		if (decimals==undefined) decimals = 2; // Default to 2 decimals
		var res = n.toLocaleString().split(sep)[0];
		if (decimals > 0) {
			n += sep + n.toFixed(decimals).split(sep)[1];
		}
		return res;
}

