﻿//variable to store hidden frame
var printingHiddenFrame;

//on load, create a hidden frame for printing the map
dojo.addOnLoad(function() {
    printingHiddenFrame = document.createElement("iframe");
    printingHiddenFrame.src = "hiddenframe.html";
    dojo.style(printingHiddenFrame, "display", "none");
    dojo.body().appendChild(printingHiddenFrame);
});


dojo.require("com.js.printing.utils");

//serialize the map's state and call layout.* through iframe
function printMap() {

    var state = {
        map: com.js.printing.getMapState(map),
        height: 600,
        width: 800,
        pid: -1,
        scale: com.js.printing.getMapScale(map)
    }

    var iframeDocument = dojo.isIE ? printingHiddenFrame.contentWindow.document : printingHiddenFrame.contentDocument;
    iframeDocument.getElementById("appState").value = dojo.toJson(state);
    iframeDocument.getElementById("form").submit();
}

function printQuickReport(pid) {

    var queryTask = new esri.tasks.QueryTask(searchURL + "/" + custom.parcels.layerID);
    var query = new esri.tasks.Query();
    query.where = "Parcel_ID = '" + pid + "'";
    query.outFields = custom.parcels.returnFields;
    query.returnGeometry = true;

    //Execute task and call showResults on completion
    queryTask.execute(query, function(results) {
        var graphic = results.features[0];


        var state = {
            map: com.js.printing.getMapState(map),
            height: 440,
            width: 660,
            pid: pid,
            data: graphic.toJson(),
            scale: com.js.printing.getMapScale(map),
            searchURL: parcelSearchLayerURL
        }

        var iframeDocument = dojo.isIE ? printingHiddenFrame.contentWindow.document : printingHiddenFrame.contentDocument;
        iframeDocument.getElementById("appState").value = dojo.toJson(state);
        iframeDocument.getElementById("form").submit();
    });
}


