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++){
		// test to see if the hint span exists first
		if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
			// the span exists!  on focus, show the hint
			inputs[i].onfocus = function () {
				if (this.value=="") {this.parentNode.getElementsByTagName("span")[0].style.display = "inline";}
			}
			// when the cursor moves away from the field, hide the hint
			inputs[i].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
	// repeat the same tests as above for selects
	var selects = document.getElementsByTagName("textarea");
	for (var k=0; k<selects.length; k++){
		if (selects[k].parentNode.getElementsByTagName("span")[0]) {
			selects[k].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			selects[k].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
}
addLoadEvent(prepareInputsForHints);

//validation section
function fncValidate() {
	if(document.ContactForm.Name.value=="") {
		document.ContactForm.Name.parentNode.getElementsByTagName("span")[0].style.display = "inline";
		document.ContactForm.Name.focus();
		return false;
	}
	if(document.ContactForm.City.value=="") {
		document.ContactForm.City.parentNode.getElementsByTagName("span")[0].style.display = "inline";
		document.ContactForm.City.focus();
		return false;
	}
	if(document.ContactForm.State.value=="") {
		document.ContactForm.State.parentNode.getElementsByTagName("span")[0].style.display = "inline";
		document.ContactForm.State.focus();
		return false;
	}
	var rePattern=/^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/
	if(document.ContactForm.Email.value.search(rePattern)==-1) {
		document.ContactForm.Email.parentNode.getElementsByTagName("span")[0].style.display = "inline";
		document.ContactForm.Email.focus();
		return false;
	}
	var rePattern=/^[0-9\-\.\(\)\ ]+$/
	if(document.ContactForm.Phone.value.search(rePattern)==-1||document.ContactForm.Phone.value.length<7) {
		document.ContactForm.Phone.parentNode.getElementsByTagName("span")[0].style.display = "inline";
		document.ContactForm.Phone.focus();
		return false;
	}
	if(document.ContactForm.How_can_we_help.value=="") {
		document.ContactForm.How_can_we_help.parentNode.getElementsByTagName("span")[0].style.display = "inline";
		document.ContactForm.How_can_we_help.focus();
		return false;
	}
	return true;
}
