// JavaScript Document


function validEmail(email) {
		invalidChars = " /:,;"
		
		if(email == "") {							//can't be null
			return false
		}
		for (i=0; i<invalidChars.length; i++) {		//does it contain invalid characters?
			badChar = invalidChars.charAt(i)
			if (email.indexOf(badChar,0) > -1) {
				return false
			}
		}
		atPos = email.indexOf("@",1)				//there must be 1 @ symbol
		if (atPos == -1) {
			return false
		}
		if (email.indexOf("@",atPos+1) != -1) {		//and only 1 @ symbol
			return false
		}
		periodPos = email.indexOf(".",atPos)
		if (periodPos == -1) {						//at least 1 "." after the @
			return false
		}
		if (periodPos+3 > email.length) {			//at least 2 characters after "."
			return false
		}
		
		return true
	}


function submitIt(contactForm) {
	
	
		//Check for  Name
		if (contactForm.name.value =="") {
			alert("Please complete all the form fields.")
			document.contactForm.name.focus();
			return false
		}
				
		//Validate your email
		if(!validEmail(contactForm.yourEmail.value)) {
			alert("Please complete all the form fields.")
			document.contactForm.yourEmail.focus();
			return false
		}
		
		//Check for question
		if (contactForm.friendsName.value =="") {
			alert("Please complete all the form fields.")
			document.friendsName.question.focus();
			return false
		}
		//Validate friends email
		if(!validEmail(contactForm.friendsEmail.value)) {
			alert("Please complete all the form fields.")
			document.contactForm.friendsEmail.focus();
			return false
		}

			return true
		}