// JavaScript Document

function initPopups() {
	var links = getElementsByClassName('a', 'tooltiplink');
	for (i=0; i < links.length; i++) {
		var a = links[i];
		a.setAttribute("aria-describedby", "popup" + a.id);
		a.onmouseover = function(event){tooltipShow(event, this);};
		a.onfocus = function(event){tooltipShow(event, this);};
		var popup = createPopup(a.id);
		insertAfter(popup, a);
	}
}


function createPopup(id) {
	var div = document.createElement("div");
	div.style.display = "none";
	div.className = "popup";
	div.id = "popup" + id;
	div.setAttribute("role", "window");
	div.setAttribute("aria-hidden", true);
	var p = document.createElement("p");
	p.className = "loading";
	var img = document.createElement("img");
	img.setAttribute("role", "progressbar");
	img.setAttribute("aria-busy", true);
	img.setAttribute("alt", "");
	img.src = "../images/ajax-loader.gif";
	var br = document.createElement("br");
	var text = document.createTextNode("Loading data");
	p.appendChild(img);
	p.appendChild(br);
	p.appendChild(text);
	div.appendChild(p);
	return div;
}

/**
* tooltipShow show a tooltip
*
* @param ( event ) event object
* @param ( node ) node of the element associated with the event
* @param ( id ) id of the element to be used as a tooltip
*
* @return false
*/

function tooltipShow( event, node) {
	var e = event || window.event;

	var tooltip_id = 'popup' + node.id;
  var node_tooltip = document.getElementById(tooltip_id);

  showHandler();

  var firstElement = TPG.Dom.getFirstChild(node_tooltip);

  if (firstElement.className == "loading") {
    getPopupData(node_tooltip, tooltip_id);
  }
  return browser.stopPropagation( e );

  function showHandler( ) {
    node_tooltip.style.display = "block";
    node_tooltip.setAttribute("aria-hidden", "false");
    node_tooltip.setAttribute("aria-live", "polite");
    node_tooltip.setAttribute("aria-atomic", "true");

    browser.addEvent( node, "blur", hideHandler, true );
    browser.addEvent( node, "mouseout", hideHandler, true );
    browser.addEvent( node, "keydown", hideHandlerEsc, true );

  }

  function hideHandler( event ) {

    var e = event || window.event;

    node_tooltip.style.display = "none";
    node_tooltip.setAttribute("aria-hidden", "true");

    browser.removeEvent( node, "blur", hideHandler, true );
    browser.removeEvent( node, "mouseout", hideHandler, true );
    browser.removeEvent( node, "keydown", hideHandlerEsc, true );

    return browser.stopPropagation( e );

  }

  function hideHandlerEsc( event ) {

    var e = event || window.event;
      if (event.keyCode == 27) {
        node_tooltip.style.display = "none";
        node_tooltip.setAttribute("aria-hidden", "true");

        browser.removeEvent( node, "blur", hideHandler, true );
        browser.removeEvent( node, "mouseout", hideHandler, true );
        browser.removeEvent( node, "keydown", hideHandlerEsc, true );

        return browser.stopPropagation( e );
    }
  }
}

//widgets_inline.js

// JavaScript Document


if (!window.Node) {
  var Node = {            // If there is no Node object, define one
    ELEMENT_NODE: 1,    // with the following properties and values.
    ATTRIBUTE_NODE: 2,  // Note that these are HTML node types only.
    TEXT_NODE: 3,       // For XML-specific nodes, you need to add
    COMMENT_NODE: 8,    // other constants here.
    DOCUMENT_NODE: 9,
    DOCUMENT_FRAGMENT_NODE: 11
  }
}

var ARIA_STATE = "aria-";

/**
* Widgets Object is used to initialize a set of controls
* and provide a conveinence fuction to cancel event propagration
* @construtor
*/

function Widgets() {
  this.widgets = new Array();
}

/**
* add is member of the Widgets Object
* and used add a widget ot the list of widgets to be intitialized
* as part of the onload event
* The controls array is the list of controls to initialize
* @member Enable
* @return none
*/

Widgets.prototype.add = function(obj) {
  this.widgets[this.widgets.length] = obj;
}

/**
* init is member of the Widgets Object
* and is called by the onload event to initialize widgets in the web resource
* The controls array is the list of controls to initialize
* @member Enable
* @return none
*/

Widgets.prototype.init = function() {

   for(var i = 0; i < this.widgets.length; i++ )
     this.widgets[i].init();
}

//
// convience function for getting the node based on id

function _$( id ) {
  return document.getElementById( id );
}


//
// WebBrowser object to abstract accessibility API differences between web standards supporting browsers and Internet Explorer 7.0
//
// The state variable keeps track of current state of checkbox
function WebBrowser() {

}


//
// keyCode is a function to get the keycode from a keypress event
//
// @param ( event object) event is an event object
//
// @return ( keycode )

WebBrowser.prototype.keyCode = function( event ) {
  var e = event || window.event;

  return e.keyCode;
}

/**
* OnClick Event Simulator
*
* @param ( node ) DOM node object
* @return nothing
*/

if( document.createEvent ) {

  // If a web standards based browser implement this function

  WebBrowser.prototype.simulateOnClickEvent = function( node ) {
    // W3C DOM Events way to trigger a "click" event
    var e = document.createEvent('MouseEvents');
    e.initEvent( 'click', true, true );

    node.dispatchEvent( e );

  }

} else {

  // If a Microsoft IE based browser implement this function

  WebBrowser.prototype.simulateOnClickEvent = function( node ) {

    var e = document.createEventObject();
    node.fireEvent( "onclick", e );

  } // endif

}

if ( document.addEventListener ) {

  // If a web standards based browser implement this function

  WebBrowser.prototype.setMouseCapture = function( node, clickHandler, downHandler, moveHandler, upHandler ) {

    if( clickHandler )
      document.addEventListener( "click",     clickHandler, true );

    if( downHandler )
      document.addEventListener( "mousedown", downHandler,  true );

    if( moveHandler )
      document.addEventListener( "mousemove", moveHandler,  true );

    if( upHandler)
      document.addEventListener( "mouseup",   upHandler,    true );

  }

  WebBrowser.prototype.releaseMouseCapture = function( node, clickHandler, downHandler, moveHandler, upHandler ) {

  if( upHandler)
      document.removeEventListener( "mouseup",   upHandler,    true );

    if( moveHandler )
      document.removeEventListener( "mousemove", moveHandler,  true );

    if( downHandler )
      document.removeEventListener( "mousedown", downHandler,  true );

    if( clickHandler )
      document.removeEventListener( "click",     clickHandler, true );

  }

} else {

  // If a Microsoft IE based browser implement this function

  WebBrowser.prototype.setMouseCapture = function( node, clickHandler, downHandler, moveHandler, upHandler ) {

   node.setCapture();
   if( clickHandler)
     node.attachEvent( "onclick", clickHandler );

   if( downHandler)
     node.attachEvent( "onmousedown", downHandler );

   if( moveHandler )
     node.attachEvent( "onmousemove", moveHandler );

   if( upHandler )
     node.attachEvent( "onmouseup", upHandler );

  } // endif

  WebBrowser.prototype.releaseMouseCapture = function( node, clickHandler, downHandler, moveHandler, upHandler ) {

   if( upHandler )
     node.detachEvent( "onmouseup", upHandler );

   if( moveHandler )
     node.detachEvent( "onmousemove", moveHandler );

   if( downHandler)
     node.detachEvent( "onmousedown", downHandler );

   if( clickHandler)
     node.detachEvent( "onclick", clickHandler );

     node.releaseCapture();

  } // endif


}




if (typeof document.documentElement.setAttributeNS != 'undefined') {

  WebBrowser.prototype.stopPropagation = function( event ) {
    event.stopPropagation();
    event.preventDefault();
    return false;
  }

  WebBrowser.prototype.target = function( event ) {
  return event.target;
  }

  WebBrowser.prototype.attrName = function( event ) {
  return event.attrName
  }

  WebBrowser.prototype.charCode = function(event) {
     return event.charCode;
  }

  WebBrowser.prototype.calculateOffsetLeft = function( node ) {
  return node.offsetLeft;
  }

  WebBrowser.prototype.calculateOffsetTop = function( node ) {
  return node.offsetTop;
  }

  WebBrowser.prototype.pageX = function( e ) {
    return e.pageX;
  }

  WebBrowser.prototype.pageY = function( e ) {
    return e.pageY;
  }

  WebBrowser.prototype.setNodePosition = function(node,left,top) {
    node.style.left = left+"px";
    node.style.top = top+"px";
  }


} else {

  WebBrowser.prototype.stopPropagation = function( event ) {
    event.cancelBubble = true;
    event.returnValue = false;
    return false;
  }

  WebBrowser.prototype.charCode = function(event) {
    return window.browser.keyCode( event );
  }

  WebBrowser.prototype.target = function( event ) {
    return event.srcElement;
  }

  WebBrowser.prototype.attrName = function( event ) {
  return event.propertyName;
  }

  WebBrowser.prototype.calculateOffsetLeft = function(node) {
  var offset = 0;

  while( node ) {
    offset += node.offsetLeft;
    node = node.offsetParent;
  }

  return offset;
  }

  WebBrowser.prototype.calculateOffsetTop = function(node) {
  var offset = 0;

  while( node ) {
    offset = offset + node.offsetTop;
    node = node.offsetParent;
  }

  return offset;
  }

  WebBrowser.prototype.pageX = function( e ) {
    return e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft);
  }

  WebBrowser.prototype.pageY = function( e ) {
    return e.clientY + (document.documentElement.scrollTop || document.body.scrollTop);
  }

  WebBrowser.prototype.setNodePosition = function(node,left,top) {
    offsetx = 0;
    offsety = 0;
    nnode = node.offsetParent
    while( nnode ) {
      offsetx = offsetx + nnode.offsetLeft;
      offsety = offsety + nnode.offsetTop;
      nnode = nnode.offsetParent;
    }
    node.style.left = left-offsetx+"px";
    node.style.top = top-offsety+"px";
  }

};


if (document.addEventListener) {

     // Functions for W3C Standards compliant implementation of adding event handlers

     WebBrowser.prototype.addEvent = function(elmTarget, sEventName, fCallback) {
       elmTarget.addEventListener(sEventName, fCallback, false);
       returnValue = true;
     };

     WebBrowser.prototype.removeEvent = function(elmTarget, sEventName, fCallback) {
       elmTarget.removeEventListener(sEventName, fCallback, false);
       returnValue = true;
     };

     WebBrowser.prototype.addChangeEvent =  function(elmTarget, fCallback) {
      elmTarget.addEventListener("DOMAttrModified", fCallback, false);
      returnValue = true;
    };

} else {

  if(document.attachEvent) {

     // IE Specific Event handler functions
     WebBrowser.prototype.addEvent = function(elmTarget, sEventName, fCallback) {
       returnValue = elmTarget.attachEvent('on' + sEventName, fCallback);
     };

     WebBrowser.prototype.removeEvent = function(elmTarget, sEventName, fCallback) {
       returnValue = elmTarget.detachEvent('on' + sEventName, fCallback);
     };

    WebBrowser.prototype.addChangeEvent =  function(elmTarget, fCallback) {
      returnValue = elmTarget.attachEvent("onpropertychange", fCallback);
    };

  } else {

     // For browsers that do not support W3C or IE event functions
     WebBrowser.prototype.addEvent = function(elmTarget, sEventName, fCallback) {
       return false;
     };

     WebBrowser.prototype.removeEvent = function(elmTarget, sEventName, fCallback) {
       return false;
     };

     WebBrowser.prototype.addChangeEvent =  function(elmTarget, fCallback) {
       return false;
     };

  }

}

widgets_flag = true;
var widgets = new Widgets();
var browser = new WebBrowser();

function initApp() {
  widgets.init();
}

//globals.js

/**
*
* The Globale Variables
*/

if (!window.Node) {
  var Node = {            // If there is no Node object, define one
    ELEMENT_NODE: 1,    // with the following properties and values.
    ATTRIBUTE_NODE: 2,  // Note that these are HTML node types only.
    TEXT_NODE: 3,       // For XML-specific nodes, you need to add
    COMMENT_NODE: 8,    // other constants here.
    DOCUMENT_NODE: 9,
    DOCUMENT_FRAGMENT_NODE: 11
  }
}


var KEY_PAGEUP   = 33;
var KEY_PAGEDOWN = 34;
var KEY_END      = 35;
var KEY_HOME     = 36;

var KEY_LEFT     = 37;
var KEY_UP       = 38;
var KEY_RIGHT    = 39;
var KEY_DOWN     = 40;

var KEY_SPACE    = 32;
var KEY_TAB      = 9;

var KEY_BACKSPACE = 8;
var KEY_DELETE    = 46;
var KEY_ENTER     = 13;
var KEY_INSERT    = 45;
var KEY_ESCAPE    = 27;

var KEY_F1        = 112;
var KEY_F2        = 113;
var KEY_F3        = 114;
var KEY_F4        = 115;
var KEY_F5        = 116;
var KEY_F6        = 117;
var KEY_F7        = 118;
var KEY_F8        = 119;
var KEY_F9        = 120;
var KEY_F10       = 121;

var KEY_M         = 77;

var NS_XHTML = "http://www.w3.org/1999/xhtml"
var NS_STATE = "http://www.w3.org/2005/07/aaa";

// **********************************************
// *
// * Commonly used helper functions
// *
// **********************************************

/**
*
* nextSiblingElement
*
* @contructor
*/

function nextSiblingElement( node ) {

  var next_node = node.nextSibling;

  while( next_node
    && (next_node.nodeType != Node.ELEMENT_NODE) ) {
    next_node = next_node.nextSibling;
  }  // endwhile

  return next_node;

}

/**
*
* previousSiblingElement
*
* @param ( node ) node object for which you are looking for the next sibling element node
*
* @return ( node) next sibling or "null"
*/

function previousSiblingElement( node ) {

  var next_node = node.previousSibling;

  while( next_node
    && (next_node.nodeType != Node.ELEMENT_NODE) ) {
    next_node = next_node.previousSibling;
  }  // endwhile

  return next_node;

}

/**
*
* firstChildElement
*
* @param ( node ) node object for which you are looking for the first child element node
*
* @return ( node) next sibling or "null"
*/

function firstChildElement( node ) {

  var next_node = node.firstChild;

  while( next_node
    && (next_node.nodeType != Node.ELEMENT_NODE) ) {
    next_node = next_node.nextSibling;
  }  // endwhile


  return next_node;

}

/**
*
* getTextContentOfNode
*
* @contructor
*/

function getTextContentOfNode( node ) {

  var next_node = node.firstChild;
  var str = "";

  while( next_node ) {

    if( (next_node.nodeType == Node.TEXT_NODE ) &&
      (next_node.length > 0 )
     )
      str += next_node.data;


    next_node = next_node.nextSibling;

  }  // endwhile

  return str;

}

/**
*
* setTextContentOfNode
*
* @contructor
*/

function setTextContentOfNode( node, text ) {

   // Generate a new text node with the text value
    var text_node = document.createTextNode(text);

    // Remove child nodes to remove text
    while (node.firstChild) {
      node.removeChild(node.firstChild);
    } // while

    // Append new text to the container element
    node.appendChild( text_node );

}

function getPopupData(root, id) {

            // Create xmlhttprequest object
        var xmlhttp = null;
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
            //make sure that Browser supports overrideMimeType
            if (typeof xmlhttp.overrideMimeType != 'undefined') {
                xmlhttp.overrideMimeType('application/json');
            }
        }
        else if (window.ActiveXObject) {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else {
            alert('Perhaps your browser does not support xmlhttprequests?');
        }

        // Create an HTTP GET request
        xmlhttp.open('GET', 'popup.json?id='+id, true);

        // Set the callback function
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4) {
                var data = eval('(' + xmlhttp.responseText + ')');
                displayPopupData(root, data);
            } else {
                // waiting for the call to complete
            }
        };

        // Make the actual request
        xmlhttp.send(null);
}

function displayPopupData(root, data) {

    // Remove loading message
    root.removeChild(TPG.Dom.getFirstChild(root));

    var table = document.createElement("table");
    table.className = 'summary1';
	var tbody = document.createElement("tbody");

    var tr = document.createElement("tr");
    th = document.createElement("th");
	th.setAttribute("scope", "row");
    th.appendChild(document.createTextNode("First Name"));
    tr.appendChild(th);
    var td = document.createElement("td");
    td.appendChild(document.createTextNode(data.firstname));
    tr.appendChild(td);
	tbody.appendChild(tr);
	
    tr = document.createElement("tr");
    th = document.createElement("th");
	th.setAttribute("scope", "row");
    th.appendChild(document.createTextNode("Last Name"));
    tr.appendChild(th);
    td = document.createElement("td");
    td.appendChild(document.createTextNode(data.lastname));
    tr.appendChild(td);
	tbody.appendChild(tr);
	
    tr = document.createElement("tr");
    th = document.createElement("th");
	th.setAttribute("scope", "row");
    th.appendChild(document.createTextNode("Age"));
    tr.appendChild(th);
    td = document.createElement("td");
    td.appendChild(document.createTextNode(data.age));
    tr.appendChild(td);
	tbody.appendChild(tr);

    tr = document.createElement("tr");
    th = document.createElement("th");
	th.setAttribute("scope", "row");
    th.appendChild(document.createTextNode("Sex"));
    tr.appendChild(th);
    td = document.createElement("td");
    td.appendChild(document.createTextNode(data.sex));
    tr.appendChild(td);
	tbody.appendChild(tr);

    tr = document.createElement("tr");
    th = document.createElement("th");
	th.setAttribute("scope", "row");
    th.appendChild(document.createTextNode("Relationship to head of"));
    tr.appendChild(th);
    td = document.createElement("td");
    td.appendChild(document.createTextNode(data.relationship));
    tr.appendChild(td);
	tbody.appendChild(tr);

    tr = document.createElement("tr");
    th = document.createElement("th");
	th.setAttribute("scope", "row");
    th.appendChild(document.createTextNode("Religion"));
    tr.appendChild(th);
    td = document.createElement("td");
    td.appendChild(document.createTextNode(data.religion));
    tr.appendChild(td);
	tbody.appendChild(tr);

    tr = document.createElement("tr");
    th = document.createElement("th");
	th.setAttribute("scope", "row");
    th.appendChild(document.createTextNode("Occupation"));
    tr.appendChild(th);
    td = document.createElement("td");
    td.appendChild(document.createTextNode(data.occupation));
    tr.appendChild(td);
	tbody.appendChild(tr);

    tr = document.createElement("tr");
    th = document.createElement("th");
	th.setAttribute("scope", "row");
    th.appendChild(document.createTextNode("Birthplace"));
    tr.appendChild(th);
    td = document.createElement("td");
    td.appendChild(document.createTextNode(data.birthplace));
    tr.appendChild(td);
	tbody.appendChild(tr);

    tr = document.createElement("tr");
    th = document.createElement("th");
	th.setAttribute("scope", "row");
    th.appendChild(document.createTextNode("Literacy"));
    tr.appendChild(th);
    td = document.createElement("td");
    td.appendChild(document.createTextNode(data.literacy));
    tr.appendChild(td);
	tbody.appendChild(tr);

    tr = document.createElement("tr");
    th = document.createElement("th");
	th.setAttribute("scope", "row");
    th.appendChild(document.createTextNode("Language"));
    tr.appendChild(th);
    td = document.createElement("td");
    td.appendChild(document.createTextNode(data.language));
    tr.appendChild(td);
	tbody.appendChild(tr);

    tr = document.createElement("tr");
    th = document.createElement("th");
	th.setAttribute("scope", "row");
    th.appendChild(document.createTextNode("Origin"));
    tr.appendChild(th);
    td = document.createElement("td");
    td.appendChild(document.createTextNode(data.origin));
    tr.appendChild(td);
	tbody.appendChild(tr);

    table.appendChild(tbody);
    root.appendChild(table);
	
	table = document.createElement("table");
    table.className = 'summary';
	tbody = document.createElement("tbody");

    tr = document.createElement("tr");
    th = document.createElement("th");
	th.setAttribute("scope", "row");
    th.appendChild(document.createTextNode("Marital status"));
    tr.appendChild(th);
    td = document.createElement("td");
    td.appendChild(document.createTextNode(data.maritalstatus));
    tr.appendChild(td);
	tbody.appendChild(tr);

    tr = document.createElement("tr");
    th = document.createElement("th");
	th.setAttribute("scope", "row");
    th.appendChild(document.createTextNode("Years married"));
    tr.appendChild(th);
    td = document.createElement("td");
    td.appendChild(document.createTextNode(data.maritalyears));
    tr.appendChild(td);
	tbody.appendChild(tr);

    tr = document.createElement("tr");
    th = document.createElement("th");
	th.setAttribute("scope", "row");
    th.appendChild(document.createTextNode("Children born"));
    tr.appendChild(th);
    td = document.createElement("td");
    td.appendChild(document.createTextNode(data.childrenborn));
    tr.appendChild(td);
	tbody.appendChild(tr);

    tr = document.createElement("tr");
    th = document.createElement("th");
	th.setAttribute("scope", "row");
    th.appendChild(document.createTextNode("Children living"));
    tr.appendChild(th);
    td = document.createElement("td");
    td.appendChild(document.createTextNode(data.childrenliving));
    tr.appendChild(td);
	tbody.appendChild(tr);

    tr = document.createElement("tr");
    th = document.createElement("th");
	th.setAttribute("scope", "row");
    th.appendChild(document.createTextNode("Specified illnesses"));
    tr.appendChild(th);
    td = document.createElement("td");
    td.appendChild(document.createTextNode(data.illnesses));
    tr.appendChild(td);
	tbody.appendChild(tr);
	
    tr = document.createElement("tr");
    th = document.createElement("th");
	th.setAttribute("scope", "row");
    th.appendChild(document.createTextNode("Household members"));
    tr.appendChild(th);
    td = document.createElement("td");
    var ul = document.createElement("ul");
	for (var i = 0; i < data.households.length; i++) {
        var li = document.createElement("li");
        li.appendChild(document.createTextNode(data.households[i]));
        ul.appendChild(li);
    }
    td.appendChild(ul);
    tr.appendChild(td);
	tbody.appendChild(tr);
	
	
    table.appendChild(tbody);
    root.appendChild(table);
}

-->
