/* Global variables */
var NAV_OVER = "7CA6CF";
var NAV_OFF = "B3D0EC";
var TAB_OVER = "FFFFFF";
var TAB_OFF = "DEE7ED";
/* end Global variables */

////////////////////////////////////////////
// Function: stat
//
// Purpose:
// Hides browser status message.
//
// Arguments: None
//
////////////////////////////////////////////
function stat(){
window.status=""
return true
}

////////////////////////////////////////////
// Function: getBTime
//
// Purpose:
// Returns a timestamp.
//
// Arguments: None
//
////////////////////////////////////////////
function getBTime(){
  var d = new Date();
  return d.getTime();
}

////////////////////////////////////////////
// Function: hover
//
// Purpose:
// changes the bgColor style of an element.
//
// Arguments: None
//
////////////////////////////////////////////
function hover(object,color){
  object.bgColor = color;
}

////////////////////////////////////////////
// Function: swapClass
//
// Purpose:
//   changes the class of an object
//
// Arguments: 1) the id of the object to change
//            2) the name of the new class
//
////////////////////////////////////////////
function swapClass(object_id,class_name){
    document.getElementById(object_id).className = class_name;
}

////////////////////////////////////////////
// Function: killWin
//
// Purpose:
//  Sets browser history to empty and closes
//  the window
//
// Arguments: None
//
////////////////////////////////////////////
function killWin(){
  window.opener.focus();
  top.window.close();
}

////////////////////////////////////////////
// Function: lgPop
//
// Purpose:
// opens a new window at 500x400
//
// Arguments:
//    name    = the name of the new window.
//    url     = the url of the window
//    offest  = [optional] the xy location of
//              the new window.
//
////////////////////////////////////////////
var createLgPop;
function lgPop(name,url,offset) {
if(offset==null){
  offset = 50;
}
createLgPop = window.open(url,name,'toolbar=no, directories=no, location=no, status=no, menubar=no, resizable=no, scrollbars=no, width=500, height=400,screenX=' + offset + ',screenY=10' + ',left=' + offset + ',top='+offset );
createLgPop.focus();
}

////////////////////////////////////////////
// Function: smPop
//
// Purpose:
// opens a new window at 300x150
//
// Arguments:
//    name    = the name of the new window.
//    url     = the url of the window
//
////////////////////////////////////////////
var createSmPop;
function smPop(name,url) {
createSmPop = window.open(url,name,'toolbar=no, directories=no, location=no, status=no, menubar=no, resizable=no, scrollbars=no, width=300, height=150');
createSmPop.focus();
}

////////////////////////////////////////////
// Function: basicPop
//
// Purpose:
// opens a new window at 500x250
//
// Arguments:
//    name    = the name of the new window.
//    url     = the url of the window
//
////////////////////////////////////////////
var CreateBasicPop;
function basicPop(url) {
CreateBasicPop = window.open(url,'basicView','toolbar=no, directories=no, location=no, status=no, menubar=no, resizable=no, scrollbars=no, width=250, height=500');
CreateBasicPop.focus();
}

////////////////////////////////////////////
// Function: tabHover
//
// Purpose:
// changes the font style of an element.
//
// Arguments: None
//
////////////////////////////////////////////
function tabHover(object,color){
  object.style.color= color;
}

////////////////////////////////////////////
// Function: go
//
// Purpose:
//  replaces the location of the window w/ a
//  specified url
//
//  NOTE:
//    If you are attempting to pass in url
//    encoded hrefs to this function, the way
//    you deal w/ it depends largely on the
//    type of element you are adding it to. if
//    you are using it in an href w/ a
//    'javascript:' call, it will unescape the
//    url encoding. otherwise you need to use
//    the unescape() function.
//
//
// Arguments: url
//
////////////////////////////////////////////
function go(url){
  if (browser.ns){
    window.location.replace(url);
  }
  else{
    window.location.href(url);
  }
}

////////////////////////////////////////////
// Function: checkBoxer
//
// Purpose:
// calls checkIt()
//
// Arguments:
//    thisObj = the object you are clicking
//    id      = id of the form to affect.
//    imgPath = the partial image path as created
//              by vss (b/c the js function is called
//              w/in a template, the image calls
//              are made relative to that document's
//              location)
//    theName = the name of the form element to check.
//
////////////////////////////////////////////
function checkBoxer(thisObj,id,imgPath,theName) {
thisElem = document.getElementById(thisObj);
bx = document.getElementById('checkBoxer');
  if(bx.checked){
    checkIt(id,false,theName);
    bx.checked = false;
    thisElem.style.background='url('+imgPath+'/checkOff.gif)';
  }
  else
  {
    checkIt(id,true,theName);
    bx.checked = true;
    thisElem.style.background='url('+imgPath+'/checkOn.gif)';
  }
}

////////////////////////////////////////////
//  Function: checkIt
//
//  Purpose:
//  checks or unchecks all the checkboxes in a
//  given form
//
//  Arguments:
//    id      = id of the form to affect.
//    value   = true or false of checked
//    theName = the name of the form element to check.
//
////////////////////////////////////////////
function checkIt(id,value,theName) {
var thisForm = document.getElementById(id);
len = thisForm.elements.length;
if (theName==''||theName==' '||theName==undefined){
theName = 'Mid';
}
for( i=0 ; i<len ; i++) {
    if (thisForm.elements[i].name==theName) {
          thisForm.elements[i].checked=value;
    }
  }
}

////////////////////////////////////////////
//  Function: flipTo
//
//  Purpose:
//  removes a specified name-value pair from
//  document url and then reloads the page.
//
//  Arguments:
//    pair    = the name-value pair to remove
//              from the url.
//
////////////////////////////////////////////
function flipTo(pair) {
queryString = document.location.search;
newQS = queryString.replace(';'+pair, '');
  document.location.replace(newQS);
}

////////////////////////////////////////////
//  Function: updateQueryValue
//
//  Purpose:
//  removes a specified name-value pair from
//  document url and then returns the new query.
//
//  Arguments:
//    pair    = the name-value pair to remove
//              from the url.
//    newPair = the name-value pair to replace
//              it with.
//
////////////////////////////////////////////
function updateQueryValue(queryString, pair, newPair) {
////////////////////////////////////////////
//  Strip the pair
////////////////////////////////////////////
  newQS = queryString.replace(pair, '');
////////////////////////////////////////////
//  Check if there is a newPair and if the
//  current value of newQS has any values other
//  than a question mark or semicolon
////////////////////////////////////////////
  if (newPair && newQS.length>1){
      newQS = newQS+'&'+newPair;
    }
    else if(newPair){
      newQS = '?'+newPair;
    }
////////////////////////////////////////////
//  cleanup extra ampersands
////////////////////////////////////////////
 while(newQS.match(/&&/)){
    newQS = newQS.replace('&&', '&');
   }
////////////////////////////////////////////
//  test if there is still a ?
////////////////////////////////////////////
  if(hasChar(newQS,'?')) newQS =+ '?';
////////////////////////////////////////////
//  return the new QS.
////////////////////////////////////////////
  return newQS;
}

////////////////////////////////////////////
//  Function: hasChar
//
//  Purpose:
//  checks for a given char
//
//  Arguments:
//    inputString = string to test
//    char        = character to look for
//
////////////////////////////////////////////
function hasChar(inputString,character){
var strArray = inputString.split('');
for (o=0; o<strArray.length; o++){
      if(strArray[o].charCodeAt(0) == character){
        return true
      }
  }
return false
}

////////////////////////////////////////////
//  Function: testForm
//
//  Purpose:
//  checks for null or empty string values in an
//  array of form elements.
//
//  Arguments:
//    idList    = comma separated list of form
//                element ids.
//
//  Usage:
//  a href="javascript:if(!testForm('1,2,3,4,5,6,7')){
//    alert('false'); //do nothing
//  }
//  else{
//    alert('bang on'); //submit form
//  };"
//
////////////////////////////////////////////
function testForm(idList) {

var idArray = idList.split(',');
var o = 0;
  for (i=0; i<idArray.length; i++){
  var thisElem = document.getElementById(idArray[i]);
    if (thisElem.value==""||thisElem.value==" "){
    o++;
    }
  }
if(o!==0){return false;}else{return true;}
}

////////////////////////////////////////////
// Function: show
//
// Purpose:
// sets visibility of a given object to visible
//
// Arguments:
//    id      = id of the object to show.
//
////////////////////////////////////////////
function show(id) {
  document.getElementById(id).style.visibility = "visible";
}


////////////////////////////////////////////
// Function: hide
//
// Purpose:
// sets visibility of a given object to hidden
//
// Arguments:
//    id      = id of the object to hide.
//
////////////////////////////////////////////
function hide(id) {
  document.getElementById(id).style.visibility = "hidden";
}


////////////////////////////////////////////
// Function: checkOctet
//
// Purpose:
// Validates the input string for a simple match of
// the octet definition.
//
// Returns:
// true or false
//
// Arguments:
//    id          = id of the object holding the string
//                  to be validated.
//
////////////////////////////////////////////
function checkOctet(id){
// NEEDS A LITTLE WORK. THE REGEX WILL ACCEPT REPETITIIONS OF THE '###.' VALUES.
inputString = new String(document.getElementById(id).value);
var checkThis = new RegExp("[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$");
  if (checkThis.test(inputString)){
    return true;
  }
  else{
    return false;
  }
}

////////////////////////////////////////////
// Function: addOption
//
// Purpose:
// Moves a value from one element to the
//
// Arguments:
//    fromId        = id of the object holding the string
//                    to be added.
//    toId          = id of the select box where the string
//                    is to be added.
//    optIndex      = intended index of the new element,
//                    an optIndex of the value 'last' will
//                    show up at the bottom of the list.
//
////////////////////////////////////////////
function addOption(fromId,toId,optIndex){
newOpt = new Option(document.getElementById(fromId).value , document.getElementById(fromId).value);
toElem = document.getElementById(toId);
if (document.getElementById(fromId).value!==""){
  if (optIndex=="last"){
    toElem.add(newOpt, toElem.length);
  }
  else{
    toElem.add(newOpt, optIndex);
  }
}
//now clear out the field
document.getElementById(fromId).value = "";
}

////////////////////////////////////////////
// Function: removeSelected
//
// Purpose:
// Moves a value from one element to the
//
// Arguments:
//    id            = id of the select area to remove
//                    an option from.
//
////////////////////////////////////////////
function removeSelected(id){
thisElem = document.getElementById(id);
thisOpt = thisElem.selectedIndex;
  if (thisOpt=="-1"){
    //no option selected. Skip.
  }
  else
  {
    thisElem.remove(thisOpt);
  }
}

////////////////////////////////////////////
// Function: focusElem
//
// Purpose:
// Moves the cursor to a given element.
//
// Arguments:
//    id            = id of the element to focus.
//
////////////////////////////////////////////
function focusElem(id){
  document.getElementById(id).focus();
}

////////////////////////////////////////////
// Function: confirmAction
//
// Show the confirmation dialog with the given message.
//    If the user selects 'ok', then follow the link.
//    Otherwise, return.
//
// Arguments:
//    message = message to display in the confirmation prompt
//      action_url = URL with which to refresh the window.
//
////////////////////////////////////////////
function confirmAction( message, action_url ){
    if(confirm(message))
    {
        window.location=action_url;
    }
}

////////////////////////////////////////////
// Function: browser
//
// Purpose:
// Inspects the browser user-Agent and
// returns a series of boolean values.
//
// Arguments: None
//
////////////////////////////////////////////

browser = {};
browser.ua  = navigator.userAgent.toLowerCase() ;
browser.dom = document.getElementsByTagName ? 1 : 0 ;     // supports the DOM
browser.dom = browser.dom && !(browser.ua.match(/opera/) ? 1 : 0) ; // sorry, not Opera just yet
browser.gek = browser.ua.match(/gecko/) ? 1 : 0 ;              // mozilla and netscape 6
browser.ns  = browser.ua.match(/netscape/) ? 1 : 0 ;           // netscape 6.x
browser.ns60= browser.ua.match(/netscape6\/6\.0/) ? 1 : 0 ;    // netscape 6.0
browser.moz = browser.gek && !browser.ns ;                          // mozilla
browser.ie  = browser.ua.match(/msie/) ? 1 : 0 ;               // IE5.x and IE6.x
browser.ie5 = browser.ua.match(/msie 5/) ? 1 : 0 ;             // IE5.x
browser.ie50= browser.ua.match(/msie 5\.0/) ? 1 : 0 ;          // IE5.0
browser.ie55= browser.ua.match(/msie 5\.5/) ? 1 : 0 ;          // IE5.5
browser.ie6 = browser.ua.match(/msie 6/) ? 1 : 0 ;             // IE6.x
browser.mac = browser.ua.match(/mac/) ? 1 : 0 ;           // macintosh platform


////////////////////////////////////////////
// Function: padZeros
//
// Purpose:
//  Pads single digit numbers with zero for
//  use with two-digit times
//
// Arguments:
//    num         a number to pad
//
////////////////////////////////////////////
function padZeros(num){
  if (num < 10)
  {
    return "0" + num;
  }

  return "" + num;
}


////////////////////////////////////////////
// Function: overHandler
//
// Purpose:
//  handles mouseover events for all buttons
//
// Arguments: None
//
////////////////////////////////////////////
function overHandler(){
  if(this.type=='button'||this.type=='submit'){
  var oClass = this.className.split(' ');
    if(oClass[1] == 'b'){ this.className = oClass[0]+ ' bOver'; }
    if(oClass[1] == 'c'){ this.className = oClass[0]+ ' cOver'; }
    if(oClass[1] == 'd'){ this.className = oClass[0]+ ' dOver'; }
    if(oClass[1] == 'e'){ this.className = oClass[0]+ ' eOver'; }
  }
}

////////////////////////////////////////////
// Function: outHandler
//
// Purpose:
//  handles mouseout events for all buttons
//
// Arguments: None
//
////////////////////////////////////////////
function outHandler(){
  if(this.type=='button'||this.type=='submit'){
    var oClass = this.className.split(' ');
    if(oClass[1] == 'bOver'){ this.className = oClass[0]+ ' b'; }
    if(oClass[1] == 'cOver'){ this.className = oClass[0]+ ' c'; }
    if(oClass[1] == 'dOver'){ this.className = oClass[0]+ ' d'; }
    if(oClass[1] == 'eOver'){ this.className = oClass[0]+ ' e'; }
  }
}

////////////////////////////////////////////
// Function: initStyles
//
// Purpose:
//  turns on style event listners
//
// Arguments: None
//
////////////////////////////////////////////
function initStyles(){
inputs = document.getElementsByTagName('input');
for(i=0;i<inputs.length;i++){
    inputs[i].onmouseover = overHandler;
    inputs[i].onmouseout = outHandler;
  }
}