<!--
// ================================================================================
    // NOTES ABOUT SCRIPT
    // ================================================================================
    // JavaScript Slick Form Validation
    // by Tim Bobo
    // Adapted loosely from a script by Paul Colton
    // if you use any of these functions please send me some e-mail (timbobo@leftbrainmedia.com) 
    // to let me know; I always like to know when someone likes my work.
    // Also give me a little credit in your code, like I have done for Paul Colton (above)     
    // and Danny Goodman (below).  If you make some improvements to my script, send them
    // my way.
    

    // ================================================================================
    // FUNCTION submit_pages() 
    // ================================================================================
    
    function submit_page(form) {
    
        foundError = false; // used at end of script to decide if to submit or not

        // ............................................................................
        // CHECK NAME FIELD FOR PROBLEMS
        // ............................................................................       
        
        nameError = "";  // if the script find an error is places the message in this varible
        companyError = "";
        // MAKER SURE NAME FIELD IS NOT BLANK

        if(form.name.value == "") {
            nameError = "You left the Name field blank.";
            foundError = true;
        }
        if(form.company.value == "") {
            companyError = "You left the Company field blank.";
            foundError = true;
        }
        // ............................................................................
        // CHECK E-MAIL FIELD FOR PROBLEMS
        // ............................................................................
        
        emailError = ""  // if the script find an error is places the message in this varible
        
        // (1) MAKE SURE THE EMAIL FIELD IS NOT BLANK

        if(form.email.value == "") {
            emailError = "You left the E-mail field blank.";
            foundError = true;
        }

        // (2) NOW MAKE SURE THE E-MAIL FIELD IS VALID
        
        if((emailError == "") && (isValidEmail(form.email) == false)) { // see function below
            emailError = "Please enter a valid email address.";
            foundError = true;
        }
        
        // ............................................................................
        // CHECK PHONE FIELD FOR PROBLEMS
        // ............................................................................
        

        phoneError = ""; // if the script find an error is places the message in this varible
        
        // (1) MAKE SURE THE PHONE FIELD IS NOT BLANK
        
        if(form.phone.value == "") {
            phoneError = "You left the phone number field blank.";
            foundError = true;
        }

        // (2) CHECK THE PHONE NUMBER FOR AT LEAST 10 INTEGERS

        if((phoneError == "") && (isValidPhoneNumber(form.phone) == false)) { //see function below
            phoneError = "Please enter full phone number with area code.";
            foundError = true;
        }
				
				//Check the dropdown list for a selection
				if (form.infoOn.selectedIndex < 0 ){
					  infoOnError = "Please choose an item to request information about.";
						foundError = true;
				}
        
        // ............................................................................
        // INFORMING USER ABOUT PROBLEMS OR DISPLAY THANK YOU MESSAGE
        // ............................................................................

        if(foundError == false) {
            //alert ("Thanks for taking time to fill out the form! \rWe will get back to you soon.")
            //return true;
            form.action="mailer.asp";
						form.method="post";
						form.submit(); 
						// go to specific URL here.
        }
        else { // SELECT THE FIRST PROBLEM FIELD
            errorMessage = "The submission contained the following errors: \r" + nameError + "\r" + companyError + "\r" + emailError + "\r" + phoneError + "\r" + infoOnError;
            alert (errorMessage)
            if (nameError != "") {
        				form.name.focus()
                form.name.select()
								companyError = ""
                emailError = ""; // this saves messing with ugly nested else statements
                phoneError = "";    // ditto
								infoOnError = "";        
            }
						if (companyError != "") {
							  form.company.focus()
							  form.company.select()
								emailError = ""; // this saves messing with ugly nested else statements
                phoneError = "";    // ditto
								infoOnError = "";        
            }
            if (emailError != "") {
                form.email.focus()
                form.email.select()
                phoneError = "";    // this saves messing with ugly nested else statements
								infoOnError = "";      
            }   
            if (phoneError != "") {
                form.phone.focus()
                form.phone.select()
								infoOnError = "";
            }
						if (infoOnError != "") {
							 	form.infoOn.focus()
						}
            return false;                       
        }   
    }

    // ================================================================================
    // FUNCTION isValidEmail(theField)
    // ================================================================================
    
    // Check for a valid email address
    // This is not full proof.  It simply looks for text before and after an @ symbol.
    // it calles on getFront & getEnd which are listed below this function
    
    function isValidEmail(theField) {
        if((getFront(theField.value,"@") != null) && (getEnd(theField.value,"@") != "")) {
            // alert (getFront(theField.value,"@"))
            // alert (getEnd(theField.value,"@"))
            return true; // the e-mail address is considered valid
        } else {
            return false; // the e-mail address is considered invalid
        }
    }
    
    // ================================================================================
    // FUNCTIONS getFront & getEnd
    // ================================================================================

    // The following 2 functions are adapted from Danny Goodman's JavaScript Handbook
    // and boy are they handy for a not much of a scripting language called JavaScript
    
    // ................................................................................
    // EXTRACT FRONT PART OF STRING PRIOR TO SEARCHSTRING
    // ................................................................................
    
    function getFront(mainStr,searchStr){
        foundOffset = mainStr.indexOf(searchStr)
        if (foundOffset <= 0) {
            return null // if the @ symbol is missing the value is -1
                        // if the @ symbol is the first char the value is 0
        } 
        else {
            return mainStr.substring(0,foundOffset)
        }
    }
    
    // ................................................................................
    // EXTRACT BACK END OF STRING AFTER TO SEARCHSTRING
    // ................................................................................
    
    function getEnd(mainStr,searchStr) {
        foundOffset = mainStr.indexOf(searchStr)
        if (foundOffset <= 0) {
            return ""   // if the @ symbol is missing the value is -1
                        // if the @ symbol is the first char the value is 0
                        // I switched this to return "" so it would match the result of an empty
                        // string below
        }
        else {
            return mainStr.substring(foundOffset+searchStr.length,mainStr.length)
                        // if nothing exists after the @ symbol this will return an empty string
        }
    }

    // ================================================================================
    // FUNCTIONS isValidPhoneNumber & LengthValid & formatPhone
    // ================================================================================

    // ................................................................................
    // THIS IS A BARE BONES CHECK.  I PLAN TO ADD MORE FUNCTIONALITY LATER.
    // ................................................................................

    function isValidPhoneNumber(theField) {
        if (LengthValid(theField) == true) {
            return true
        } else {
            return false;
        }       
    }
    
    // ................................................................................
    // CHECK THAT A PHONE NUMBER HAS THE AT LEAST 10 NUMBERS IN IT
    // ................................................................................

    function LengthValid(theField) {
        newNumber = "" // string resulting from stripping away all non integers
        for (var i = 0; i < theField.value.length; i++) {
            parseResut = "" + (parseInt(theField.value.charAt(i))) // makes sure it is a string
            if (parseResut.length == 1) {
                newNumber = newNumber + "" + parseResut;
            }
        }   
        if (newNumber.length >= 10) {
            return true;
            
            } else {
                return false
        }
    }
 
    // ................................................................................
    // PULLS OUT AND RETURNS INTEGERS NEXT TO EACH OTHER AT BEGINNING OF A STRING
    // ................................................................................

    function leadingNumbers(theString) { ; 
        newNumber = ""; // string resulting from getting first set of integers
        i = 0;
        doContinue = true;
        while (doContinue == true) { ;
            parseResut = "" + (parseInt(theString.charAt(i))) ; // makes sure it is a string
            if (parseResut.length == 1) { ; // returned value is a single integer
                newNumber = newNumber + "" + parseResut; // links it as a string
                i++
            }
            else {
                doContinue = false;
            }
        }   
        return newNumber;
    }
   
    // ................................................................................
    // FORMATS PHONE NUMBER IF THE FIELD CONTAINS 10 OR 11 NUMBERS AT THE FIRST
    // USES THE leadingNumbers(string) FUNCTION LISTED ABOVE
    // ................................................................................
    
    function formatPhone(theField) {
        clearTrailingSpace(theField)
		originalText = "" + theField.value  // makes sure text is a string not a integer
        enteredNumber = "" + leadingNumbers(originalText)
                                                    // takes the numbers off the first part
                                                    // of the text and saves it as a string
                                                    // now you have a string that is the same as
                                                    // all the numbers next together at the
                                                    // beginning of the text string
                                                    // so someone could enter a phone number
                                                    // with a descriptive word beside it
                                                    // and only the phone number part would
                                                    // be formatted
        if (enteredNumber.length == 10) {  // this if statement takes care of 10 digit numbers
            theField.value = "(" + enteredNumber.substring(0,3) + ")"
                             + enteredNumber.substring(3,6) + "-" + enteredNumber.substring(6,10)
                             + originalText.substring(10,originalText.length)
        } else {
            if (enteredNumber.length == 11) {  // this if statement takes care of 11 digit numbers
                                               // more conditional statements could be added
                                               // for international numbers
            theField.value = enteredNumber.substring(0,1) + "("
                             + enteredNumber.substring(1,4) + ")"
                             + enteredNumber.substring(4,7) + "-"
                             + enteredNumber.substring(7,11)
                             + originalText.substring(11,originalText.length)
            }
        }             
    
    }
    // ================================================================================
    // FUNCTIONS capWords
    // ================================================================================
    
    function capWords(theField) {
    clearTrailingSpace(theField)
	if (theField.value != "") { // skip all the work if the field is blank
        nameLength = theField.value.length // gets length of string
        nextPoint = 0; // starts the search for a blank char after this point
        contLoop = true;
        captString = theField.value; // this string will replace the field at the end
        captString = captString.charAt(0).toUpperCase() + captString.substring(1,nameLength)
        wordStart = 0;
        while (contLoop == true) {
            foundOffset = theField.value.indexOf(" ",nextPoint) // finds first space
            if ((foundOffset == -1) || (foundOffset > nameLength)) {
                contLoop = false; // stops looping process
            
            } else {
                wordStart = foundOffset + 1; // next char after a space should be the start of a word
                nextPoint = wordStart; // sets the next Index of to start at last found space
                captString = (captString.substring(0,wordStart)) +
                             (captString.charAt(wordStart).toUpperCase()) + 
                             (captString.substring(wordStart + 1,nameLength))
              }
        }
        theField.value = captString
        return true;        
        }
    else {
        return true;
        }
    }

    // ================================================================================
    // FUNCTIONS clearTrailingSpace
    // ================================================================================
    
	// clears traling spaces out of a field
	
    function clearTrailingSpace(theField) {
		newValue = theField.value;
		lastChar = newValue.charAt(newValue.length - 1);// minus 1 because strings start at 0
		while (lastChar == " ") {;
			endingChar = (newValue.length) - 1;
			newValue = newValue.substring(0,endingChar);
			lastChar = newValue.charAt(newValue.length - 1);
		}
		theField.value = newValue;
		return true;
    }


    // ================================================================================
    // END OF MAIN SCRIPT
    // ================================================================================
// -->