// JavaScript Document
jQuery(document).ready(function() {
	// validate signup form on keyup and submit
	var validator = jQuery('#formContact').validate({
		rules: {
			'email': {
				required: true,
				email: true
			}
		},
		messages: {
			'email': {
				minlength: "Please enter a valid email address"
			}
		},
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}
	});
});
jQuery(document).ready(function() {
	// validate signup form on keyup and submit
	var validator = jQuery('#formConsult').validate({
		rules: {
			'firstName': {
				required: true
			},
			'lastName': {
				required: true
			},
			'email': {
				required: true,
				email: true
			},
			'servicesRequested': {
				required:true
			},
			'code': {
				required:true
			}
		},
		messages: {
			'firstName': {
				required: ""
			},
			'lastName': {
				required: ""
			},
			'email': {
				required: "",
				email: ""
			},
			'servicesRequested': {
				required: ""
			},
			'code': {
				required: ""
			}
		},
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}
	});
});


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 () {
		if (jQuery(this.parentNode.getElementsByTagName("form")[2]).hasClass('validation-hints'))
		{
	   		if (!jQuery(this.parentNode.getElementsByTagName("label")[1]).hasClass('error')) 
	   		{ 
	   			this.parentNode.getElementsByClassName("hint")[0].style.display = "inline";
			}
		}
	}
    inputs[i].onblur = function () {
		if (jQuery(this.parentNode.getElementsByTagName("form")[2]).hasClass('validation-hints'))
		{	
		    this.parentNode.getElementsByClassName("hint")[0].style.display = "none";
		}
    }
  }
}
addLoadEvent(prepareInputsForHints);

jQuery.fn.inputHints = function() {

	// hides the input display text stored in the title on focus
    // and sets it on blur if the user hasn't changed it.

    // show the display text
    $(this).each(function(i) {
	if ($(this).hasClass('form-hints'))
	{
        $(this).val($(this).attr('title'));
	}
    });

    // hook up the blur & focus
    $(this).focus(function() {
	if ($(this).hasClass('form-hints'))
	{					   
        if ($(this).val() == $(this).attr('title'))
            $(this).val('');
	}
    }).blur(function() {
	if ($(this).hasClass('form-hints'))
	{
        if ($(this).val() == '')
            $(this).val($(this).attr('title'));
	}
    });
};

$(document).ready(function() {
	    $('input[title]').inputHints();
});