var ocall_query;
var rsend_query;
var fastorder_query;

function send_ocall() {
	var ocall_name = encodeURIComponent(document.getElementById('ocall_name').value);
	var ocall_phone = encodeURIComponent(document.getElementById('ocall_phone').value);
	var ocall_time = encodeURIComponent(document.getElementById('ocall_time').value);

	var url = 'http://funburg.ru/ajax/call_order.php?action=call_order' + '&ocall_name=' + ocall_name + '&ocall_phone=' + ocall_phone + '&ocall_time=' + ocall_time + '&some=' + Math.random();

	ocall_query = createRequestObject();
	ocall_query.open("GET", url, true);
	ocall_query.onreadystatechange = ocallReadyState;
	ocall_query.send(null);
}

function ocallReadyState() {
	if(ocall_query.readyState == 4) {
		ocallOk();
	}
}

function ocallOk() {
	document.getElementById('ocall_form').style.display = 'none';
	document.getElementById('ocall_thanks').style.display = 'block';
}


function send_response() {
	var rsend_name = encodeURIComponent(document.getElementById('rsend_name').value);
	var rsend_contacts = encodeURIComponent(document.getElementById('rsend_contacts').value);
	var rsend_text = encodeURIComponent(document.getElementById('rsend_text').value);

	var url = 'http://funburg.ru/ajax/response_send.php?action=response_send' + '&rsend_name=' + rsend_name + '&rsend_contacts=' + rsend_contacts + '&rsend_text=' + rsend_text + '&some=' + Math.random();

	rsend_query = createRequestObject();
	rsend_query.open("GET", url, true);
	rsend_query.onreadystatechange = rsendReadyState;
	rsend_query.send(null);
}

function rsendReadyState() {
	if(rsend_query.readyState == 4) {
		rsendOk();
	}
}

function rsendOk() {
	document.getElementById('rsend_form').style.display = 'none';
	document.getElementById('rsend_thanks').style.display = 'block';
}

function send_fastorder() {
	var fastorder_type = encodeURIComponent(document.getElementById('fastorder_type').value);
	var fastorder_id = encodeURIComponent(document.getElementById('fastorder_id').value);
	var fastorder_price = encodeURIComponent(document.getElementById('fastorder_price').value);
	var fastorder_number = encodeURIComponent(document.getElementById('fastorder_number').value);
	var fastorder_name = encodeURIComponent(document.getElementById('fastorder_name').value);
	var fastorder_contacts = encodeURIComponent(document.getElementById('fastorder_contacts').value);

	var url = 'http://funburg.ru/ajax/quick_order.php?type=' + fastorder_type + '&id=' + fastorder_id + '&price=' + fastorder_price + '&number=' + fastorder_number + '&name=' + fastorder_name + '&contacts=' + fastorder_contacts + '&some=' + Math.random();

	fastorder_query = createRequestObject();
	fastorder_query.open("GET", url, true);
	fastorder_query.onreadystatechange = fastorderReadyState;
	fastorder_query.send(null);
}

function fastorderReadyState() {
	if(fastorder_query.readyState == 4) {
		fastorderOk();
	}
}

function fastorderOk() {
	document.getElementById('fastorder_show_form').style.display = 'none';
	document.getElementById('fastorder_thanks').style.display = 'block';
}

function showThanks() {
	document.getElementById('thanks').style.top = document.body.scrollTop + 200 + 'px';
	document.getElementById('background_order').style.top = document.body.scrollTop + 'px';
	document.getElementById('background_order').style.width = screen.width;
	document.getElementById('background_order').style.height = screen.height;

	document.getElementById('thanks_block').style.display = 'block';
	document.getElementById('thanks').style.display = 'block';
	document.getElementById('background_order').style.display = 'block';
	document.getElementsByTagName('body')[0].style.overflow = 'hidden';
}

function closeThanks() {
	document.getElementById('thanks_block').style.display = 'none';
	document.getElementById('thanks').style.display = 'none';
	document.getElementById('background_order').style.display = 'none';
	document.getElementsByTagName('body')[0].style.overflow = 'visible';
}
