// initialize variables
var hlight = "";

// template for bs logo in topnav
function writeLogo(){
	document.writeln('<a name="top"></a>');
	document.writeln('<table width="155" border="0" cellspacing="0" cellpadding="0">');
	document.writeln('  <tr> ');
	document.writeln('    <td width="11"><img src="http://www.bearstearns.com/bsportal/images/accntbar.gif" width="11" height="70"></td>');
	document.writeln('    <td><a href="http://www.bearstearns.com/"><img src="http://www.bearstearns.com/bsportal/images/logo_invert.gif" width="144" height="70" border="0"></a></td>');
	document.writeln('  </tr>');
	document.writeln('</table>');

}

// template for disclaimer
function writeDisclaimer(){
	document.writeln('<table width="595" cellpadding="0" cellspacing="0" border="0">');
	document.writeln('  <tr>');
	document.writeln('     <td align="center" height="30" valign="bottom" class="disclaimer"><font size="1"><br>© 2006 Bear, Stearns & Co. Inc. Published in the U.S.A. All rights reserved.'); 
	document.writeln('       This site and the content accessible herein are subject to certain <a href="javascript:openWindow(\'http://www.bearstearns.com/bear/bsportal/common/DisclaimerContent.jsp\',\'disclaim\',\'width=640,height=400,scrollbars=yes,left=200,top=200\')"><span class="disclaimerlink">disclaimers</span></a> and <a href="javascript:openWindow(\'http://www.bearstearns.com/bear/bsportal/TermsAndConditions.do\',\'disclaim\',\'width=640,height=400,scrollbars=yes,left=200,top=200\')"><span class="disclaimerlink">Access Agreement</span></a>.');
	document.writeln('       See Bear Stearns\' <a href="javascript:openWindow(\'http://www.bearstearns.com/bear/bsportal/home/PrivacyPolicy.jsp\',\'disclaim\',\'width=640,height=400,scrollbars=yes,resizable=yes,left=200,top=200\')"><span class="disclaimerlink">Privacy Policy</span></a>.</font><br></td>');
	document.writeln('  </tr>');
	document.writeln('</table>');
}

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];}}
}

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_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
  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 openWindow(theURL,winName,features) { //v2.0
  win = window.open(theURL,winName,features)
  if (win) {win.focus();}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

var firstErrorArray = new Array();

// registration form functions
function resetErrorFields(arrayCheck) {
	// this will changes all fields if they were red back to white
	firstErrorArray = new Array();
	 for (i = 0; i < arrayCheck.length; i++) {
	 	divError(arrayCheck[i], 1);
 	}
}

function divError(divID, returnState) {
	// this function will change the field to a red color to show an error	
  if (document.getElementById(divID)) {
	if (returnState) {
		document.getElementById(divID).style.background = "#FFFFFF"
	} else {
		firstErrorArray.push(divID);
		document.getElementById(divID).style.background = "#FFCCFF"
	}
  }
}

function findPosY(obj) {
    var curtop = 0;
   if(!obj) {
	 return 0
   } else {
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
	if (curtop) {
   	 return curtop-50;
	} else {
	 return curtop;
	} 	
  }
}


function validateTypes(formValue, vType, alertMessage) {
  var validReturn = 1;
  if (formValue) {
   if (formValue != "") {
	if (vType == "email") {
		var emailExp=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");
		if(!emailExp.test(formValue)) {
	 		validReturn = 0;
		}
	} else if (vType == "number") {
		if(isNaN(formValue)){
			validReturn = 0;
		}
	} else if (vType == "zip") {
		// Check for correct zip code
		
		//sep = this.setArg( sep, "- " );
		//var regex = new RegExp( "^[0-9]{5}(|[" + sep.toPattern() + "][0-9]{4})?$" );

     	var reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
 		if(!reZip.test(formValue)) {
			validReturn = 0;
		}
	 }
    }	
  }
  
  if (alertMessage) {
	  if (!validReturn) {
	  	alert(alertMessage);
	  }
  } else {
  	return validReturn;
  }
}