/********************************************************************************
'IMPORTANT NOTE:
'This file contains general purpose java functions/constants/variables usable in any project
'Please do not put in this file even slightest bit of code or constants specific to any project
'This file is shared with many projects in source safe, changes to this files will affect all 
'  the projects in which it is shared.
'Please take extreme care editing this file.
'Author: pna (Austin Computing Solutions)
'Date last modified: as in SourceSafe
'********************************************************************************/

function trim(strText) {
    // this will get rid of leading spaces
    while (strText.substring(0,1) == ' ')
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
   return strText;
}

function readonlyScroll(sender)
{
	//if( !(event.keyCode == 37 or event.keyCode == 39) )
	if(event.keyCode != 37 && event.keyCode != 39)
	{
		event.keyCode = 0;
		return false;
	}
	return true;
}

function getElement(sElementName)
{
	return window.document.getElementsByName(sElementName)[0];
}

function getElementById(sElementId)
{
	return window.document.getElementById(sElementId);
}


function CheckTextLength(sender, nMax)
{
	var e = event
	if( sender.value.length >= nMax )
	{
		if( e.type == "keydown")
		{
			if( e.keyCode == 32 || 
			e.keyCode >= 48 && e.keyCode <= 57 || 
			e.keyCode >= 65 && e.keyCode <= 90 )
			{
				alert("You have reached the maximum limit of " + nMax + " characters.")						
				e.keyCode = 0;
			}
		}
	}
}

function urlEncode(text) {
	//var pat = "/\//g"
	//text= text.replace(pat,"%2F");
	//text= text.replace(/\?/g,"%3F");
	//text= text.replace(/=/g,"%3D");
	//text= text.replace(/&/g,"%26");
	//text= text.replace(/ /g,"%20");
	text= text.replace(/#/g,"%23");
    return text;
}

function isNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   sText = rtrim(ltrim(sText));
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if ((i == 0) && (Char == "-")) // check first character for minus sign
		continue;
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}
   
function MoneyFormat(Number)
{
	sNumber = new String(Number*1);
	var PointIndex = sNumber.indexOf(".");
	
	if( PointIndex == -1)
	{ //No decimal point, it's a whole number
		sNumber += ".00";
		return  sNumber;
	}
	var Decimals;
	Decimals = sNumber.length - PointIndex - 1;
		if( Decimals == 0)
	{
		sNumber += "00";
		return  sNumber;
	}
	else if( Decimals == 1)
	{
		sNumber += "0";
		return  sNumber;
	}
	else  if( Decimals == 2)
	{
		return  sNumber;
	}
	else
	{
		return sNumber.substr(0,PointIndex+3);
	}
}

