﻿var gridview1 = {
    cells: [
            [{ width: '50px', formatter: formatZoom },
             { name: 'PARCEL ID', width: '100px' },
             { name: 'OWNER', width: '200px' },
             { name: 'ADDRESS', width: '200px' },
             { name: "DEED ACRES", width: '75px' },
             { name: "TOTAL ACRES", width: '75px' },
             { name: "PIN", width: '100px' },
             { name: "DEEDREF", width: '100px' },
             { name: "DEED YEAR", width: '75px' },
             { name: "SITE ADDRESS", width: '300px' },
             { name: "TAX VALUE", width: '125px' },
             { name: "SALE DATE", width: '125px' },
             { name: "SALE PRICE", width: '125px' },
             { name: "REMARKS", width: '250px' },
             { name: "TOWN", width: '100px' },
             { name: "ACCOUNT", width: '100px' },
             { name: "HT SQ FEET", width: '100px' },
             { name: "LAND USE", width: '200px' },
             { name: "YEAR BUILT", width: '100px' },
             { name: "EFF YR BLT", width: '100px' },
             { name: "FIRE DIST", width: '100px' }
             ]
        ]
         };

         // #####################################################################
         // Functions dealing with individual Parcel Graphics
         function parcelDetails(graphic, indx) {
             return getParcelContent(graphic, indx);
         }
         
         
         function getParcelContent(graphic, indx) {
             var pid = getGraphicAttribute(graphic, "CYPAR");
             var salePrice = getGraphicAttribute(graphic, "SALE_PRICE");
             var totalval = getGraphicAttribute(graphic, "TOTAL_VALUE");
             if (indx == null)
                 indx = 0

             var s = [];
             s.push("<div class=\"detail-section\">");
             s.push("<div class=\"captionbr\">${OWNER}</div>");
             s.push("<div class=\"detail-section\">");
             s.push("<div>${ADDRESS}</div></div></div>");
             s.push("<div class=\"detail-section\"><span class=\"captionbr\">Tax Account Info</span>  ");
             s.push("<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">");
             s.push("    <tr><td>Parcel #:</td><td> ${CYPAR}</td></tr>");
             s.push("    <tr><td>PIN:</td><td>${PIN}</td></tr>");
             s.push("    <tr><td>Account Num:</td><td>${ACCT_NUM}</td></tr>");
             s.push("    <tr><td>Deed Info:</td><td><div>${DEED_BOOK} ${DEED_PAGE} ${DEED_YEAR}</div></td></tr>");
             s.push("</table>");
             s.push("</div><div class=\"detail-section\"><span class=\"captionbr\">Physical Setting Info</span>");
             s.push("<table width=\"90%\" cellpadding=\"0\" cellspacing=\"0\" style=\"padding-left: 0.3em\">");
             s.push("  <tr><td>Address:</td><td>${PROP_ADDRESS}</td></tr>");
             s.push("  <tr><td>Land Use:</td><td>${LAND_USE_DESC}</td></tr>");
             s.push("  <tr><td><nobr>Calc-Acres:</nobr></td><td>${TOTAL_ACRES}</td></tr>");
             s.push("  <tr><td><nobr>Deed Acres:</nobr></td><td>${DEED_ACRES}</td></tr>");
             s.push("</table></div>");
             s.push("<div class=\"detail-section\">     ");
             s.push("<span class=\"captionbr\">Sale & Assessment Information</span>  ");
             s.push("<table width=\"90%\" cellpadding=\"0\" cellspacing=\"0\" style=\"padding-left: 0.3em\">");
             s.push("<tr><td>Assessed Value: </td><td>" + dojo.currency.format(totalval, { currency: "USD", places: 0 }) + "</td></tr>");
             s.push("<tr><td>Year Built:</td><td>${YEAR_BUILT}</td></tr><tr><td colspan=\"2\">&nbsp;</td></tr>");
             s.push("<tr><td>Heated Sq Footage:</td><td>${HT_SQ_FT}</td></tr>");
             s.push("<tr><td>Sale Price:</td><td>" + dojo.currency.format(salePrice, { currency: "USD", places: 0 }) + "</td></tr>");
             s.push("<tr><td>Sale Date:</td><td>${SALE_DATE}</td></tr>");
             s.push("</table></div>");
             s.push("<div class=\"detail-section\">");
             s.push("<table width=\"90%\" cellpadding=\"0\" cellspacing=\"0\" style=\"padding-left: 0.3em\">");
             if (pid != "") {
                 s.push("<tr><td><img src=\"images/details2/compsales1.png\"></td><td><a href=\"#\" onmousedown=\"doInitCompSales('${CYPAR}');\">Comp Sales</a></td></tr>");
                 s.push("<tr><td><img src=\"images/details2/adjoiners.png\"></td><td><a href=\"javascript:doAdjoiners('" + pid + "');\" >Adjoining Parcels</a>    </td></tr>");
                 s.push("<tr><td><img src=\"images/details2/print.gif\"></td><td><a href=\"#\" onmousedown=\"printQuickReport('" + pid + "');\">Quick Report</a></td></tr>");
                 s.push("<tr><td><img src=\"images/details2/map.gif\"></td><td><a href=\"#\" onmousedown=\"showPrintableMapProducts('" + pid + "');\">Printed Map Products</a></td></tr>");

                 //        s.push("<tr><td colspan=\"2\">");
                 //        s.push("<a href=\"#\" onmousedown=\"doInitCompSales('${CYPAR}');\"><img src=\"images/details/compsales1.png\"></a>");
                 //        s.push("<a href=\"adjoinersreport.htm?id=" + pid + "\" target=\"_blank\"><img src=\"images/details/adjoiners.png\"></a>");
                 //        s.push("<a href=\"#\" onmousedown=\"printMapHTML('" + pid + "');\"><img src=\"images/details/quickreport.png\"></a>");
                 //        s.push("</td></tr>");


                 //        // separate the main tools from the frivolous
                 //        s.push("<tr><td colspan=\"2\"><hr/></td></tr>");
                 //        s.push("<tr><td colspan=\"2\"><a href=\"#\" onmousedown=\"showGoogleStreetViewByIndex(" + indx + ");\"><img src=\"images/details/streetview.png\" alt=\"googlestreet\"/></a></td></tr>");

             }
             s.push("</table></div>");
             return s.join("");
         }


         function getParcelContent2(graphic) {
             var s = [];
             s.push("<div class=\"detail-section\">");
             s.push("<div class=\"captionbr\">${OWNER}</div>");
             s.push("<div class=\"detail-section\">");
             s.push("<div>${ADDRESS}</div></div></div>");
             s.push("<div class=\"detail-section\"><span class=\"captionbr\">Tax Account Info</span>  ");
             s.push("<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">");
             s.push("    <tr><td>Cypar #:</td><td> ${CYPAR}</td></tr>");
             s.push("    <tr><td>PIN:</td><td>${PIN}</td></tr>");
             s.push("    <tr><td>Account Num:</td><td>${ACCT_NUM}</td></tr>");
             s.push("    <tr><td>Deed Info:</td><td><div>${DEED_BOOK} ${DEED_PAGE} ${DEED_YEAR}</div></td></tr>");
             s.push("</table>");
             s.push("</div><div class=\"detail-section\"><span class=\"captionbr\">Physical Setting Info</span>");
             s.push("<table width=\"90%\" cellpadding=\"0\" cellspacing=\"0\" style=\"padding-left: 0.3em\">");
             s.push("  <tr><td>Address:</td><td>${PROP_ADDRESS}</td></tr>");
             s.push("  <tr><td>Town Name:</td><td>${TOWNSHIP}</td></tr>");
             s.push("  <tr><td>Land Use:</td><td>${LAND_USE_DESC}</td></tr>");
             s.push("  <tr><td><nobr>Calc-Acres:</nobr></td><td>${TOTAL_ACRES}</td></tr>");
             s.push("  <tr><td><nobr>Deed Acres:</nobr></td><td>${DEED_ACRES}</td></tr>");
             s.push("</table></div>");
             s.push("<div class=\"detail-section\">     ");
             s.push("<span class=\"captionbr\">Sale & Assessment Information</span>  ");
             s.push("<table width=\"90%\" cellpadding=\"0\" cellspacing=\"0\" style=\"padding-left: 0.3em\">");
             s.push("<tr><td>Assessed Value: </td><td>${TOTAL_VALUE}</td></tr>");
             s.push("<tr><td>Year Built:</td><td>${YEAR_BUILT}</td></tr><tr><td colspan=\"2\">&nbsp;</td></tr>");
             s.push("<tr><td>Sale Price:</td><td>${SALE_PRICE}</td></tr>");
             s.push("<tr><td>Sale Date:</td><td>${SALE_DATE}</td></tr>");
             s.push("</table></div>");
             s.push("<div class=\"detail-section\">");
             s.push("<table width=\"90%\" cellpadding=\"0\" cellspacing=\"0\" style=\"padding-left: 0.3em\">");
             s.push("<tr><td colspan=\"2\"><a href=\"#\" onmousedown=\"doInitCompSales('${CYPAR}');\">Comparable Sales</a></td></tr>");
             s.push("<tr><td colspan=\"2\"><a href=\"adjoinersreport.htm?id=${CYPAR}\" target=\"_blank\">Find Adjoining Parcels</a>    </td></tr>");
             s.push("<tr><td colspan=\"2\"><a href=\"#\" onmousedown=\"printMapHTML('${CYPAR}');\">Quick Report</a></td></tr>");
             s.push("</table></div>");
             return s.join("");
         }

         function parcelBrief(graphic, indx) {

             return getParcelContent(graphic, indx);


         }
         

         function ParcelRow(graphic, indx, cssClass) {
             var rowText = "";

             //Add result feature to table
             var pin = graphic.attributes.CYPAR;
             var owner1 = graphic.attributes.OWNER;
             //var objectid = graphic.attributes.FID; 
             var addr = graphic.attributes["PROP_ADDRESS"];

             rowText = "<tr onmouseover=\"onRowMouseOver(this, " + indx + ");\" onmouseout=\"onRowMouseOut(this, " + indx + ");\" class=\"" + cssClass + "\" >";
             rowText += "<td valign=\"top\"><div onclick=\"zoomTo(" + indx + ");\"><img src=\"images/zoomtofeature.gif\" alt=\"zoomto\" /></div></td>";
             rowText += "<td><a href=\"#\" onmousedown=\"javascript:showDetails(" + indx + ");\">" + pin + "</a></td>";
             rowText += "<td><div>" + owner1 + "</div><div>" + addr + "</div>";

             dojo.forEach(additionalFields, function(fldName) {
                 switch (fldName.toUpperCase()) {
                     case "SALE_DATE":
                         var sd = new Date(graphic.attributes[fldName]);
                         rowText += "<div>Date of Sale: " + sd.getMonth() + "/" + sd.getDay() + "/" + sd.getFullYear() + "</div>";
                         break;
                     case "SALE_PRICE":

                         rowText += "<div>Price of Sale: $" + graphic.attributes[fldName] + "</div>";
                         break;
                     default:
                         console.debug(fldName);
                         rowText += "<div>" + graphic.attributes[fldName] + "</div>";
                         break;
                 }

             });

             rowText += "</td></tr>";

             return rowText;


         }

         function ParcelRowHeader() {

             return "";

         }

         
         

         function parcelReport(graphic) {
             var pid = graphic.attributes["CYPAR"];
             var mailing = graphic.attributes["ADDRESS"];
             var owner1 = graphic.attributes["OWNER"];
             var prop_addr = graphic.attributes["PROP_ADDRESS"];
             var deedref = "";  //graphic.attributes["BOOK_PAGE"];
             var totalval = graphic.attributes["TAX_VALUE"];
             console.debug("query " + pid);
             var salePrice = getGraphicAttribute(graphic, "SALE_PRICE");


             var s = [];

             s.push("<table width=\"100%\"><tr><td colspan=\"4\">Parcel Report: " + pid + "</td></tr>");
             s.push("<tr><td colspan=\"4\">");
             s.push("<div><div style=\"text-align:left\"><div>" + owner1 + "</div>");
             s.push("<div>" + mailing + "</div></div></div></td></tr>");

             s.push("<tr><td>Account Number:</td><td>" + getGraphicAttribute(graphic, "ACCOUNT") + "</td>");
             s.push("<td>PIN:</td><td class=\"b\">" + getGraphicAttribute(graphic, "PIN") + "</td></tr>");
             s.push("  <tr><td>Site Address:</td><td>" + getGraphicAttribute(graphic, "SITUS_ADDX") + "</td>");
             s.push("  <td>Land Use:</td><td>" + getGraphicAttribute(graphic, "LAND_USE_DESC") + "</td></tr>");
             s.push("  <tr><td><nobr>Calc-Acres:</nobr></td><td>" + getGraphicAttribute(graphic, "TOTAL_ACRES") + "</td>");
             s.push("  <td><nobr>Deed Acres:</nobr></td><td>" + getGraphicAttribute(graphic, "DEED_ACRES") + "</td></tr>");
             s.push("<tr><td>Deed Reference:</td><td>" + deedref + " " + getGraphicAttribute(graphic, "DEED_YEAR") + "</td>");
             s.push("<td>Total Value:</td><td class=\"b\">" + dojo.currency.format(totalval, { currency: "USD", places: 0 }) + "</td></tr>");
             s.push("<tr><td>Heated Sq Footage:</td><td>" + getGraphicAttribute(graphic, "HT_SQ_FEET") + "</td>");
             s.push("<td>Year Built:</td><td class=\"b\">" + getGraphicAttribute(graphic, "YEAR_BUILT") + "</td></tr>");
             s.push("<tr><td>Sale Price:</td><td>" + dojo.currency.format(salePrice, { currency: "USD", places: 0 }) + "</td>");
             s.push("<td>Sale Date:</td><td class=\"b\">" + getGraphicAttribute(graphic, "SALE_DATE") + "</td></tr>");

             s.push("</table>");
             return s.join("");

         }
         
         function formatZoom(value) {

             return "<a href=\"#\" onmousedown=\"zoomToResultbyIndex(" + value + ")\"><img src=\"images/zoomtofeature.gif\"/></a>";

         }







function parcelQuery() {
    this.Owner = "";
    this.PID = "";
    this.cypar = "";
    this.account = 0;
//    this.HouseNum = "";
//    this.StreetName = "";
//    this.StreetDir = "";
//    this.StreetType = "";

    // advanced search
    this.township = "";
    //this.city = "";
    
    this.toYear = "";
    this.fromYear = "";
    this.toMonth = "";
    this.fromMonth = "";
    this.startDate = "";
    
    this.minvalue = 0;
    this.maxvalue = 0;
    
    this.minacreage = 0;
    this.maxacreage = 0;
    
    this.maxsaleprice = 0;
    this.minsaleprice = 0;

    this.minyearbuilt = "";
    this.maxyearbuilt = "";

    this.minsqfootage = "";
    this.maxsqfootage = "";
    
    
    
//    this.impval = "";
    this.landuse = "";
    this.book = "";
    this.page = "";

    // buffer
    this.x = 0;
    this.y = 0;
    this.selectedPID = "";
    this.radius = 0;


    this.clearQuery = function() {

        this.Owner = "";
        this.PID = "";
        this.account = 0;
        //        this.HouseNum = "";
        //        this.StreetName = "";
        //        this.StreetDir = "";
        //        this.StreetType = "";

        // buffer
        this.x = 0;
        this.y = 0;
        this.selectedPID = "";
        this.radius = 0;

        // advanced search
        this.township = "";
        //this.city = "";
        this.minvalue = 0;
        this.maxvalue = 0;
        this.toYear = "";
        this.fromYear = "";
        this.toMonth = "";
        this.fromMonth = "";
        this.startDate = "";
        this.minacreage = 0;
        this.maxacreage = 0;
        //this.impval = "";
        this.landuse = "";
        this.book = "";
        this.page = "";
    }

    this.getOwnerWhereClause = function() {
        var wherePart = [];

        if (this.Owner != "") {
            wherePart.push("OWNER LIKE '" + this.Owner + "%'");
        }
        return wherePart.join("");
    }

    this.getAccountNumQuery = function() {

    //var swhere = "(ACCOUNT_NUMBER = " + this.account + ") OR (ACCOUNT_NUMBER LIKE %" + this.account + "%)";
    var swhere = "ACCT_NUM = " + this.account;
        return swhere;
    }

    this.getCyparWhereClause = function() {
        var swhere = "CYPAR like '" + this.cypar + "%'";
        return swhere;
    }


    this.getPIDWhereClause = function() {
        var swhere = "PIN like '" + this.PID + "%'";
        return swhere;
    }


    this.getAdvancedWhereClause = function() {

        var sWhere = [];

        // Fields in Advanced Search:
        var townshipFieldName = "TOWN_CODE";
        var totalValFieldName = "TOTAL_VALUE";
        var acreageFieldname = "DEED_ACRES";
        var saleDateFieldName = "SALE_DATE";
        var salePriceFieldName = "SALE_PRICE";
        var luFieldName = "PROP_CLASS";
        var acctnumFieldName = "ACCT_NUM";
        var yearBuiltFieldName = "YEAR_BUILT";
        var sqfootageFieldName = "HT_SQ_FT";





        // acreage
        if (this.minacreage == "")
            this.minacreage = 0;

        if ((this.minacreage > 0) && (this.minacreage != "") && (this.minacreage != 9999)) {
            sWhere.push("(" + acreageFieldname + ">=" + this.minacreage + ")");
        }

        if ((this.maxacreage > 0) && (this.maxacreage != "") && (this.maxacreage != 9999)) {
            if (sWhere.length > 0) sWhere.push(" AND ");
            sWhere.push("(" + acreageFieldname + "<=" + this.maxacreage + ")");
        }

        if (this.startDate != "") {
            //alert("Start date is: " + this.startDate);

            if (sWhere.length > 0) sWhere.push(" AND ");
            sWhere.push("(" + saleDateFieldName + " >= '" + this.startDate + "')");
        }

        // total value
        if ((this.maxvalue > 0) && (this.maxvalue != "")) {
            if (sWhere.length > 0) sWhere.push(" AND ");
            sWhere.push("(" + totalValFieldName + " <= " + this.maxvalue + ")");
        }

        // total value
        if ((this.minvalue > 0) && (this.minvalue != "")) {
            if (sWhere.length > 0) sWhere.push(" AND ");
            sWhere.push("(" + totalValFieldName + " >= " + this.minvalue + ")");
        }


        // sale price
        if ((this.minsaleprice > 0) && (this.minsaleprice != 9999)) {
            if (sWhere.length > 0) sWhere.push(" AND ");
            sWhere.push("(" + salePriceFieldName + " >= " + this.minsaleprice + ")");
        }

        if ((this.maxsaleprice > 0) && (this.maxsaleprice != 9999)) {
            if (sWhere.length > 0) sWhere.push(" AND ");
            sWhere.push("(" + salePriceFieldName + " <= " + this.maxsaleprice + ")");
        }

        // year built
        if (this.minyearbuilt != "") {
            if (sWhere.length > 0) sWhere.push(" AND ");
            sWhere.push("(" + yearBuiltFieldName + ">=" + this.minyearbuilt + ")");
        }

        // year built
        if (this.maxyearbuilt != "") {
            if (sWhere.length > 0) sWhere.push(" AND ");
            sWhere.push("(" + yearBuiltFieldName + "<=" + this.maxyearbuilt + ")");
        }

        if (this.minsqfootage != "") {
            if (sWhere.length > 0) sWhere.push(" AND ");
            sWhere.push("(" + sqfootageFieldName + ">=" + this.minsqfootage + ")");
        }

        if (this.maxsqfootage != "") {
            if (sWhere.length > 0) sWhere.push(" AND ");
            sWhere.push("(" + sqfootageFieldName + "<=" + this.maxsqfootage + ")");
        }


        // Land use code
        if (this.landuse != "") {
            if (sWhere.length > 0) sWhere.push(" AND ");
            sWhere.push("(" + luFieldName + " IN (" + this.landuse + "))");
        }

        //alert(sWhere.join(""));

        return sWhere.join("");
    }

}



