var BaseURL = '';
$(document).ready(function() {
	$('#top-menu ul li').hover(function() {
		$(this).children('ul').css({'top': '20px', 'display': 'block'});
		$(this).children('ul').animate({'top': '15px'});
	}, function() {
		$(this).children('ul').css({'display': 'none'});
	});
	$('#wtu_submit').click(function(){

		$('#wtu_name, #wtu_email, #wtu_message').removeClass('wtu_error_input');
		$('#wtu_name, #wtu_email, #wtu_message').parent().find('em').remove();
		  
		  
	      var ok = true;
		if($('#wtu_name').val()==''){
			  $('#wtu_name').addClass('wtu_error_input');
			  $('#wtu_name').parent().append('<em>Обязательное поле</em>');
			  ok=false;
		}

		if($('#wtu_email').val()==''){
			  $('#wtu_email').addClass('wtu_error_input');
			  $('#wtu_email').parent().append('<em>Обязательное поле</em>');
			  ok=false;
		}else{
			if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.getElementById('wtu_email').value))){ 
			  $('#wtu_email').addClass('wtu_error_input');
			  $('#wtu_email').parent().append('<em>Неправильный адрес</em>');
			  ok=false;
			}
		}
		if($('#wtu_message').val()==''){
			  $('#wtu_message').addClass('wtu_error_input');
			  $('#wtu_message').parent().append('<em>Обязательное поле</em>');
			  ok=false;
		}
		
		if(ok){
		          var data = [];

		    	    data.push({name: 'wtu_name', 		value: $('#wtu_name').val()});
		    	    data.push({name: 'wtu_email', 		value: $('#wtu_email').val()});
		    	    data.push({name: 'wtu_message', 	value: $('#wtu_message').val()});

			    $.ajax({
				      type: "POST",
				      url: "/inc/swtu.php",
				      data: data,
				      async: false,
				      beforeSend: function(resp) {
					      $('#wtu_form').html('<table cellpadding="0" cellspacing="0" border="0" width="100%" style="border:none;">'+
										      '<tr>'+
											      '<td align="center" style="border:none;"><img src="/style/img/ajax-loader.gif" /></td>'+
										      '</tr>'+
										'</table>');
				      },
				      success: function(res) {
					  $('#wtu_form').html(res);
				      },
				      complete: function() {
				      },
				      error: function() {
					  $('#wtu_form').html('К сожалению произошла ошибка. Попробуйте еще раз');
				      }
			    });
		}
	});
});

