if( typeof(lang_url_prefix) == 'undefined'  )
    var lang_url_prefix = '';

var commonPhrases = {
        createNewOrder : 'Создать новый заказ',
        continueWithExistingOrder : 'Продолжить работу с существующим заказом',
        attention : 'Внимание!',
        chooseAction : 'Выберите дальнейшее действие'
    };

function orderConfirm(url, header, content, options){
	confirmDialog = new YAHOO.widget.SimpleDialog("dlg", {
		width: "500px",
		effect:{effect:YAHOO.widget.ContainerEffect.FADE,
				duration:0.25},
		fixedcenter:true,
		zIndex: 10000,
		modal:false,
		visible:true,
		underlay: "shadow",
		draggable:false });

	confirmDialog.setHeader(header);
	confirmDialog.setBody(content);
	confirmDialog.cfg.setProperty("icon",YAHOO.widget.SimpleDialog.ICON_WARN);
	
	var handleYes = function() {
		this.hide();
		document.location = url + '?new_order=1' + ( ! options ? '' : '&' + options );
		return false;
	}
	var handleNo = function() {
		this.hide();
		document.location = url + ( ! options ? '' : '?' + options );
		return false;
	}
	var buttons = [ { text: commonPhrases.createNewOrder,
						handler:handleYes,
						isDefault:true  },
					{ text: commonPhrases.continueWithExistingOrder,
						handler:handleNo }
					];

	confirmDialog.cfg.queueProperty("buttons", buttons);
	confirmDialog.render(document.body);
	confirmDialog.show();

	return false;
}

function searchHotelConfirm( options ){
	if(! options)
		options = '';
	return orderConfirm(lang_url_prefix + "/main/search_hotel/", commonPhrases.attention, commonPhrases.chooseAction, options);
}

function searchTransferConfirm(){
	return orderConfirm(lang_url_prefix + "/main/search_transfer/", commonPhrases.attention, commonPhrases.chooseAction);
}

function searchVehicleConfirm(){
	return orderConfirm(lang_url_prefix + "/main/search_vehicle/", commonPhrases.attention, commonPhrases.chooseAction);
}

function getE(id){
	return document.getElementById(id);
}

function ShowWin(url,x,y,name,isscrollbars, menubar) {
cx=screen.width/2-(x/2);
cy=screen.height/2-(y/2);
isscrollbars=(isscrollbars=="no")?"no":"yes";
if(name == null) name="_blank";
if(menubar == null) menubar = 'no';
window.open(url,name,"toolbar=no,status=no,directories=no,menubar="+menubar+",resizable=yes,width="+x+",height="+y+",scrollbars="+isscrollbars+",top="+cy+",left="+cx);
}

function defined(x){
	return typeof(x) != 'undefined' && x != null;
}

function addListener(element, event, func){
	if(element.attachEvent)
		element.attachEvent('on' + event, function(){ func(window.event) });
	else if(element.addEventListener)
		element.addEventListener(event, func, false);
}

function removeListener(element, event, func){
	if(element.detachEvent)
		element.detachEvent('on' + event, func);
	else if(element.removeEventListener)
		element.removeEventListener(event, func, false);
}

function popupHotel(url, print) {
	ShowWin(url, 800, 600, '', 'yes', print?print:'no');
	return false;
}


var HintObj, HintOpacity;

function ShowHint(element, hint_id, class_name, src_id) {
	HintObj = getE(hint_id);
	HintObj.className = class_name;
	if (src_id)
		HintObj.innerHTML = getE(src_id).innerHTML;
	HintOpacity = 0.1;
	HintObj.style.opacity = HintOpacity;
    HintObj.style.visibility = "visible";
    $(element).mousemove(PositionTip);
    Appear();
}

function HideHint(element, hint_id) {
	getE(hint_id).style.visibility = 'hidden';
	element.onmousemove = '';
}

function ShowOfferHint(element, id_offer, offer_type) {
	ShowHint(element, 'id_OfferHint', "special_offer_hint_" + offer_type, 'id_offer_' + id_offer);
}

function IeTrueBody() {
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
} 
 
function PositionTip(e) {
	var ie = document.all && !window.opera;
	var ns6 = document.getElementById && !document.all;
	
	var marginX = parseInt( getE('container').offsetLeft );

	var curX = (ns6)?e.pageX : event.clientX+IeTrueBody().scrollLeft;
	var curY = (ns6)?e.pageY : event.clientY+IeTrueBody().scrollTop;
	var winwidth = ie&&!window.opera? IeTrueBody().clientWidth : window.innerWidth-20;
	var winheight = ie&&!window.opera? IeTrueBody().clientHeight : window.innerHeight-20;
	 
	var rightedge = ie&&!window.opera? winwidth-event.clientX : winwidth-e.clientX; 
	var bottomedge = ie&&!window.opera? winheight-event.clientY-15 : winheight-e.clientY-15; 
	
	if (rightedge < HintObj.offsetWidth && curX-HintObj.offsetWidth > 0)
		HintObj.style.left = curX-HintObj.offsetWidth+"px";
	else
		HintObj.style.left = curX-marginX+"px";
	
	if (bottomedge<HintObj.offsetHeight)
		HintObj.style.top = curY-HintObj.offsetHeight+"px"
	else
		HintObj.style.top = curY+15+"px";
} 
 
function Appear() {
	var ua = navigator.userAgent.toLowerCase();
	
	if (HintOpacity < 1) { 
		(ua.indexOf('opera') == -1) ? HintOpacity+=0.1 : HintOpacity+=100; // special exeption on Opera
		HintObj.style.opacity = HintOpacity; 
		HintObj.style.filter = 'alpha(opacity='+HintOpacity*100+')'; 
		t = setTimeout('Appear()', 30); 
	}
}

// Get Absolut coordinates of DOM-element
function getAbsolutePos(el) {
	var r = { x: el.offsetLeft, y: el.offsetTop };

	if (el.offsetParent) {
		var tmp = getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}

// Recursively convert object to string (for debug output)
function obj2str(obj, split){
	if( !split ) split = '\n';

	var tab = '    ';
	var result = '', val = '';

	for( var i in obj ) {
		if( typeof(obj[i]) == 'object' )
	        val = obj2str(obj[i]);
	    else
	        val = obj[i];

        result += tab + i + " : " + val + split;
    }

    result = '{' + split + result + '}';

	return result;
}

