function mouseloc(e) {
  if (!e) var e = window.event;
  if (e.pageX || e.pageY) {
    mx = e.pageX;
    my = e.pageY;
  }
  else if (e.clientX || e.clientY) {
    mx = e.clientX + document.body.scrollLeft
      + document.documentElement.scrollLeft;
    my = e.clientY + document.body.scrollTop
      + document.documentElement.scrollTop;
  }
  return mx, my;
}

// show Div like a popup with dimmed background
function popshowDim(reqd) {
	var div = document.getElementById(reqd);
	var dim = document.getElementById('dim');
	
	if(div.style.display=="none") {
		div.style.display = "block";
		dim.style.display = "block";
	} else {
		div.style.display = "none";
		dim.style.display = "none";
	}
}

// show popup
function popshow(popnm,divtohide) {
        if (document.getElementById) {
                  document.getElementById(popnm).style.display = "block";
                 if (divtohide) {
                           document.getElementById(divtohide).style.display = "none";
                 }
        }
}

function popshowSecure(thisobj,trgt,w,h) {
	var pageloc =  thisobj.getAttribute("href");
	if (!trgt) trgt = "_blank";
	window.open(pageloc,trgt,'width='+w+',height='+h);
}

// show div with iframe
function showIFrame(id) {
	var div = document.getElementById(id);
	
	if (div.style.display == 'none') {
		div.style.display = 'block';
		div.style.position = 'absolute';
		div.style.left = '200px';
		div.style.top = '250px';
		div.style.width = '70px';
		div.style.height = '500px';
	} else if (div.style.display == 'block') {
		div.style.display = 'none';
	}
}

// Show-Hide div
function divShowHide(objname) {
	var thisobj = document.getElementById(objname);
	thisobj.style.display = thisobj.style.display == "none" ? "" : "none";
}

// show 1 div, hide all others - with plus/minus in link (NEW VERSION)
// PLUS IMAGE PATH - /img/b_show_sm.gif
// MINUS IMAGE PATH - /img/b_hide_sm.gif
function plusminusshowhide(sequence,elementid,imgid,img1url,img2url)
{
	document.getElementById(elementid+sequence).style.display = document.getElementById(elementid+sequence).style.display=="none"?"block":"none";
	for (i=1;i<=30;i++)
	{
		if(elementid+i!=elementid+sequence)
		{
				document.getElementById(elementid+i).style.display='none';
		}
		document.getElementById(imgid+i).src=document.getElementById(elementid+i).style.display=='none'?img1url:img2url;
	}
}

// show 1 div, hide all others - with plus/minus in link (OLD VERSION)
function opendiv(id)
{
	var divstyle = document.getElementById(id);
	if (divstyle.style.display == 'none')
	{
		for (i=1;i<=30;i++)
		{
			var divname = 'div'+i;
			var imgdivname = 'img'+divname;
			var divstyle = document.getElementById(divname).style;
			divstyle.display=(id==divname)?'block':'none';
			document.images[imgdivname].src=(divstyle.display=='none')?'/img/b_show_sm.gif':'/img/b_hide_sm.gif';
		}
	}
	else if (divstyle.style.display == 'block')
	{
		imgdivname = 'img'+id;
		divstyle.style.display = 'none';
		document.images[imgdivname].src='/img/b_show_sm.gif';
	}
}


// show/hide and also change name of the link
function showhidedivlinkchange(linkid,elementid,linkdivshow,linkdivhide)
{
	document.getElementById(elementid).style.display=document.getElementById(elementid).style.display=='none'?'block':'none';
	document.getElementById(linkid).innerHTML=document.getElementById(elementid).style.display=='block'?linkdivhide:linkdivshow;
}

// swap newslist
function swapnewslist(id)
{
	var divstyle = document.getElementById(id);
	if (divstyle.style.display == 'none')
	{
		for (i=1;i<=30;i++)
		{
			var divname = 'news'+i;
			var divstyle = document.getElementById(divname).style;
			divstyle.display=(id==divname)?'block':'none';
		}
	}
}

// swap news - shows selected news item, hides all others
function shownewsstory(id)
{
	var divstyle = document.getElementById(id);
	if (divstyle.style.display == 'none')
	{
		for (i=1;i<=150;i++)
		{
			var divname = 'div'+i;
			var divstyle = document.getElementById(divname).style;
			divstyle.display=(id==divname)?'block':'none';
		}
	}
}

// process logout
/* LM: Removed as unnecessary, used in page PHP on logout.php instead
function doSecureLogout(url)
{
	document.getElementById('securelogout').src = url;
}
*/

// following globals required for the help functions
var helpwiderwidth = 481;
var helpnarrowidth = 250;
var helpwiden = 0;

// help widget toggle
function helptoggle() {
  if (document.getElementById) {
	if (document.getElementById("widgets_efo") || document.getElementById("widgets_public")) {
				var rwidge = document.getElementById("widgets_public") ? document.getElementById("widgets_public") : document.getElementById("widgets_efo");
				var rwidgedivs =  rwidge.getElementsByTagName("DIV");
				var rwidgeselects =  rwidge.getElementsByTagName("SELECT");
				for (var chk = 0; chk < rwidgedivs.length; chk++) {
					if (rwidgedivs[chk].className == "widget" && (rwidgedivs[chk].id != "widgehelp" && rwidgedivs[chk].id != "login")) {
						rwidgedivs[chk].style.opacity = rwidgedivs[chk].style.opacity == 0.3 ? 1 : 0.3;
						rwidgedivs[chk].style.filter = rwidgedivs[chk].style.filter == "alpha(opacity=30)" ? "alpha(opacity=100)" : "alpha(opacity=30)";
						/*
						var idAdvert = /Advert/;
						var idChart = /Chart/;
						if ( idAdvert.test(rwidgedivs[chk].id) || idChart.test(rwidgedivs[chk].id) ) {
							rwidgedivs[chk].style.display = rwidgedivs[chk].style.display == "none" ? "block" : "none";
						}
						*/
					}
				}
				for (var chk = 0; chk < rwidgeselects.length; chk++) {
					rwidgeselects[chk].style.display = rwidgeselects[chk].style.display == "none" ? "block" : "none";
				}
	}

	document.getElementById("widgehelpcontent").style.display = document.getElementById("widgehelpcontent").style.display == "block" ? "none" : "block";
	document.getElementById("widgehelpbot").style.display = document.getElementById("widgehelpbot").style.display == "block" ? "none" : "block";
	document.getElementById("widgehelptop").style.height = document.getElementById("widgehelptop").style.height == "20px" ? "21px" : "20px";
	var timg = document.getElementById("togglehelpimg").src;
	var imgn = timg.length - 14;
	document.getElementById("togglehelpimg").src = timg.substr(imgn) == 'b_minimise.gif' ? '/img/b_maximise.gif' : '/img/b_minimise.gif';
	document.getElementById("togglehelpimg").alt = document.getElementById("togglehelpimg").alt == 'show content' ? 'hide content' : 'show content';
	if ( (document.getElementById("widgehelptop").style.width == helpwiderwidth +"px" || helpwiden == 1 ) ) {
	// LM#TODO - maybe need to change 'widgehelptop' back to 'help' in the above line
	  helptogglewide();
	  helpwiden = 1;
	} else {
	  helpwiden = 0;
	}
	//PTA redirect to section of help:
	var help_anchor = window.location.hash;
	if (help_anchor != '') {window.location.hash = help_anchor;}
  }
}

// toggle help section contents and check for width change
function helpsectiontoggle(thisobj,wid) {
  if (document.getElementById) {

	thisimgn = thisobj.src.length - 13;

	// check that the help width should change
	if (wid) {
	  var showimg = 0;

	  var htimgarr = document.getElementById("widgehelp").getElementsByTagName("IMG");
	  for (var chk = 0; chk < htimgarr.length; chk++ ) {
		var imgn = htimgarr[chk].src.length -13;
		var htimg = htimgarr[chk].src.substr(imgn)
		if (htimgarr[chk].className == "helpcontenttoggleimgwide" && htimg == "b_hide_sm.gif")  showimg++;

	}

	var timg = document.getElementById("togglewidehelpimg").src;
	var imgn = timg.length - 10;
	  if ( (thisobj.src.substr(thisimgn) == 'b_show_sm.gif' && timg.substr(imgn) == "b_wide.gif") || (thisobj.src.substr(thisimgn) == 'b_hide_sm.gif' && showimg == 1 && timg.substr(imgn) == "b_narr.gif") ) {
		helptogglewide();
	  }
	}

	thisobj.src = thisobj.src.substr(thisimgn) == 'b_hide_sm.gif' ? '/img/b_show_sm.gif' : '/img/b_hide_sm.gif';
	thisobj.alt = thisobj.src.substr(thisimgn) == 'b_hide_sm.gif' ? 'hide content' : 'show content';

	var sibnxt = thisobj.parentNode.nextSibling;
	while (sibnxt) {
	  while (sibnxt.nodeType != 1) {
		sibnxt = sibnxt.nextSibling;
	  }
	  if (sibnxt.getElementsByTagName("IMG").length > 0) {
		if (sibnxt.getElementsByTagName("IMG")[0].className == "helpcontenttoggleimg" || sibnxt.getElementsByTagName("IMG")[0].className == "helpcontenttoggleimgwide") {
		  break;
					} else {
					sibnxt.style.display = sibnxt.style.display == "none" ? "" : "none";
					}
	  } else {
		sibnxt.style.display = sibnxt.style.display == "none" ? "" : "none";
	  }
	  sibnxt = sibnxt.nextSibling;
	}
  }
}

// toggle help width
function helptogglewide(closeall) {
  if (document.getElementById) {
	var newwidth = document.getElementById("widgehelp").style.width == helpwiderwidth +"px" ? helpnarrowidth : helpwiderwidth;

	if ( document.getElementById("widgehelpcontent").style.display == "none" && newwidth == helpwiderwidth) {
	return;
	}

	document.getElementById("widgehelptop").style.width = document.getElementById("widgehelpbot").style.width = document.getElementById("widgehelp").style.width = newwidth +"px";
	document.getElementById("widgehelp").style.left  = 985 - newwidth +"px";
	document.getElementById("widgehelpcontent").style.width  = newwidth - 21 +"px";
	document.getElementById("widgehelp").getElementsByTagName("H2")[0].style.width  = newwidth - 18 +"px";
	document.getElementById("helptogglelink").style.left  = newwidth - 35 +"px";
	document.getElementById("widgehelptop").style.background = newwidth == helpwiderwidth ? "url(/img/widg_sngl_l4.gif)" : "url(/img/widg_sngl_l2.gif)";
	document.getElementById("widgehelpbot").style.background = newwidth == helpwiderwidth ? "url(/img/widg_bot_l4.gif)" : "url(/img/widg_bot_l2.gif)";

	var timg = document.getElementById("togglewidehelpimg").src;
	var imgn = timg.length - 10;
	document.getElementById("togglewidehelpimg").src = timg.substr(imgn) == 'b_wide.gif' ? '/img/b_narr.gif' : '/img/b_wide.gif';
	if (newwidth == helpnarrowidth)  helpwiden = 0;

	if (newwidth == helpnarrowidth && document.getElementById("widgehelpcontent").style.display == "block" && closeall == "widgclose") {

	  var htimgarr = document.getElementById("widgehelp").getElementsByTagName("IMG");
	  for (var chk = 0; chk < htimgarr.length; chk++ ) {
		thatobj = htimgarr[chk];
		if (thatobj.className == "helpcontenttoggleimgwide") {
		  thatobj.src = '/img/b_show_sm.gif';
		  thatobj.alt = 'show content';

		  var sibnxt = thatobj.parentNode.nextSibling;
		  while (sibnxt) {
			while (sibnxt.nodeType != 1) {
			  sibnxt = sibnxt.nextSibling;
			}
			if (sibnxt.getElementsByTagName("IMG").length > 0) {
			  if (sibnxt.getElementsByTagName("IMG")[0].className == "helpcontenttoggleimg" || sibnxt.getElementsByTagName("IMG")[0].className == "helpcontenttoggleimgwide") {
				break;
			  }
			} else {
//                  sibnxt.style.display = sibnxt.style.display == "none" ? "" : "none";
			  sibnxt.style.display = "none";
			}
			sibnxt = sibnxt.nextSibling;
		  }
		}
	  }
	}
  }
}

// toggle widgets open and close
function widgtoggle(thisobj) {
  if (document.getElementsByTagName) {
	var timg = thisobj.src;
	var imgn = timg.length - 14;
	var thiswidgdivs = thisobj.parentNode.parentNode.parentNode.getElementsByTagName("DIV");
	for (var chk = 0; chk < thiswidgdivs.length; chk++) {

	  switch(thiswidgdivs[chk].className) {

	  case "widgettop":
		if (thisobj.parentNode.parentNode.getElementsByTagName("UL").length > 0) {
		  thisobj.parentNode.parentNode.getElementsByTagName("UL")[0].style.display = timg.substr(imgn) == "b_maximise.gif" ? "block" : "none";
		  thisobj.parentNode.parentNode.getElementsByTagName("H2")[0].className = timg.substr(imgn) == "b_maximise.gif" ? "" : "headnonav";
		}
		thiswidgdivs[chk].style.height = timg.substr(imgn) == "b_maximise.gif" ? "20px" : "21px";
		thisobj.alt = timg.substr(imgn) == "b_maximise.gif" ? "hide content" : "show content";
		thisobj.src = timg.substr(imgn) == "b_maximise.gif" ? "/img/b_minimise.gif" : "/img/b_maximise.gif";
		break;

	  case "widgetcont":
		thiswidgdivs[chk].style.display = thiswidgdivs[chk].style.display == "none" ? "block" : "none";
		break;

	  case "widgetbot":
		thiswidgdivs[chk].style.display = thiswidgdivs[chk].style.display == "none" ? "block" : "none";
		break;
	  }
	}
  }
}

function selmenureload() {
  if (document.getElementById) {
	var alldivs =  document.getElementsByTagName("DIV");
	for (var chk = 0; chk < alldivs.length; chk++) {
	  if (alldivs[chk].className == "selmenu") {
	   alldivs[chk].style.display = "block";
	  }
	}
  }
}

function targetwin(thisobj,trgt) {
	var pageloc =  thisobj.getAttribute("href");
	if (trgt=="") return;
	if (!trgt) trgt = "_blank";
	window.open(pageloc,trgt);
}

// possible solution to fixing pdf download issues
function externalLinks() {
	if (!document.getElementsByTagName) return;

	var anchors = document.getElementsByTagName("a");

	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];

		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank";
		}
}

window.onload = externalLinks;

function hideStatus()
{
	// hide status bar text
	var statusMsg		= ""

	window.status = statusMsg
	return true
}

function switchDisplayDiv(sTrigger,iDisplay,sClass,iTotalDivs)
{
	// switch between divs for any given number of divs
	var wantedDiv		= document.getElementById(sTrigger + iDisplay);
	var wantedTrigger	= document.getElementById('trigger' + sTrigger + iDisplay);

	for (var i = 1; i <= iTotalDivs; i++)
	{
		var oDivDisplay = document.getElementById(sTrigger + i).style.display;

		if (i != iDisplay)
		{
			document.getElementById(sTrigger + i).style.display = 'none';
			if (i == 1) {
				document.getElementById('trigger' + sTrigger + i).className = 'first';
			} else {
				document.getElementById('trigger' + sTrigger + i).className = '';
			}
		} else {
			if (i == 1) {
				document.getElementById('trigger' + sTrigger + i).className = 'first hi';
			} else {
				document.getElementById('trigger' + sTrigger + i).className = 'hi';
			}
		}
	}

	if (wantedDiv.style.display == 'none')
	{
		wantedDiv.style.display = ''; // /!\ style.display='block' does not work correctly with FF
	}

	hideStatus();
}

function switchDisplayTabColumn(columnName,iDisplay,iHide,totalTD,evt)
{
	var e = (evt) ? evt : window.event;
	var target = (e.target) ? e.target : e.srcElement;

	// hide / show columns of a tab

	for (var i = 1; i <= totalTD; i++)
	{
		if (iHide.length) {
			for (var j = 1; j <= iHide.length; j++) {
				if (iHide[j-1] != iDisplay) {
					document.getElementById('column_' + columnName + iHide[j-1] + i).style.display = 'none';
				}
			}
		}
		else {
			document.getElementById('column_' + columnName + iHide + i).style.display = 'none';
		}
		document.getElementById('column_' + columnName + iDisplay + i).style.display = ''; // /!\ style.display='block' does not work correctly with FF
	}
	document.getElementById(columnName + '_filter').innerHTML=target.innerHTML;
}

function showFundManager(url) {
    if (url != '0') {document.location.href = "/market-data/funds/fund-selector.php?COMPANY="+url+"&TYPE=&ISAPEP=&MAINSECTOR=&LOCALSECTOR=&TRADENOW=on&SPECIALISTSECTOR=&AREASECTOR=&PERF_PERIOD=&PERF_COND=&PERF_VALUE=&FEES_TYPE=&FEES_COND=&FEES_VALUE=&get=Search"};
}

function testdigit() {
  if (document.getElementById) {
    if (document.getElementById('lusername').value.search(/^[0-9]+$/) > -1) {
    document.getElementById('passcodetext').style.display = "none";
    document.getElementById('passcodedigit').style.display = "block";
    document.getElementById('logindigittext').style.display = "block";
  }
 }
}

function pcadd(codeadd) {
  if (document.getElementById) {
    document.getElementById('lpassworddigit').value += codeadd;
  }
}


function pcclear() {
  if (document.getElementById) {
    document.getElementById('lpassworddigit').value = "";
  }
}

function loadfocus() {
  if (document.getElementById) {
    document.getElementById('lusername').focus();
  }
}

function customisetoggle(thisobj) {
      if (document.getElementsByTagName) {
        var custdivs = thisobj.parentNode.parentNode.getElementsByTagName('DIV');
        var custh1 = thisobj.parentNode.parentNode.getElementsByTagName('H1');
//        custh1[0].style.margin = "0 0 0 10px";
// alert(custh1[0].style.margin);

        for (var chk = 0; chk < custdivs.length; chk++) {
          clnme = /mainhome/i;
          if ( clnme.test(custdivs[chk].className) ) {
            custdivs[chk].style.display = custdivs[chk].style.display == "none" ? "block" : "none";
          }
        }
        var imgn = thisobj.src.length -10;
        thisobj.src= thisobj.src.substr(imgn) == 'b_hide.gif' ? '/img/b_show.gif' : '/img/b_hide.gif';
        thisobj.alt = thisobj.src.substr(imgn) == 'b_hide.gif' ? 'hide content' : 'show content';
      }
    }



// toggle  search results open and close
    function searchselectortoggle(thisobj) {
      if (document.getElementsByTagName) {
        var timg = thisobj.src;
        var imgn = timg.length - 16;
        var thissrchdivs = thisobj.parentNode.parentNode.parentNode.getElementsByTagName("DIV");
        for (var chk = 0; chk < thissrchdivs.length; chk++) {

          clnme = /tabstopl6/;
          if ( clnme.test(thissrchdivs[chk].className) ) thissrchdivs[chk].className = "tabstopl6";

          switch(thissrchdivs[chk].className) {

          case "tabstopl6":
            if (thisobj.parentNode.parentNode.getElementsByTagName("UL").length > 0) {
              thisobj.parentNode.parentNode.getElementsByTagName("UL")[0].style.display = timg.substr(imgn) == "b_maximise_p.gif" ? "block" : "none";
              thisobj.parentNode.parentNode.getElementsByTagName("H2")[0].className = timg.substr(imgn) == "b_maximise_p.gif" ? "" : "headnonav";
            }
            thissrchdivs[chk].style.background = "url(/img/tabs_sngl_l6.gif)";
            thissrchdivs[chk].style.height = timg.substr(imgn) == "b_maximise_p.gif" ? "20px" : "21px";
            thisobj.alt = timg.substr(imgn) == "b_maximise_p.gif" ? "hide content" : "show content";
            thisobj.src = timg.substr(imgn) == "b_maximise_p.gif" ? "/img/b_minimise_p.gif" : "/img/b_maximise_p.gif";
            break;

          case "tabscont6":
            thissrchdivs[chk].style.display = timg.substr(imgn) == "b_maximise_p.gif" ? "block" : "none";
            break;

          case "tabsbotl6":
            thissrchdivs[chk].style.display = timg.substr(imgn) == "b_maximise_p.gif" ? "block" : "none";
            break;
          }
        }
      }
    }




sections = ['group2'];

  /*
  Debug Functions for checking the group and item order
  */
  function getGroupOrder() {
    var sections = document.getElementsByClassName('section');
    var alerttext = '';
    sections.each(function(section) {
      var sectionID = section.id;
      var order = Sortable.serialize(sectionID);
      if (sectionID=="group2")
      {
        $('choosen_element').value=Sortable.sequence(section);
      }
      alerttext += sectionID + ': ' + Sortable.sequence(section) + '\n';
    });
    if ($('choosen_element').value!='')
    {
      $('save_form').submit();
    }
    else
    {
      alert('you must choose some elements');
      return true;
    }
  }

/* Save the current state for public/member/customer. */
function saveState(setting,value) {
	AjaxRequest.get({
		'url' : '/member/save-state.php?setting=' + setting + '&value=' + value,
		'onSuccess' : function(req) {
			var result = req.responseText;
			}
		});
}

// The following two function Require Scriptaculous
function showNotice() {
	Effect.Appear('notification');
}
function hideNotice() {
	Effect.Fade('notification');
}

function openWatchlistNews(url){
	winpops=window.open(url,'watchlistNews','width=760,height=500,scrollbars,')
}

function initQuoteLinks()
{	
	var alllinks = $('pagenav').getElementsByTagName('a');
	for(var i = 0; i < alllinks.length; i++)
		if(alllinks[i].id == "navhi4")
			alllinks[i].id = "";
}

function highLightQuoteLink(mypathname)
{
	var alllinks = $('pagenav').getElementsByTagName('a');
	for(var i = 0; i < alllinks.length; i++)
		if(alllinks[i].pathname == mypathname)
			alllinks[i].id = "navhi4";
}

function refreshDetails(symb)
{	
	AjaxRequest.get({
			'url' : '/sharefunddetails.php?symbole=' + symb,
				'onSuccess' : function(req) {
				try {
					$('sharedetails').innerHTML = req.responseText;
				} catch(e) {
					return;
				}
			}
		});
	return;
}

function navigate(view)
{
	document.location.hash = '#'; 
	initQuoteLinks(); 
	tab = view.split('#');

	if(tab.length < 2)
		return;

	pageNews = (tab[0] == '/ajax/news.php');
	

	AjaxRequest.get({
			'url' : tab[0] + '?' + tab[1],
				'onSuccess' : function(req) {
				try {
					$('quotepagecontent').innerHTML = req.responseText;

					var allscript = $('quotepagecontent').getElementsByTagName('SCRIPT');
					for(var i=0; i<allscript.length; i++)
						{
							window.eval(allscript[i].text);
						}
				} catch(e) {
					return;
				}
			}
		});
	return;
}

function contenttoggle(thisobj) {
  if (document.getElementsByTagName) {
	thisobj.parentNode.parentNode.parentNode.getElementsByTagName('DIV')[2].style.display = thisobj.parentNode.parentNode.parentNode.getElementsByTagName('DIV')[2].style.display == 'none' ? 'block' : 'none' ;
	var imgn = thisobj.src.length -10;
	thisobj.src= thisobj.src.substr(imgn) == 'b_hide.gif' ? '/img/b_show.gif' : '/img/b_hide.gif';
	thisobj.alt = thisobj.src.substr(imgn) == 'b_hide.gif' ? 'hide content' : 'show content';
  }
}

function sectiontoggle(thisobj) {
  if (document.getElementsByTagName) {

	var imgn = thisobj.src.length -13;
	thisobj.src= thisobj.src.substr(imgn) == 'b_hide_sm.gif' ? '/img/b_show_sm.gif' : '/img/b_hide_sm.gif';
	thisobj.alt = thisobj.src.substr(imgn) == 'b_hide_sm.gif' ? 'hide content' : 'show content';

	var sibnxt = thisobj.parentNode.parentNode.nextSibling;
	while (sibnxt) {
	  while (sibnxt.nodeType != 1) {
		sibnxt = sibnxt.nextSibling;
	  }
	  if (sibnxt.getElementsByTagName("TH")[0]) {
		break;
	  } else {
		sibnxt.style.display = sibnxt.style.display == "none" ? "" : "none";
	  }
//          if (sibnxt.nextSibling) {
		sibnxt = sibnxt.nextSibling;
//          } else {
//            break;
//          }
	}
  }
}
