var nameBox = false;
var emailBox = false;

// This function checks if the username field
// is at least 6 characters long.
// If so, it attaches class="welldone" to the 
// containing fieldset.

function checkName(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (txt.length > 1) {
		fieldset.className = "welldone";
		//emailBox = true;
		//alert ("hello");
		//fielset.style.backgroundColor = "#FFFFCC";
		//fieldset.getElementByClassName("hint1").style.display = "none";
	} else {
		fieldset.className = "";
	}
}

// This function checks the email address to be sure
// it follows a certain pattern:
// blah@blah.blah
// If so, it assigns class="welldone" to the containing
// fieldset.

function checkEmail(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(txt)) {
		fieldset.className = "welldone";
		//emailBox = true;
		//alert ("hello");
		//fielset.style.backgroundColor = "#FFFFCC";
		//fieldset.getElementByClassName("hint1").style.display = "none";
	} else {
		fieldset.className = "";
	}
}

function validateForm() {
	alert('Hello');
	mNv=mainform.nameBox.value;
	if (mNv=='') {
		alert('Your name is a required field. Please try again.');
		event.returnValue=false;
	}
	mEv=mainform.emailBox.value;
	if (mEv=='') {
		alert('Your email is a required field. Please try again.');
		event.returnValue=false;
	}
}

// this part is for the form field hints to display
// only on the condition that the text input has focus.
// otherwise, it stays hidden.

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function prepareInputsForHints() {
  var inputs = document.getElementsByTagName("input");
  for (var i=0; i<inputs.length; i++){
    inputs[i].onfocus = function () {
      this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
    }
    inputs[i].onblur = function () {
      this.parentNode.getElementsByTagName("span")[0].style.display = "none";
    }
  }
}
addLoadEvent(prepareInputsForHints);