function mv_declareClassQueryBuilder(){dojo.declare("MV.QueryBuilder",null,{AktText:"",AktValue:"",AktOperator:"",AktWert:"",FeldWrite:!0,WertWrite:!0,ExcelWrite:!0,OperatorWrite:!0,Doc:null,txtHelp:"",Window:null,BGColor:"white",themaId:"",constructor:function(a){this.txtHelp=a;null!=document.MVqueryLayer&&(document.MVqueryLayer.MVlistQueryLayer.selectedIndex=0)},clear:function(a){this.changeField("f-1");this.AktWert=this.AktOperator=this.AktValue=this.AktText="";this.Doc.MVquery.SQLEingabe.value=
"";this.Doc.MVquery.TextEingabe.value=""},layerSelect:function(a){if(""==a||this.themaId==a)return!0;this.Doc.getElementById("MVqueryFields").innerHTML="";this.Doc.getElementById("MVqueryValues").innerHTML="";this.themaId=a;this.clear();if(mv_Map.Layers.item(a).XMLAccess){var b=a+"queryfields";null==mv_XMLFileArray[b]&&(mv_XMLFileArray[b]=mv_loadXMLDoc(mv_Doc.BaseURL+"embfiles/"+a+"queryfields.html","text"));this.Doc.getElementById("MVqueryFields").innerHTML=mv_XMLFileArray[b];b=a+"queryvalues";null==
mv_XMLFileArray[b]&&(mv_XMLFileArray[b]=mv_loadXMLDoc(mv_Doc.BaseURL+"embfiles/"+a+"queryvalues.html","text"));this.Doc.getElementById("MVqueryValues").innerHTML=mv_XMLFileArray[b]}else mv_loadQueryDB(a)},help:function(){mv_alert(this.txtHelp)},sqlField:function(a){a=a.options[a.selectedIndex].value;this.changeField(a);var b=this.Doc.MVquery.fields.options[this.Doc.MVquery.fields.selectedIndex].text;1==this.FeldWrite?(this.sqlString(a,b),this.FeldWrite=!1):this.changeLast(a,this.AktField,b,this.AktText);
this.AktText=b;this.AktField=a},changeLast:function(a,b,c,e){var d=this.Doc.MVquery.TextEingabe.value,d=d.substring(0,d.length-e.length)+c;this.Doc.MVquery.TextEingabe.value=d;d=this.Doc.MVquery.SQLEingabe.value;d=d.substring(0,d.length-b.length)+a;this.Doc.MVquery.SQLEingabe.value=d},sqlString:function(a,b){this.Doc.MVquery.TextEingabe.value+=b;this.Doc.MVquery.SQLEingabe.value+=a;this.writeStatus()},writeStatus:function(){this.OperatorWrite=this.WertWrite=this.FeldWrite=!0},sqlOperator:function(a){if("%"==
a)return this.sqlString(a,a),!0;1==this.OperatorWrite?(this.sqlString(a,a),this.OperatorWrite=!1):" ) "==this.AktOperator&&(" or "==a||" and "==a)||" ( "==a&&(" or "==this.AktOperator||" and "==this.AktOperator)?(this.sqlString(a,a),this.OperatorWrite=!1):this.changeLast(a,this.AktOperator,a,this.AktOperator);this.AktOperator=a},sqlValue:function(a){a=a.options[a.selectedIndex].text;1==this.WertWrite?(this.sqlString(a,a),this.WertWrite=!1):this.changeLast(a,this.AktWert,a,this.AktWert);this.AktWert=
a},test:function(){var a=this.Doc.MVquery.TextEingabe.value;for(i=0;i<this.Doc.MVquery.fields.length;i++)var b=this.Doc.MVquery.fields.options[i].text,b=b.replace(/\(/g,"\\("),b=b.replace(/\)/g,"\\)"),b="\\"+b,b=b.replace("]","\\]"),b=new RegExp(b,["g"]),a=b=a.replace(b,this.Doc.MVquery.fields.options[i].value);this.Doc.MVquery.SQLEingabe.value=b},doQuery:function(a){if(""==this.Doc.MVquery.SQLEingabe.value)return!1;var b=mv_Map.Layers.item(this.themaId),c=this.Doc.MVquery.SQLEingabe.value;b.XMLAccess&&
(c=mv_selRecords(c,this.themaId));mv_selRecords2(b.XMLAccess,c,this.themaId,this.themaId,a,!0,!0,20,!0,this.ExcelWrite);return!1},testAndDoQuery:function(){this.test();this.doQuery(!1);return!1},changeField:function(a){for(var b=this.Doc.getElementById("MVqueryValues").getElementsByTagName("div"),c=0;c<b.length;c++){var e=b.item(c);a==e.getAttribute("id")?e.style.display="inline":e.style.display="none"}}})}
function mv_openQuery(a,b){var c=mv_showWindow(mv_Doc.BaseURL+"embfiles/query.html","MVQueryBuilder",b);(new mv_Timer).setTimeout("mv_setQueryPage",500,c,a)}function mv_setQueryPage(a,b){mv_Query.Doc=a.document;mv_Query.Window=a;if(null!=a.document.MVqueryLayer)for(var c=0;c<a.document.MVqueryLayer.MVlistQueryLayer.length;c++)a.document.MVqueryLayer.MVlistQueryLayer[c].value==b&&(a.document.MVqueryLayer.MVlistQueryLayer.selectedIndex=c);mv_Query.themaId="";mv_checkQueryLoaded(b)}
function mv_checkQueryLoaded(a){window.setTimeout("mv_testQuery('"+a+"')",200)}function mv_testQuery(a){try{null==(mv_Query.Doc.getElementById("MVqueryFields").innerHTML="")?mv_checkQueryLoaded(a):mv_Query.layerSelect(a)}catch(b){mv_checkQueryLoaded(a)}}function mv_queryTool(a){mv_clearEvents(!1,"query");mv_showQuery(a.currentTarget.title)}
function mv_showQuery(a){var b=dijit.byId("MVqueryFP");if("undefined"!=typeof b)b.bringToTop(),b.show(),b.set("style","width:auto;height:auto");else{b=dojo.byId("MVqueryContent");mv_removeEle(b);var c=mv_makeNode(document,"div",{id:"MVqueryFP"});c.style.display="none";dojo.byId("MVqueryFPContainer").appendChild(c);c.appendChild(b);require(["dojox/layout/FloatingPane"],function(b){b=new b({resizable:!1,dockable:!1,title:a,style:"position:absolute;top:90px;left:90px;width:auto;height:auto;visibility:hidden;z-index:4;",
close:function(){this.hide()}},"MVqueryFP");b.startup();b.bringToTop();b.show();b.set("style","width:auto;height:auto")})}};