var sPerformace = 1;
var sPortfolio = 3;
var sVolatility = 6;
var sDetails = 5;
var sExportPrices = 10;
var sFTPortfolio = 11;
var sRiskMatrixSingle = 20;
var MenuHeight = 140;
var bUnloadToModulePg = false

var CONST_FULL_COMPANY_TILDE_IDENTIFIER = '~~~~~~~~~~~~~~~~'
var CONST_FULL_CATEGORY_TILDE_IDENTIFIER = '~~~~~~~~~~~~~'
var CONST_FULL_INDICES_REGION_TILDE_IDENTIFIER = '~~~~~~~~~~~~~~~~~~~'
var CONST_FULL_INDICES_SUPPLIER_TILDE_IDENTIFIER = '~~~~~~~~~~~~~~~~~~~~'
var CONST_CATEGORY_AVERAGE_IDENTIFIER = '~~~~~~'
var CONST_COMPANY_AVERAGE_IDENTIFIER = '~~~~~~~~~~~~~~~~~~~~~~'
var CONST_INDICES_IDENTIFIER = 'INDICES~INDICES'


function setBMarkflag(boolFlag) {
	var strInvRef = 'dataref';	
	var arrInvRef;
	var strselectref;
	//if ((boolFlag == true) || (boolFlag == false)) {
	 	var strselectref = getCookie(strInvRef); //# check Reference cookie
	 	if (strselectref == null) {
			//windowWrite("value was null->set to (0,"+boolFlag+")");
	 		arrInvRef = new Array(0,boolFlag); //#= intcookiecount,boolMKbenchmark
	 	} else {
	 		arrInvRef = strselectref.split("|",2);
	 		if (arrInvRef.length < 2) {
			//alert("set: "+boolFlag);
			//arrInvRef[0] = 0;
	 		}
	 		arrInvRef[1] = boolFlag; //#= boolMKbenchmark
	 	}
		strselectref = arrInvRef.join("|");
		setDataCookie(strInvRef,strselectref);
	//}
}

function getRefEl(intIndex) {
	var strInvRef = 'dataref';	
	var arrInvRef;
	var strselectref;
   var boolflag = new Boolean();
 	var strselectref = getCookie(strInvRef); //# get Reference cookie
 	if (strselectref == null) {
 		return null; //#= empty = null.
 	} else {
 		arrInvRef = strselectref.split("|",3);
		if (arrInvRef.length >= intIndex) {
 			return arrInvRef[intIndex]; //#= return value
		}else {
			return null;
		}
 	}
}
function getCookiecount() {
	var intValue;
   var intValue = parseInt(getRefEl(0)); //# check Reference cookie
 	if (isNaN(intValue)) {
 		return 0; //#= default is false.
 	} else {
 		return intValue; //#= assign value
 	}
}
function getBMarkflag() {
	var strValue;
    var boolflag = new Boolean();
 	var strValue = getRefEl(1); //# check Reference cookie
	boolflag = (strValue);
	return boolflag;
}


if (document.layers) {
		window.captureEvents(Event.MOUSEMOVE);
	}

	window.onMouseMove = resetTimer;

	var tID = '';

	function resetTimer(e) {
		clearTimeout(tID); // reset the timer
		tID = setTimeout('executeTimer()', 1740000); //29 minutes
		
	}

	function executeTimer() {
		alert('Your session at MMIA has expired');
   	parent.parent.location.replace('../login.asp')
	}


function LogoutInfo()
{
//*'-------------------------------------------------------------------
//'Date: 05/09/2004
//'Developer: DQ
//'Comments: Have an onunload function on this page that will redirect to a page that will write user log details
//'*******************************************************************/
//Returns full array of the check box Analysis Options
var w = 480, h = 340;
if (document.all || document.layers) {
   w = screen.availWidth;
   h = screen.availHeight;
}
var popW = 300, popH = 100;
var leftPos = (w-popW)/2, topPos = (h-popH)/2;


	if(bUnloadToModulePg != true){		//If not going to module page
		popup=window.open("../modules/loginDecoy1.asp?Locale=ENG&Lo=1", 'report','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',alwaysLowered');	
	}	
}

function getBMark() {
	var strValue;
	var arrValue = new Array();
 	var strValue = getRefEl(2); //# check Reference cookie
 	if (strValue != null) {
 		arrValue[0] = strValue;
 	} else {
		arrValue[0] = null;
	}
	return arrValue;
}
function getDataSelect() {
   var strInvCookie = 'dataselect';	
	var strCat = "";
	var arrValue;
	var intCookiecount = getCookiecount();
	for(iLoop=0;iLoop<=intCookiecount;iLoop++) {
		strTmp = getCookie(strInvCookie+iLoop);
		if (strTmp != null){
			strCat = strCat + "|" + strTmp;
		}
	}
	if (strCat.length > 3) {
		strCat = strCat.substring(1,strCat.length);
		arrValue = strCat.split("|");
	}else {
		arrValue = new Array(null);
	}
	return arrValue;
}


function setCookie(name, value) {
	var today = new Date();
	var expire_text="";
	//if (daystoexpire) {
	var expires = new Date(today.getTime() + ((86400000))); // 1 day
	expire_text = ";expires=" + expires.toGMTString()
	//}
	document.cookie = name + "=" + escape(value) + "; path=/";
	
}

// getCookie
function getCookie (name) {
	var dcookie = document.cookie;
	var cname = name + "=";
	var clen = dcookie.length;
	var cbegin = 0;
	windowWrite("cookie:"+dcookie);
	while (cbegin < clen) {
		var vbegin = cbegin + cname.length;
		if (dcookie.substring(cbegin, vbegin) == cname) {
			var vend = dcookie.indexOf (";", vbegin);
			if (vend == -1) vend = clen;
			return unescape(dcookie.substring(vbegin, vend));
		}
		cbegin = dcookie.indexOf(" ", cbegin) + 1;
		if (cbegin == 0) break;
	}
	return null;
}

function checkSelected(){

var ConvSelectType ="<%=iDataSelectType%>";								//Change to java type
var sSearch = 2;
var iDataTree = 5;
var bSelected = false;
var sInvCookieStr="";
	for (i = 0;i<document.myform.elements.length;i++){					//Check if any check box's have been selected
		if(document.myform.elements[i].type == "checkbox"){
			if (document.myform.elements[i].checked){
				sInvCookieStr = sInvCookieStr + document.myform.elements[i].value + "|"
				bSelected = true;	
			}
		}
	}
	if (bSelected == true){	
	    return true;
	}
		
	alert ('Please select something');
	return false;														//Cancel post
}

function SaveInvestCookie(sCookieName)
{
var sInvCookieStr="";
var bSelected=false;
	for (i = 0;i<document.myform.elements.length;i++){					//Check if any check box's have been selected
		if(document.myform.elements[i].type == "checkbox"){
			if (document.myform.elements[i].checked){
				sInvCookieStr = sInvCookieStr + document.myform.elements[i].value + "|"
				bSelected = true;	
			}
		}
	}
	if (bSelected == true){	
	    sInvCookieStr = sInvCookieStr.substring(0, sInvCookieStr.length-1)	//Write investment id for next page.
		setCookie(sCookieName, sInvCookieStr);
		return true;
	}else{
		sInvCookieStr = "";
		setCookie(sCookieName, sInvCookieStr);
	}
}
function ClearAll()
{

for (i = 0;i<parent.frames[1].myform.elements.length;i++){							//Check if any check box's have been selected
	if(parent.frames[1].myform.elements[i].type == "checkbox"){
		parent.frames[1].myform.elements[i].checked = false;
	 }			
}
return true;
}

function wordsplit(items) 
{
var charect = "";
for (var n = 1 ; n <= items.length ; n++) 
{
if (items.substring(n-1,n) == "@") 
{ charect+=" "; }
else 
{ charect+=items.substring(n-1,n); }
}
return charect;
} 	 

function sCurrPageMarker(sName, sMarker)
{
setCookie(sName, sMarker);
}

function DeselectCookie(ObjChkBox, sCookie, sCookieName)
{
	var SeparatorTilde = '|';
	var sBuildNewStr = "";
	if(ObjChkBox.checked == false){
		var sChkBoxValue = ObjChkBox.value.substring(0, ObjChkBox.value.length-1)
		var SplitTilde = sCookie.split(SeparatorTilde);
		for (i = 0;i<SplitTilde.length;i++){
			if(SplitTilde[i] == sChkBoxValue){
				SplitTilde[i] = ""		
			}
		}
		for (i = 0;i<SplitTilde.length;i++){
			if(SplitTilde[i] != ""){
				sBuildNewStr = sBuildNewStr + SplitTilde[i] + "|"
			}
		}
		sBuildNewStr = sBuildNewStr.substring(0, sBuildNewStr.length-1)
		setCookie(sCookieName, sBuildNewStr) 				
	}
		
	
}

function SaveDataListCookie(iName, sInvCookieStr)
{
setCookie(iName, sInvCookieStr);
}
function setDataCookie(iName, sInvCookieStr)
{
setCookie(iName, sInvCookieStr);
}

// Begin navigation functions

function ModuleMenu()
{ // used to jump back to module selection screen
// should clear any cookies/session data as required
	if (parent.frames[1].TopDropSelect.CheckPgLoaded()) {
		var IsLoad = parent.frames[1].TopDropSelect.CheckPgLoaded()
		if (IsLoad == true){
			setBMarkflag(false);
			//parent.frames[1].TopDropSelect.GatherCookieData();
		}
	}
	bUnloadToModulePg=true
	parent.location.replace('../framesets/Dataselectionframe.asp?ModuleType=12'); 
	setBMarkflag(false);
}

function ShowSelector(boolIsBenchMark, iFramSZ, iModuleType)
{ // boolIsBenchMark: optional argument used in Volatility to specify whether
// (true) = BenchmarkSelector OR
// (false) = DataSelector is to be shown
	var sType = iModuleType;
	
	benchmarkcookie = getBMarkflag()
	
	parent.Report.location.replace("../Modules/DataLoading.asp");
	if (boolIsBenchMark && sType==6) {
		var benchmarkcookie;
				
		if(sType==6){
			benchmarkcookie = getBMarkflag()
		}else{
			benchmarkcookie = false
			boolIsBenchMark=false
		}
				
		//if currentSelector == requested => display current selector
		if ('false' == boolIsBenchMark) { // display current selector
			parent.document.body.rows=''+iFramSZ+',*,0%,0%';
			parent.Bottomside.location.replace('../framesets/DataFrame.asp');
		} else { // show opposite selector so reload page
			setBMarkflag(boolIsBenchMark);
			parent.parent.document.body.rows='150,*,0,0';
			parent.Bottomside.location.replace('../framesets/SifaDataFrame.asp');
		}
	} else { //not Vol mod, so just redisplay
		parent.document.body.rows=''+iFramSZ+',*,0%,0%';
	}
}

function myvoid() {}
// End navigation functions
//AD debug
var windowDebug = false;
var popupD;
if (windowDebug) {
	if (parent.length == 0) {
	popupD =top.window.open("","message","toolbar=no,width=350,height=300,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
	var msgcontent = "";
	windowWrite("Andrews Debug window:<br>");
	}
}

function windowWrite(newstring) { 
	if (windowDebug) {
		day = new Date();
		hour = day.getHours();
		minute = day.getMinutes();
		minute = (minute < 10) ? "0" + minute : minute;
		msgcontent = msgcontent + hour + ":" + minute + "# " + newstring + "<BR>";
		if (popupD) {
		popupD.document.open();
		popupD.document.write(msgcontent);
		popupD.document.close();
		}
	}
}

/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setPermanentCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}
// -end debug code

function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}



function deleteOption(object,index) {
	object.options[index] = null;
}

function addOption(object,text,value) {
	var defaultSelected = false;
	var selected = false;
	var optionName = new Option(text, value, defaultSelected, selected)
	object.options[object.length] = optionName;
	object.options[object.length-1].selected = false;
 }

	
function reverseSort(a, b) 
{ 
if(a < b) 
     return -1 
  if(a > b) 
     return 1 
  return 0 
} 



function sortOptions(what) {
	//'-------------------------------------------------------------------
	//'Description: Sorts combo box's. company etc
	//'-------------------------------------------------------------------
	//'Date: 20/06/2!!4
	//'Developer: David Quinn
	//'Comments:   
	//'*******************************************************************

	
	var copyOption = new Array();
	for (var i=0;i<what.options.length;i++)
       copyOption[i] = new Array(what[i].text, what[i].value);

	copyOption.toLowerCase
	copyOption.sort(reverseSort);

	for (var i=what.options.length-1;i>-1;i--)
       deleteOption(what,i);

	for (var i=0;i<copyOption.length;i++)
		addOption(what,copyOption[i][0],copyOption[i][1])
	
	for(var i=0;i<what.options.length;i++){
		if(i<what.options.length-1){
			if(what.options[i].text == what.options[i+1].text){
				what.options[i] = null
			}
		}	  
	}
        
}


function PopupWindow()
{
//-------------------------------------------------------------------
//'Description: Used For popup attributes
//'Pass 
//'Return
//'-------------------------------------------------------------------
//'Date: 19/01/01
//'Developer: David Quinn
//'Comments: Will find out if Report or Graph wanted and then generate
//'*******************************************************************
if (self.screen) {
		winwidth= screen.availWidth;
		winheight = screen.availHeight;
		}
		else
			if (navigator.javaEnabled && navigator.javaEnabled()) {
			winwidth = java.awt.Toolkit.getDefaultToolkit().getScreenSize().availWidth;
			winheight = java.awt.Toolkit.getDefaultToolkit().getScreenSize().availHeight;
			}
   
	popup=window.open("dataloading.asp","DetailsReport","toolbar=no,width=" + (winwidth -10 ) + ",height=" + (winheight - 50) + ",location=no,directories=no,status=yes,menubar=no,screenX=0,screenY=0,left=0,top=0,scrollbars=yes,resizable=yes");
		
	//setTimeout("popup.focus()", 2000);
	
return true;															//No post
}

function NoUnload()
{
	try{
		parent.parent.frames[0].bUnloadToModulePg=true
	}catch(e){
	}
}

//SIFA Toolbar functions

var menu1=new Array()
menu1[0]='<a target="_parent" href="../framesets/fSifaStaticContentFrame.asp?pgStaicContent=1" onclick="NoUnload();">Definitions</a><br>'
menu1[1]='<a target="_parent" href="../framesets/fSifaStaticContentFrame.asp?pgStaicContent=2" onclick="NoUnload();">Suitability</a><br>'
menu1[2]='<a target="_parent" href="../framesets/fSifaStaticContentFrame.asp?pgStaicContent=3" onclick="NoUnload();">User Notes</a><br>'
menu1[4]='<a target="_parent" href="../framesets/fSifaStaticContentFrame.asp?pgStaicContent=5" onclick="NoUnload();">Search</a><br>'


var menuwidth='165px' //default menu width
var menubgcolor='../Images/DropDownGreyBG.gif'  //menu image instead of bgcolor
var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

var ie4=document.all
var ns6=document.getElementById&&!document.all

function LoadDefaultSifaMenu()
{
	if (ie4||ns6)
	document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-image: url('+menubgcolor+')" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')
}


function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (menuwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){

if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")-20
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
	if (typeof dropmenuobj!="undefined"){
		if (ie4||ns6)
			dropmenuobj.style.visibility="hidden"
	}
}

function delayhidemenu(){

if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu