
   function loseChangesMade() {
       var changes = "N";
        if (document.all.p_rowstatus) {
           if (document.all.p_rowstatus.length) {
              for (i=0;i<document.all.p_rowstatus.length;i++) {
                 if (document.all.p_rowstatus[i].value != "NEW" && document.all.p_rowstatus[i].value != "QUERY")
                     changes = "Y";
              }
           } else if (document.all.p_rowstatus.value != "NEW" && document.all.p_rowstatus.value != "QUERY")
                     changes = "Y";
       } else return true;
       if (changes=="N") 
             return true;  
       else {
         retVal = makeMsgBox ("Lose Changes Made?","Are you sure you want to lose your changes?",2,4,0,0);
         if (retVal == 6)
            return true;
         else
            return false;
       }
   } //end of changesMade()

function round(number,X) {
   // rounds number to X decimal places, defaults to 2
   X = (!X ? 2 : X);
   return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}


	function isPriorDate(checkDate, baseDate) {

        firstSlash  = checkDate.indexOf("/");
        secondSlash = checkDate.indexOf("/", firstSlash+1);
        checkMonth  = checkDate.substring(0,firstSlash);
        checkDay    = checkDate.substring(firstSlash+1,secondSlash);
        checkYear   = checkDate.substring(secondSlash+1,checkDate.length);
        
        firstSlash  = baseDate.indexOf("/");
        secondSlash = baseDate.indexOf("/", firstSlash+1);
        baseMonth   = baseDate.substring(0,firstSlash);
        baseDay     = baseDate.substring(firstSlash+1,secondSlash);
        baseYear    = baseDate.substring(secondSlash+1,checkDate.length);
        
        if (checkYear < baseYear) {
            return true;
        }
        if (checkYear > baseYear) {
           return false;
        }
        if (checkMonth < baseMonth) {
           return true;
        }
        if (checkMonth > baseMonth) {
           return false;
        }
        if (checkDay < baseDay) {
           return true;
        }
        return false;
                  
     }  //end of function isPriorDate()

/*======================================================================================= 
checkSimpleInteger() - makes sure we've got a number with no signs or commas just a plain integer
======================================================================================*/
function checkSimpleInteger(obj) {
                  
     if (obj.value.indexOf("-") != -1 || 
         obj.value.indexOf("+") != -1 || 
         obj.value.indexOf(",") != -1 ||
         isNaN(obj.value)) {
         alert("Please enter a simple integer number.");
         obj.focus();
         return false; 
    }
 }

/*======================================================================================= 
validNumber() - takes a format mask.  uses 9 for optional number, 0 for default of 0, and a decimal
======================================================================================*/


        function validNumber(theObject, format, noNegatives)
                   {
					if (noNegatives)
						{
							if (theObject.value < 0)
							{
								alert("Negative numbers are not allowed in this numeric field");
								return false;
							}
						}
					if (isNaN(theObject.value))
                           {
                           alert("A non-numeric character was discovered in a numeric field");
                           // makeMsgBoxInvNum("Invalid Number", "A non-numeric character was discovered in a numeric field", 2, 6, 0, 0);
                            return false;
                           }
                    theDecimal = theObject.value.indexOf(".");
                    if (theDecimal != -1) {
                       preDecimal  = theObject.value.substring(0, theDecimal);
                       postDecimal = theObject.value.substring(theDecimal+1,theObject.value.length);
                    } else {
                       preDecimal  = theObject.value;
                       postDecimal = "";  
                    }
                    formatDecimal = format.indexOf(".");
                    if (formatDecimal != -1) {
                       preformatDecimal  = format.substring(0, formatDecimal);
                       postformatDecimal = format.substring(formatDecimal+1,format.length);
                    } else {
                       preformatDecimal  = format;   
                       postformatDecimal = "";  
                    }
//alert(theObject.value+": "+preDecimal+":"+theDecimal+":"+postDecimal+" / "+format+": "+preformatDecimal+":"+formatDecimal+":"+postformatDecimal);
                   if (formatDecimal == -1 && theDecimal != -1) { 
                            alert("Number does not accept decimal values.");
                            //makeMsgBoxInvNum("Invalid Number", "Number does not accept decimal values.", 2, 6, 0, 0);
                            return false;
                           }
                   if (preDecimal.length > preformatDecimal.length) {
                            alert("Number too large.");
                            //makeMsgBoxInvNum("Invalid Number", "Number too large.", 2, 6, 0, 0);
                            return false;
                           } 
                   if (postDecimal.length > postformatDecimal.length) {
                            alert("Too many numbers after the decimal.");
                            //makeMsgBoxInvNum("Invalid Number", "Too many numbers after the decimal.", 2, 6, 0, 0);
                            return false;
                           } 
       //the obvious problems are covered. now insert zeroes where desired before ending
                   if ((format.indexOf("0", formatDecimal-1, formatDecimal+1) != -1) &&
                       (theObject.value != "" && theObject.value != null)) {
                         //put in the zeroes if necessary
                        zeroes = 0;
                           for(i=preformatDecimal.length;i>=0;--i) {
                              if (preformatDecimal.substring(i,i+1).indexOf("0") != -1) {
                                  ++zeroes;
                              }
                           }
                           zeroes = zeroes - preDecimal.length;
                           if (zeroes > 0) {
                             for(i=1;i<=zeroes;++i) {
                                 theObject.value = "0"+theObject.value;
                             }
                           }
                          if (postformatDecimal.length > 0) {
                             zeroes = 0;
                             for(i=0;i<=postformatDecimal.length;++i) {
                                if (postformatDecimal.substring(i,i+1).indexOf("0") != -1) {
                                    ++zeroes;
                                }
                             }
                             zeroes = zeroes - postDecimal.length;
                             if (zeroes > 0) {
                               if (theDecimal == -1) {
                                  theObject.value = theObject.value+".";
                               }
                               for(i=1;i<=zeroes;++i) {
                                   theObject.value = theObject.value+"0";
                               }
                             }
                           }
                   }
                 return true;
                     } 


/*======================================================================
validDate()

Description: 
Pass in the object to be checked. Provides a method for checking the validity of a date.  It returns the date in the object in the format "MM/DD/YYYY" if it is correct.  Alerts the user if it is not correct and does not affect the object's value.

 Checks formatting, must use exactly two slashes.
 Checks end of month except for leap year.
 Checks two digit year, assumes year 1900 if greater than 70, assumes
 year 2000 if less than 70.
 Checks that all entered values are numbers
 Change made by VASANT to check for leap year (2/29 is valid only for leap year)
====================================================================== */
function validDate(v_date) {
	// Check for empty string date first
	if (v_date.value == "") {
		return true;
	}
        first_slash  = v_date.value.indexOf("/");
        second_slash = v_date.value.indexOf("/", first_slash+1);
        v_month     = v_date.value.substring(0, first_slash);
        v_day      = v_date.value.substring(first_slash+1,second_slash);
        v_year      = v_date.value.substring(second_slash+1,v_date.value.length);
        //      alert("month "+v_month);
        //      alert("day "+v_day);
        //      alert("year "+v_year);
        if (second_slash == -1 || v_month < 1 || v_month > 12 || v_day < 1 || v_day > 31 || 
		(v_year.length != 4 && v_year.length != 2) || (v_year.substring(0,1) > 2 && v_year.length > 2)) 
	{
		alert("Please enter a valid date. e.g, MM/DD/YYYY");
		v_date.focus();
		return false;              
	} else { 
		if (((v_month == 4 || v_month == 6 || v_month == 9 || v_month == 11) && v_day > 30)||(v_month == 2 && v_day > 29)) 
		{
			alert("Please enter a valid date; e.g, MM/DD/YYYY");
			v_date.focus();
			return false;
		}
	}

	if (v_month.length < 2)  {    
	    v_month = "0"+ v_month;                
	}

    	if (v_month.length > 2)  {    
          alert("Please enter a valid date; e.g, MM/DD/YYYY");
	    v_date.focus();
          return false;
	}
              
	       
	if (v_day.length < 2)  {    
	    v_day = "0"+ v_day;                
	}

      if (v_day.length > 2)  {    
          alert("Please enter a valid date; e.g, MM/DD/YYYY");
	    v_date.focus();
          return false;
	}
        
	var today = new Date();
	if (v_year.length < 3)  { 
                 if (v_year > 69) { 
                    v_year = "19" + v_year;
                 }
                 else {
                    v_year = "20" + v_year;
                 }
	}
	
	//make sure the entry is all numbers not characters
	v_numbers = "0123456789";
	if (v_numbers.indexOf(v_month.substring(0,1)) == -1 ||
		v_numbers.indexOf(v_month.substring(1,2)) == -1 ||
               	v_numbers.indexOf(v_day.substring(0,1)) == -1 ||
               	v_numbers.indexOf(v_day.substring(1,2)) == -1 ||
               	v_numbers.indexOf(v_year.substring(0,1)) == -1 ||
               	v_numbers.indexOf(v_year.substring(1,2)) == -1 ||
               	v_numbers.indexOf(v_year.substring(2,3)) == -1 ||
               	v_numbers.indexOf(v_year.substring(3,4)) == -1) {
                	alert("Please enter a valid date; e.g, MM/DD/YYYY");
			v_date.focus();
                	return false;
	} 

	     // Check for leap year
		if (v_month == 2 && v_day == 29 )
                { 
			if (v_year % 4 > 0)
			{
                  		alert("Please enter a valid date; e.g, MM/DD/YYYY");
				v_date.focus();
                  		return false;
			} 
			if (v_year % 100 == 0 && v_year % 400 > 0 )
			{
				alert("Please enter a valid date; e.g, MM/DD/YYYY");
				v_date.focus();
				return false;
			} 
		}

              v_date.value = v_month+"/"+v_day+"/"+v_year;
              return true;
       }

/*======================================================================
   maxTextArea()

   Description: 
   Takes a text area object and a number.  If the length of the text 
   area's value is greater than the number given, the text is truncated 
   to the maxLength and returned.  If not greater, the original text 
   value is returned.
====================================================================== */
     function maxTextArea(textAreaObj, maxlength) {
      // This is length of item minus what key user just pressed
      var strLength = textAreaObj.value.length;
      // figure out what user typed
      var charCode = window.event.keyCode;
      if (charCode == 13) {
         // User just typed a carriage return we need to count that as 2
         strLength = strLength + 2;
      } else {
         // User typed some other character count it as 1
         strLength++;
      }
      if (strLength > maxlength) {
          textAreaObj.value = textAreaObj.value.substring(0,(maxlength));
            return false;
      }  else {
            return true;
      }
   }

/*=============================================================================

checkDecimalFormat - ensures that a decimal is placed in a particular place
           theObject - the text field thats to be checked
           precision - the number of digits allowed to the right of the decimal

                   
===============================================================================*/


                  function checkDecimalFormat(theObject, precision)
                         {
                    var objectValueString=theObject.value; //the value of the text field
                    var objectName=theObject.name;  //the name of the text field
                    adjustedPrecision=theObject.maxLength-precision; //the adjusted decimal offset given
                                                             //the fact that the string counts from the right
                    var strLength=objectValueString.length   //the length of the value passed in
                    

                        //append zeros to the string to ensure a
                        //constant length when comparing the placement of the decimal
 
                         for(x=0;x<theObject.maxLength-strLength;x++)
                           {
                             objectValueString="0"+objectValueString;
                           }
                           
                              
                     //This loop finds the . if it exists and checks the placement - returns false 
                     //if the decimal is not in the correct place.
                     
                         for(i=0;i<theObject.maxLength;i++)
                        {
                         var ch=objectValueString.charAt(i);
                        
                         if (ch==".")
                               {
                              
                               if(i<adjustedPrecision-1)
                                  { 
                                   makeMsgBox("Invalid Number", "The decimal must not occur more than "+precision+" spaces from the right.", 2, 6, 0, 0);
                                   
                                   return false;
                                   
                                  }
                                }
                         }
						 return true;
                        }


/*======================================================================================================
CheckDecimalLength - allows for the maxlength to be 1 greater than the DB supports
                     so a decimal can be used.  

                      theObject - the text field that is to be checked
                      precision - the number of digits to the right of the decimal that should be allowed
                                  if this parameter exists, CheckDecimalLength call CheckDecimalValue to 
                                  ensure that the correct number of decimals are present
=======================================================================================================*/



                 function checkDecimalLength(theObject, precision) 
                    {
                    var objectValueString=theObject.value;
                    var offset=1;
					var integerLength=0;
					var theObjIntLen=0;
                    for(i=0;i<objectValueString.length;i++)
                    {
                        var ch=objectValueString.charAt(i);
                        if (ch==".")
                        {
                              offset=0;
                               break;
                        }
                        theObjIntLen++;
                    }

					// First check the decimal places for precision
					 if (precision!="") 
                       {
                         var boo=checkDecimalFormat(theObject, precision);
						 if (!boo)
						 {
							 return boo;
						 }
                       }

					// Now check the units places for length
					 integerLength = theObject.maxLength-precision-1;
					 if (theObjIntLen>integerLength)
                       {
                       makeMsgBox("Invalid Number","Input to this field must have a format of "+integerLength+"."+precision+": "+integerLength+" Units places and "+precision+" Decimal places.", 2, 6, 0, 0);
                       return false;
                       }
                   return true;
              }

/*======================================================================================================
CheckNumber - ensures that whats entered into a text field that is suppose to be numeric is indeed numeric
                       theObject - the text field being checked
                       precision - calls the preceding functions to check for precision. It can
                                   be left off if all you want is to check for number
=========================================================================================================*/


        function checkNumber(theObject, precision)
                   {
				   var objectValue = theObject.value;
				   if (objectValue == ".")
				   {
						objectValue = "0" + objectValue;
				   }
				    if (window.event.type == "keypress")
				    {
						objectValue += String.fromCharCode(window.event.keyCode);
						if (isNaN(objectValue))
						{
							window.event.keyCode = "";
						}
				    }

                    if (isNaN(objectValue))
                           {
                            makeMsgBox("Invalid Number", "A non-numeric character was discovered in a number-only field", 2, 6, 0, 0);
                            return false;
                           }
                      if (precision!="") 
                       {
                         var boo=checkDecimalLength(theObject, precision);
                         return boo;
                       }
                 return true;
                     } 
