/********************************************************************
<vss>
*
* common.js
* Included JavaScript supporting common page functions.
*
* Note:
	4/21/04 - In VSS common.js is stored as common\control\js\common.js and
						is shared to other projects. 
						This shared link between projects should not be branched
						Sharing common.js between projects allows the developer to
						make his changes once and "get latest" to update other projects.
						Additional Note: When deployed there will be multiple copies of
						common.js.

* Original Programmer: Tyler Jensen
*
* Last Modified:	$Modtime: 4/11/05 9:42a $
* Modified by:		Bbarrow
*
</vss>
********************************************************************/

//textarea length limit functions
var ta_sublen = 0
var ta_lentest = true;
function taOnKeyPress(obj, evt, lenlimit) {
	if(ta_lentest == false) return true;
	else {
		if(obj.value.length < lenlimit) return true;
		else	{
			if((evt.keyCode <= 31) && (evt.keyCode != 13) || (evt.keyCode == 8))	return true; //ignore control keys
			else	{
				if(obj.value.length > lenlimit) {
					alert('The text length limit is ' + lenlimit + ' characters.\nYour input will be trimmed to that length.');
					obj.value = obj.value.substring(0, ta_sublen);
				}
				return false; //ignore keystroke
			}
		}
	}
}
function taOnBlur(obj, lenlimit) {
	if(obj.value.length > lenlimit) 	{
		alert('The text length limit is ' + lenlimit + ' characters.\nYour input will be trimmed to that length.');
		obj.value = obj.value.substring(0, ta_sublen);
		obj.focus();
	}
}

//string trim functions
function strltrim() {return this.replace(/^\s+/,'');}
function strrtrim() {return this.replace(/\s+$/,'');}
function strtrim() {return this.replace(/^\s+/,'').replace(/\s+$/,'');}
String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;

//string functions
function ReplaceString(s, search, repl) {return(s.replace(new RegExp(search, 'gi'), repl));}

//validation functions
function isNumber(str) {
   var re = /^[-]?\d*\.?\d*$/;
   str = str.trim();
   if (!str.match(re)) {
      return false;
   }
   return true;
} 
function isPositiveNumber(str) {
   var re = /^\d*\.?\d*$/;
   str = str.trim();
   if (!str.match(re)) {
      return false;
   }
   return true;
} 
function numberOnly(evt) {
	evt = (evt) ? evt : ((window.event) ? event : null);
	if (evt) {
		var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
		if (elem) {
			var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
			if ((charCode < 32) ||
				(charCode > 44 && charCode < 47) ||
				(charCode > 47 && charCode < 52)) {
					return true;
			} else {
				return false;
			}
		}		
	}
}
function positiveNumberOnly(evt) {
	evt = (evt) ? evt : ((window.event) ? event : null);
	if (evt) {
		var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
		if (elem) {
			var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
			if (charCode > 47 && charCode < 59)
				return true;
			 else
				return false;
		}		
	}
}
function upperOnly(event) {
	var charCode = event.keyCode;
	if(charCode > 96 && charCode < 123) {
		event.keyCode = charCode - 32;
	}
}
function WebDateChooser_KeyDown(oDropDown, keyCode, oEvent)
{
	if(keyCode == 13) {
		var ee = oEvent.event;
		ee.cancelBubble = true;
		ee.returnValue = false;
		if(doLookupClick){return doLookupClick();}
	}
}
/*
<vss>
 *$History: common.js $                                                        &
 * 
 * *****************  Version 11  *****************
 * User: Bbarrow      Date: 4/11/05    Time: 9:43a
 * Updated in $/SONAR/Development/Web/Common/Controls/js
 * Added WebDateChooser_KeyDown function.
 * 
 * *****************  Version 10  *****************
 * User: Jgroll       Date: 3/28/05    Time: 2:16p
 * Updated in $/SONAR 2.1/Development/Web/Sonar.Web.Case/controls/js
 * Changed positivenumberonly function.  
 * 
 * *****************  Version 9  *****************
 * User: Dnorth       Date: 3/26/05    Time: 2:54p
 * Updated in $/SONAR 2.1/Development/Web/Common/Controls/js
 * DT #8021
 * 
 * *****************  Version 8  *****************
 * User: Dnorth       Date: 3/26/05    Time: 2:41p
 * Updated in $/SONAR 2.1/Development/Web/Common/Controls/js
 * Added upperOnly function.
 * 
 * *****************  Version 7  *****************
 * User: Dnorth       Date: 3/25/05    Time: 8:21a
 * Updated in $/SONAR 2.1/Development/Web/Common/Controls/js
 * Added numberOnly and positiveNumberOnly onkeypress handlers.
 * 
 * *****************  Version 6  *****************
 * User: Dnorth       Date: 3/25/05    Time: 8:04a
 * Updated in $/SONAR 2.1/Development/Web/Common/Controls/js
 * Consolidate whitespace, etc.
 * 
 * *****************  Version 3  *****************
 * User: Tjensen      Date: 10/13/04   Time: 4:27p
 * Updated in $/SONAR/2.0/Development/Web/Sonar.Web.Bills/controls/js
 * update last fix
 * 
 * *****************  Version 2  *****************
 * User: Tjensen      Date: 10/13/04   Time: 4:06p
 * Updated in $/SONAR/2.0/Development/Web/Sonar.Web.Bills/controls/js
 * added IsNumeric function for 6397 - can be used elsewhere as well
 * 
 * *****************  Version 7  *****************
 * User: Sjensen      Date: 6/21/04    Time: 5:42p
 * Updated in $/Web Projects/Projects/SONAR/2.0/Development/Web/Sonar.Web.Bills/controls/js
 * Removed  old ltrim, rtrim and trim functions.  Added note comment about
 * sharing common.js between projects
 * 
 * *****************  Version 4  *****************
 * User: Dnorth       Date: 4/08/04    Time: 4:17p
 * Updated in $/Web Projects/Projects/SONAR/1.1/Development/Web/Sonar.Web.Bills/controls/js
 * Added new trim, ltrim, and rtrim jscript functions.
 * 
 * *****************  Version 3  *****************
 * User: Tjensen      Date: 3/05/04    Time: 11:51a
 * Updated in $/Web Projects/Projects/SONAR/1.1/Development/Web/Sonar.Web.Bills/controls/js
 * added vss comment tags
 * 
</vss>
 */
