// the following functions provide input masking capabilities
var cbCharsRe = /[cvxz]/i;
var kbCharsRe = /[\x08\x0D\x00\x03\x16\x18\x1A]/;
var numCharsRe = /\d/;
var doubleRe = /[\d\.]+/;

/* Check copy/paste/cut/undo keystrokes */
function chkClipboard(e, ch) {
	if (e.which) {
		return e.ctrlKey && cbCharsRe.test(ch);
	} else {
		return false;
	}
}

/* Validate the keystroke against a regular expression */
function kc(e, allowRe) {
	var ch = getKeyChar(e);
  	return (allowRe.test(ch) || kbCharsRe.test(ch) || chkClipboard(e, ch));
}

/* Validate the keystroke is a numeric value */
function cn(e) {
  	return kc(e, numCharsRe);
}

/* Validate the keystroke is a double (floating point) value */
function cdb(formValue, e) {
  	var isValid = kc(e, doubleRe);
  	if(isValid) {
		var ch = getKeyChar(e);
		if(ch == ".") {
			if(formValue.indexOf(".") >= 0) {
				return false;
			} else {
				return true;
			}
		} else {
			return true;
		}
  	} else {
     	return false;
  	}
}

/* Get the keystroke character from an event */
function getKeyChar(e) {
	var key;
	if(window.event) {
		key = e.keyCode; // for IE, e.keyCode or window.event.keyCode
	} else if(e.which) {
		key = e.which; // netscape
	}
	var ch = String.fromCharCode(key);
	return ch;
}

var isDHTML = 0;
var isLayers = 0;
var isAll = 0;
var isID = 0;

if (document.getElementById) {isID = 1; isDHTML = 1;}
else {
browserVersion = parseInt(navigator.appVersion);
if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {isLayers = 1; isDHTML = 1;}
else {
if (document.all) {isAll = 1; isDHTML = 1;}
}}

function findDOM(objectID,withStyle) {
var menuArea = "menuArea";
   if (withStyle == 1) {
      if (isID) { return (document.getElementById(objectID).style) ; }
      else { 
         if (isAll) { return (document.all[objectID].style); }
      else {
         if (isLayers) { return (document.layers[menuArea].layers[objectID]); }
      };}
   }
   else {
      if (isID) { return (document.getElementById(objectID)) ; }
      else { 
         if (isAll) { return (document.all[objectID]); }
      else {
         if (isLayers) { return (document.layers[menuArea].layers[objectID]); }
      };}
   }
}

function displayPop(url, name, width, height) {
   var myWin;
   if (document.layers)
      myWin = window.open(url, name, "width=" + width + ",height=" + height + ",resizable=yes,scrollbars=yes,toolbar=no,screenX=20,screenY=20");
   else
      myWin = window.open(url, name, "width=" + width + ",height=" + height + ",resizable=yes,scrollbars=yes,toolbar=no,top=20,left=20");
   myWin.focus();
}

/* Make hover menus work in stupid, broken IE */
sfHover = function() {
	var sfEls = document.getElementById("nav-tabs").getElementsByTagName("TD");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


