/*--- 
************************************************************************************************

@name			js_SubFunctions.js

@description  	this script contains all the subfunctions used by SubmitForm for ease of
				implementation.:

			
@param			object_value (string) - value to be evaluated

@return			(boolean) - true, if edit check passes
						  - false, if edit check fails

						  
@author			john dugan
@authoremail	john.dugan@weberize.com

@copyright		Copyright (c) 2000 by Weberize.  All rights reserved.
@date			12/31/2000
				
************************************************************************************************
---*/



//*************************************************************************************//
//  check credit card number routine                                                   //
//*************************************************************************************//
	
	//----------------------------------------------------------------------//
	//---  javascript to validate a credit card number.                  ---//
	//----------------------------------------------------------------------//

		function checkcreditcard(object_value, card_type) {
	     	
			//--------------------------------------------//
			//---  remove leading and trailing spaces  ---//
			//--------------------------------------------//
			trimmed_card_type = trim(card_type);
			
			
			//------------------------------//
			//---  if null, return true  ---//
			//------------------------------//
		    if (trimmed_card_type.length == 0)
		        return true;
			
	
			//--------------------------------------------//
			//---  remove leading and trailing spaces  ---//
			//--------------------------------------------//
			trimmed_object_value = trim(object_value);
			
			
			//------------------------------//
			//---  if null, return true  ---//
			//------------------------------//
		    if (trimmed_object_value.length == 0)
		        return true;
			
	
			//-----------------------------------------------//
			//---  credit card number must be an integer  ---//
			//-----------------------------------------------//
	     	if (!checkinteger(trimmed_object_value))
	        	return false;
	      
	         
			//--------------------------------------------------------//
			//---  evaluate card type and  run appropriate checks  ---//
			//--------------------------------------------------------//
	     	switch (trimmed_card_type) {
				
				//---  american express  ---//
				case "amex":
	        		if ( ((trimmed_object_value.substring(0,2) != "34") && (trimmed_object_value.substring(0,2) != "37") ) || (trimmed_object_value.length != 15) ) { 
						return false
					}
					break
				
				//---  discover  ---//
				case "disc":
					if ( (trimmed_object_value.substring(0,4) != "6011") || ( (trimmed_object_value.length != 13) && (trimmed_object_value.length != 16) ) ) { 
						return false
					}
					break
				
				//---  mastercard  ---//
				case "mc":
					if ( (trimmed_object_value.substring(0,1) != "5") || (trimmed_object_value.length != 16) ) { 
						return false
					}
					break
				
				//---  visa  ---//
				case "visa":
					if ( (trimmed_object_value.substring(0,1) != "4") || ( (trimmed_object_value.length != 13) && (trimmed_object_value.length != 16) ) ) { 
						return false
					}
					break

				default:
					return true
					
			}
	      
	         			
			//-------------------------------//
			//---  set working variables  ---//
			//-------------------------------//
			var doubledigit = trimmed_object_value.length % 2 == 1 ? false : true;
		    var checkdigit = 0;
		    var tempdigit;
	    	
			
			//----------------------//
			//---  mod 10 check  ---//
			//----------------------//
	   	    for (var i=0; i < trimmed_object_value.length; i++) {
		    	
				tempdigit = eval(trimmed_object_value.charAt(i))
		
		    	if (doubledigit) {
				
					tempdigit *= 2;
		            checkdigit += (tempdigit % 10);
		
					if ((tempdigit / 10) >= 1.0)
						checkdigit++;
					
					doubledigit = false;
		        }
		        else {
		        	
					checkdigit += tempdigit;
		            doubledigit = true;
				}
		     }       
		     
			 
			 //----------------------------------------------------------------//
			//---  if check digit not evenly divisible by 10, return false  ---//
			//-----------------------------------------------------------------//
			if (checkdigit % 10 != 0)
				return false;
				
				
			//-------------------------------------------------------//
			//---  if card number passed all checks, return true  ---//
			//-------------------------------------------------------//
			return true;
		}



//*************************************************************************************//
//  check date routine                                                                 //
//*************************************************************************************//
	
	//----------------------------------------------------------------------//
	//---  javascript to validate a date.                                ---//
	//----------------------------------------------------------------------//
	
		function checkdate(object_value) {
		
			//--------------------------------------------//
			//---  remove leading and trailing spaces  ---//
			//--------------------------------------------//
			trimmed_object_value = trim(object_value);
			
			
			//------------------------------//
			//---  if null, return true  ---//
			//------------------------------//
		    if (trimmed_object_value.length == 0)
		        return true;
			
				
				
			//-----------------------------------------//
			//---  require length between 8 and 10  ---//
			//-----------------------------------------//
			if ((trimmed_object_value.length < 8) || (trimmed_object_value.length > 10))
				return false;
				
		
			//-----------------------------------//
			//---  find first and last slash  ---//
			//-----------------------------------//
			iFirstSlash  = trimmed_object_value.indexOf("/");
			iSecondSlash = trimmed_object_value.lastIndexOf("/");
			
			
			//--------------------------------------------------------------------//
			//---  first slash must exist and cannot be in the first position  ---//
			//--------------------------------------------------------------------//
			if (iFirstSlash < 1)		
				return false;
			
			
			//------------------------------------------------------------------------------//
			//---  second slash must exist and cannot be in the last position or sooner  ---//
			//---    than the third position                                             ---//
			//------------------------------------------------------------------------------//
			if ((iSecondSlash < 3) || (iSecondSlash == trimmed_object_value.length - 1))
				return false;
			
			
			//-------------------------------------------------//
			//---  first and second slash must be distinct  ---//
			//-------------------------------------------------//
			if (iFirstSlash == iSecondSlash)			
				return false;
			
			
			//-----------------------------------------------------------------------------//
			//---  set month, day, and year values (numbers look goofy because indices  ---//
			//---    are calculated differently)                                        ---//
			//-----------------------------------------------------------------------------//
			sMonth = trimmed_object_value.substring(0, (iFirstSlash));
			sDay   = trimmed_object_value.substring((iFirstSlash + 1), (iSecondSlash));
			sYear  = trimmed_object_value.substring(iSecondSlash + 1);
			
			//--------------------------------------------------------//
			//---  if first digit of month or day is 0, strip off  ---//
			//--------------------------------------------------------//
			if (sMonth.charAt(0) == "0")
				sMonth = sMonth.substring(1);
			if (sDay.charAt(0) == "0")
				sDay = sDay.substring(1);
				
			//----------------------------------------//
			//---  month must be between 1 and 12  ---//
			//----------------------------------------//
			if (!checkrange(sMonth,'1','12'))
				return false;
			
			//--------------------------------------------//
			//---  year must be between 1500 and 2500  ---//
			//--------------------------------------------//
			if (!checkyear(sYear))
				return false;
			
			//---------------------------------------------------------------//
			//---  day must fall within appropriate range for that month  ---//
			//---------------------------------------------------------------//
			if (!checkday(sMonth,sDay,sYear))
				return false;
			
			
			return true;
		}
	
	
	
//*************************************************************************************//
//  check day routine                                                                  //
//*************************************************************************************//

	//----------------------------------------------------------------------//
	//---  javascript to validate a day against a month and year.        ---//
	//----------------------------------------------------------------------//
	
		function checkday(iMonth, iDay, iYear) {
			
			//----------------------------------------------//
			//---  if month with 31 days, max day is 31  ---//
			//----------------------------------------------//		
			if (iMonth == "1" || iMonth =="3" || iMonth == "5" || iMonth == "7" || 
			    iMonth == "8" || iMonth == "10" || iMonth == "12") { 
			    
				iMaxDay = 31; 
			}
			
			//----------------------------------------------//
			//---  if month with 30 days, max day is 30  ---//
			//----------------------------------------------//	
			else if (iMonth == "4" || iMonth == "6" || iMonth == "9" || iMonth == "11") { 
				
				iMaxDay = 30; 
			}
			
			//-------------------------------------------------//
			//---  if february, max day is either 28 or 29  ---//
			//-------------------------------------------------//	
			else { 
				
				if ((iYear % 4) == 0) {
					if ( ((iYear % 100) == 0) && ((iYear % 400) != 0) ) {
					
						iMaxDay = 28;
					}
					else {
						
						iMaxDay = 29;
					}
				}
				else {
				
					iMaxDay = 28;
				} 
			}
			
			//-------------------------------------------------//
			//---  check that day is between 1 and max day  ---//
			//-------------------------------------------------//	
			if ((iDay < 1) || (iDay > iMaxDay)) {

				return false;
			}
		
			return true;
		}
		

		
//*************************************************************************************//
//  check email routine                                                                //
//*************************************************************************************//
	
	//-----------------------------------------------------------------------//
	//---  javascript to validate an email address.                       ---//
	//-----------------------------------------------------------------------//
	
		function checkemail(object_value) {
		
			//--------------------------------------------//
			//---  remove leading and trailing spaces  ---//
			//--------------------------------------------//
			trimmed_object_value = trim(object_value);
			
			
			//------------------------------//
			//---  if null, return true  ---//
			//------------------------------//
			if (trimmed_object_value.length == 0)
				return true;
			
			
			//------------------------------//
			//---  require @ symbol      ---//	
			//------------------------------//	
			if (trimmed_object_value.indexOf("@") == -1)
				return false;
			
						
			//---------------------------//	
			//---  require no spaces  ---//
			//---------------------------//
			if (trimmed_object_value.indexOf(" ") != -1)
				return false;
			
			
			//---------------------------//
			//---  set position of @  ---//
			//---------------------------//
			var iAtIndex = trimmed_object_value.indexOf("@");
			
			
			//------------------------------------------------------//
			//---  @ must exist and cannot be in first position  ---//
			//------------------------------------------------------//
			if (iAtIndex < 1)
				return false;
			
			
			//----------------------------------------------------//
			//---  set string equal to everything after the @  ---//
			//----------------------------------------------------//	
			var sRightPart = trimmed_object_value.substr(iAtIndex + 1);
		
	
			//------------------------------------------------------------//
			//---  require a period in the 2rd or greater position to  ---// 
			//---    the right of the @ sign                           ---//
			//------------------------------------------------------------//
			if (sRightPart.indexOf(".") < 1)
				return false;
	
			
			//--------------------------------------------------------------------------//
			//---  require 4 or more characters to the right of the @ sign, forcing  ---// 
			//---    the TLD to be 2 or more characters                              ---//
			//--------------------------------------------------------------------------//
			if (sRightPart.length < 4)
				return false;
				
		
		
			return true;
		}


	
//*************************************************************************************//
//  check file name routine                                                                //
//*************************************************************************************//
	
	//-----------------------------------------------------------------------//
	//---  javascript to validate a file name.                            ---//
	//-----------------------------------------------------------------------//
	
		function checkfilename(object_value) {
		
			//--------------------------------------------//
			//---  remove leading and trailing spaces  ---//
			//--------------------------------------------//
			trimmed_object_value = trim(object_value);
			
			
			//------------------------------//
			//---  if null, return true  ---//
			//------------------------------//
			if (trimmed_object_value.length == 0)
				return true;
			
			
			//------------------------------//
			//---  disallow '\' and ':'  ---//	
			//------------------------------//	
			if ((trimmed_object_value.indexOf("\\") > -1) || (trimmed_object_value.indexOf(":") > -1))
				return false;
			
				
			//---------------------------//
			//---  set position of .  ---//
			//---------------------------//
			var iPeriodIndex = trimmed_object_value.indexOf(".");
			
			
			//--------------------------------------------------------------//
			//---  . must exist and cannot be in first or last position  ---//
			//--------------------------------------------------------------//
			if ((iPeriodIndex < 1) || (iPeriodIndex == (trimmed_object_value.length - 1)))
				return false;
			
			
			
			return true;
		}


//*************************************************************************************//
//  check integer routine                                                              //
//*************************************************************************************//
	
	//----------------------------------------------------------------------->
	//---  javascript to validate an integer.  Converts spaces to nulls.  --->
	//---  Returns true for nulls; returns false if charAt is not a       --->
	//---  base-10 digit.                                                 --->
	//----------------------------------------------------------------------->
	
		function checkinteger(object_value) {
			
			//--------------------------------------------//
			//---  remove leading and trailing spaces  ---//
			//--------------------------------------------//
			trimmed_object_value = trim(object_value);
			
			
			//------------------------------------------------------------------//
			//---  if not null, make sure each character is a base-10 digit  ---//
			//------------------------------------------------------------------//
			if (trimmed_object_value.length != 0) {
			
				for (i=0; i < trimmed_object_value.length; i++) {
				
					if (trimmed_object_value.charAt(i) < "0" || trimmed_object_value.charAt(i) > "9")
						return false;
				}		
			}
			
			return true
		}
		

		
//*************************************************************************************//
//  check number routine                                                               //
//*************************************************************************************//
	
	//---------------------------------------------------//
	//---  javascript to validate a rational number.  ---//
	//---------------------------------------------------//

		function checknumber(object_value) {
    
			//--------------------------------------------//
			//---  remove leading and trailing spaces  ---//
			//--------------------------------------------//
			trimmed_object_value = trim(object_value);
			
			
			//------------------------------//
			//---  if null, return true  ---//
			//------------------------------//
		    if (trimmed_object_value.length == 0)
		        return true;
		    
			
			//--------------------------------------//
			//---  last character cannot be '.'  ---//
			//--------------------------------------//
		    if (trimmed_object_value.indexOf(".") == (trimmed_object_value.length - 1))
		        return false;
		    
			
			//-------------------------------//
			//---  set working variables  ---//
			//-------------------------------//
			var first_possible_char  = ".+-0123456789";
        	var other_possible_char  = ".0123456789";
        	var check_char;
        	var decimal = false;
        	

    		
			//--------------------------------------------------------//
			//---  first character can be '+', '-', '.', or digit  ---//
			//--------------------------------------------------------//
	        check_char = first_possible_char.indexOf(trimmed_object_value.charAt(0))
    
			
			//----------------------------------------------------------//
			//---  if first char not in possible list, return false  ---//
			//----------------------------------------------------------//
			if (check_char < 0) 
				return false;
			
			
			//--------------------------------------------//
			//---  if first char decimal, set boolean  ---//
			//--------------------------------------------//
        	if (check_char == 0)
            	decimal = true;
        
		
			//---------------------------------------------------------------------//        
        	//---  remaining characters can be '.' or digit (only one decimal)  ---//
			//---------------------------------------------------------------------//
        	for (var i=1; i < object_value.length; i++) {
				
				check_char = other_possible_char.indexOf(trimmed_object_value.charAt(i))
                
				if (check_char < 0)
                	return false;
                
				if (check_char == 0) {
					
					if (decimal) {
                    	return false;
					}
                    else {
                    	decimal = true;
					}
                }
                
        	}       
    
    		
			return true
		}

	
//*************************************************************************************//
//  check phone routine                                                                //
//*************************************************************************************//
	
	//----------------------------------------------------------------------//
	//---  javascript to validate a phone number (nnn-nnn-nnnn).         ---//
	//----------------------------------------------------------------------//

		function checkphone(object_value) {
			
			//--------------------------------------------//
			//---  remove leading and trailing spaces  ---//
			//--------------------------------------------//
			trimmed_object_value = trim(object_value);
			
			
			//------------------------------//
			//---  if null, return true  ---//
			//------------------------------//
		    if (trimmed_object_value.length == 0)
		        return true;
		    
			
			//----------------------------------------//
			//---  if length not 12, return false  ---//
			//----------------------------------------//
		    if (trimmed_object_value.length != 12)
		        return false;

		
			//---------------------------------//
			//---  break number into parts  ---//
			//---------------------------------//
			phone1    = trimmed_object_value.substring(0,3);
			slash1    = trimmed_object_value.charAt(3);
			phone2    = trimmed_object_value.substring(4,7);
			slash2    = trimmed_object_value.charAt(7);
			phone3    = trimmed_object_value.substring(8,12);
			min_value = "100";
			max_value = "999";
			
			
			//----------------------------------------------------------//
			//---  area code must be an integer between 100 and 999  ---//
			//----------------------------------------------------------//
		    if (!checkrange(phone1, min_value, max_value))
				return false;
			
			
			//-------------------------------------------------//
			//---  require area code separator to be a "-"  ---//
			//-------------------------------------------------//
		    if (slash1 != "-")
		    	return false;

			
		    //---------------------------------------------------------//
			//---  exchange must be an integer between 100 and 999  ---//
			//---------------------------------------------------------//
		    if (!checkrange(phone2, min_value, max_value))
				return false;
			
		    
			//------------------------------------------------//
			//---  require exchange separator to be a "-"  ---//
			//------------------------------------------------//
		    if (slash2 != "-")
		    	return false;
			
			
		    //---------------------------------------------//
			//---  last four digits must be an integer  ---//
			//---------------------------------------------//
		    if (!checkinteger(phone3))
				return false;
						
		    
			return true;
		}
		

	

//*************************************************************************************//
//  check value range routine                                                          //
//*************************************************************************************//

	//-------------------------------------------------------------------------//
	//---  javascript to require a number to be within an inclusive range.  ---//
	//-------------------------------------------------------------------------//
	
		function checkrange(object_value, min_value, max_value) {
			
			//--------------------------------------------//
			//---  remove leading and trailing spaces  ---//
			//--------------------------------------------//
			trimmed_object_value = trim(object_value);
			temp_object_value    = trimmed_object_value;
			
			
			//------------------------------//
			//---  if null, return true  ---//
			//------------------------------//
		    if (trimmed_object_value.length == 0)
		        return true;
				
				
			//--------------------------------------------------------------//
		    //---  if minimum value or maximum value null, return false  ---//
			//--------------------------------------------------------------//
		    if ( (min_value == null) || (max_value == null) )
				return false;
			
		    
			//------------------------------------------------------------------------//
		    //---  if minimum value or maximum value are integers, pad with zeros  ---//
			//---    so all values have same length                                ---//
			//------------------------------------------------------------------------//
		    if ( (checkinteger(min_value)) && (checkinteger(max_value)) ) {
				
				//---  reset trimmed object value  ---//
				trimmed_object_value = temp_object_value;
				
				//---  set all lengths  ---//
				length_object = trimmed_object_value.length;
				length_min    = min_value.length;
				length_max    = max_value.length;
				
				//---  determine longest length  ---//
				if (length_object >= length_min) {
				
					if (length_object >= length_max) {
						length_longest = length_object;
					}
					else {
						length_longest = length_max;
					}
				}
				else {
				
					if (length_min >= length_max) {
						length_longest = length_min
					}
					else {
						length_longest = length_max
					}
				}
				
				//---  pad object value with zeros if shorter than longest length  ---//
				if (length_object != length_longest) {
					
					temp_value = "";
					
					length_diff = length_longest - length_object;
					for (i=0; i < length_diff; i++) {
						temp_value += "0";
					}
				
					trimmed_object_value = temp_value + trimmed_object_value;
				}
				
				//---  pad min value with zeros if shorter than longest length  ---//
				if (length_min != length_longest) {
					
					temp_value = "";
					
					length_diff = length_longest - length_min;
					for (i=0; i < length_diff; i++) {
						temp_value += "0";
					}
				
					min_value = temp_value + min_value;
				}
				
				//---  pad max value with zeros if shorter than longest length  ---//
				if (length_max != length_longest) {
					
					temp_value = "";
					
					length_diff = length_longest - length_max;
					for (i=0; i < length_diff; i++) {
						temp_value += "0";
					}
				
					max_value = temp_value + max_value;
				}
			}
			
		           			
			//---------------------------------------------------------------------------------//
		    //---  if object_value less than minimum or greater than maximum, return false  ---//
			//---------------------------------------------------------------------------------//
		    if ((trimmed_object_value < min_value) || (trimmed_object_value > max_value))
				return false;
			
		        
		    return true;
		}


//*************************************************************************************//
//  check ssn routine                                                                  //
//*************************************************************************************//
	
	//------------------------------------------------------------------------>
	//---  javascript to validate an ssn.  must be in format 555-55-5555.  --->
	//------------------------------------------------------------------------>
	
		function checkssn(object_value) {
			
			//--------------------------------------------//
			//---  remove leading and trailing spaces  ---//
			//--------------------------------------------//
			trimmed_object_value = trim(object_value);
			
			
			//------------------------------//
			//---  if null, return true  ---//
			//------------------------------//
			if (trimmed_object_value.length == 0)
				return true;
			
			
			//--------------------------------//
			//---  length must be 5 or 10  ---//
			//--------------------------------//            
			if ((trimmed_object_value.length != 11))
				return false;
			
			
			//---------------------------------//
			//---  break number into parts  ---//
			//---------------------------------//
			ssn1   = trimmed_object_value.substring(0,3);
			slash1 = trimmed_object_value.charAt(3);
			ssn2   = trimmed_object_value.substring(4,6);
			slash2 = trimmed_object_value.charAt(6);
			ssn3   = trimmed_object_value.substring(7,11);
						
			
			//-----------------------------------------------//
			//---  first three digits must be an integer  ---//
			//-----------------------------------------------//
		    if (!checkinteger(ssn1))
				return false;
			
			
			//---------------------------------------------//
			//---  require first separator to be a "-"  ---//
			//---------------------------------------------//
		    if (slash1 != "-")
		    	return false;

			
		    //--------------------------------------------//
			//---  next two digits must be an integer  ---//
			//--------------------------------------------//
		    if (!checkinteger(ssn2))
				return false;
			
			
			//----------------------------------------------//
			//---  require second separator to be a "-"  ---//
			//----------------------------------------------//
		    if (slash2 != "-")
		    	return false;

			
		    //---------------------------------------------//
			//---  last four digits must be an integer  ---//
			//---------------------------------------------//
		    if (!checkinteger(ssn3))
				return false;
						
		    
			return true;
		}
		


//*************************************************************************************//
//  check year routine                                                                 //
//*************************************************************************************//

	//-------------------------------------------------------------------//
	//---  javascript to validate a year (nnnn)                       ---//
	//-------------------------------------------------------------------//

		function checkyear(object_value) {
			
			//--------------------------------------------//
			//---  remove leading and trailing spaces  ---//
			//--------------------------------------------//
			trimmed_object_value = trim(object_value);
			
			
			//------------------------------//
			//---  if null, return true  ---//
			//------------------------------//
			if (trimmed_object_value.length == 0)
				return true;
			
			
			//--------------------------//
			//---  length must be 4  ---//
			//--------------------------//            
			if ((trimmed_object_value.length != 4))
				return false;
			
			
			//---------------------------------------------//
			//---  range must be between 1800 and 2100  ---//
			//---------------------------------------------//   
			if (!checkrange(trimmed_object_value,'1800','2100'))
				return false;
						
			
			return true;
		}
	
	
				
//*************************************************************************************//
//  check zip routine                                                                  //
//*************************************************************************************//

	//-----------------------------------------------------------------------//
	//---  javascript to validate a zip code (nnnnn or nnnnn-nnnn).       ---//
	//-----------------------------------------------------------------------//

		function checkzip(object_value) {
			
			//--------------------------------------------//
			//---  remove leading and trailing spaces  ---//
			//--------------------------------------------//
			trimmed_object_value = trim(object_value);
			
			
			//------------------------------//
			//---  if null, return true  ---//
			//------------------------------//
			if (trimmed_object_value.length == 0)
				return true;
			
			
			//--------------------------------//
			//---  length must be 5 or 10  ---//
			//--------------------------------//            
			if ((trimmed_object_value.length != 5) && (trimmed_object_value.length != 10))
				return false;
			
			
			//-----------------------------------------------------//			
			//---  if length is 5, make sure zip is an integer  ---//
			//-----------------------------------------------------//
			if (trimmed_object_value.length == 5) {
			
			    if (!checkinteger(trimmed_object_value))
					return false;
			}
			
				
			//------------------------------------------------------------//			
			//---  else, first five and last four must be integer and  ---//
			//---    separator must be a "-"                           ---//
			//------------------------------------------------------------//
			else {
			    
				zip5 = trimmed_object_value.substring(0,5);
				zip1 = trimmed_object_value.charAt(5);
				zip4 = trimmed_object_value.substring(6,10);
				
			    if (!checkinteger(zip5))
					return false;
				
				
				if (zip1 != "-")
					return false;
								
				
			    if (!checkinteger(zip4))
					return false;
				
			}
			
			return true;
		}
	
	
	
//*************************************************************************************//
//  require select routine                                                             //
//*************************************************************************************//

	//------------------------------------------------------------------------//
	//---  javascript to require a select box option value. Returns false  ---//
	//---    for nulls or -1.                                              ---//
	//------------------------------------------------------------------------//
	
		function requireselect(object_value) {
			
			//--------------------------------------------//
			//---  remove leading and trailing spaces  ---//
			//--------------------------------------------//
			trimmed_object_value = trim(object_value);
			
			//-------------------------------------//
			//---  if null or -1, return false  ---//
			//-------------------------------------//
			if ((trimmed_object_value.length == 0) || (trimmed_object_value == "-1"))
				return false;
			
						
			return true;
		}


		
//*************************************************************************************//
//  require text routine                                                               //
//*************************************************************************************//
	

	//------------------------------------------------------------------------//
	//---  javascript to require a text value. Returns false for nulls.    ---//
	//------------------------------------------------------------------------//
	
		function requiretext(object_value) {
			
			//--------------------------------------------//
			//---  remove leading and trailing spaces  ---//
			//--------------------------------------------//
			trimmed_object_value = trim(object_value);
			
			//-------------------------------//
			//---  if null, return false  ---//
			//-------------------------------//
			if (trimmed_object_value.length == 0)
				return false;
			
			
			return true;
		}


		
//*************************************************************************************//
//  trim routine                                                                       //
//*************************************************************************************//

	//------------------------------------------------------------------------//
	//---  javascript to trim leading and trailing white space from the    ---//
	//---    passed value.                                                 ---//
	//------------------------------------------------------------------------//
	
		function trim(object_value) {
			
			//------------------------------------//
			//---  initialize loop conditions  ---//
			//------------------------------------//
			var bFoundLeading = true;
			var bFoundTrailing = true;
			
			
			//-------------------------------//
			//---  remove leading spaces  ---//
			//-------------------------------//		
			while (bFoundLeading) {
				bFoundLeading = (object_value.substring(0, 1) == " ");
		
				if (bFoundLeading) {
					object_value = object_value.substring(1);
				}
		
			}
			
			//--------------------------------//
			//---  remove trailing spaces  ---//
			//--------------------------------//	
			while (bFoundTrailing) {
				
				bFoundTrailing = (object_value.substring((object_value.length - 1), object_value.length) == " ");
				
				if (bFoundTrailing) {
					object_value = object_value.substring(0,(object_value.length - 1));
				}
		
			}
			
			//------------------------------//
			//---  return trimmed value  ---//
			//------------------------------//	
			return object_value;
			
		}			