var arrObjectsM=[];
var map_flag=0;var d=document;var ScreenW=0;var ScreenH=0;var MouseX=0;var MouseY=0;var hidden_load=1;var zoom=10;var mapDirect=0;var closeWindow=1;function setCookie(name,value,expires,path,domain,secure){var curCookie=name+"="+escape(value)+
((expires)?"; expires="+expires.toGMTString():"")+
((path)?"; path="+path:"")+
((domain)?"; domain="+domain:"")+
((secure)?"; secure":"")
document.cookie=curCookie}
function getCookie(name){var prefix=name+"="
var cookieStartIndex=document.cookie.indexOf(prefix)
if(cookieStartIndex==-1)
return null
var cookieEndIndex=document.cookie.indexOf(";",cookieStartIndex+prefix.length)
if(cookieEndIndex==-1)
cookieEndIndex=document.cookie.length
return unescape(document.cookie.substring(cookieStartIndex+prefix.length,cookieEndIndex))}
function ViewOrHide(id)
{if(document.getElementById(id).style.display=='none'){document.getElementById(id).style.display='';}else{document.getElementById(id).style.display='none';}}
function View(id)
{document.getElementById(id).style.display='';}
function Hide(id)
{document.getElementById(id).style.display='none';}
function closeother(partname,obj){var opened=document.getElementsByTagName('div');for(i=0;i<opened.length;i++){if(opened[i].id.indexOf(partname)>-1){if(opened[i].id!=obj){Hide(opened[i].id);ge(opened[i].id).innerHTML="";}}}}
function make_checkedall(partname){el=document.getElementsByTagName('input');for(i=0;i<el.length;i++){if(el[i].id.indexOf(partname)>-1){el[i].checked=true;}}}
function make_uncheckedall(partname){el=document.getElementsByTagName('input');for(i=0;i<el.length;i++){if(el[i].id.indexOf(partname)>-1){el[i].checked=false;}}}
function make_active_list(){el=document.getElementsByTagName('input');found=0;for(i=0;i<el.length;i++){if(el[i].id.indexOf("makeactive")>-1){if(el[i].checked==true){found=1;doLoad('activ'+el[i].value,'newperiod',{id:el[i].value});doLoad('activ'+el[i].value,'changeActive',{id:el[i].value,make:1,reload:1});}}}
if(found==0){alert("Не выбрано ни одного объекта!!!");}
return false;}
function AreasGo(flag_city,x,y)
{var point=new GLatLng(x,y);if(flag_city==1)
var z=10;else if(flag_city==2)
var z=8;else
var z=7;map.setCenter(point,z);zoom_change(z,0)}
function GoToPage(p,st_vkl)
{switch(st_vkl)
{case-1:d.forms['allFrm'].page.value=p;doLoad('content','newout',ge('allFrm'));break;case 0:d.forms['saleFrm'].page.value=p;doLoad('content','newout',ge('saleFrm'));break;case 1:d.forms['rentFrm'].page.value=p;doLoad('content','newout',ge('rentFrm'));break;case 2:d.forms['soldFrm'].page.value=p;doLoad('content','newout',ge('soldFrm'));break;case 3:d.forms['mmmFrm'].page.value=p;doLoad('content','newout',ge('mmmFrm'));break;case 5:d.forms['opoFrm'].page.value=p;doLoad('content','newout',ge('opoFrm'));break;case 6:d.forms['hlhFrm'].page.value=p;doLoad('content','newout',ge('hlhFrm'));case 7:d.forms['myoFrm'].page.value=p;doLoad('content','newout',ge('myoFrm'));break;}}
function new_window(alias)
{window.open('/window.php?alias='+alias,'Text','toolbar=0,location=0,directories=0,menuBar=0,resizable=0,scrollbars=yes,width=700,height=550,left=32,top=16');}
function city_window(frm)
{if(frm)
my_frm=frm;else
my_frm='regfrm';window.open('/city_change.php?my_frm='+my_frm,'Text','toolbar=0,location=0,directories=0,menuBar=0,resizable=0,scrollbars=yes,width=800,height=550,left=32,top=16');}
function url_window(url,w,h)
{window.open(url,'Text','toolbar=0,location=0,directories=0,menuBar=0,resizable=0,scrollbars=yes,width='+w+',height='+h+',left=32,top=16');}
function HW2(cx,cy)
{size_screen();var v=ScreenW-502;if(v<500)
v=500;var h2x=200
var h2y=parseInt(v/2);}
function HW()
{if(ge('smartcloseblock')){if(ge('switch_block')){ge('switch_block').src='/d/img/vkladka/closeblock_btn.gif';}
size_screen();if(ScreenW>=1200)
{ge('reklama').style.display='block';}
else
{ge('reklama').style.display='none';}
main_img();}}
function resize_map(){}
function switch_right_block2()
{if(ge('adv_1').innerHTML==''){r_cont=ge("adv_2").innerHTML;ge("adv_2").innerHTML="";ge("adv_1").innerHTML=r_cont;ge('center').style.width='100%';ge('switch_block').src='/d/img/vkladka/closeblock_btn.gif';}else{r_cont=ge("adv_1").innerHTML;ge("adv_1").innerHTML="";ge("adv_2").innerHTML=r_cont;ge('center').style.width='100%';ge('switch_block').src='/d/img/vkladka/closeblock_btn2.gif';}
ge('base_table').style.width='100%';}
function switch_right_block()
{limit='72%';var nav=navigator.appName;if((nav!="Netscape")&&(nav!="Opera"))
{if((ge('center').style.styleFloat=='left')&&(ge('center').style.width==limit)&&(ge('proba').style.bottom=='372px')&&(ge('baner').style.height=='3px'))
{ge('center').style.styleFloat='none';ge('center').style.width='100%';ge('proba').style.bottom='0px';ge('baner').style.height='5px';ge('switch_block').src='/d/img/vkladka/closeblock_btn2.gif';}
else
{ge('center').style.styleFloat='left';ge('center').style.width=limit;ge('proba').style.bottom='372px';ge('baner').style.height='3px';ge('switch_block').src='/d/img/vkladka/closeblock_btn.gif';}}
else
{if((ge('center').style.cssFloat=='left')&&(ge('center').style.width==limit)&&(ge('proba').style.bottom=='372px')&&(ge('baner').style.height=='3px'))
{ge('center').style.cssFloat='none';ge('center').style.width='100%';ge('proba').style.bottom='0px';ge('baner').style.height='5px';ge('switch_block').src='/d/img/vkladka/closeblock_btn2.gif';}
else
{ge('center').style.cssFloat='left';ge('center').style.width=limit;ge('proba').style.bottom='372px';ge('baner').style.height='3px';ge('switch_block').src='/d/img/vkladka/closeblock_btn.gif';}}}
d.onmousedown=function(event){if(!event){event=window.event;}
MouseX=event.clientX+d.body.scrollLeft;MouseY=event.clientY+d.body.scrollTop;}
function save_button_c(value,id)
{if(value==1)
elementInner(id,"<a class=\"button_link\" href=\"javascript://\"  onclick=\"saveImages(\'regfrm\'); d.forms[\'regfrm\'].submit();return false;\"><img src=\"/d/img/save_button.gif\" width=\"90\" height=\"34\" alt=\"Сохранить\"></a>");else
elementInner(id,"<img src=\"/d/img/save_button_2.gif\" width=\"90\" height=\"34\" alt=\"Не активна\">");}
function ResetForm(f){var v;for(var n=0;n<f.elements.length;n++)
{e_t=f.elements[n].type;e_id=f.elements[n].id;switch(e_t)
{case"text":if(ge(e_id))
{ge(e_id).value="";}
break;case"textarea":if(ge(e_id))
ge(e_id).innerHTML="";break;case"checkbox":if(ge(e_id))
ge(e_id).checked=false;break;case"select-one":if(ge(e_id))
ge(e_id).options[0].selected=true
break;}}}
function set_sort(direction,perem,period)
{sort_direction=direction;sort_var=perem;if(status_vkladka==0)
doLoad('content','newout',ge('saleFrm'));if(status_vkladka==1)
doLoad('content','newout',ge('rentFrm'));if(status_vkladka==2)
doLoad('content','newout',ge('soldFrm'));if(status_vkladka==3)
doLoad('content','newout',ge('mmmFrm'));if(status_vkladka==6)
doLoad('content','newout',ge('hlhFrm'));if(status_vkladka==5)
doLoad('content','newout',ge('opoFrm'));if(status_vkladka==-1)
doLoad('content','newout',ge('allFrm'))}
function pos_nav(){}
function tabs_change(new_tab)
{document.images['tab_'+tab_active+'_left'].src='/d/img/corners/left_n.png';document.images['tab_'+tab_active+'_right'].src='/d/img/corners/right_n.png';block_none('tab_'+tab_active+'_info');ge('tab_'+tab_active+'_center').className='tab_bg';ge('tab_'+tab_active+'_link').className='tab_link';tab_active=new_tab;document.images['tab_'+tab_active+'_left'].src='/d/img/corners/left.png';document.images['tab_'+tab_active+'_right'].src='/d/img/corners/right.png';ge('tab_'+tab_active+'_center').className='tab_bg_a';ge('tab_'+tab_active+'_link').className='tab_link_a';block_yes('tab_'+tab_active+'_info');}
function zoom_change(new_zoom,flag_z)

{
if(new_zoom>17)new_zoom=17;
if(new_zoom!=last_zoom)
{for(i=0;i<=new_zoom;i++)
{

document.images['map_zoom'+i].src='/d/img/map/plash_active.png';}
for(i=new_zoom+1;i<=17;i++)
{document.images['map_zoom'+i].src='/d/img/map/plash.png';}
last_zoom=new_zoom;}
zoom=new_zoom;if(map_flag==1)
{if(!flag_z)
{if(firstRun==0)
{changePK(0);bounds1=map.getBounds();GetMapBounds(bounds1,'zoom1');switch(status_vkladka)
{case-1:d.forms['allFrm'].page.value=1;doLoad('content','newout',ge('allFrm'));break;case 0:d.forms['saleFrm'].page.value=1;doLoad('content','newout',ge('saleFrm'));break;case 1:d.forms['rentFrm'].page.value=1;doLoad('content','newout',ge('rentFrm'));break;case 2:d.forms['soldFrm'].page.value=1;doLoad('content','newout',ge('soldFrm'));break;case 3:d.forms['mmmFrm'].page.value=1;doLoad('content','newout',ge('mmmFrm'));break;case 5:d.forms['opoFrm'].page.value=1;doLoad('content','newout',ge('opoFrm'));break;case 6:d.forms['hlhFrm'].page.value=1;doLoad('content','newout',ge('hlhFrm'));break;}}}}}
function main_img()
{if(ge('imgBox'))
ge('imgBox').style.left=parseInt(ScreenW/2)-240;}
function size_screen()
{var nav=navigator.appName;if((nav!="Netscape")&&(nav!="Opera"))
{ScreenW=d.body.clientWidth;ScreenH=d.body.clientHeight;}
else
{ScreenW=window.innerWidth;ScreenH=window.innerHeight;}}
function VkladkaA(id)
{var nn=new Array();nn=my_filter_a[id];var my_flag=0;if(nn)
for(i=0;i<nn.length;i++)
{if(ge('opt_id'+nn[i]+'[do]'))
{if(ge('opt_id'+nn[i]+'[do]').value)
my_flag=1;}
if(ge('opt_id'+nn[i]))
{if(ge('opt_id'+nn[i]).value)
my_flag=1;}}
return my_flag;}
function ChangeClass(id,flag)
{if(flag==1)
ge(id).className='FilterVklTY';else
ge(id).className='FilterVklT';}
function Stage()
{if((ge('last_floor').checked)||(ge('first_floor').checked)||(ge('opt_id59[do]').value)||(ge('opt_id59[ot]').value))
{ge('kkk5').className='FilterVklTY';}
else
{ge('kkk5').className='FilterVklT';}}
function loadImg(id,id_img,title)
{size_screen();window.scroll(0,0);ge(id).style.left=parseInt(ScreenW/2)-parseInt(ImgList[id_img]['x']/2);ge(id).style.width=parseInt(ImgList[id_img]['x'])+60;ge(id).style.height=parseInt(ImgList[id_img]['y'])+30;block_yes(id);if(id_img!=0)
{var prev=parseInt(id_img)-1;elementInner(id+'Left','&nbsp;<a href=javascript:// onclick=loadImg(\''+id+'\','+prev+','+ImgList[prev][title]+')><img src=/d/img/imglist/prev.png width=15 height=14 class=png></a>&nbsp;&nbsp;');}
else
elementInner(id+'Left','&nbsp;&nbsp;');if(id_img!=ImgList.length-1&&ImgList.length>1)
{var next=parseInt(id_img)+1;elementInner(id+'Right','&nbsp;<a href=javascript:// onclick=loadImg(\''+id+'\','+next+','+ImgList[next][title]+')><img src=/d/img/imglist/next.png width=15 height=14 class=png></a>&nbsp;&nbsp;');}
else
{elementInner(id+'Right','&nbsp;&nbsp;');next=0;}
if(!title)
title="&nbsp;";elementInner(id+'Center','<font style="font-weight:bold;">'+ImgList[id_img]['title']+'</font><div style="padding-top: 3px; margin:0px;"><a href=javascript:// onclick=loadImg(\''+id+'\','+next+','+ImgList[next][title]+')><img id=img'+id_img+' name=img'+id_img+' src=/content/Image/module_img/c/'+ImgList[id_img]['src']+' width='+ImgList[id_img]['x']+'  height='+ImgList[id_img]['y']+'></a></div>');}
function setValue(id,min,max,vkladka)
{ge('opt_id'+id+'[ot]').value=min;ge('opt_id'+id+'[do]').value=max;if(max==''){var flag=0;flag=VkladkaA(vkladka);if(flag==0)
ChangeClass('kkk'+vkladka,0);}
else
ChangeClass('kkk'+vkladka,1);}
function setCheckboxes(the_form,the_checkboxes,do_check)
{var elts=(the_checkboxes!='')?document.forms[the_form].elements[the_checkboxes+'[]']:document.forms[the_form].elements;var elts_cnt=(typeof(elts.length)!='undefined')?elts.length:0;if(elts_cnt){for(var i=0;i<elts_cnt;i++){elts[i].checked=do_check;}}else{elts.checked=do_check;}
return true;}
function changePK(val)
{pKey=val;}
function ge(p1){return d.getElementById(p1);}
function block_none(id)
{if(d.getElementById(id))
d.getElementById(id).style.display='none';}
function block_yes(id)
{if(d.getElementById(id))
d.getElementById(id).style.display='block';}
function block_invert(id)
{if(d.getElementById(id))
{if(d.getElementById(id).style.display=='block')
d.getElementById(id).style.display='none';else
d.getElementById(id).style.display='block';}}
function block_invert2(id,id2){
	
	if(d.getElementById(id)){		
		if(d.getElementById(id).style.display=='block'){
				
			d.getElementById(id).style.display='none';
			d.images[id2].src='/d/img/vkladka/arrow_top.png';
		}
		else{
			d.getElementById(id).style.display='block';
			d.images[id2].src='/d/img/vkladka/arrow_down.png';
		}
	}
}
function smart_turnblock(){}
function change_vkladka(id,status){
	$('#data_all').hide();
	$('#data_mmm').hide();
	$('#data_rent').hide();
	$('#data_sold').hide();
	$('#data_sale').hide();
	$('#data_hlh').hide();
	$('#data_opo').hide();
	$('#data_Popular').hide();	
	$('#'+id).show();
	$('td.vklLeftY').removeClass('vklLeftY').addClass('vklLeft');
	$('td.vklRightY').removeClass('vklRightY').addClass('vklRight');
	$('td.vklBgY').removeClass('vklBgY').addClass('vklBg');
	$('#'+id+'_vkt td.vklLeft').removeClass('vklLeft').addClass('vklLeftY');
	$('#'+id+'_vkt td.vklRight').removeClass('vklRight').addClass('vklRightY');
	$('#'+id+'_vkt td.vklBg').removeClass('vklBg').addClass('vklBgY');
}

function carousel_thickbox(tovar_id){
	jQuery('#mycarousel'+tovar_id).jcarousel({scroll: 1,  animation: 'fast'});
	$("a.thickbox").fancybox({
		'overlayShow'	: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	
	$("a[rel=gallery"+tovar_id+"]").fancybox({
		'overlayShow'	: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			
			var alias=$('#img_'+tovar_id+'_'+currentIndex).attr('mya')+'.'+$('#img_'+tovar_id+'_'+currentIndex).attr('myt');			
			//return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '<a href="/content/Image/module_img/'+alias+'" style="float:right;width:16px;display:block" target=_blank><img src=/d/img/view-fullscreen.png width=16 height=16 title="Открыть оригинал" alt="Открыть оригинал"/></a></span>';
			return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '');
		}
	});
}

function MapRemoveMarker(){
	for(var i in arrObjectsM) {		
		map.removeOverlay(arrObjectsM[i]);
	}
	arrObjectsM=[];
}
function ShowInfoObjects(city_id){
	setTimeout(function (){
		
	var info_type = new Array();
	all_chk=$('input.info_type:checked');   	
    for(i=0;i<all_chk.length;i++)  info_type[i]=$(all_chk[i]).val();
    bounds1=map.getBounds();
	GetMapBounds(bounds1,'grag');
    doLoad('','newout_objects',{'city_id':city_id,'mapXY':mapXY,'info_type':info_type});
  },100);
}

function ShowInfoObjectsToMap(mas){
	MapRemoveMarker();	
	var myIcon = new Array();	
	for(value in mas.types){
		var t =mas.types[value];
		myIcon[t]=new GIcon(G_DEFAULT_ICON);
		myIcon[t].iconSize = new GSize(23, 29);
		myIcon[t].shadow='';  
    	myIcon[t].image = "/d/img/marker/info"+t+".png";	
	}	
	for(value in mas.bindings){
		
		b=mas.bindings[value];	
		var latlng = new GLatLng(b.x,b.y);		
		markerOptions = {icon:myIcon[b.info_type_id],draggable:true};
		arrObjectsM[value]=new GMarker(latlng,markerOptions);		
		map.addOverlay(arrObjectsM[value]);
		ShowInfoObjectsToMapInfo(arrObjectsM[value],b);		
	}	
	
}

function ShowInfoObjectsToMapInfo(point,info){
	GEvent.addListener(point,"click",function() {
		change_ok=0;	
		html='<div style="text-align:left"><span style="font-size: 14px; color: rgb(6, 121, 174); font-weight: bold;">'+info.title+'</span><br /><b>Адрес:</b> '+info.street+'<br /><b>Телефон:</b> '+info.phone+'<br />'+info.descr+'</div>';
	    map.savePosition();
	    point.openInfoWindowHtml(html);	   
	     
	});
	GEvent.addListener(point,"infowindowbeforeclose",function()  {       
       map.returnToSavedPosition();   
       change_ok=1;         
    });
}

function GetMapBounds(bounds1,vvv){           
    var p1=bounds1.getSouthWest();
    var p2=bounds1.getNorthEast();          
    mapXY[0]=p1.lat();
    mapXY[1]=p2.lat();
    mapXY[2]=p1.lng();
    mapXY[3]=p2.lng();                            
}
