// ---------------------------------------------
// use this to add a new window.onload handler
// ie. AddOnLoadHandler(tool_tip_hover) instead of window.onload = function() { tool_tip_hover_code }
// ---------------------------------------------
function AddOnLoadHandler(init_fxn){
    var old_init = window.onload;
    var new_init = init_fxn;
    window.onload = function(){
         if (typeof(old_init)=="function"){
            old_init();
         }
         new_init();
    }
    return this;
}

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string') {
			var element_name = element;
			element = document.getElementById(element_name);
			if (!element) { // try by name
				var element = document.getElementsByName(element_name);
				if (element && element.length == 1) { // only accept if its the only one found
					element = element[0];
				}
			}
		}
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

function getElementsByClass(searchClass,startNode,htmlTag) {
	var classElements = new Array();
	if (startNode == null) startNode = document;
	if (htmlTag == null) htmlTag = '*';
	var els = startNode.getElementsByTagName(htmlTag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function hasClass(ele, cls) {
	return $(ele).className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
}
 
function addClass(ele, cls) {
	if (!this.hasClass(ele, cls)) $(ele).className += " " + cls;
}

function removeClass(ele, cls) {

	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
		$(ele).className = $(ele).className.replace(reg, ' ');
	}
}

function setStyle(objId, style, value){
   $(objId).style[style] = value;
}

// --------------------------------------------------------
// jumps fields for phone #.  naming convention must be
// prefix1, prefix2, prefix3 where prefix is the name/id of the 
// phone field.
//
// NOTE: in FireFox, if you are getting a SelectedIndex error
// add the following to the input control: autocomplete="off"
// --------------------------------------------------------
function jumpPhone(fld,prefix) {
	switch(fld.name) {
		case prefix + '_area':
			if(document.getElementById(prefix + '_area').value.length==3) {
				document.getElementById(prefix + '_pre').focus();
				document.getElementById(prefix + '_pre').select();
			}
			break;
		case prefix + '_pre':
			if(document.getElementById(prefix + '_pre').value.length==3) {
				document.getElementById(prefix + '_post').focus();
				document.getElementById(prefix + '_post').select();
			}
			break;
	}
}

// --------------------------------------------------------
// clears a select dropdown list
// --------------------------------------------------------
function clearSelectList(obj) {
	if (typeof(obj)!='object') {
		obj = document.getElementById(obj);
	}
	if (obj) {
		var len = obj.length;
		
		while (len > 0) {
			obj.remove(len);
			len--;
		}
	}
}

// --------------------------------------------------------
// returns the value of a select dropdown
// --------------------------------------------------------
function getSelectValue(obj) {
	obj = $(obj);
	var value=null;
	if (obj) {
		value = obj.options[obj.selectedIndex].value
	}
	
	return value;
}

// --------------------------------------------------------
// toggles a checkbox
// --------------------------------------------------------
function toggleCheck(obj,bNoClick){
	obj = $(obj);
	if (obj) {
		// perform the click
		if (!bNoClick) {
			obj.click();
		} else {
			obj.checked=!obj.checked;		
		}
	}
}

// --------------------------------------------------------
// returns true if the passed checkbox is checked
// --------------------------------------------------------
function isChecked(obj) {
	obj = $(obj);
	if (!obj) {
		alert('Could not locate '+obj);
		return false;
	} else {
		return obj.checked;		
	}
}

// --------------------------------------------------------
// returns true if the passed element is visible
// --------------------------------------------------------
function isVisible(obj)
{
	var el = $(obj);
	if (!el) {
		alert('Could not locate '+obj);
	} else {
		return (el.style.display!='none');
	}	
}

// --------------------------------------------------------
// shows an element by setting its display value
// --------------------------------------------------------
function showElement(obj) 
{
	var el = $(obj);
	if (!el) {
		alert('Could not locate '+obj);
	} else {
		el.style.display='';
	}
}

// --------------------------------------------------------
// hides an element by setting its display value
// --------------------------------------------------------
function hideElement(obj) 
{
	var el = $(obj);
	if (!el) {
		alert('Could not locate '+obj);
	} else {
		el.style.display='none';
	}
}

// --------------------------------------------------------
// toggles visibility of the passed element
// --------------------------------------------------------
function toggleElement(obj) {
	if (typeof(obj)!='object') {
		obj = document.getElementById(obj);
	}
	if ( obj.style.display != "none" ) {
		obj.style.display = 'none';
	}
	else {
		obj.style.display = '';
	}
}

// --------------------------------------------------------
// disables the passed element
// --------------------------------------------------------
function disableElement(obj) {
	obj = $(obj);
	
	if (isArray(obj) || (typeof(obj.length) == "number" && obj.type != 'select-one')) {
		for (i=0; i < obj.length; i++) {
			disableElement(obj[i]);
		}
	} else {
		if (obj) {
			obj.disabled = true;	
		} else {
			alert('Could not locate '+obj);
		}
	}
}

// --------------------------------------------------------
// enables the passed element
// --------------------------------------------------------
function enableElement(obj) {
	obj = $(obj);
	
	if (isArray(obj) || (typeof(obj.length) == "number" && obj.type != 'select-one')) {
		for (i=0; i < obj.length; i++) {
			enableElement(obj[i]);
		}
	} else {
		if (obj) {
			obj.disabled = false;	
		} else {
			alert('Could not locate '+obj);
		}
	}
}

// --------------------------------------------------------
// toggles the enable of an element
// --------------------------------------------------------
function toggleEnabled(obj) {
	if (typeof(obj)!='object') {
		obj = document.getElementById(obj);
	}
	if ( obj.disabled == false ) {
		obj.disabled = true;
	} else {
		obj.disabled = false;
	}
}

// disables all elements of a certain class
function disableElementsOfClass(searchClass, startNode, htmlTag) {
	var elements = getElementsByClass(searchClass,startNode,htmlTag);

	if (elements) {
		for (i = 0; i < elements.length; i++) {
			disableElement(elements[i]);
		}
	}
}

// disables all elements of a certain class
function enableElementsOfClass(searchClass, startNode, htmlTag) {
	var elements = getElementsByClass(searchClass,startNode,htmlTag);

	if (elements) {
		for (i = 0; i < elements.length; i++) {
			enableElement(elements[i]);
		}
	}
}

// hides all elements of a certain class
function hideElementsOfClass(searchClass, startNode, htmlTag) {
	var elements = getElementsByClass(searchClass,startNode,htmlTag);

	if (elements) {
		for (i = 0; i < elements.length; i++) {
			hideElement(elements[i]);
		}
	}
}

// shows all elements of a certain class
function showElementsOfClass(searchClass, startNode, htmlTag) {
	var elements = getElementsByClass(searchClass,startNode,htmlTag);

	if (elements) {
		for (i = 0; i < elements.length; i++) {
			showElement(elements[i]);
		}
	}
}

// returns the # of checked elements.  can be a radio group or a checkbox array.
function getCheckedCount(elementName) {
	return getCheckedElements(elementName).length;
}

// returns an array of checked elements.  can be radio or checkboxes.
function getCheckedElements(elementName) {
	var elements = new Array();
	var elementGroup = document.getElementsByName(elementName);

	if (elementGroup) {
		for (i=0; i < elementGroup.length; i++) {
			if (elementGroup[i].checked == true) {
				elements.push(elementGroup[i]);
			}
		}
	} else {
		alert('Unable to locate ' + elementName);
	}

	return elements;
}

// checks all elements of the passed name.  can be a radio group or a checkbox array.
function checkAll(elementName, perform_click) {

	var elementGroup = document.getElementsByName(elementName);
	
	if (elementGroup) {
		for (i=0; i < elementGroup.length; i++) {
			if (!elementGroup[i].checked) {
				if (perform_click) { elementGroup[i].click(); }
				elementGroup[i].checked = true;
			}
		}
	} else {
		alert('Unable to locate ' + elementName);
	}		
}

// unchecks all elements of the passed name.  can be a radio group or a checkbox array.
function uncheckAll(elementName, perform_click) {

	var elementGroup = document.getElementsByName(elementName);
	
	if (elementGroup) {
		for (i=0; i < elementGroup.length; i++) {
			if (elementGroup[i].checked) {
				if (perform_click) { elementGroup[i].click(); }
				elementGroup[i].checked = false;
			}
		}
	} else {
		alert('Unable to locate ' + elementName);
	}		
}

// --------------------------------------------------------
// note this takes a reference to the form named element, the the element id
// ex. clearRadio(document.formName.elementName);
// --------------------------------------------------------
function clearRadio(radioGroup){	
	for (i=0; i < radioGroup.length; i++) {
		if (radioGroup[i].checked == true) {
			radioGroup[i].checked = false
		}
	}
}

// --------------------------------------------------------
// returns the index of the selected radio option
// --------------------------------------------------------
function getRadioCheckedIndex(radioName) {

	var radioGroup = document.getElementsByName(radioName);
	
	if (radioGroup) {
		for (i=0; i < radioGroup.length; i++) {
			if (radioGroup[i].checked == true) {
				return i;
			}
		}
	} else {
		alert('Unable to locate ' + radioName);
	}
		
	return -1;
}

// --------------------------------------------------------
// returns true if the passed radio control has something selected
// --------------------------------------------------------
function isRadioChecked(radioName) {
	return (getRadioCheckedIndex(radioName) >= 0);
}

// --------------------------------------------------------
// returns the value of the selected radio option
// --------------------------------------------------------
function getRadioValue(radioName) {
	var radioGroup = document.getElementsByName(radioName);

	if (radioGroup) {
		for (i=0; i < radioGroup.length; i++) {
			if (radioGroup[i].checked == true) {
				return radioGroup[i].value;
			}
		}
	} else {
		alert('Unable to locate ' + radioName);
	}
	
	return '';
}

// --------------------------------------------------------
// selects a radio option based on value
// --------------------------------------------------------
function setRadioValue(radioName,value) {
	var radioGroup = document.getElementsByName(radioName);

	if (radioGroup) {
		for (i=0; i < radioGroup.length; i++) {
			if (radioGroup[i].value == value) {
				radioGroup[i].checked = true;
			}
		}
	} else {
		alert('Unable to locate ' + radioName);
	}
}

// --------------------------------------------------------
// disables a radio group
// --------------------------------------------------------
function disableRadio(radioName) {

	var radioGroup = document.getElementsByName(radioName);
	
	if (radioGroup) {
		for (i=0; i < radioGroup.length; i++) {
			radioGroup[i].disabled = true;
		}
	} else {
		alert('Unable to locate ' + radioName);
	}
}

// --------------------------------------------------------
// enables a radio group
// --------------------------------------------------------
function enableRadio(radioName) {

	var radioGroup = document.getElementsByName(radioName);
	
	if (radioGroup) {
		for (i=0; i < radioGroup.length; i++) {
			radioGroup[i].disabled = false;
		}
	} else {
		alert('Unable to locate ' + radioName);
	}
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function toProperCase(s)
{
  return s.toLowerCase().replace(/^(.)|\s(.)/g, 
          function($1) { return $1.toUpperCase(); });
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }

var numb = '0123456789';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

function isValid(parm,val) {
	var i;
	if (parm == "") return true;
	for (i=0; i<parm.length; i++) {
		if (val.indexOf(parm.charAt(i),0) == -1) return false;
	}
	return true;
}

function isNum(parm) {return isValid(parm,numb);}
function isLower(parm) {return isValid(parm,lwr);}
function isUpper(parm) {return isValid(parm,upr);}
function isAlpha(parm) {return isValid(parm,lwr+upr);}
function isAlphanum(parm) {return isValid(parm,lwr+upr+numb);}

function validateDollar( obj, bAlertFocus )
{
	if (typeof(obj)!='object') {
		obj = document.getElementById(obj);
	}

	if (obj) {
		var afterDecimal = 0;
		var bHitDecimal = false;
		
		var temp_value = obj.value;
		
		if (temp_value == "")
		{
		  obj.value = "0.00";
		  return true;
		}

		var Chars = "0123456789.,$";
		for (var i = 0; i < temp_value.length; i++)
		{
			if (bHitDecimal) afterDecimal++;
			if (temp_value.charAt(i) == '.') bHitDecimal = true;

			if (afterDecimal>2) {
		        if (bAlertFocus) {
			        alert("Only 2 decimal values are allowed in this field.");
			        obj.focus();
				    obj.select();
				}
				return false;
			}

		    if (Chars.indexOf(temp_value.charAt(i)) == -1)
		    {
		        if (bAlertFocus) {
			        alert("Invalid Character(s)\n\nOnly numbers (0-9), a dollar sign, a comma, and a period are allowed in this field.");
			        obj.focus();
				    obj.select();
				}
		        return false;
		    }
		}
		
		if (bHitDecimal && afterDecimal<2) {
			for (var i = afterDecimal; i<2; i++) {
				obj.value += '0';
			}
		} else if (!bHitDecimal) {
			obj.value += '.00';
		}	
	} else {
		alert('Could not locate '+obj);
	}
	
	return true;
}
// based on 3 fields called field_nm_hh,field_nm_mm,field_nm_ss 
function validTime(base_fld) {
	var hh = $(base_fld + '_hh').value;
	var mm = $(base_fld + '_mm').value;
	var ss = $(base_fld + '_ss').value;

	return isNum(hh) && isNum(mm) && isNum(ss) && 
		parseInt(hh)>=0 && parseInt(hh)<24 &&
		parseInt(mm)>=0 && parseInt(mm)<60 &&
		parseInt(ss)>=0 && parseInt(ss)<60;		
}

function charCodeFromEvent(evt) {
	return (evt.which) ? evt.which : evt.keyCode;
}

// returns true if the key pressed was a number
// usage: onkeypress="return isNumberKey(event);"
function isNumberKey(evt)
{
	var charCode = charCodeFromEvent(evt);
	
	var allowed_special_keys = new Array();
	allowed_special_keys.push(46) // delete key
	allowed_special_keys.push(39) // right arrow
	if (!evt.shiftKey) {
		allowed_special_keys.push(37) // left arrow
	}
	
	if (charCode > 31 && (charCode < 48 || charCode > 57) && !allowed_special_keys.inArray(charCode)) return false;
	return true;
}

// returns true if the key pressed was an alphanumeric value
// usage: onkeypress="return isAlphaNumberKey(event);"
function isAlphaNumberKey(evt, nospecial)
{

	var charCode = charCodeFromEvent(evt);
	var allowed_special_keys = new Array();
	
	allowed_special_keys.push(8)  // backspace
	allowed_special_keys.push(9)  // tab
	if (String.fromCharCode(charCode) != ".") {
		allowed_special_keys.push(46) // delete key
	}
	allowed_special_keys.push(39) // right arrow
	if (!evt.shiftKey) {
		allowed_special_keys.push(37) // left arrow
	}
	if (!isAlphanum(String.fromCharCode(charCode)) && !allowed_special_keys.inArray(charCode)) return false;
	return true;
}

// returns true if the key pressed was not the enter key
// usage: onkeypress="return isNotEnterKey(event);"
function isNotEnterKey(evt, nospecial) {
	return charCodeFromEvent(evt) != 13;
}

Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};

function isArray(obj) {
   return obj.constructor == Array;
}

function addEvent(elm, evType, fn, useCapture) {
	elm = $(elm);
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else {
		elm['on' + evType] = fn;
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function insertAfter(newElement, targetElement) 
{ 
	newElement = $(newElement);
	targetElement = $(targetElement);

    // Target is what you want it to go after. 
    // Look for this elements parent. 
    var parent = targetElement.parentNode; 

    // If the parents lastchild is the target 
    // element... 
    if(parent.lastchild == targetElement) { 
        // Add the newElement after the target 
        // element. 
        parent.appendChild(newElement); 
    } else { 
        // Else the target has siblings, insert 
        // the new element between the target and 
        // it's next sibling. 
        parent.insertBefore(newElement, targetElement.nextSibling); 
    } 
} 

function scrollToElement(obj, pxPaddingX, pxPaddingY) {

	obj = $(obj);

	var posX = 0;
	var posY = 0;
              
	while (obj != null) {
		posX += obj.offsetLeft;
		posY += obj.offsetTop;
		obj = obj.offsetParent;
	}
	posX += (pxPaddingX ? pxPaddingX : 0);
	posY += (pxPaddingY ? pxPaddingY : 0);
		
	window.scrollTo(posX,posY);
}

function getScrollPosition() {
	var scrollTop = document.body.scrollTop;

	if (scrollTop == 0) {

	    if (window.pageYOffset) {
	        scrollTop = window.pageYOffset;
		} else {
	        scrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
	}
}

function switchColorAndCursor(box, direction) {

	if(direction=='in') {
		$(box).style.cursor = "pointer";
		changeOpac(60,box);
	} else {
		$(box).style.cursor = "default";
		changeOpac(100,box);
	}
}

function switchCursor(obj, direction) {
			
	if(direction=='in') {
		$(obj).style.cursor = "pointer";
	} else {
		$(obj).style.cursor = "default";
	}
}

function disableButton(obj) {
	disableElement(obj);
	changeOpac(60, obj);
	$(obj).style.cursor = "default";
}

function enableButton(obj) {
	enableElement(obj);
	changeOpac(100, obj);
	$(obj).style.cursor = "pointer";
}

//change the opacity for different browsers
// original from: http://www.brainerror.net/scripts_js_blendtrans.php
function changeOpac(opacity,id) {
	var group = $(id);
	
	if (group) {

		var object = group.style;
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";

		var elem = group.childNodes;

		for(var i = 0; i < elem.length; i++) {
			if (elem[i].id) {
				changeOpac(opacity,elem[i].id); // recursively set the opacity on the children
			}
		}		
	}
}

// JavaScript Document
function resizeimage(imagename, maxwidth, maxheight) {
	oldimageheight=$(imagename).height;
	oldimagewidth=$(imagename).width;
	
	for (i = $(imagename).height; i >= maxheight; i--){
		$(imagename).height=i;
		$(imagename).width=(i/oldimageheight)*oldimagewidth
	}
	oldimageheight=$(imagename).height;
	oldimagewidth=$(imagename).width;

	for (i=$(imagename).width; i >= maxwidth ; i--){
		$(imagename).width=i;
		$(imagename).height=(i/oldimagewidth)*oldimageheight;
	}

} 

function copyObject(from, to) {
	for (i in from) {
		to[i] = from[i];
	}			
}

function word_count(obj) {
	obj = $(obj);
	
	word_count = 0;
	for (i = 0; i < obj.value.length; i++) {
		if (obj.value.charAt(i) == " " && obj.value.charAt(i - 1) != " ")  {
			word_count++;
		} 
	}
}

function get_max_word_size(obj) {
	obj = $(obj);
	
	word_size = 0;
	max_word_size = 0;
	
	for (i = 0; i < obj.value.length; i++) {		
		if (obj.value.charAt(i) == " " && obj.value.charAt(i - 1) != " ")  {
			max_word_size = Math.max(max_word_size, word_size);
			word_size = 0;
		} else {
			word_size++;
		}
	}
	// catch the last one
	max_word_size = Math.max(max_word_size, word_size);
	
	return max_word_size;
}

function insert_at_cursor(obj, to_insert) {
	obj = $(obj);
	if (document.selection) { // IE
		obj.focus();
		sel = document.selection.createRange();
		sel.text = to_insert;
	} else if (obj.selectionStart || myField.selectionStart == '0') { // FF
		var start_pos = obj.selectionStart;
		var end_pos = obj.selectionEnd;
		obj.value = obj.value.substring(0, start_pos) + to_insert + obj.value.substring(end_pos, obj.value.length);
	} else {
		obj.value += to_insert;
	}
}

function delete_at_cursor(obj) {
	obj = $(obj);
	if (document.selection) { // IE
		obj.focus();
		sel = document.selection.createRange();
		alert(sel);
		sel.text = to_insert;
	} else if (obj.selectionStart || myField.selectionStart == '0') { // FF
		obj.value = obj.value.substring(0, obj.selectionStart - 1) + obj.value.substring(obj.selectionEnd, obj.value.length);
	}
}

function strip_words_to_size(obj, max_size) {
	obj = $(obj);
	
	var text = "";
	word_size = 0;
	var cursor_pos = get_cursor_position(obj);
	var reset_pos = false;
	
	for (i = 0; i < obj.value.length; i++) {		
		if (obj.value.charAt(i) == " " && obj.value.charAt(i - 1) != " ")  {
			// end of word
			word_size = 0;
			// add in spaces
			text += obj.value.charAt(i);
		} else {
			word_size++;
			if (word_size <= max_size) { 
				text += obj.value.charAt(i);
			} else {
				reset_pos = true;
			}
		}
	}
		
	if (reset_pos) {
		obj.value = text;
		set_cursor_position(obj, cursor_pos-1, cursor_pos-1);
	}
	
	return reset_pos;
}

function set_cursor_position(obj, start, end) {
	obj = $(obj);

	if (obj.setSelectionRange) {
		 obj.setSelectionRange(start,end);
	} else if (obj.createTextRange) {	
		var range = obj.createTextRange();
		range.collapse(true);
		range.moveEnd('character',end);
		range.moveStart('character',start);
		range.select();
	}
}

function get_cursor_position(obj) {
	obj = $(obj);
	var position = 0;

	if (obj.selectionStart){
		position = obj.selectionStart;
	} else if (!document.selection) {
		position = 0;
	} else {
		var i = obj.value.length + 1;
		if (obj.createTextRange) {
			var current_pos = document.selection.createRange().duplicate();
			while (current_pos.parentElement() == obj && current_pos.move("character",1) == 1) {
				--i;
			}
		}
		position = (i == obj.value.length + 1 ? obj.value.length : i - 1);
	}
	
	return position;
}

function client_side_include(id, url, append) {
  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
 var element = document.getElementById(id);
 if (!element) {
  alert("Bad id " + id +
   "passed to clientSideInclude." +
   "You need a div or span element " +
   "with this id in your page.");
  return;
 }
  if (req) {
    // Synchronous request, wait till we have it all
    req.open('GET', url, false);
    req.send(null);
    
    if (append) {
		var span = document.createElement("span");
		span.innerHTML = req.responseText;
		element.appendChild(span);
    } else {
		element.innerHTML = (append ? element.innerHTML : "") + req.responseText;
	}
  } else {
    element.innerHTML =
   "Sorry, your browser does not support " +
      "XMLHTTPRequest objects. This page requires " +
      "Internet Explorer 5 or better for Windows, " +
      "or Firefox for any system, or Safari. Other " +
      "compatible browsers may also exist.";
  }
}

function fix_date(id) {
	var element = $(id);
	// replace / and \ with -, split date into array 'date'
	var text_date = element.value.replace(/[\.\/\\]/g, "-");
	
	// if no - then treat as no formatting entered
	if (text_date.indexOf("-") == -1) {
		text_date = text_date.substring(0, 2) + '-' + text_date.substring(2, 4) + '-' + text_date.substring(4);
	}
	
	var date = text_date.split("-");
		
	// add 20 or 19 to year if only 2 digits
	if (/^[0-4][0-9]$/.test(date[2])) {
		date[2] = '20' + date[2];
	} else if (/^[5-9][0-9]$/.test(date[2])) {
		date[2] = '19' + date[2];
	}
	date_str = date.join("-");
	// don't change field if resulting date_str is not formatted properly
	if (!/^[0-1]?[0-9]-[0-3]?[0-9]-[1|2][0|9][0-9]{2}$/.test(date_str)) {
		return;
	}
	element.value = date.join("-");
}