﻿function MapPageRender(containerId) 
{
    var container = document.getElementById(containerId);

    var str = "";
    str += "<input id=\"SelectedRegionHF\" type=\"hidden\" value=\"-1\" />";
    str += "<table width=\"100%\" height=\"100%\">";
    str += "<tr height=\"100%\">";
    str += "<td style=\"padding:0px\">";

    str += "<table width=\"100%\" height=\"100%\">";
    str += "<tr height=\"100%\">";
    //str += "<tr style=\"background-color:#0000FF;\">";
    str += "<td id=\"MapContainer\">";
    str += GetMapHTML();
    str += "</td>";
    str += "</tr>";
    str += "<tr height=\"100px\" align=\"center\">";
    str += "<td id=\"LegendContainer\">";
    str += GetLegendHTML();
    str += "</td>";
    str += "</tr>";
    str += "</table>";
    
    str += "</td>";
    str += "<td width=\"350px\" valign=\"top\">";
    
    str += "<table width=\"100%\" height=\"100%\">";
    str += "<tr>";
    str += "<td align=\"center\" valign=\"top\">";

    str += "<table>";
    str += "<tr>";
    str += "<td id=\"CheckerContainer\">";
    str += GetCheckerHTML();
    str += "</td>";
    str += "</tr>";
    str += "<tr>";
    str += "<td id=\"ComboBoxContainer\" class=\"mapPageText\">";
    str += "Indicator: <br/>";
    str += GetComboBoxHTML();
    str += "</td>";
    str += "</tr>";
    str += "</table>";
    
    str += "</td>";
    str += "</tr>";
    str += "<tr height=\"250px\">";
    str += "<td id=\"Diagram1Container\">";
    str += GetDiagram1HTML();
    str += "</td>";
    str += "</tr>";
    str += "<tr height=\"250px\">";
    str += "<td id=\"Diagram2Container\">";
    str += GetDiagram2HTML();
    str += "</td>";
    str += "</tr>";
    str += "<tr height=\"100%\">";
    str += "<td>";
    str += "</td>";
    str += "</tr>";
    str += "</table>"; 
    
    str += "</td>";
    str += "</tr>";  
    str += "</table>";
    container.innerHTML = str;
    LoadDiagram1();
    LoadDiagram2();
    LoadMap();
    LoadLegend();
}

function LoadScript(url) 
{
    var newScript = document.createElement('script');
    newScript.src = url;
    newScript.type = "text/javascript";
    document.body.appendChild(newScript);
}

var map1 = null; 

function LoadMap() 
{
    var modeCheckerHF = document.getElementById('ModeCheckerHF');
    var year = "2007";
    if (modeCheckerHF.value == "2") { year = "2006"; }
    if ((modeCheckerHF.value == "4") || (modeCheckerHF.value == "5")) { year = "2008"; }
    var indicatorComboHF = document.getElementById('IndicatorComboHF');
    var f = {};
    f.width = '100%'; 
    f.height = '100%';
	f.allowScriptAccess = 'sameDomain';
	f.allowFullScreen='false';
    f.movie = 'swf/FlashMapEngine.swf?topBase=swf/Georgia.swf';
    f.wmode='opaque';
    f.flashvars = "disableProgressIndication=true&registerWithJS=1&dataURL=Reporting/MapXML.ashx?params=" + year + "," + indicatorComboHF.value + "";
    f.id = 'map1';
    f.menu = 'false';
    insertFlashToId(f, 'MapContainer');
    map1 = document.getElementById('map1');
    //map1 = thisMovie("map1");
}

function mapClick(region)
{
    toStateInfo(region);
}

function mouseOverStates(region) 
{
    clearInterval(ChartTimerId);
    ChartTimerId = setInterval("timerUpdate()", 10000);
    document.getElementById("SelectedRegionHF").value = region;
    LoadDiagram2();
}

ChartTimerId = null;

function timerUpdate() 
{
    if (document.getElementById("SelectedRegionHF") == null) 
    {
        clearInterval(ChartTimerId);
        return;
    }
    var reg = parseInt(document.getElementById("SelectedRegionHF").value);
    reg += 2;
    if (reg >= 13321) 
    {
        reg = 13001;
    }
    mouseOverStates(reg);
}

function GetMapHTML() 
{
    var res = "";
    
    return (res);
}

function LoadLegend() 
{
    var modeCheckerHF = document.getElementById('ModeCheckerHF');
    var year = "2007";
    if (modeCheckerHF.value == "2") { year = "2006"; }
    if ((modeCheckerHF.value == "4") || (modeCheckerHF.value == "5")) { year = "2008"; }
    var indicatorComboHF = document.getElementById('IndicatorComboHF');
    LoadScript("reporting/RenderLegendScript.ashx?params=" + year + "," + indicatorComboHF.value); 
}

function GetLegendHTML() 
{
    var res = "";

    return (res);
}

function CheckModeItem(item) {
    var item1 = document.getElementById('CheckerItem1');
    var item2 = document.getElementById('CheckerItem2');
    var item3 = document.getElementById('CheckerItem3');
    var item4 = document.getElementById('CheckerItem4');
    var item5 = document.getElementById('CheckerItem5');
    var hf = document.getElementById('ModeCheckerHF');
    if (hf != null) {
        if (hf.value == item) { return; }
        hf.value = item;
        this.className = 'factCaptionSelected';
        if (item1 != null) {
            if (item == 1) {
                item1.className = 'factCaptionSelected';
                item1.style.textDecoration = '';
            }
            else {
                item1.className = 'factCaptionUnSelected';
            }
        }
        if (item2 != null) {
            if (item == 2) {
                item2.className = 'factCaptionSelected';
                item2.style.textDecoration = '';
            }
            else {
                item2.className = 'factCaptionUnSelected';
            }
        }
        if (item3 != null) {
            if (item == 3) {
                item3.className = 'factCaptionSelected';
                item3.style.textDecoration = '';
            }
            else {
                item3.className = 'factCaptionUnSelected';
            }
        }
        if (item4 != null) {
            if (item == 4) {
                item4.className = 'factCaptionSelected';
                item4.style.textDecoration = '';
            }
            else {
                item4.className = 'factCaptionUnSelected';
            }
        }
        if (item5 != null) {
            if (item == 5) {
                item5.className = 'factCaptionSelected';
                item5.style.textDecoration = '';
            }
            else {
                item5.className = 'factCaptionUnSelected';
            }
        }
    }
    OnCheckerChanged();     
}

function OnCheckerChanged() 
{
    var modeCheckerHF = document.getElementById('ModeCheckerHF');
    var indicatorsCombo = document.getElementById('IndicatorsCombo');
    var indicatorComboHF = document.getElementById('IndicatorComboHF');
    if (indicatorsCombo == null) { return; }
    var comboBoxItem1 = document.getElementById('comboBoxItem1');
    var comboBoxItem2 = document.getElementById('comboBoxItem2');
    var comboBoxItem3 = document.getElementById('comboBoxItem3');
    var comboBoxItem4 = document.getElementById('comboBoxItem4');
    var comboBoxItem5 = document.getElementById('comboBoxItem5');
    var comboBoxItem6 = document.getElementById('comboBoxItem6');
    if ((modeCheckerHF == null) || ((modeCheckerHF.value != '3') && (modeCheckerHF.value != '5'))) 
    {
       
        comboBoxItem1.value = "1";
        comboBoxItem1.innerHTML = "Expenditures";
        if (comboBoxItem1.selected) { indicatorComboHF.value = "1"; }
        comboBoxItem2.value = "2";
        comboBoxItem2.innerHTML = "Payroll";
        if (comboBoxItem2.selected) { indicatorComboHF.value = "2"; }
        comboBoxItem3.value = "3";
        comboBoxItem3.innerHTML = "Employment";
        if (comboBoxItem3.selected) { indicatorComboHF.value = "3" }
        comboBoxItem4.value = "4";
        comboBoxItem4.innerHTML = "State Tax Receipts";
        if (comboBoxItem4.selected) { indicatorComboHF.value = "4"; }
        comboBoxItem5.value = "5";
        comboBoxItem5.innerHTML = "Local Tax Receipts";
        if (comboBoxItem5.selected) { indicatorComboHF.value = "5"; }
        comboBoxItem6.value = "11";
        comboBoxItem6.innerHTML = "Employment Share of Total Private Employment";
        if (comboBoxItem6.selected) { indicatorComboHF.value = "11"; }
    }
    else 
    {
        comboBoxItem1.value = "6";
        comboBoxItem1.innerHTML = "Expenditures";
        if (comboBoxItem1.selected) { indicatorComboHF.value = "6"; }
        comboBoxItem2.value = "7";
        comboBoxItem2.innerHTML = "Payroll";
        if (comboBoxItem2.selected) { indicatorComboHF.value = "7"; }
        comboBoxItem3.value = "8";
        comboBoxItem3.innerHTML = "Employment";
        if (comboBoxItem3.selected) { indicatorComboHF.value = "8"; }
        comboBoxItem4.value = "9";
        comboBoxItem4.innerHTML = "State Tax Receipts";
        if (comboBoxItem4.selected) { indicatorComboHF.value = "9"; }
        comboBoxItem5.value = "10";
        comboBoxItem5.innerHTML = "Local Tax Receipts";
        if (comboBoxItem5.selected) { indicatorComboHF.value = "10"; }
        comboBoxItem6.value = "12";
        comboBoxItem6.innerHTML = "Employment Share of Total Private Employment";
        if (comboBoxItem6.selected) { indicatorComboHF.value = "12"; }
    }
    LoadDiagram1();
    LoadDiagram2();
    LoadMap();
    LoadLegend();
}

function GetCheckerHTML() 
{
    var res = "";
    var js = "";
        
    res += "<input id=\"ModeCheckerHF\" type=\"hidden\" value=\"4\"/>";
    
    res += "<table style=\"border-collapse: collapse\">";
    res += "<tr>";
    res += "<td style=\"padding-right: 4px; border-right-style:solid; border-right-width:1px;\" align=\"center\">";
    js = "CheckModeItem(4);";
    res += "<div id=\"CheckerItem4\" style=\"padding:2px;\" class=\"factCaptionSelected\"  onmouseover=\"if(this.className == 'factCaptionUnSelected') {this.style.textDecoration = 'underline';}\" onmouseout=\"this.style.textDecoration = '';\" onclick=\"" + js + "\">";
    res += "2008";
    res += "</div>";
    res += "</td>";
    res += "<td style=\"padding-right: 4px; border-right-style:solid; border-right-width:1px;\" align=\"center\">";
     js = "CheckModeItem(1);";
    res += "<div id=\"CheckerItem1\" style=\"padding:2px;\" class=\"factCaptionUnSelected\"  onmouseover=\"if(this.className == 'factCaptionUnSelected') {this.style.textDecoration = 'underline';}\" onmouseout=\"this.style.textDecoration = '';\" onclick=\"" + js + "\">";
    res += "2007";
    res += "</div>";
    res += "</td>";
    res += "<td style=\"padding-left: 4px; padding-right: 4px; border-right-style:solid; border-right-width:1px;\" align=\"center\">";
     js = "CheckModeItem(2);";
    res += "<div id=\"CheckerItem2\" style=\"padding:2px;\" class=\"factCaptionUnSelected\" onmouseover=\"if(this.className == 'factCaptionUnSelected') {this.style.textDecoration = 'underline';}\" onmouseout=\"this.style.textDecoration = '';\" onclick=\"" + js + "\">";
    res += "2006";
    res += "</div>";
    res += "</td>";
    res += "<td style=\"padding-left: 4px; padding-right: 4px; border-right-style:solid; border-right-width:1px;\" align=\"center\">";
    js = "CheckModeItem(5);";
    res += "<div id=\"CheckerItem5\" style=\"padding:2px;\" class=\"factCaptionUnSelected\" onmouseover=\"if(this.className == 'factCaptionUnSelected') {this.style.textDecoration = 'underline';}\" onmouseout=\"this.style.textDecoration = '';\" onclick=\"" + js + "\">";
    res += "2008/2007";
    res += "</div>";
    res += "</td>";
    res += "<td style=\"padding-left: 4px;\" align=\"center\">";
     js = "CheckModeItem(3);";
    res += "<div id=\"CheckerItem3\" style=\"padding:2px;\" class=\"factCaptionUnSelected\" onmouseover=\"if(this.className == 'factCaptionUnSelected') {this.style.textDecoration = 'underline';}\" onmouseout=\"this.style.textDecoration = '';\" onclick=\"" + js + "\">";
    res += "2007/2006";
    res += "</div>";
    res += "</td>";
    res += "</tr>";
    res += "</table>";
    return (res);    
}

function comboSelectedItemChanged() 
{
    LoadDiagram1();
    LoadDiagram2();
    LoadMap();
    LoadLegend();
}

function GetComboBoxHTML() 
{
    var modeCheckerHF = document.getElementById('ModeCheckerHF');
    var res = "";
    res += "<input id=\"IndicatorComboHF\" type=\"hidden\" value=\"1\"/>"
    var js = "var hf = document.getElementById('IndicatorComboHF'); hf.value=value; comboSelectedItemChanged();";
    res += "<select id=\"IndicatorsCombo\" onchange=\""+js+"\" >";
    if ((modeCheckerHF == null) || ((modeCheckerHF.value != '3') && (modeCheckerHF.value != '5'))) 
    {
        res += "<option id=\"comboBoxItem1\" value=\"1\" selected=\"true\">Expenditures</option>";
        res += "<option id=\"comboBoxItem2\" value=\"2\">Payroll</option>";
        res += "<option id=\"comboBoxItem3\" value=\"3\">Employment</option>";
        res += "<option id=\"comboBoxItem4\" value=\"4\">State Tax Receipts</option>";
        res += "<option id=\"comboBoxItem5\" value=\"5\">Local Tax Receipts</option>";
        res += "<option id=\"comboBoxItem6\" value=\"11\">Employment Share of Total Private Employment</option>";
    }
    else 
    {
        res += "<option id=\"comboBoxItem1\" value=\"6\" selected=\"true\">Expenditures</option>";
        res += "<option id=\"comboBoxItem2\" value=\"7\">Payroll</option>";
        res += "<option id=\"comboBoxItem3\" value=\"8\">Employment</option>";
        res += "<option id=\"comboBoxItem4\" value=\"9\">State Tax Receipts</option>";
        res += "<option id=\"comboBoxItem5\" value=\"10\">Local Tax Receipts</option>";
        res += "<option id=\"comboBoxItem6\" value=\"12\">Employment Share of Total Private Employment</option>";
    }
    res += "</select>";
    return (res);
}

function LoadDiagram1() 
{
    var modeCheckerHF = document.getElementById('ModeCheckerHF');
    var year = "2007";
    if (modeCheckerHF.value == "2") { year = "2006"; }
    if ((modeCheckerHF.value == "4") || (modeCheckerHF.value == "5")) { year = "2008"; }
    var indicatorComboHF = document.getElementById('IndicatorComboHF');
    
    var StolbicChart = new FusionCharts("swf/MSColumn2D.swf", "Stolbic", "350px", "250px", "0", "0");
    StolbicChart.setDataURL("Reporting/Diagram1XML.ashx?params=" + year + "," + indicatorComboHF.value);
    StolbicChart.render("Diagram1Container");
}

function GetDiagram1HTML() 
{
    var res = "";

    return (res);
}

function LoadDiagram2() 
{
    var selectedRegionHF = document.getElementById('SelectedRegionHF');
    var modeCheckerHF = document.getElementById('ModeCheckerHF');
    var year = "2007";
    if (modeCheckerHF.value == "2") { year = "2006"; }
    if ((modeCheckerHF.value == "4") || (modeCheckerHF.value == "5")) { year = "2008"; }
    var indicatorComboHF = document.getElementById('IndicatorComboHF');

    var StolbicChart = new FusionCharts("swf/MSColumn2D.swf", "Stolbic2", "350px", "250px", "0", "0");
    StolbicChart.setDataURL("Reporting/Diagram2XML.ashx?params=" + year + "," + indicatorComboHF.value + "," + selectedRegionHF.value);
    StolbicChart.render("Diagram2Container");
}

function GetDiagram2HTML() 
{
    var res = "";
    
    return (res);
}

function callLegendMouseOver(e) {
    var box = document.getElementById("MapContainer");
    var map = findElem(box, "map1");
    if (map == null) {
        map = document.getElementById("map1");
    }
    map.LegendItemMouseOver(e);
}

function callLegendMouseOut(e) {
    var box = document.getElementById("MapContainer");
    var map = findElem(box, "map1");
    if (map == null) {
        map = document.getElementById("map1");
    }
    map.LegendItemMouseOut(e);
}

function findElem(parent, id) {
    for (var i = 0; i < parent.childNodes.length; i++) {
        if ((parent.childNodes[i].id == id) && (parent.childNodes[i].nodeName.toUpperCase() == "EMBED")) {
            return (parent.childNodes[i]);
        }
        else {
            var res = findElem(parent.childNodes[i], id);
            if (res != null) {
                return (res);
            }
        }
    }
    return (null);
}

function thisMovie(movieName) 
{
    //if (navigator.appName.indexOf("Microsoft") != -1) {
    //    return window[movieName]
    //}
    //else {
    //    return document[movieName]
    //}
    return(document.getElementById('map1'));
}