﻿// Additional references can be found from http://www.hunlock.com/blogs/Mastering_JSON_(_JavaScript_Object_Notation_)

function iecheck() {
  if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
    var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
    var iever = (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) <= 7 );
  }
  return iever;
}

function importJavascript(asFileName)
{
   lsFile = "http://www.aoa.gov/AoAroot/Site_Utilities/widget/Statistic/";
   // lsFile = "http://localhost/AoAroot/Site_Utilities/widget/Statistic/";

    
    lsFile += asFileName;
    lsURL = "<script type='text/javascript' src='" + lsFile;
    lsURL += "'></scr" + "ipt> "; 

    document.write(lsURL);

}  

MyXssMagic = new function() 
{
 var BASE_URL = 'http://www.aoa.gov/AoAroot/Site_Utilities/Widget/'; 
 //var BASE_URL = 'http://localhost/AoAroot/Site_Utilities/Widget/';   
  
  var STYLESHEET = BASE_URL + "Statistic/aoa_statistic_widget_2011.css"
  var CONTENT_URL = BASE_URL + "Statistic/json_statistic_data.js";
  var ROOT = 'start_stats_widget';
  var now = new Date();
  
  var currentMonth = now.getMonth();
  var gsImageFolder = "Statistic/images/";
  
  var logoimage = "<div id='aoa_statistic_wrapper'>";
      logoimage += "<div id='aoa_statistic_top'><img src= '" + BASE_URL;
      logoimage += gsImageFolder + "stats_widget_headerSM.gif' alt='AoA Statisical Widget' /></div>";
        logoimage += "<div id='aoa_statistic_mid' >";
        logoimage += "<div id='aoa_statistic_left' >";
        logoimage += "<div id='aoa_statistic_center' >";
        logoimage += "<span id='aoa_statistic_title'>Place your title here</span><br /><br />";
        logoimage += "<a href= '" + currentMonth + ".gif '>";
        logoimage += "<img id='aoa_stats_image' src= '" + BASE_URL;
        logoimage += gsImageFolder + "clear.gif' title='Click for more information' alt='BOO'/></a>";
        logoimage += "<br />";
        logoimage += "<span id='aoa_statistic_footnote'>Insert additional body text here</span>"; 
        logoimage += "</div>";// closes center div
        logoimage += "</div>";// closes left div
        logoimage += "</div>";// closes mid div
        logoimage += "<div style='clear:both'></div>";//clears mid div
        logoimage += "<div id='aoa_statistic_bottom'>";
       
        /* ---------------------------------------------------------*/
        /*    StatsBackOne is function from json_statistic_data.js  */
        /*   PREVIOUS BUTTON     */
        /* ---------------------------------------------------------*/
		logoimage +=  "<a href='#' onClick='StatsBackOne();return false'";
		logoimage += "id='aoa_stats_prevbtn'> <img src= '" + BASE_URL;
		logoimage += gsImageFolder +  "prev_orgbtn.gif'alt='Previous Button'"; 
		logoimage += " title='Click to see previous'/></a>";
       
        logoimage +=  "<a href='" + BASE_URL +"index.aspx'>"; 
        logoimage += " <img src= '" + BASE_URL + gsImageFolder + "share_orgbtn.gif' ";
        logoimage += " id='aoa_stats_sharebtn' alt='Share Button' title='Click to reveal widget code'/></a>";
      
       // INFO BUTTON back and uncomment lines in json_statisic_data.js
       //logoimage +=  "<a href='REPLACEBYJSON'>";
       //logoimage += "<img src= '" + BASE_URL + gsImageFolder + "info_orgbtn.gif'"; 
       //logoimage += " id='aoa_stats_infobtn' title='Click for more information'/></a>";
        
        /* ---------------------------------------------------------*/
        /*    StatsForwardOne is function from json_statistic_data.js  */
        /*    NEXT BUTTON         */
        /* ---------------------------------------------------------*/
        logoimage += "<a href='#' onClick='StatsForwardOne();return false' ";
        logoimage += " id='aoa_stats_nextbtn'> <img src= '" + BASE_URL;
        logoimage += gsImageFolder + "next_orgbtn.gif' alt='Next Button' ";
        logoimage += " title='Click to see next'/></a>";
        
        
        logoimage +=  "</div>";// closes bottom div
        logoimage +=  "</div>";// closes wrapper div
 //link the stylesheet to the page
 function requestStylesheet(stylesheet_url) 
 {
    stylesheet = document.createElement("link");
    stylesheet.rel = "stylesheet";
    stylesheet.type = "text/css";
    stylesheet.href = stylesheet_url;
    stylesheet.media = "all";
    document.lastChild.firstChild.appendChild(stylesheet);
  }
  
  //this script is currently not being used because it is manually placed in the homepage
  function requestContent( local ) 
  {
    var script = document.createElement("script");
    script.src = CONTENT_URL;
    // IE7 doesn't like this: document.body.appendChild(script);
    // Instead use:
    document.getElementsByTagName('head')[0].appendChild(script);
  }
    requestStylesheet(STYLESHEET); 
    document.write("<div id='" + ROOT + "' visible='true'></div>");    
    
//    requestContent();

    document.getElementById(ROOT).innerHTML = logoimage; //write out interface inside ROOT ID
    document.getElementById('aoa_statistic_title').innerHTML = "Living Today for a Better Tomorrow - Healthy Living Tips";

 curYearStatTip = "currentYearStats.js";
 prevYearStatTip = "previousYearStats.js";
 
 importJavascript(prevYearStatTip);
 importJavascript(curYearStatTip);

}







