// JavaScript Document

jQuery.noConflict();

jQuery(document).ready(function(){
	// Kapcsolat és weboldal elemzés form

	jQuery('#z3n_kapcsolat_form').submit(function() {
	
		var no_error    = true;
		var first_error = true;
		var error_obj   = null;
		var name        = null;
		var form_focus  = null;
	
		if ( (jQuery('#contact-form-success').css('display')) != 'none' )
		{
			jQuery('#contact-form-success').css('display','none');
		}

		jQuery('#contact-form-error').text('The name and the message fields are required');
	
		jQuery('input.z3n_kapcsolat_kotelezo, textarea.z3n_kapcsolat_kotelezo').each(function() {
	
			if (jQuery(this).val() == '') 
			{
				no_error = false;
			
				if (first_error)
				{
					first_error = false;
					error_obj   = jQuery(this);
				}		
			}
	
		});

		if( no_error )
		{
			
			var email = jQuery('#z3n_kapcsolat_email');
			var email_val = email.val();

			if (email_val)
			{
			
				var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

				if (!filter.test(email_val)) 
				{
					
					//document.write(email_val);
					
					no_error = false;
				
					if (first_error) 
					{
						 first_error = false;
						 error_obj   = email;
					 }
					 
					 jQuery('#contact-form-error').text('The email format is invalid');
				}
				
			}
		}
	
		if(no_error)
		{
			return true;	
		}
		else
		{
			form_focus = '#' + error_obj.attr('id');
			jQuery(form_focus).focus(); 
			
			if ( (jQuery('#contact-form-error').css('display')) != 'block' )
			{
				jQuery('#contact-form-error').fadeIn('slow');
			}
		
			return false;
		}
	
	});
	
});
