function initHighlight() {
    if (!document.getElementsByTagName){ return; }
    var allfields = document.getElementsByTagName("input");

    // loop through all input tags and add events
    for (var i=0; i<allfields.length; i++){
        var field = allfields[i];
        if ((field.getAttribute("type") == "text") || (field.getAttribute("type") == "password") ) {
            field.onfocus = function () {
              this.className = 'highlightActiveField';
          	 	 if(this.value==this.defaultValue) {
          	 	 	 this.value = "";
          	 	 }
            }
            field.onblur = function (){
              this.className = 'highlightInactiveField';
            	if(this.value==="") {
            		this.value = this.defaultValue;
            	}
            }
        }
    }
}

// Nifty function to add onload events without overwriting
// ones already there courtesy of the lovely and talented
// Simon Willison http://simon.incutio.com/
function addLoadEvent(func) {   
    var oldonload = window.onload;
    if (typeof window.onload != 'function'){
        window.onload = func;
    } else {
        window.onload = function(){
        oldonload();
        func();
        }
    }
}

addLoadEvent(initHighlight);
		
		function validEmail(email) {
			invalidChars = " /:,;"
	
			if (email == "") {
				return false
			}
			for (i=0; i<invalidChars.length; i++) {
				badChar = invalidChars.charAt(i)
				if (email.indexOf(badChar,0) > -1) {
					return false
				}
			}
			atPos = email.indexOf("@",1)
			if (atPos == -1) {
				return false
			}
			if (email.indexOf("@",atPos+1) > -1) {
				return false
			}
			periodPos = email.indexOf(".",atPos)
			if (periodPos == -1) {
				return false
			}
			if (periodPos+3 > email.length)	{
				return false
			}
			return true
		}
		
		function submitMail(carForm) {
			if (!validEmail(carForm.email.value)) {
				alert("Please enter a valid email address")
				carForm.email.focus()
				carForm.email.select()
				return false
			}
			return true
		}
		
		function submitIt(carForm) {
			if (!validEmail(carForm.email.value ) || carForm.email.value==carForm.email.defaultValue) {
				alert("Please enter a valid email address")
				carForm.email.focus()
				carForm.email.select()
				return false
			}
			if (carForm.name.value=="" || carForm.name.value==carForm.name.defaultValue){
				alert("Please enter you name")
				return false
			}
			if (carForm.subject.value=="" || carForm.subject.value==carForm.subject.defaultValue){
				alert("Please enter a subject for your message")
				return false
			}
	
			return true
		}
