var index1;
var parentdivid;
var oldfunction=null;
var intervalid;
var glblVal = 0;

function check_Mode()
{
//var url1=location.href;
//var url1lower=url1.toLowerCase();
//if (url1lower.indexOf('branchpage2')!=-1)
//{

var iframe1=window.frames[0];
if(iframe1 != null)
{
if (iframe1.document.getElementById('staticMap') !=null)
{
clearInterval(intervalid);
var ver1=getInternetExplorerVersion();
if ( ver1 > -1 )
  {
    if ( ver1 >= 7.0 ) 
	setInterval("resizeIframe()",10);
  }

add_csslink();
create_tab('staticMap');
create_tab('s');
change_Tab(0);
if (iframe1.document.getElementById('m') !=null)
iframe1.document.getElementById('m').style.display='none';
var  aa=iframe1.document.getElementById('s').getElementsByTagName("A");
for(var i = 0; i < aa.length; i++) 
{
if (aa[i].innerHTML.indexOf('Get Directions') !=-1)
{
var oldf=aa[i].onclick;
aa[i].onclick=function() {
if (window.frames[0].document.getElementById('txtPostalCode') !=null && window.frames[0].document.getElementById('selStateProvince') && window.frames[0].document.getElementById('txtCity') )
{
if(window.frames[0].document.getElementById('txtPostalCode').value =='' && (window.frames[0].document.getElementById('txtCity').value == '' || window.frames[0].document.getElementById('selStateProvince').value == '' ))
return false;
}

if (window.frames[0].document.getElementById('m') !=null)
window.frames[0].document.getElementById('m').style.display='block';
if(window.frames[0].document.getElementById('mapquesttabcontainers') !=null)
window.frames[0].document.getElementById('mapquesttabcontainers').style.visibility='hidden';
if(window.frames[0].document.getElementById('tabDiv') !=null)
window.frames[0].document.getElementById('tabDiv').style.visibility='hidden';
if (oldf)oldf();
if(window.frames[0].document.getElementById('Message') !=null)
if (window.frames[0].document.getElementById('Message').innerHTML.indexOf('required')==-1)
change_position();
};
}//if
}//for
}
//}//end of if
}//null
}//end of function check_Mode

function change_Tab(index1)
{
var iframe1=window.frames[0];
if (index1==0)
{
//document.getElementById('maindiv').style.visibility='visible';
//document.getElementById('divSearchCriteria').style.visibility='hidden';
iframe1.document.getElementById('staticMap').style.visibility='visible';
iframe1.document.getElementById('s').style.visibility='hidden';

iframe1.document.getElementById('staticMap').style.width='50%';
iframe1.document.getElementById('s').style.width='0px';
iframe1.document.getElementById('staticMap').style.height='50%';
iframe1.document.getElementById('s').style.height='0px';
}//
else
{
//document.getElementById('maindiv').style.visibility='hidden';
//document.getElementById('divSearchCriteria').style.visibility='visible';
iframe1.document.getElementById('staticMap').style.visibility='hidden';
iframe1.document.getElementById('s').style.visibility='visible';

iframe1.document.getElementById('s').style.width='50%';
iframe1.document.getElementById('staticMap').style.width='0px';
iframe1.document.getElementById('s').style.height='50%';
iframe1.document.getElementById('staticMap').style.height='0px';

}
var MapQuestDD1_imgMapobj=iframe1.document.getElementById('MapQuestDD1_imgMap');

	   if (MapQuestDD1_imgMapobj !=null)
	   {
	  MapQuestDD1_imgMapobj.style.width='310px';
	  MapQuestDD1_imgMapobj.className='imgmapwidth';
	  }
}//
function create_tab(parentdivid)
{
var iframe1=window.frames[0];
var _mapquesttabcontainer=iframe1.document.createElement('div');
_mapquesttabcontainer.id='mapquesttabcontainer' + parentdivid;
_mapquesttabcontainer.className='mapquesttab';
var _div1=iframe1.document.createElement('div');
_div1.id='divtab1' + parentdivid;
if (parentdivid=='staticMap') 
_div1.className='mapquesttabselected';
else
_div1.className='mapquesttabdefault';
_div1.onclick = function()
{
change_Tab(0);
};

_div1.innerHTML='&nbsp;&nbsp;Map&nbsp;&nbsp;';
_div1.style.width='40px';

_mapquesttabcontainer.appendChild(_div1);
var _div2=iframe1.document.createElement('div');
_div2.id='divtab2' + parentdivid;
if (parentdivid=='staticMap') 
_div2.className='mapquesttabdefault';
else
_div2.className='mapquesttabselected';
_div2.innerHTML='&nbsp;&nbsp;Directions&nbsp;&nbsp;';
_div2.style.width='80px';
_div2.onclick = function()
{
change_Tab(1);
};
_mapquesttabcontainer.appendChild(_div2);
var _maindiv=window.frames[0].document.getElementById(parentdivid);
//var mapImgWidth= window.frames[0].document.getElementById('MapQuestDD1_imgMap');
_maindiv.innerHTML='<div id="tabDiv" class="mapquesttab1" >' + _maindiv.innerHTML + '</div>'
//var _divblank=iframe1.document.createElement('div');
//_divblank.style.width='80%'
//_mapquesttabcontainer.appendChild(_divblank);
_maindiv.appendChild(_mapquesttabcontainer);
_maindiv.insertBefore(_mapquesttabcontainer,_maindiv.firstChild);

//var _divblank=iframe1.document.getElementById('tabDiv');
//if(mapImgWidth.width!=''||mapImgWidth.width!=0)
//_divblank.style.width=mapImgWidth.width+'px';
}//
function change_position()
{
try
{

window.frames[0].document.getElementById("s").className="sdiv_ongetdir";
window.frames[0].document.getElementById("m").className="mdiv_ongetdir";

var s1=window.frames[0].document.getElementById('s');
var s2=window.frames[0].document.getElementById('mapquesttabcontainers');
var s3=window.frames[0].document.getElementById('tabDiv');
if (s2 !=null)
s1.removeChild(s2);
if (s3 !=null)
s1.removeChild(s3);
s1.style.visibility='visible';
var s11=window.frames[0].document.getElementById('staticMap');
var s21=window.frames[0].document.getElementById('mapquesttabcontainerstaticMap');
var s31=window.frames[0].document.getElementById('tabDiv');
if (s21 !=null)
s11.removeChild(s21);
if (s31 !=null)
s11.removeChild(s31);

right_print_btn();
resizeIframe('MQframe');
}
catch(e)
{
var cc;
}
}//function
//attach event to get direction button
function right_print_btn()
{
var  aa=window.frames[0].document.getElementById('s').getElementsByTagName("A");
for(var i = 0; i < aa.length; i++) 
{
if (aa[i].innerHTML.indexOf('Get Directions') !=-1)
{
var oldf=aa[i].onclick;
aa[i].onclick=function() {
if (oldf)oldf();
right_print_btn();
};
}//if
}//for
}//function

function right_print_btn()
{

if (window.frames[0].document.getElementById('divRouteResults') !=null)
{
var  aa=window.frames[0].document.getElementById('divRouteResults').getElementsByTagName("A");
for(var i = 0; i < aa.length; i++) 
{
aa[i].style.paddingLeft='95px';
aa[i].style.paddingRight='15px';//newly added
}
}//if
}//function
intervalid=setInterval("check_Mode()",10);
function resizeIframe(frameId) {
   var extheight=10;
   
var ver1=getInternetExplorerVersion();
if ( ver1 > -1 )
  {
    if ( ver1 >= 7.0 ) 
	extheight=60;
  }
    var frameId = frameId || 'MQframe';
var frame=parent.document.getElementById(frameId);
if(frame == null)
	return false;
var innerDoc=(frame.contentDocument)?frame.contentDocument:frame.contentWindow.document;
if(glblVal == 1)
{
    document.getElementById('loadImgContainer').style.display='none';
    frame.style.visibility='visible';
    }
    

    var greyBarDivs = getElementsByClassName('act',frame.contentWindow.document.getElementById('maindiv'));
     if(greyBarDivs.length > 0)
     {
       greyBarDivs[0].style.display = 'none';
       
        var greyBarDivs = getElementsByClassName('width143prcnt',frame.contentWindow.document.getElementById('maindiv'));
        for(i=0;i<greyBarDivs.length;i++)
        {
            greyBarDivs[i].style.display = 'none';
        }
         var greyBarDivs = getElementsByClassName('mapquesttab1',frame.contentWindow.document.getElementById('staticMap'));
         for(i=0;i<greyBarDivs.length;i++)
        {
            greyBarDivs[i].style.overflow = 'hidden';
            greyBarDivs[i].style.width = '172%';
        }
        var greyBarDivs = getElementsByClassName('width60',frame.contentWindow.document.getElementById('divContent'));
         for(i=0;i<greyBarDivs.length;i++)
        {
            greyBarDivs[i].style.display = 'none';
            greyBarDivs[i].style.width = '0px';
        }
        
          var greyBarDivs = getElementsByClassName('mapquesttab1',frame.contentWindow.document.getElementById('s'));
         for(i=0;i<greyBarDivs.length;i++)
        {
            greyBarDivs[i].style.overflow = 'hidden';
            greyBarDivs[i].style.width = '172%';
        }
        var greyBarDivs = getElementsByClassName('greyLine',frame.contentWindow.document.getElementById('pnlViewDirections'));
        for(i=0;i<greyBarDivs.length;i++)
        {
            greyBarDivs[i].style.display = 'none';
        }
      
       
       var dataDiv = getElementsByClassName('act',document.getElementById('FAAdvisors'));
       if(dataDiv.length >0)
            dataDiv[0].style.display = 'block';
     }
     var objToResize=(frame.style)?frame.style:frame;
var tothgt=parseInt(innerDoc.body.scrollHeight+extheight);
if (tothgt < 320)
tothgt=320;
objToResize.height=tothgt+'px';
     glblVal += 1;
//       document.getElementsByTagName("body")[0].style.background = 'none';
}

//Added for migration of MapQuest into IFrame - sroy1 - 03-02-09
	function getElementsByClassName(classname,node){
        if(!node) node = document.getElementsByTagName("body")[0];
        var a = [];
        var re = new RegExp('\\b' + classname + '\\b');
        var els = node.getElementsByTagName("*");
        for(var i=0,j=els.length; i<j; i++)
            if(re.test(els[i].className))
            a.push(els[i]);
            return a;
    }
    
function writeHrefTagforBranch()
{

    var qs = window.location.search.substring(1);
    var type;
    var stateName;
    Keyvaluepair = qs.split("&");
    
    for (i=0;i<Keyvaluepair.length;i++)
    {
        tabKeyValue = Keyvaluepair[i].split("=");
        if(tabKeyValue[0] == "stateid")
        {
            type = tabKeyValue[1];
        }
        if(tabKeyValue[0] == "statename")
        {
//            if(tabKeyValue[1].indexOf('%20') != -1)
//                stateName = tabKeyValue[1].replace('%20',' ');
//                 else if(tabKeyValue[1].indexOf('+') != -1)
//                stateName = tabKeyValue[1].replace('+',' ');
//            else
//                stateName = tabKeyValue[1];  
                 stateName = tabKeyValue[1];
				
				 if(stateName.indexOf('%20') != -1)
                stateName = stateName.replace('%20',' ');				                
      
	           var intIndexOfMatch=stateName.indexOf('+')
	           while (intIndexOfMatch != -1)
	           {
		            stateName = stateName.replace( "+", " " )
		            intIndexOfMatch = stateName.indexOf( "+" );
               }
                
        }
    }
     if(type != undefined || stateName != undefined)
    {
        href = "BranchByState.aspx?stateid=" + type + "&statename=" + stateName ;
        aText = "< " + stateName + " Branch Offices Index ";
        document.write('<' + 'a href="' + href + '">' + aText  + '</a>');
    }
}
function add_csslink()
{
var iframe1=window.frames[0];
 var filename='/publish/tm/css/branchPagemap.css';
 var doc=iframe1.document;
     var fileref=doc.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
//  if(window.location.href.toLowerCase().indexOf('facustompage1')!=-1)
//  filename=filename + '1.css';
//   if(window.location.href.toLowerCase().indexOf('facustompage2')!=-1)
//  filename=filename + '2.css';
//  if(window.location.href.toLowerCase().indexOf('facustompage3')!=-1)
//  filename=filename + '3.css';

  fileref.setAttribute("href", filename);
  doc.getElementsByTagName("head")[0].appendChild(fileref);

 
}//

function writeAddrWithImage(d, u, txt, title,cssclass) 
{
    var s = String.fromCharCode(64);
    
    //TODO: this will be removed for the 1.2.04 Release
    if (document.title == "Merrill Lynch Branch Office")
    {        
        var _numTitle = title.length / 2;        
        var arrTitle = title.split(' ');     
        var newTitle = title.substring(_numTitle);
        newTitle = newTitle.replace(' ','');
        var _tempName = arrTitle[0];
        var _numNameLength = arrTitle.length / 2;        
        for (var i=1; i<_numNameLength; i++)
            _tempName = _tempName + ' ' +arrTitle[i];        
        if (_tempName == newTitle)
            title = newTitle;
        if (txt != title)
            txt = title;
    } 
    ////////////////////////////////////////////////////////
    
    document.write('<a href="' + 'mai' + 'lto:' + u + s + d);
  
    if ( txt == null || txt.length == 0 ) 
        document.write('\">');
    else
        document.write('\" title=\"'+title+'\"><IMG alt="email" src="/publish/tm/images/email.png" width="16" height="16"/><\/a>');}
        
function writeHrefTagGeneric(href, className, title, aText, target)
{
var href = "..\\system\\SendToAFriendModal.aspx?"+target;
    if ( null == title || title.length == 0 )
		document.write('<' + 'a href="' + href + '" class="' + className + '" target="' + target + '"><IMG alt="email" src="/publish/tm/images/email.png" width="16" height="16"/></a>');
    else
        document.write('<' + 'a href="' + href + '" title="' + title + '" class="' + className + '" target="' + target + '"><IMG alt="email" src="/publish/tm/images/email.png" width="16" height="16"/></a>');
                
}
function dvcard(qsVcard) 
    {    
   qsVcard='qscard=' + qsVcard;
	//  var qsVcard='qscard=ganesh+team::;;5209+VILLAGE+PARKWAY;;ROGERS,%20AR%2072758:(800)+677-3512::EYER';
	//var url=window.location.protocol + '://' + window.location.host + '/' ;
	 var navResult = '../system/DivForm.aspx';
        if ( qsVcard != null && qsVcard.length > 0 )
            window.open(navResult+ '?' + qsVcard,'winv','resizable=yes,toolbar=no,menubar=no,location=0,status=0,scrollbars=0,width=10px,height=10px,top=1000px');
	  return false;
	}
        
  function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}      


function ImageNotFound(clientid)
{
//alert('first one not found');

document.getElementById(clientid).src = '/publish/tm/images/bull_logo.jpg';
}

function writeHrefTagforIcons(href, className, type, title)
{
if(type == "facebook")
{
var href = href + window.location.href;
document.write('<' + 'a href="' + href + '" title="' + title + '" class="' + className + '" target="_blank"><IMG alt="facebook" src="/publish/tm/images/facebook.png" width="16" height="16"/></a>');
}                
}
function LoadMQFrame()
{		
    //var objFrame = document.getElementsByTagName('iframe')[0];

	for(i=0;i<document.getElementsByTagName('iframe').length;i++)
	{
		if(document.getElementsByTagName('iframe')[i].id.indexOf('MQframe')!=-1)
		{
			var objFrame = document.getElementsByTagName('iframe')[i];
			break;
		}
	}
	
    if(objFrame && objFrame.id=='MQframe')
    {
        var pageQuery = "Address="+mqVar_Address;
        pageQuery +="&City="+mqVar_City;
        pageQuery +="&State="+mqVar_State;
        pageQuery +="&Zip="+mqVar_Zip;
        objFrame.src="../system/Mapquest.aspx?" + pageQuery; 
		
        var handler = function(){resizeIframe('MQframe')};
        //objFrame.onload= handler;
//        if (objFrame.addEventListener) 
//        {
//          objFrame.addEventListener('load', handler, false);
//        } 
//        else if (objFrame.attachEvent) 
//        {
//          objFrame.attachEvent('onload', handler);
//          //objFrame.attachEvent('onreadystatechange ', handler);
//        }
    }
}
