
// constants to define the title of the alert and button text.
var ALERT_TITLE_ERROR = "Ошибка";
var ALERT_TITLE = "Сообщение";
var ALERT_BUTTON_TEXT = "OK";

// over-ride the alert method only if this a newer browser.
// Older browser will see standard alerts
if(document.getElementById) {
	window.alert = function(txt, status) {
		if (typeof status == "undefined") status = 0;
		createCustomAlert(txt, status);
	}
}

function createCustomAlert(txt, status) {
	// shortcut reference to the document object
	d = document;

	// if the modalContainer object already exists in the DOM, bail out.
	if(d.getElementById("modalContainer")) return;

	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		var alertTop = document.getElementsByTagName("body")[0].scrollTop + 200;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		var alertTop = document.documentElement.scrollTop + 100;
		$$('select').each(function (sel){
			sel.style.visibility = "hidden";
		});
	}

	// create the DIV that will be the alert
	//alertObj = mObj.appendChild(d.createElement("div"));
	alertObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	alertObj.id = "alertBox";
	// MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
	//if(d.all && !window.opera) alertObj.style.top = alertTop + "px"//document.body.scrollTop + "px";
	alertObj.style.top = alertTop + "px";
	// center the alert box
	alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";

	// create an H1 element as the title bar
	h1 = alertObj.appendChild(d.createElement("h1"));
	if (status == 0)
		h1.appendChild(d.createTextNode(ALERT_TITLE_ERROR));
	if (status == 1)
		h1.appendChild(d.createTextNode(ALERT_TITLE));

	// create a paragraph element to contain the txt argument
	msg = alertObj.appendChild(d.createElement("p"));
	msg.innerHTML = txt;
	//msg.appendChild(d.createTextNode(txt));

	// create an anchor element to use as the confirmation button.
	a = alertObj.appendChild(d.createElement("a"));
	a.href = '';
	a.setAttribute('onclick', 'removeCustomAlert();return false;');
	a.className = 'bt';
	a.style.margin = '10px auto';
	span1 = alertObj.appendChild(d.createElement("span"));
	span1.innerHTML = ALERT_BUTTON_TEXT;
	span2 = alertObj.appendChild(d.createElement("span"));
	span1.appendChild(span2);
	a.appendChild(span1);
	
	alertObj.innerHTML = alertObj.innerHTML + '<div class="angs lta"></div><div class="angs rta"></div><div class="angs lba"></div><div class="angs rba"></div>';
	
	// create the modalContainer div as a child of the BODY element
	mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	mObj.id = "modalContainer";
	 // make sure its as tall as it needs to be to overlay all the content on the page
	mObj.style.height = document.documentElement.scrollHeight + "px";
}

// removes the custom alert from the DOM
function removeCustomAlert() {
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("alertBox"));
	//document.getElementsByTagName("body")[0].removeChild(document.getElementById("overlay"));
	$$('select').each(function (sel){
		sel.style.visibility = "";
	});
}

function unfocusDiv() {
	$$('.focus_bl_brd').each(function(div){
		div.removeClassName("focus_bl_brd");
	});
}

function focusDiv(where, type) {
	unfocusDiv();
	
	$(where + "_" + type).addClassName("focus_bl_brd");
}

function  alertOffline() {
	Event.observe(window, 'load', function() {
		alert("Все такси находятся оффлайн. Воспользуйтесь системой позже.");
	});
}

function  alertNanGeo() {
	Event.observe(window, 'load', function() {
		alert("Нет такси в данном направлении. Попробуйте поменять маршрут.");
	});
}

function  alertWrongTrackID() {
	Event.observe(window, 'load', function() {
		alert("Заказа с таким номером не существует.");
	});
}
