GKconst={
	WEBSERVER: "http://giskirov.ru/",
	SERVER: "http://188.128.114.221/",
	PHPGETHELPWORDS:"php/gkm_get_HelpWords.php",
	PHPGETFIRMINFO:"php/gkm_get_FirmInfo.php",
	PHPGETFIRMHOUSES:"php/gkm_get_FirmHouses.php",
	PHPGETHOUSEPROV:"php/gkm_get_ProvByHouse.php",
	PHPGETHOUSEPHOTO:"php/gkm_get_HousePhoto.php",
	PHPGETCATALOGREKL:"php/gkm_get_KatalogRekl.php",
	PHPGETQWREKL:"php/gkm_get_QueryWordsRekl.php",
	PHPSTATSQW:"php/gkm_stat_FindWords.php",
	PHPSTATSMAINREKL:"php/gkm_stat_clickMainRekl.php",
	PHPSTATSPRAVKAKIROVA:"php/gkm_stat_SpravkaKirova.php",
	CGIGETQW:"cgi-bin/get_qw_firms",
	CGIGETPODRUBRICFIRMS:"cgi-bin/gkm_get_Podrubric_House_firms",
	CGIGETHOUSEFIRMS:"cgi-bin/gkm_get_Podrubric_House_firms",
	CGIGETFLOORWORDS:"cgi-bin/gkm_get_podval",
		
	GOTOMAP:	"goto/map.php",
	
	SLIDERSTEPS:8,
	SLIDERLENGTHSTEP:9
	//PHPGETPODRUBRICFIRMS:"php/gkm_get_Podrubric_firms.php",
	//PHPGETHOUSEFIRMS:"php/gkm_get_HouseFirms.php",
};
GKvar={
	IDRubricNow:0,
	IDPodRubricNow:0,
	IDFirmsNow:'',
		
	QueryWord:'',
	PageNow:'',
	FeaturesSEARCHMARKERS:'',
	HousePhotos:''
};
var GKMap;

$(document).ready(function(){
	if (stupidIE==1) $('#PageMap_LoadScript').show();
	
	GKvar.PageNow='katalog';
	$('#ListStatusText_search').addClass("StatusTexthide");
	
	document.getElementById('layer1').checked=true;
	document.getElementById('layer2').checked=true;
	document.getElementById('layer3').checked=true;
	document.getElementById('selectLayer1').checked=true;
	document.getElementById('selectLayer2').checked=true;
	document.getElementById('selectLayer3').checked=true;
	document.getElementById('selectLayer4').checked=true;
	
	document.getElementById('page').style.height = (document.body.clientHeight-document.getElementById('header').clientHeight-3)+'px';	
	document.getElementById('PageList_cont').style.height = (document.getElementById('PageList_main').clientHeight-document.getElementById('PageList_main_header').clientHeight-21)+'px';	
	createSliderBar();
	createKatalog(Katalog);
	QueryWords_action();
	
	
	$.getScript(GKconst.SERVER+GKconst.CGIGETQW+"?flags=&query_words=",function(){
		LoadMainRe(mr['org_id'],mr['url'],mr['pic']);	//главная реклама									
	});
	
	LoadCatalogRe();	//реклама в каталоге
	
	if (stupidIE==1){ //эта дурость для IE 6-8		
		jQuery.getScript('http://giskirov.ru/js/OpenLayers.js', function(){							
			jQuery.getScript('http://giskirov.ru/js/gk_map.js', function(){
					
					$('#PageMap_LoadScript').hide();
					
					GKMap = new GKM();
					GKMap.initialize();
					GKMap.addLAYERS();
					onClickTool(GKD.ToolNow);
					
					if (GKMap.ParametersURL.qw!=undefined ){ 
						$('#QueryWords').val(GKMap.ParametersURL.qw);
						onClickSearch();
					} 
					else {
						$.getScript(GKconst.SERVER+GKconst.PHPGETQWREKL,function(){
							if (QWRecl.length>0)  $('#QueryWords').val(QWRecl);	//реклама в поисковой строке
						});
						
						MainLoadContent();
						GKMap.loadContent();
					}
			});
		});				
	}else{
		jQuery.getScript('http://giskirov.ru/js/gk_map.js', function(){								
					
					GKMap = new GKM();
					GKMap.initialize();
					GKMap.addLAYERS();
					onClickTool(GKD.ToolNow);
										
					if (GKMap.ParametersURL.qw!=undefined ){ 
						$('#QueryWords').val(GKMap.ParametersURL.qw);
						onClickSearch();
					}
					else {
						$.getScript(GKconst.SERVER+GKconst.PHPGETQWREKL,function(){
							if (QWRecl.length>0)	$('#QueryWords').val(QWRecl);	//реклама в поисковой строке
						});						
						
						MainLoadContent();
						GKMap.loadContent();
					}
		});	
	};
	
	$("#PageMap_Photo_image").click(function() {

		var list_index=$("#PageMap_Photo_image").attr("value");		
		list_index++;
		
		if (list_index < GKvar.HousePhotos.length) {
			 OnClickHousePhoto(GKvar.HousePhotos[list_index]['id'],GKvar.HousePhotos[list_index]['width'] ,GKvar.HousePhotos[list_index]['height'],list_index); }
		else closeHousePhoto();
			
	});

});

function removeRULE(){
	GKMap.removeRULE();
};

window.onresize=function(){	
	document.getElementById('page').style.height = (document.body.clientHeight-document.getElementById('header').clientHeight-3)+'px';
	document.getElementById('PageList_cont').style.height = (document.getElementById('PageList_main').clientHeight-document.getElementById('PageList_main_header').clientHeight-21)+'px';
	if ($("#PL_2").html()!='') document.getElementById('PL_2_list').style.height = document.getElementById('PageList_cont').clientHeight-50+'px'; 
	if ($("#PL_3").html()!='') document.getElementById('PL_3_list').style.height = document.getElementById('PageList_cont').clientHeight-50+'px'; 
	if ($("#PL_4").html()!='Список пуст') document.getElementById('PL_4_list').style.height = document.getElementById('PageList_cont').clientHeight-50+'px';
};

function createSliderBar (){
	$("#SliderScrolBar").draggable({
		containment:'parent',
		axis: 'y',
		grid: [0,GKconst.SLIDERLENGTHSTEP],
		stop: eventStopSliderBar
  });
	
};

function eventStopSliderBar (event, ui){
	
	var zoom= Math.round( (63-ui.position.top) / GKconst.SLIDERLENGTHSTEP );
	GKMap.controlzoomTo( zoom );
/*
	alert("Событие: " + event.type +
	            "\n\ntop: " + ui.position.top +
	            " px\nleft: " + ui.position.left +
	            " px");*/
};

function setPositionSliderBar (zoom){
	
	document.getElementById('SliderScrolBar').style.top= Math.round(63-GKconst.SLIDERLENGTHSTEP*zoom)+'px';	
};

function onClickListArrowLeft (){
	document.getElementById('PageList').style.width= "auto";
	$("#PageList_main").hide("slide", 200, function (){		
		GKMap.updateMap();
	});
};

function onClickListArrowRight (){	
	$("#PageList_main").show("slide", 200, function (){
		document.getElementById('PageList').style.width= "300px";
	});
};


function onClickFloorDopInfo (){	
	$("#PageMap_floor_menu").slideToggle(200, function (){
		
	});
};

function onMouseOverHouse(NameElement){
	$('.FI_house_show').hide();
	$(".FI_house_show[id='"+NameElement+"']").show();
};

function onMouseOutHouse(){
	
};

function positionCatalogRe(){
	/*
	var ostHeight=	$("#PageList_cont").height()-$("#PL_1").height();	
	if (document.getElementById('CatalogRe_cont').display=='none') ostHeight=ostHeight-234;
			//так делать нельзя
			
			// надо так $('#PL_3').is(':visible')==true
			* 
	$('#QueryWords')[0].value=ostHeight;
	
	if (ostHeight > 0){	$("#CatalogRe_cont").show();}
	else {	$("#CatalogRe_cont").hide();};
	* */		
	
};

function createKatalog(Katalog){	
	$("#PageList_cont > div").hide();

	var myHTML='<ul id="gkTreeview" class="filetree treeview-gk">';
	
	for (var i=0; i<Katalog.length;i++){
		myHTML+='<li class="closed"><span class="folder"  onClick="onClickRubric('+Katalog[i]['id']+');">'+Katalog[i]['name']+'</span><ul>';
		
		for (var j=0; j<Katalog[i]['podrubric'].length;j++){
			myHTML+='<li><span class="file" onClick="onClickPodrubric('+Katalog[i]['podrubric'][j]['id']+',\''+Katalog[i]['name']+'\',\''+Katalog[i]['podrubric'][j]['name']+'\');">'+Katalog[i]['podrubric'][j]['name']+'</span></li>';			
		};
		
		myHTML+='</ul></li>';		
	};	
	myHTML+='</ul>';
	
	myHTML+='<div id="CatalogRe_cont"></div>';
	
	$("#PL_1").html(myHTML).show();	
	$("#gkTreeview").treeview({
		animated: "fast",
		persist: "location",
		collapsed: true,
		unique: true,
		
		toggle: function() {
		//console.log("%s was toggled.", $(this).find(">span").text());			
		}
	});
	
};

function ShowKatalog (){
	if (GKvar.PageNow=='search'){
		closeHousePhoto();
		GKMap.removeFeaturesSEARCHMARKERS();
		$("#PageList_cont > div").hide();
		$("#PL_1").show();
		$('#ListStatusText_Katalog').removeClass("StatusTexthide");
		$('#ListStatusText_search').addClass("StatusTexthide");		
		GKvar.PageNow='katalog';
		$("#ListArrowRight>span").html("каталог");		
	}else {
		$("#PageList_cont > div").hide();
		$("#PL_1").show();			
	}
	
	GKMap.stopFilterSEARCHMARKERS();
};
function ShowSearch (){		
	if (GKvar.PageNow=='katalog'){
		GKMap.setFeaturesSEARCHMARKERS(GKvar.FeaturesSEARCHMARKERS);
		$("#PageList_cont > div").hide();
		$("#PL_4").show();
		$('#ListStatusText_Katalog').addClass("StatusTexthide");
		$('#ListStatusText_search').removeClass("StatusTexthide");		
		GKvar.PageNow='search';
		$("#ListArrowRight>span").html("результаты_поиска");	
	}else {
		$("#PageList_cont > div").hide();
		$("#PL_4").show();	
	}
};
function OnClickBackKatalog (){	
	$("#PageList_cont > div").hide();
	$("#PL_1").show();	
};

function OnClickBackPodrubFirms (){	
	$("#PageList_cont > div").hide();
	$("#PL_2").show();
	GKMap.stopFilterSEARCHMARKERS();	
};

function OnClickBackResultSearch (ShowOnMap){	
	$("#PageList_cont > div").hide();
	$("#PL_4").show();
	if (ShowOnMap==false) GKMap.stopFilterSEARCHMARKERS();	
	else {
		GKMap.removeFeaturesSEARCHMARKERS();	
		GKMap.setFeaturesSEARCHMARKERS(GKvar.FeaturesSEARCHMARKERS);
	};
};

function onClickSearch (){
	var Flags='';
	if ( document.getElementById("selectLayer1").checked==true ) Flags+='f';
	if ( document.getElementById("selectLayer2").checked==true ) Flags+='a';
	if ( document.getElementById("selectLayer3").checked==true ) Flags+='t';
	if ( document.getElementById("selectLayer4").checked==true ) Flags+='b';
	
	if ((Flags!='')&&($('#QueryWords')[0].value!='')) GKSearch( $('#QueryWords')[0].value, Flags );	
};


function getSearchItem(TypeSI,locArray){
	var myHTML='';
	var SEARCHMARKERS = [];
	
	switch (TypeSI){
			
		case "firms":			
				for (var i=0;i<locArray.length;i++){
					
					if (i==0) {GKvar.IDFirmsNow=locArray[i]['id'];}
					else if (i<100){GKvar.IDFirmsNow+=','+locArray[i]['id'];};					
					
					myHTML+='<li class="Firms"  onClick="OnClickSearchItemFirm('+locArray[i]['id']+',false);"><span class="FirmsName">'+locArray[i]['fn']+'</span><span class="FirmsPodrubric">'+locArray[i]['podtext']+'</span></li>';			
					for (var j=0;j<locArray[i]['coords'].length;j++)
						SEARCHMARKERS.push( {x:locArray[i]['coords'][j]['x'], y:locArray[i]['coords'][j]['y'], ID:locArray[i]['id'], typeBack:'search', nameRub: '', namePodRub: '' } );					
				};				
				
				GKMap.addFeaturesSEARCHMARKERS(SEARCHMARKERS);			
				break;
		
		case "houses":			
				for (var i=0;i<locArray.length;i++){
					myHTML+='<li class="Houses"  onClick="GKMap.gotoAddress('+locArray[i]['x']+', '+locArray[i]['y']+');">'+locArray[i]['address']+'</li>';
				
					SEARCHMARKERS.push( {x:locArray[i]['x'], y:locArray[i]['y'], ID:locArray[i]['id'], typeBack:'search_house', nameRub: '', namePodRub: '' } );
				};
				
				GKMap.addFeaturesSEARCHMARKERS(SEARCHMARKERS);	
				break;		
	
		case "trans":			
				for (var i=0;i<locArray.length;i++)
					myHTML+='<li class="Trans"  onClick="onClickTrasLine('+locArray[i]['id']+','+locArray[i]['type']+');">'+locArray[i]['name']+'</li>';

				break;
		
		case "modules":			
				for (var i=0;i<locArray.length;i++)
					if (locArray[i]['tr']==2) 
						myHTML+='<li class="Modules"  onClick="OnClickSearchItemFirm('+locArray[i]['id']+',false);"><img src="http://188.128.114.221/picture/firms/'+locArray[i]['rp']+'" width="234px" height="60px" /></li>';

				break;
				
		case "photos":			
				for (var i=0;i<locArray.length;i++)											
						myHTML+='<li class="Photos" value="'+i+'" onClick="OnClickHousePhoto('+locArray[i]['id']+','+locArray[i]['width']+','+locArray[i]['height']+','+i+');"><img src="http://giskirov.ru/photo/preview/'+locArray[i]['id']+'.jpg" width="234px" ALT="Фотография'+i+'" title="Увеличить" /></li>';
	
				break;	
	};

		
	return myHTML;	
};

function GKSearch(SearchString,Flags){	
	GKvar.QueryWord='';
	closeHousePhoto();
	
	$('.ac_results').hide();
/*
	SearchString= SearchString.replace(new RegExp("'",'g'),"");
	SearchString= SearchString.replace(new RegExp('"','g'),"");
	SearchString= SearchString.replace(new RegExp("%",'g'),"");
	SearchString= SearchString.replace(new RegExp("<",'g'),"");
	SearchString= SearchString.replace(new RegExp(">",'g'),"");
	SearchString= SearchString.replace(/\\/g,"/");
	
	var strBUF=SearchString.split(' ');
	var str='';
			
	for(var i=0;i<strBUF.length;i++){		
		if (strBUF[i]!=""){			
			if (str!="")str+="&" ;
			str+=strBUF[i];				
		}
	};
	*/
	str=SearchString;
	
	if	(str.length>0){
		GKvar.QueryWord=str;
		GKMap.removeFeaturesSEARCHMARKERS();
					
		$.getScript(GKconst.SERVER+GKconst.PHPSTATSQW+"?query_words="+encodeURIComponent(str) );	
		var myHTML= '';
		myHTML+='<div>Идет загрузка...</div>';			
		$("#PL_4").html(myHTML);
		ShowSearch();
		
		$("#PageList_main").show();
		document.getElementById('PageList').style.width= "300px";
		//onClickListArrowRight();		
		
		setTimeout(function(){			
			$.getScript(GKconst.SERVER+GKconst.CGIGETQW+"?flags="+Flags+"&query_words="+encodeURIComponent(str),function(){
					LoadMainRe(mr['org_id'],mr['url'],mr['pic']);	//главная реклама
				
					var myHTML= '<div class="PageListBack">'+
								'По запросу  <span class=FirmsPodTextlight>"'+SearchString+'"</span> найдено '+(firms.length+houses.length+transports.length)+' записей'+	
								'</div>';
					myHTML+='<div id="PL_4_list"><ul class="ListItems">';
					myHTML+=getSearchItem('modules',modules);	//modules-получаем из скрипта
					myHTML+=getSearchItem('trans',transports);	//transports-получаем из скрипта					
					
					if (priorityFlag=="fa") {					
						myHTML+=getSearchItem('firms',firms);	//firms-получаем из скрипта	
						myHTML+=getSearchItem('houses',houses);	//houses-получаем из скрипта	
					}else{	
						myHTML+=getSearchItem('houses',houses);	//houses-получаем из скрипта				
						myHTML+=getSearchItem('firms',firms);	//firms-получаем из скрипта								
					};	
					
					if ( (firms.length+houses.length+transports.length)==0 ){
					myHTML+='<li class="spravkakirova"><a href="http://www.spravkakirova.ru/webchat/#end" target="_blank" onclick="return !openPopup(this.href);">Задать вопрос оператору</a><li>';	
						}
					
					myHTML+='</ul></div>';	
					$("#PL_4").html(myHTML);
					
					GKvar.FeaturesSEARCHMARKERS=GKMap.getFeaturesSEARCHMARKERS();					
										
					GKMap.setPositionMap('-73.407295703883','0.11974039009096',1);					
					
					setTimeout(function(){ 
						document.getElementById('PL_4_list').style.height = document.getElementById('PageList_cont').clientHeight-50+'px'; 				
					}, 0);
					
			});
		}, 0);
	};	
};


function GKHouseFirms(IDHouse){	
	var myHTML= '';
		myHTML+='<div>Идет загрузка...</div>';			
		$("#PL_4").html(myHTML);
		ShowSearch();
		
		$("#PageList_main").show();
		document.getElementById('PageList').style.width= "300px";
		//onClickListArrowRight();
	
	setTimeout(function(){
			GKMap.removeFeaturesSEARCHMARKERS();
			
			$.getScript(GKconst.SERVER+GKconst.CGIGETHOUSEFIRMS+"?IDhouse="+encodeURIComponent(IDHouse),function(){
					var myHTML= '<div class="PageListBack">'+
								'Найдено '+(firms.length)+' записей'+	
								'</div>';
					myHTML+='<div id="PL_4_list"><ul class="ListItems">';
					myHTML+=getSearchItem('modules',modules);	//modules-получаем из скрипта
					myHTML+=getSearchItem('firms',firms);	//firms-получаем из скрипта
					myHTML+='</ul></div>';	
					$("#PL_4").html(myHTML);
					
					GKvar.FeaturesSEARCHMARKERS=GKMap.getFeaturesSEARCHMARKERS();										
					
					setTimeout(function(){ 
						document.getElementById('PL_4_list').style.height = document.getElementById('PageList_cont').clientHeight-50+'px'; 				
					}, 0);
					
			});
	}, 0);
	
};


function GKHouseProv(IDHouse){	
	var myHTML= '';
		myHTML+='<div>Идет загрузка...</div>';			
		$("#PL_4").html(myHTML);
		ShowSearch();
		
		$("#PageList_main").show();
		document.getElementById('PageList').style.width= "300px";
		//onClickListArrowRight();
	
	setTimeout(function(){
			GKMap.removeFeaturesSEARCHMARKERS();
			
			$.getScript(GKconst.SERVER+GKconst.PHPGETHOUSEPROV+"?IDhouse="+encodeURIComponent(IDHouse),function(){
					var myHTML= '<div class="PageListBack">'+
								'Найдено '+(firms.length)+' провайдеров'+	
								'</div>';
					myHTML+='<div id="PL_4_list"><ul class="ListItems">';
					myHTML+=getSearchItem('modules',modules);	//modules-получаем из скрипта
					myHTML+=getSearchItem('firms',firms);	//firms-получаем из скрипта
					myHTML+='</ul></div>';	
					$("#PL_4").html(myHTML);
					
					GKvar.FeaturesSEARCHMARKERS=GKMap.getFeaturesSEARCHMARKERS();										
					
					setTimeout(function(){ 
						document.getElementById('PL_4_list').style.height = document.getElementById('PageList_cont').clientHeight-50+'px'; 				
					}, 0);
					
			});
	}, 0);
	
};


function GKHousePhoto(IDHouse){	
	var myHTML= '';
		myHTML+='<div>Идет загрузка...</div>';			
		$("#PL_4").html(myHTML);
		ShowSearch();
		
		$("#PageList_main").show();
		document.getElementById('PageList').style.width= "300px";
		//onClickListArrowRight();
	
	setTimeout(function(){
			GKMap.removeFeaturesSEARCHMARKERS();
			
			$.getScript(GKconst.SERVER+GKconst.PHPGETHOUSEPHOTO+"?IDhouse="+encodeURIComponent(IDHouse),function(){
					GKvar.HousePhotos = housephotos;
				
					var myHTML= '<div class="PageListBack">'+
								'Найдено '+(housephotos.length)+' фотографий'+	
								'</div>';
					myHTML+='<div id="PL_4_list"><ul class="ListItems">';					
					myHTML+=getSearchItem('photos',housephotos);		//housephotos-получаем из скрипта
					myHTML+='</ul></div>';	
					$("#PL_4").html(myHTML);
					
					GKvar.FeaturesSEARCHMARKERS=GKMap.getFeaturesSEARCHMARKERS();										
					
					setTimeout(function(){ 
						document.getElementById('PL_4_list').style.height = document.getElementById('PageList_cont').clientHeight-50+'px'; 				
					}, 0);
					
			});
	}, 0);
	
};

function onClickRubric (IDrubric){
	GKvar.IDRubricNow=IDrubric;	
	GKvar.IDPodRubricNow=0;
	getFloorWords();
};

function onClickPodrubric (IDpodrubric,NameRubric, NamePodrubric){	
	
	GKvar.IDPodRubricNow=IDpodrubric;	
	
	GKMap.removeFeaturesSEARCHMARKERS();
	
	$("#PageList_cont > div").hide();
	
	var myHTML= '<div class="PageListBack" onClick="OnClickBackKatalog();">'+
				'<div class="rub">'+NameRubric+' / <span class="podrub">'+NamePodrubric+'/</span></div>'+	
				'</div>';
	myHTML+='<div>Идет загрузка...</div>';			
	$("#PL_2").html(myHTML).show();
	
	setTimeout(function(){
			
		jQuery.getScript(GKconst.SERVER+GKconst.CGIGETPODRUBRICFIRMS+'?IDpodRubric='+IDpodrubric, function(){
					
			var myHTML= '<div class="PageListBack" onClick="OnClickBackKatalog();">'+
						'<div class="rub">'+NameRubric+' / <span class="podrub">'+NamePodrubric+'/</span></div>'+	
						'</div>';				
			myHTML+='<div id="PL_2_list"><ul class="ListItems">';
			myHTML+=getListItem('modules',modules,NameRubric, NamePodrubric);	//modules-получаем из скрипта
			myHTML+=getListItem('firms',firms,NameRubric, NamePodrubric);	//firms-получаем из скрипта
			myHTML+='</ul></div>';	
			$("#PL_2").html(myHTML);
			
			GKMap.setPositionMap('-73.407295703883','0.11974039009096',1);
			
			setTimeout(function(){ 
				document.getElementById('PL_2_list').style.height = document.getElementById('PageList_cont').clientHeight-50+'px'; 				
			}, 0);
			
		});
		
	}, 0);

};


function OnClickHousePhoto(idphoto,loc_width,loc_height,list_index){
	
	var temp_width=loc_width;
	var temp_height=loc_height;
	
	var keyW=0;
	var keyH=0;	
	if ( ($("#PageMap_Photo").width()-40) < loc_width ) {keyW=1; temp_width =$("#PageMap_Photo").width()-40; temp_height='auto'; };
	if ( ($("#PageMap_Photo").height()-40)< loc_height) {keyH=1; temp_width ='auto'; temp_height=$("#PageMap_Photo").height()-40; };
	
	if ( (keyW==1)&&(keyH==1) ) {
		
		var koefPIC=loc_width/loc_height;
		var koefPageMap=($("#PageMap_Photo").width()-40)/($("#PageMap_Photo").height()-40);
		
		if  (koefPIC>koefPageMap) {temp_width =$("#PageMap_Photo").width()-40; temp_height='auto'; }
		else {temp_width ='auto'; temp_height=$("#PageMap_Photo").height()-40; }		
	
	};
	
	$("#PageMap_Photo_image").html('<img src="http://giskirov.ru/photo/'+idphoto+'.jpg" class="PageMap_HousePhoto" width="'+temp_width+'" height="'+temp_height+'" ALT="Фотография" />');
	$("#PageMap_Photo_image").attr("value",list_index);
	$("#PageMap_Photo").show();
	
		
	setTimeout(function(){		
			document.getElementById('PageMap_Photo_cont').style.marginTop =  Math.round(-($(".PageMap_HousePhoto").height()+30)/2 )+'px';
			document.getElementById('PageMap_Photo_cont').style.marginLeft = Math.round(-($(".PageMap_HousePhoto").width()+30)/2 )+'px';
	}, 0);
	
};


function closeHousePhoto(){
	$('#PageMap_Photo').hide();
};


function OnClickMainRe(IDFirm){

	jQuery.getScript(GKconst.SERVER+GKconst.PHPSTATSMAINREKL+'?id='+encodeURIComponent(IDFirm));
	
};


function LoadMainRe(IDFirm, URl, Pic){
	var myHTML='';	
	if (URl==''){		
		myHTML='<div id="HeaderMainRe" onclick="OnClickMainRe('+IDFirm+'); OnClickSearchItemFirm('+IDFirm+',true);" title="Подробнее"></div>';
	}else {
		myHTML='<a href="http://'+URl+'" target="_Blank" onClick="OnClickMainRe('+IDFirm+');" title="Подробнее"><div id="HeaderMainRe"></div></a>';
	};	
	$("#HeaderBanner").html(myHTML);	
	
	setTimeout(function(){
		$('#HeaderMainRe').css( "background-image", 'url("'+GKS.SERVER+GKS.WEBSERVERMAINRE+Pic+'")' );
	}, 0);
};


function LoadCatalogRe(){
	
	$.getScript(GKconst.SERVER+GKconst.PHPGETCATALOGREKL,function(){
		
		if (KatalogRecl['org_id']>0) {
			var IDFirm =KatalogRecl['org_id'];
			
			var myHTML='';	
			if (KatalogRecl['url']==''){		
				myHTML='<div id="CatalogRe" onclick="OnClickMainRe('+IDFirm+'); OnClickSearchItemFirm('+IDFirm+',true);" title="Подробнее"></div>';
			}else{ 
				myHTML='<a href="http://'+KatalogRecl['url']+'" target="_Blank" onClick="OnClickMainRe('+IDFirm+');" title="Подробнее"><div id="CatalogRe"></div></a>';
			};
			$("#CatalogRe_cont").html(myHTML);	
			
			setTimeout(function(){
				$('#CatalogRe').css( "background-image", 'url("'+GKS.SERVER+GKS.WEBSERVERCATALOGRE+KatalogRecl['pic']+'")' );
			}, 0);	
		};								
	});	
};


function getListItem(TypeLI,locArray,NameRubric, NamePodrubric){
	var myHTML='';
	var SEARCHMARKERS = [];	
		
	switch (TypeLI){
			
		case "firms":	
				for (var i=0;i<locArray.length;i++){
					myHTML+='<li class="Firms"><span class="FirmsName" onClick="OnClickItemPodrubFirm('+locArray[i]['id']+',\''+NameRubric+'\' , \''+NamePodrubric+'\');">'+locArray[i]['fn']+'</span></li>';
					
					for (var j=0;j<locArray[i]['coords'].length;j++)
						SEARCHMARKERS.push( {x:locArray[i]['coords'][j]['x'], y:locArray[i]['coords'][j]['y'], ID:locArray[i]['id'], typeBack:'katalog',nameRub: NameRubric, namePodRub: NamePodrubric } );			
				};
				
				GKMap.addFeaturesSEARCHMARKERS(SEARCHMARKERS);			
				break;
		
		case "modules":			
				for (var i=0;i<locArray.length;i++)
					if (locArray[i]['tr']==2) 
						myHTML+='<li class="Modules"  onClick="OnClickItemPodrubFirm('+locArray[i]['id']+',\''+NameRubric+'\' , \''+NamePodrubric+'\');"><img src="http://188.128.114.221/picture/firms/'+locArray[i]['rp']+'" width="234px" height="60px" /></li>';

				break;	
	};
	

	return myHTML;
};

function OnClickItemPodrubFirm (IDFirm, NameRubric, NamePodrubric){	
	$("#PageList_cont > div").hide();
	
	var myHTML= '<div class="PageListBack" onClick="OnClickBackPodrubFirms();">'+
				'<div class="rub">'+NameRubric+' / <span class="podrub">'+NamePodrubric+'/</span></div>'+	
				'</div>';
	myHTML+='<div>Идет загрузка...</div>';			
	$("#PL_3").html(myHTML).show();
	
	setTimeout(function(){
			
		jQuery.getScript(GKconst.SERVER+GKconst.PHPGETFIRMINFO+'?id='+encodeURIComponent(IDFirm)+'&qw=', function(){
			var SEARCHMARKERS = [];
					
			var myHTML= '<div class="PageListBack" onClick="OnClickBackPodrubFirms();">'+
				'<div class="rub">'+NameRubric+' / <span class="podrub">'+NamePodrubric+'/</span></div>'+	
				'</div>';			
			myHTML+='<div id="PL_3_list"><div id="FirmInfo">'+FirmInfo['html']+'</div></div>';
			$("#PL_3").html(myHTML);
			
			GKMap.setFilterSEARCHMARKERS(IDFirm);
			
			setTimeout(function(){ 				
				document.getElementById('PL_3_list').style.height = document.getElementById('PageList_cont').clientHeight-50+'px';							
			}, 0);
			
		});
		
	}, 0);
	
};

function OnClickSearchItemFirm (IDFirm,ShowOnMap){	
	$("#PageList_cont > div").hide();
	
	var myHTML= '<div class="PageListBack" onClick="OnClickBackResultSearch(false);">'+
				'<div class="rub">Список результатов поиска</div>'+	
				'</div>';
	myHTML+='<div>Идет загрузка...</div>';
				
	$("#PL_3").html(myHTML).show();

	$("#PageList_main").show();
	document.getElementById('PageList').style.width= "300px";
	//onClickListArrowRight();
	
	setTimeout(function(){
			
		jQuery.getScript(GKconst.SERVER+GKconst.PHPGETFIRMINFO+'?id='+encodeURIComponent(IDFirm)+'&qw='+encodeURIComponent(GKvar.QueryWord), function(){
					
			var myHTML= '<div class="PageListBack" onClick="OnClickBackResultSearch('+ShowOnMap+');">'+
				'<div class="rub">Список результатов поиска</div>'+	
				'</div>';				
			myHTML+='<div id="PL_3_list"><div id="FirmInfo">'+FirmInfo['html']+'</div></div>';
			$("#PL_3").html(myHTML);			
			
			if (ShowOnMap==false) GKMap.setFilterSEARCHMARKERS(IDFirm);
			else 
				{
					GKMap.removeFeaturesSEARCHMARKERS();				
					jQuery.getScript(GKconst.SERVER+GKconst.PHPGETFIRMHOUSES+'?IDFirm='+encodeURIComponent(IDFirm), function(){
					
						var SEARCHMARKERS=[];
						for (var i=0;i<FirmHouses.length;i++)
							SEARCHMARKERS.push( {x:FirmHouses[i]['x'], y:FirmHouses[i]['y'], ID:IDFirm, typeBack:'search', nameRub: '', namePodRub: '' } );					
												
						GKMap.addFeaturesSEARCHMARKERS(SEARCHMARKERS);	
					});
								
			};
			
			setTimeout(function(){ 				
					document.getElementById('PL_3_list').style.height = document.getElementById('PageList_cont').clientHeight-50+'px';							
			}, 0);
				
		});
		
	}, 0);	
};

function onClickTrasLine(IDTranLine,type){
	GKMap.addFeaturesTRANSLINE(IDTranLine);	
	GKMap.showLayers('layer2',true);
	if (type!=4) GKMap.setPositionMap('-73.407295703883','0.11974039009096',1)
	else  GKMap.setPositionMap('-73.214434146871','0.079614543228157',2);
	document.getElementById('layer2').checked=true;
};

function autocompItem (row, i, num) {		
	/*return row[0]+"|"+row[1];*/
	return row[0];
};

function autocompResult(row) {
	return row[0];	
};	

function QueryWords_keypress(event){
	event = event || window.event;

	if (event.keyCode==13) onClickSearch();
	
};
/*
function updateCount(event, data, formatted) {	
	$.get(Main_outHost+'/php/updateCount.php?ID='+data[2]);
};*/

function QueryWords_action(){

	$("#QueryWords").autocomplete( GKconst.SERVER+GKconst.PHPGETHELPWORDS,{
			delay: 100,
			autoFill: false,
			minChars: 3,
			cacheLength:20,
			matchSubset:20,
			maxItemsToShow: 20,
			selectFirst:false,			
			formatItem: autocompItem,
			formatResult:autocompResult 
	});
		
	$("#QueryWords").keypress(function(e) {
		QueryWords_keypress(e);	
	});
	/*
	//счетчик нажатий
	$("#query_words").result(updateCount).next().click(function() {
		$(this).prev().search();
	});
	*/
};

function gotoPodrubr_firms(IDrubric,IDPodrubric){
	ShowKatalog();
	
	var NameRubric=''; 
	var NamePodrubric='';
	
	for (var i=0;i<Katalog.length;i++)		
		if (Katalog[i]['id']==IDrubric) {
			
			NameRubric=Katalog[i]['name'];			
			for (var j=0;j<Katalog[i]['podrubric'].length;j++)	
				if (Katalog[i]['podrubric'][j]['id']==IDPodrubric) {
					NamePodrubric=Katalog[i]['podrubric'][j]['name'];
					break;
				};
		};	
	
	onClickPodrubric (IDPodrubric, NameRubric, NamePodrubric);		
};

function onClickTool(NameTool){
	
	$('#PageMap_Control_instrument > div').removeClass('now');  
	
	switch (NameTool){
			
		case "tool_LAPA":	
				$('#PageMap_Control_instrument #Lapa').addClass('now');  
				break;
		
		case "tool_RULE":			
				$('#PageMap_Control_instrument #Rule').addClass('now');  
				break;	
	};	
	
	GKMap.toggleCONTROL(NameTool);
};

function getLinkMap(){
	$('#LinkMap')[0].value=GKMap.getURLPositionMap();
};

function getHtmlforSite(){
	
};


function OnClickFloorWords(rekl_id, firm_id){
	 
	 if (firm_id>0) { OnClickSearchItemFirm(firm_id,true);};
	 
	 //rekl_id	 добавить счетчик рекламы
	
};


function MainLoadContent(){
	
	if (GKMap.ParametersURL.showinfo!=undefined )

		switch (GKMap.ParametersURL.showinfo){

				case "housefirms":						
						if (GKMap.ParametersURL.id>0) GKHouseFirms(GKMap.ParametersURL.id);										
						break;
						
				case "housephoto":						
						if (GKMap.ParametersURL.id>0) GKHousePhoto(GKMap.ParametersURL.id);										
						break;
						
				case "houseprov":						
						if (GKMap.ParametersURL.id>0) GKHouseProv (GKMap.ParametersURL.id);										
						break;
		};
	
};


function getFloorWords(){
/*
	var loc_firms='';
	var loc_catalog='';
	
	if ( ( $('#PL_1').is(':visible')==true )||( $('#PL_2').is(':visible')==true ) ) 
		{ loc_catalog=GKvar.IDRubricNow+','+GKvar.IDPodRubricNow; };
	
	if ( $('#PL_4').is(':visible')==true) { loc_firms=GKvar.IDFirmsNow;};
	
	jQuery.getScript(GKconst.SERVER+GKconst.CGIGETFLOORWORDS+'?firms='+encodeURIComponent(loc_firms)+'&BBOX='+encodeURIComponent(GKMap.getBBOX())+'&catalog='+encodeURIComponent(loc_catalog), function(){
			
		var myHTML= '';
		
		for (var i=0;i<podval.length;i++){		
			if (podval[i]['url']=='') { myHTML+='<div class="reklFloorWords"><div class="FloorWords" ><span onclick="OnClickFloorWords('+podval[i]['id']+','+podval[i]['org_id']+');">'+podval[i]['text']+'</span></div></div>';}			
			else myHTML+='<div class="reklFloorWords"><div class="FloorWords" ><a href="http://'+podval[i]['url']+'" target="_Blank" onclick="OnClickFloorWords('+podval[i]['id']+',0);" title="Узнать подробнее">'+podval[i]['text']+'</a></div></div>';		
		};		
				
		$("#DivFloorWords").html(myHTML);		
			
	});	
	*/
};


/* spravkakirova.webchat */
var window_popup = null;

function openPopup(href, slug) {
	jQuery.getScript(GKconst.SERVER+GKconst.PHPSTATSPRAVKAKIROVA);
	
	if (typeof(slug) == 'undefined') {slug = 'popup';}
	if (window_popup && window_popup.closed != true && typeof(window_popup.close) != 'undefined') { window_popup.close(); }
	window_popup = window.open(href, slug, "width=400,height=580,left=40,top=30,toolbar=0,location=0,directories=0,menubar=0,scrollbars=1,resizable=0,status=0,fullscreen=0");
	if (!window_popup) { return false; }
	window_popup.focus();	
	return true;
}

/* spravkakirova.webchat */

var window_popupHTML = null;

function openHtmlforSite(href, slug) {
	
	
	
	if (typeof(slug) == 'undefined') {slug = 'popup';}
	if (window_popupHTML && window_popupHTML.closed != true && typeof(window_popupHTML.close) != 'undefined') { window_popupHTML.close(); }
	window_popupHTML = window.open(href+GKMap.getPositionMapforHtml(), slug, "toolbar=0,location=0,directories=0,menubar=0,scrollbars=1,resizable=0,status=0,fullscreen=0");
	if (!window_popupHTML) { return false; }
	window_popupHTML.focus();	
	return true;
}

