<!-- // Start of AdSubtract JavaScript block; you can ignore this.
     // It is used when AdSubtract blocks cookies or pop-up windows.
document.iMokie = "cookie blocked by AdSubtract";
document.iMferrer = "referrer blocked by AdSubtract";
function iMwin() {
	this.location = "";
	this.frames = new Array(9);
	this.frames[0] = this;
	this.frames[1] = this;
	this.frames[2] = this;
	this.frames[3] = this;
	this.frames[4] = this;
	this.frames[5] = this;
	this.frames[6] = this;
	this.frames[7] = this;
	this.frames[8] = this;
	this.length = 0;
}
// End of AdSubtract JavaScript block. -->
/**
 * @class UserWrapper contains global methods in the user_wrapper.js file.
 * This is not really a class, but it serves to better organize the javadoc
 * comments generated from this file.
 * Without this, all methods get documented in a 'GLOBALS' page with methods
 * from all other .js files.
 * @private
 */
function UserWrapper()
{
}

/**
 * Encodes a text string to be usable as a URL parameter value.
 * The following characters are encoded with their hexadecimal values
 * preceded by a percent symbol:
 * &amp;, %, #, space, ?, &lt;, &gt;, {, }, [, ], |, ^, ~, `
 * @member UserWrapper
 * @param str the text string to transform.
 * @return the transformed text string.
 * @type String
 */
function URLEncode(str)
{
	var ms = "%25#23 20?3F<3C>3E{7B}7D[5B]5D|7C^5E~7E`60+2B";
	var msi = 0;
	var i,c,rs,ts;

	while (msi < ms.length) {
		c = ms.charAt(msi);
		rs = ms.substring(++msi, msi +2);
		msi += 2;
		i = 0;

		while (true) {
			i = str.indexOf(c, i);

			if (i == -1)
				break;

			ts = str.substring(0, i);
			str = ts + "%" + rs + str.substring(++i, str.length);
		}
	}
	return str
}

/**
 * This function provides the same conversion as that obtained from
 * java.net.URLEncoder.encode().  The function converts a string into
 * the x-www-form-urlencoded MIME format.
 * <p>
 * To convert the string, each character is examined in turn:
 * <ul>
 *  <li> The ASCII characters 'a' through 'z', 'A' through 'Z',
 *       '0' through '9', and '.', '-', '*', '_' remain the same.
 *  <li> The space character (' ') is converted into a plus sign ('+').
 *  <li> All other characters are converted into the 3-character string
 *       %XY, where XY is the two-digit hexadecimal representation of the
 *       lower 8-bits of the character.
 * </ul>
 * <p>
 * NB: The list of characters that are not encoded have been determined by
 *     referencing O'Reilly's "HTML: The Definitive Guide" (page 164).
 * <p>
 * The implementation is derived from that found at
 * <a href="http://summerholiday.org/freecode/JavaScript_URL_Encode.html">
 * summerholiday.org/freecode/JavaScript_URL_Encode.html
 * </a>
 * (which appears to share significant DNA with the code at
 * <a href="http://www.blooberry.com/indexdot/html/topics/urlencoding.htm">
 * www.blooberry.com/indexdot/html/topics/urlencoding.htm</a>).
 *
 * @member UserWrapper
 * @param paramValue the text string to transform.
 * @return the transformed text string.
 * @type String
 */
function URLEncodeParamValue (paramValue)
{
	var len       = paramValue.length;
	var i         = 0;
	var newStr    = '';
	var paramChar = '';

	for (i = 0; i < len; i++) {
		paramChar = paramValue.substring (i, i + 1);

		if (isUrlOK (paramChar))
			newStr = newStr + paramChar;
		else if (paramChar.charCodeAt(0) == 32)
			newStr = newStr + '+';
		else {
			tval1 = paramChar;
			newStr = newStr + '%' + decToHex (tval1.charCodeAt(0), 16);
		}
	}
	return newStr;
}

/**
 * An array of hexadecimal digits used by URLEncodeParamValue.
 * @final
 * @private
 * @member UserWrapper
 * @see #URLEncodeParamValue
 */
var hexVals = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');

/**
 * Converts a decimal number into hexadecimal.
 * @private
 * @member UserWrapper
 * @param num the decimal number to convert.
 * @param the radix (must be 16, should not be a parameter).
 * @return the hexadecimal number as a string
 * @type String
 * @see #URLEncodeParamValue
 */
function decToHex(num, radix)
{
	var hexString = '';

	while (num >= radix) {
		temp = num % radix;
		num = Math.floor(num / radix);
		hexString += hexVals[temp];
	}

	hexString += hexVals[num];
	return reversal(hexString);
}

/**
 * Reverses a text string.
 * @private
 * @member UserWrapper
 * @param s the string to reverse.
 * @return the reversed string.
 * @type String
 * @see #URLEncodeParamValue
 */
function reversal (s)
{
	var len = s.length;
	var trans = '';

	for (i = 0; i < len; i++)
		trans = trans + s.substring(len-i-1, len-i);

	s = trans;
	return s;
}

/**
 * Determines whether a given character can be used in a URL parameter value
 * without encoding.
 * @private
 * @member UserWrapper
 * @param compareChar the character to test
 * @return <code>true</code> if the character can be used unencoded.
 * @type boolean
 * @see #URLEncodeParamValue
 */
function isUrlOK(compareChar)
{
	var charCode = compareChar.charCodeAt(0);

	if ((charCode >= 97 && charCode <= 122)		// 'a'-'z'
      || (charCode >= 65 && charCode <= 90)	// 'A'-'Z'
      || (charCode >= 48 && charCode <= 57)	// '0'-'9'
      || charCode == 46				// '.'
      || charCode == 45				// '-'
      || charCode == 95				// '_'
      || charCode == 42)				// '*'
	{
		return true;
	}
	else {
		return false;
	}
}

/**
 * Find all the checkboxes in a form that contain a given text string in their
 * name and set their checked property.
 * @member UserWrapper
 * @param formname the name of the form in which to change checkboxes.
 * @param checkname the name that is a substring of the targeted checkboxes.
 * @param val the value to set on the checkboxes.
 */
function SetChecked(formname, checkname, val)
{
	dml = document[formname];
	len = dml.elements.length;

	for (var i = 0; i < len ; i++) {
		if (dml.elements[i].type == 'checkbox' && dml.elements[i].name.indexOf(checkname) >= 0) {
			dml.elements[i].checked=val;
		}
	}
}

/**
 * Limit the size of a text area.
 * This should be called from the "keyup" event.
 * @member UserWrapper
 * @param textArea the "textarea" HTML element in which to limit the content.
 * @param lengthLimit is an integer specifying the maximum number of characters
 *        to allow in the textarea.
 * @param warningText is optional text to display to the user when the length
 *        is exceeded.  global.properties has a nice default message key - text_size_warning.
 */
function limitArea(textAreaID, lengthLimit, warningText)
{
	if (!lengthLimit)
		lengthLimit = 255;

	if (!warningText)
		warningText = "This text area has a limit of " + lengthLimit + " characters.";

	var currentString = new String(textAreaID.value);

	if (currentString.length > lengthLimit) {
		alert(warningText);
		textAreaID.value = currentString.substr(0, lengthLimit);
	}
}

/**
 * Opens a new window and returns false
 * so it can be used in a form button. In addition it has
 * a default window features string so that parameter is
 * optional.
 * @member UserWrapper
 * @param theURL the URL to fetch into the window.
 * @param winName the name of the new window.
 * @param winFeatures a text string specifying features of the new window.
 * @return <code>false</code>
 * @type boolean
 */
function newWindowButton(theURL, winName, winFeatures)
{
	if (!winFeatures) {
		winFeatures = "directories=yes,location=yes,menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes,left=5,top=5";
	}
	window.open(theURL, winName, winFeatures);
	return false;
}

/**
 * Changes a field's value from 9 consecutive digits into the social security
 * format of '###-##-####'.
 * @member UserWrapper
 * @param _el the HTML input element to change.
 */
function fixSSN(_inputElem)
{
	var ssnString    = _inputElem.value;
	var returnString = '';
	var re           = new RegExp('([0-9]{9})');

	if (re.test(ssnString)) {
		returnString = ssnString.substring(0, 3) + '-' + ssnString.substring(3, 5) + '-' + ssnString.substring(5, 9);
		_inputElem.value = returnString;
	}
}

function chkZipCode(objName)
{
	var checkOK = "0123456789";
	var checkStr = objName;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";

	if (checkStr.value.length < 5) {
		alertsay = "Please enter a 5 digit ZIP code or a ZIP+4 code in the format nnnnn-nnnn.";
		allValid = false;
	}
 	else if (checkStr.value.length > 5 && checkStr.value.length != 10) {
		alertsay = "Please enter a 5 digit ZIP code or a ZIP+4 code in the format nnnnn-nnnn.";
		allValid = false;
	}

	if (allValid) {
		for (var i = 0;  i < 5;  i++) {
			ch = checkStr.value.charAt(i);

			for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j))
					break;

			if (j == checkOK.length) {
				allValid = false;
				alertsay = "ZIP code must be numeric.";
				break;
			}
		}

		if (allValid && checkStr.value.length > 5) {
			if (checkStr.value.charAt(5) != "-") {
				allValid = false;
				alertsay = "ZIP+4 must be in the format nnnnn-nnnn.";
			}
			else if (checkStr.value.substring(6, 10) == "0000") {
				allValid = false;
				alertsay = "0000 is not a valid ZIP+4 extension.";
			}
			else {
				for (i = 6;  i < 10;  i++) {
					ch = checkStr.value.charAt(i);

					for (j = 0;  j < checkOK.length;  j++)
						if (ch == checkOK.charAt(j))
							break;

					if (j == checkOK.length) {
						allValid = false;
						alertsay = "ZIP+4 must be numeric.";
						break;
					}
				}
			}
		}
	}

	if (!allValid) {
		alert(alertsay);
		return (false);
	}

	return (true);
}


/**
 * If the user hits 'OK' on the confirm panel, fetches a popup from the server, refreshing
 * the users session.
 * @member UserWrapper
 */
function keepAlive(logoutWarning, confirmURL)
{

	if (confirm(logoutWarning)) {
		msgWin = window.open(confirmURL, '', 'scrollbars=no,resizable=no,alwaysRaised=yes,dependent=yes,width=1,height=1');

		if (msgWin != null)
			msgWin.close();

		resetTimeout();
	}
}


function forceKeepAlive(confirmURL)
{
	msgWin = window.open(confirmURL, '', 'scrollbars=no,resizable=no,alwaysLowered=yes,dependent=yes,width=1,height=1');
	msgWin.close();
	// Uncomment the line below to make this last forever.
	// resetTimeout();
}


/**
 * Appends the given param/val pair to the given original url.
 * @member UserWrapper
 */
function appendToUrl (original, param, val)
{
	var url = new String (original);
	var sep ="";

	if (url.indexOf("?") == -1)
      sep= "?";
	else
      sep= "&";

	return url.valueOf() + sep + param + "=" + val;
}

/**
 * If you permform multiple validation steps in an onSubmit event handler,
 * then it is important to call submitOnce() last because it sets an internally
 * used flag that indicates that the form has been submitted.
 * Otherwise, calling submitOnce() might set _submitOnce=true and then some
 * other validation might return false (which aborts the form submission).
 * But then the FORM could not be submitted again because _submitOnce==true.
 * @member UserWrapper
 */
var _submitOnce = false;

function submitOnce(msg)
{
  if (_submitOnce) {
    alert(msg);
    return false;
  }
  else {
    _submitOnce = true;
    return true;
  }
}

function submitEnter(mybutton,e)
{
	var keycode;

	if (window.event)
		keycode = window.event.keyCode;
	else if (e)
		keycode = e.which;
	else
		return true;

	if (keycode == 13) {
		mybutton.click();
		return false;
	}
	else
		return true;
}

/**
 * Returns the currently selected option of a SELECT element.
 * @member UserWrapper
 */
function getOptionSelection (formName, selectName)
{
	var selList = null;

	if (document.getElementById)
		selList = document.getElementById (selectName);
	else if (formName)
		selList = document.forms[formName].elements[selectName];

  return (selList != null) ? selList.options[selList.selectedIndex].value : null;
}

/**
 * The functions below can be used to make embedded surveys
 * change the choices as you fill out the questions.
 * @member UserWrapper
 */
function choiceSelected(question, choice) {
   return true;
}

function relateQuestion(formName, question, question2, choice, optionList) {
   // Array offsets of values in Array optionList

   memberOf		= 0;
   sTag			= 1;
   optionLabel		= 2;

   var optionListCounter = 0;
   var selectListCounter = 0;

   // clear the old options
   for (optionListCounter = document.forms[formName].elements[question].options.length - 1; optionListCounter >= 0 ; optionListCounter--) {
      document.forms[formName].elements[question].options[optionListCounter] = null;
   }

   // set the new options
   for (optionListCounter = 0; optionListCounter < optionList.length; optionListCounter++) {
      if (optionList[optionListCounter][memberOf] == choice) {
         var newoption = new Option(optionList[optionListCounter][optionLabel], optionList[optionListCounter][sTag]);
         document.forms[formName].elements[question2].options[selectListCounter++] = newoption;
      }
   }

   // set selected element
   document.forms[formName].elements[question].options[0].selected = true;

   // refresh if necessary
   if (navigator.appName == 'Netscape' && parseInt(navigator.appVersion) < 5) {
      history.go(0);
   }
}

