Prv8 Shell
Server : Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4
System : Linux server.jackjohnson.com 2.6.32-279.5.2.el6.x86_64 #1 SMP Fri Aug 24 01:07:11 UTC 2012 x86_64
User : jackjohn ( 502)
PHP Version : 5.3.17
Disable Function : NONE
Directory :  /home/jackjohn/www/style/javascript/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/jackjohn/www/style/javascript/common.js
// ----------------------------------------------------------------------------
// Common Functions - Javascript Library
// Copyright (C) 2003-2004, All Rights Reserved
// ----------------------------------------------------------------------------
// This program is protected by local and international copyright laws. Any
// use of this program is subject to the the terms of the license agreement
// included as part of this distribution archive. Any other uses are stictly
// prohibited without the written permission of the Vendor and all other
// rights are reserved.
// ----------------------------------------------------------------------------

// -----------------------------------------------------------------------------
// Function    : toggleVisibilityOnElementsById
// Description :
// Usage       : <input type="checkbox" ... onclick="toggleVisibilityOnElementsById(this.checked, ['elementId', 'elementId']);">
// -----------------------------------------------------------------------------

function toggleVisibilityOnElementsById(visibilityBool, elements) {

  if (visibilityBool) { showElementsById(elements); }
  else                { hideElementsById(elements); }

}

/* ------------------------------------------------------------------------- *\
  Function    : show
  Description : make the listed elements visible
  Usage       : show(elementNameArray);
\* ------------------------------------------------------------------------- */

function showElementsById(showArray) {
  hideAllExcept(showArray, []);
}

/* ------------------------------------------------------------------------- *\
  Function    : hide
  Description : hide the listed elements
  Usage       : hide(elementNameArray);
\* ------------------------------------------------------------------------- */

function hideElementsById(hideArray) {
  hideAllExcept([], hideArray);
}

/* ------------------------------------------------------------------------- *\
  Function    : hideAllExcept
  Description : hide all elements except the ones listed in showList.
  Usage       : hideAllExcept(showList, allElements);
\* ------------------------------------------------------------------------- */

function hideAllExcept(showArray, allElements) {

  if (typeof showArray != 'object')   { error('first argument must be an array'); }
  if (typeof allElements != 'object') { error('second argument must be an array'); }

  // build hash of elements
  var elementList = new Object();
  for (var n=0; n < allElements.length; n++) { elementList[ allElements[n] ] = 'hide'; }
  for (var n=0; n < showArray.length; n++)   { elementList[ showArray[n] ]   = 'show'; }

  // show/hide all elements
  for (var elementName in elementList) {
    if (!elementName) { continue; } // skip blank element names

    var element = document.getElementById(elementName) || error("Couldn't find element: " + elementName);

    if      (elementList[elementName] == 'hide') { element.style.display = 'none'; }
    else if (elementList[elementName] == 'show') { element.style.display = ''; }
    else { error("'" +elementName+ "' doesn't have a hide or show value!"); }
  }
}

function _applyToBranch(el, coderef) {   // run code for each element node in DOM branch
  if (typeof el == 'string') { el = document.getElementById(el); }
  if (el == null) { return alert('_applyToBranch: Invalid elect name or reference'); };

  // apply to parent
  coderef(el);        // note: this gets called twice

  // apply child nodes
  for (var n=0; n<el.childNodes.length; n++) {
    var thisNode = el.childNodes[n];

    // display each child element node
    if (thisNode.nodeType == 1) { coderef(thisNode); }

    // if child node has children of it's own, disable those
    if (thisNode.childNodes.length) { _applyToBranch(thisNode, coderef); }
  }
}

function DisableBranch(el) {
  var coderef = function(node) { node.setAttribute('disabled','disabled', 0); };
  _applyToBranch(el, coderef);
}

function EnableBranch(el) {
  var coderef = function(node) { node.removeAttribute('disabled', 0); };
  _applyToBranch(el, coderef);
}

/* ---------------------------------------------------------------------- *\
  Function    : getFormFieldNames
  Description : return a hash of form field names and noderefs - from
                specified parent node down.
  Usage       : var formFields = getFormFieldNames(parentNode);
\* ---------------------------------------------------------------------- */

function getFormFieldNames(parentNode) {
  var namesHash = new Object();

  // get INPUT element names
  var inputs    = parentNode.getElementsByTagName('input');
  for (var n=0; n < inputs.length; n++) {
    var el = inputs[n];
    if (el.type ==  'hidden' || el.type == 'text' || el.type == 'password' ||
        el.type == 'radio' || el.type == 'checkbox') { // file, submit, reset, button, submit, and image are excluded
      namesHash[ el.name ] = el;
    }
  }

  // get SELECT element names
  var selects   = parentNode.getElementsByTagName('select');    // select-one, select-multi
  for (n=0; n < selects.length; n++) {
    el = selects[n];
    namesHash[ el.name ] =  el;
  }

  // get TEXTAREA element names
  var textareas = parentNode.getElementsByTagName('textarea');  // textareas
  for (n=0; n < textareas.length; n++) {
    el = textareas[n];
    namesHash[ el.name ] =  el;
  }

  return namesHash;

}

/* ---------------------------------------------------------------------- *\
  Function    : getFormFieldValueByName
  Description : return the value that would be submitted by a form element.
                Note: We don't support elements that can return multiple
                values.  Also, we ALWAYS return value attribute from select
                options.  Even if they're value="" or undefined.  That's
                because we can't differentiate between no value attribute
                defined and value="".
                (TODO: Could we use innerHTML to actually look at the tag contents?)
\* ---------------------------------------------------------------------- */

function getFormFieldValueByName(fieldName) {

  // get list of matching elements
  var matchingElements = document.getElementsByName(fieldName);
  if (matchingElements.length == 0) { error("getFormFieldValueByName: no form fields found with name '"+fieldName+"'"); }
  var firstMatch = matchingElements[0];
  var fieldValue;

  // check for unsupported elements
  if (firstMatch.type == 'select-multiple') {
    error("Multi-value fields like 'select-multiple' not supported!");
  }
  else if (firstMatch.type == 'checkbox' && matchingElements.length > 1) {
    error("Multi checkboxes with the same name not supported!");
  }
  else if (matchingElements.length > 1) {
    for (var n=0; n < matchingElements.length; n++) {
      var eType = matchingElements[n].type;
      if (eType != 'radio') { error("Multiple fields with the same name not supported (except for radios)"); }
    }
  }

  //
  // get element value
  //


  // hidden, textarea, password, and text fields
  if (firstMatch.type == 'hidden' || firstMatch.type == 'textarea' ||
      firstMatch.type == 'password' || firstMatch.type == 'text') {
    fieldValue = firstMatch.value;
  }

  // for single pulldowns
  else if (firstMatch.type == 'select-one') {
    var selectedIndex = firstMatch.options.selectedIndex;
    var txt = firstMatch.options[ selectedIndex ].text;        // <option>text</option> value
    var val = firstMatch.options[ selectedIndex ].value;       // <option value="this">

    // only check value attribute (because we can't tell between no value attribute and value="")
    fieldValue = val;
  }

  // for checkboxes and radios
  else if (firstMatch.type == 'checkbox' || firstMatch.type == 'radio') {
    for (n=0; n < matchingElements.length; n++) {
      var thisField = matchingElements[n];
      if (thisField.checked) {
        fieldValue = thisField.value;
        break;
      }
    }
  }

  // unknown elements
  else { error("Unknown form field type: " + firstMatch.type);  }

  // return value
  if (fieldValue == null) { fieldValue = ''; }
  return fieldValue;
}


/* ---------------------------------------------------------------------- *\
  Function    : setFormFieldValueByName
  Description : Set the value or state or a form field based on a value.
                Note: We don't support elements that can return multiple
                values.  We don't support option text (only option value).
\* ---------------------------------------------------------------------- */

function setFormFieldValueByName(fieldname, fieldvalue) {

  // get list of matching elements
  var matchingElements = document.getElementsByName(fieldname);
  if (matchingElements.length == 0) { error("setFormFieldValueByName: no form fields found with name '"+fieldname+"'"); }
  var firstMatch = matchingElements[0];
  var n;

  // check for unsupported elements
  if (firstMatch.type == 'select-multiple') {
    error("Multi-value fields like 'select-multiple' not supported!");
  }
  else if (firstMatch.type == 'checkbox' && matchingElements.length > 1) {
    error("Multi checkboxes with the same name not supported!");
  }
  else if (matchingElements.length > 1) {
    for (n=0; n < matchingElements.length; n++) {
      var eType = matchingElements[n].type;
      if (eType != 'radio') { error("Multiple fields with the same name not supported (except for radios)"); }
    }
  }

  //
  // set element value
  //


  // hidden, textarea, password, and text fields
  if (firstMatch.type == 'hidden' || firstMatch.type == 'textarea' ||
      firstMatch.type == 'password' || firstMatch.type == 'text') {
    firstMatch.value = fieldvalue;
  }

  // for single pulldowns
  else if (firstMatch.type == 'select-one') {
    for (n=0; n < firstMatch.options.length; n++) {
      var thisOption = firstMatch.options[n];
      if (thisOption.value == fieldvalue) { thisOption.selected = true; }
      else                                { thisOption.selected = false; }
    }
  }

  // for checkboxes
  else if (firstMatch.type == 'checkbox') {
    if (firstMatch.value == fieldvalue) { firstMatch.checked = true; }
    else                                { firstMatch.checked = false; }
  }

  // for radios
  else if (firstMatch.type == 'radio') {
    for (n=0; n < matchingElements.length; n++) {
      var thisField = matchingElements[n];
      if (thisField.value == fieldvalue) { thisField.checked = true; }
      else                               { thisField.checked = false; }
    }
  }

  // unknown elements
  else { error("Unknown form field type: " + firstMatch.type);  }

  return true;
}


/* ------------------------------------------------------------------------- *\
  Function    : _htmlEncode
  Description : encode special characters as html entities
\* ------------------------------------------------------------------------- */

function htmlEncode(str) {

  str += '';  // convert object to string
  if (typeof str != 'string') { error("htmlEncode: value not a string!"); }

  str = str.replace(/&/ig, "&amp;");
  str = str.replace(/</ig, "&lt;");
  str = str.replace(/>/ig, "&gt;");
  str = str.replace(/"/ig, "&quot;");

  return str;
}

/* ---------------------------------------------------------------------- *\
  Function    : cloneObject
  Description : copy an object by value instead of by reference
  Usage       : var newObj = cloneObject(oldObj);
\* ---------------------------------------------------------------------- */

function cloneObject(obj) {
  var newObj          = new Object();

  // check for array objects
  if (isArray(obj)) { newObj = obj.constructor(); }

  for (var n in obj) {
    var node = obj[n];
    if (typeof node == 'object') { newObj[n] = cloneObject(node); }
    else                         { newObj[n] = node; }
  }

  return newObj;
}

/* ------------------------------------------------------------------------- *\
  Function    : isArray
  Description : test if object is an array or not and return true or false
  Usage       :
\* ------------------------------------------------------------------------- */

function isArray(obj) {

  // arrays are always objects
  if (typeof obj != 'object') { return false; }

  // test constructor
  if (obj.constructor &&
      obj.constructor.toString().indexOf('function '+'Array(') == 1) { return true; }

  // test for Array methods
  var methods = ['join','pop','push','reverse','shift','sort','splice','unshift'];
  var isArray = true;
  for (var n=0; n < methods.length; n++) {
    var methodName = methods[n];
    if (typeof obj[methodName] == 'undefined') {
      isArray = false;
      break;
    }
  }
  return isArray;

}

/* ---------------------------------------------------------------------- *\
  Function    : obj2query
  Description : convert the names/values of an objects properties into an
                url encoded querystring or vice versa.
  Usage       : var obj   = query2obj(queryString);
                var query = obj2query(obj);
\* ---------------------------------------------------------------------- */

function obj2query(obj) {
  var newQuery = "";

  for (var pname in obj) {
    var pvalue = obj[pname];
    if (typeof pvalue == 'object') { continue; }
    if (newQuery.length > 0) { newQuery += "&"; }
    newQuery += escape(pname) +"="+ escape(pvalue);
  }

  return newQuery;
}

function query2obj(query) {
  var obj   = new Object();
  var pairs = new Array();

  // error checking
  if (typeof(query) != 'string') { error("query2obj: query value must be a string, not '" +typeof(query)+ "'!"); }

  // remove ? from query string
  if (query.charAt(0) == '?') { query = query.substring(1, query.length); }

  pairs = query.split("&");

  for (var i=0; i < pairs.length; i++) {
    var thispair = pairs[i]
    thispair = thispair.replace(/\+/g, " ");  // URL_Decode: Replace + chars with ' '
    var namevalue = thispair.split("=");      // split into name and value

    // set field name/value values.  set undefined values to zero length string
    var fname  = (namevalue[0] == null)  ? '' : unescape( namevalue[0] );
    var fvalue = (namevalue[1] == null)  ? '' : unescape( namevalue[1] );

    if (fname.length) { obj[fname] = fvalue; }            // set object value
  }

  return obj;

}


/* ---------------------------------------------------------------------- *\
  Function    : whatBrowserEngine
  Description : return name of browser engine so we can write workaround
                for specific browsers.  Note, we only test for browser
                engines we support.

  Usage       : var browser = whatBrowserEngine()
\* ---------------------------------------------------------------------- */

function whatBrowserEngine() {
  var agt = navigator.userAgent.toLowerCase();

  var is_opera  = (agt.indexOf("opera") != -1);
  var is_khtml  = (agt.indexOf('khtml')!=-1) ||
                  (agt.indexOf('konqueror')!=-1) ||
                  ((agt.indexOf('safari')!=-1) && (agt.indexOf('mac')!=-1));
  var is_gecko  = (agt.indexOf('gecko')!=-1);
  var is_msie   = (agt.indexOf('msie')!=-1);

  // Note: some agent strings pretend to be other browsers (eg: KHTML, like Gecko)
  if (is_opera)                                       { return 'opera'; }
  if (!is_opera && is_khtml)                          { return 'khtml'; }
  if (!is_opera && !is_khtml && is_gecko)             { return 'gecko'; }
  if (!is_opera && !is_khtml && !is_gecko && is_msie) { return 'msie'; }

  return 'unknown';
}

/* ---------------------------------------------------------------------- *\
  Function    : setWindowGlobal
  Description : store or retrieve a global variable or object.
                Global means global to this window.  Access parent windows
                with window.opener.
  Usage       : setWindowGlobal(oName, oValue);
                oValue = getWindowGlobal(oName);
\* ---------------------------------------------------------------------- */

function setWindowGlobal(oName, oValue) {
  if (typeof(window._jsGlobals) == 'undefined') { window._jsGlobals = new Object(); }
  var windowGlobals = window._jsGlobals;

  windowGlobals[oName] = oValue;
}

function getWindowGlobal(oName) {
  if (typeof(window._jsGlobals) == 'undefined') { window._jsGlobals = new Object(); }
  var windowGlobals = window._jsGlobals;

  return windowGlobals[oName];
}

// -----------------------------------------------------------------------------
// Function    :
// Description :
// Usage       :
// -----------------------------------------------------------------------------


function popup(url, width, height, name) {
//  // figure our optimal window placement for popup dialog
//  var posX    = event.screenX;
//  var posY    = event.screenY + 20;
//  var screenW = screen.width;                                 // screen size
//  var screenH = screen.height - 20;                           // take taskbar into account
//  if (posX + width > screenW) { posX = posX - width - 40; }   // if mouse too far right
//  if (posY + height > screenH) { posY = posY - height - 80; } // if mouse too far down

  if (name == null) { name = 'popup_' + Math.floor(Math.random()*1000000); }

  return window.open(url,name,'resizable=yes,location=no,scrollbars=yes,toolbar=no,menubar=no,directories=no,status=yes'
                              +',height='+height+',width='+width
//                            +',top='+posY+',left='+posX+',screenY='+posY+',screenX='+posX   // top,left for IE; screenX,screenY for NS
                           );
}


/* ---------------------------------------------------------------------- *\
  Function    : error
  Description : display an error message and stop script execution.  Error
                can also be caught in try/catch block.
  Usage       : error("unable to complete process");
\* ---------------------------------------------------------------------- */

function error(msg) {
  alert("Error: " + msg);

  // supress browser errors
  window.onerror = function() { return true; };

  // throw exception (so we don't continue executing code)
  throw new Error(msg);
}


/* ---------------------------------------------------------------------- *\
  Function    : swapNode
  Description : swap two DOM nodes with each other
  Usage       :
\* ---------------------------------------------------------------------- */

function swapNode(node1, node2, manual) {
  if (node1 == node2) { return; }

  // use builtin features if available
  if (!manual && typeof node1.swapNode != 'undefined') {
    node1.swapNode(node2);
    return;
  }

  // otherwise, do it manually

  var node1_nextSibling = node1.nextSibling;
  var node1_parentNode  = node1.parentNode;
  var node2_nextSibling = node2.nextSibling;
  var node2_parentNode  = node2.parentNode

  if (node1_nextSibling) { node1_parentNode.insertBefore(node2, node1_nextSibling); }
  else                   { node1_parentNode.appendChild( node2 ); }

  if (node2_nextSibling) { node2_parentNode.insertBefore(node1, node2_nextSibling); }
  else                   { node2_parentNode.appendChild( node1 ); }

}

/* ---------------------------------------------------------------------- *\
  Function    : removeChildNodes
  Description : remove all child nodes of an element.
                Elements can be specified by object reference or name.
  Usage       :
\* ---------------------------------------------------------------------- */

function removeChildNodes(el) {
   while (el.firstChild) {
    el.removeChild( el.firstChild );
  }
}

/* ---------------------------------------------------------------------- *\
  Function    : disallowOptionValues
  Description : Don't allow options with the specified value to be selected.
                Display an error message (if defined) and reset pulldown to
                first option.  Multiple values/errors can be displayed.
  Usage       : <select onclick ="this.oldIndex = this.selectedIndex";
                        onchange="disallowOptionValues(this, {'disallowedValue': 'Error: Invalid selection',
                                                              'disallowedValue': 'Error: Invalid selection'})">
\* ---------------------------------------------------------------------- */

function disallowOptionValues(obj, disallowedValues) {
  var selectedValue = obj.options[obj.selectedIndex].value;
  if (disallowedValues[selectedValue]) {
    var errorMsg    = disallowedValues[selectedValue];
    if (errorMsg) { alert(errorMsg); }

    if (obj.oldIndex != null) { obj.selectedIndex = obj.oldIndex; }
    else                      { obj.selectedIndex = 0; }
  }
}


// ----------------------------------------------------------------------------

haha - 2025