var mapopen=false;
var lat=0;
var lng=0;
var idtomapc = new Array();
var idtomap = new Object();
var mapst = new Object();
var itssearch = false;

function addtonotepad(id, ticket_id, page)
{
	$.ajax({
   		type: 'GET',
   		url: 'http://'+ document.domain + '/json',
		cache: false,
		dataType: 'json',
   		data: 'act=addnotepad&id=' + id + '&ticket_id=' + ticket_id + '&page=' + page,
		error: function(msg){
				alert('Ошибка добавления в избранное');
		},
   		success: function(msg){
			if (msg.result.status==200) { 
						$('#ctrlbar').html("<input type=button value=\"добавлен\">");
					}
			if (msg.result.status==500) {
						$('#ctrlbar').html("<input type=button value=\"Уже добавлено\">");
					}	
				$('#favor').html("<a href='/favorites/'> <img border='0' name='Image1' src='/i/butfvr.gif'></a>");	
        			}
 		});
}

function rmfromnotepad(id, ticket_id, page)
{
	$.ajax({
   		type: 'GET',
   		url: 'http://'+ document.domain + '/json',
		cache: false,
		dataType: 'json',
   		data: 'act=rmfromnotepad&id=' + id + '&ticket_id=' + ticket_id,
		error: function(msg){
				alert('Ошибка добавления в избранное');
		},
   		success: function(msg){
			if (msg.result.status==200) { 
						$('#tr_'+id).remove();
					} else {
						$('#ctrlbar').html("Ошибка удаления");
					}	
        			}
 		});
}
function countChecked() {
					var result='';
					var element = $("input:checked");
					for (i=0; i<$("input:checked").length; i++){
						var k = element[i].value;
						result+='x'+k;
						}
	      				return result;	
 }
function StaticMapEnable(lat,lng,id){

			      				if (GBrowserIsCompatible()) {
			        					mapst[id] = new GMap2(document.getElementById('map_canvas_static_id'+id));
									mapst[id].test = id;
			        					mapst[id].setCenter(new GLatLng(lat,lng), 16);
									mapst[id].disableDragging();
									mapst[id].disableDoubleClickZoom();
									mapst[id].disableScrollWheelZoom();	
									function createMarker(point) {
			      							var marker = new GMarker(point);
			      					        	return marker;
			    						}
			 
			
										mapst[id].addOverlay(createMarker(new GLatLng(lat,lng)));
			   					}
}
function OpenMap(){

		if(itssearch==true && mapopen==true) { 
				$('#map_canvas').show();
				$('#map_control').show();
		} else {
				$('#map_canvas').slideToggle('slow');
				$('#map_control').slideToggle('slow');
				if (mapopen!=true) {mapopen=true;} else {mapopen=false;}
				}
			if ($("input:checked").length>0) {UpdateMap(countChecked());} else {ShowMap();}

		d.getElementById('ctrlbar').style.visibility='hidden';
}
$(document).ready(function(){
				for (i=0; i< idtomapc.length; i++) {
/*					$('#map_canvas_static_id'+idtomap.id).each(function(){*/
					StaticMapEnable(idtomap[idtomapc[i]].lat,idtomap[idtomapc[i]].lng,idtomap[idtomapc[i]].id);  
				/*	});*/
				}
    			/*	$('.spoiler').hide();
			
 				$('#button').button(); */
    				$('#button').click(function(){
        							$('.spoiler').slideToggle('slow');
						/*		if ($('#button').text()!='Скрыть фильтр'){
									$('#button').text('Скрыть фильтр');
								} else {
									$('#button').text('Фильтровать');
									}; */
							    }
						 );
				$('#map_canvas').hide();
				$('#map_control').hide();
 			/*	$('#button_map').button(); */
    				$('#button_map, #button_map_close').click(function(){
								OpenMap();
								return false;
							    }
						 );
				$(":checkbox").change(function(){
								if (mapopen==true) UpdateMap(countChecked());
							});
				$('#alertctrl_canvas').hide();
 			/*	$('#button_alertctrl').button(); */
    				$('#button_alertctrl, #button_alertctrl_close').click(function(){
								$('#alertctrl_canvas').slideToggle('slow');
								return false;
							    }
							);
				if (mapopen==true) { OpenMap();}
			
			    
			
			   }
		)
    			    
		   
			

