var MM_submitted = false;

function MM_preloadImages() { //v3.0
  if (!MM_submitted) {
    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];}}
  }
  return true;
}

function MM_swapImgRestore() { //v3.0
  if (!MM_submitted) {
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  }
  return true;
}

function MM_findObj(n, d) { //v4.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);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  if (!MM_submitted) {
    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];}
  }
  return true;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

function goMenu(targ,selObj,restore){ //v3.0
  if ( selObj.selectedIndex == 0 || selObj.selectedIndex == 1){
		return false;
	} else {
		//eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
		eval(selObj.options[selObj.selectedIndex].value);
	}
  if (restore) selObj.selectedIndex=0;
}

function popUp(url)
{
  window.open( url,"",
   "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=650,height=550,left=250,top=100");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// for generic open window usage
function openWindow(theURL,winName,features) { //v2.0
  win = window.open(theURL,winName,features)
  if (win) {win.focus();}
}

// used in the select tag
function openBrWindow(theURL,winName,features) { //v2.0
  openPDFWin('',winName,'',document.formselect.select[document.formselect.select.selectedIndex].value);
}

// use this javascript function if you need to load a pdf file into a new window
// your href should look like this:  <a href="javascript:openWin('', 'pdfWin', '', '/bscportal/pdfs/yourpdffile.pdf')">
function openPDFWin(theURL,winName,features,theURL2){
	features = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=500';
	var newWin = window.open(theURL,winName,features);
	newWin.document.open("text/html", "replace");
	newWin.document.writeln("<html><head>");
	//newWin.document.writeln("<scr"+"ipt language='Javascript'>");
	//newWin.document.writeln("function openBastard(){");
	//newWin.document.writeln("document.location.replace('"+theURL2+"')");
	//newWin.document.writeln("}");
	//newWin.document.writeln("openBastard()\;");
	//newWin.document.writeln("</scr"+"ipt>");
	newWin.document.writeln("</head><body onLoad=\'document.location.replace(\""+theURL2+"\")\'>");
	newWin.document.writeln("</body></html>");
	newWin.document.close();
	newWin.focus();
}

function setSubmitted() {
  MM_submitted = true;
}

function openUrl(form,murlparams)
{
  var mbaseurl,strl;
  var len,chr;
  len =0;

  mbaseurl = form.BaseUrl.value;

  openUrlWithBase(mbaseurl, murlparams);

} 

function openUrlWithBase(mbaseurl,murlparams)
{
  var urlStr;
  var len,chr;
  len =0;

  urlStr = mbaseurl + murlparams;
  if ( mbaseurl.length > 0 )
  {
   len = mbaseurl.length -1;
   chr = mbaseurl.charAt(len);
   if ( chr != '&' ) {
     urlStr = mbaseurl + '&' + murlparams;
   }
 }
 openPDFWin('','pdf','scrollbars=yes,resizable=yes,width=400,height=600', urlStr);
} 

function writeTopnav(topnavname, subnavname){
	tL = topnavarr.length;
	var abslink = "";
	
	if (topnavname == "Press Releases") abslink = "/bearstearns/aboutbearstearns/";  // handle press releases separtely to handle subsubdir
	if (hlight == "institutions") abslink = "/bearstearns/institutions/";  // correct redirect; when topnav is Institutions, Merchant Banking on bearstearns.com a redirect to the ROOT of www.bsmb.com/ is in place
	
	if (subdir) abslink = "../";	// subdir passed from CF app to correct href call from a sub directory
//	document.writeln("topnavname="+topnavname+" topnavarr.length="+topnavarr.length+" subnavname="+subnavname);
	document.writeln('<table border="0" cellspacing="0" cellpadding="0">');
	document.writeln('  <tr>');
	if (topnavarr){
		for (i=0; i < tL; i++){
			if (topnavarr[i] == topnavname){
				document.writeln('    <td nowrap bgcolor="#cccccc" height="10">&nbsp;&nbsp;<a href="'+ abslink + topnavarrlink[i] +'"><span class="link-topnavactive">'+topnavarr[i]+'</span></a>&nbsp;&nbsp;</td>');
				document.writeln('    <td bgcolor="#ffffff" height="10" width="1"><img src="/bscportal/images/space_clear.gif" width="1" height="1"></td>');
			}else{
				document.writeln('    <td nowrap bgcolor="#000066" height="10">&nbsp;&nbsp;<a href="'+ abslink + topnavarrlink[i] +'"><span class="link-topnav">'+topnavarr[i]+'</span></a>&nbsp;&nbsp;</td>');
				document.writeln('    <td bgcolor="#ffffff" height="10" width="1"><img src="/bscportal/images/space_clear.gif" width="1" height="1"></td>');
			}
		}
	}
	document.writeln('  </tr>');
	document.writeln('</table>');
	document.writeln('<table width="595" border="0" cellspacing="0" cellpadding="0">');
	document.writeln('  <tr>');
	document.writeln('    <td bgcolor="#CCCCCC"><img src="/bscportal/images/spacer.gif" width="595" height="2"></td>');
	document.writeln('  </tr>');
	document.writeln('</table>');
	
	var leftsub = false;
	if (topnavname){
		
		topnavarrLength = topnavarr.length;  
		topchar = topnavarr.join().toLowerCase();
		topcharLength = topchar.length + (topnavarrLength*4);	// total character length of topnav array
		sposbeginchar = topchar.indexOf(topnavname.toLowerCase());
		sposbeginpx = 595*(sposbeginchar/100);
		sposendchar = topchar.indexOf(",", sposbeginchar+1);
		if (sposendchar == -1){
			sposendchar = topcharLength;
		}else {
			sposendchar = topchar.indexOf(",", sposbeginchar+1);
		}
		sposendpx = 595*(sposendchar/100);
		smidchar = sposendchar - sposbeginchar;  // midpoint in characters
		smidpx = Math.round(sposbeginpx + ((sposendpx-sposbeginpx)/2));  // midpoint of selected tab from left
		
			
		if (subnavname){
			if (subnavarr != 0){
				subcharLength = subnavarr.join().length;
				subpxLength = Math.round(595 * (subcharLength/100)); 
				submidpx = Math.round(subpxLength/2)
				if ((submidpx + smidpx) > 595){
					subposbegin = smidpx-(submidpx+((submidpx + smidpx)-550))
				}else {
					subposbegin = Math.round(smidpx - submidpx);
				}
				
				//if ((subposbegin + subpxLength) > 595)subposbegin = (subposbegin + subpxLength) - 595;
				//alert(subposbegin + " "+subpxLength)
				if (subposbegin > 0)leftsub=true;
				
			}
			
		}
	}
	
//	if (subnavname != "" || subnavname != undefined){
	if (subnavname){
		
		
		if (leftsub == true)document.write('<img align="left" src="/bscportal/images/spacer.gif" width="'+subposbegin+'" height="2">');
		document.writeln('<table border="0" cellspacing="0" cellpadding="0">');
		document.writeln('  <tr>');
		// accomodate  Institutions, Merchant Banking on bearstearns.com to redirect to the ROOT of www.bsmb.com/
		if (topnavname == "Merchant Banking") abslink = "/bearstearns/institutions/";
		
		if (subnavarr.length > -1)sL = subnavarr.length;
		for (i=0; i < sL; i++){
			if (subnavarr[i] == subnavname){
				
				document.writeln('    <td nowrap bgcolor="#cccccc" height="10">&nbsp;&nbsp;<a href="'+ abslink + subnavarrlink[i] +'"><span class="link-topnavactive">'+subnavarr[i]+'</span></a>&nbsp;&nbsp;</td>');
				document.writeln('    <td bgcolor="#ffffff" height="10" width="1"><img src="/bscportal/images/space_clear.gif" width="1" height="1"></td>');
			}else{
				document.writeln('    <td nowrap bgcolor="#000066" height="10">&nbsp;&nbsp;<a href="'+ abslink + subnavarrlink[i] +'"><span class="link-topnav">'+subnavarr[i]+'</span></a>&nbsp;&nbsp;</td>');
				document.writeln('    <td bgcolor="#ffffff" height="10" width="1"><img src="/bscportal/images/space_clear.gif" width="1" height="1"></td>');
			}
		}
		document.writeln('  </tr>');
		document.writeln('</table>');

	}
	
}