function createRequestObject(){
	var xmlhttp;
  	try {
   		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  	} catch (e) {
    	try {
      		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    	} catch (E) {
      		xmlhttp = false;
   		}
  	}
  	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    	xmlhttp = new XMLHttpRequest();
  	}

  	return xmlhttp;
}

function show_callback_form() {
	document.getElementById('ocall_form').style.display = 'block';
	document.getElementById('ocall_thanks').style.display = 'none';

	document.getElementById('callback_form').style.display = 'block';
	document.getElementsByTagName('body')[0].style.overflow = 'hidden';
}

function close_callback_form() {
	press_button_funburg('popup_cross', 'callback_cross');

	document.getElementById('callback_form').style.display = 'none';
	document.getElementsByTagName('body')[0].style.overflow = 'auto';
}

var ocall_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 show_order_form() {
	document.getElementById('order_show_form').style.display = 'block';
	document.getElementById('order_thanks').style.display = 'none';

	document.getElementById('order_form').style.display = 'block';
	document.getElementsByTagName('body')[0].style.overflow = 'hidden';
}

function close_order_form() {
	press_button_funburg('popup_cross', 'order_cross');

	document.getElementById('order_show_form').style.display = 'none';
	document.getElementsByTagName('body')[0].style.overflow = 'auto';
}

var order_query;

function send_order() {
	var order_name = encodeURIComponent(document.getElementById('order_name').value);
	var order_contacts = encodeURIComponent(document.getElementById('order_contacts').value);
	var order_comment = encodeURIComponent(document.getElementById('order_comment').value);
	var order_source = encodeURIComponent(document.getElementById('source').value);

	var url = 'http://decoration.funburg.ru/ajax/order.php?name=' + order_name + '&contacts=' + order_contacts + '&comment=' + order_comment + '&source=' + order_source + '&some=' + Math.random();

	order_query = createRequestObject();
	order_query.open("GET", url, true);
	order_query.onreadystatechange = orderReadyState;
	order_query.send(null);
}

function orderReadyState() {
	if(order_query.readyState == 4) {
		orderOk();
	}
}

function orderOk() {
	document.getElementById('order_form').style.display = 'none';
	document.getElementById('order_thanks').style.display = 'block';
	
	document.getElementsByTagName('body')[0].style.overflow = 'auto';
}

function press_button_funburg(name, tag_id) {
	if(name == 'next')
	{
		if(next_button == 1) {
			document.getElementById(tag_id).src = 'http://funburg.ru/images/' + name + '_pressed.jpg';
		}
	}
	else {
		document.getElementById(tag_id).src = 'http://funburg.ru/images/' + name + '_pressed.jpg';
	}
}

function unpress_button_funburg(name, tag_id) {
	button_timeout = setTimeout('unpress_button_go("' + name + '", "' + tag_id + '")', 50);
}

function unpress_button_go(name, tag_id) {
	try	{document.getElementById(tag_id).src = 'http://funburg.ru/images/' + name + '.jpg';} catch(e) {};
}
