$(document).ready(function(){	
	$("div.highlight input").each(function() {
		if (this.name != "send") {
			$(this).bind("focus", function() {		
				$(this).addClass("hl");
			});
		}
	});	
});

$(document).ready(function(){	
	$("div.highlight input").each(function() {
		$(this).bind("blur", function() {		
			$(this).removeClass("hl");
		});
	});
});

$(document).ready(function(){	
	$("div.highlight textarea").each(function() {
		$(this).bind("focus", function() {		
			$(this).addClass("hl");
		});
	});
});

$(document).ready(function(){	
	$("div.highlight textarea").each(function() {
		$(this).bind("blur", function() {		
			$(this).removeClass("hl");
		});
	});
});

function checkForm() {	
	
	var error = false;
	var b = $("input.rel");
	
	b.each(function() {
		if(this.value == "" || this.value == "Заполните поле") {			
			error = true;
			$(this).addClass("error");
			$(this).val('Заполните поле');			
		}
		else {
			$(this).removeClass("error");
		}
		
		/*if (this.name == "contmail") {
			
			var reg = new RegExp("[0-9a-z_]+@[0-9a-z_^.]+\\.[a-z]{2,3}", 'i')
			var result=reg.test($(this).val());			
			if (!result)  {				
				$(this).addClass("error");
				this.title = "Неверный e-mail";				
				error = true;
			}
		}*/
	});	

	var b = $("textarea.rel.yes");
	
	
	b.each(function() {	
		
		if($(this).val() == "" || $(this).val() == "Заполните поле") {			
			error = true;
			$(this).addClass("error");
			$(this).val('Заполните поле');			
		}
		else {
			$(this).removeClass("error");
		}
		
	});	
	
	if (error) return false;
	
	if (error == false) {		
		ajaxOrder();
	}
	

	
}


function ajaxOrder() {	
	
	var contface = $("#contface").val();
	var contphone = $("#contphone").val();
	var contmail = $("#contmail").val();
	var question = $("#question").val();
	
	
	var name = $("#name").val();
	var email = $("#email").val();
	
	
	if (name == "" && email == "") {
		$.post(
		  '/contacts',
		  {
			contface: contface,
			contphone: contphone,
			contmail: contmail,
			question: question		
		  },
		onAddSuccess
		);	
		$("#send").hide();
		$("#preloader").show();
		
		
	}
	
}

function onAddSuccess(data) {		
	if(data == "ok") {
		$("#preloader").hide();
		$("#order-form").append("<div id='thanks'>Спасибо. Мы ответим на Ваш вопрос в ближайшее время</div>");		
	}
	else {
		$("#send").show();
		$("#preloader").hide();
		$("#order-form").append("<div id='thanks'>Не отправлено</div>");
	}
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
