function openPopup(pagePath,iWidth,iHeight,forPrint,useUnique,keepOpen){
			var iWinWidth = (iWidth) ? parseInt(iWidth) : 455;
			var iWinHeight = (iHeight) ? parseInt(iHeight) : 380;
			
			pagePath = String(pagePath).toLowerCase();
			// if other arguments exist, the first after url overwrites width of window
			
			
			//if (iWidth) iWinWidth = iWidth;
			//if (iHeight) iWinHeight = iHeight;
						
			var iAvailWidth = screen.availWidth - 40;
			var iAvailHeight = screen.availHeight - 40;
			if (iAvailWidth < iWinWidth) iWinWidth = iAvailWidth;
			if (iAvailHeight < iWinHeight) iWinHeight = iAvailHeight;
			// also center position of window
			var iLeft = (iAvailWidth - iWinWidth)/2;
			var iTop = (iAvailHeight - iWinHeight)/2;
			
			// make a function to generate window name unique or non unique as requested
			// close or do not close opened windows
			// add window to global least level array in opened windows stack
						
			var newWinName = (useUnique) ? getWindowName() : 'newWindow'; 
			
			var GlobalArray = (!keepOpen) ?  getGlobalArray() : new Array();
			
			if (forPrint)
				GlobalArray[GlobalArray.length] = window.open(pagePath,newWinName,'width='+ iWinWidth +',left='+ iLeft +',top='+ iTop +',height='+ iWinHeight +',toolbar=0,status=0,menubar=1,resizable=1,scrollbars=1');
			else
				GlobalArray[GlobalArray.length] = window.open(pagePath,newWinName,'width='+ iWinWidth +',left='+ iLeft +',top='+ iTop +',height='+ iWinHeight +',toolbar=0,status=0,menubar=0,resizable=1,scrollbars=1');
				
			
			GlobalArray[GlobalArray.length-1].focus();	
			
			
			if (event)
			{
				event.cancelBubble = true;
				event.returnValue = false;			
			}
			
		}
		
		var MenuIsOpen = false;
		function openModal(pagePath,iWidth,iHeight,isModal){
			var iWinWidth = (iWidth) ? parseInt(iWidth) : 455;
			var iWinHeight = (iHeight) ? parseInt(iHeight) : 380;
			
			pagePath = String(pagePath).toLowerCase();
			
			var iAvailWidth = screen.availWidth;
			var iAvailHeight = screen.availHeight;
			if (iAvailWidth < iWinWidth) iWinWidth = iAvailWidth;
			if (iAvailHeight < iWinHeight) iWinHeight = iAvailHeight;
			/*
			// also center position of window
			var iLeft = (iAvailWidth - iWinWidth)/2;
			var iTop = (iAvailHeight - iWinHeight)/2;
			*/
			// open either a modal or modless dialog according to isModal
						
			var modalReturn;
				
			if (isModal)
				modalReturn = showModalDialog(pagePath,window,'dialogHeight:'+ iWinHeight+ 'px;dialogWidth:'+ iWinWidth+'px ;center: yes ;resizable: no ;scroll: no;status:no');
			else{
				if (!MenuIsOpen) showModelessDialog(pagePath,window,'dialogHeight:'+ iWinHeight+ 'px;dialogWidth:'+ iWinWidth+'px ;center: yes ;resizable: no ;scroll: yes;help:no; status:no;');
				MenuIsOpen = true;
				// this line means i have to reset menuisopen upon closure of dialog!
				
			}
			
			if (event && isModal)
			{
				event.cancelBubble = true;
				event.returnValue = false;			
			}
			
			
			
		}
		
	var newWin = new Array();
	function getGlobalArray(){
		
		if (window.opener)
		{
			if (window.opener.getGlobalArray)
				return window.opener.getGlobalArray();
			else
				return newWin;
		}
		else
			return newWin;
	}

	function getWindowName(){
		// keep searching for a new unique ID
		
		var newID = window.document.uniqueID;
		if (window.newID){
			newID = window.document.body.uniqueID;
		}
		return newID;
	}
	
	function unloadPopup(){
										  
		// loop thru all opened windows and close only if this is the main window
		if (!window.opener){
			var i = 0;
			var newWinX;
			
			for (i=0; i<newWin.length; i++){
				
				if (window.newWin[i])
					if (!window.newWin[i].closed)
						window.newWin[i].close();
				newWin[i] = null;
			
			}
		}
		
		
		
	}
	var onLoadFocus = true; // set this to false in individual documents
	window.onunload = unloadPopup;
	window.onload = loadPage;
	var loadBodyFunc;
	
	function loadPage(){
		
		if (loadBodyFunc){
			eval(loadBodyFunc);
		}
		
		
	}
	
	
	function doChoose(elemID){
		// when choice is made, popup for user to choose dates
		var srcElem = event.srcElement;
		var divElem = document.getElementById(elemID);
		if (!divElem) return;
		
		var chooseElem = srcElem.options[srcElem.selectedIndex].getAttribute("choose");
		if (chooseElem)
		
			divElem.style.display = 'inline';
		else
			divElem.style.display = 'none';
		
	}
	
	function goTo(url){
		if (window.opener){
			window.opener.location.href = url;
			window.opener.focus();
		}
	}
	
	
	var SelectedTab;
	/* for testing CRAP CODE **** REMOVE LATER ****/
	function showHideRange(){
		var elem  = document.getElementById('range');
		if (elem.style.display == 'none')
			elem.style.display = 'block';
		else
			elem.style.display = 'none';
	}
	var tabElem;
function showTab(ind){
		// change source and change table shown
				
		var newTab = document.getElementById("tab" + ind);
		if (!tabElem)
			tabElem = document.getElementById("tab1");
			
		if (tabElem)
			tabElem.style.display = "none";
		
		if (newTab){
			newTab.style.display = "block";
			tabElem = newTab;
		}
		
		//change image source
		document.getElementById('tabImage').src = gImagesFolder + "/iTabMain"+ ind +".gif";
		
		
	}
	var tabElem2;
	function showTab2(ind){
		// change source and change table shown
		
		var newTab = document.getElementById("tab" + ind);
		if (!tabElem2)
			tabElem2 = document.getElementById("tab5");
		
		
		if (tabElem2)
			tabElem2.style.display = "none";
		
		if (newTab){
			newTab.style.display = "block";
			tabElem2 = newTab;
		}
		
		//change image source
		document.getElementById('tabImage2').src = gImagesFolder +"/iTabSector"+ ind +".gif";
		
		
	}
	
	
	/***************TICKER***********************************/
	var CodeElem = {};
	var ValueElem = {};
	var ValueImgs = {};
	var ValueElem1 = {};
	var ValueElem2 = {};
	var shownInd = 0;
	var bEmpty = false;
	var tickerGroup;
	function updatTickerObj(arr, strEmptyMsg){
		//window.parent.status = (new Date()).getTime();
		var totalComp;
		var i;

		if (!tickerGroup) tickerGroup = {};
		
		// if no elements exist, display invalid information
		if (bEmpty){
			document.getElementById('tickerObj').innerText = "";
			bEmpty = false;
		}
		if (arr.length == 0) {
			tickerGroup = {};
			CodeElem = {};
			ValueElem = {};
			ValueImgs = {};
			ValueElem1 = {};
			ValueElem2 = {};	
			bEmpty = true;
			document.getElementById('tickerObj').innerText = strEmptyMsg;
			
			return;
		}
		for (i=0; i<arr.length; i++){
			
			// take one element at a time, create an array, and read the elements inside
			totalComp = arr[i].text.split("|");
						
			// first element is company id, then code, value and change (KEEP TRACK)
			var companyID = totalComp[0];
			var Code = totalComp[1];
			var Value = totalComp[2];
			var Change = totalComp[3];
			var Type = totalComp[4];
			
			elem = document.getElementById(companyID);
			
			//var returnElem = createElem(compIDs);
			//updateElement(returnElem,compCodes, compValues, compChanges);
			
			
			// look for the element in the current tickerGroup, if found, update, else create a new element
			//	alert(tickerGroup[companyID]);
				//if (tickerGroup[companyID]){
				if (elem){
				
					// do get the children
					if (!CodeElem[companyID]){
						CodeElem[companyID] = elem.children[0];
						ValueElem[companyID] = elem.children[1];
						// ya 7arram
						ValueImgs[companyID] = new Array(ValueElem[companyID].children[0],ValueElem[companyID].children[1],ValueElem[companyID].children[2]);
						ValueElem1[companyID] = ValueElem[companyID].childNodes(0);
						ValueElem2[companyID] = ValueElem[companyID].childNodes(4);
						
						// get shown index
						
						
					}	
					var j;
					for (j=0; j<ValueImgs[companyID].length; j++){
						if (ValueImgs[companyID][j].style.display != 'none') {
							shownInd = j;
							
							break;
						}
					}		
					CodeElem[companyID].setAttribute("onclick", "window.parent.location.href='" + companyURL + "?c=" + Type + "&id=" + companyID + "&st=1");
					ValueElem1[companyID].nodeValue = Value;
					
					var nChange = (Change < 0) ? Change * -1 : Change;
					ValueElem2[companyID].nodeValue = parseFloat(Change.replace(",","").replace("-","")).toFixed(2) + "%";
					
					var Changef = Change.replace(",","")
					
					var imgInd= (Changef >= 0) ? ((Changef > 0) ? 0 : 2): 1;
					
					ValueImgs[companyID][shownInd].style.display = 'none';
					ValueImgs[companyID][imgInd].style.display = ''; //tickerImagesFolder +"i"+ imgSrc +".gif";
					shownInd = imgInd;
	
				}else{
					// create a new element
					var newElem = document.createElement("SPAN");
					newElem.className = "tickerElement";
					document.getElementById('tickerObj').appendChild(newElem);
					
					newElem.id = companyID;
					newElem.companyID = companyID;
					newElem.Code = Code;
					newElem.Type = Type;
					newElem.Value = Value;
					newElem.Change = Change;
					
					// for synchrinization problems, lets add company to tickergroup here
					tickerGroup[companyID] = newElem;
				}
			
		}
	}
	
	var fixedCompanyDetailsURL = "market/company.htm";
	var tickerImagesFolder = "images/";

	var currentState = 'started';
	function tickerPlay(dir){
		var tickerObj = document.getElementById('tickerObj');
		var pauseImage = document.getElementById('pauseImage');
		if (dir == 1) {
			tickerObj.direction = 'left'; 
			tickerObj.start(); 
			currentState = 'stopped';
			pauseImage.click();
		}else if(dir == -1) {
			tickerObj.direction = 'right'; 
			tickerObj.start(); 
			currentState = 'stopped';
			pauseImage.click();
		}else {
			// save last dir, restart
			if (currentState == 'started') { 
				tickerObj.stop();
				event.srcElement.src = event.srcElement.playImage;
				currentState = 'stopped';
			}else {
				event.srcElement.src = event.srcElement.stopImage;
				tickerObj.start();
				currentState = 'started';
			}
			
			
		}
	}
//'JS
//**************************************************************************
//*****************************Please Dont Remove***************************
//**************************************************************************	

	function toggleselectEnable(item,itemID1){
	//var fieldObj1 = document.getElementById(itemID);
	var fieldObj = document.getElementById('_ctl0_' +itemID1);
	
	if ((item.value==5) || (item.value == 6) || (item.value == -2))
	{	fieldObj.style.display = 'none';
		fieldObj.value=-1;
		}
	else
		{fieldObj.style.display = '';
		}
		
}
	
//'JS
function SelectCategory(fieldObjname,fieldObjId){
	var fieldObj = document.getElementsByName(fieldObjname);
	var i;
	if (fieldObj){
			for (i=0;i<fieldObj.length;i++){
				if ( fieldObj[i].getAttribute("blokid") != fieldObjId)
					{
					fieldObj[i].runtimeStyle.display = 'none';
					}
				else
					{
					fieldObj[i].runtimeStyle.display = '';
					// do click first one whichev
								
					if (fieldObj[i].doClick == "yes") fieldObj[i].children[0].click();
					}
			
			}
			
			
	}	
	
	
}
function doClickLetter(){
	var elems = document.getElementsByName('letterLinks');
	if (elems){
		if(elems.length > 0)
			elems[0].click();
	}
	
}

//'JS
function ShowHideDivTerms(fieldObjname,fieldObjId){
	var fieldObj = document.getElementsByName(fieldObjname);
	var i;
	if (fieldObj){
			for (i=0;i<fieldObj.length;i++){
			if ( fieldObj[i].getAttribute("blokid") !== fieldObjId)
			{
			fieldObj[i].runtimeStyle.display = 'none';
			}
			else
			{
			fieldObj[i].runtimeStyle.display = '';
			}
			}
	}	
	
}

//'SM
function clearField(txt){
	handleField(txt,event.srcElement,0);
}

//'SM
function fillField(txt){
	handleField(txt,event.srcElement,1);
}

//'SM
function handleField(txt,fieldObj,actionInt){
	var val = fieldObj.value;
	switch (actionInt){
		case 0:
			if (val == txt) fieldObj.value = "";
			break;
		case 1:
			if (val == "") fieldObj.value = txt;
			break;
	}
}

//'SM
function populateContent(){
	// find PrintContent main container
	if (!window.opener) return;
	
	var mainContainer = window.opener.document.getElementById('PrintContent');
	
	if (!mainContainer) return;
	
	var elem = document.getElementById('PrintContent');
	
	if (!elem) return;

	// grap "doPrint" elements
	var elems = mainContainer.all;
	doPrintContent(elems,elem);
}

function doPrintContent(cContainer,printElem){

	var sepDiv;
	var ccContainer;

	for (var i=0; i<cContainer.length; i++){
		if (cContainer[i].getAttribute("doPrint") == "true")
		{
			prTitle = cContainer[i].getAttribute("prTitle");
			if (prTitle) 
				sepDiv = "<p class='bgGreyLight borderBotGreyDark'>"+ prTitle  + '</p>';
			else
				sepDiv = '';
				
			printElem.innerHTML += sepDiv + cContainer[i].innerHTML;
		}
		else
		{
			// span children as well
			if (cContainer[i].tagName == "IFRAME"){
				ccContainer = cContainer[i].ownerDocument.frames(cContainer[i].id).document.all;
				doPrintContent(ccContainer,printElem);
			}
		}
	}
}

	

//'SM
function SubmitQuoteSearch(sUrl, arrFields)
{
	var query = '';
	var bNoData = true;

	for (i=0; i<arrFields.length; i++)
		if (document.getElementById(arrFields[i]).value != '')
			{
				query += '&q' + [i] + '=' + document.getElementById(arrFields[i]).value;
				bNoData	= false;
			}
	
	if (bNoData)
		document.getElementById('trError').style.display = 'block';
	else
	{
		document.getElementById('trError').style.display = 'none';
		window.location = sUrl + query;
	}
		
		
	return false;
}

	var gHiLight;
	function doHilight(){
		// lose global highlight, and gain this one
		var elem = event.srcElement;
		if (gHiLight){
			gHiLight.className = "track";
			
		}
		elem.className = "track hilight";
		gHiLight = elem;
	}
	var gHiLightLetter;	
		function doHilightLetter(){
		
		// lose global highlight, and gain this one
		var elem = event.srcElement;
		
		if (gHiLightLetter){
			gHiLightLetter.className = "box";
			
		}
		elem.className = "box hilightLetter";
		
		gHiLightLetter = elem;
	}

//**************************************************************************
//**************************************************************************
//'IK on [Saturday, January 15, 2005]
var sessionInterval = "";
var sessionCounter;
//start the window interval 
function startSessionInterval(SessionTimeOut)
{
    sessionInterval = window.setInterval("displaySessionTimer()",60000);
    sessionCounter = SessionTimeOut;
} 
// Stop the window interval 
function stopSessionInterval()
{
    window.clearInterval (sessionInterval);
    sessionInterval="";
}
//Display a message when the session is about to expire 
function displaySessionTimer()
{
//eval("document.all."+"SessionTimer").innerHTML = --isessioncounter;
      --sessionCounter;
      if (sessionCounter == 0)
      {
            alert ("Your session has expired. You'll be asked to submit your sign-in credentials on the system. Any unsaved information on the current page will be lost.");
            stopSessionInterval();
      }
}
//**************************************************************************	
function updateSelected(tabID,index){
	var tabO = window.top.document.getElementById(tabID);	
	if (tabO){
		//var newTab = tabO.tabs.selectedIndex + dir;
		
		tabO.tabs[index].Select();
	}
	
}


function disableLinks(){
	var elem = document.getElementById('PrintContent');
	
	if (!elem) return;
	var elems = elem.getElementsByTagName("A");

	for (var i=0; i<elems.length; i++){
		elems[i].onclick = cancelEvent;
		elems[i].className = 'nolink';
	}
}

function cancelEvent(){
	event.returnValue = false;
	event.cancelBubble = true;
	
}
function reactiveEvent()
{
	event.returnValue = true;
	event.cancelBubble = false;
}

function showNoPrint(){
	
	alert('There are no contents to print');
	cancelEvent();
}

function changeHref(slink, linkid )
{
	var slink2;
	var selectedIndex;
	var selectedSubIndex;
	var selectedSubIndex2;
	if (document.getElementById('maintabs'))
		{
			selectedIndex=document.getElementById('maintabs').tabs.selectedIndex+1;
			slink2=slink;
			if (slink2.indexOf('st')!= -1)
				{
						if (document.getElementById('subtab'+ selectedIndex))
							{
								selectedSubIndex=document.getElementById('subtab' + selectedIndex).tabs.selectedIndex+1;
								if (slink2.indexOf('tab2')!= -1)
									{
										slink2=slink2.substring(0, slink2.indexOf('st'));
										document.getElementById(linkid).href= slink2+ 'st=' + selectedIndex +'%26'+ 'tab2=' + selectedSubIndex ;
									}
								else
									{
										slink2=slink2.substring(0, slink2.indexOf('st'));
										document.getElementById(linkid).href= slink2+ 'st=' + selectedIndex +'%26'+ 'tab2=' + selectedSubIndex ;
									}
							}
						
						//to MSM 30 
						else if (document.getElementById('frameContent'))
							{
								if (document.frames('frameContent').document.getElementById('aboutmsmtab')) 
									{	
										selectedSubIndex=document.frames('frameContent').document.getElementById('aboutmsmtab').tabs.selectedIndex+1;
										if (slink2.indexOf('tab2')!= -1)
											{
												slink2=slink2.substring(0, slink2.indexOf('st'));
												document.getElementById(linkid).href= slink2+ 'st=' + selectedIndex +'%26'+ 'tab2=' + selectedSubIndex ;
											}
										else
											{
												slink2=slink2.substring(0, slink2.indexOf('st'));
												document.getElementById(linkid).href= slink2+ 'st=' + selectedIndex +'%26'+ 'tab2=' + selectedSubIndex ;
											}
									}
								else
									{
										slink2=slink2.substring(0, slink2.indexOf('st'));
										document.getElementById(linkid).href= slink2+ 'st=' + selectedIndex;
									}
							}
						else
							{
								slink2=slink2.substring(0, slink2.indexOf('st'));
								document.getElementById(linkid).href= slink2+ 'st=' + selectedIndex ;
							}	
				}
			else
				{
					if (document.getElementById('subtab'+ selectedIndex))
						{
							selectedSubIndex=document.getElementById('subtab'+ selectedIndex).tabs.selectedIndex+1;
							if (slink2.indexOf('tab2')!= -1)
								{
									slink2=slink2.substring(0, slink2.indexOf('st'));
									document.getElementById(linkid).href= slink2 +'%26'+ 'st=' + selectedIndex +'%26'+ 'tab2=' + selectedSubIndex ;
								}
							else
								{
									document.getElementById(linkid).href= slink2+'%26'+ 'st=' + selectedIndex +'%26'+ 'tab2=' + selectedSubIndex ;
								}
						}	
						
					//to MSM 30 
					else if (document.getElementById('frameContent'))
						{
								if (document.frames('frameContent').document.getElementById('aboutmsmtab')) 
									{	
										selectedSubIndex=document.frames('frameContent').document.getElementById('aboutmsmtab').tabs.selectedIndex+1;
										if (slink2.indexOf('tab2')!= -1)
											{
												document.getElementById(linkid).href= slink2+'%26'+ 'st=' + selectedIndex +'%26'+ 'tab2=' + selectedSubIndex ;
											}
										else
											{
												document.getElementById(linkid).href= slink2+'%26'+ 'st=' + selectedIndex +'%26'+ 'tab2=' + selectedSubIndex ;
											}
									}
								else
									{
										document.getElementById(linkid).href= slink2+'%26'+ 'st=' + selectedIndex;
									}
							}		
					else
						{
						document.getElementById(linkid).href= slink2+'%26'+'st='+selectedIndex ;
						}			
				}
		}			
}
