

function toggleAdvOpt(){
	var advOptTable = document.getElementById("advOpt");
	if (advOptTable.style.display == "block" || advOptTable.className == "advOpt1"){
		advOptTable.className = "advOpt0";
		//reset drop downs if user hides them.
		document.forms["searchOptions"].advFilter.value = 0;
		document.forms["searchOptions"].fundSize.selectedIndex = 0;
		document.forms["searchOptions"].fundAge.selectedIndex = 0;
		document.forms["searchOptions"].initCharge.selectedIndex = 0;
		document.forms["searchOptions"].annualCharge.selectedIndex = 0;
	}
	else{
		advOptTable.className = "advOpt1";
		document.forms["searchOptions"].advFilter.value = "1";
	}
}


function GoToPage(pageNo){
	document.forms["searchOptions"].pageNo.value = pageNo;
	//document.forms["searchOptions"].submit();	
	submitForm();
}

function ChangeDataType(type){
	document.forms["searchOptions"].dataType.value = type;
	var typeArr = new Array("price","perf","risk","fees");
	for (var i=0; i<typeArr.length; i++){
		if (typeArr[i] == type){
			document.getElementById(type+"Table").className = "dataTableOn";
			document.getElementById(type+"Link").className = "dataTypeOn";
		}
		else{
			document.getElementById(typeArr[i]+"Table").className = "dataTable";
			document.getElementById(typeArr[i]+"Link").className = "dataType";
		}
	}
	//move pageNav down below dataTable height (in case of word-wrapping).
	var pnTop = 305; //document.getElementById(type+"Table").style.top;  remove because it can't read the stylesheet, only in-line.
	pnTop += document.getElementById(type+"Table").scrollHeight;
	if (document.getElementById("pageNav")){
		document.getElementById("pageNav").style.top = pnTop + 5;
	}
	document.getElementById("disclaimer").style.top = pnTop + 30;
}

function GoMainSite(brand){
	var str = "http://";
	switch (brand){
		case 'tdw'	:	str += "www.tdwaterhouse.co.uk/"; break;
		case 'rbs'	:	str += "www.rbs-sharedealing.co.uk"; break;
		case 'ntw'	:	str += "www.natweststockbrokers.co.uk"; break;
		default		:	str += "www.tdwaterhouse.co.uk/"; break;	
	}
	var version_val = parseInt(navigator.appVersion)
	if (version_val>=4 || window.location.replace){
		window.location.replace(str);
	}
	else{
		window.location.href = str;
	}
}


function Sort(field){
	document.forms["searchOptions"].sortField.value = field;
	//document.forms["searchOptions"].submit();
	submitForm();
}

function clearForm(){
	for (var i=0; i<document.forms["searchOptions"].elements.length; i++){
		if (document.forms["searchOptions"].elements[i].selectedIndex){
			document.forms["searchOptions"].elements[i].selectedIndex = 0;
		}
	}
}

function GoTrade(brand){
	var str = "https://";
	switch (brand){
		case 'tdw'	:	str += "secure.tdwaterhouse.co.uk/webbroker2/logged.do"; break;
		case 'rbs'	:	str += "secure.rbs-sharedealing.co.uk/rbs-secure2/logged.do"; break;
		case 'ntw'	:	str += "secure.natweststockbrokers.co.uk/nws-secure2/logged.do"; break;
		default		:	str += "secure.tdwaterhouse.co.uk/webbroker2/logged.do"; break;	
	}
	var version_val = parseInt(navigator.appVersion)
	if (version_val>=4 || window.location.replace){
		window.location.replace(str);
	}
	else{
		window.location.href = str;
	}
}

function GoDisclaimer(brand){
	var str = "";
	switch (brand){
		case 'tdw'	:	str += "http://www.tdwaterhouse.co.uk/investment/frtandcs_tdw.htm"; break;
		case 'rbs'	:	str += "http://www.rbs-sharedealing.co.uk/investment/frtandcs_rbs.htm"; break;
		case 'ntw'	:	str += "http://www.natweststockbrokers.co.uk/investment/frtandcs_nws.htm"; break;
		default		:	str += "http://www.tdwaterhouse.co.uk/investment/frtandcs_tdw.htm"; break;	
	}
	openWindow(str);
}

function hiliteSortField(){
	
	var sortfield = document.getElementById("sortField").value;
	
		
	if (sortfield!="" || sortfield!="NameLong"){
		var sortHead = document.getElementById("lnk" + sortfield);
		if (sortHead){
			sortHead.style.textDecoration="underline";		
		}
	}	
	
	if (sortfield=="NameLong") {
		
		document.getElementById("lnkPricesNameLong").style.textDecoration="underline";
		document.getElementById("lnkPerfNameLong").style.textDecoration="underline";
		document.getElementById("lnkRiskNameLong").style.textDecoration="underline";
		document.getElementById("lnkFeesNameLong").style.textDecoration="underline";
	}

	
}

function openWindow(url){
	window.open(url,"disclaimer","width=750,height=550");
}
//Submit the form and sets URL queryString with manger code if manager is not All.
function submitForm(){ 
 var brand=document.getElementById("brand").value;
 var managerValue=document.getElementById("managerDDL").value;
 if(managerValue != "" && brand=="tdw")
 {   
   document.forms["searchOptions"].action="PriceTable.aspx?manager="+managerValue;   
 }
 document.forms["searchOptions"].submit();
}

function pageBreak(){
  var innerText=document.getElementById("Margin").innerHTML;
  var totalLen=innerText.length;
  if((document.getElementById("Margin").getElementsByTagName("a")).length>25)
  {
  var elementA=document.getElementById("Margin").getElementsByTagName("a")[25];
  var aContentLen= elementA.innerHTML.length;
  
  var aContentPos=innerText.indexOf('>'+elementA.innerHTML);
  
  var firstPart=innerText.substring(0,aContentPos+aContentLen+5);
  var secondPart=innerText.substring(aContentPos+aContentLen+5,totalLen);
  
  document.getElementById("Margin").innerHTML=firstPart + "</br>" + secondPart;
  }  
}

