// SET NAMESPACE
// ---------------------------------------------------------------------------

var BOFA = new Object;

// TOGGLE SEARCH PROMPT
// ---------------------------------------------------------------------------

var showSearchPrompt = true;
var resultMapIconClicked = false;

// ONLOAD BEHAVIOR
// ---------------------------------------------------------------------------

LigeoAPI.addOnLoad(function(){ // alert('addOnLoad()');
	
	if (doesInowCookieExist("feedback")){
		var feedbackObj = document.getElementById('toolbarFeedback');
		if (LigeoVarUtils.isNotNullOrEmpty(feedbackObj)){
			feedbackObj.style.visibility="hidden";
		}
	} 

	initHandlerResult ();
    
	if (typeof LigeoAPI != "undefined") {
	   //set custom balloon style
		LigeoAPI.setCustomBalloonStyle("CUSTOM1");
	}

	if( (typeof isWidgetSearch != "undefined") && LigeoVarUtils.isNotNull(isWidgetSearch) && !isWidgetSearch) {
		showPrompt();
	}
	
	LigeoFeaturesAPI.setSingleLineAsync(true);
	
	// Initialize sidebar
	BOFA.sb = new SideBar();
	
	var myInput = document.getElementById('locationText');
	if(LigeoVarUtils.isNotNullOrEmpty(myInput) &&  myInput.type=='text' && myInput.title!=''){
		myInput.onblur=function(){blurInput(this);}
	}
	
	if ((typeof isWidgetSearch != "undefined") && LigeoVarUtils.isNotNullOrEmpty(isWidgetSearch) && isWidgetSearch){
		document.getElementById('modal-window').style.display='block';
		var myResultsLink = document.getElementById('resultsLink');
		var myForm = document.getElementById('searchForm');
		var myElement = document.getElementById('resultsBlock');
		myResultsLink.className = 'toggleFeaturesClosed';
		myForm.fullAddress.value = widgetInput;
		LigeoAddressParser.parseAddress(myForm, myElement);
		isWidgetSearch = false;
	}
	
});






	
// ON FOCUS CHANGE ADDRESS INPUT
// ---------------------------------------------------------------------------

function focusInput(obj){
		if(obj.value==obj.title){
		obj.value='';
		obj.style.color='#333';
	}
}

// ON BLUR CHANGE ADDRESS INPUT
// ---------------------------------------------------------------------------

function blurInput(obj){
	if(obj.value==''){
				obj.value=obj.title;
		obj.style.color='#666';
	}else{
		obj.style.color='#333';
	}
}

// SHOW SEARCH PROMPT
// ---------------------------------------------------------------------------

function showPrompt(){//  alert('showPrompt()');
	if ( !showSearchPrompt ) {
		return;
	}
	
	var fixItTimeOut = setTimeout(function() {

		if( document.getElementById('prompt') ){ 
			document.getElementById('prompt').style.display='block';
		}
	}, 1);
}

// KILL SEARCH PROMPT
// ---------------------------------------------------------------------------

function killPrompt(){
	showSearchPrompt = false;
	if( document.getElementById('prompt') ){ 
		document.getElementById('prompt').style.display='none';
	}
}

// GET QUERY VARIABLE
// ---------------------------------------------------------------------------

function getQueryVariable(variable){
  var query=window.location.search.substring(1);
  var vars=query.split('&');
  for(var i=0;i<vars.length;i++){
    var pair=vars[i].split('=');
    if(pair[0]==variable){
    	// alert('getQueryVariable('+variable+') == "'+pair[1]+'"');
    	return pair[1];
    }
  }
}

// TOGGLE HEADER  THIS IS WHERE THE FIX FOR BOFA 1803 IS
// ---------------------------------------------------------------------------

function toggleHeader(obj)
{
	
	var locations = $('resultList').getElementsByTagName('li');
		
	for(var i=0; i<locations.length; i++)
	{
		if(locations[i] == $(obj))
        {   


            if(locations[i].hasClassName('open'))
            {
                Element.removeClassName(locations[i], 'open');
                Element.addClassName(locations[i], 'open');         
            } else {
                Element.removeClassName(locations[i], 'open');
                Element.addClassName(locations[i], 'open');
            }
         } else {
              Element.removeClassName(locations[i], 'open');
              Element.addClassName(locations[i], 'open');
		}
	}
	
}

// ICON BEHAVIOR
// ---------------------------------------------------------------------------

function overNumberIcon(num) {

	try{
		if($('resultImage'+num)) $('resultImage'+num).src = $('resultImage'+num).src.replace(/Off/g, 'On');
		if($('marker_'+num)) $('marker_'+num).src = $('marker_'+num).src.replace(/Off/g, 'On');

		var thatObj = document.getElementById('thisAddressHeader'+num); 
		var thatObj2 = document.getElementById('numberIconArea'+num);
		if (thatObj != null && thatObj != undefined) {
			thatObj.className = 'resultListMouseOver';
		}
		if (thatObj2 != null && thatObj2 != undefined) {
			thatObj2.style.background = '#DEF4FB';
		}
	} catch(err) {}
   
	return true;
}

function offNumberIcon(num) {

	try{
		if($('resultImage'+num)) $('resultImage'+num).src = $('resultImage'+num).src.replace(/On/g, 'Off');
		if($('marker_'+num)) $('marker_'+num).src = $('marker_'+num).src.replace(/On/g, 'Off');

		var thatObj = document.getElementById('thisAddressHeader'+num);
		var thatObj2 = document.getElementById('numberIconArea'+num); 
		if (thatObj != null && thatObj != undefined) {
			thatObj.className = 'resultListMouseOff'; 
			thatObj.style.color = '#333';
		}
		if (thatObj2 != null && thatObj2 != undefined) {
			thatObj2.style.background = '#FFF'; 
			thatObj2.style.color = '#333';
		}
	} catch(err) {}
	
	return true;
}

// TOGGLE VISIBILITY
// ---------------------------------------------------------------------------

function toggleObj(obj,thisObj,thatObjId){
	if(!(obj=$(obj))) return;
	if(!(thisObj=$(thisObj))) return;
	obj.className=(obj.className=='hide' ? 'show' : 'hide');
	thisObj.className=(thisObj.className=='toggleFeaturesClosed' ? 'toggleFeaturesOpen' : 'toggleFeaturesClosed');
	//new line added for title tag
	thisObj.title=(thisObj.className=='toggleFeaturesClosed' ? 'Expand to View Specific Features' : 'Collapse Specific Features');

 if(obj.id == "atmFeatures"){
     	$('atmFeaturesAdaAlt').alt=(thisObj.className=='toggleFeaturesClosed' ? 'Expand to View Specific Features' : 'Collapse Specific Features');
 }
 else if(obj.id == "bankingCenterFeatures"){
     	 $('bankingCenterFeaturesAdaAlt').alt=(thisObj.className=='toggleFeaturesClosed' ? 'Expand to View Specific Features' : 'Collapse Specific Features'); 
 }

	var thatObj = document.getElementById(thatObjId);
	if (typeof thatObj != "undefined" && thatObj != null) {
		thatObj.className=(thatObj.className=='toggleFeaturesClosed' ? 'toggleFeaturesOpen' : 'toggleFeaturesClosed');
	}
}

// TOGGLE SIDEBAR
// ---------------------------------------------------------------------------

var SideBar = function()
{

	/* Public methods */
	
	var _public = {
	
		load : function(panel)
		{
			switch(panel){
	
				case 'locate' :
					if($('locateLink').className == 'toggleFeaturesClosed')
					{
						this.toggleArrow('locateLink', true);					
						if ($('unitedStatesTab').className != 'selected'){
							this.toggleView(false,'locationsContent');
							this.toggleView(true,'internationalContent');
						} else {
							this.toggleView(true,'locationsContent');
							this.toggleView(false,'internationalContent');
							$('advancedSearchLink').className = 'toggleFeaturesOpen';
							$('adaAltAdv').alt = "Collapse Advanced Search";
							$('advancedSearchLink').title = "Collapse Advanced Search";	
						}
						this.toggleView(false,'resultsContent','resultsLink');
						this.toggleView(false,'directionsContent','directionsLink');
					} else {
						this.toggleArrow('locateLink', false);
						$('advancedSearchLink').className = 'toggleFeaturesClosed';
						$('adaAltAdv').alt = "Expand to View Advanced Search";
						$('advancedSearchLink').title = "Expand to View Advanced Search";						
						this.toggleView(false,'locationsContent');
						this.toggleView(false,'internationalContent');
					}
					_public.show('searchFields');
					break;
			
				case 'unitedStates' :
					_public.show('locationsContentAll');
					if ($('advancedSearchLink').className == 'toggleFeaturesOpen'){
						$('locateLink').className = 'toggleFeaturesOpen';
					} else {
						$('locateLink').className = 'toggleFeaturesClosed';
					}						
					this.toggleView(false,'internationalContent');
					if (isResults){
						$('resultsBlock').style.display = "block";
					}
					if (($('directionsHeader') != null && $('directionsHeader') != undefined)
							|| isRoute) {
						$('directionsBlock').style.display = "block";
					}
					break;
					
				case 'international' :
					_public.hide('locationsContentAll');
					$('locateLink').className = 'toggleFeaturesOpen';				
					this.toggleView(true,'internationalContent');
					$('resultsBlock').style.display = "none";
					$('directionsBlock').style.display = "none";
					break;
	
				case 'results' : 
					// initial page load
					if($('resultsLink').className == 'toggleFeaturesOpen' &&
							$('resultsBlock').style.display == "none") {
						$('advancedSearchLink').className = 'toggleFeaturesClosed';
						this.toggleView(true,'resultsContent','resultsLink');
						this.toggleView(false,'locationsContent','locateLink');
						this.toggleView(false,'internationalContent');
						this.toggleView(false,'directionsContent','directionsLink');
					// page refresh
					} else if($('resultsLink').className == 'toggleFeaturesOpen' &&
							$('resultsBlock').style.display == "block") {
						$('advancedSearchLink').className = 'toggleFeaturesClosed';
						this.toggleView(true,'resultsContent','resultsLink');
						this.toggleView(false,'locationsContent','locateLink');
						this.toggleView(false,'internationalContent');
						this.toggleView(false,'directionsContent','directionsLink');
					//Doing this incase adv search opened and then a grid search
					} else if($('advancedSearchLink').className == 'toggleFeaturesOpen') {
                        this.toggleArrow('locateLink', false);
                        $('advancedSearchLink').className = 'toggleFeaturesClosed';
                        $('adaAltAdv').alt = "Expand to View Advanced Search";
                        $('advancedSearchLink').title = "Expand to View Advanced Search";						
                        this.toggleView(false,'locationsContent');
                        this.toggleView(false,'internationalContent');
                    } 
                    else {		
						this.toggleView(false,'resultsContent','resultsLink');
					}
					$('resultsBlock').style.display = "block";
					break;
			
				case 'directions' :
					$('directionsBlock').style.display = "block";
					if(!$('directionsLink') || $('directionsLink').className == 'toggleFeaturesClosed')
					{
						_public.show('searchFields');
						if ( $('advancedSearchLink') ) {
							$('advancedSearchLink').className = 'toggleFeaturesClosed';
						}
						this.toggleView(true,'directionsContent','directionsLink');
						this.toggleView(false,'locationsContent','locateLink');
						this.toggleView(false,'internationalContent');
						this.toggleView(false,'resultsContent','resultsLink');
					} else {
						this.toggleView(false,'directionsContent','directionsLink');
					}
					LigeoAPI.closeBalloon();
					break;
			}
		}
			
		,toggleView : function(show,obj,link)
		{
			if(show)
			{
				_public.show(obj);
				if(link=$(link)) link.className = 'toggleFeaturesOpen';
			} else {
				_public.hide(obj);
				if(link=$(link)) link.className = 'toggleFeaturesClosed';
			}
		}
			
		,show : function(obj)
		{
			if(!(obj=$(obj))) return;
			obj.addClassName('show').removeClassName('hide');
		}
			
		,hide : function(obj)
		{
			if(!(obj=$(obj))) return;
			obj.addClassName('hide').removeClassName('show');
		}
		
		,toggleArrow : function(link,show)
		{
			
			if(link=$(link)) link.className = (show ? 'toggleFeaturesOpen' : 'toggleFeaturesClosed');
		}
	};

	/* Return public methods */

	return _public;
};


// FILTER RESULTS
// ---------------------------------------------------------------------------

function filterResults(locationTypeFilter, resultGroupNum){
    if (locationTypeFilter != null)
    {
        // Keep this around on the page for when the results content is refreshed
	    BOFA.locationTypeFilter = locationTypeFilter;
    }
    if (BOFA.locationTypeFilter == null || BOFA.locationTypeFilter == undefined)
    {
        return;
    }
    
    changeSelect(document.getElementById("searchFormFilter"), BOFA.locationTypeFilter);
    
    var firstResult = document.getElementById("thisResult" + resultGroupNum);
    if (firstResult != null && firstResult != undefined)
    {
	    var resultSet = firstResult.parentNode.getElementsByTagName('li');
	    for(var key=0; key<resultSet.length; key++){
	        var spanObj = document.getElementById("spanIdNum" + resultGroupNum);
	        var spanObjText = "";
	        if (spanObj != null){
	            spanObjText = spanObj.firstChild.data;
	        }
	       
	        var currResult = resultSet[key];
	        
	        if (BOFA.locationTypeFilter == "ALL"){
	            currResult.className = "open";//HERE IS WHERE BOFA-1803 WAS FIXED - USED TO BE CLOSED
	            LigeoAPI.showLocation(key);
	        } else if (spanObjText.indexOf(BOFA.locationTypeFilter) == -1){    	
	            currResult.className = "hideResult";
	            LigeoAPI.hideLocation(key);
	        } else if (currResult.className == "hideResult"){
	            currResult.className = "open";//HERE IS WHERE BOFA-1803 WAS FIXED - USED TO BE CLOSED
	            LigeoAPI.showLocation(key);
	        } 
	        resultGroupNum++;
	    }
	    
//	BOFA-918 
//	It is now written that the first result will now NEVER be open...leave this code here for when someone changes their mind
	    
	    //now set the first result that is not hidden to 'open'
//	    for(var key=0; key<resultSet.length; key++){
//	       
//	        var currResult = resultSet[key];
//	        
//	        if (currResult.className == "closed" || currResult.className == "open"){
//	            currResult.className = "open";
//	            break;
//	        }
//	    }
    }
    LigeoAPI.closeBalloon();
}

function changeSelect(selectElement, newValue)
{
    if (selectElement != undefined && selectElement != null)
    {
	    for (var i=0; i < selectElement.options.length; i++)
	    {
	        if (selectElement.options[i].value == newValue)
	        {
	            selectElement.options[i].selected = true;
	        }
	    }
    }
}

// TOGGLE TABS
// ---------------------------------------------------------------------------

function toggleTab(tab){
	tab.className='selected';

	for(var allTabs = tab.parentNode.getElementsByTagName('li'), i=allTabs.length-1; i>=0; i--){
		if(allTabs[i]!=tab){
			allTabs[i].className='none';
		}
	}
}

// TOGGLE DRILL MODAL TABS
// ---------------------------------------------------------------------------

function toggleModalTabs(obj){
	var tabs=obj.parentNode.getElementsByTagName('li');
	for(var x=tabs.length-1; x>=0; x--){
		if(obj==tabs[x]){
			tabs[x].className='selected';
			$('drill-nonmodal-block-'+(x+1)).className='modalShow';
		}else{
			tabs[x].className='off';
			$('drill-nonmodal-block-'+(x+1)).className='modalHide';
		}
	}
}


// TOGGLE DRILL TAB
// ---------------------------------------------------------------------------

function toggleDrillTab(isAtmOnly){

	if (isAtmOnly){
		var servicesContent = document.getElementById('drill-nonmodal-services');
		servicesContent.style.display = "";
	} else {	
		var hoursObj = document.getElementById('detailsHours');
		var servicesObj = document.getElementById('detailsServices');
		hoursObj.className=(hoursObj.className == 'selected' ? 'none' : 'selected');
		servicesObj.className=(servicesObj.className == 'selected' ? 'none' : 'selected');

		var hoursLink = document.getElementById('hoursLink');
		var servicesLink = document.getElementById('servicesLink');
		var hoursContent = document.getElementById('drill-nonmodal-hours');
		var servicesContent = document.getElementById('drill-nonmodal-services');
		if (hoursObj.className == 'selected'){
			hoursLink.onclick = function(){return false;};
			servicesLink.onclick = function(){toggleDrillTab();};
		} else {
			hoursLink.onclick = function(){toggleDrillTab();};
			servicesLink.onclick = function(){return false;};
		}
				
		var hoursContent = document.getElementById('drill-nonmodal-hours');
		var servicesContent = document.getElementById('drill-nonmodal-services');
		hoursContent.style.display = (hoursContent.style.display == 'none' ? '' : 'none');
		servicesContent.style.display = (servicesContent.style.display == 'none' ? '' : 'none');
	}
}

// CHECK/UNCHECK 
// ---------------------------------------------------------------------------

function checkAll(obj){
	var parent=obj.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('input')[0];
	var siblings=obj.parentNode.parentNode.parentNode.getElementsByTagName('input');
	if(obj.checked){
		parent.checked=true;
		for(var x=siblings.length-1; x>=0; x--){
			if(obj!=siblings[x]) siblings[x].checked=false;
		}
	}
}

// TOGGLE ALL
// ---------------------------------------------------------------------------

function toggleAll(obj,children){
		for(var x=children.length-1; x>=0; x--) children[x].checked=false;
	if(obj.checked){
		children[0].checked=true;
	}
}

// UNCHECK "ALL FEATURES/TYPES"
// ---------------------------------------------------------------------------

function uncheck(obj){
	var parent=obj.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('input')[0];
	if(obj.checked) parent.checked=true;
	obj.parentNode.parentNode.parentNode.getElementsByTagName('input')[0].checked=false;
}

function onEventProc(aEvent)
{
  var win = aEvent.currentTarget;
  var top_doc = win.frames[0].document;
  var cur_doc = aEvent.target;
  if (top_doc == cur_doc)
    alert("load complete");
} 

function showEmail(){
	$('email-nonmodal-window').style.display='block';
	var emailForm = document.getElementById("sendToFriend");
	emailForm.yourName.value="";
	emailForm.yourEmail.value="";
	emailForm.emailAddresses.value="";
	emailForm.message.value="";
	emailForm.copyYourself.checked="";
	var emailConfirmDiv = document.getElementById("emailConfirm");
	if (LigeoVarUtils.isNotNull(emailConfirmDiv)){
		emailConfirmDiv.style.display='none';
	}
}

function printIt(urlHost){
	
	var zoomLevel;
	var currLat;
	var currLon;
    var type;
	var page;

    var veMap;

    if(LigeoAPI.getLigeoMap().myId == LigeoAPI.RESULT_MAP_ID){
        veMap = LigeoAPI.getLigeoMapById(LigeoAPI.RESULT_MAP_ID).getVEMap();
    }else if (LigeoAPI.getLigeoMap().myId == LigeoAPI.ROUTE_MAP_ID){
        veMap = LigeoAPI.getLigeoMapById(LigeoAPI.ROUTE_MAP_ID).getVEMap();
    }
    
    if(veMap.GetMapStyle() == "b"){
        var wasB = true;
        veMap.SetMapStyle("h");
    }else if(veMap.GetMapStyle() == "o"){
        var wasO = true;
        veMap.SetMapStyle("a");
    }
	
	if(LigeoAPI.getLigeoMap().myId == LigeoAPI.RESULT_MAP_ID){
		zoomLevel = veMap.GetZoomLevel();
		currLat = veMap.GetCenter().Latitude;
		currLon = veMap.GetCenter().Longitude;
	    type = "printResults";
		page = "/jsp/resultsPopUp.jsp";
	} else if (LigeoAPI.getLigeoMap().myId == LigeoAPI.ROUTE_MAP_ID){
		zoomLevel = veMap.GetZoomLevel();
		currLat = veMap.GetCenter().Latitude;
		currLon = veMap.GetCenter().Longitude;
		type = "printRoute";
		page = "/jsp/routePopUp.jsp";
	}
	page = page + "?";
	page = page + "zoom=" + zoomLevel;
	page = page + "&lat=" + currLat;
	page = page + "&lon=" + currLon;
	var filterElement = document.getElementById("searchFormFilter");
	if ( filterElement ){
		page = page + "&locationTypeFilter=" + filterElement.value;
	}
    if(wasB){
        veMap.SetMapStyle("b");
    }
    if(wasO){
        veMap.SetMapStyle("o");
    }

	window.open(urlHost + page, type,'width=1024,height=768,resizable=yes,scrollbars=yes'); 
}

function profilePrintIt(urlHost){
    
    var zoomLevel;
    var currLat;
    var currLon;
    var type;
    var page;

    var veMap;

    if(LigeoAPI.getLigeoMap().myId == LigeoAPI.DRILL_MAP_ID){
        veMap = LigeoAPI.getLigeoMapById(LigeoAPI.DRILL_MAP_ID).getVEMap();
    }else if (LigeoAPI.getLigeoMap().myId == LigeoAPI.ROUTE_MAP_ID){
        veMap = LigeoAPI.getLigeoMapById(LigeoAPI.ROUTE_MAP_ID).getVEMap();
    }

    if(veMap.GetMapStyle() == "b"){
        var wasB = true;
        veMap.SetMapStyle("h");
    }else if(veMap.GetMapStyle() == "o"){
        var wasO = true;
        veMap.SetMapStyle("a");
    }
    
    if(LigeoAPI.getLigeoMap().myId == LigeoAPI.DRILL_MAP_ID){
        zoomLevel = veMap.GetZoomLevel();
        currLat = veMap.GetCenter().Latitude;
        currLon = veMap.GetCenter().Longitude;
        type = "printResults";
        page = "/jsp/profilePageResultsPopUp.jsp";
    } else if (LigeoAPI.getLigeoMap().myId == LigeoAPI.ROUTE_MAP_ID){
        zoomLevel = veMap.GetZoomLevel();
        currLat = veMap.GetCenter().Latitude;
        currLon = veMap.GetCenter().Longitude;
        type = "printRoute";
        page = "/jsp/profilePageRoutePopUp.jsp";
    }
    page = page + "?";
    page = page + "zoom=" + zoomLevel;
    page = page + "&lat=" + currLat;
    page = page + "&lon=" + currLon;

 page = page + "&locationTypeFilter=" + BOFA.locationTypeFilter;

    if(wasB){
        veMap.SetMapStyle("b");
    }
    if(wasO){
        veMap.SetMapStyle("o");
    }
    
    window.open(urlHost + page, type,'width=1024,height=768,resizable=yes,scrollbars=yes'); 
    
    if ( window.getCoremetricsID ) {
     cmCreateManualLinkClickTag('printable_version_link','PRINTABLE',getCoremetricsID(true));
    }
     
}

function getElementsByStyleClass (className) {
  var all = document.all ? document.all :
    document.getElementsByTagName('*');
  var elements = new Array();
  for (var e = 0; e < all.length; e++)
    if (all[e].className == className)
      elements[elements.length] = all[e];
  return elements;
}

function changeMarkerImg(){
    var markerImg = "";
	for(var i=1; i<11; i++){
	   markerImg = document.getElementById("marker_"+ i);
	   if(markerImg != null){
	   	markerImg.src = "../images/marker.gif";
	   }else{
	   	//alert("markerImg "+ markerImg +" is null");
	   }
	}	   
}

function revertImg(){
	var markerImg = "";
	for(var i=1; i<11; i++){
       markerImg = document.getElementById("marker_"+ i);
       if(markerImg != null){
        markerImg.src = "../images/clear.gif";
       }else{
        //alert("markerImg "+ markerImg +" is null");
        }
    }   
	
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}


function initHandlerResult () {
    if(document.NW != null) {
        document.NW.focus();
    }
}

BOFA.search = function(groupNum, searchForm) {

	if ( typeof LigeoAPI == "undefined" ) {
		return false;
	}
	
	isRoute = false;
	
	try {
		filterResults('ALL',groupNum);
		$('prompt').style.display='none'; 
		checkFullAddress();
		LigeoAPI.skipGridSearch(true);
		LigeoDOMUtils.showSelectedMap(LigeoAPI.RESULT_MAP_ID);
		$('modal-window').style.display='block';
		if ( $('directionsBlock') ) {
			$('directionsBlock').style.display = "none";
		}
		try {
			cmCreateManualLinkClickTag('go_button','GO',getCoremetricsID(true));
		} catch ( error ) {
			LigeoLogger.error("Exception caught from cmCreateManualLinkClickTag "+error );
		}
		LigeoAddressParser.parseAddress(searchForm, document.getElementById('resultsBlock'));
	} catch(err){}
	
	return false;
}

BOFA.drill = function(drillUrl)
{
	LigeoAPI.freezeMap(true);
	LigeoAPI.ajaxHtmlMessages(drillUrl, $('detailsBlock'));
	return true;  //Don't follow href
}

BOFA.route = function(routeUrlOrForm, changeRouteStart)
{
	if(document.getElementById('drill-nonmodal-window')!=null){
		new Effect.Fade('drill-nonmodal-window', {duration:.8});
	}
	$('modal-window').style.display='block';
	showRoute();
	if (changeRouteStart){
		return LigeoAddressParser.parseAddress(routeUrlOrForm, document.getElementById('directionsBlock'));
		//return false;
	} else {
		return LigeoAPI.ajaxHtmlMessages(routeUrlOrForm, document.getElementById('directionsBlock'));
	}
}

function showRoute() {
	BOFA.sb.load('directions'); 
	LigeoDOMUtils.showSelectedMap(LigeoAPI.ROUTE_MAP_ID); 
}

function formatSelectValue(inValue){
	var outValue = inValue;
	outValue = outValue.replace(/ /g,'_');
	outValue = outValue.toLowerCase();
	return outValue;
}

function setDisclaimerAd(inValue){
	elementToSet = document.getElementById('disclaimerAd');
	if (LigeoVarUtils.isNotNullOrEmpty(elementToSet)){
		elementToSet.style.visibility = inValue;
	}
}

// BOFA Search

function bt_rollover(ref, classRef) { eval(ref).className = classRef; }


function checkFullAddress() {
	if (document.getElementById("locationText").value == document.getElementById("locationText").title){
		document.getElementById("locationText").value = "";
	}
	//a hackaround to geocode 28255 as latitude 35.21107 and longitude -80.86715.
	checkFor28255();
}

// CREATE COOKIE FUNCTION
function setInowCookie( name, value, expires, path )  {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// sets expiration in milliseconda
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" );
}
	

function doesInowCookieExist(check_name) {

	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if ( cookie_name == check_name )
		{
			return true;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	return false;
}	

function setAdText(adText) {
	setDisclaimerAd("visible");
	var elementToSet = document.getElementById('disclaimerAd');
	if (LigeoVarUtils.isNotNullOrEmpty(elementToSet)){
		elementToSet.innerHTML = adText;
	}

}

function resetAllMaps() {
	if (LigeoFeaturesAPI.isStateImageMapShowing == false) {
		for(var i = 0; i < LigeoConfigurationAPI.getMyMapDivIDs().length; i++) {
		 	var thisMap = LigeoAPI.getLigeoMapById(LigeoConfigurationAPI.getMyMapDivIDs()[i]);
		    var resetCenter = new LigeoLocation("resetCenter");
		    resetCenter.setLatitude(38.86883);
		    resetCenter.setLongitude(-96.486962);
		    thisMap.setCenterAndZoom(resetCenter.getVELatLong(), 4);
		    thisMap.clearResults();
		}
		$('directionsBlock').style.display = "none";
	}

}

//Global Var used to determine if we should re-disp the route
myRouteSub = false;
function showProfileRoute(formSubmit, routePageSubmit) {

    if (myRouteSub) {
        formSubmit = true;
    }
    else if (routePageSubmit) {
        formSubmit = routePageSubmit;
        myRouteSub = routePageSubmit;
    }

    if ($('atm_display') != null) {
        $('atm_display').style.display='none';
    }

    
    $('showRoute').style.display='none';
    $('showDetails').style.display='inline';

    if ($('branch_display') != null) {
        $('branch_display').style.display='none';
    }

    if (!formSubmit) {
        $('ligeo-route').style.display='none';
    }
    
    $('directions_display').style.display='block';

    if ($('directionsLink') != null) {
        $('directionsLink').style.display='none';
    }
    if (formSubmit) {
    	if ( $('distance') ) {
        	$('distance').style.display='block';
        }
        LigeoDOMUtils.showSelectedMap(LigeoAPI.ROUTE_MAP_ID); 
 
    }


    return true;

}

function fixFullAddress() {
   if ($("directionText").value == 'Enter a starting address.') {
        $("directionText").value = "";
    }
}
function showProfileDetails() {
    if ($('atm_display') != null) {
      $('atm_display').style.display='block';
    }
    $('showRoute').style.display='inline';
    $('showDetails').style.display='none';
    if ($('branch_display') != null) {
        $('branch_display').style.display='block';
    }
    $('directions_display').style.display='none';
    LigeoDOMUtils.showSelectedMap(LigeoAPI.DRILL_MAP_ID); 
}



function checkFor28255() {
	//a hackaround to geocode 28255 as latitude 35.21107 and longitude -80.86715.
	var userInput = document.getElementById("locationText").value;
	var is_postal_28255 = document.getElementById("postal_28255");
	if (LigeoVarUtils.isNotNullOrEmpty(userInput) && 
			(trimString(userInput) == '28255' || trimString(userInput) == '28255, NC' || 
			 trimString(userInput) == '28255,NC' || trimString(userInput) == '28255 NC') ) {
		LigeoFeaturesAPI.doNotDisplayParsedAddressInFullAddressField()
		is_postal_28255.value = true;
	} else {
		is_postal_28255.value = false;
	}
}

function trimString(str) {
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

function disableContextMenu() {
    return false;
}

function checkReloadStatus(areResults) {
	BOFA.sb = new SideBar();
	if (areResults) {
		if (LigeoConfigurationAPI.isApplicationReloaded()) {  			
			$('resultsBlock').style.display = "block";
			$('advancedSearchLink').className = 'toggleFeaturesClosed';
			BOFA.sb.toggleView(true,'resultsContent','resultsLink');
			BOFA.sb.toggleView(false,'locationsContent','locateLink');
			BOFA.sb.toggleView(false,'internationalContent');
			BOFA.sb.toggleView(false,'directionsContent','directionsLink');
	    }
	} else {
		$('resultsBlock').style.display = "none";
		$('advancedSearchLink').className = 'toggleFeaturesOpen';
		BOFA.sb.toggleView(true,'resultsContent','resultsLink');
		BOFA.sb.toggleView(true,'locationsContent','locateLink');
		BOFA.sb.toggleView(false,'internationalContent');
		BOFA.sb.toggleView(false,'directionsContent','directionsLink');
	}
}

function stopMapZoomOnBalloonOpen() {
	if (resultMapIconClicked == true){
		resultMapIconClicked = false;
		return true;
	} else {
		resultMapIconClicked = false;
		return false;
	}
}
/*
 * This method is kind of hack to make legends on map display correctly. Its only used on profile page for route map.
 * Only profile page in app has pre-loaded route map and its display style is set to 'none' initially. 
 * So VE kind of behaves differently for container with display 'none' (kind of odd :)) hence legends are overlapping each other.
 * Refer BOFA-2440 & BOFA-2454   
 * */
function setLegendCSS() {
	var routeMapContainer = document.getElementById("ligeo-route-map");
	var childeren = routeMapContainer.childNodes;
	for(var childCount=0; childCount<childeren.length; childCount++) {
		//alert(childeren[childCount].className);
		var child = childeren[childCount];
		if((child.className.indexOf('MSVE_ScaleBarLabelBg') != -1) || (child.className.indexOf('MSVE_ScaleBarBg') != -1)) {
			//alert("");
			child.style.bottom = '13px'
		} else if ((child.className.indexOf('MSVE_ScaleBarLabelFg') != -1) || (child.className.indexOf('MSVE_ScaleBarFg') != -1)) {
			child.style.bottom = '14px'
		}
	}
}