var gisEditorLoaded=false;function closeGISEditor(){$("#popup_background").fadeOut("fast");$("#gis_editor").fadeOut("fast");$("#gis_editor").html("")}
function prepareJSVersion(){$(".go").hide();$("input[name='gis_data[save]']").attr("value",PMA_messages.strCopy).insertAfter($("#gis_data_textarea")).before("<br><br>");$("#gis_data_editor").prepend('<a class="close_gis_editor">'+PMA_messages.strClose+"</a>");$('<a class="cancel_gis_editor"> '+PMA_messages.strCancel+"</a>").insertAfter($("input[name='gis_data[save]']"));$("div#gis_data_output p").remove();$(".add").each(function(){var b=$(this);b.addClass("addJs").removeClass("add");var a=b.attr("class");
b.after('<a class="'+a+'" name="'+b.attr("name")+'">+ '+b.attr("value")+"</a>").remove()})}function addDataPoint(b,a){return"<br>"+$.sprintf(PMA_messages.strPointN,b+1)+':<label for="x"> '+PMA_messages.strX+' </label><input type="text" name="'+a+"["+b+'][x]" value=""><label for="y"> '+PMA_messages.strY+' </label><input type="text" name="'+a+"["+b+'][y]" value="">'}function initGISEditorVisualization(){selectVisualization();styleOSM();loadSVG();addZoomPanControllers();zoomAndPan()}
function loadJSAndGISEditor(b,a,c,e,d){var f=document.getElementsByTagName("head")[0],g,h=["js/jquery/jquery.svg.js","js/jquery/jquery.sprintf.js","js/jquery/jquery.mousewheel.js","js/jquery/jquery.event.drag-2.0.js","js/tbl_gis_visualization.js"];for(i=0;i<h.length;i++){g=document.createElement("script");g.type="text/javascript";g.src=h[i];f.appendChild(g)}g=document.createElement("script");g.type="text/javascript";g.onreadystatechange=function(){this.readyState=="complete"&&loadGISEditor(b,a,c,
e,d)};g.onload=function(){loadGISEditor(b,a,c,e,d)};g.src="js/openlayers/OpenLayers.js";f.appendChild(g);gisEditorLoaded=true}function loadGISEditor(b,a,c,e,d){var f=$("#gis_editor");$.post("gis_data_editor.php",{field:a,value:b,type:c,input_name:e,get_gis_editor:true,token:d},function(g){if(g.success==true){f.html(g.gis_editor);initGISEditorVisualization();prepareJSVersion()}else PMA_ajaxShowMessage(g.error,false)},"json")}
function openGISEditor(){var b=document.documentElement.clientWidth,a=document.documentElement.clientHeight,c=b*0.9,e=a*0.9;a=a/2-e/2;b=b/2-c/2;var d=$("#gis_editor"),f=$("#popup_background");d.css({top:a,left:b,width:c,height:e});f.css({opacity:"0.7"});d.append('<div id="gis_data_editor"><img class="ajaxIcon" id="loadingMonitorIcon" src="'+pmaThemeImage+'ajax_clock_small.gif" alt=""></div>');f.fadeIn("fast");d.fadeIn("fast")}
function insertDataAndClose(){var b=$("form#gis_data_editor_form"),a=b.find("input[name='input_name']").val();$.post("gis_data_editor.php",b.serialize()+"&generate=true",function(c){c.success==true?$("input[name='"+a+"']").val(c.result):PMA_ajaxShowMessage(c.error,false)},"json");closeGISEditor()}
$(document).ready(function(){$(".open_gis_editor a").removeClass("formLinkSubmit");$("input[name='gis_data[save]']").live("click",function(b){b.preventDefault();insertDataAndClose()});$("#gis_editor").live("submit",function(b){b.preventDefault();insertDataAndClose()});$("#gis_editor").find("input[type='text']").live("change",function(){var b=$("form#gis_data_editor_form");$.post("gis_data_editor.php",b.serialize()+"&generate=true",function(a){if(a.success==true){$("#gis_data_textarea").val(a.result);
$("#placeholder").empty().removeClass("hasSVG").html(a.visualization);$("#openlayersmap").empty();eval(a.openLayers);initGISEditorVisualization()}else PMA_ajaxShowMessage(a.error,false)},"json")});$(".gis_type").live("change",function(){var b=$("#gis_editor"),a=$("form#gis_data_editor_form");$.post("gis_data_editor.php",a.serialize()+"&get_gis_editor=true",function(c){if(c.success==true){b.html(c.gis_editor);initGISEditorVisualization();prepareJSVersion()}else PMA_ajaxShowMessage(c.error,false)},
"json")});$(".close_gis_editor, .cancel_gis_editor").live("click",function(){closeGISEditor()});$(".addJs.addPoint").live("click",function(){var b=$(this),a=b.attr("name"),c=a.substr(0,a.length-11);a=$("input[name='"+c+"[no_of_points]']");var e=parseInt(a.attr("value"));c=addDataPoint(e,c);b.before(c);a.attr("value",e+1)});$(".addLine.addJs").live("click",function(){var b=$(this),a=b.attr("name");a=a.substr(0,a.length-10);var c=a.slice(a.lastIndexOf("[")+1,a.lastIndexOf("]")),e=$("input[name='"+a+
"[no_of_lines]']"),d=parseInt(e.attr("value")),f="<br>";if(c=="MULTILINESTRING"){f+=PMA_messages.strLineString+(d+1)+":";c=2}else{f+=PMA_messages.strInnerRing+d+":";c=4}f+='<input type="hidden" name="'+a+"["+d+'][no_of_points]" value="'+c+'">';for(i=0;i<c;i++)f+=addDataPoint(i,a+"["+d+"]");f+='<a class="addPoint addJs" name="'+a+"["+d+'][add_point]">+ '+PMA_messages.strAddPoint+"</a><br>";b.before(f);e.attr("value",d+1)});$(".addJs.addPolygon").live("click",function(){var b=$(this),a=b.attr("name");
a=a.substr(0,a.length-13);var c=$("input[name='"+a+"[no_of_polygons]']"),e=parseInt(c.attr("value")),d=PMA_messages.strPolygon+(e+1)+":<br>";d+='<input type="hidden" name="'+a+"["+e+'][no_of_lines]" value="1">';for(i=0;i<4;i++)d+=addDataPoint(i,a+"["+e+"][0]");d+='<a class="addPoint addJs" name="'+a+"["+e+'][0][add_point]">+ '+PMA_messages.strAddPoint+'</a><br><a class="addLine addJs" name="'+a+"["+e+'][add_line]">+ '+PMA_messages.strAddInnerRing+"</a><br><br>";b.before(d);c.attr("value",e+1)});$(".addJs.addGeom").live("click",
function(){var b=$(this),a=$("input[name='gis_data[GEOMETRYCOLLECTION][geom_count]']"),c=parseInt(a.attr("value")),e=PMA_messages.strGeometry+(c+1)+":<br>",d=$("select[name='gis_data["+(c-1)+"][gis_type]']").clone();d.attr("name","gis_data["+c+"][gis_type]").val("POINT");var f="<br>"+PMA_messages.strPoint+' :<label for="x"> '+PMA_messages.strX+' </label><input type="text" name="gis_data['+c+'][POINT][x]" value=""><label for="y"> '+PMA_messages.strY+' </label><input type="text" name="gis_data['+c+
'][POINT][y]" value=""><br><br>';b.before(e);d.insertBefore(b);b.before(f);a.attr("value",c+1)})});
