jQuery.noConflict();
jQuery(document).ready(function(){

       jQuery("#contactForm").submit(function(){

	   	var countTextbox = 0;
		var countValidatedTextboxes = 0;
		var emailRegEx =/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		var textbox = document.getElementsByTagName("input");

		  	for (var i=0; i < textbox.length; i++)
		  	{
				if (textbox[i].className.match("required_field"))
				{
					if(textbox[i].getAttribute('id') == 'name')
					{
    							if((textbox[i].value == ''))
								{

    							   textbox[i].style.backgroundColor = '#FFEB8B';

      					         }
    							 else
								 {
    							   textbox[i].style.backgroundColor = '#fff';
    							   countValidatedTextboxes++;
    							}
					}
					if(textbox[i].getAttribute('id') == 'email')
					{
    							if((textbox[i].value == '')  || (emailRegEx.test(textbox[i].value) == false))
								{

    							   textbox[i].style.backgroundColor = '#FFEB8B';
      					         }
    							 else
								 {
    							   textbox[i].style.backgroundColor = '#fff';
    							   countValidatedTextboxes++;
    							}
					}
					if(textbox[i].getAttribute('id') == 'subject')
					{
    							if((textbox[i].value == ''))
								{

    							   textbox[i].style.backgroundColor = '#FFEB8B';
      					         }
    							 else
								 {
    							   textbox[i].style.backgroundColor = '#fff';
    							   countValidatedTextboxes++;
    							}
					}

				}
				countTextbox++;
			}

			if(countValidatedTextboxes == 3)
			{
				return true;
			}
			else
			{
				jQuery(".error_message").html("Please fill in all the required fields");
				jQuery(".error_message").show();
				return false;
			}




	   });
       jQuery("#registrationForm").submit(function(){

	   	var countTextbox = 0;
		var countValidatedTextboxes = 0;
		var emailRegEx =/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		var textbox = document.getElementsByTagName("input");

		  	for (var i=0; i < textbox.length; i++)
		  	{
				if (textbox[i].className.match("required_field"))
				{
					if(textbox[i].getAttribute('id') == 'name')
					{
    							if((textbox[i].value == ''))
								{

    							   textbox[i].style.backgroundColor = '#FFEB8B';
      					         }
    							 else
								 {
    							   textbox[i].style.backgroundColor = '#fff';
    							   countValidatedTextboxes++;
    							}
					}
					if(textbox[i].getAttribute('id') == 'email')
					{
    							if((textbox[i].value == '')  || (emailRegEx.test(textbox[i].value) == false))
								{

    							   textbox[i].style.backgroundColor = '#FFEB8B';
      					         }
    							 else
								 {
    							   textbox[i].style.backgroundColor = '#fff';
    							   countValidatedTextboxes++;
    							}
					}
					if(textbox[i].getAttribute('id') == 'pass1')
					{
    						   var pass1 =   textbox[i].value;

    							if((textbox[i].value == ''))
								{

    							   textbox[i].style.backgroundColor = '#FFEB8B';
      					         }
    							 else
								 {
    							   textbox[i].style.backgroundColor = '#fff';
    							   countValidatedTextboxes++;
    							}
					}

					if(textbox[i].getAttribute('id') == 'pass2')
					{

    						   var pass2 =   textbox[i].value;


    							if((textbox[i].value == ''))
								{
    							   textbox[i].style.backgroundColor = '#FFEB8B';
      					         }else if ( pass1 != pass2 )  {
                                    var matchPass = 0;
                                    textbox[i].style.backgroundColor = '#FFEB8B';
      					         }
    							 else
								 {
    							   textbox[i].style.backgroundColor = '#fff';
    							   countValidatedTextboxes++;
    							}
					}

				}
				countTextbox++;
			}
			if(countValidatedTextboxes == 4)
			{
				return true;
			}
			else
			{
				if ( matchPass == 0 ) {
                jQuery(".error_message").html("Sorry password dont match");
				} else {
				jQuery(".error_message").html("Please fill in all the required fields");

				}


				jQuery(".error_message").show();
				return false;
			}
	   });


	   jQuery("#edit_profileForm").submit(function(){

	   	var countTextbox = 0;
		var countValidatedTextboxes = 0;
		var emailRegEx =/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		var textbox = document.getElementsByTagName("input");
        var PassError = 0;
		  	for (var i=0; i < textbox.length; i++)
		  	{
				if (textbox[i].className.match("required_field"))
				{
					if(textbox[i].getAttribute('id') == 'name')
					{
    							if((textbox[i].value == ''))
								{

    							   textbox[i].style.backgroundColor = '#FFEB8B';
      					         }
    							 else
								 {
    							   textbox[i].style.backgroundColor = '#fff';
    							   countValidatedTextboxes++;
    							}
					}
					if(textbox[i].getAttribute('id') == 'contact_number')
					{
    							if((textbox[i].value == ''))
								{

    							   textbox[i].style.backgroundColor = '#FFEB8B';
      					         }
    							 else
								 {
    							   textbox[i].style.backgroundColor = '#fff';
    							   countValidatedTextboxes++;
    							}
					}
					if(textbox[i].getAttribute('id') == 'email')
					{
    							if((textbox[i].value == '')  || (emailRegEx.test(textbox[i].value) == false))
								{

    							   textbox[i].style.backgroundColor = '#FFEB8B';
      					         }
    							 else
								 {
    							   textbox[i].style.backgroundColor = '#fff';
    							   countValidatedTextboxes++;
    							}
					}



				}else {

                   if(textbox[i].getAttribute('id') == 'pass')
					{
    						   var pass =   textbox[i].value;

    							if((textbox[i].value == ''))
								{

    							   textbox[i].style.backgroundColor = '#FFEB8B';
      					         }
    							 else
								 {
    							   pass = 'entered'
    							   textbox[i].style.backgroundColor = '#fff';
    							   countValidatedTextboxes++;
    							}
					}

					if(textbox[i].getAttribute('id') == 'new_pass1')
					{
    						   var pass1 =   textbox[i].value;

    							if((textbox[i].value == ''))
								{

    							   textbox[i].style.backgroundColor = '#FFEB8B';
      					         }
    							 else
								 {
    							   textbox[i].style.backgroundColor = '#fff';
    							   countValidatedTextboxes++;
    							}
					}

					if(textbox[i].getAttribute('id') == 'new_pass2')
					{

    						   var pass2 =   textbox[i].value;
    							if((textbox[i].value == ''))
								{
    							   textbox[i].style.backgroundColor = '#FFEB8B';
								 }else if ( pass1 != pass2 )  {
                                    PassError = 2;
                                    textbox[i].style.backgroundColor = '#FFEB8B';
      					         } else {
    							   textbox[i].style.backgroundColor = '#fff';
    							   countValidatedTextboxes++;
    							}
					}




				}
				countTextbox++;
			}

			if ( pass == 'entered' && pass1 == '' )  {
                                    PassError = 1;

      		}

			//  alert(countValidatedTextboxes);
			if( (countValidatedTextboxes == 3 && PassError == 0 ) || countValidatedTextboxes == 6 && PassError == 0 )
			{
				return true;
			}
			else
			{

				if ( PassError == 1 ) {
                jQuery(".error_message").html("Please Fill in the new password ");
				}else if ( PassError == 2 ) {
                jQuery(".error_message").html("Sorry New password dont match");
				}else {
				jQuery(".error_message").html("Please fill in all the required fields");

				}

				jQuery(".error_message").show();
				return false;
			}
	   });
	   jQuery("#email_password").submit(function(){

	   	var countTextbox = 0;
		var countValidatedTextboxes = 0;
		var emailRegEx =/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		var textbox = document.getElementsByTagName("input");

		  	for (var i=0; i < textbox.length; i++)
		  	{
				if (textbox[i].className.match("required_field"))
				{
					if(textbox[i].getAttribute('id') == 'name')
					{
    							if((textbox[i].value == ''))
								{

    							   textbox[i].style.backgroundColor = '#FFEB8B';
      					         }
    							 else
								 {
    							   textbox[i].style.backgroundColor = '#fff';
    							   countValidatedTextboxes++;
    							}
					}
					if(textbox[i].getAttribute('id') == 'email')
					{
    							if((textbox[i].value == '')  || (emailRegEx.test(textbox[i].value) == false))
								{

    							   textbox[i].style.backgroundColor = '#FFEB8B';
      					         }
    							 else
								 {
    							   textbox[i].style.backgroundColor = '#fff';
    							   countValidatedTextboxes++;
    							}
					}

				}
				countTextbox++;
			}

			if(countValidatedTextboxes == 2)
			{
				return true;
			}
			else
			{
				jQuery(".error_message").html("Please fill in all the required fields");
				jQuery(".error_message").show();
				return false;
			}
	   });
	   jQuery("#login_form").submit(function(){

	   	var countTextbox = 0;
		var countValidatedTextboxes = 0;
		var textbox = document.getElementsByTagName("input");

		  	for (var i=0; i < textbox.length; i++)
		  	{
				if (textbox[i].className.match("required_field"))
				{
					if(textbox[i].getAttribute('id') == 'username')
					{
    							if((textbox[i].value == ''))
								{

    							   textbox[i].style.backgroundColor = '#FFEB8B';
      					         }
    							 else
								 {
    							   textbox[i].style.backgroundColor = '#fff';
    							   countValidatedTextboxes++;
    							}
					}
					if(textbox[i].getAttribute('id') == 'password')
					{
    							if((textbox[i].value == ''))
								{

    							   textbox[i].style.backgroundColor = '#FFEB8B';
      					         }
    							 else
								 {
    							   textbox[i].style.backgroundColor = '#fff';
    							   countValidatedTextboxes++;
    							}
					}

				}
				countTextbox++;
			}

			if(countValidatedTextboxes == 2)
			{
				return true;
			}
			else
			{
				jQuery(".error_message").html("Please fill in all the required fields");
				jQuery(".error_message").show();
				return false;
			}
	   });
	jQuery("#name").focus(function() {

		jQuery("#name").css('backgroundColor', '#fff');

	});
	jQuery("#username").focus(function() {

		jQuery("#username").css('backgroundColor', '#fff');

	});
	jQuery("#email").focus(function() {

		jQuery("#email").css('backgroundColor', '#fff');

	});
	jQuery("#subject").focus(function() {

		jQuery("#subject").css('backgroundColor', '#fff');

	});
	jQuery("#password").focus(function() {

		jQuery("#password").css('backgroundColor', '#fff');

	});




});






