// JavaScript Document



/**********************************
  Macromedia Javascript Functions
**********************************/

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images) { if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0) { d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null) {document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)) {
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function MM_jumpMenu(targ,selObj,restore) { //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

// directly swap an image using the element as the parameter
function swapImageObj(obj, ima) {
  obj.src = ima;
}

function confirmDelete(delUrl, message) {
  if (confirm("Are you sure you want to remove "+message+"?")) {
    document.location = delUrl;
  }
}

/******************************
  Window popup
*******************************/
var photoWin;
function popupWin(URL, winName, features) {
  photoWin=window.open(URL,winName,features)
  if (window.focus) {photoWin.focus()}
}

/**********************************
  Changes the selected value of a
  drop-down menu 
**********************************/

function changeMenu(id, index) {
 var _menu = document.getElementById(id);
 _menu.selectedIndex = index;
}



/**********************************
  Email Obfuscator
   - prevents email addresses from 
     being read by spammers
**********************************/

function mail2(box, dom, tld, display) {
  var ref = box + "@" + dom + "." + tld;
  if(display.length == 0) display = ref;
  document.write("<a" + " href" + "=mail" + "to:" + ref + ">" + display + "</a>");
}


/**********************************
  Bookmark a page
**********************************/

function setBookmark(urlAddress, pageName) {
  if (window.external) {
    window.external.AddFavorite(urlAddress,pageName)
  } else { 
    alert('Press CTRL and D to add a bookmark to:\n"'+urlAddress+'".');
  }
}


/**********************************
  Turn off and on content
**********************************/

function toggleVisibility(id) {
  var obj = document.getElementById(id);
  if (obj.style.visibility == 'hidden') {
    obj.style.visibility = "visible";
  } else {
    obj.style.visibility = "hidden";
  }  
}


function toggleDisplay(id) {
  var obj = document.getElementById(id);
  if (obj.style.display == 'none') {
    obj.style.display = "";
  } else {
    obj.style.display = "none";
  }  
}

var display_group = "";
function toggleDisplayGroup(num, prefix, num_items) {
  // hides page content where the id= prefix+1,2,3... num_items
  // shows page content where the id=prefix+num
  // if set, var_to_increment is an external variable that tracks the index of the currently displayed item
  // set var_to_increment to the new value, then display the id at that value
  if (arguments.length > 3) {
    var var_to_increment = arguments[3];
    // if next_or_prev is specified, value_to_increment will be increased or decreased as directed
    // set the var_to_increment value to the next, or previous available number
    if (arguments.length > 4) {
     var next_or_prev = arguments[4];
      switch (next_or_prev) {
        case 'next':
          if (eval(var_to_increment+" + 1") > num_items) {
            eval(var_to_increment+" = 1");
          } else {
            eval(var_to_increment+" += 1");
          }
          break;
        case 'prev':
          if (eval(var_to_increment+" - 1") <= 0) {
            eval(var_to_increment+" = "+num_items);
          } else {
            eval(var_to_increment+" -= 1");
          }
          break;
      }
    } else {
      if (num > 0 && num <= num_items) {
        eval(var_to_increment+" = "+num);
      }
    }
    var id = prefix + eval(var_to_increment);
    var element, current_id;
    for (var i=1; i<=num_items; i++) {
      current_id = prefix+i;
      element = document.getElementById(current_id);
      if (current_id == id) {
        display_group = current_id;
        element.style.display = "block";
      } else {
        element.style.display = "none";
      }
    }
  } else {
    var id = prefix + num;
    var element, current_id;
    var is_equal = false;
    for (var i=1; i<=num_items; i++) {
      current_id = prefix+i;
	  
      element = document.getElementById(current_id);
      if (num > 0) {
        is_equal = (current_id == id) ? true : false;
      } else {
        is_equal = true;      
      }
      if (is_equal) {
        display_group = current_id;
        element.style.display = "block";
      } else {
        element.style.display = "none";
      }
    }  
  }
}

function toggleOut() {
  var element = document.getElementById(display_group);
  element.style.display = "none";
}

function toggleImage(id, on, off) {
  var obj = document.getElementById(id);
  if (obj.src == on) {
    MM_changeProp(id,'','src',off,'IMG');
  } else if (obj.src == off) {
    MM_changeProp(id,'','src',on,'IMG');
  }
}

function toggleImageGroup(num, prefix, num_items) {
  // turns back image whose id= prefix+1,2,3... num_items
  // toggles image whose the id=prefix+num
  // image_on and image_off are global vars (defined on the page that uses them)
  var on = image_on;
  var off = image_off;
  var id = prefix+num;
  var current_id;
  for (var i=1; i<=num_items; i++) {
    current_id = prefix+i;
    if (current_id == id) {
      toggleImage(current_id, on, off);
    } else {
      MM_changeProp(current_id,'','src',off,'IMG');
    }
  }
}

/**********************************
  Find the x y coords of an element
   - http://www.quirksmode.org/js/findpos.html
**********************************/

function findPosX(obj) {
  var curleft = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curleft += obj.offsetLeft
      obj = obj.offsetParent;
    }
  }
  else if (obj.x)
    curleft += obj.x;
  return curleft;
}

function findPosY(obj) {
  var curtop = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curtop += obj.offsetTop
      obj = obj.offsetParent;
    }
  }
  else if (obj.y)
    curtop += obj.y;
  return curtop;
}


function swapClass(obj, classname) {
  obj.className = "";
}

function toggleClassGroup(obj, prefix, num_items, on_class, off_class) {
  var current_id;
  for (var i=1; i<=num_items; i++) {
    current_id = prefix+i;
    current_obj = document.getElementById(current_id);
    current_obj.className = off_class;
  }
  obj.className = on_class;
}


/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/

function getElementsByClassName(oElm, strTagName, strClassName) {
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}


function showAttachedLayer(id_of_layer, obj, offset_y) {
  // REQUIRES: findPosY, findPosX
  var layer = document.getElementById(id_of_layer);
  var _x = findPosX(obj);
  var _y = findPosY(obj);
  _y += (arguments.length > 2) ? arguments[2] : 0;
  // alert('x: '+_x+' y: '+_y);
  layer.style.top = _y + 'px';
  layer.style.left = _x + 'px';
  // alert('x: '+layer.style.left+' y: '+layer.style.top);
  layer.style.visibility = "visible";
}

function hideAttachedLayer(id_of_layer) {
  var layer = document.getElementById(id_of_layer);
  layer.style.visibility = "hidden";
}



/**********************************
  Enlarge photo pop up
   - prevents window focus from 
     hiding behind the main window
**********************************/

var photoWin;
function openBrWindow(theURL, winName, features, center) {
  if (arguments.length > 3 && arguments[3]) {
    // get the width and height out of the features string
    // assumes the window width and height will be between 100 and 999 (3-digits)
    var my_width = (features.indexOf('width=') != -1) ? parseInt(features.substr(features.indexOf('width=') + 6, 3)) : 400;
    var my_height = (features.indexOf('height=') != -1) ? parseInt(features.substr(features.indexOf('height=') + 7, 3)) : 400;
    var x_pos = (screen.width / 2) - (my_width / 2);
    var y_pos = (screen.height / 2) - (my_height / 2);
    features += ',top='+x_pos+',left='+y_pos;
  }
  photoWin=window.open(theURL,winName,features);
  if (window.focus) {
    photoWin.focus();
  }
}



/**********************************
  Change the background image
**********************************/

function swapBg(id, url) {
  var obj = document.getElementById(id);
  obj.style.backgroundImage = 'url('+url+')';
}

function swapBgObj(obj, url) {
  obj.style.backgroundImage = 'url('+url+')';
}

function swapBgColor(obj, color) {
  obj.style.backgroundColor=color;
}



/**********************************
  Set Rollovers on table columns
**********************************/

function initTableColumns(id) {
  var tbl = document.getElementById(id);
  var trs = tbl.getElementsByTagName('tr');
  for (var j=0; j<trs.length; j++) {
    var tr_node = trs[j];
    if (tr_node.nodeName.toLowerCase() == 'tr' && tr_node.getElementsByTagName('td').length > 0) {
      var tds = tr_node.getElementsByTagName('td');
      for (var i=0; i<tds.length; i++) {
        var node = tds[i];
        addEvent(node, 'mouseover', bgOn(node), false);
        addEvent(node, 'mouseout', bgOff(node), false);
      }
    }
  }
  addEvent(window, 'unload', EventCache.flush, false);
}

function addEvent(e1m, evType, fn, useCapture) {
  // cross-browser event handling for IE5+, NS6 and Mozilla
  // By Scott Andrew
  if (e1m.addEventListener) {
    e1m.addEventListener(evType, fn, useCapture);
    return true;
  } else if (e1m.attachEvent) {
    var r = e1m.attachEvent('on' + evType, fn);
    // EventCache from file: event-cache.js
    // manages events to prevent memory-leak in IE
    EventCache.add(e1m, evType, fn);
    return r;
  } else {
    e1m['on' + evType] = fn;
  }
}

function bgOn(obj) {
  var color = '#E8F3F7';
  obj.style.backgroundColor=color;
}
function bgOff(obj) {
  var color = '#F4F9FB';
  obj.style.backgroundColor=color;
}


/**********************************
  Cookie scripts
  from: http://www.quirksmode.org/js/cookies.html
**********************************/

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function eraseCookie(name) {
  createCookie(name,"",-1);
}

var popup_y_offset = -150;
var popup_on_color = '#E8F3F7';
var popup_off_color = '#FFFFFF';

//////////////////////////
// Email Obfuscator
// <a href="/site_map.phtml" onMouseOver="SetHREF(this, 'kyle', 'firstnetimpressions', 'com', 'FNI - Website Inquiry')" onFocus="SetHREF(this, 'kyle', 'firstnetimpressions', 'com', 'FNI - Website Inquiry')"><script>address("kyle", "firstnetimpressions", "com");< /script></a>
//////////////////////////

function address(name, dom, tld)
{
  var addr = name + '@' + dom + '.' + tld;
  document.write(addr);
}

function SetHREF(obj, box, dom, tld, sbj)
{
  var addr = 'mailto:' + box + '@' + dom + '.' + tld;
  addr = (sbj != null) ? addr + '?subject=' + sbj : addr;
  obj.href = addr;
}