function checkForm()

{

  var valid = true;

	for (i=0; i < this.length; i++)

	{

		if ($(this[i]).hasClass("compulsory"))

		{

			var type = this[i].type.toLowerCase();

			if (type == "textarea" || type == "text" || type == "password"){

				if (this[i].value == this[i].defaultValue || this[i].value == "")

				{

				  $(this[i]).addClass("errorField");	

				 	valid = false;

				}

				else

				{

				  $(this[i]).removeClass("errorField");				

				}

			}

			else 

			{

				if (type == "checkbox" && !this[i].checked)

				{

				 	valid = false;

				}

			}

		}

	}

	if(!valid)

	{

		alert('Please fill in required fields.')

	}

	else

	{

		for (i=0; i < this.length; i++)

		{

			var type = this[i].type.toLowerCase();

			if (type == "textarea" || type == "text" || type == "password")

			{

				if(this[i].value == this[i].defaultValue)

				{

					this[i].value = '';

				}

			}

		}		

	}

	return valid;

}



function checkValue ()

{

	if(this.value == this.defaultValue)

	{

		this.value = "";

	}

	else if(this.value=="")

	{

		this.value = this.defaultValue;

	}

}



$(document).ready(function(){  

  $("#contactFormLeft").bind("submit", checkForm);

  $("#contactFormLeft textarea, #contactFormLeft input[type='text']").each(function(){

    $(this).bind("focus", checkValue);

    $(this).bind("blur", checkValue);

  });

  $("#headerContactForm").bind("submit", checkForm);

  $("#headerContactForm textarea, #headerContactForm input[type='text']").each(function(){

    $(this).bind("focus", checkValue);

    $(this).bind("blur", checkValue);

  });

});
