
 
 
function fSubmit(queryParam){
 
 field= document.getElementById("valueOfHoldings");
if(field){
 	if(field.value=="" || field.value==0){
		alert(document.getElementById("lb_"+fieldName).innerHTML+" should have a value greater then 0.")
		field.value="0"
		return
	}
  }
 	
 			document.navigationform.analysis.value=true;
	  	    document.navigationform.action="portfolio_analysis.jsp?"+queryParam
		    document.navigationform.submit();
	   
}
	    
	    
function fSubmitNewSearch(obj){
	 document.navigationform.reset.value=true;
	 document.navigationform.submit();
	   
}
	    
	    
	    
function fNumberCheck(e){
	var keycode;
	if (window.event)
		keycode = window.event.keyCode;
	else if (e) 
		keycode = e.which;
	else 
		return true;
	// Allow only numbers, backspace and decimal point 
 
	if (((keycode>47) && (keycode<58) )  || (keycode==8)|| (keycode==127) ) 
	{ 
		 
		return true;
	}
	return false;
}

function fAmountCheck(myfield,e){
	var keycode;
	if (window.event)
		keycode = window.event.keyCode;
	else if (e) 
		keycode = e.which;
	else 
		return true;
	// Allow only numbers, backspace and decimal point 
 
	if (((keycode>47) && (keycode<58) )  || (keycode==8) || (keycode==46) || (keycode==127) ) 
	{ 
		 
	
		// Allow only one decimal point
		if (keycode == 46 && (myfield.value.lastIndexOf(".") >= 0))
			return false;
			
		return true;
	}
	return false;
}

function fCalculations(field){

var fieldName = field.name

if(field.value=="" || field.value==0){
	alert(document.getElementById("lb_"+fieldName).innerHTML+" should have a value greater then 0.")
	field.value="0"
//	return
}

var ratioOrdinary = document.navigationform.ratioOrdinary.value;
var ratioDRs = document.navigationform.ratioDRs.value;
var valueOfHoldings = replaceAll(document.navigationform.valueOfHoldings.value);
var numberOfOrdinaryShares = replaceAll(document.navigationform.numberOfOrdinaryShares.value);
var pricePerOrdinaryShare = replaceAll(document.navigationform.pricePerOrdinaryShare.value);
var numberOfDRs = replaceAll(document.navigationform.numberOfDRs.value);
var pricePerDR = replaceAll(document.navigationform.pricePerDR.value);


	if(fieldName=="valueOfHoldings"){
		
		if(pricePerOrdinaryShare>0){
			numberOfOrdinaryShares = Math.round(valueOfHoldings/pricePerOrdinaryShare);
		}else{
			alert(document.getElementById("lb_pricePerOrdinaryShare").innerHTML+" should have a value greater then 0.")
			numberOfOrdinaryShares=0
		}
		
		if (numberOfOrdinaryShares > 0)
			numberOfDRs =  Math.round(ratioDRs*numberOfOrdinaryShares/ratioOrdinary) ;
		else
			numberOfDRs =  0;
		
	}


   	else if(fieldName=="numberOfOrdinaryShares"){
	 
		
		numberOfOrdinaryShares = Math.round(numberOfOrdinaryShares);
		valueOfHoldings = numberOfOrdinaryShares*parseFloat(pricePerOrdinaryShare).toFixed(2) ;
		
		if (numberOfOrdinaryShares > 0)
			numberOfDRs=  Math.round(ratioDRs*numberOfOrdinaryShares/ratioOrdinary) ;
		else
			numberOfDRs =  0;
	}
	
	
	
	else if(fieldName=="pricePerOrdinaryShare"){
	
		pricePerOrdinaryShare = parseFloat(pricePerOrdinaryShare).toFixed(2);
	 	valueOfHoldings = numberOfOrdinaryShares*pricePerOrdinaryShare;
	
	 
	}
	
	else if(fieldName=="numberOfDRs"){
	
		numberOfDRs = Math.round(numberOfDRs);
		
		if (numberOfDRs > 0)
	 		numberOfOrdinaryShares= Math.round(numberOfDRs* ratioOrdinary/ratioDRs);
	 	else
	 		numberOfOrdinaryShares = 0;
	 		
		valueOfHoldings = numberOfOrdinaryShares*parseFloat(pricePerOrdinaryShare).toFixed(2);
	
	
	}else if(fieldName=="pricePerDR"){
	
	
	}

document.navigationform.valueOfHoldings.value = format(parseFloat(valueOfHoldings).toFixed(2)) ;
document.navigationform.numberOfOrdinaryShares.value = format(parseFloat(numberOfOrdinaryShares).toFixed(0))  ;
document.navigationform.pricePerOrdinaryShare.value =  format(parseFloat(pricePerOrdinaryShare).toFixed(2));
document.navigationform.numberOfDRs.value =  format(parseFloat(numberOfDRs).toFixed(0));
document.navigationform.pricePerDR.value = format(parseFloat(pricePerDR).toFixed(2))  ;




}

function format(Num) {
	var newNum = "";
	var newNum2 = "";
	var count = 0;
	decPart=""
	index = Num.indexOf(".")
	
	if(index>0){
		decPart = Num.substring(index)
		Num = Num.substring(0,index)
	}
	//this loop actually adds the commas
	for (var k = Num.length-1; k >= 0; k--) {
		var oneChar = Num.charAt(k);
		if (count == 3) {
			newNum += ",";
			newNum += oneChar;
			count = 1;
			continue;
		} else {
			newNum += oneChar;
			count ++;
		}
	} //but now the string is reversed!

	//re-reverse the string
	for (var k = newNum.length-1; k >= 0; k--){
		var oneChar = newNum.charAt(k);
		newNum2 += oneChar;
	}

	return newNum2+decPart;
}

function replaceAll(Num) {
	while (Num.indexOf(",")>=0){
		Num = Num.replace(",","")
	}
	return Num
}



var marketValueHelp = "This number is calculated based on the average daily update to the depositary receipt price and multiplied by the number of depositary receipts entered under the field \"Number of DRs\". The price listed by the DR Converter for the individual DR is not a real time quote and should not be construed as such.";
var drCostHelp1 = "ADRIssConvFee * NoOfDRs + BrokCommFeeUS + DepServFee * NoOfDRs + DividendFee * NoOfDRs + DomestCustFee + CustodyFee + StampDutyTaxADR * MarketValue";
var drCostHelp2 = "BrokCommFeeUS + DepServFee * NoOfDRs + DividendFee * NoOfDRs + DomestCustFee + CustodyFee + StampDutyTaxADR * MarketValue";
var ordCostHelp = "BrokCommFeeFgn + FXConversionFee * MarketValue + GlobalCustSettlFee + GlobalSafekeepingFee * MarketValue + StampDutyTaxORD * MarketValue";
var ordPriceHelp = "This figure is not a real time quote nor is it necessarily representative of the price of the ordinary share in the home market. This figure is derived utilizing the \"Price per DR\" and the \"Ratio\" (DRs to Ordinary Shares).";
var drPriceHelp = "Price shown is provided via IDC and is updated every night. BNY Mellon and its suppliers believe the information herein was obtained from reliable sources but they do not guarantee its accuracy.";
 
