function GmlReports(map,light){this.map=map;if(this.map.getProjection()=="EPSG:900913"){this.layer=new OpenLayers.Layer.GML("gml","/map_edit/show_file.php?id=36186&type=gml",{projection:new OpenLayers.Projection("EPSG:4326")});}
else
this.layer=new OpenLayers.Layer.GML("gml");this.layer.preFeatureInsert=function(feature){if(!feature.style)
feature.style={strokeWidth:4,strokeColor:"#0bcf00",strokeOpacity:1.0,pointRadius:6,fillColor:"transparent",fillOpacity:0.3};if(!light)
if(feature.geometry.CLASS_NAME.indexOf('Point')>-1){feature.style.strokeColor="red";feature.style.pointRadius=6;return;}
var status=feature.attributes['status'];if(!light)
if(status=='ERROR'){feature.style.strokeColor="red";}else if(status=='WARNING'){feature.style.strokeColor="yellow";}}
this.selector=new OpenLayers.Control.SelectFeature(this.layer,{onSelect:function(feature){objRef.onSelect(objRef,feature);},selectStyle:{fillColor:"blue",fillOpacity:0.4,hoverFillColor:"white",hoverFillOpacity:0.8,strokeColor:"blue",strokeOpacity:1,strokeWidth:5,hoverStrokeColor:"red",hoverStrokeOpacity:1,hoverStrokeWidth:0.2,pointRadius:8,pointerEvents:"visiblePainted",cursor:"pointer"}});this.map.addControl(this.selector);this.selector.deactivate();this.map.addLayer(this.layer);this.pointStyle=new Object();this.pointStyle.externalGraphic='/images/marker_red.png';this.pointStyle.pointRadius=30;this.selectedPointStyle=new Object();this.selectedPointStyle.externalGraphic='/images/marker_red.png';this.selectedPointStyle.pointRadius=36;this.selectedPointStyle.fillOpacity=0.6;var objRef=this;this.createSuccess=function(responseText){var jsonReply=eval("("+responseText+")");if(!jsonReply.reply.error){$('#create_status').text('Road created successfully!');g_cartouche.refreshView();}else{$('#create_status').text('Error: '+jsonReply.reply.message);}}
this.createError=function(){$('#create_status').text('Error: request cannot be sent to server');}
this.createSegment=function(objRef,id){var params="report_id="+objRef.report_id+"&segment_id="+id;$('#create_status').text('Please wait...');$.ajax({type:'POST',url:'/map_edit/reports_create_seg.php',data:params,success:objRef.createSuccess.bind(objRef),error:objRef.createError.bind(objRef)});}
this.onSelect=function(objRef,feature){var isSegment=false;if(feature.geometry.CLASS_NAME.indexOf('LineString')>-1)
isSegment=true;var lonlat=this.map.lastMouseLonlat;var measurement_system=$(".measurement_system").text();var info="<p style='padding:5px;'><b>";if(feature.attributes['name'])
info+="Street: "+feature.attributes['name'];if(feature.attributes['start_time'])
info+="<br>Start time: "+feature.attributes['start_time'];if(feature.attributes['end_time'])
info+="<br>End time: "+feature.attributes['end_time'];if(feature.attributes['length']){if(measurement_system=="metric")
info+="<br>Length: "+feature.attributes['length']+" m";else
info+="<br>Length: "+Math.round(feature.attributes['length']/0.3048)+" feet";}
if(feature.attributes['speed'])
{if(measurement_system=="metric")
info+="<br>Speed: "+feature.attributes['speed']+" "+$("."+measurement_system+"_speed").text();else
info+="<br>Speed: "+Math.round(feature.attributes['speed']/1.609)+" "+$("."+measurement_system+"_speed").text();}
if(feature.attributes['info'])
info+="<br>type: "+feature.attributes['info'];if(feature.attributes['description'])
info+="<br>Info: "+feature.attributes['description'];if(isSegment)
info+="<br><span id=\"create_status\"><a style=\"color:#4169E1;display:block;margin:4px 0;text-decoration:none;\" onmouseover=\"this.style.color='#4197E1'\"  onmouseout=\"this.style.color='#4169E1'\" id=\"reportCreateSeg\" href=\"#\">Create new road from this segment</a></span>";info+="</b></p><br/>";var popup=new OpenLayers.Popup.FramedCloud(null,lonlat,null,info,null,true);popup.setBackgroundColor("#c9d7ec");popup.setOpacity(0.95);feature.layer.map.addPopup(popup,true);if(isSegment){$("#reportCreateSeg").click(function(){objRef.createSegment(objRef,feature.attributes['id']);return false;});}}
this.showReport=function(id,name,bbox){var report_url;this.report_id=id;if(id==0)
report_url="/test_gml.xml";else
report_url="/map_edit/show_file.php?id="+id+"&type=gml";if(bbox){var bounds=new OpenLayers.Bounds(bbox.left,bbox.bottom,bbox.right,bbox.top);if(this.map.getProjection()=="EPSG:900913")
bounds.transform(new OpenLayers.Projection("EPSG:4326"),this.map.getProjectionObject());this.map.zoomToExtent(bounds);}
this.layer.setUrl(report_url);}}