// Email window popup with disclaimer static text.
// use: when user clicks an attorney email link
//
function emailWindow(email)
{
	window.open("email-popup.html?email=" + email, "EmailNotice", "toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=yes,width=560,height=680");
}

// vcard window popup with disclaimer static text.
// use: when user clicks an attorney vcard link
//
function vcardWindow(id)
{
	window.open("vcard-popup.html?id=" + id, "VcardNotice", "toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=yes,width=560,height=680");
}

// External link window popup with disclaimer static text.
// use: when user clicks an external link first display disclaimer statictext
// requires: external-popup.html
// 
// user must enter links in the wysiwyg editor as:
// javascript:exteranlLink('http://www.firmseek.com/')
//
// open new window with same W & H as existing, add width='x', height='x'
// to open to a specific size
//
function externalLink(link)
{
	window.open("external-popup.html?link=" + link, "ExternalLink", "toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,menubar=yes,resizable=yes");
}

// Bookmark page link, IE only.
// all other browsers displays an alert box.  not sure how detailed we
// want to make this, eg NS, Firefox 'press ctrl+d' message, Mozilla ??
//
function addToFavorites()
{
	var ua = navigator.userAgent.toLowerCase(); 

	// browser engine name
	this.isGecko	   = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
	this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

	// browser name
	this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
	this.isSafari	   = (ua.indexOf('safari') != - 1);
	this.isOmniweb	   = (ua.indexOf('omniweb') != - 1);
	this.isOpera	   = (ua.indexOf('opera') != -1); 
	this.isIcab	   = (ua.indexOf('icab') != -1); 
	this.isAol	   = (ua.indexOf('aol') != -1); 
	this.isIE	   = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
	this.isMozilla	   = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
	this.isFirebird    = (ua.indexOf('firebird/') != -1);
	this.isFirefox	  = (ua.indexOf('firefox/') != -1);
	this.isNS	   = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );

	this.versionMajor = parseInt(this.versionMinor);
	this.isMac    = (ua.indexOf('mac') != -1);

	this.isIE5x = (this.isIE && this.versionMajor == 5);

	if (window.external && !this.isMac)
	{
		var url=window.location.href;
		var title=document.title;
		window.external.AddFavorite(url,title)
	} else if (!this.isMac && (this.isNS || this.isFirefox || this.isMozilla))
	{
		alert("Press Ctrl+D to bookmark this page."); 
	} else if (this.isMac && (this.isSafari || this.ie5x || this.isMozilla))
	{
		alert("Press Apple/Squiggle+D to bookmark this page."); 
	} else {
		alert("Sorry! Your browser doesn't support this function.\nUse your browser's bookmark feature to add a bookmark."); 
	}
}

// Place holder for the 'print this page' link
// s/b replaced when we do the html templates
//
function printPage()
{
	window.print();  
}

// 
// NS only
//
function findOnThisPage()
{
	window.find();	
}


// preload images
function preloadImages()
{
	var imagesToLoad = new Array('i/menu/menu_practice_on.png', 'i/menu/menu_attorneys_on.png', 'i/menu/menu_about_on.png', 'i/menu/menu_news_on.png', 'i/menu/menu_publications_on.png', 'i/menu/menu_offices_on.png', 'i/menu/menu_careers_on.png', 'i/menu/menu_contact_on.png');

	// Don't bother if there's no document.images
	if (document.images)
	{
		if (typeof(document.WM) == 'undefined')
		{
			document.WM = new Object();
		}

		document.WM.loadedImages = new Array();

		// Loop through all the arguments.
		var argLength = imagesToLoad.length;

		for(arg=0;arg<argLength;arg++) 
		{
			// For each arg, create a new image.
			document.WM.loadedImages[arg] = new Image();
			// Then set the source of that image to the current argument.
			document.WM.loadedImages[arg].src = imagesToLoad[arg];
		}
	}
}

// functions for FAQ page
var lastAnswer = null;
var lastTitle = null;

function showAllAnswers( titleElement, dataCount )
{
	if( lastTitle )
		RemoveClassName(lastTitle,'selected');
	
	AddClassName(titleElement,'selected');
	lastTitle = titleElement;
	lastAnswer = null;
	
	for( answerId=1; answerId<dataCount; answerId++)
	{
		if( answerElement = document.getElementById('answer_'+answerId) )	
		{
			answerElement.style.display='block';
		}	
	}	
}

function hideAllAnswers() {
	answerId = 1;
	
	while( answerElement = document.getElementById('answer_'+answerId) )	
	{
		answerElement.style.display='none';
		//alert( answerElement );
		answerId++;
	}
}

function showAnswer( answerId, titleElement )
{
	if( lastTitle )
		RemoveClassName(lastTitle,'selected');
		
	if( lastAnswer )
		lastAnswer.style.display='none';
	else
		hideAllAnswers();	
	
	if( answerElement = document.getElementById('answer_'+answerId) )	
	{
		AddClassName(titleElement,'selected');
		answerElement.style.display='block';
	}
	
	lastAnswer = answerElement;
	lastTitle = titleElement;
}

// ----------------------------------------------------------------------------
// AddClassName
//
// Description : adds a class to the class attribute of a DOM element
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to add
//
function AddClassName(objElement, strClass, blnMayAlreadyExist)
   {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // if the new class name may already exist in list
      if ( blnMayAlreadyExist )
         {

         // get uppercase class for comparison purposes
         var strClassUpper = strClass.toUpperCase();

         // find all instances and remove them
         for ( var i = 0; i < arrList.length; i++ )
            {

            // if class found
            if ( arrList[i].toUpperCase() == strClassUpper )
               {

               // remove array item
               arrList.splice(i, 1);

               // decrement loop counter as we have adjusted the array's contents
               i--;

               }

            }

         }

      // add the new class to end of list
      arrList[arrList.length] = strClass;

      // add the new class to beginning of list
      //arrList.splice(0, 0, strClass);
      
      // assign modified class name attribute
      objElement.className = arrList.join(' ');

      }
   // if there was no class
   else
      {

      // assign modified class name attribute      
      objElement.className = strClass;
   
      }

   }
// 
// AddClassName
// ----------------------------------------------------------------------------


// ----------------------------------------------------------------------------
// RemoveClassName
//
// Description : removes a class from the class attribute of a DOM element
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to remove
//
function RemoveClassName(objElement, strClass)
   {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();

      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ )
         {

         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper )
            {

            // remove array item
            arrList.splice(i, 1);

            // decrement loop counter as we have adjusted the array's contents
            i--;

            }

         }

      // assign modified class name attribute
      objElement.className = arrList.join(' ');

      }
   // if there was no class
   // there is nothing to remove

   }
// 
// RemoveClassName
// ----------------------------------------------------------------------------
  
  
if( !document.getElementsByClassName )
{
	document.getElementsByClassName = function(clsName){
	    var retVal = new Array();
	    var elements = document.getElementsByTagName("*");
	    for(var i = 0;i < elements.length;i++){
	        if(elements[i].className.indexOf(" ") >= 0){
	            var classes = elements[i].className.split(" ");
	            for(var j = 0;j < classes.length;j++){
	                if(classes[j] == clsName)
	                    retVal.push(elements[i]);
	            }
	        }
	        else if(elements[i].className == clsName)
	            retVal.push(elements[i]);
	    }
	    return retVal;
	}
}