  function isValidEmail(str) {
   	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  }
  
	function isValidEmailAddress(emailAddress) {
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		return pattern.test(emailAddress);
	}
  
  $('#response_msg').ajaxStart(function() {
	$(this).html('sending...');
  });
  
  function contact_submit_send() {
  	 if($('input[name="name"]').val() == '') {
	 	$('#response_msg').html('Please enter your name !');
	 } else if($('input[name="email"]').val() == '') {
	 	$('#response_msg').html('Please enter your email !');
	 } else if($('input[name="app"]').val() == '') {
	 	$('#response_msg').html('Please enter application !');
	 } else if($('textarea[name="problem"]').val() == '') {
	 	$('#response_msg').html('Please enter the problem faced !');
	 } else if(!isValidEmailAddress($('input[name="email"]').val())) {
	 	$('#response_msg').html('Please enter a valid email address !');
	 } else {
  	  	$.post("send.php", { 'sendbutton': 'y', 'name': $('input[name="name"]').val(), 'email': $('input[name="email"]').val(), 
							 'app': $('input[name="app"]').val(), 'problem': $('textarea[name="problem"]').val() } ,
				function(data) { 
					if(data == 'y') { 
						$('#tb_form').fadeOut(0);
						$('#break_line').fadeOut(0);
						$('#response_msg').html('Thank you for contact us, <br />we will reply you as soon as possible!'); 
					} else { 
						$('#response_msg').html('System send mail failure, please contact with <b>fenix@kdanmobile.com</b> !'); 
					} 
				});
    }
  }
  
