/**
 * Opens a classic new window.
 *
 * @param linkURL
 * @param w        new window width
 * @param h        new window height
 * @param x        new window x-coordinate
 * @param y        new window y-coordinate
 */
function openPopup(linkURL, w, h, x, y) {
  var params;
  params = "width = " + w;
  params += ", height = " + h;
  params += ", resizable = yes";
  params += ", scrollbars = yes";
  params += ", toolbar = no";
  params += ", menubar = no";
  params += ", status = no";
  params += ", directories = no";

  var newWindow = window.open(linkURL, "newWindow", params)
    newWindow.moveTo(x, y);
    newWindow.focus();
  }

function resetField(f) {
    document.getElementById(f).selectedIndex = 0;
}

function clearField(f) {
    document.getElementById(f).value = "";
}



/*
 * Finds the current "left" (x) position of the parent object from which the script
 * was fired. This is used to position popups near to their parent link rather
 * than in an asbolute or relative position within a document or page.
 */
function findPosX(obj) {
    var curleft = 0;
    if(obj.offsetParent) {
        while(1) {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent) break;
          obj = obj.offsetParent;
        }
    } else if (obj.x) {
        curleft += obj.x;
    }
    return curleft;
  }

/*
 * Finds the current "top" (y) position of the parent object from which the script
 * was fired. This is used to position popups near to their parent link rather
 * than in an asbolute or relative position within a document or page.
 */
  function findPosY(obj) {
    var curtop = 0;
    if(obj.offsetParent) {
        while(1) {
          curtop += obj.offsetTop;
          if(!obj.offsetParent) break;
          obj = obj.offsetParent;
        }
    } else if(obj.y) {
        curtop += obj.y;
    }
    return curtop;
  }


function closePopup(obj) {
 document.getElementById(obj).style.display =  "none";
}


/**
 * Displays a DHTML modal popup on the web page.
 *
 * @param obj      the id of the hidden div to display
 */
function showModalPopup(obj) {
      if(obj == null || document.getElementById(obj) == null) return;
      // setup the veil over the page
      var ie=document.all && !window.opera;
      var standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body; //create reference to common "body" across doctypes
      var scroll_top=(ie)? standardbody.scrollTop : window.pageYOffset;
      var docwidth=(ie)? standardbody.clientWidth : window.innerWidth;         // The innerWidth property in FF does not include the scrollbar width
      var docheight=(ie)? standardbody.clientHeight: window.innerHeight;
      var docheightcomplete=(standardbody.offsetHeight>standardbody.scrollHeight)? standardbody.offsetHeight : standardbody.scrollHeight;
      var veilDivEl = document.getElementById('veilDiv');
      veilDivEl.style.width=docwidth+"px"; //set up veil over page
      veilDivEl.style.height=docheightcomplete+"px"; //set up veil over page
      veilDivEl.style.visibility="visible"; //Show veil over page

      var popup = document.getElementById(obj);
      var objwidth = popup.offsetWidth;
      var objheight = popup.offsetHeight;
      popup.style.visibility="visible"; //Show interstitial box
      popup.style.left=docwidth/2-objwidth/2+"px"; // Center popup horizontally
      var topposition=(docheight>objheight)? scroll_top+docheight/2-objheight/2+"px" : scroll_top+5+"px"; // Center popup vertically
      popup.style.top=Math.floor(parseInt(topposition))+"px";
    
      var is_ie6 = document.all && (navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1);
      if (is_ie6) {
         var html =
            "<iframe style=\"position: absolute; display: block; " +
            "z-index: -1; width: "+docwidth+"px; height: "+docheightcomplete+"px;top: -"+docheightcomplete/3+"px; left: -"+docwidth/3+"px;" +
            "filter: mask(); border: 1px solid #CCCCCC; background-color: #FFFFFF; \"></iframe>";
         if (popup) popup.innerHTML += html;
      }
}
/**
 * Displays a popup on the web page. Popups created by this script will automatically position their top-right
 * corner at the locaton from which they were called. To modify the positioning, provide an offset for x and
 * y. Note: if using the CSS attribute "filter: mask()" causes problems, a similar approach would be to use
 * the following in its place "filter: alpha(opacity=0); -moz-opacity: 0;".
 *
 * @param objLink  the id of the link from which this popup was called (used for positioning).
 * @param obj      the id of the hidden div to display
 * @param offsetX  the x offset for positioning
 * @param offsetY  the y offset for positioning
 */
function showPopup(objLink, obj, offsetX, offsetY) {

  var is_ie6 = document.all && (navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1);
  var popup = document.getElementById(obj);
  var link = document.getElementById(objLink);
  var posX = findPosX(link);
  var posY = findPosY(link);

      popup.style.left = posX + offsetX + "px";
      popup.style.top = posY + offsetY + "px";

  if (is_ie6) {
     var html =
        "<iframe style=\"position: absolute; display: block; " +
        "z-index: -1; width: 1000px; height: 1000px; top: -1px; left: -2px; overflow: hidden;" +
        "filter: mask(); border: 1px solid #CCCCCC; background-color: #FFFFFF; \"></iframe>";
     if (popup) popup.innerHTML += html;
  }
    popup.style.display = "block";
}

/******************************************************************************
/* Toggles the display of the search criteria table
/******************************************************************************/

var viewText = "View Search Criteria";
var hideText = "Hide Search Criteria";
var iconExpanded = "../images/icon-expanded-sign.gif";
var iconCollapsed = "../images/icon-collapsed-sign.gif";

function expandDiv(obj) {
    var o = document.getElementById(obj);
    var r = document.getElementById("searchCriteraLink");
    var i = document.getElementById("iconExpandCollapse");

    if ((o.style.display) == "block") {
        o.style.display = "none";
        i.setAttribute('src', iconCollapsed);
    } else {
        o.style.display = "block";
        i.setAttribute('src', iconExpanded);
    }

    if (r.innerHTML == viewText) {
        r.innerHTML = hideText;
    } else {
        r.innerHTML = viewText;
    }
}

function collapseDiv(obj) {
    document.getElementById(obj).style.display = "none";
    document.getElementById("searchCriteraLink").innerHTML = viewText;
}


/******************************************************************************
/* Functions to automatically set and reset the region field on the search form.
/*  Resets the region select box if the user resets the form or if the function
/* is called from within the swapRegion() function
/*  REMOVED DUE TO THE REMOVAL OF THE REGION FIELD FROM THE SEARCH FORM
/******************************************************************************

 function resetRegion() {
    var x = document.getElementById("selectRegion");
    x.disabled = false;
    x.reset();
 }
*/

/* For each state, there is only one region, but for each region there are
 * multiple states. This function sets the appropriate region when a user selects
 * a state. For example: User selects 'Maryland', the region will automatically
 * select 'South' and will become disabled. Selecting 'All States' will re-enable
 * region select box.
 *
 * West = AK AZ CA CO HI MT NM NV OR UT WA WY
 * Central = IA IL IN KS MI MN MO NB ND OH OK SD WI
 * South = AL AR DC DE FL GA KY LA MD MS NC SC TN TX VA WV
 * East = CT MA ME NH NJ NY PA RI VT
 *
 * region.selectedIndex:
 * 0 = All Regions
 * 1 = West
 * 2 =
 * 3 = South
 * 4 = Central

  function swapRegion() {
    var region = document.getElementById("selectRegion");
    var state = document.getElementById("selectState");

      switch(state.options[state.selectedIndex].value)
      {
        // West
        case "AK":
        case "AZ":
        case "CA":
        case "CO":
        case "HI":
        case "MT":
        case "NM":
        case "NV":
        case "OR":
        case "UT":
        case "WA":
        case "WY":
          region.selectedIndex = 1;       // West
          break;
        // Central
        case "IA":
        case "IL":
        case "IN":
        case "KS":
        case "MI":
        case "MN":
        case "MO":
        case "NB":
        case "ND":
        case "OH":
        case "OK":
        case "SD":
        case "WI":
          region.selectedIndex = 4;      // Central
          break;
        // South
        case "AL":
        case "AR":
        case "DC":
        case "DE":
        case "FL":
        case "GA":
        case "KY":
        case "LA":
        case "MD":
        case "MS":
        case "NC":
        case "SC":
        case "TN":
        case "TX":
        case "VA":
        case "WV":
          region.selectedIndex = 3;      // South
          break;
        // East
        case "CT":
        case "MA":
        case "ME":
        case "NH":
        case "NJ":
        case "NY":
        case "PA":
        case "RI":
        case "VT":
          region.selectedIndex = 2;      // East
          break;
        default:
          region.selectedIndex = 0;
          break;
      } // end switch

      if (state.selectedIndex != 0) {           // If a state is selected
        region.disabled = true;                 // disable the region select;
      } else {                                  // otherwise,
        resetRegion();                          // reset and enable it
      }
  }
*/
