if (window.focus) { self.focus() }

function ChangeTimeframes(sChartName) {
	if (bYieldCurveIsSelected()) {
		//Yield Curve is active
		for (i=0; i < document.images.length; i++) {
			//remove Active chart marker
			if (document.images[i].src.toLowerCase()=="http://www.thefinancials.com/images/activechart.gif") {
				document.images[i].src = "http://www.theFinancials.com/images/blank.gif";
				break
			}
		}

		var sChartFileName=document.forms['TFC_MFR_Form'].optTimeframe[nCheckedControlIDX].value.split(/-/);
		var sChartFileName=sChartFileName[0] + 'p.jpg'
		document.images[sChartName].src='http://www.theFinancials.com/Samples/' + sChartFileName
	} else {
		document.images[sChartName].src='http://www.theFinancials.com/Samples/' + asChart1Props[nTimeFrameIndex] + 'p.jpg'
		//if yield curve is available, add back Active chart marker
		if (typeof(sLastLocation)!='undefined') {
			movePageMarker(sLastLocation.split(/_/)[0],sLastLocation)
		}
	}
}

function LoadThumbnail(sChartName_w, sChartName_m, sChartName_y, sChartName_3y, sNewLocation) {
	for (i=0; i < document.forms['TFC_MFR_Form'].optTimeframe.length; i++) {
		if (document.forms[document.forms.length-1].optTimeframe[i].checked) {
			var sTimeframe=document.forms['TFC_MFR_Form'].optTimeframe[i].value.split(/-/);
			var sTimeframe=sTimeframe[0]
			break;
		}
	}
	switch (sTimeframe.toUpperCase()){
		case "W" : 
			sChartName=sChartName_w;
			break;		
		case "Y" : 
			sChartName=sChartName_y;
			break;		
		case "Y3" : 
			sChartName=sChartName_3y;
			break;		
		case "M" : 
			sChartName=sChartName_m;
			break;		
		default : 
			sChartName=sChartName_m;
			for (i=0; i < document.forms['TFC_MFR_Form'].optTimeframe.length; i++) {
				nTimeFrameName=document.forms['TFC_MFR_Form'].optTimeframe[i].value.split(/-/);
				nTimeFrameName=nTimeFrameName[0];
				if (nTimeFrameName=="M") {
					document.forms['TFC_MFR_Form'].optTimeframe[i].checked=true
					break;
				}
			}
			break;		
	}

	sChart1Props=sChartName_w+"_"+sChartName_m+"_"+sChartName_y+"_"+sChartName_3y;
	sChartContainerName=sNewLocation.split(/_/);
	document.images[sChartContainerName[0]].src='http://www.theFinancials.com/Samples/' + sChartName + 'p.jpg'
	for (i=0; i < document.forms['TFC_MFR_Form'].optTimeframe.length; i++) {
		if (document.forms['TFC_MFR_Form'].optTimeframe[i].checked) {
			nTimeFrameIndex=document.forms['TFC_MFR_Form'].optTimeframe[i].value.split(/-/);
			nTimeFrameIndex=nTimeFrameIndex[1];
			break;
		}
	}

	if (sNewLocation) {
		movePageMarker(sChartContainerName[0],sNewLocation) 
	}
}

function ZoomThumbnail(sDir, sThumbChartName, sTarget) {
		if (!sDir) {
			sDir="vortex";
		}
		if (typeof(sTarget)=='undefined') {
			sTarget="_top";
		} else {
			if (!sTarget) {
				sTarget="_top";
			}
		}
		var nCurChartID= new String(document.images[sThumbChartName].src);
		var nCurChartIDList=nCurChartID.split('/');
		var nCurChartID=nCurChartIDList[nCurChartIDList.length-1];
		var nCurChartID=nCurChartID.substring(0,7) + 'v.PDF';
		if (sTarget.toUpperCase()=="_BLANK") {
			window.open("http://www.theFinancials.com/Samples/" + nCurChartID);
		} else {
			top.document.location="http://www.theFinancials.com/Samples/" + nCurChartID;
		}
}

function movePageMarker(sChartContainerName,sNewLocation) {
	sLastLocation=sNewLocation;
	sNameToMatch=String(sChartContainerName+"_ChartInd_");
	for (i=0; i < document.images.length; i++) {
		sImageName=String(document.images[i].name);
		if (sImageName.substr(0,sNameToMatch.length)==sNameToMatch) {
			if (sImageName == sNewLocation) {
				document.images[sNewLocation].src="http://www.theFinancials.com/images/ActiveChart.gif";			
			} else {
				document.images[i].src = "http://www.theFinancials.com/images/blank.gif";
			}
		}
	}
	return null;
}

function GetCSVData(bNewWindow) {
	if (typeof(bNewWindow)=='undefined') {
		bNewWindow=true;
	}

	if (bYieldCurveIsSelected()) {
		//Yield Curve is active		
		var sDataFileName=document.forms['TFC_MFR_Form'].optTimeframe[nCheckedControlIDX].value.split(/-/);
		var sDataFileName=sDataFileName[0] + '.csv';
	} else {
		var sDataFileName=asChart1Props[3] + '.csv';
	}

	if (bNewWindow) {
		window.open("http://www.theFinancials.com/data/" + sDataFileName);
	} else {
		top.document.location="http://www.theFinancials.com/data/" + sDataFileName;
	}
}

function bYieldCurveIsSelected() {
	for (i=0; i < document.forms['TFC_MFR_Form'].optTimeframe.length; i++) {
		if (document.forms['TFC_MFR_Form'].optTimeframe[i].checked) {
			nTimeFrameIndex=document.forms['TFC_MFR_Form'].optTimeframe[i].value.split(/-/);
			nTimeFrameIndex=nTimeFrameIndex[1];
			nCheckedControlIDX=i;
			break;
		}
	}

	if (typeof(sChart1Props)=='undefined') {
		asChart1Props=initChart1Props.split(/_/);
	} else {
		asChart1Props=sChart1Props.split(/_/);
	}

	if (typeof(asChart1Props[nTimeFrameIndex])=='undefined') {
		return true;
	} else {
		return false;
	}

}

function drpGoToPage(drpDown) {
	var sTarget=drpDown.options[drpDown.selectedIndex].value; 
	if (sTarget=='') {
		drpDown.selectedIndex=0;
	} else {
		document.location=sTarget;
 	} 
	return true;
} 
