/*****************************************
 Function: openWindow functions
 Description: opens pop up window
 Input Params: url, x, y, winName
 Return Value: n/a
******************************************/

function openWindow(url,x,y) {
	/**************************************************************************
	  DO NOT USE THIS FUNCTION! CONFLICTS WITH FUNCTION NAME IN verticalAd.js
	**************************************************************************/
	mywin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=30,top=30,width=' + x + ',height=' + y + '');
	mywin.focus();
}

function openAnySizeWin(url,x,y) {
	mywin = window.open(url,'TSX','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=30,top=30,width=' + x + ',height=' + y + '');
	mywin.focus();
}

function openNewWindow(url,x,y, winName) {
	mywin = window.open(url,winName,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=30,top=30,width=800,height=650');
	mywin.focus();
}

function openNewWindowTech(url,x,y, winName) {
	mywin = window.open(url,winName,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,left=30,top=30,width=' + x + ',height=' + y + '');
	mywin.focus();
}

function openNewWindowMedia(url,x,y, winName) {
	mywin = window.open(url,winName,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=30,top=30,width=' + x + ',height=' + y + '');
	mywin.focus();
}


/*****************************************
 Function: BrowserDetectLite
 Description: browser detection script
 Input Params: n/a
 Return Value: n/a
******************************************/
// Browser Detect Lite  v2.1
// http://www.dithered.com/javascript/browser_detect/index.html
// modified by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)
// modified by Michael Lovitt to include OmniWeb and Dreamcast
// modified by Matt Moore for RealDecoy to include NS7

function BrowserDetectLite() {
	var ua = navigator.userAgent.toLowerCase(); 
	this.ua = ua;

	// browser name
	this.isGecko     = (ua.indexOf('gecko') != -1);
	this.isMozilla   = (this.isGecko && ua.indexOf("gecko/") + 14 == ua.length);
	this.isNS        = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );

	this.isIE        = ( (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) ); 
	this.isOpera     = (ua.indexOf("opera") != -1); 
	this.isKonqueror = (ua.indexOf("konqueror") != -1); 
	this.isIcab      = (ua.indexOf("icab") != -1); 
	this.isAol       = (ua.indexOf("aol") != -1); 
	this.isWebtv     = (ua.indexOf("webtv") != -1); 
	this.isOmniweb   = (ua.indexOf("omniweb") != -1);
	this.isDreamcast   = (ua.indexOf("dreamcast") != -1);
	
	// spoofing and compatible browsers
	this.isIECompatible = ( (ua.indexOf("msie") != -1) && !this.isIE);
	this.isNSCompatible = ( (ua.indexOf("mozilla") != -1) && !this.isNS && !this.isMozilla);
	
	// browser version
	this.versionMinor = parseFloat(navigator.appVersion); 
	
	// correct version number for NS6+ 
	if (this.isNS && this.isGecko) {
		this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
	}
	
	// correct version number for IE4+ 
	else if (this.isIE && this.versionMinor >= 4) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
	}
	
	// correct version number for Opera 
	else if (this.isOpera) {
		if (ua.indexOf('opera/') != -1) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera/') + 6 ) );
		}
		else {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera ') + 6 ) );
		}
	}
	
	// correct version number for Konqueror
	else if (this.isKonqueror) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
	}
	
	// correct version number for iCab 
	else if (this.isIcab) {
		if (ua.indexOf('icab/') != -1) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab/') + 6 ) );
		}
		else {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab ') + 6 ) );
		}
	}
	
	// correct version number for WebTV
	else if (this.isWebtv) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('webtv/') + 6 ) );
	}
	
	this.versionMajor = parseInt(this.versionMinor); 
	this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
	
	// platform
	this.isWin   = (ua.indexOf('win') != -1);
	this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1) );
	this.isMac   = (ua.indexOf('mac') != -1);
	this.isUnix  = (ua.indexOf('unix') != -1 || ua.indexOf('linux') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
	
	// specific browser shortcuts
	this.isNS4x = (this.isNS && this.versionMajor == 4);
	this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
	this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
	this.isNS4up = (this.isNS && this.versionMinor >= 4);
	this.isNS6x = (this.isNS && this.versionMajor == 6);
	this.isNS6up = (this.isNS && this.versionMajor >= 6);
	this.isNS7 = (this.isNS && this.versionMajor >= 7);
	
	this.isIE4x = (this.isIE && this.versionMajor == 4);
	this.isIE4up = (this.isIE && this.versionMajor >= 4);
	this.isIE5x = (this.isIE && this.versionMajor == 5);
	this.isIE55 = (this.isIE && this.versionMinor == 5.5);
	this.isIE5up = (this.isIE && this.versionMajor >= 5);
	this.isIE6x = (this.isIE && this.versionMajor == 6);
	this.isIE6up = (this.isIE && this.versionMajor >= 6);
	
	this.isIE4xMac = (this.isIE4x && this.isMac);
}

/*****************************************
 Function: showHide
 Description: for showing/hiding 15 rows in 
 current market/closing summary table results
 Input Params: tbodyID, linkToActivate
 Return Value: n/a
 note: value in class can contain spaces
******************************************/

function showHide(tbodyID,linkToActivate) {


	var browser = new BrowserDetectLite();

	var body = document.getElementById( tbodyID );

	if( !body ) {
		return;
	}
	
	var rowList = body.getElementsByTagName( "TR" );

	if( !rowList ) {
		return;
	}

	var newClassAttr;
	var startIdx;
	var currentClassAttr;
	
	for( var i = 0; i < rowList.length; i++ ) {

		var row = rowList.item( i );

		if( browser.isIE ) {
			currentClassAttr = row.className;
		} else {
			currentClassAttr = row.getAttribute( "class" );		
		}

		if( !currentClassAttr ) {
			continue;
		}

		if((startIdx = currentClassAttr.indexOf( "showRow" )) != -1 ) {

			newClassAttr = "hideRow";

			if( currentClassAttr.length > 7 ) {
				newClassAttr = newClassAttr + currentClassAttr.substring( 0,  startIdx );
				newClassAttr = newClassAttr + currentClassAttr.substring( startIdx + 7 );
			} 
			if( browser.isIE ) {
				row.className = newClassAttr;
			}
			else
			{
				row.setAttribute( "class", newClassAttr );
			}
		}
		else if((startIdx = currentClassAttr.indexOf( "hideRow" )) != -1 ) {

			newClassAttr = "showRow";

                        if( currentClassAttr.length > 7 ) {
                                newClassAttr = newClassAttr + currentClassAttr.substring( 0,  startIdx );
                                newClassAttr = newClassAttr + currentClassAttr.substring( startIdx + 7 );
                        }

                        if( browser.isIE ) {
                                row.className = newClassAttr;
                        }
                        else
                        {
                                row.setAttribute( "class", newClassAttr );
                        }

		}
	}

	var link1 = document.getElementById( "toggleLinkLow" );
	var link2 = document.getElementById( "toggleLinkHigh" );

	if( linkToActivate == 1 ) {
		link1.style.display = "";
		link2.style.display = "none";
	}
	else
	{
                link2.style.display = "";
                link1.style.display = "none";
	}

}


function show(elementId) {
	document.getElementById(elementId).style.display="block";
}

function showInline(elementId) {
	document.getElementById(elementId).style.display="inline";
}

function hide(elementId) {
	document.getElementById(elementId).style.display="none";
}


/*****************************************
 Function: toggleNews
 Description: for toggling between news tabs
 Input Params: n/a
 Return Value: n/a
******************************************/
function toggleNews( tabNumber )
{
	if( tabNumber < 0 )
	{
		return;
	}

	var newsDiv = document.getElementById( "newsBox" );
   	var navList = newsDiv.getElementsByTagName( "LI" );

	if( tabNumber >= navList.length )
	{
		return;
	}

	for( var i = 0; i < navList.length; i++ )
	{
		var tab = navList.item( i );

		if( i == tabNumber ) 
		{
			tab.setAttribute( "id", "currentTab" );						
		}
		else
		{
			tab.setAttribute( "id", "inactiveTab" );
		}
	}

}



/*****************************************
 Function: trim
 Description: Helper function to remove leading and trailing whitespace.
 Input Params: string
 Return Value: string with leading and trailing spaces removed.
******************************************/
function trim( str ){
   return str.replace(/^\s*|\s*$/g,"");
}





/*****************************************
 Function: clearQuoteForm
 Description: Iterate through the inputs for symbols and
              clear them
 Input Params: none
 Return Value: none
******************************************/
function clearQuoteForm( formName )
{
	if( !formName )
	{
		return;
	}

	var targForm = document.forms[formName];
	var targInputPrefix = "QuoteSymbol_";

	if( !targForm ) {
		return;
	}

	// Find an empty text field
	for( var i = 0; i < targForm.length; i++ ) {

		var input = targForm.elements[ i ];

		if( input.type == 'text' && input.name.indexOf( targInputPrefix ) == 0 ) {

			input.value = "";
		}
	}
}

/*****************************************
 Function: transferSymbol
 Description: Put the given symbol into the given form.
              Iterates through TEXT form elements to find an
              empty or whitespace value.
 Input Params: string symbol
 Return Value: none
******************************************/
function transferSymbol( symbol )
{	
	// This function is used in two places
	// so look for two different target forms,
	// and as a last resort, the "quick quote" form.

	var targForm = window.opener.document.forms["quotelookupQ"];
	var targInputPrefix = "QuoteSymbol_";

	if( !targForm ) {
		targForm = window.opener.document.forms["quoteLookUp"];
		targInputPrefix = "Symbol_";
	}

	if( !targForm ) {
		targForm = window.opener.document.forms["insidertradesearch"];
		targInputPrefix = "QuerySymbol";
	}
	
	if( !targForm ) {
		return;
	}

	// Find an empty text field
	for( var i = 0; i < targForm.length; i++ ) {

		var input = targForm.elements[ i ];

		if( input.type == "text" && input.name.indexOf( targInputPrefix ) == 0 ) {

			if( input.value.length == 0 || trim( input.value ).length == 0 ) {
				input.value = symbol;
				break;
			} else if( input.value == symbol ) {
				break; // Don't allow repeated symbols
			}	
		}
	}
}


/*****************************************
 Function: quickQuoteTransferSymbol
 Description: Put the given symbol into  the quick quote input.
 Input Params: string symbol
 Return Value: none
******************************************/
function quickQuoteTransferSymbol( symbol )
{	
	var targForm = window.opener.document.forms["quickQuote"];
		
	if( !targForm ) {
		return;
	}

	var input = targForm.elements[ "QuoteSymbol_1" ];

	if( !input ) {
		return;
	} 

	input.value = symbol;

	return;
}




/*****************************************
 Function: tickerTransferSymbol
 Description: Put the given symbol into form 'symbols' textarea.
 Input Params: string symbol
 Return Value: none
******************************************/


function tickerTransferSymbol( symbol )
{	
	var targForm = window.opener.document.forms["ticker"];
	
	if( !targForm ) {
		return;
	}

	var input = targForm.elements[ "symbols" ];

	if( !input ) {
		return;
	} 

	input.value += symbol + ",";

}



/*****************************************
 Function: startTicker
 Description: launches the java ticker
 Input Params: url
 Return Value: none
******************************************/
function startTicker(url) {
if (url){
tickerString="/HttpController?GetPage=CustomizedTicker&symbols=" + escape(url)
newWin = window.open(tickerString,"tickerWin","toolbar=0,location=0,width=680,height=159,left=30,top=30,resizable=0");
}else{
newWin = window.open('',"tickerWin","toolbar=0,location=0,width=680,height=159,left=30,top=30,resizable=0");
document.ticker.submit();
}
}


/*****************************************
 Function: confirmSubmit(msg)
 Description: prompts the user to confirm a message before proceeding
 Input Params: message
 Return Value: true if agreed, false if cancel
******************************************/
function confirmSubmit(msg)
{
	return confirm(msg);
}

function confirmSubmitEdit(msg1, fieldName, msg2)
{
	var newMsg = msg1 + eval(fieldName + ".value") + " ."  + msg2;

	return confirm(newMsg);
}

function confirmSubmitListView(msg1, msg2)
{
	var sStockList;
	var iList;

	// Try to lookup the list name.
	var tab = document.getElementById( "currentTab" );
	if( tab ) {
		sStockList = tab.getElementsByTagName( "A" ).item( 0 ).firstChild.nodeValue;
	
	}

	if( !sStockList ) {
		return false;
	}
	return confirm( msg1 + sStockList + " ."  + msg2 );
}


function signOnGo() {
	var iTempSelectedIndex = document.getElementById('signOnForm').elements['signOnSelect'].selectedIndex;
	location.href = document.getElementById('signOnForm').elements['signOnSelect'].options[iTempSelectedIndex].value;
}


function lastModified() {
	lastmod = document.lastModified; // get string of last modified date 
	lastmoddate = Date.parse(lastmod); // convert modified string to date 
	if(lastmoddate == 0) 
	{ 
	// unknown date (or January 1,// 1970 GMT) 
	document.write('<p class="lastUpdated">Dernière mise à jour : Unknown</p>'); 
	} 
	else 
	{ 
	oDate = new Date(lastmod); 
	
	var enArray = new Array(12); 
	
	enArray[0] = "janvier"; 
	enArray[1] = "f&eacute;vrier"; 
	enArray[2] = "mars"; 
	enArray[3] = "avril"; 
	enArray[4] = "mai"; 
	enArray[5] = "juin"; 
	enArray[6] = "juillet"; 
	enArray[7] = "ao&ucirc;t"; 
	enArray[8] = "septembre"; 
	enArray[9] = "octobre"; 
	enArray[10] = "novembre"; 
	enArray[11] = "d&eacute;cembre"; 
	
	var nYear = oDate.getFullYear(); 
	var sYear = nYear.toString(); 
	var sLastTwo = sYear.substr(2,2); 
	
	//a way to convert a string to number 
	var nLastTwo = sLastTwo - 0; 
	var nCorrectYear = nLastTwo + 2000; 
	
	lastFormattedDate = oDate.getDate() + " " + enArray[oDate.getMonth()] + " " + nCorrectYear .toString(); 
	document.write('<p class="lastUpdated">Dernière mise à jour : ' + lastFormattedDate + '</p>'); 
	}	
}


/*****************************************
 Function: clearDefault
 Description: Clear the default text in the 
              Quick Quote  form so it doesn't get submitted.
 Input Params: none
 Return Value: none
******************************************/
function clearDefault()
{	
	var targForm = document.forms[ "quickQuote" ];
		
	if( !targForm ) {
		return;
	}

	var input = targForm.elements[ "QuoteSymbol_1" ];

	if( !input ) {
		return;
	} 

	if( input.value == "Entrez symbole" ) {
		input.value = "";
	}
	
}

function popupDisclaimer()
{
	var msg = "Vous êtes sur le point de quitter le site tmx.com. ";
	msg += "Nous ne sommes pas responsables du contenu du site Web ";
	msg += "sur le point de visiter. SEDAR est le Système Électronique ";
	msg += "de Données, d'Analyse et de Recherche, un système de dépôt ";
	msg += "électronique pour le dépôt des documents des sociétés ";
	msg += "publiques et des fonds communs du Canada. Veuillez prendre ";
	msg += "note que les documents suivants ne reflètent pas la nouvelle ";
	msg += "politique comptable de Groupe TSX; les états financiers ";
	msg += "déposés précédemment et les commentaires de la direction ";
	msg += "correspondants pour l’année se terminant le 31 décembre 2004 ";
	msg += "(comprenant les points saillants financiers, les états ";
	msg += "financiers et les commentaires correspondants contenus ";
	msg += "dans le rapport annuel 2004); les états financiers et ";
	msg += "les commentaires correspondants pour le premier, deuxième ";
	msg += "et troisième trimestres de 2004 ainsi que le premier et ";
	msg += "deuxième trimestres de 2005 et la notice annuelle datée "
	msg += "du 24 mars 2005. Pour le premier et deuxième trimestres de ";
	msg += "2005, veuillez consulter les états financiers redressés et "
	msg += "vérifiés de 2004 et les commentaires révisés, les états ";
	msg += "financiers intermédiaires redressés et les commentaires "
	msg += "révisés correspondants. Pour consulter les documents ";
	msg += "publics de Groupe TSX inc. déposés auprès des organismes ";
	msg += "de réglementation canadiens, cliquez sur OK. Pour retourner ";
	msg += "vers tmx.com, cliquez sur Annuler.";
		
	return confirm( msg );
}

/*****************************************
 Function: loginNav
 Description: Take the user to apage, depending on the selected value.
 Input Params: Selected value
 Return Value: none
******************************************/
function loginNav( navSelect )
{
        var openNewWidow = false;
        var url;

        if( navSelect.selectedIndex == 1 )
        {
                url = "/HttpController?GetPage=StocklistViewPage&Language=fr";
        }
        else if( navSelect.selectedIndex == 2 )
        {
                openNewWidow = true;
                url = "http://secure.tsx.com/tsxsecurefile";
        }
        else if( navSelect.selectedIndex == 3 )
        {
                url = "https://secure.tsx.com/IRWeb/IRWebHttpController?SaveView=true&GetPage=LoginPage";
        }
        else if( navSelect.selectedIndex == 4 )
        {
                openNewWidow = true;
                url = "http://www.tsxdatalinx.com";
        }
        else
        {
                return;
        }

        if( openNewWidow )
        {
                mywin = window.open( url );
                mywin.focus();
        }
        else
        {
                location.href = url;
        }

}


/*****************************************
 Function: closeAndRefresh
 Description: Reload the parent window, if any, and close the current window.              
 Input Params: none
 Return Value: none
******************************************/
function closeAndRefresh()
{
	if( window.opener.document )
	{
		window.opener.document.location.reload();
	}
	
	window.close();
}


/*****************************************
 Variables: RandomNumber
 Description: Generates a random number on each refresh, used in creating a new URL to force refresh of charts and pages              
 Input Params: none
 Return Value: none
******************************************/
	RanNum = new String (Math.random()); 
	ranNumSub = RanNum.substring (2, 8);

