﻿$(document).ready(function() {

	$('#submit_btn').mousedown(function() {
	$(this).attr("src","/wp-content/themes/alexpro/images/ok_press.jpg");
	});
	$('#submit_btn').mouseup(function() {
	$(this).attr("src","/wp-content/themes/alexpro/images/ok_hover.jpg");
	});
	$('#submit_btn').hover(function() {
	$(this).attr("src","/wp-content/themes/alexpro/images/ok_hover.jpg");
	}, function() {
	$(this).attr("src","/wp-content/themes/alexpro/images/ok.jpg");
	});
	
	$('#submit_btn').click(function() {
	
	$('#feedback input').removeClass('oops');
	$('#feedback textarea').removeClass('oops');
	
	var name = $('input#name').val();
		if (name == '' || name==' ' || name=='Ваше имя') {
			$('input#name').addClass('oops');
			$('input#name').focus();
			return false;
		}
	var email = $('input#email').val();
		if (email=='Ваш e-mail' || email==' ') {
			email='';
		}
	var question = $('textarea#question').val();
		if (question == '' || question=='Ваше сообщение' || question==' ') {
			$('textarea#question').addClass('oops');
			$('textarea#question').focus();
			return false;
		}
	var phone = $('input#phone').val();
		if (phone=='Ваш телефон' || phone==' ') {
			phone='';
		}
	
	my_date = new Date();
	
	var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&question=' + question + '&date=' + my_date;

	$('h2.gohide').fadeOut(300);
	$('#feedback').fadeOut(300, function() {$('.cnt').append('<div class="wait">Отправка сообщения...</div>');});

		$.ajax({
      		type: 'POST',
      		url: '/wp-content/themes/alexpro/bin/process.php',
      		data: dataString,
			success: function() {
				$('.wait').fadeOut(300, function() {$('.cnt').append('<div class="gotcha">Спасибо, мы получили Ваше сообщение!<br><br>Если это необходимо, мы ответим Вам в ближайшее время.</div>');});
      		},
			error: function() {
				$('.wait').fadeOut(300, function() {$('.cnt').append('<div class="gotchanot">К сожалению, при отправке произошла ошибка.<br><br>Перезагрузите страницу и попробуйте отправить сообщение ещё раз.</div>');});
			}
		});
	});

$("#feedback #name").focus(function() {
	attr = $(this).attr("value");
	if(attr=="Ваше имя") {
		$(this).attr("value","");
		$(this).css("color","#434343");
	};
});
$("#feedback #name").blur(function() {
	attr = $(this).attr("value");
	if(attr=="") {
		$(this).attr("value","Ваше имя");
		$(this).css("color","#434343");
	};
});
$("#feedback #phone").focus(function() {
	attr = $(this).attr("value");
	if(attr=="Ваш телефон") {
		$(this).attr("value","");
		$(this).css("color","#434343");
	};
});
$("#feedback #phone").blur(function() {
	attr = $(this).attr("value");
	if(attr=="") {
		$(this).attr("value","Ваш телефон");
		$(this).css("color","#bdbebe");
	};
});
$("#feedback #email").focus(function() {
	attr = $(this).attr("value");
	if(attr=="Ваш e-mail") {
		$(this).attr("value","");
		$(this).css("color","#434343");
	};
});
$("#feedback #email").blur(function() {
	attr = $(this).attr("value");
	if(attr=="") {
		$(this).attr("value","Ваш e-mail");
		$(this).css("color","#bdbebe");
	};
});
$("#feedback #question").focus(function() {
	attr = $(this).val();
	if(attr=="Ваше сообщение") {
		$(this).html("");
	};
});
$("#feedback #question").blur(function() {
	attr = $(this).val();
	if(attr=="") {
		$(this).html("Ваше сообщение");
	}
});


});
