function checkForm (type) {
	var fields;

	if (type == 'private')
		fields = ['clientName', 'address_p', 'contactPhone_p'];
	else if (type == 'corporate')
		fields = ['organisationName', 'address_c', 'contactPerson', 'contactPhone_c'];

	for (i in fields) {
		var field = $('#'+ fields[i]);

		if (! field.val ()) {
			alert ('Вы не заполнили все обязательные поля');
			return false;
		}
	}

	$('.disableOnSubmit').attr ('disabled', 'disabled');

	return true;
}

function noSubmit (e) {
	return (e.which !== 13);
}

function addToOrder(id) {
	var url = 'order.php';
	var qLink = $(this);
	var id = qLink.attr('href').replace('#', '');
	
	$.getJSON (url, {
		action: 'addGoods',
		id: id
	}, function(data) {
		updateTotalPrice(qLink, data)
	});
}

function updateTotalPrice (qLink, data) {
	var qMessageBox = $('#messageBox');
	var pos = qLink.offset();
	
	pos.top -= 5;
	pos.left -= 190;
	
	qMessageBox
		.css('top', pos.top+'px')
		.css('left', pos.left+'px')
		.fadeIn(500, function() {
			$(this).fadeOut(1000);
		});
	
	$('#totalPrice a').text ('Ваша корзина: '+data.price+' рублей');
}

function showForm(type) {
	$.cookie('orderType', type);
	
	if (type == 'private') {
		$('#form_corporate').hide (); 
		$('#form_private').show ();
	} else {
		$('#form_private').hide ();
		$('#form_corporate').show (); 		
	}
}

function saveOrderData() {
	
}
