function fetchFactSheets(filterType)
{
	document.frmMain.action = 'PKRFactsheetSelection.asp';
	document.frmMain.pageNo.value = '1';
	document.frmMain.rank.value = '';
	document.frmMain.factSheetType.value = filterType;
	document.frmMain.submit();
}

function SelectedRowToggled(MyFundId)
{

	var selectedFund	= '<fund id=\'' + MyFundId + '\'/>';
	var myFunds = document.frmMain.myFundXml.value;
	
	//if already selected then remove
	if(myFunds.indexOf(selectedFund) != -1)
		removeFund(selectedFund);
	else
	{
		if(myFunds == '' || myFunds == null)
			myFunds = '<myfunds></myfunds>';
			
		//not already present so add fund
		addFund(selectedFund);

	}
}
function addFund(selectedFund)
{
		
	//remove the myfunds close element to add new fund then add it again
	var MyFundIdXml = removeMyFundsCloseElement(document.frmMain.myFundXml.value);
	
	
	document.frmMain.myFundXml.value = MyFundIdXml + selectedFund + '</myfunds>';

}


function removeFund(selectedFund)
{
	var myFunds = document.frmMain.myFundXml.value;
	
	var startIndex	= myFunds.indexOf(selectedFund)
	var lenFund		= selectedFund.length;
	
	var substrBeforeFund	= myFunds.substr(0,startIndex);
	var substrAfterFund		= myFunds.substr(startIndex + lenFund);

	document.frmMain.myFundXml.value  = substrBeforeFund + substrAfterFund;
}

function removeMyFundsCloseElement(myFunds)
{
	var funds = '';
	if(myFunds.indexOf('</myfunds>') != -1)
		funds = myFunds.substring(0,myFunds.indexOf('</myfunds>'));
	else
		funds = myFunds;

	return(funds);
}

function PreviousPage()
{
//	document.frmMain.target = '_self';
	document.frmMain.action = 'PKRFactsheetSelection.asp';
	var crntPage = parseInt(document.frmMain.pageNo.value,10);
	if(crntPage > 1)
		document.frmMain.pageNo.value = crntPage - 1;
	else
		document.frmMain.pageNo.value = 1;
	
	document.frmMain.submit();
	
}

function NextPage()
{
//	document.frmMain.target = '_self';
	document.frmMain.action = 'PKRFactsheetSelection.asp';
	var crntPage = parseInt(document.frmMain.pageNo.value,10);
	document.frmMain.pageNo.value = crntPage + 1;
	document.frmMain.submit();
	
}

function ViewOnSinglePage()
{
	document.getElementById('fundsperpage').value = '*';
	document.frmMain.action = 'PKRFactsheetSelection.asp';
	document.frmMain.pageNo.value = '1';
	document.frmMain.submit();
}
function ShowCSV()
{
	document.frmMain.action = 'PKRFactsheetSelection.asp?csv=true';
	document.frmMain.submit();
}
function ShowCSVPrice()
{
	ShowCSV();

}
function ShowCSVPerformance()
{
	ShowCSV();
}
function OrderBy(orderField)
{
	document.frmMain.action = 'PKRFactsheetSelection.asp';
	document.frmMain.rank.value = orderField;
	document.frmMain.submit();
}

function HiLiteRow(rowId)
{
	var HI_LITE_COLOR = 'goldenrod';
	
	var row = document.getElementById('row_' + rowId);
	var underline = document.getElementById('underline_' + rowId); 
	if(row != null)
	{
		if(row.childNodes[0].className != 'TDResultsWhiteHL' && row.childNodes[0].className != 'TDResultsGreyHL')		
		{
			//Highlight row
			var sTdClass = '';
			for(var idx=0; idx < row.children.length;idx++)
			{
				if(row.childNodes[idx].className == 'TDResultsWhite')
					sTdClass = 'TDResultsWhiteHL';
				else
					sTdClass = 'TDResultsGreyHL';
				
				row.childNodes[idx].className = sTdClass;
			}
			var highlightButton = document.getElementById('highLightButton_' + rowId); 
			if(highlightButton != null)
			{
				highlightButton.src = 'Media/highlight_arrow_blue.gif';
			}
		}
		else
		{
			//unhighlight row
			var sTdClass = '';
			for(var idx=0; idx < row.children.length;idx++)
			{
				if(row.childNodes[idx].className == 'TDResultsWhiteHL')
					sTdClass = 'TDResultsWhite';
				else
					sTdClass = 'TDResultsGrey';
				
				row.childNodes[idx].className = sTdClass;
			}
			var highlightButton = document.getElementById('highLightButton_' + rowId); 
			if(highlightButton != null)
			{
				highlightButton.src = 'Media/highlight_arrow_grey.gif';				
			}			
			
		}
		
	}
}

function resetCompanyFilters()
{
	var fundType = document.getElementById('fundtype');
	if(fundType != null)
	{
		fundType.selectedIndex = -1;
	}

		
	var sector = document.getElementById('sector');
	if(sector != null)
	{
		sector.selectedIndex = -1;
	}	
	
	var ccy = document.getElementById('currency');
	if(ccy != null)
	{
		ccy.selectedIndex = -1;
	}
	
	var fundMgr = document.getElementById('fundmanager');
	if(fundMgr != null)
	{
		fundMgr.selectedIndex = -1;
	}
	
	var category = document.getElementById('category');
	if(category != null)
	{
		category.selectedIndex = -1;
	}	
	
	var fundId = document.getElementById('fundid');	
	if(fundId != null)
	{
		fundId.value = '';
	}
		
	var fundName = document.getElementById('fundname');
	if(fundName != null)
	{
		fundName.value = '';
	}
}

function indexFromValue(sValue, ctlList)
{
	var rslt = -1;
	
	for(var idx=0; idx < ctlList.length;idx++)
	{
		if(ctlList.options[idx].value == sValue)
			rslt = idx;
	}
	
	return rslt;
}

function goCompany()
{
	var companyList = document.getElementById('company');
	var companyCode = companyList.options[companyList.selectedIndex].value;
	var screenType = document.frmMain.factSheetType.value;
	
	var sURL = '';
	
	if(screenType=='performance'){
		sURL = '/funds/performance';
	}
	else {
		sURL = '/funds/prices';
	}
	
	// Reset all company specific filters
	resetCompanyFilters();

	// Reset the page number to page 1
	document.frmMain.pageNo.value = 1;
	
	switch(companyCode)
	{
		case 'OLABFIN'	:
			this.location.href = 'http://www.skandia-life.fi' + sURL;
			return;
		case 'OLABNOR'	:
			this.location.href = 'http://www.skandia-life.no' + sURL;
			return;
		// krisaa 7437:28 26/09/2006
		case 'SIML' :
			// commented by Sathya on 27 Dec 2007, SR00247C, Desc: To open the SIML in separate window
 			//this.location.href = 'http://www.skandiainvestmentmanagement.com/funds/fund_information.asp';
			// Added by Sathya on 27 Dec 2007, SR00247C, Desc: To open the SIML in separate window
			window.open('http://www.skandiainvestmentmanagement.com/funds/fund_information.asp', '_blank'); 
			return;
		// MURARV 14630:8 20/06/2007 SelestiaWrap Changes
		case 'SISL' :
 			this.location.href = 'Funds_SISL.htm';
			return;
		default			:
			document.frmMain.action = 'PKRFactsheetSelection.asp?lang=ENG';
			break;			
	}
	document.frmMain.rank.value = '';
	document.frmMain.submit();
	
}

function goPerformance(fundIdValue, companyCodeValue)
{
	var fundId = document.getElementById('fundid');	
	if(fundId != null)
	{
		fundId.value = fundIdValue;
	}
	
	var companyList = document.getElementById('company');
	if(companyList != null)
	{
		companyList.selectedIndex = indexFromValue(companyCodeValue,companyList);
	}
	
	fetchFactSheets('performance');
}

function dispPDF(fundid, coco, clss, lang){
	window.open('/Funds/GetFactsheet.asp?FundID=' + fundid + '&amp;Company='+ coco + '&amp;Class=' + clss + '&amp;Language=' + lang + '&amp;Series=1&amp;FileType=PDF',null)
}
function dispHTM(fundid, coco, clss, lang){
	window.open('/Funds/GetFactsheet.asp?FundID=' + fundid + '&amp;Company='+ coco + '&amp;Class=' + clss + '&amp;Language=' + lang + '&amp;Series=1&amp;FileType=HTM',null)
}