function divInfo(id, label) {
	this.div = $(id);
	this.label = $(label);

	Event.observe(this.label, 'mouseover', this.showInfo.bind(this));
	Event.observe(this.label, 'mouseout', this.hideInfo.bind(this));
	Event.observe(this.div, 'mouseover', this.keepInfo.bind(this));
	Event.observe(this.div, 'mouseout', this.hideInfo.bind(this));
	this.div.hide();
}

divInfo.prototype.showInfo = function(event) {
	var e = event | window.event;
	var x = Event.pointerX(event);
	var y = Event.pointerY(event);
	this.div.style.left = x - 2;
	this.div.style.top = y - 2;
	if (this.div.visible() == false) {
		this.div.show();
	}
}

divInfo.prototype.keepInfo = function() {
	if (this.div.visible() == false) {
		this.div.show();
	}
}

divInfo.prototype.hideInfo = function() {
	this.div.hide();
}

function clearField() {
	if (this.value == 'ччмм') {
		this.value = '';
	}
}

function showOrder(div, orderDiv, input, button) {
	this.div = $(div);
	this.orderDiv = $(orderDiv);
	this.input = $(input);
	this.button = $(button);
	this.value=this.input.value;

	Element.observe(this.input, 'keypress', this.keyEvent.bind(this, this.input));
	Element.observe(this.button, 'click', this.checkNumber.bind(this, this.input));
}

showOrder.prototype.keyEvent = function(elem, e) {
	if (!e)	e = window.event;
	if (e.keyCode != 13) return false;
	this.checkNumber.call(this,elem);
}



showOrder.prototype.showOrderDiv = function() {
	var obj = this;
	var value = this.value;
	document.body.style.overflow = "auto";

	this.div.show();
	this.orderDiv.show();
	var req = new Ajax.Request('/work/getOrder.php', {
		onComplete : pasteIt,
		parameters : {
			getOrder : 1,
			phone : value
		}
	})

	function pasteIt(t) {
		obj.orderDiv.innerHTML = t.responseText;

		AutoCompleteField.init('AutoCompleteField0', 'metro', 'name',
				'AutoCompleteField0_text', 3);
		AutoCompleteField.init('AutoCompleteField1', 'street', 'fullname',
				'AutoCompleteField1_text', 3);
		AutoCompleteField.init('AutoCompleteField2', 'metro', 'name',
				'AutoCompleteField2_text', 3);
		AutoCompleteField.init('AutoCompleteField3', 'street', 'fullname',
				'AutoCompleteField3_text', 3);
		OrderEditor.init("DataForm", false, "R", false);
		$('closeIt').onclick = function() {
			obj.orderDiv.hide();
			obj.div.hide();
			document.body.style.overflow = "";
		}

	}
}

showOrder.prototype.checkNumber = function(el) {
	var value = el.value;
	this.value=value;
	if (value.length != 10)	{alert("Неверный номер");return false;}
	if (this.checkNum.call(this)!=true) {alert("Неверный номер");return false;}
	this.showOrderDiv.call(this);
}

showOrder.prototype.checkNum=function(el) {
	var pat = new RegExp('^[0-9]+$');
	if (pat.test(this.value)) return true;
	else return false;
}

function ShowHide(id){
	($(id).visible()) ? $(id).hide() : $(id).show();
}

Element.observe(window, 'load', function(){
	var o=new showOrder('backDiv','order','textPhone','orderButton');
});