function check_input(id,field)
{
	$val = $('#'+id).val();
	if($val=='' || $val==field)
	{
		alert('Заполните поле '+field);
		return false;
	}
	return true;
}
$(document).ready(function (){
	
	$('#some_text div.company:first').addClass('active');
	$('#more').click(function(){
		var cur = $('#some_text div.company.active');
		cur.removeClass('active');
		if(cur.next()[0].tagName=='DIV')
			cur = cur.next();
		else
			cur = $('#some_text div.company:first');
		cur.addClass('active');
		return false;
	});
	
	$('.text').focus(function(){
		var old_value = this.getAttribute('old_value');
		if(old_value==null)
		{
			this.setAttribute('old_value',this.value);
			old_value = this.value;
		}
		if(old_value==this.value)
			this.value = '';
	});
	$('.text').blur(function(){
		if(this.value=='')
			this.value = this.getAttribute('old_value');
	});
	
	$('#manager_call form').submit(function(){
		if(!check_input('manager_call #name','Имя'))
			return false;
		if(!check_input('manager_call #phone','Телефон'))
			return false;

		$.post("/articles/manager_call", {name:$('#manager_call #name').val(),phone:$('#manager_call #phone').val()}, function(data, textStatus, XMLHttpRequest){
			
		}, 'json');
		$("#manager_call .clsbtn").click();
		return false;
	});
	$('#order_audit form').submit(function(){
		if(!check_input('order_audit #site_name','Имя сайта'))
			return false;
		if(!check_input('order_audit #name','ФИО'))
			return false;
		if(!check_input('order_audit #phone','Контактный телефон'))
			return false;
		if(!check_input('order_audit #question','Список запросов'))
			return false;
		
		$.post("/articles/order_audit", {
			site_name:$('#order_audit #site_name').val(),
			name:$('#order_audit #name').val(),
			phone:$('#manager_call #phone').val(),
			question:$('#manager_call #question').val(),
			more_info:$('#manager_call #more_info').val()
		}, function(data, textStatus, XMLHttpRequest){
			
		}, 'json');
		$("#order_audit .clsbtn").click();
		return false;
	});
});