// highlight, addtofavorite, Browser detect 


//v1.6
//active links are not clickable
var disable_active_link = false;

//enable or disable rollovers on active links related by scope with active states
var rollover_active_scope = false;

/*active states, i.e all buttons that have corresponding (...)-a.*
e.g. if all (n-main-)(...).* have active states: ['n-main-']
only n-main-atty.gif and all (n-feat-)(...).* have active state: ['n-main-atty','n-feat']
none have active states: ['#']*/
var arr_active = ['#'];

//class applied to active text links
var active_class = 'active';

//[['link','scope','scope',(...)],(...)]
var arr_scopes=[
['/CM/Custom/TOCPracticeAreaDescriptions.asp','../../PracticeAreas/index.html','/CM/PracticeAreaDescriptions'],
['/CM/Custom/Attorneys.asp','../../Bio/index.html','/CM/AttorneyBios/'],
['/','/CM/Custom/Home.asp'],
['/CM/Custom/Contact.asp','/CM/Custom/ThankYou.asp']
];

//use class "h_exclude" to avoid class "active" from being applied to any link
//use class "h_always_exclude" if the link or rollover is always an exception
//[['path to exclude from highlighting','exception','exception',(...)],(...)]
var enable_exception=false;
var arr_scope_exceptions=[
['/CM/Custom/TOCPracticeAreaDescriptions.asp','http://admin.bornsteinlawfirm.lawoffice.com/PracticeAreas/Social-Security-Disability.asp','http://admin.bornsteinlawfirm.lawoffice.com/PracticeAreas/Workers-Compensation.asp','/PracticeAreas/Personal-Injury.asp']
];

var at = document.getElementsByTagName('a'), it = document.getElementsByTagName('img'),i=0;
var uc = '~~~~';
//re = new RegExp(/^.+\('([^']+)'.+'\/(.+\/)+(.+)',.\)$/m);
re = new RegExp(/^.+\('([^']+)'.+?'\/([^.]+\/)+(.+?)',/m);

fp = document.location + uc;
rp = fp.replace(/^http:\/\/[^\/]+(\/.*)$/,'$1');
dn = fp.replace(rp,'')+'/';
rf = rp.replace(/^(\/(.+\/)+).+$/,'$1');
fn = rp.replace(rf,'');

fp = fp.replace(uc,'');
rp = rp.replace(uc,'');
fn = fn.replace(uc,'');


//Make '/' something unique
rp=(rp=='../../index.html')?uc:rp;
for(i=0;i<arr_scopes.length;i++){
	for(j=0;j<arr_scopes[i].length;j++){
		arr_scopes[i][j] = (arr_scopes[i][j]=='../../index.html')?uc:arr_scopes[i][j];
	}
}

for(i=0;i<at.length;i++){	
	at_hr = at[i].getAttribute('href');	
	
	/*if(at[i].className=='h_always_exclude')
		break;*/
	
	if(at_hr!=null){
		at_hr=(at_hr==dn)?uc:at_hr;	
		bs = scopes(at_hr);
		
		if((at_hr.indexOf(rp)>-1&&at_hr.indexOf('#')==-1&&at_hr.indexOf('?')==-1||bs)){			
			
			//at[i].className=(at[i].className!='last')?active_class:active_last_class;
			//alert(at_hr);

			if(!(at[i].className=='h_exclude'&&at_hr.indexOf(rp)==-1))
				at[i].className = (at[i].className!='')?at[i].className + ' ' + active_class:active_class;			

			
			
			
			if(!bs&&disable_active_link)
				at[i].removeAttribute('href');
			
			if(at[i].getAttribute('onmouseover')!=null){
				mo = at[i].getAttribute('onmouseover')+'';
				m = re.exec(mo);
	
				for(j=0;j<it.length;j++){
					if(it[j].getAttribute('name')==m[1]||it[j].getAttribute('id')==m[1]){
						as=m[3];
						for(k=0;k<arr_active.length;k++){
							if(m[3].indexOf(arr_active[k])>-1){
								as=m[3].replace('-o.','-a.');
								if(!bs||!rollover_active_scope)
									at[i].setAttribute('onmouseover',mo.replace('-o.','-a.'));
								break;
							}
						}					
						//alert(bs);
						
						it[j].src = '/Includes/Templates/Active/images/' + as;
					}
	
				}		
			}
		}
	}
}


function scopes(hr){	
	var i=0,j=0;
	//alert('*' + hr + '* - *' + dn + '*');
	mod_fp=(fn=='')?uc:fp;

	//Take care of exceptions first
	if(enable_exception){
		for(i=0;i<arr_scope_exceptions.length;i++){
			if(hr.indexOf(arr_scope_exceptions[i][0])>-1){			
				for(j=1;j<arr_scope_exceptions[i].length;j++){				
					if(mod_fp.indexOf(arr_scope_exceptions[i][j])>-1)
						return false;
				}
			}
		}
	}
	for(i=0;i<arr_scopes.length;i++){
		//Do scopes of current link fit the current file path? 
		if(hr.indexOf(arr_scopes[i][0])>-1){
			for(j=1;j<arr_scopes[i].length;j++){
				//alert(fp + ' - ' + arr_scopes[i][j] + ' - ' + i);
				
				if(mod_fp.indexOf(arr_scopes[i][j])>-1){
					return true;
				}
			}
		}
		
	}
	return false;
}


// add to favorite
<!--
function addIEFavorite(firmname) {
	if (window.external) {
           var title
           var firm_name = firmname
           var meta = document.getElementsByTagName('meta')
           for(var i=0; i<meta.length; i++) {
                       var meta_name = meta[i].getAttribute('name').toLowerCase()
                       if (meta_name == 'title') title = meta[i].getAttribute('content')
           }
           if (title == null) {
                       external.AddFavorite(location.href, firm_name)
           }
           else {
                       external.AddFavorite(location.href, firm_name+' - '+title)
           }
	}
	else {
           alert("This feature is not supported in your browser. Please use your regular bookmarks menu.");

	}
}
// -->

// Browser Detect Lite  v2.1.4
// http://www.dithered.com/javascript/browser_detect/index.html
// modified by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)


function BrowserDetectLite() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser name
   this.isGecko     = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isMozilla   = (this.isGecko && ua.indexOf('gecko/index.html') + 14 == ua.length);
   this.isNS        = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   this.isIE        = ( (ua.indexOf('msie') != -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) ); 
   this.isSafari    = (ua.indexOf('safari') != - 1);
   this.isOpera     = (ua.indexOf('opera') != -1); 
   this.isKonqueror = (ua.indexOf('konqueror') != -1 && !this.isSafari); 
   this.isIcab      = (ua.indexOf('icab') != -1); 
   this.isAol       = (ua.indexOf('aol') != -1); 
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isNS && this.isGecko) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('index.html') + 1 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('index.html') + 1 ) );
   }
   else if (this.isOpera) {
      if (ua.indexOf('opera/index.html') != -1) {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera/index.html') + 6 ) );
      }
      else {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera ') + 6 ) );
      }
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/index.html') + 10 ) );
   }
   else if (this.isIcab) {
      if (ua.indexOf('icab/index.html') != -1) {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab/index.html') + 6 ) );
      }
      else {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab ') + 6 ) );
      }
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/index.html') + 6), (ua.lastIndexOf('gecko/index.html') + 14) ) : -1 );
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin   = (ua.indexOf('win') != -1);
   this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac   = (ua.indexOf('mac') != -1);
   this.isUnix  = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetectLite();
