var js_server_path = location.pathname.replace('.asp','');
var js_pathparts = js_server_path.split("/");

// BEGIN BREAK OUT OF FRAMES

function bustFrames(){
  if (window != top){
    top.location.href=location.href
  }
}

// END BREAK OUT OF FRAMES



// BEGIN FIELD-CLEARING FUNCTION

function clearField(field){
  if (field.value == field.defaultValue) {
    field.value = "";
  }
}

function clearDefault(el) 
{
	if (el.defaultValue==el.value) el.value = "";
}
function changeDefault(el) {
	if (el.value == "") el.value = el.defaultValue;
}


// END FIELD-CLEARING FUNCTION

// BEGIN DHTML FUNCTIONS

// initRollovers - Find all images that have the class "roll", and set events for each (avoids needing to add event handling to image tags)
// - loops through all image tags on the page, and skips any that have no 'roll' class

function initRollovers()
{
  // Set rollstate variable (this is typically either 'on' or 'over')
  var roll_state = "over";
  // Loop through all im if they contain the class roll
  var imgs=document.getElementsByTagName('img');
  for(i=0;i<imgs.length;i++){
    img_obj = imgs[i];
    if(/roll/.test(img_obj.className)){

      // add the function roll to the parent Element (i.e a href) of the image
      img_obj.parentNode.onmouseover=function(){rollOver(this, roll_state);};
      img_obj.parentNode.onmouseout=function(){rollOver(this, '');};
      img_obj.parentNode.onfocus=function(){rollOver(this, roll_state);};
      img_obj.parentNode.onblur=function(){rollOver(this, '');};
      // Preload images (on and over variations)
      img_width = img_obj.width;
      img_height = img_obj.height;
      img_name = img_obj.id;
      img_ext = img_obj.src.substring(img_obj.src.lastIndexOf('.'), img_obj.src.length);

      // Preload 'over' images (if applicable)
      img_name_over = img_name.replace("_button", "_over");
      eval (img_name_over + " = new Image(" + img_width + "," + img_height + ")" );
      eval (img_name_over + ".src = \"" + img_obj.src.replace(img_ext, "_over" + img_ext) + "\"");

      // Preload 'on' images (if applicable)
      img_name_on = img_name.replace("_button", "_on");
      eval (img_name_on + " = new Image(" + img_width + "," + img_height + ")" );
      eval (img_name_on + ".src = \"" + img_obj.src.replace(img_ext, "_on" + img_ext) + "\"");
    }
  }
}

// initSmartNav - Highlights all navigation for current page (at each level)
// - loops through each part of path (parts = directory or filename)

function initSmartNav(){
  pathparts = js_pathparts;
  // Specify filename suffix for highlighted nav
  var hl_suffix = "_on";
  // Loop through path parts to find navigation matches
  for(i=0;i<pathparts.length;i++){
    pathpart = pathparts[i];
    // If pathpart is not empty and if element exists with pathpart and '_button' as it's ID
    if (pathpart.length > 0 && document.getElementById(pathpart+'_button')){
      navbutton = document.getElementById(pathpart+'_button');
      // If navbutton doesn't already include hl_suffix in the filename add it (new src = everything before the period, then hl_suffix, then everything after)
      if (navbutton.src.indexOf(hl_suffix) == -1){
        img_ext = navbutton.src.substring(navbutton.src.lastIndexOf('.'), navbutton.src.length);
        navbutton.src= navbutton.src.replace(img_ext, hl_suffix+img_ext);
      }
      disable_rollover_effects(navbutton);
    }
  }
}

function disable_rollover_effects(butt){
  // Disable rollover effects for highlighted nav
  butt.parentNode.onmouseover=null;
  butt.parentNode.onmouseout=null;
  butt.parentNode.onfocus=null;
  butt.parentNode.onblur=null;
}

function rollOver(obj, rollstate){
  var i,isnode,src,ftype,newsrc,nownode;
  // loop through all childNodes (i.e. img within a)
  for (i=0;i<obj.childNodes.length;i++){
    nownode=obj.childNodes[i];
    // if the node is an element and an IMG set the variable and exit the loop
    if(nownode.nodeType==1 && /img/i.test(nownode.nodeName)){
      isnode=i;
      break;
    }
  }
  // check src and do the rollover
  img_src = obj.childNodes[isnode].src;
  ftype = img_src.substring(img_src.lastIndexOf('.'), img_src.length);
  if(/_on/.test(img_src)){
    currstate = 'on';
  }
  else if(/_over/.test(img_src)){
    currstate = 'over';
  }
  else{
    currstate = '';
  }
  newsrc = '';
  if (currstate != rollstate){
    newsrc = img_src.replace(ftype, '_'+rollstate+ftype);
  }
  else{
    return;
  }
  if (rollstate.length == 0){
    newsrc = img_src.replace('_'+currstate, '');
  }
  if (newsrc.length != 0){
    obj.childNodes[isnode].src=newsrc;
  }
}

// END DHTML FUNCTIONS

// WINDOW FUNCTIONS
function loadPopup(url, name, width, height, chrome, scrollbars, resizable, centered) {
  // For chrome, scrollbars, resizable, centered use 1 or 0
  if (centered == 1){
    var winleft = Math.round((screen.width-width)/2);
    var wintop = Math.round((screen.height-height)/2);
    if (chrome == 1){
      wintop = wintop - 80;
    }
    else{
      wintop = wintop - 30;
    }
    if (wintop < 0) wintop = 0;
  }
  var features = '';
  features = features + 'width=' + width;
  features = features + ',height=' + height
  if (chrome == 1){
    features = features + ',directories=1,location=1,menubar=1,status=1,toolbar=1';
  }
  else{
    features = features + ',directories=0,location=0,menubar=0,status=0,toolbar=0';
  }
  features = features + ',resizable=' + (resizable - 0);
  features = features + ',scrollbars=' + (scrollbars - 0);
  if (winleft > 0 && wintop > 0){
    features = features + ',left=' + (winleft - 0);
    features = features + ',top=' + (wintop - 0);
  }
  //alert("Features: " + screen.width + "/" + screen.height + " -- " +features);
  popup = window.open (url, name, features);
  popup.focus();
  return void(0);
}

// To close a window use... window.close();
// To print use... window.print();
// To redirect use... window.location = "http://www.google.com/";


// Begin Show and Hide Layers

function showLayer (layer_id) {
  document.getElementById(layer_id).style.display='block';
}
function hideLayer (layer_id) {
  document.getElementById(layer_id).style.display='none';
}

// End Show and Hide layers
