// Goes to a specific URL.
function goTo(elem)
{
  var frm = document.getElementById("howHelpForm");
  var url = frm.howHelp.options[frm.howHelp.selectedIndex].value;
  window.location = url;
}

//Reset forms, used when the CLEAR button is hit
function resetForm(formName)
{

  var theForm = document.getElementById(formName);
  theForm.reset();
}

// Opens a new window
function openVideo()
{
  window.open('http://bayview.ichameleongroup.com/presentation.html','video','scrollbars=no,menubar=no,height=485,width=772,resizable=no,toolbar=no,location=no,status=no');
}

// Opens a new window
function openCalc()
{
  window.open('./documents/downloads/1031calculator.jsp','Calc','scrollbars=no,menubar=no,height=780,width=800,resizable=no,toolbar=no,location=no,status=no');
}

// Opens a new window
function openemail()
{
  window.open('./content/body/emailsample.jsp','email','scrollbars=yes,menubar=no,height=700,width=450,resizable=no,toolbar=no,location=no,status=no');
}

// Opens a new window
function openbbuilders()
{
  window.open('http://www.121customsite2.com/entry/getinfo.asp','bbuilders','scrollbars=yes,menubar=no,height=600,width=1000,resizable=yes,toolbar=no,location=no,status=yes');
}

// Opens a new window
function openbbuilders2()
{
  window.open('http://www.121customsite2.com/login.asp','bbuilders2','scrollbars=yes,menubar=no,height=600,width=1000,resizable=yes,toolbar=no,location=no,status=yes');
}


// Opens a new window
function openbenefits()
{
  window.open('./content/body/partnerbenefitsbody.jsp','benefits','scrollbars=yes,menubar=no,height=290,width=450,resizable=no,toolbar=no,location=no,status=no');
}

// Opens a new window
function openfaq()
{
  window.open('./content/body/partnerfaq.jsp','faq','scrollbars=yes,menubar=no,height=300,width=450,resizable=no,toolbar=no,location=no,status=no');
}

// Opens a new browser window anchored to the appropriate glossary word, 
// based on an input URL of this form:
//	'./index.jsp?pageId=glossary#capitalgain'
// Example usage (with a tooltip):
//	<a href="javascript:openGlossaryDefWindow('./index.jsp?pageId=glossary#capitalgain');"><span title= " ...tooltip text... " class="tooltip">capital gains</span></a>
function openGlossaryDefWindow( url )
{
	window.open(url, "", "height=400,width=800,toolbar=0,menubar=0,location=0,resizable=1,scrollbars=1,dependent=0,status=0,left=25,top=25");
}

//Opens the default media player to play a MP3 file
// Params: SongURL (String -- beware, case sensitive!)
// Usage examples:
//  <a href="javascript: playAudioFile('fugue.mp3')">Bach: Fugue in D Minor </a><br />
//  <a href="javascript: playAudioFile('./audio/mp3/1031_Basics_From_Bayview_Financial-01.mp3')">1031 Exchange Basics </a><br />
function playAudioFile(SongURL) { 
	window.open (SongURL, "Player", "toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizeable=no,copyhistory=no,width=200,height=30"); 
}

// Removes leading whitespaces
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) {
	return LTrim(RTrim(value));
}

//inserts a dash if the number does not have it
//format 10-1234
function insertExchangeDash(value){
  var exchangeNo = trim(value);
  exchangeNo = exchangeNo.replace(/-/ig,'');
  exchangeNo = exchangeNo.replace(/[a-z]/ig,'');
    exchangeNo = exchangeNo.replace(/#/ig,'');
  exchangeNo = exchangeNo.replace(/'.'/g,'');
  if(exchangeNo.length > 3){
  	if(exchangeNo.indexOf('-') == -1){
  	   exchangeNo = exchangeNo.substring(0,2) + "-" + exchangeNo.substring(2, exchangeNo.length);
	}
  }
  return exchangeNo;
}

function removeEX(exchangeNo){
	var cleanExchangeNo = exchangeNo;
	cleanExchangeNo = cleanExchangeNo.toUpperCase();
	//Makes sures that there is no EX or EX. strings
	if(cleanExchangeNo.indexOf('EX.') > -1){
	  cleanExchangeNo = cleanExchangeNo.substring(3, cleanExchangeNo.length);
	}
	if(cleanExchangeNo.indexOf('EX') > -1){
	  cleanExchangeNo = cleanExchangeNo.substring(2, cleanExchangeNo.length);
	}
	//does a second clean in case of a space
	cleanExchangeNo = trim(cleanExchangeNo);
	return cleanExchangeNo;
}
