﻿var current_field = "0#add_streetname";
var url = "..\\Services\\WebService.asmx";
var current_search = 0;
try {

    /* Call GetCompletionList2 web service and retrieve the completion
       list for the passed values of search type and search text. */
    function call_service(control, searchtype) {
        current_field = control;
        var param = document.getElementById(control).value;
        if (param.length > 2) {
            var pl = new SOAPClientParameters();
            pl.add("prefixText", param);
            pl.add("search_type", searchtype);
            SOAPClient.invoke(url, "GetCompletionList2", pl, true, recieve_callBack);
        }
    }
    
    /*
        Show Passed Completion List below the search control.
    */
    function recieve_callBack(st) {
        var i = 0;
        var inner = "";
        while (st[i]) {
            inner += '<a style="cursor:pointer; text-decoration:none; font:13px tahoma; width:100%;" onclick="settext(this.innerHTML);">' + st[i] + '</a><br>';
            i++;
        }
        show_results();
        document.getElementById("div_results").innerHTML = inner;
    }

    var vil_select_control;
    // Call Web Sevice Function that Retrieves Villages List
    function call_service_ddl_vill(control, searchtype) {
        current_field = control;
        vil_select_control = control;
        var pl = new SOAPClientParameters();
        pl.add("search_type", searchtype);
        SOAPClient.invoke(url, "GetCompletionList_ddl_vill", pl, true, recieve_callBack_dll_vill);
    }
    
    // Fill Villages Drop Down List.
    function recieve_callBack_dll_vill(st) {
        var i = 0;
        var no = "";
        var name = "";
        var temp = "";
        var e = document.getElementById(vil_select_control);
        e.options[0] = new Option("---اختر---", -1);
        while (st[i]) {
            temp = st[i].split("#");
            no = temp[0];
            name = temp[1];
            e.options[i + 1] = new Option(name, no);
            i++;
        }
    }
    
    /*
        1. Fill Village Text Control with The Selected Village Number.
        2. Call Web Service Function That Retrieve the Blocks List for the Selected Village.
        3. Zoom to the Selected Village.
    */
    var block_select_control, list_loading;
    function call_service_ddl_block(control1, control, txt_control, lists_load, searchtype) {
        list_loading = lists_load;
        vil_select_control = control1;
        block_select_control = control;
        document.getElementById(list_loading).style.visibility = "visible";
        current_field = control;
        var village = document.getElementById(vil_select_control).value;
        //fill village no int textbox
        var cont = document.getElementById(vil_select_control);
        var val = cont.options[cont.selectedIndex].value;
        document.getElementById(txt_control).value = val;
        var pl = new SOAPClientParameters();
        pl.add("search_type", searchtype);
        pl.add("vill", village);
        SOAPClient.invoke(url, "GetCompletionList_ddl_block", pl, true, recieve_callBack_dll_block);
        var lIndex1 = getLayerIndex("القرى");
        var lIndex2 = getLayerIndex("القرى");
        executeFind(lIndex1, lIndex2, 'VILLAGE_NO', 'VILLAGE_NO', document.getElementById(vil_select_control).value);
    }
    
    // Fill Blocks Drop Down List.
    function recieve_callBack_dll_block(st) {
        var i = 0;
        var no = "";
        var name = "";
        var temp = "";
        document.getElementById(block_select_control).disabled = false;
        var e = document.getElementById(block_select_control);
        e.options.length = 0;
        e.options[0] = new Option("---اختر---", -1);
        while (st[i]) {
            temp = st[i].split("#");
            no = temp[0];
            name = temp[1];
            e.options[i + 1] = new Option(name, no);
            i++;
        }
        document.getElementById(list_loading).style.visibility = "hidden";
    }
    
    
    var sector_select_control;
    /*
        1. Fill Block Text Control with The Selected Block Number.
        2. Call Web Service Function That Retrieve the Sectors List for the Selected Block.
        3. Zoom to the Selected Block.
    */
    function call_service_ddl_sector(control1, control2, control, txt_control, list_load, searchtype) {
        list_loading = list_load;
        vil_select_control = control1;
        block_select_control = control2;
        sector_select_control = control;
        document.getElementById(list_loading).style.visibility = "visible";
        current_field = control;
        var village = document.getElementById(vil_select_control).value;
        var cont = document.getElementById(block_select_control);
        var block = cont.options[cont.selectedIndex].text;
        var val = cont.options[cont.selectedIndex].value;
        document.getElementById(txt_control).value = val;
        var pl = new SOAPClientParameters();
        pl.add("search_type", searchtype);
        pl.add("vill", village);
        pl.add("block", val);
        SOAPClient.invoke(url, "GetCompletionList_ddl_sector", pl, true, recieve_callBack_dll_sector);
        var lIndex1 = getLayerIndex("الاحواض");
        var lIndex2 = getLayerIndex("القرى");
        var outField = ["BLOCK_NAME_A", "VILLAGE_NO"];
        executeQuery(lIndex1, outField, "searchtext", "BLOCK_NAME_A = '" + block + "' AND VILLAGE_NO = '" + village + "'", true);
        //executeFind(lIndex1, lIndex2, 'BLOCK_NAME_A', 'VILLAGE_NO', block)
    }
    
    // Fill Sectors Drop Down List.
    function recieve_callBack_dll_sector(st) {
        var i = 0;
        var no = "";
        var name = "";
        var temp = "";
        document.getElementById(sector_select_control).disabled = false;
        var e = document.getElementById(sector_select_control);
        e.options.length = 0;
        e.options[0] = new Option("---اختر---", -1);
        while (st[i]) {
            temp = st[i].split("#");
            no = temp[0];
            name = temp[1];
            e.options[i + 1] = new Option(name, no);
            i++;
        }
        document.getElementById(list_loading).style.visibility = "hidden";
    }
    
    /*
        1. Fill Sector Text Control with The Selected Sector Number.
        2. Call Web Service Function That Retrieve the Plots List for the Selected Sector.
    */
    var plot_select_control;
    function call_service_ddl_plot(control1, control2, control3, control, txt_control, lists_load, searchtype) {
        list_loading = lists_load;
        vil_select_control = control1;
        block_select_control = control2;
        sector_select_control = control3;
        plot_select_control = control;
        document.getElementById(list_loading).style.visibility = "visible";
        current_field = control;
        var village = document.getElementById(vil_select_control).value;
        var block = document.getElementById(block_select_control).value;
        var sector = document.getElementById(sector_select_control).value;
        var cont = document.getElementById(sector_select_control);
        var val = cont.options[cont.selectedIndex].value;
        document.getElementById(txt_control).value = val;
        var pl = new SOAPClientParameters();
        pl.add("search_type", searchtype);
        pl.add("vill", village);
        pl.add("block", block);
        pl.add("sector", sector);
        SOAPClient.invoke(url, "GetCompletionList_ddl_plot", pl, true, recieve_callBack_dll_plot);
    }
    
    // Fill Plots Drop Down List.
    function recieve_callBack_dll_plot(st) {
        var i = 0;
        var no = "";
        var name = "";
        var temp = "";
        document.getElementById(plot_select_control).disabled = false;
        var e = document.getElementById(plot_select_control);
        e.options[0] = new Option("---اختر---", -1);
        while (st[i]) {
            temp = st[i].split("#");
            no = temp[0];
            name = temp[1];
            e.options[i + 1] = new Option(name, no);
            i++;
        }
        document.getElementById(list_loading).style.visibility = "hidden";
    }
    
    // Fill Sector Text Control with The Selected Plot Number.
    function set_plot_no(txt_control) {
        var cont = document.getElementById(plot_select_control);
        var val = cont.options[cont.selectedIndex].value;
        document.getElementById(txt_control).value = val;
    }
    
    /* Set the Selected Value from the Completion list to
       its proper control depending on the selected search type.*/
    function settext(val) {
        var next = next_control(current_field);
        var xxcc = new Array();
        xxcc = next.split("#");
        document.getElementById(current_field).value = val;
        document.getElementById("div_results").innerHTML = "";
        hide_results();
        if (xxcc[0] == 1) {
            document.getElementById(next).disabled = false;
            document.getElementById(next).focus();
        }

    }

    // show search div according to search type selection
    function select_search(index, length) {
        var i = 1;
        //document.getElementById("div0").style.display = "none";
        current_search = index;

        while (i < length) {
            if (i == index) {
                document.getElementById("div" + index).style.display = "block";
                document.getElementById("div" + index).className = "enabled";

            }
            else {
                document.getElementById("div" + i).style.display = "none";
                document.getElementById("div" + i).className = "disabled";
            }
            i++;
        }
        if (index == 4) {
            call_service_ddl_vill("0#plt_village_name", "1");
        }
        document.getElementById("lnduse_print_btn").style.display = "none";
    }

    // array of the names of all searchs fields controls names in appearence order
    var controls = new Array();
    controls[0] = "0#add_streetname";
    controls[1] = "1#add_buildingno";
    controls[2] = "0#strt_streen_name";
    controls[3] = "0#lndmrk_landmark_name";
    controls[4] = "0#plt_village_name";
    controls[5] = "1#plt_block_name";
    controls[6] = "1#plt_sector_no";
    controls[7] = "1#plt_plot_no";
    controls[8] = "0#dstrct_district_name";
    controls[9] = "0#vlg_village_name";
    controls[10] = "0#vlg_village_name";

    // function to return the name of the next control of the current sellected control
    function next_control(zz) {
        var i = 0;
        var found = false;
        var index;
        while (i < 11 && !found) {
            if (controls[i] == zz) {
                found = true;
            }
            i++;
        }
        return controls[i];
    }

    //function to set the left and top values of the results div relative to the selected textbox position
    function set_results_position() {
        var top = getElementTop(current_field);
        top += 21;
        var left = getElementLeft(current_field);
        left += 1;
        document.getElementById("div_results").style.top = top + "px";
        document.getElementById("div_results").style.left = left + "px";
    }
    
    // Show Completion List Div.
    function show_results() {
        set_results_position();
        document.getElementById("div_results").style.display = "block";
    }
    
    // Hide Completion List Div.
    function hide_results() {
        document.getElementById("div_results").style.display = "none";
    }

    // functions that return the left of an element
    function getElementLeft(Elem) {

        var elem;
        if (document.getElementById) {
            var elem = document.getElementById(Elem);
        } else if (document.all) {
            var elem = document.all[Elem];
        }
        xPos = elem.offsetLeft;
        tempEl = elem.offsetParent;
        while (tempEl != null) {
            xPos += tempEl.offsetLeft;
            tempEl = tempEl.offsetParent;
        }
        return xPos;

    }

    // functions that return the top of an element
    function getElementTop(Elem) {

        if (document.getElementById) {
            var elem = document.getElementById(Elem);
        } else if (document.all) {
            var elem = document.all[Elem];
        }
        yPos = elem.offsetTop;
        tempEl = elem.offsetParent;
        while (tempEl != null) {
            yPos += tempEl.offsetTop;
            tempEl = tempEl.offsetParent;
        }
        return yPos;

    }

    var contentinfo = 'non';
    var contentinfodatatype = 'non';
    /*
      Zoom to Feature Function.
      Zoom to the searched feature depending on the search type.
    */
    function zoom_to_feature() {
        switch (current_search) {
           
            case "0":
                //do nothing
            break;
            
            case "9":
            //do nothing
                call_service_Tax(document.getElementById("TaxServicesTxt").value);
            case "1":
                var buildingno = document.getElementById("1#add_buildingno").value;
                var stname = document.getElementById("0#add_streetname").value;
                var sqlwhere = "STREET_NAME_A = '" + stname + "' and BULDING_NUMBER = '" + buildingno + "'";
                var out = ["STREET_NAME_A","BULDING_NUMBER", "DISTRICT_NAME_A", "ZONING_NAME_A"];
                var lIndex = getLayerIndex("ترقيم الابنية");
                executeQuery(lIndex, out, stname, sqlwhere, true);
                break;
            case "2":
                var stname = document.getElementById("0#strt_streen_name").value;
                var sqlwhere = "STREET_NAME_A = '" + stname + "'";
                var out = ["STREET_NAME_A"];
                var lIndex = getLayerIndex("حدود الشوارع التنظيمية");
                executeQuery(lIndex, out, stname, sqlwhere, false);
                //street zoom code
                break;
            case "3":
                var stname = document.getElementById("0#lndmrk_landmark_name").value;
                var sqlwhere = "LANDMARK_NAME_A = '" + stname + "'";
                var out = ["LANDMARK_NAME_A", "LANDMARK_DISCRIPTION_A"];
                var lIndex = getLayerIndex("landzoom");
                executeQuery(lIndex, out, stname, sqlwhere, false);
                //landmarkk zoom code
                break;
            case "4":
                var sqlwhere = "VILLAGE_NO = " + document.getElementById("vill_txt").value + "and BLOCK_NO = " + document.getElementById("block_txt").value + "and SECTOR_NO = " + document.getElementById("sector_txt").value + "and PLOT_NO = " + document.getElementById("plot_txt").value;
                //sqlwhere = "VILLAGE_NO = 112 and BLOCK_NO = 5 and SECTOR_NO = 0 and PLOT_NO = 32";
                stname = document.getElementById("plot_txt").value;
                var out = ["DISTRICT_NUMBER", "LANDUSE_DESC", "SHAPE.AREA"];
                var lIndex = getLayerIndex("قطع الاراضي");

                executeQuery(lIndex, out, stname, sqlwhere, false);
                document.getElementById("lnduse_print_btn").style.display = "block";
                //plot zoom code
                break;
            case "5":
                //executeFind(layer1, layer2, field1, field2, searchText);
                var lIndex1 = getLayerIndex("احياء الامانة");
                var lIndex2 = getLayerIndex("مناطق أمانة عمان");
                executeFind(lIndex1, lIndex2, 'ZONING_NAME_A', 'DISTRECT_NAME_A', document.getElementById('0#dstrct_district_name').value);
              
                //zone zoom code
                break;
            case "6":
                var lIndex1 = getLayerIndex("القرى");
                var lIndex2 = getLayerIndex("الاحواض");
                executeFind(lIndex1, lIndex2, 'BLOCK_NAME_A', 'VILLAGE_NAME_A', document.getElementById('0#vlg_village_name').value);
                //village zoom code
                break;
            case "7":
                var lIndex1 = getLayerIndex("الشكاوى");
                var lIndex2 = getLayerIndex("مناطق أمانة عمان");
                executeFind(lIndex1, lIndex2, 'COMP_NO', 'DISTRECT_NAME_A', document.getElementById('0#complaint_no').value);
                
                //zone zoom code
                break;

            case "8":
                var CarCode = document.getElementById("CarCode").value;
                var CarNo = document.getElementById("CarNo").value;
                call_service_tkt(CarCode, CarNo);

                break;
        }
    }
}

catch (e) {
    alert(e.name + ' : ' + e.message);
}

// Call the Web Service Function that Retrieves Car Tickets List for a Passed Car Number.
function call_service_tkt(CarCode, CarNo) {
    // current_field = control;
    //var param = document.getElementById(control).value;
    var pl = new SOAPClientParameters();
    pl.add("CarCode", CarCode);
    pl.add("CarNo", CarNo);
    SOAPClient.invoke(url, "GetTkt", pl, true, recieve_callBack_tkt);
}

// Construct the Car Tickets Div and Show it Fillled with the Car Tickets.
function recieve_callBack_tkt(st) {

    var CarValue = 0;
    var CarCode = document.getElementById("CarCodeText").value;
    var CarNo = document.getElementById("CarNumberText").value
    //length = 1
    var TktData = st;
    var i = 0;
    var TktDivData = "<table style=' background-color:Highlight; float:right;color:white;' dir='rtl'>";
    TktDivData += "<tr ><td style=' text-align:center;' ><table >";
    TktDivData += "<tr ><td >رقم السياره :</td><td style='border-left:solid 3px black ;'>" + CarNo + "</td><td >رمز السيارة :</td><td >" + CarCode + "</td><td ></td></tr></td></tr></table>";
    if (TktData.length != 0) {
        TktDivData += "<tr><td class=' tkttable'>وصف المخالفة</td><td class=' tkttable'>رقم المخالفة</td><td class=' tkttable'>قيمة المخالفة</td><td class=' tkttable'>تاريخ المخالفة</td><td class=' tkttable'>الموقع</td></tr><tr>";
        for (i; i < TktData.length; i++) {
            var user = st[i].split('#');
            // TktDivData += "<tr><td class=' tkttable'>" + user[0] + " " + user[1] + "</td><td class=' tkttable'>" + user[2] + "</td><td class=' tkttable'>" + user[3] + "</td><td class=' tkttable'>" + user[4] + "</td><td class=' tkttable'>";
            CarValue += parseInt(user[2]);
            if (user[5] == "") {
                TktDivData += "<tr><td class=' tkttable'>" + user[6] + "</td><td class=' tkttable'>" + user[0] + " " + user[1] + "</td><td class=' tkttable'>" + user[2] + "</td><td class=' tkttable'>" + user[3] + "</td><td class=' tkttable'>";
                TktDivData += "لا يوجد موقع";
            }
            else {
                TktDivData += "<tr  style=' background-color:Red' ><td class=' tkttable'>" + user[6] + "</td><td class=' tkttable'>" + user[0] + " " + user[1] + "</td><td class=' tkttable'>" + user[2] + "</td><td class=' tkttable'>" + user[3] + "</td><td class=' tkttable'>";
                TktDivData += " <a href='javascript:TktGetLocation(" + user[4] + "," + user[5] + ");'> موقع المخالفة </a>";

            }
            TktDivData += "  </td></tr><tr>";
        }
    }
    else {

        TktDivData += "<tr><td>لا يوجد مخالفة</td><td></td><td ></td><td></td></tr>"
    }
    TktDivData += "<tr  style=' background-color:Red' ><td></td><td class=' tkttable'>القيمة الكلية</td><td class=' tkttable'>" + CarValue + "</td><td class=' tkttable'></td><td class=' tkttable'></td><td class=' tkttable'>";
    TktDivData += "<tr><td class=' tkttable'><a href='javascript:TktDivhide();'>انهاء</a></td><td ></td><td ></td><td ></td><td ></td></tr><tr>";
    TktDivData += "</table>";
    document.getElementById("TktDiv").style.display = "block";
    document.getElementById("TktDiv").innerHTML = TktDivData;


}

// Zoom to Car Ticket Location using the passed x and y values.
var gsvc, wkidIn, wkidOut, srs;
function TktGetLocation(x, y) {
    var x = x;
    var y = y;

    var point = new esri.geometry.Point(x, y, new esri.SpatialReference({ wkid: 4326 }));
    var geometryService = new esri.tasks.GeometryService("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");

    var graphic = new esri.Graphic();
    graphic.geometry = point;
    var graphics = [graphic]; //Array

    geometryService.project(graphics, map.spatialReference, projectCallbackFunction);
}

// Zooms to the geometry of the last graphic in the passed graphics if it contain one(contain geometry).
function projectCallbackFunction(graphics) {
    var graphic
    for (var i = 0; i < graphics.length; i++) {
        graphic = graphics[i];
        if (graphic.geometry != null) {
            var point = graphic.geometry;
            map.centerAt(point);
            var symbol = new esri.symbol.PictureMarkerSymbol('./images/police_icon.png', 40, 40);
            graphic.setSymbol(symbol);
            map.graphics.add(graphic);
            map.setExtent(new esri.geometry.Extent(point.x - 500, point.y - 500, point.x + 500, point.y + 500, new esri.SpatialReference({ wkid: 4281 })));
        }
        else {
            alert("graphic[" + i + "] doesn't contain geometry");
        }
    }

}

// Hide Car Tickets Results Div.
function TktDivhide() {

    document.getElementById("TktDiv").style.display = "none";

}

// Show Other Services Div and hide it in 8 sec.
function showOptions() {//otherservice
    document.getElementById("services_div").style.top = "75px";
    document.getElementById("services_div").style.right = "400px";
    document.getElementById("services_div").style.display = "block";
    hideDiv("services_div");
    var wsx = document.getElementById("otherservice");
}

// Hide the Passed Div in 8 sec.
var counter = 0;
var countobjct = 0;
function hideDiv(divname) {
    var container = document.getElementById(divname);
    if (counter < 8) {
        counter += 1;
        countobjct = setTimeout(function() { hideDiv(divname) }, 1000);
    }
    else {
        clearTimeout(countobjct);
        document.getElementById(divname).style.display = "none";
        counter = 0;
    }
}

// Call the Web Service Function that Retrieves the Landmarks Categories List.
function call_service_ddl_landMarks() {
    var pl = new SOAPClientParameters();
    SOAPClient.invoke(url, "GetCompletionList_ddl_landMarks", pl, true, recieve_callBack_dll_landMarks);
}

// Fill the Landmarks Categories Drop Down List.
function recieve_callBack_dll_landMarks(st) {
    var i = 0;
    var no = "";
    var name = "";
    var temp = "";
    var e = document.getElementById("landmark_cat_ddl");
    e.options[0] = new Option("---اختر---", -1);
    while (st[i]) {
        temp = st[i].split("#");
        no = temp[0];
        name = temp[1];
        e.options[i + 1] = new Option(name, no);
        i++;
    }

}

//landmark_cat_ddl
// Zoom to a Land using the Land Passed Informations.
function call_service_GetLand(vill,block,sector,plot) {
    
        var sqlwhere = "VILLAGE_NO = " + document.getElementById(vill).value + " and BLOCK_NO = " + document.getElementById(block).value + " and SECTOR_NO = " + document.getElementById(sector).value + " and PLOT_NO = " + document.getElementById(plot).value;
                    
        stname = document.getElementById(plot).value;
        var out = ["DISTRICT_NUMBER", "LANDUSE_DESC", "SHAPE.AREA"];
        var lIndex = getLayerIndex("قطع الاراضي");
        
        contentinfo = "ضريبة التحققات";
        executeQuery(lIndex, out, stname, sqlwhere, false);
        //document.getElementById("ChecksTaxLabel").style.visibility = "visible";
    
}

// Call the Web Service Function that Retrieves the Checks List for a land using the passed information.
var checks_tax_temp_graphic;
function call_service_ChecksTax(vil,block,sector,plot,temp_graphic) {
    showLoading();
    checks_tax_temp_graphic = temp_graphic;
    var p1 = new SOAPClientParameters();
    p1.add("VillageNo", parseInt(vil));
    p1.add("BlockNo", parseInt(block));
    p1.add("Sector", parseInt(sector));
    p1.add("Plots", parseInt(plot));

    SOAPClient.invoke(url, "GetChecksTax", p1, true, recieve_callBack_ChecksTax);
}

// Show and Fill the Land Checks Div.
function recieve_callBack_ChecksTax(st) {

    var i = 0;
    var total = 0;
    if (st.length != 0) {
        contentinfo = "<table style='text-align: center; width: 100%;' dir='rtl' cellpadding='5'>";
        contentinfo += "<tr><td>قيمة التحققات</td><td>المبلغ المدفوع</td><td>المبلغ المتبقي</td><td>نوع التحقق</td></tr>";
        var DLSKey = "";
        for (i; i < st.length; i++) {
            var TaxData = st[i].split('#');
            total += parseFloat(TaxData[0])-parseFloat(TaxData[1]);
            contentinfo += "<tr><td>" + TaxData[0] + "</td><td>" + parseFloat(TaxData[1]).toFixed(3) + "</td><td>" + (parseFloat(TaxData[0])-parseFloat(TaxData[1])).toFixed(3) + "</td><td>" + TaxData[2] + "</td></tr>";
        }
        contentinfo += "<tr><td colspan='4' style='text-align: right; font-weight: bold;'>المجموع المتبقي: " + total.toFixed(3) + " دينار.</td></tr>";
        contentinfo += "</table>";
    }
    else
    {
        contentinfo = "<div style='text-algin: right; direction: rtl;'>لا يوجد تحققات على القطعة</div>";
    }

    var screenPoint1 = map.toScreen(checks_tax_temp_graphic._extent.getExtent().getCenter());
    map.infoWindow.setTitle("<div style='text-align: right;'>استعلام ضريبة التحققات</div>");
    map.infoWindow.setContent(contentinfo);
    map.infoWindow.show(screenPoint1, map.getInfoWindowAnchor(screenPoint1));
    hideLoading();
}

/* Call the Web Service Function that Retrieves
   the Tax List for the Passed National Number. */
var NatNo;
function call_service_Tax(NatNo) {
    showLoading();
    var NatNoTxt = NatNo;
    var pl = new SOAPClientParameters();
    pl.add("NAT_NO", NatNoTxt);

    SOAPClient.invoke(url, "GetTaxationByNat", pl, true, recieve_callBack_Tax);
}


// Fiil and Show the Tax Results Div.
function recieve_callBack_Tax(st) {

    var i = 0;
    var TktDivData = "<table style=' background-color:white; float:right;' dir='rtl'>";

    TktDivData += "<tr ><td style=' border-bottom:solid 2px Black;' >رقم القطعه :</td><td ></td></tr>";
    if (st.length != 0) {
        var DLSKey = "";
        for (i; i < st.length; i++) {
            var TaxData = st[i].split('#');
            TktDivData += "<tr><td style=' border-bottom:solid 2px Black;' >" + TaxData[3] + "</td><td ><a  href='javascript:ShowPlots(" + TaxData[0] + "," + TaxData[1] + "," + TaxData[2] + "," + TaxData[3] + "," + TaxData[4] + "," + TaxData[5] + "," + TaxData[6] + "," + TaxData[7] + ")' > تكبير الموقع</a></td>";
        }
    }

    TktDivData += "<tr><td ><a href='javascript:TktDivhide();'>انهاء</a></td><td></td></tr>";
    TktDivData += "</table>";
    document.getElementById("TktDiv").style.display = "block";
    document.getElementById("TktDiv").innerHTML = TktDivData;
    hideLoading();

}


var BuildTax;
var BuildNoTax;
var FloorNoTax;
var FlatNoTax;
// Execute Query Task for land depending on its passed data.
function ShowPlots(Village, block, Sector, Plots, BuildNo, FloorNo, FlatNo, Tax) {
    BuildTax = Tax;
    BuildNoTax = BuildNo;
    FloorNoTax = FloorNo;
    FlatNoTax = FlatNo;

    queryTask = new esri.tasks.QueryTask("http://www.ammancitygis.gov.jo/ok/rest/services/public1/MapServer/" + getLayerIndex("قطع الاراضي"));
    query = new esri.tasks.Query();
    query.returnGeometry = true;
    query.outFields = ["DLS_KEY ", "VILLAGE_NO", "BLOCK_NO", "SECTOR_NO", "PLOT_NO"]; ;

    query.where = "VILLAGE_NO = " + Village + " and BLOCK_NO = " + block + " and SECTOR_NO = " + Sector + " and PLOT_NO = " + Plots;
    yuyu = "<div style='background-color:ActiveBorder;width:100%;text-align:center;  font-weight: bold;'> <table   dir='rtl' ><tr><td> رقم القرية </td><td> " + Village + "</td></tr><tr><td>رقم الحوض</td><td>" + block + "</td></tr><tr><td>رقم الحي</td><td>" + Sector + "</td></tr><tr><td>رقم القطعه</td><td>" + Plots + "</td></tr><tr><td>المبنى</td><td>" + BuildNoTax + "</td></tr><tr><td>رقم الطابق</td><td>" + FloorNoTax + "</td></tr><tr><td>رقم الشقه</td><td>" + FlatNoTax + "</td></tr><tr><td>مجموع المسقفات</td><td>" + parseInt(BuildTax) + "</td></tr></table><div>";

    queryTask.execute(query, CallbackPlotsTax);
}

// Zoom to the land feature stored in the passed results feature set.
var yuyu;
function CallbackPlotsTax(results) {
    map.graphics.clear();
    var result2 = results;
    //var result3 = result2.features
    var graphic = result2.features[0];
    var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_FORWARD_DIAGONAL, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([150, 1, 1]), 3), new dojo.Color([140, 5, 5, 0.55]));
    graphic.setSymbol(symbol);
    map.graphics.add(graphic);
    var resultExtent = graphic._extent;
    //        var finalExtent = new esri.geometry.Extent(resultExtent.expand(3), new esri.SpatialReference({ wkid: 28191 }));
    var initialExtent = new esri.geometry.Extent(resultExtent.expand(2), new esri.SpatialReference({ wkid: 28191 }));
    var l1Extent = new esri.geometry.Extent(resultExtent.expand(3), new esri.SpatialReference({ wkid: 28191 }));
    screenPoint1 = map.toScreen(graphic._extent.getExtent().getCenter());
    map.infoWindow.setTitle("استعلام");
     map.infoWindow.setContent(yuyu);
    map.infoWindow.show(screenPoint1, map.getInfoWindowAnchor(screenPoint1));
    map.setExtent(l1Extent);
     map._refresh();
    delayer(); 
}

// Show Tax Service Div and hide all other services divs.
function TaxRadioClickHandler()
{
    document.getElementById("taxRadio").checked="checked";
    document.getElementById("checksTaxRadio").checked="";
    document.getElementById("VehicleTicketsRadio").checked="";
    
    document.getElementById("ChecksTaxDiv").className = "disabled";
    document.getElementById("VehicleTicketsDiv").className = "disabled";
    document.getElementById("TaxDiv").style.visibility = "visible";
}

// Close Tax Service Div.
function TaxExitButton()
{
    document.getElementById("taxDiv").style.visibility = "hidden";
    document.getElementById("taxRadio").checked =  "";
    document.getElementById("VehicleTicketsDiv").className = "disabled"
}

// Show Land Checks Service Div and hide all other services divs.
function ChecksTaxRadioClickHandler()
{
    document.getElementById("taxRadio").checked="";
    document.getElementById("checksTaxRadio").checked="checked";
    document.getElementById("VehicleTicketsRadio").checked="";
    
    document.getElementById("ChecksTaxDiv").className = "enabled";
    document.getElementById("TaxDiv").style.visibility = "hidden";
    document.getElementById("VehicleTicketsDiv").className = "disabled";
}

// Show Car Tickets Service Div and hide all other services divs.
function VehicleTicketsRadioClickHandler()
{
    document.getElementById("taxRadio").checked="";
    document.getElementById("checksTaxRadio").checked="";
    document.getElementById("VehicleTicketsRadio").checked="checked";
    
    document.getElementById("ChecksTaxDiv").className = "disabled";
    document.getElementById("VehicleTicketsDiv").className = "enabled";
    document.getElementById("TaxDiv").style.visibility = "hidden";
}

// Close Car Tickets Service Div.
function VehicleTicketsExitButton()
{
    document.getElementById("ChecksTaxDiv").className = "disabled";
    document.getElementById("VehicleTicketsRadio").checked =  "";
    document.getElementById("VehicleTicketsDiv").className = "disabled"
}

// Close Land Checks Div.
function ChecksTaxExitButton()
{
    document.getElementById("ChecksTaxDiv").className = "disabled";
    document.getElementById("checksTaxRadio").checked =  "";
    document.getElementById("VehicleTicketsDiv").className = "disabled"
}

// Syncronize the Layers Navigation Tab with the Other Services Layers List.
function navigateVisibleLayerWithServicesMenu(name)
{
    if(document.getElementById(name)!=null && document.getElementById("chk" + name)!=null)
         document.getElementById("chk" + name).checked = document.getElementById(name).checked;
}

function default_search_by_landmark_identify(graphic)
{
    var infoTemplate = new esri.InfoTemplate();
    infoTemplate.setTitle(graphic.attributes["LANDMARK_DISCRIPTION_A"]); 
    var infotempContent = "<div id='tabs' style='width:100%;'><tabel cellspacing='0' style='border:solid 1px black; width:100%; float:right;'><tr><td>" + graphic.attributes["LANDMARK_NAME_A"] + "</td></tr></tabel></div>";
    infoTemplate.setContent(infotempContent);
    map.infoWindow.resize(250, 80);
    graphic.setInfoTemplate(infoTemplate);
}

function Build_Amman_Projects_Accordion() {

    var sql = "SELECT distinct test, mainproject FROM WEB.PROJECTALL order by test";
    var pl = new SOAPClientParameters();
    pl.add("sqlstatement", sql);
    pl.add("search_field", "mainproject");
    SOAPClient.invoke(url, "Getdatareader", pl, true, amman_projects_recieve_callBack);

}

function amman_projects_recieve_callBack(st) {

    var PHTML = "<div style='padding-top: 10px;' align='center'>";
    var i = 0;
    for (var i = 0; st[i]; i++) {
        PHTML += '<input style="width:130px; color:White; font-weight:bold; background-color:#302217;" type="button" value="' + st[i] + '" onclick="zoom_to_amman_project(this);" />';
        PHTML += '<br />';
    }
    PHTML += "</div>";
    document.getElementById("amman_projects").innerHTML = PHTML;
}

function zoom_to_amman_project(btn_control) {

    var ptest = btn_control.value;
    var sqlwhere = "mainproject = '" + ptest + "'";

    var out = ["OBJECTID", "NAME", "ProjectAll.AREA", "DESCRIPTION", "IMAGE1", "IMAGE2", "TEST", "SHAPE", "SHAPE.AREA", "SHAPE.LEN", "mainproject"];
    var lIndex = getLayerIndex("مشاريع الامانه");

    amman_projects_execute_query(lIndex, out, sqlwhere);

}

