	function open_message()   { 
	         new_window02 = window.open('', 'fresh','scrollbars=no,height=274,width=400,top=180,left=150') 
	} 

   // Alphabetic Check-standard
		 
		 function its_a_letter(character)   {
			
			   var lowercase_letters = " abcdefghijklmnopqrstuvwxyz"
			   var uppercase_letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
			   
			   // if its not in lowercase or uppercase(including space) then return false
			   if (lowercase_letters.indexOf(character) == -1 && 
                   uppercase_letters.indexOf(character) == -1) {
				   
				   return false
				   
				   }
				  // otherwise its a letter return true
				   return true
				}
			// alphabetic string check  - uses its_a_letter() function
			function its_alphabetic(string_value)   {
	string_value = string_value.toLowerCase()
			   // run through each character in the string
			   for (var counter = 0; counter < string_value.length; counter++)   {
			   
			      // Get the current character
				  current_char = string_value.charAt(counter)
				  
				  // If its not a letter return false
				  if (!its_a_letter(current_char) )   {
				  
				  return false
				  }
			}	  				  	   
                  // Otherwise, the string has nothing but alphabetic characters
				  return true				  
       }

         // Alphabetic Check - message (possible Spaces)
		 function not_a_message(character)   {
			
			   var bad_characters = "<>/+="
			   
			   // if its not in lowercase or uppercase(including space) then return false
			   if (bad_characters.indexOf(character) >= 0) {
				   
				   return true
				   
				   }
				  // otherwise its a letter return true
				   return false
				}
			// alphabetic string check  - uses its_a_letter() function
			function is_message(string_value)   {
			
			   // run through each character in the string
			   for (var counter = 0; counter < string_value.length; counter++)   {
			   
			      // Get the current character
				  current_char = string_value.charAt(counter)
				  
				  // If its not a letter return false
				  if (not_a_message(current_char) )   {
				  
				  return false
				  }
			}	  				  	   
                  // Otherwise, the string has nothing but alphabetic characters
				  return true				  
       }
//----------------------------------------------------------------------------------------------------------------------------------------------------------


         // Valid Email; Check
		 function valid_email(submitted_address)   {
		 
		       // check the length
			   if (submitted_address.length < 5)   {
			   return false
			   }
			   
			   // check @ and .
			   at_location = submitted_address.indexOf("@")
			   dot_location = submitted_address.lastIndexOf(".")
			   
			   if (at_location == -1 || dot_location == -1 || at_location > dot_location)   {
			         return false
					 }
					 
					 // Is there at least one character before @
				if (at_location == 0)   {
				    return false
					}	 
					
					// Is there at least one character between @ and .?
				if (dot_location - at_location <= 1)   {
				    return false
					}	
               
			   // Is there at least one character after .?
			   if (submitted_address.length - dot_location <= 1)   {
			   return false
			   }
			   
			   // otherwise valid address
			   return true
	}		   
			   
		

//----------------------------------------------------------------------------------------------------------------------------------------------------------
             // Interger Check 

function its_a_digit(character)   {
		  

		        var digit_characters = "0123456789"
				
				// if it's not in the digit string, then return false
				if (digit_characters.indexOf(character) == -1)   {
				return false
			}
			    // Otherwise, its a digit, 
				return true
		}
		
		  function its_integer(string_value)   {
		        // run through each character in the string
				for (var counter = 0; counter < string_value.length; counter++)   {
				
				        // get current character
						current_char = string_value.charAt(counter)
						
						//if not digit return false
						if (!its_a_digit(current_char))   {
						return false
						}
				}
				
				// Otherwise thre string has nothing but digits, so return true
				    return true
					}					
//----------------------------------------------------------------------------------------------------------------------------------------------------------

	      // Interger Check (telephone format)
		  function its_a_digit_t(character)   {
		  
		        var digit_characters = "-()0123456789"
				
				// if it's not in the digit string, then return false
				if (digit_characters.indexOf(character) == -1)   {
				return false
			}
			    // Otherwise, its a digit, 
				return true
		}
		
		  function its_integer_t(string_value)   {
		        // run through each character in the string
				for (var counter = 0; counter < string_value.length; counter++)   {
				
				        // get current character
						current_char = string_value.charAt(counter)
						
						//if not digit return false
						if (!its_a_digit_t(current_char))   {
						return false
						}
				}
				
				// Otherwise thre string has nothing but digits, so return true
				    return true
					}	
//----------------------------------------------------------------------------------------------------------------------------------------------------------

             //  If all Whitespace check
			 function its_whitespace(string_value)   {
			 
			       // These are the whitespace characters
				   var whitespace = " \n\r\t"
				   
				   // Run through each character in the string,
				   for (var counter = 0; counter < string_value.length; counter++)   {
				   
				         // Get the current character
						 current_char = string_value.charAt(counter)
						 
						 // If its not in the whitespace characters string,
						 // return false because non-whitespace character found
						 if (whitespace.indexOf(current_char) == -1)   {
						 
						 return false
				}
	}
	
	                     // Otherwise the string has nothing but whitespace characters, so return true
						 return true
			}			 					 

//-----------------------------------toTitleCase() 
function title_case()   {
      
	  var temp_string = this.toLowerCase()
	  var left_string
	  var right_string
	  var new_letter
	  
	  // first to uppercase
	  var first_char = temp_string.left(1).toUpperCase()
	  temp_string = first_char + temp_string.substring(1)
	  
	  // get the position  of the first space
	  var space_location = temp_string.indexOf(" ")
	  
	  // loop until there are nomore
	  while (space_location != -1)   {
	  
	     // Get the part up to and including the current space
		 left_string = temp_string.left(space_location + 1)
		 
		 //get the first letter of the next word and convert it to uppercase
		 new_letter = temp_string.charAt(space_location + 1).toUpperCase()
		 
		 //get the rest of the the string after that letter
		 right_string = temp_string.right(temp_string.length - space_location - 2)
		 
		 // put it all together
		 temp_string = left_string + new_letter + right_string
		 
		 // get the next space
		 space_location = temp_string.indexOf(" ", space_location + 1)
		 
		}
		return temp_string
	}


//-----------------------------------left() 	
function extract_left(total_chars)   {
        
		return this.substring(0, total_chars)
	  }

//----------------------------------right() 
	  
function extract_right(total_chars)   {

        return this.substring(this.length - total_chars)
		}
		

//----------------------------------------------------------------------------------------------------------------------------------------------------------
//  Main Function
   function entry_check()  {
	  
	  with(document.ContactUs) {
	  			String.prototype.right = extract_right
	            String.prototype.left = extract_left
	            String.prototype.toTitleCase = title_case
			     ContactUs.txtName.value = ContactUs.txtName.value.toTitleCase()
				 ContactUs.txtEmail.value = ContactUs.txtEmail.value.toLowerCase()
	  	  var invalid_message = "Valid information is required in the following:" + "\n___________________________________\n\n"
	       var invalid_fields = 0
		           if (txtName.value.length < 2 || !its_alphabetic(txtName.value))
			          {
			        invalid_message += "Name" + "\n"
					invalid_fields++
			            	}								
				  if (txtEmail.value.length == 0 || !valid_email(txtEmail.value))
			          {
			        invalid_message += "Email Address" + "\n"
					invalid_fields++
			            	}	
		           if (txtMessage.value.length < 2 || !is_message(txtMessage.value))
			          {
			        invalid_message += "Message" + "\n"
					invalid_fields++
			            	}							
							                    }  
		if (invalid_fields > 0)   {
				    invalid_message += "___________________________________\n\n" + "Please re-enter the appropriate Data."
						
						alert(invalid_message);
					}						 
            else 
			{
				open_message()
				ContactUs.submit()
				document.ContactUs.reset()
				}
}
 
