        // Utility validation functions
        function strltrim() 
        {
            //Match spaces at beginning of text and replace with a null string
            return this.replace(/^\s+/,'');
        }
        function strrtrim() 
        {
            //Match spaces at end of text and replace with a null string
            return this.replace(/\s+$/,'');
        }
        function strtrim() 
        {
	        //Match spaces at beginning and end of text and replace
	        //with null strings
	        return this.replace(/^\s+/,'').replace(/\s+$/,'');
        }
        function boolIsEmail() {
        if (this.search(/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/) != -1)
            return true;
        else
            return false;
        }
        function boolIsPhone() {
        if( this.match(/[^0-9\s().-]+/g) )
	        return false;
        else
	        return true;
        }
        function boolIsZip() {
        if( this.search(/^[0-9]{5}(-[0-9]{4})?$/) != -1 )
	        return true;
        else
	        return false;
        }
        function boolIsAlpha() {
            if( this.search(/^[a-zA-Z]+$/) != -1 ) 
                return true;
            else
                return false;
        }
        function boolIsWholeNum() {
            if( this.search(/^[1-9][0-9]*/) != -1 ) 
                return true;
            else
                return false;
        }
        function boolIsNumYears() {
        if( this.search(/^[0-9]+$/) != -1 )
        {
	        x=parseInt(this);
	        if (isNaN(x)){
		        return false;
	        } else {
		        if (x>0 && x<100) {
			        return true;
		        } else {
			        return false
		        }
	        }
        } else {
	        return false;
        }
        }

        String.prototype.ltrim = strltrim;
        String.prototype.rtrim = strrtrim;
        String.prototype.trim = strtrim;
        String.prototype.isEmail = boolIsEmail;
        String.prototype.isPhone = boolIsPhone;
        String.prototype.isZip = boolIsZip;
        String.prototype.isAlpha = boolIsAlpha;
        String.prototype.isWholeNum = boolIsWholeNum;
        String.prototype.isNumYears = boolIsNumYears;

        function cleanTextField( value ) {
	        value = value.trim();
	        value = value.replace(/[<>]+/g,'');
	        value = value.replace(/\'/g,"''");
	        return value;
        }
        function cleanInput( obj ) {
	        obj.value = cleanTextField(obj.value);
        }
        function cleanTextarea512( value ) {
	        value = cleanTextField(value);
	        if( value.length > 512 )
		        value = value.substring(0,512);
	        return value;
        }
        function checkGroup(inputName, length) {
	        for( var i=1; i<=length; i++ )
	        {
		        if( document.getElementById(inputName+"_"+i).checked )
			        return true;
	        }
	        return false;
        }
        function isCleanedBlank( value ) {
	        return (value == "");
        }
        function isBlank( obj ) {
	        obj.value = cleanTextField( obj.value );
	        return (obj.value == "");
        }
        function AdditionalFormField() {
	        var name = null;
	        var text = null;
	        var type = null;
        }


        String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
       
        
        function roundOff(rnum, rlength)
		{
		        //value = "" + value //convert value to string

			var result = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);

		        //precision = parseInt(precision);
		        //var whole = "" + Math.round(value * Math.pow(10, precision));
		        //var decPoint = whole.length - precision;
		        //if(decPoint != 0)
		        //{
		        //        result = whole.substring(0, decPoint);
		        //        result += ".";
		        //        result += whole.substring(decPoint, whole.length);
		        //}
		        //else
		        //{
		        //        result = whole;
		        //}
			//alert(rnum + ' - ' + result);
		        //return "" + result;				
			return "" + roundNumber(rnum, rlength)
		}

	function roundNumber(number,decimals) {
	var newString;// The new rounded number
	decimals = Number(decimals);
	if (decimals < 1) {
		newString = (Math.round(number)).toString();
	} else {
		var numString = number.toString();
		if (numString.lastIndexOf(".") == -1) {// If there is no decimal point
			numString += ".";// give it one at the end
		}
		var cutoff = numString.lastIndexOf(".") + decimals;// The point at which to truncate the number
		var d1 = Number(numString.substring(cutoff,cutoff+1));// The value of the last decimal place that we'll end up with
		var d2 = Number(numString.substring(cutoff+1,cutoff+2));// The next decimal, after the last one we want
		if (d2 >= 5) {// Do we need to round up at all? If not, the string will just be truncated
			if (d1 == 9 && cutoff > 0) {// If the last digit is 9, find a new cutoff point
				while (cutoff > 0 && (d1 == 9 || isNaN(d1))) {
					if (d1 != ".") {
						cutoff -= 1;
						d1 = Number(numString.substring(cutoff,cutoff+1));
					} else {
						cutoff -= 1;
					}
				}
			}
			d1 += 1;
		} 
		newString = numString.substring(0,cutoff) + d1.toString();
	}
	if (newString.lastIndexOf(".") == -1) {// Do this again, to the new string
		newString += ".";
	}
	var decs = (newString.substring(newString.lastIndexOf(".")+1)).length;
	for(var i=0;i<decimals-decs;i++) newString += "0";
	//var newNumber = Number(newString);// make it a number if you like
	return newString; // Output the result to the form field (change for your purposes)

	}


		
        function converttodecimal(X)
        {
           with (new Object(Math.round(100*X)+''))
            {
	        return substring(0,length-2)+'.'+substring(length-2,length)
	        }
        }
        
        function addCommas(nStr)
        {
            nStr += '';
            x = nStr.split('.');
            x1 = x[0];
            x2 = x.length > 1 ? '.' + x[1] : '';
            var rgx = /(\d+)(\d{3})/;
            while (rgx.test(x1)) {
                x1 = x1.replace(rgx, '$1' + ',' + '$2');
            }
            return x1 + x2;
        }
        function CurrencyFormatted(amount)
        {
	        var i = parseFloat(amount);
	        if(isNaN(i)) { i = 0.00; }
	        var minus = '';
	        if(i < 0) { minus = '-'; }
	        i = Math.abs(i);
	        i = parseInt((i + .005) * 100);
	        i = i / 100;
	        s = new String(i);
	        if(s.indexOf('.') < 0) { s += '.00'; }
	        if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	        s = minus + s;
	        return s;
        }
        
        function StringToBool(val)
        {
            if ( val.toLowerCase() == "false" )
                {return false;}
            else if ( val.toLowerCase() == "true" )
                {return true;}
            else
                {return true;}
        }

        function IsEmpty(strTtxName,TxtValue)
        {
          if (TxtValue.length==0)
          {
            var strMsg = strTtxName+".";
            alert(strMsg);
            return 0;
          }
	        else
          {
            return 1;
          }
        }
        function check(QuickSearch) //All the validations done through this function.
        {
	        if (IsEmpty('Search field is blank',QuickSearch.APN.value)==0){document.QuickSearch.APN.focus();return false;}
	        if (IsEmpty('Please select a product',QuickSearch.SearchScope.options[QuickSearch.SearchScope.selectedIndex].value)==0){document.QuickSearch.SearchScope.focus();return false;}
                return true;
        }
