﻿// ************************************************************
// CitySourced Widget Javascript Include - IFRAME'd Version
// By Jason Kiesel (/member/jason)
// Copyright (c) 2012 CitySourced, Inc.
// ************************************************************

// ************************************************************
// Global Variables - These CAN be overridden...
var csWidgetIframeBorder = "0";
var csWidgetIframeHeight = "100%";
var csWidgetIframeScrolling = "no";
var csWidgetIframeWidth = "100%";
var host = "http://www.citysourced.com";

// ************************************************************
// Shared Functions - Writes the IFRAME Html...
function csWidgetIframeWriteHtml(url) {
    var html = "<iframe src='" + url +
	    "' frameborder='" + csWidgetIframeBorder +
	    "' height='" + csWidgetIframeHeight +
	    "' width='" + csWidgetIframeWidth +
	    "' scrolling='" + csWidgetIframeScrolling +
	    "'></iframe>";
    document.write(html);
}

// ************************************************************
// Public Functions - Read Widgets (GET REPORTS)...
function csWidgetIframeReportsAsMap(boundaryId, mapWidth, mapHeight, mapId, mapType, mapDashboardSize, cacheKey) {
    var csUrlReportsAsMap = host + "/widgets/1_0/reportsasmap.aspx" +
        "?boundaryid=" + boundaryId +
        "&mapid=" + mapId +
        "&mapwidth=" + mapWidth +
        "&mapheight=" + mapHeight +
        "&maptype=" + mapType +
        "&mapdashboardsize=" + mapDashboardSize +
        "&parenturl=" + encodeURIComponent(document.location) +
        "&cachekey=" + cacheKey;
    csWidgetIframeWriteHtml(csUrlReportsAsMap);
}
function csWidgetIframeReportsByCustomerId(customerId, mapId, mapWidth, mapHeight, mapLat, mapLng, mapType, mapDashboardSize, mapZoom, cacheKey) {
    var csUrlReportsByCustomerId = host + "/widgets/1_0/reportsbycustomerid.aspx" +
        "?customerid=" + customerId +
        "&mapid=" + mapId +
        "&mapwidth=" + mapWidth +
        "&mapheight=" + mapHeight +
        "&maplat=" + mapLat +
        "&maplng=" + mapLng +
        "&maptype=" + mapType +
        "&mapdashboardsize=" + mapDashboardSize +
        "&mapzoom=" + mapZoom +
        "&parenturl=" + encodeURIComponent(document.location) +
        "&cachekey=" + cacheKey;
    csWidgetIframeWriteHtml(csUrlReportsByCustomerId);
}
function csWidgetIframeReportsByCustomerIdUnbranded(customerId, mapId, mapWidth, mapHeight, mapLat, mapLng, mapType, mapDashboardSize, mapZoom, cacheKey) {
    var csUrlReportsByCustomerIdUnbranded = host + "/widgets/1_0/reportsbycustomerid.aspx" +
        "?customerid=" + customerId +
        "&mapid=" + mapId +
        "&mapwidth=" + mapWidth +
        "&mapheight=" + mapHeight +
        "&maplat=" + mapLat +
        "&maplng=" + mapLng +
        "&maptype=" + mapType +
        "&mapdashboardsize=" + mapDashboardSize +
        "&mapzoom=" + mapZoom +
        "&parenturl=" + encodeURIComponent(document.location) +
        "&cachekey=" + cacheKey +
        "&unbranded=true";
    csWidgetIframeWriteHtml(csUrlReportsByCustomerIdUnbranded);
}

// ************************************************************
// Public Functions - Write Widgets (CREATE REPORTS)...
function csWidgetIframeReportCreate(mapId, mapWidth, mapHeight, mapLat, mapLng, mapType, mapDashboardSize, mapZoom, cacheKey) {
    var csUrlReportCreate = host + "/widgets/1_0/reportcreate.aspx" +
        "?mapid=" + mapId +
        "&mapwidth=" + mapWidth +
        "&mapheight=" + mapHeight +
        "&maplat=" + mapLat +
        "&maplng=" + mapLng +
        "&maptype=" + mapType +
        "&mapdashboardsize=" + mapDashboardSize +
        "&mapzoom=" + mapZoom +
        "&parenturl=" + encodeURIComponent(document.location) +
        "&cachekey=" + cacheKey;
    csWidgetIframeWriteHtml(csUrlReportCreate);
}
function csWidgetIframeReportCreateByCustomerId(customerId, mapId, mapWidth, mapHeight, mapLat, mapLng, mapType, mapDashboardSize, mapZoom, cacheKey) {
    var csUrlReportCreateByCustomerId = host + "/widgets/1_0/reportcreate.aspx" +
        "?customerid=" + customerId +
        "&mapid=" + mapId +
        "&mapwidth=" + mapWidth +
        "&mapheight=" + mapHeight +
        "&maplat=" + mapLat +
        "&maplng=" + mapLng +
        "&maptype=" + mapType +
        "&mapdashboardsize=" + mapDashboardSize +
        "&mapzoom=" + mapZoom +
        "&parenturl=" + encodeURIComponent(document.location) +
        "&cachekey=" + cacheKey;

    csWidgetIframeWriteHtml(csUrlReportCreateByCustomerId);
}
function csWidgetIframeReportCreateByCustomerIdUnbranded(customerId, mapId, mapWidth, mapHeight, mapLat, mapLng, mapType, mapDashboardSize, mapZoom, cacheKey) {
    var csUrlReportCreateByCustomerIdUnbranded = host + "/widgets/1_0/reportcreate.aspx" +
        "?customerid=" + customerId +
        "&mapid=" + mapId +
        "&mapwidth=" + mapWidth +
        "&mapheight=" + mapHeight +
        "&maplat=" + mapLat +
        "&maplng=" + mapLng +
        "&maptype=" + mapType +
        "&mapdashboardsize=" + mapDashboardSize +
        "&mapzoom=" + mapZoom +
        "&parenturl=" + encodeURIComponent(document.location) +
        "&cachekey=" + cacheKey +
        "&unbranded=true";
    csWidgetIframeWriteHtml(csUrlReportCreateByCustomerIdUnbranded);
}
