// JavaScript Document



  


  function isLength(phone){
		   var length = phone.length;
		   if(length >9 && length <13)
			 return true;
			 else
			 return false;
		   
		   }
		   

 function isValidEmail(email) {
	  var emailreg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	  return emailreg.test(email);
  
	   }




function validatecontact(){
	
	       //alert('hi');
	       var name  = $('.name').val();
		   var phone = $('.phone').val();
		   var email = $('.email').val();
		   var address = $('.address').val();
		    var subject = $('.subject').val();
		   var message = $('.message').val();
		   
		   
		   //alert(email);
		   
		  if(name == ''){
			      
			    $('.nameerror').html('Name cannot be empty');
			    return false;  
			  
			    $('.name').keyup(function(){
					  
					    $('.nameerror').hide();
					});
			  
			  }else if(phone == ''){
				  
				  $('.phoneerror').html('Phone Number cannot be empty');
				    return false;  
				  $('.phone').keyup(function(){
					  
					  $('.phoneerror').hide();
					  
					  });
				  
				  
			 }else if(email == ''){
				 $('.emailerror').html('Email can not be empty');
			// $('.email').focus();
			  $( '.email' ).blur(function() {
				   var x = $('.email').val();
    var atpos = x.indexOf("@");
    var dotpos = x.lastIndexOf(".");
    if (atpos< 1 || dotpos<atpos+2 || dotpos+2>=x.length) {
         $('.emailerror').html('Invalid Email');
        return false;
    }
                 $('.emailerror').hide();
				 return true;
                });
			  return false;  
					
			 }else if(address == ''){
				 
				   
				   $('.addresserror').html('Address cannot be empty');
				     return false;  
				  $('.address').keyup(function(){
					  
					   $('.addresserror').hide();
					  
					  });
				 
				 }else if(subject == ''){
					 
					 
					 $('.subjecterror').html('Subject cannot be empty');
					   return false;  
					 $('.subject').keyup(function(){
			
			          $('.subjecterror').hide();
						 
						 });
					
					 
			 }else if(message == ''){
					 
					 
					 $('.messageerror').html('Message cannot be empty');
					   return false;  
					 $('.message').keyup(function(){
			
			          $('.messageerror').hide();
						 
						 });
					
					 
			 }else{
	   
	                    
			return true;
			 }
	
	
	
	}
	
	
	
	function validatequick(){
	
	       var name  = $('.name').val();
		   var email = $('.email').val();
		  
		   var message = $('.message').val();
		   
		   
		  // alert(email);
		   
		  if(name == ''){
			      
			    $('.nameerror').html('Name cannot be empty');
			    return false;  
			  
			    $('.name').keyup(function(){
					  
					    $('.nameerror').hide();
					});
			  
			  }else if(email == ''){
				 $('.emailerror').html('Email can not be empty');
			// $('.email').focus();
			  $( '.email' ).blur(function() {
				   var x = $('.email').val();
    var atpos = x.indexOf("@");
    var dotpos = x.lastIndexOf(".");
    if (atpos< 1 || dotpos<atpos+2 || dotpos+2>=x.length) {
         $('.emailerror').html('Invalid Email');
        return false;
    }
                 $('.emailerror').hide();
				 return true;
                });
			  return false;  
					
			 }else if(message == ''){
					 
					 
					 $('.messageerror').html('Message cannot be empty');
					   return false;  
					 $('.message').keyup(function(){
			
			          $('.messageerror').hide();
						 
						 });
					
					 
			 }else{
	   
	                    
			return true;
			 }
	
	
	
	}
	
	
	
	function validateblur(classname,message){
		
		
		var data = $(classname).val();
		
		
		
		
		if (message == 'Email' ) {
		  if(isValidEmail(data)) {
			  classname = classname+'error';
			  $(classname).hide();
			  
		  } else {
			  classname = classname+'error';
		  
			  $(classname).html('Enter a valid Email');
			  $(classname).show();
			//  $('.email').focus();
		  }
	  }
		
		 if (message == 'Phone') {
		  if(isLength(data) ) {
			  classname = classname+'error';
			  $(classname).hide();
			  
		  } else {
			  classname = classname+'error';
		  
			  $(classname).html('Phone number must be 10-12 digits');
			  $(classname).show();
			 // $('.phone').focus();
		  }
	  }
		
		
		if(data == ''){
		
			classname = classname + 'error';
			$(classname).html(message +' cannot be empty');
			$(classname).show();
			$(classname).focus();
			
			} else {
				
				classname = classname + 'error';
				$(classname).hide();
				
				}
		
		
		}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	