// preload images
  var aryImages = new Array(12);
  aryImages[0] = "/images/shim.gif";
  aryImages[1] = "/images/shim_2c54d6.gif";
  aryImages[2] = "/images/shim_000000.gif";
  aryImages[3] = "/images/shim_0033CC.gif";
  aryImages[4] = "/images/shim_333333.gif";
  aryImages[5] = "/images/shim_999999.gif";
  aryImages[6] = "/images/shim_b5c7de.gif";
  aryImages[7] = "/images/shim_b5c7ed.gif";
  aryImages[8] = "/images/shim_bbbbbb.gif";
  aryImages[9] = "/images/shim_cccccc.gif";
  aryImages[10] = "/images/shim_f6f6ea.gif";
  aryImages[11] = "/images/sm_pro_logo.gif";
  
  for (i=0; i < aryImages.length; i++) {
    var preload = new Image();
    preload.src = aryImages[i];
  }


//  End -->

   /* This Function inserts a text field of approximately equal visual length in NN and IE
      since NN and IE interpret length differently */
function insertTextField(len, max, name, currval, style) {
	if (style=="" || style==null) style="text";

//len should be equal to the IE length needed. It will be equated for NN.
	if (len<=10) if (browserName=='Netscape') Math.round(len=len/2);
	if (len>10) if (browserName=='Netscape') Math.round(len=len/1.3);
	document.write('<input type="text" name="' + name + '" size="' + len + '" maxlength="' + max + '" value="' + currval + '" class="' + style + '">');
}


   /* This Function does the same thing, using the class smallprompt */
function insertSmTextField(len, max, name, currval, style) {
	if (style=="" || style==null) style="smallprompt";

//len should be equal to the IE length needed. It will be equated for NN.
	if (len<=10) if (browserName=='Netscape') Math.round(len=len/2);
	if (len>10) if (browserName=='Netscape') Math.round(len=len/1.3);
	document.write('<input type="text" name="' + name + '" size="' + len + '" maxlength="' + max + '" value="' + currval + '" class="' + style + '">');
}


   /* Same thing as the first, but using the focus element -- specific to research toolbar */
function insertTextFieldFocus(len, max, name, currval, style) {
	if (style == "" || style == null) style="smallprompt";

//len should be equal to the IE length needed. It will be equated for NN.
	if (len<=10) if (browserName=='Netscape') Math.round(len=len/2);
	if (len>10) if (browserName=='Netscape') Math.round(len=len/1.3);
	document.write('<input type="text" name="' + name + '" size="' + len + '" maxlength="' + max + '" value="' + currval + '" onfocus="getresearch.foc.value=\'' + name + '\';" class="' + style + '">');
}


/* This function activates selector drop-downs for navigation */
function jumpto(s)
	{	var where = s.options[s.selectedIndex].value;
		if (s.selectedIndex == 3)
			top.location.href = where;
		else
			location.href = where;
	}


//THIS popup window is to show All industry list.
function popUp(countryListID) {
 	var url = '/analysts/industry_full_list.phtml?country_list_id=' + countryListID;
	window.open(url,'Popup','width=660,height=400,scrollbars=no,resizable');
} // end function
	
function popUp_window(link, width, height, scrollbars, name) {
	newWindow = window.open((link),(name),'width='+width+',height='+height+',scrollbars='+scrollbars+',resizable');
	newWindow.focus();
}

function help_window(host, link, width, height, scrollbars, name) {
	newWindow = window.open((host + '/help/' + link),(name),'width='+width+',height='+height+',scrollbars='+scrollbars+',resizable');
	newWindow.focus();
}

//THIS FUNCTION CONSOLIDATES THE WINDOW.OPEN COMMAND SO YOU ONLY NEED TO GIVE IT THE LINK
function showChart(link) {
	window.open( link, 'StarStationChart','width=678,height=640,scrollbars=no');
} // end function


function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

/* Functions that swaps images. */
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

// open a new window for reuters.com
function open_reuters(ric) {
  var win = window.open('http://www.reuters.com/finance/stocks/overview?symbol='+ric, 'reutersMain');
  win.focus();
}

function CCBN_Help(link) {
window.close;
var win = window.open( (link),'Help','width=650,height=225,scrollbars=yes,resizable');
win.focus();
} // end function

//The function below is open a new window for US MSN MONEY CANADA
function contact(link, height) {
var win = window.open( (link),'Contact','width=390,height='+height+',scrollbars=yes,resizable');
win.focus();
}

function fc_window(link){
var win = window.open((link),'FC','width=668,height=690,scrollbars=yes,resizable'); 
win.focus();
}

function client_support_window(link){
  var win = window.open(link,'Contact','width=700,height=600,scrollbars=yes,resizable'); 
  win.focus();
}


// The 3 functions below are use for partners only: GoToPage(), GoToTrial(), GoBack().
function GoToPage(page_set)
	{
		document.location = "/linkback/partners.phtml?page_set="+page_set;
	}

function GoToTrial()
	{
		document.free_trial.submit();
		// will possibly change if Free Trial page moves to a GET
	}

function GoBack()
	{
		 history.back();
		 // in future, allows us to deal with going back to a POST-ed page (by re-POSTing)
		 // if we track which page we are on
	}

//this function is to hightlight the entire row when user place the mouse over the row.	
function changeBG(row_id, bgColor){
	row_id.bgColor = bgColor;
}

//+-+-+-+-+-+-+-+-+-+-+-+-+for highlight row+-+-+-+-+-+-+-+-+-+-+-+-+//
var preEl ;
var orgBColor;
function HighLightTR(highlightColor){  

	if(typeof(preEl)!='undefined') {
		preEl.bgColor=orgBColor;
	} 
	var el = event.srcElement;
	el = el.parentElement;
	el = el.parentElement;
	orgBColor = el.bgColor;
	el.bgColor=highlightColor;
	preEl = el; 
}

//+-+-+-+-+-+-+-+-+-+-+-+-+End of highlight row+-+-+-+-+-+-+-+-+-+-+-+-+//	


//these 2 functions is to show bigger chart on the Ticker Summary page.
function showBigChart(current, category, text, object_name, chart_height){

  hideImage_Current();

 	obj = document.all.item(object_name);
	obj.innerHTML=text;
	var X,Y;

  if (category == 'chart'){
    chart_height += 20;    
    if  ( document.body.clientHeight - event.clientY > chart_height ){ //show under 
      Y = document.body.scrollTop + event.clientY + 20;
      X = event.clientX - 560 < 10 ? 10 :  event.clientX - 560 ;
    }else if ( event.clientY > chart_height ){ //show above
      Y = document.body.scrollTop + event.clientY - chart_height;
      X = event.clientX - 600 < 10 ? 10 :  event.clientX - 600 ;
    } else if ( event.clientX > 600 ){ //show on left
      X = 10 ;
      Y = document.body.scrollTop + event.clientY - 100 ;
    } else { //show under with some part invisible
      X = 10;
      Y =  document.body.scrollTop + event.clientY + 20;
    }   
  } else if (category == 'big_piv_chart') {
    X = 400;
    Y = document.getElementById('gv_c').offsetTop + 160;
  } else{//eps and revenue chart
	  if (category == 'y2') {
		  X = event.clientX+document.body.scrollLeft-410;
		} else {
		  X = event.clientX+document.body.scrollLeft+70;
		}
    if (X < 7) {
      X = 7;
    }
    Y = event.clientY + document.body.scrollTop-75;
  }

 	obj.style.pixelLeft=X;
  obj.style.pixelTop=Y;
  obj.style.visibility="visible";
  currentView_object_name = object_name;
}

function hideBigChart(object_name){
    document.all.item(object_name).style.visibility="hidden";
}


var currentView_object_name = null;
var iframe_img_shim_id = 'iframe_img_shim';
function imageView(text, object_name, pixelTop, pixelLeft){

  var obj = document.all.item(object_name);
  var img = document.createElement(text);  

  // wait for image to load so we know the correct height and width,
  // then create an iframe 'shim' underneath it to cover any SELECT
  // elements that would otherwise show through in IE6
  img.onload = function() {
    var iframe = document.createElement('iframe');
    iframe.id = iframe_img_shim_id;
    iframe.src = "javascript:false";
    iframe.style.position = 'absolute';
    iframe.style.pixelLeft = pixelLeft;
    iframe.style.pixelTop = pixelTop;
    iframe.style.width = img.offsetWidth;
    iframe.style.height = img.offsetHeight;
    iframe.style.zIndex = 5000;
    document.body.appendChild(iframe);
    obj.style.visibility="visible";  // this must be in onload function otherwise selects will flash above image then go away
  }
  obj.appendChild(img);

 	obj.style.pixelLeft=pixelLeft;
  obj.style.pixelTop=pixelTop;
  obj.style.zIndex = 9999;
  obj.style.border='1px solid black';

	currentView_object_name = object_name;

}

function hideImage(object_name){
  var obj = document.all.item(object_name);
  if (obj.children.length) {
    obj.removeChild(obj.firstChild);
  }
  obj.style.visibility = 'hidden';

  var iframe = document.getElementById(iframe_img_shim_id);
  if (iframe) {
    document.body.removeChild(iframe);
  }
}

function hideImage_Current() {
  if (currentView_object_name != null) {
    hideImage(currentView_object_name);
  }	
}


function set_content_to_waiting() {
  if (window.parent.content != null) {
    if (window.parent.content.document != null) {
      if (window.parent.content.document.body != null) {
	if (window.parent.content.document.body.style != null) {
	  if (window.parent.content.document.body.style.cursor != null) {
	    window.parent.content.document.body.style.cursor='wait';
	  }
	}
      }
    }
  }
}

function open_header_field_selector(){
  var url = "/header_field_selector.phtml";
  var width = 750;
  var height = 350;
  var allow_scroll = 'yes';
  var allow_resize = 'yes';
 
  var parameters = "width=" + width + ",height=" + height + ",status=no,scrollbars=" + allow_scroll + ",resizable=" + allow_resize;
  d_win = window.open(url, 'header_field_selector', parameters, true);
  d_win.focus();
  window.onunload=cleanup;
  window.onfocus=popcheck;
}

// Used by the report_generator_table class but 
// also gets invoked when ticker lookup fails and default page is printpack
function check_bad_ticker () {
  var bad_ticker_signal = document.getElementById('bad_ticker_signal');

  if (bad_ticker_signal) {
    var bad_ticker_signal_child = bad_ticker_signal.firstChild.nodeValue;

    if (bad_ticker_signal_child == '1') {
      alert(document.getElementById('bad_ticker_message').firstChild.nodeValue);
    }
  }

  return true;
}

function reset_ticker_input(){
  obj = document.getTicker.ticker;
	
  if (typeof(obj) != "undefined"){
    obj.value = obj.value;
  }
}

// allow tab characters in textarea
function allow_tab_character() {
  if (event != null && event.srcElement && event.srcElement.value && event.keyCode == 9) {
    if (document.selection != null) {
      document.selection.createRange().text = '\t';
      event.returnValue = false;
    } else {
      event.srcElement.value += '\t';
      return false;
    }
  }
}

function SetCookie(cookieName,cookieValue,nDays) {
  var today = new Date();
  var expire = new Date();
  if (nDays==null || nDays==0) nDays=1;
  expire.setTime(today.getTime() + 3600000*24*nDays);

  if(document.cookie){
    document.cookie = cookieName+"="+escape(cookieValue)+";domain=.starmine.com"+";expires="+expire.toGMTString();
  }
}

var d_win = null;

function popcheck() {
  if(d_win != null){
    if (!d_win.closed) {
      d_win.focus();
    } else {
      d_win = null;
    }
  }
}

function close_popup() {
  if ((d_win != null) && (!d_win.closed)) {
    d_win.set_opener_controls();
  }
  cleanup();
}

function cleanup() {
  if ((d_win != null) && (!d_win.closed)) {
    d_win.close();
  }
  d_win = null;
}
