
	/*
 	 * 	 File:		luanrstarr.js
	 *	 Desc:		Custom JS functions for website
	 *	 Last Modified: David Cramblett 2009.08.30
	 *	 Copyright 2008-2009 Lunar Starr Photography and Design, LLC
	 */



// Function to validate web contact form, stage is used to specify which 
// stage of the form the user is on.
function validateContactForm ( contactForm, stage ) {

	var validForm = true;
	var errorMessage = "";

	// User is entering their contact information
	if (stage == 1) {

		// Check the Name field for null value
		if ( contactForm.name.value == "" ) {
			validForm = false;
			errorMessage += "Name is a required field<br />";
			}

		// Check the Email field for null value
		if ( contactForm.email1.value == "" ) {
			validForm = false;
			errorMessage += "Email is a required field<br />";
			}
		// Check the Email field is constructed reasonably
		else if ( !validate_email(contactForm.email1) ) {
			validForm = false;
                        errorMessage += "The Email field does not seem to contatin a valid address<br />";
                        }

		// Check the Confirm Email field for null value
		if ( contactForm.email2.value == "" ) {
			validForm = false;
			errorMessage += "Confirm Email is a required field<br />";
			}

		// Check that both email fields match
		if ( contactForm.email1.value != contactForm.email2.value  ) {
			validForm = false;
			errorMessage += "Email and Confirm Email must match<br />";
			}
		}

	// User is entering their message
	if (stage == 2) {

		// Check that the submitter actually types a message to send
                if (  contactForm.mesgBody.value == "" ) {
                        validForm = false;
                        errorMessage += "Please type your message before sending!<br />";
                        }
		}


	// If any checks failed, send the user an error message
	if (!validForm) {

		errorMessage = "<p>" + errorMessage + "</p>";
		
		document.getElementById("contactErrorMesg").innerHTML = errorMessage;
			
		}

	return validForm;

} //END Fucntion validateContactForm ( contactForm, stage )



function validateContactFormField ( formField, type ) {

		var validField = true;
		var validImageFiled = formField.name + "Valid";

		
		if (type == "Name") {

			if ( formField.value == ""  || formField.value.length < 5 ) {
				validField = false;
				document.getElementById(validImageFiled).src = "/images/formFieldInvalid.png";
				}
			else {
				validField = true;
                                document.getElementById(validImageFiled).src = "/images/formFieldValid.png";         
                                }

			}


		if (type == "Email") {

			if ( formField.value == ""  || formField.value.length < 6 ) { 
                                validField = false;
                                document.getElementById(validImageFiled).src = "/images/formFieldInvalid.png";         
                                }
			else if ( !validate_email(formField) ) {
                                validField = false;
                                document.getElementById(validImageFiled).src = "/images/formFieldInvalid.png";         
                                }
                        else {
                                validField = true; 
                                document.getElementById(validImageFiled).src = "/images/formFieldValid.png";  
                                }

                        }


	return validField;


} //END Function validateContactFormField ( formField, type )


function validate_email(field) {

	with (field) {

  		apos = value.indexOf("@");
  		dotpos = value.lastIndexOf(".");
		charsAfterDot = value.length - dotpos;


  		if ( apos < 1 || dotpos-apos < 2 || charsAfterDot < 2 ) {
			return false;
			}
  		else {
			return true;
			}
  		}

} // END Function validate_email(field)
