function AjaxResult(response){eval(response)}
function get_options(Id, El){
	$.post(
		'/req/get_options.php',
		{
el:El,
id:Id
		},
		AjaxResult
	)
}

function orderby(val){
	location.href = location.href.replace(/orderby=[0-9]+/, 'orderby='+val)
}

function getBrowserInfo() {
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (navigator.appName) t = 'Netscape';
 return {type:t,version:v};
}

function bookmark(a){
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = url+','+title;
  return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
 return false;
}

var confirm_form = function(f){
	var result = true;
	$('.required', f).each(function(){
		if(!this.value){
result = false;
alert('Поля, отмеченные *, обязательны для заполнения!');
return false;
		}
	})
	return result;
}

function show_map(latitude, longitude, scale){

		$('#google_map').toggle()
		document.getElementById('google_map').style.height = '400px'
		if(GBrowserIsCompatible()){
var marker;
var map = new GMap2(document.getElementById('google_map'));
map.setCenter(new GLatLng(latitude, longitude), scale);
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.enableDragging()
map.enableDoubleClickZoom()
map.enableContinuousZoom()
map.enableScrollWheelZoom()
var cpoint = new GLatLng(latitude, longitude);
var marker= new GMarker(cpoint);
map.addOverlay(marker);
		}
	}


function preventSelection(element){
  var preventSelection = false;

  function addHandler(element, event, handler){
    if (element.attachEvent)
      element.attachEvent('on' + event, handler);
    else
      if (element.addEventListener)
        element.addEventListener(event, handler, false);
  }
  function removeSelection(){
    if (window.getSelection) { window.getSelection().removeAllRanges(); }
    else if (document.selection && document.selection.clear)
      document.selection.clear();
  }
  function killCtrlA(event){
    var event = event || window.event;
    var sender = event.target || event.srcElement;

    if (sender.tagName.match(/INPUT|TEXTAREA/i))
      return;

    var key = event.keyCode || event.which;
    if (event.ctrlKey && key == 'A'.charCodeAt(0))  // 'A'.charCodeAt(0) можно заменить на 65
    {
      removeSelection();

      if (event.preventDefault)
        event.preventDefault();
      else
        event.returnValue = false;
    }
  }
  addHandler(element, 'mousemove', function(){
    if(preventSelection)
      removeSelection();
  });
  addHandler(element, 'mousedown', function(event){
    var event = event || window.event;
    var sender = event.target || event.srcElement;
    preventSelection = !sender.tagName.match(/INPUT|TEXTAREA/i);
  });
  addHandler(element, 'mouseup', function(){
    if (preventSelection)
      removeSelection();
    preventSelection = false;
  });
  addHandler(element, 'keydown', killCtrlA);
  addHandler(element, 'keyup', killCtrlA);
}

preventSelection(document);

var message="Копирование запрещено. Авторские права принадлежат компании TrustHouse.";
function clickIE4(){
	if (event.button==2){
		alert(message);
		return false;
	}
}
function clickNS4(e){
	if (document.layers||document.getElementById&&!document.all){
		if (e.which==2||e.which==3){
alert(message);
return false;
		}
	}
}
if (document.layers){
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
	document.onmousedown=clickIE4;
}
document.oncontextmenu=new Function("alert(message);return false")


function object_select(el, country, id){
	$(el).attr('disabled', 'disabled');
	$(el).next().html('загрузка');
	$.post('/req/object_select.php',{country:country, id:id}, function(response){
		$(el).next().replaceWith(response);
		/*$(el).next().tooltip({
			tip:'#tooltip',
			offset:[-10, 0],
			delay:200
		})*/
		$(el).removeAttr('disabled', 'disabled');
	})
}

/*$(function(){
	if(country = location.href.match(/http:\/\/(www\.)?trusthouse\.ru\/([a-z]+)/)){
		if(country.length < 3) return;
		$('<div class="tooltip" id="tooltip"><a href="/'+country[2]+'/?page=catalog&selected=1">Просмотреть отмеченные объекты</a></div>').appendTo('body')
		$('label', '.catalog_header').tooltip({
			tip:'#tooltip',
			offset:[-10, 0],
			delay:200
		})
	}
})*/

function cancel_select(country){
	$.post('/req/cancel_select.php',{country:country}, function(response){
		location.href='/'+country+'/'
	})
}
