﻿function toggleLanguage()
{
    //get current cookie
    //get current URL, and switch the Lang part
    //redirect to the proper URL
}

function gotoPage(selectList) {
   var selectedIndex = selectList.selectedIndex;

   if (selectedIndex != "") {
      window.location.href = selectList[selectedIndex].value;
   }
}
function getElements(containingEl, tagName){
   containingEl = getRef(containingEl);
   var returnedCollection = new Array(0);
   var collection  = (containingEl.all && tagName == "*") ? 
   containingEl.all : containingEl.getElementsByTagName(tagName);
     
   for(var i = 0; i < collection.length; i++)
      returnedCollection[returnedCollection.length] = collection[i];
   return returnedCollection;
}
function hideChildElements(containingEl, tagName){
   containingEl = getRef(containingEl);
   var collection  = (containingEl.all && tagName == "*") ? 
   containingEl.all : containingEl.getElementsByTagName(tagName);
   //call hiddenDiv for all returned elements, not including
   //the div containing footer and the div containing the close button
   for(var i = 1; i < collection.length; i++){
      if(collection[i].id.indexOf('Footer') == -1 && collection[i].id.indexOf('Close') == -1 ){
         hiddenDiv(collection[i]);
      }
   }
}
function getRef(obj){
   if(typeof obj == "string")
      obj= document.getElementById(obj);
   return obj;
}
function setClassName(obj, className){
   getRef(obj).className= className;
}
function getClassName(obj){
   obj = getRef(obj);
   return obj.className;
}
   
function setStyle(obj, style, value){
   getRef(obj).style[style]= value;
}
function getStyle(obj, style){
   if(!document.getElementById) return;
   var obj = getRef(obj);
   var value = obj.style[style];
   if(!value)
      if(document.defaultView)
         value = document.defaultView.
            getComputedStyle(obj, "").getPropertyValue(style);
      else if(obj.currentStyle)
         value = obj.currentStyle[style];
   return value;
}
function displayDiv(obj){
   setStyle(obj, 'display', 'block');
}
function hideCells(parentDivId, columnIndex) {
    var tr = getElements(parentDivId,"tr");
    var tdcol = getElements(tr[0],"td");
    for (var x = columnIndex + 1; x < 3; x++) {
        var collection = getElements(tdcol[x], "div");
        if (collection != null) {
            for (var i = 0; i < collection.length; i++) {
                hiddenDiv(collection[i]);
            }
        }                    
    }
}
function hiddenDiv(obj){
   var args = arguments;
   for (var i = 0; i < args.length; i++){
      var input = args[i];
      var el = getRef(input);
      setStyle(el, 'display', 'none');
   }
}
// hide navigation menu contents
function hideSubnavs(){
   hideChildElements('aboutNavOverlay', 'div');
   hideChildElements('lawyersNavOverlay', 'div');
   hideChildElements('transactionsNavOverlay', 'div');
   hideChildElements('practiceNavOverlay', 'div');
   hideChildElements('newsNavOverlay', 'div');
   hideChildElements('publicationsNavOverlay', 'div');
   hideChildElements('studentsNavOverlay', 'div');
   hideChildElements('careersNavOverlay', 'div');
}
//new window
function NewWindow(mypage, myname, w, h, scroll) {
   var winl = (screen.width - w) / 2;
   var wint = (screen.height - h) / 2;
   winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
   win = window.open(mypage, myname, winprops)
   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
function changeSort(strLink,form){
   
   var currentUrl = strLink.split('?');
   var sortStringType = '?type=' + form.type.value;
   var sortStringValue = '&value=' + form.value.value;
   var sortStringFieldToSort = '&fieldtosort=' + form.fieldtosort.value;
   var searchStringFieldToSort = 'fieldtosort=' + form.fieldtosort.value;
   
   //if field to sort has changed, change sort order to ascending,
   //else, change to descending
   if (strLink.indexOf(searchStringFieldToSort ) == -1){
      form.sortbyorder.value = 'ASC';
      }
   //if field to sort has not changed, toggle sort order,
   else if(currentUrl[1].indexOf(searchStringFieldToSort ) != -1){
      if(currentUrl[1].indexOf('ASC') != -1 || currentUrl[1].indexOf('sortbyorder') == -1){
         form.sortbyorder.value = 'DESC';
      }
      else{
         form.sortbyorder.value = 'ASC';
      }
   }
   var sortStringSortByOrder = '&sortbyorder=' + form.sortbyorder.value;
   currentUrl[0] += sortStringType;
   currentUrl[0] += sortStringValue;
   currentUrl[0] += sortStringFieldToSort;
   currentUrl[0] += sortStringSortByOrder;
   return currentUrl[0];
}
// form validation
// Check that an email address is valid based on RFC 821 (?)
function isValidEmail(address) {
    if (address != '' && address.search) {
      if (address.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true;
      else return false;
    }
   // allow empty strings to return true - screen these with either a 'required' test or a 'length' test
   else return true;
}
function validatePublications(fields){
   var returnValue = true;
   var args = arguments;
    for (var inputIdIndex = 0; inputIdIndex < args.length; inputIdIndex++) {
      var inputId = args[inputIdIndex];
      var input = document.getElementById(inputId);
      // if field contains no data, display div containing error;
      if ((input.type == "text") && input.value.length == 0) {
         document.getElementById('e' + inputId).style.display = 'block';
         returnValue = false;
      }
      else {
         document.getElementById('e' + inputId).style.display = 'none';
      }
      // validate email address
      if (input.id == "txtEmail"){
         if (isValidEmail(input.value)){
            document.getElementById('etxtEmailb').style.display = 'none';
         }
         else {
           document.getElementById('etxtEmailb').style.display = 'block';
           returnValue = false;
         }
      }
   }
   
   return returnValue;
}
function validateApplyOnline(fields, maxCharCoverLetterAmt, maxCharResumeAmt) {
   var returnValue = true;
   var args = fields.split(';');
    for (var inputIdIndex = 0; inputIdIndex < args.length; inputIdIndex++) {
      var inputId = args[inputIdIndex];
      var input = document.getElementById(inputId);
      // validate fields containing no data
      if ((input.type == "text" || input.type == "textarea") && input.value.length == 0) {
         document.getElementById('e' + inputId).style.display = 'block';
         returnValue = false;
      }
      else {
         document.getElementById('e' + inputId).style.display = 'none';
      }
      // validate CoverLetter textarea max character amount
      if (input.type == "textarea" && input.id == 'txtCoverLetter'){
         if (input.value.length <= maxCharCoverLetterAmt){
            document.getElementById('e' + inputId + 'b').style.display = 'none';
         }
         else{
            document.getElementById('e' + inputId + 'b').style.display = 'block';
            returnValue = false;
         }
      }
      // validate Resume textarea max character amount
      if (input.type == "textarea" && input.id == 'txtResume'){
         if (input.value.length <= maxCharResumeAmt){
            document.getElementById('e' + inputId + 'b').style.display = 'none';
         }
         else{
            document.getElementById('e' + inputId + 'b').style.display = 'block';
            returnValue = false;
         }
      }
      // validate email address
      if (input.id == "txtFromEmail"){
         if (isValidEmail(input.value)){
            document.getElementById('etxtFromEmailb').style.display = 'none';
         }
         else {
           document.getElementById('etxtFromEmailb').style.display = 'block';
           returnValue = false;
         }
      }
   }
   return returnValue;
}

// Rollover  v2.0
// documentation: http://www.dithered.com/javascript/rollover/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)

function isDefined(property) {
  return (typeof property != 'undefined');
}
var rolloverInitialized = false;
function rolloverInit() {
   if (!rolloverInitialized && isDefined(document.images)) {
      
      // get all images (including all <input type="image">s)
      // use getElementsByTagName() if supported
      var images = new Array();
      if (isDefined(document.getElementsByTagName)) {
         images = document.getElementsByTagName('img');
         var inputs = document.getElementsByTagName('input');
         for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].type == 'image') {
               images[images.length] = inputs[i];
            }
         }
      }
      
      // otherwise, use document.images and document.forms collections
      // remove if not supporting IE4, Opera 4-5
      else {
         images = document.images;
         inputs = new Array();
         for (var formIndex = 0; formIndex < document.forms.length; formIndex++) {
            for (var elementIndex = 0; elementIndex < document.forms.elements.length; elementIndex++) {
               if (isDefined(document.forms.elements[i].src)) {
                  inputs[inputs.length] = document.forms.elements[i];
               }
            }
         }
      }
      
      // get all images with '_off.' in src value
      for (var i = 0; i < images.length; i++) {
         if (images[i].src.indexOf('_off.') != -1) {
            var image = images[i];
            
            // store the off state filename in a property of the image object
            image.offImage = new Image();
            image.offImage.src = image.src;
            
            // store the on state filename in a property of the image object
            // (also preloads the on state image)
            image.onImage = new Image();
            image.onImage.imageElement = image;
            
            // add onmouseover and onmouseout event handlers once the on state image has loaded
            // can't use image.onImage.onload to attach event handlers in Safari - this==document instead of image
            if (navigator.userAgent.toLowerCase().indexOf('safari') != -1) {
               image.onmouseover = function() {
                  this.src = this.onImage.src;
               };
               image.onmouseout = function() {
                  this.src = this.offImage.src;
               };
            }
            else {
               image.onImage.onload = function() {
                  this.imageElement.onmouseover = function() {
                     this.src = this.onImage.src;
                  };
                  this.imageElement.onmouseout = function() {
                     this.src = this.offImage.src;
                  };
               };
            }
            
            // set src after defining onload event handler so onload while fire if _on image is cached
            image.onImage.src = image.src.replace(/_off\./, '_on.');
         }
      }
   }
   rolloverInitialized = true;
}
// call rolloverInit when document finishes loading
if (isDefined(window.addEventListener)) {
   window.addEventListener('load', rolloverInit, false);
}
else if (isDefined(window.attachEvent)) {
   window.attachEvent('onload', rolloverInit);
}

// Adobe Acrobat Detection  v1.0
// http://www.dithered.com/javascript/acrobat_detect/index.html
// code by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)

var acrobatVersion = 0;
function getAcrobatVersion() {
    var agent = navigator.userAgent.toLowerCase(); 
    
    // NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Acrobat plugin in plugin array
    if (navigator.plugins != null && navigator.plugins.length > 0) {
      for (i=0; i < navigator.plugins.length; i++ ) {
         var plugin = navigator.plugins[i];
         if (plugin.name.indexOf("Adobe Acrobat") > -1) {
            acrobatVersion = parseFloat(plugin.description.substring(30));
         }
      }
    }
   
    // IE4+ Win32:  attempt to create an ActiveX object using VBScript
    else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
       document.write('<scr' + 'ipt language="VBScript"\> \n');
       document.write('on error resume next \n');
        document.write('dim obAcrobat \n');
        document.write('set obAcrobat = CreateObject("PDF.PdfCtrl.5") \n');
        document.write('if IsObject(obAcrobat) then \n');
        document.write('acrobatVersion = 5 \n');
        document.write('else set obAcrobat = CreateObject("PDF.PdfCtrl.1") end if \n');
        document.write('if acrobatVersion < 5 and IsObject(obAcrobat) then \n');
        document.write('acrobatVersion = 4 \n');
        document.write('end if');
        document.write('</scr' + 'ipt\> \n');
  }
    // Can't detect in all other cases
    else {
        acrobatVersion = acrobatVersion_DONTKNOW;
    }
    return acrobatVersion;
}
acrobatVersion_DONTKNOW = -1;