
/*** bundled: /script/ui.jsm */
// $Id: ui.jsm 15123 2009-01-10 02:34:22Z ftseng $

//--- Browser interaction functions ---

// Whether the browser allows bookmarks to be created via javascript
function bookmarkable(){
    if( (window.external && typeof window.external.addFavorite != 'undefined' ) || (window.sidebar && window.sidebar.addPanel) ){
        return true;
    }else{
        return false;
    }
}

// Create a bookmark with the specified url and name
function bookmark(url, name){
    if(window.external && typeof window.external.addFavorite != 'undefined'){ 
        window.external.AddFavorite(url, name);
    }
    if(window.sidebar && window.sidebar.addPanel){
        window.sidebar.addPanel(name, url, '');
    }
}

// Whether the browser allows the clipboard to be copied to
function clipboardable(){
    if(window.clipboardData && window.clipboardData.setData){
        return true;
    }else{
        return false;
    }
}

// Copy the specified text to the clipboard
function clipboard(text){
    if(window.clipboardData && window.clipboardData.setData){
        window.clipboardData.setData('Text', text);
    }
}

//--- End browser interaction functions ---

//--- Close button functions ---

// switch image on mouse-in on close button
function closeMouseIn(img_obj){
    var img = $(img_obj);
    img.src = img.src.replace('content_close.gif', 'content_close_hover.gif');
}

// switch image back on mouse-out on close button
function closeMouseOut(img_obj){
    var img = $(img_obj);
    img.src = img.src.replace('content_close_hover.gif', 'content_close.gif');
}

//--- End close button functions ---

//--- Popup functions -->

//Corner constants
var UPPER_LEFT = 1;
var UPPER_RIGHT = 2;
var LOWER_LEFT = 3;
var LOWER_RIGHT = 4;

// Popup locking variables
var popupLockObj = null;
var popupLockOffsetX = 0;
var popupLockOffsetY = 0;

// Popup blur variables
var windowBlurred = false;

// Function pointer for close popup event
var onClosePopup = null;

// Create a popup window
function createPopup(x, y, corner, titleHTML, bodyHTML, blur, lock, onclose){
    // blur the window if necessary
    if(blur){
        blurWindow();
        windowBlurred = true;
    }else{
        windowBlurred = false;
    }

    // create the popup
    var popup = document.createElement("div");
    popup.setAttribute("class", "popup");
    popup.setAttribute("className", "popup");
    popup.setAttribute("id", "popup");  

    if(onclose){
        onClosePopup = onclose;
    }else{
        onClosePopup = null;
    }

    popup.innerHTML = " <img class='preload' src='http://www-nychanis-com.1.s.kplex.org/014/static/images/content_close.gif' alt=''> <img class='preload' src='http://www-nychanis-com.3.s.kplex.org/014/static/images/content_close_hover.gif' alt=''> <table style='width: auto'>     <tr>         <td>             " + titleHTML + "         </td>         <td style='width: 0%; vertical-align: top'>             <img src='http://www-nychanis-com.1.s.kplex.org/014/static/images/content_close.gif' style='cursor: pointer; padding-left: 12px; padding-bottom: 8px; float: right' onmouseover='closeMouseIn(this)' onmouseout='closeMouseOut(this)' onclick='deletePopup()' alt=''>         </td>     </tr>     <tr>         <td id='popup_content' class='popup_content' colspan='2' style='white-space: nowrap'>             " + bodyHTML + "         </td>     </tr> </table>";
    
    // add the popup to the document  
    document.body.appendChild(popup); 
    var popupStyle = getObject(popup);  

    var width = getObjectWidth(popup);
    var height = getObjectHeight(popup);

    // position the popup                       
    if(corner == UPPER_RIGHT){                       
        x = x - width;               
    }else if(corner == LOWER_LEFT){                  
        y = y - height;              
    }else if(corner == LOWER_RIGHT){                 
        x = x - width;               
        y = y - height;              
    }                                      

    if (x < 5) { x = 5 }
    if (y < 5) { y = 5 }

    popupStyle.left = x + "px";                      
    popupStyle.top = y + "px";

    //solve any change in dimension that occured upon move
    if(corner == UPPER_RIGHT || corner == LOWER_RIGHT){
        var deltaWidth = width - getObjectWidth(popup);
        popupStyle.left = x + deltaWidth + "px";
    }
    if(corner == LOWER_LEFT || corner == LOWER_RIGHT){
        var deltaHeight = height - getObjectHeight(popup);
        popupStyle.top = y + deltaHeight + "px";
    }

    // set the locking variables if necessary
    if(lock != null && lock != false){
        popupLockObj = lock;
        popupLockOffsetX = getObjectXCoord(popupLockObj) - getObjectXCoord(popup);
        popupLockOffsetY = getObjectYCoord(popupLockObj) - getObjectYCoord(popup);
    }else{
        popupLockObj = null;
        popupLockOffsetX = 0;
        popupLockOffsetY = 0;
    }
    // set event handlers
    window.onresize = onresizePopup;
    window.onscroll = onscrollPopup;
}

// Delete the popup
function deletePopup(){
    window.onresize = null;
    window.onscroll = null;

    deleteObj("popup");
    if(windowBlurred){
        deleteObj("blur");
    }

    if(onClosePopup){
        onClosePopup();
        onClosePopup = null;
    }
}

// Blur (gray) entire window for popup
function blurWindow(){
    var blur = document.createElement("div");
    blur.setAttribute("class", "blur");
    blur.setAttribute("className", "blur");
    blur.setAttribute("id", "blur");
    blur.setAttribute("onclick", "deletePopup()");
    try{ blur.attachEvent("onclick", deletePopup); }
    catch(err){}

    var blurStyle = getObject(blur);
    blurStyle.top = scrollPosTop() + "px";
    blurStyle.left = scrollPosLeft() + "px";
    blurStyle.width = "100%";                                                                                                                                                                                           
    blurStyle.height = "100%";

    document.body.appendChild(blur);
} 

// Onresize this resets the position of the popup to be relative to the object it was locked to
function onresizePopup(){
    // reposition popup if locked to an object
    if(popupLockObj != null){
        var popupStyle = getObject("popup");
        popupStyle.left = popupLockObj.offsetLeft - popupLockOffsetX + "px";
        popupStyle.top = popupLockObj.offsetTop - popupLockOffsetY + "px";
    }

    //resize the blur div if needed
    if(windowBlurred){
        var blurStyle = getObject("blur");
        blurStyle.width = "100%";
        blurStyle.height = "100%";
    }
}

// Onscroll this repositions the blur div to stay within the window
function onscrollPopup(){
    //reposition the blur div if needed
    if(windowBlurred){
        var blurStyle = getObject("blur");
        blurStyle.top = scrollPosTop() + "px";
        blurStyle.left = scrollPosLeft() + "px";
    }
}

//--- End popup functions ---

// Cache image
function cacheImg(src){
    if(document.images){
        var image = new Image();
        image.src = src;
    }
}

// Delete an object and all children    
function deleteObj(obj){                
    var theObj = getRawObject(obj);     
    var theParent = theObj.parentNode;  
    theParent.removeChild(theObj);      
}

// Get the computed style (as defined by W3C)                     
function getCompStyle(obj){
    var theObj = getRawObject(obj);
    if(document.defaultView) {
        return document.defaultView.getComputedStyle(theObj, "");
    }else{
        return theObj.currentStyle;
    }
}

// Get the x coordinate of an object in window space
function getObjectXCoord(obj){
    var theObj = getRawObject(obj);
    return theObj.offsetLeft + theObj.offsetParent.offsetLeft;
}

// Get the y coordinate of an object in window space
function getObjectYCoord(obj){
    var theObj = getRawObject(obj);
    return theObj.offsetTop + theObj.offsetParent.offsetTop;
}

// Get the left scroll position
function scrollPosLeft(){
    var posLeft = 0;
    if(window.pageXOffset){
        posLeft = window.pageXOffset;
    }else if(document.documentElement.scrollLeft){
        posLeft = document.documentElement.scrollLeft;
    }else if(document.body.scrollLeft){
        posLeft = document.body.scrollLeft;
    }
    return posLeft;
}

// Get the top scroll position
function scrollPosTop(){
    var posTop = 0;
    if(window.pageYOffset){
        posTop = window.pageYOffset;
    }else if(document.documentElement.scrollTop){
        posTop = document.documentElement.scrollTop;
    }else if(document.body.scrollTop){
        posTop = document.body.scrollTop;
    }
    return posTop;
}

// Set the opacity of an object
function setOpacity(obj, opacity) { 
    var theObj = getObject(obj);
    opacity = (opacity >= 100) ? 99.999 : opacity; 
    theObj.filter = "alpha(opacity: " + opacity + ")";
    theObj.KHTMLOpacity = opacity / 100;
    theObj.MozOpacity = opacity / 100;
    theObj.opacity = opacity / 100;
}

// Global variables
var isCSS, isW3C, isIE4, isNN4;
// initialize upon load to let all browsers establish content objects
function initDHTMLAPI() {
    if (document.images) {
        isCSS = (document.body && document.body.style) ? true : false;
        isW3C = (isCSS && document.getElementById) ? true : false;
        isIE4 = (isCSS && document.all) ? true : false;
        isNN4 = (document.layers) ? true : false;
        isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
    }
}
// set event handler to initialize API
window.onload = initDHTMLAPI;

// Seek nested NN4 layer from string name
function seekLayer(doc, name) {
    var theObj;
    for (var i = 0; i < doc.layers.length; i++) {
        if (doc.layers[i].name == name) {
            theObj = doc.layers[i];
            break;
        }
        // dive into nested layers if necessary
        if (doc.layers[i].document.layers.length > 0) {
            theObj = seekLayer(document.layers[i].document, name);
        }
    }
    return theObj;
}

// Convert object name string or object reference
// into a valid element object reference
function getRawObject(obj) {
    var theObj;
    if (typeof obj == "string") {
        if (isW3C) {
            theObj = document.getElementById(obj);
        } else if (isIE4) {
            theObj = document.all(obj);
        } else if (isNN4) {
            theObj = seekLayer(document, obj);
        }
    } else {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}

// Convert object name string or object reference
// into a valid style (or NN4 layer) reference
function getObject(obj) {
    var theObj = getRawObject(obj);
    if (theObj && isCSS) {
        theObj = theObj.style;
    }
    return theObj;
}

// Position an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0 
            theObj.left = x + units;
            theObj.top = y + units;
        } else if (isNN4) {
            theObj.moveTo(x,y)
        }
    }
}

// Move an object by x and/or y pixels
function shiftBy(obj, deltaX, deltaY) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0 
            theObj.left = getObjectLeft(obj) + deltaX + units;
            theObj.top = getObjectTop(obj) + deltaY + units;
        } else if (isNN4) {
            theObj.moveBy(deltaX, deltaY);
        }
    }
}

// Set the z-order of an object
function setZIndex(obj, zOrder) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.zIndex = zOrder;
    }
}

// Set the background color of an object
function setBGColor(obj, color) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isNN4) {
            theObj.bgColor = color;
        } else if (isCSS) {
            theObj.backgroundColor = color;
        }
    }
}

// Set the visibility of an object to visible
function show(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "visible";
    }
}

// Set the visibility of an object to hidden
function hide(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "hidden";
    }
}

// Retrieve the x coordinate of a positionable object
function getObjectLeft(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("left");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.left;
    } else if (elem.style) {
        result = elem.style.left;
    } else if (isNN4) {
        result = elem.left;
    }
    return parseInt(result);
}

// Retrieve the y coordinate of a positionable object
function getObjectTop(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("top");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.top;
    } else if (elem.style) {
        result = elem.style.top;
    } else if (isNN4) {
        result = elem.top;
    }
    return parseInt(result);
}

// Retrieve the rendered width of an element
function getObjectWidth(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetWidth) {
        result = elem.offsetWidth;
    } else if (elem.clip && elem.clip.width) {
        result = elem.clip.width;
    } else if (elem.style && elem.style.pixelWidth) {
        result = elem.style.pixelWidth;
    }
    return parseInt(result);
}

// Retrieve the rendered height of an element
function getObjectHeight(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetHeight) {
        result = elem.offsetHeight;
    } else if (elem.clip && elem.clip.height) {
        result = elem.clip.height;
    } else if (elem.style && elem.style.pixelHeight) {
        result = elem.style.pixelHeight;
    }
    return parseInt(result);
}


// Return the available content width space in browser window
function getInsideWindowWidth() {
    if (window.innerWidth) {
        return window.innerWidth;
    } else if (isIE6CSS) {
        // measure the html element's clientWidth
        return document.body.parentElement.clientWidth
    } else if (document.body && document.body.clientWidth) {
        return document.body.clientWidth;
    }
    return 0;
}
// Return the available content height space in browser window
function getInsideWindowHeight() {
    if (window.innerHeight) {
        return window.innerHeight;
    } else if (isIE6CSS) {
        // measure the html element's clientHeight
        return document.body.parentElement.clientHeight
    } else if (document.body && document.body.clientHeight) {
        return document.body.clientHeight;
    }
    return 0;
}

// Ask for confirmation and redirect to URL (GET)
function ask(question, url) {
   if (confirm(question)) {
      document.location.href = url;
   }
}

// Ask for confirmation and submit to URL (POST)
function askp(question, url) {
   if (confirm(question)) {
      return post(url);
   }
}

// Submits POST request to given URL
function post(url) {
   var body = document.getElementsByTagName('body')[0];
   var form = document.createElement('form');
   form.style.display = 'none';
   body.appendChild(form);
   form.method = 'post';
   form.action = url;
   form.submit();
   body.removeChild(form);
   return false;
}

// Submits get request to given URL
function get(url) {
    document.location.href = url;
    return false;
}

var emptied = new Array();
function emptyOnFirstFocus(obj){
    var theObj = getRawObject(obj);
    var id = theObj.id;

    for(var i = 0; i <  emptied.length; i++){
        if(id == emptied[i]){
            return;
        }
    }

    emptied[emptied.length] = id;
    theObj.value = '';
}

function findPosX(obj) {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent) break;
          obj = obj.offsetParent;
        }
    else if(obj.x) curleft += obj.x;
    return curleft;
  }

function findPosY(obj) {
    var curtop = 0;
    if(obj.offsetParent)
        while(1) {
          curtop += obj.offsetTop;
          if(!obj.offsetParent) break;
          obj = obj.offsetParent;
        } 
    else if(obj.y) curtop += obj.y;
    return curtop;
}

function ajaxPopupNear(elem, url) {
    // determine position and dimensions of 'near' element
    elem = $(elem);
    var elem_x = findPosX(elem);
    var elem_y = findPosY(elem);
    var elem_d = elem.getDimensions();
    var elem_h = elem_d.height;
    var elem_w = elem_d.width;

    // determine window coordinate where popup should be placed
    var x = elem_x + elem_w;
    var y = elem_y + elem_h + 2;

    // load url and create the popup
    new Ajax.Request(url, {
        method:'get',
        onComplete: function(res) {
            createPopup(x, y, UPPER_RIGHT, '', res.responseText, true, elem);
        }
   });
}

function hide_container(container, controller) {
    var elem = $(container);
    var cntl = $(controller);
    elem.old_width = elem.getDimensions().width;
    if (cntl) { elem.old_width -= cntl.getDimensions().width }
    elem.old_whiteSpace = elem.style.whiteSpace;
    elem.old_overflow = elem.style.overflow;
    elem.style.whiteSpace = 'nowrap';
    elem.style.overflow = 'hidden';
    elem.style.width = '1px';
}

function show_container(container) {
    var elem = $(container);
    elem.style.width = elem.old_width + 'px';
    elem.style.whiteSpace = elem.old_whiteSpace;
    elem.style.overflow = elem.old_overflow;
}

function toggle_right_boxes() {
    var elem = $('right_boxes_container');
    var cntl = $('right_boxes_controller');
    (elem.style.width == '1px') ? show_container(elem) : hide_container(elem, cntl);
}

function toggle_left_nav() {
    var elem = $('left_nav_container');
    var cntl = $('left_nav_controller');
    (elem.style.width == '1px') ? show_container(elem) : hide_container(elem, cntl);
}

function buttonIn(button) {
    button = $(button);
    button.removeClassName('button_on');
    button.addClassName('button_ov');
}

function buttonOut(button) {
    button = $(button);
    button.removeClassName('button_ov');
    button.addClassName('button_on');
}

function formAddedToURL(form) {
    var uri = document.location.toString();

    if (form.cid.value) {
        uri = uri + "&cid=" + form.cid.value
    }
    if (form.pl.value) {
        uri = uri + "&pl=" + form.pl.value
    }
    //alert("Submitting form as url: " + uri);
    document.location = uri;
    return false;
}

function submitFormAsURL(form) {
    // read through form fields, creating a url from the form fields and the current url
    var url = document.location.toString();
    var url_params = url.indexOf('?') > 0 ? toString().toQueryParams() : {};

    // var form_params = form.serialize.toQueryParams();
    // new_params      = $H( url_params ).merge(form_params);
    // new_url         = new_params.toQueryString();

    // FIXME: give better feedback, testing for cases where they typed too fast (see ticket #592)
    if (!form.cid.value && !form.pl.value) {
        alert("Please enter an indicator and/or a place and select from the drop down boxes before searching.");
        return false;
    }
    // FIXME: support multiple values for a key (for toolbar, for example)
    if (form.cid.value) {
        url_params.cid = form.cid.value
    }
    if (form.pl.value) {
        url_params.pl = form.pl.value
    }

    var new_url_args = $H( url_params ).toQueryString();
    // alert("Loading new page: " + form.action + "?" + new_url_args );
    // return false;
    document.location = form.action + "?" + new_url_args;
    return false;
}

/* for input boxes that have a default text to be replaced by user's input */
function inputOnFocus(inputBox) {
    inputBox = $(inputBox);
    inputBox.className='';
    /* save the original default if we haven't already */
    if (!inputBox.defaultValue) {
        inputBox.defaultValue = inputBox.value;
    }
    if (inputBox.value == inputBox.defaultValue) {
        inputBox.clear();
    }

}
/* for input boxes that have a default text to be replaced by user's input */
function inputOnBlur(inputBox) {
    inputBox = $(inputBox);
    /* if there was something in the input box when it was deselected, do nothing. */
    if (!inputBox.value) {
        inputBox.value = inputBox.defaultValue;
    }
    if (inputBox.value == inputBox.defaultValue) {
        inputBox.className='blurred';
    }
}
/* for redirecting user to a specific page after he selects either Data or Place or Both from blue bar */
function place_target_page( suffix ) {
    var data_selected = document.getElementById("cid" + suffix ).value;
    var place_selected = document.getElementById("place" + suffix ).value;
    var whereplace_selected = document.getElementById("where" + suffix ).value;
    var continue_url = document.getElementById("continue" + suffix ).value;
    var url = continue_url;
    if (data_selected && place_selected) {
        url = "http://www.nychanis.com/place/dataprofile?category=rv";
    } else if (data_selected && !place_selected) {
        url = "http://www.nychanis.com/place?from=blue_bar&category=rv";
    } else if (!data_selected && place_selected) {
        if ((suffix == 'home') || (suffix == 'splash')) {
            url = "http://www.nychanis.com/place";
        } else {
            url = continue_url;
        }         
    }

    document.getElementById("continue" + suffix ).value = url;
}
// end form functions

/* add_year function is needed for ui/ind_name, used on rankings and charts pages, it adds indicator of the selected year into active indicator list */
function add_year(element_id) {
  var cids = $F(element_id);
  var url = "http://www.nychanis.com/mod_active?";
  cids.split(',').each( function(cid) {
    url += '&add_cid='+cid;
  });
  window.location = url; 
}

/* loading glossary */
function open_glossary(term) {
  var url = "http://www.nychanis.com/resources/glossary" + '?term=' + term;
  window.open(url,'width=600,height=500,top=100,left=300,scrollbars=1,resizable=1');
}

function show_glossary_title(n, keyword, term) {
  n.onclick = function() { open_glossary(term); }

  // Fetch the title with ajax  
  if (!n.title) {
    n.title = 'loading glossary... move mouse again to view';
    var url = "http://www.nychanis.com/ajax/glossary_title" + '?key='+escape(keyword);
    new Ajax.Request(url, {
        method:'get',
        onComplete: function(res) {
            n.title = res.responseText;
        }
    });
  }
}


/*** bundled: /script/infobox.js */
var INFO_BOX_IMG_PATH = 'http://www-nychanis-com.2.s.kplex.org/014/static/images/map/info_tool';
    function InfoBox(content, settings ) {
    if (!settings) { settings = {}; }
    this.settings = settings;
	var container = $(Builder.node('div')).setStyle({position: 'absolute',  'zIndex': 110, minHeight: '64px', minWidth: '128px', width: 'auto'});
    
    this.close = InfoBox._makeClose(this);

    var cb = InfoBox._createImg('getinfo_close.png',105,INFO_BOX_IMG_PATH);
    cb.onclick = this.close;
    cb.style.padding = '5px';
    cb.style.paddingRight = '0px';
	cb.style.cursor = 'pointer';

    content.addHeader({value: cb});

    this.content_table = $(Builder.node('table',{cellpadding:'0', cellspacing:'0', border:'0'}));
    this.content_table.setStyle({'white-space': 'nowrap' });
    var table_body = document.createElement("TBODY");

    //now create the header

    var table_header =  InfoBox._createHeaderRow(content.getHeader(),INFO_BOX_IMG_PATH);

    table_body.appendChild( table_header );
    var rows = content.getRows();
    var row_count = rows.length;
    rows.each(function (v,i) {
            var tr = {};
            if ((i + 1) >= row_count) { tr.no_line = true;} 
            table_body.appendChild( InfoBox._createInfoRow( v ,tr, INFO_BOX_IMG_PATH));
        }
              );

    table_body.appendChild( InfoBox._createFooterRow(content.getColumns() ,INFO_BOX_IMG_PATH) );
    
    this.content_table.appendChild( table_body );
    this.container = container;
    this.container.appendChild(this.content_table);


    var tail = InfoBox._createImg( 'getinfo_arrow_yl.png', 110, INFO_BOX_IMG_PATH);
    tail.style.width=30;
    tail.style.height=22;


    var tail_div = $(Builder.node("div"));
    tail_div.style.position = 'absolute';
    tail_div.style.zIndex = 110;
    tail_div.appendChild(tail);
	this.tail = tail_div;
    
	this.cb = cb;	
    this.domObjs = [ container, tail_div ];

	this.infoWindowContainer = document.createElement('div',INFO_BOX_IMG_PATH);	
	this.infoWindowContainer.style.position = 'absolute';

	for(var i=0; i<this.domObjs.length; i++) {
		this.domObjs[i].onmousedown = 
        this.domObjs[i].onmouseup = 

        function(e) {
			e = (e) ? e : ((window.event) ? event : null);
			if (e == null) return;
			e.cancelBubble = true;
			e.returnValue = false;
			if (e.stopPropogation) e.stopPropogation();
			if (e.preventDefault) e.preventDefault();
		}
		this.infoWindowContainer.appendChild(this.domObjs[i]);
	}
    //document.body.appendChild(this.infoWindowContainer);
}

InfoBox.prototype.hide = function() {
	this.domObjs.each( function(v,i) { hide(v); });
}


InfoBox.prototype.destroy = function() {
	this.hide();
	try {
	while (this.domObjs.length) {
	  this.infoWindowContainer.removeChild(this.domObjs.pop());
        }
    document.body.removeChild( this.container_ele );
}catch (e) {}


}


InfoBox._makeClose = function(box) {
	return function(event) {
		try { box.destroy(); } catch(e) {};
        // IE7 does not send an event object, will cause errors if you try to use
        if (event) {
            //          Event.stop(event);
        }
	};
}


InfoBox._createFooterRow = function (array_count, img_path) {
    var tr = $(Builder.node("tr"));
    var style = { width: '8px', lineHeight: '22px' , padding: '0px'};
   
    tr.appendChild( InfoBox._createBorderCell(img_path + "/getinfo_dl.png",style,false)) ;    

    for(var x = 0; x< array_count; x++) {
        tr.appendChild( InfoBox._createBorderCell(img_path + "/getinfo_d1px.png",style,true)) ;    
    }

    tr.appendChild( InfoBox._createBorderCell(img_path + "/getinfo_dr.png",style,false)) ;    
    return tr;
}
    InfoBox._createHeaderRow = function (array,img_path) { 
    

    var tr = $(Builder.node("tr"));
    tr.appendChild( InfoBox._createBorderCell(img_path + "/getinfo_ul.png",{width: '8px'},false)) ;    
    var td_style = {};
    td_style.background = "url('" + img_path + "/getinfo_u1px.png')";
    td_style.verticalAlign ='middle';
    td_style.color = "#333333";
    td_style.fontWeight = "bold";
    td_style.lineHeight = "22px";
    td_style.fontFamily = "Arial,Helvetica";
    InfoBox._createTableCells(tr,array,td_style);
    tr.appendChild( InfoBox._createBorderCell(img_path + "/getinfo_ur.png",{width: '8px'},false));    
    return tr;
}
    
InfoBox._createBorderCell = function(img,style, background_repeat) {        
    var img;
    if (background_repeat) {
        style.background = "url('" + img + "')";
        if (style.width == '8px') {
            img = $(Builder.node("img",{src: INFO_BOX_IMG_PATH + "/getinfo_8px_trans.png"})).setStyle({ padding: '0px' });
        } else {
            img = $(Builder.node("img",{src: INFO_BOX_IMG_PATH + "/getinfo_11px_trans.png"})).setStyle({ padding: '0px' });
        }
    }else {
        style.background='';
        img = $(Builder.node("img",{src: img})).setStyle({ padding: '0px' });
    }
        var td = $(Builder.node("td",img)).setStyle( style );
    return td;
}

InfoBox._createInfoRow = function (array, tr_prop, img_path) {
    var tr = $(Builder.node("tr"));
    tr.appendChild( InfoBox._createBorderCell(img_path + "/getinfo_l1px.png",{width: '8px'},true) ) ;    
    var td_style = {};
    td_style.background = "#FFFFFF"
    td_style.lineHeight = "22px";
    td_style.fontFamily = "Arial,Helvetica";
    array.push({no_line: true});

    array[0].style = { background: "#FFFFFF", lineHeight: "22px", textAlign: "left", fontFamily: "Arial,Helvetica", padding: '5px'};
    array[1].style = { background: "#FFFFFF", lineHeight: "22px", textAlign: "right", fontFamily: "Arial,Helvetica", padding: '5px'};
    if (!tr_prop.no_line) {
        array[0].style.borderBottom = '1px dashed #F8D14C';
        array[1].style.borderBottom = '1px dashed #F8D14C';
        td_style.borderBottom = '1px dashed #F8D14C';
    }    


    InfoBox._createTableCells(tr,array,td_style);

    tr.appendChild( InfoBox._createBorderCell(img_path + "/getinfo_r1px.png",{width: '1px'},true) ) ; 
    return tr;
}

InfoBox._createTableCells = function (tr,array,style) {
    array.each( function( v, i ) { 
    var td;
    if (v.attr) {
        td = $(Builder.node("td", v.attr,v.value));
    }else {
        td = $(Builder.node("td", v.value));
    }
    if (v.style) {
        td.setStyle(v.style);
    }else if (style) {
        td.setStyle(style);
    }
    td.noWrap = true;
    tr.appendChild(td);
    
        }
                );
}
    InfoBox._createImg = function ( img_name, zIndex ,img_path) {
     
    var img = $(Builder.node("img"));
    img.src = img_path + "/" + img_name;
    if (zIndex) {
        img.style.zIndex = zIndex;

    }
    return img;
};

InfoBox._createDiv = function (img_name, img_path) {
    var div = $(Builder.node("div"));
    div.style.width = '300px';
    div.style.height = '100px';
	div.style.background = '#FF0000 url(' . img_path + '/' + img_name + ')';
	div.style.zIndex = 103;

    return div;
};

InfoBox._imagesLoad = function(iw) {
	return function() {
		InfoBox._nbLoaded++;
		if (InfoBox._nbLoaded > 3 && iw.resize)
			iw.resize();
	};
}


InfoBox.prototype.getPosition = function() {
	return this.position;
}


InfoBox.prototype.showAt = function(x,y) {


	this.resize();

    
    if (!this.settings.multiple && !this.settings.tooltip) {

        var dim = $(document.body).getDimensions();
        var style = {
        'class': 'popup',
        'id': 'popup',
        'top': '0px',
        'left' : '0px',
        'width' :"100%",
        'height' : dim.height + 'px',
        'position' : 'absolute',
        'zIndex': 110
        };

        var popup = $(Builder.node('div',this.infoWindowContainer));
        popup.setStyle( style );
        popup.style.zIndex = 110;
        popup.onclick = this.close;
        document.body.appendChild(popup);
        show(popup);        
        this.container_ele = popup;
    } else {
        document.body.appendChild(this.infoWindowContainer);
        this.container_ele = this.infoWindowContainer;
        
    }
    this.infoWindowContainer.style.left = x + 'px';
    this.infoWindowContainer.style.top = y + 'px';
    show(this.infoWindowContainer);
}



InfoBox.prototype.resize = function() {
	var x = 0;//this.infoWindowContainer.offsetLeft;
	var y = -11;//this.infoWindowContainer.offsetTop;
	this.px(this.tail, 'top', y);
	this.px(this.tail, 'left', x + 1);
	this.px(this.container, 'top', y - 4);
	this.px(this.container, 'left', x + 27);
}

InfoBox.prototype.px = function(obj, attr, n) {
	 obj['style'][attr] = Math.round(n) + 'px';
}






function InfoBoxContent() {
    this.columns = Array();
    this.rows = Array();
    this.col_num = 0;
    this.row_col_num = 0; 

}
// convert all this into a standard table

InfoBoxContent.prototype.toTableHtml= function () {

  return this.toContent({
start: "<table>",
start_header: "<tr>",
end_header: "</tr>",
start_header_item: "<td>",
end_header_item: "</td>",

start_row: "<tr>",
end_row: "</tr>",
start_row_item: "<td>",
end_row_item: "</td>",
end: "</table>"
});

}

InfoBoxContent.prototype.toTableNode= function (width) {

  var table = $(Builder.node('table',this.toContentNode({
start: "tbody",
header: "tr",
header_item: "td",
row: "tr",
row_item: "td"
})));

  if (width) {
     table.style.width = width + "px";
  }

  return table;
}


InfoBoxContent.prototype.toContent = function (settings) {
   var html = settings.start;

   html += settings.start_header;
    
   this.columns.each(function(h) {
  html += settings.start_header_item;
  html += h.value;
  html += settings.end_header_item;
});
   html += settings.end_header;

this.rows.each(function(row) {
   html += settings.start_row;
row.each(function(col) {
  html += settings.start_row_item;
  html += col.value;
  html += settings.end_row_item;
});
   html += settings.end_row;
});


   html += settings.end;
  
   return html;

}
   


InfoBoxContent.prototype.toContentNode = function (settings) {
   var node = $(Builder.node(settings.start));

   var node_header = $(Builder.node(settings.header));
    
   this.columns.each(function(h) {

      node_header.appendChild($(Builder.node(settings.header_item,h.value)));
   });

node.appendChild( node_header );

this.rows.each(function(row) {

   var row_node = $(Builder.node(settings.row));

row.each(function(col) {
      row_node.appendChild($(Builder.node(settings.row_item,col.value)));
});
node.appendChild(row_node);
});

   return node;

}
   




InfoBoxContent.prototype.addHeader = function( header ) {
    if (header) { 
        this.columns.push( header ); 
        if (header.attr && header.attr.colSpan) {
            this.col_num += header.attr.colSpan; 
        } else {
            this.col_num++; 
        }
    }
}
InfoBoxContent.prototype.addRow = function( row ) {
    this.rows.push( row );

    if (row.length > this.row_col_num) {
        this.row_col_num = row.length;
    }
}
InfoBoxContent.prototype.getHeader = function() {
    return this.columns;
}
InfoBoxContent.prototype.getRows = function() {
    return this.rows;
}
InfoBoxContent.prototype.getColumns = function() {
    return this.col_num;
}


    function InfoBoxCell(v,s) {
        this.value = v;
        this.style = s;
    }


var X;
var Y;

function openInfoBox(e,content,settings) {
    X = e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
    Y =  e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop));

    var infobox = new InfoBox(content,settings);

    if (settings.tooltip) {
      var element = Event.element(e);
      var dim = element.getDimensions();	
      var position = getObjectPageXY( element );
	infobox.showAt( position.x + dim.width, position.y + dim.height);
    } else {
      infobox.showAt(X,Y);
    }
    return infobox;
}

function getObjectPageXY(elem) {
  // Climb tree of parents to get x,y position of this object within the whole page
  // Use this function to calculate an offset to subtract from the mouse event pageX + pageY,
  // when you want to get the coordinates of the mouse relative to a particular object
  var r={"x":0,"y":0};
  while(elem) {
    r.x+=elem.offsetLeft; r.y+=elem.offsetTop; elem=elem.offsetParent;
  }
  return r;
}



function openDialog( e, places) {
    try {
    var content = new InfoBoxContent();
    if (places.length) {
        content.addHeader({value: "Values for Related Places", attr: {colSpan: 2, align: 'center'}});
            places.each(function( pl ) {
                    var link;
                    if (pl.no_link) {
                        link = pl.boundary_name;
                    }else {
                        link = $(Builder.node('a',{href:"http://www.nychanis.com/charts/mod_active?add_pl=" + pl.place_id    },pl.boundary_name));
                    }
                    content.addRow([ {value: link }, {value: pl.indicator_value }]);
                });
        
            var infobox = new InfoBox( content );
        infobox.showAt(X,Y);
    }else {
        content.addRow([{ value: "No Data Available"}]);
        content.addHeader({value: ''});
        var infobox = new InfoBox(content);
        infobox.showAt(X,Y);

    }


   }catch(e) { window.alert(e.message); }

}

function rollupWindow( e, ind,place, place_name) {
    X = e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
    Y =  e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop));

    new Ajax.Request("/json/rollup.html",{method: 'get', parameters: {pl: place, cid: ind}, onComplete: function(res){
                             var places;
                             places = eval(res.responseText);
                             if (places.length) {
                                 places.unshift({ indicator_value: 'N/A', boundary_name: place_name, no_link: true});
                             }
                             openDialog(e,places);


                         }}
                     
                     );
}

/*** bundled: /script/minmax_slider.js */
var MinMaxSlider = Class.create();
MinMaxSlider.prototype = {
    initialize: function(args) {
        this.choices     = $A(args['choices']);
        this.can_overlap = args['can_overlap'];

        this.min         = args['min_init'];
        this.min_choice  = this.choices[this.min];
        this.min_track   = args['min_track'];
        this.min_handle  = args['min_handle'];

        this.max         = args['max_init'];
        this.max_choice  = this.choices[this.max];
        this.max_track   = args['max_track'];
        this.max_handle  = args['max_handle'];

        this.on_change_min = args['on_change_min'];
        this.on_change_max = args['on_change_max'];
        this.on_complete   = args['on_complete']

        this.min_slider = new Control.Slider(this.min_handle, this.min_track, {
            range:  $R(0, this.choices.length-1),
            values: $R(0, this.can_overlap ? this.choices.length-1 : this.choices.length-2),

            onChange:function(v) {
                this.min = v;
                this.min_choice = this.choices[v];
                this.checkMax(v);
                if (this.on_change_min) { this.on_change_min(this.min_choice); }
                if (this.ready && this.on_complete) {
                    this.on_complete(this.min_choice, this.max_choice);
                }
            }.bind(this),
            onSlide:function(v) {
                this.checkMax(v);
                if (this.on_change_min) { this.on_change_min(this.choices[v]); }
            }.bind(this)
        });

        this.max_slider = new Control.Slider(this.max_handle, this.max_track, {
            range:  $R(0, this.choices.length-1),
            values: $R(this.can_overlap ? 0 : 1, this.choices.length-1),

            onChange:function(v) {
                this.max = v;
                this.max_choice = this.choices[v];
                this.checkMin(v);
                if (this.on_change_max) { this.on_change_max(this.max_choice); }
                if (this.ready && this.on_complete) {
                    this.on_complete(this.min_choice, this.max_choice);
                }
            }.bind(this),
            onSlide:function(v) {
                this.checkMin(v);
                if (this.on_change_max) { this.on_change_max(this.choices[v]); }
            }.bind(this)
        });

        this.ready = 0;
        this.min_slider.setValue(this.min);
        this.max_slider.setValue(this.max);
        this.ready = 1;

    },

    checkMax: function(min) {
        if (!this.can_overlap) min = min+1;
        if (this.max < min) {
            var wasready = this.ready;
            this.ready = 0;
            this.max_slider.setValue(min);
            this.ready = wasready;
        }
    },
    checkMin: function(max) {
        if (!this.can_overlap) max = max-1;
        if (this.min > max) {
            var wasready = this.ready;
            this.ready = 0;
            this.min_slider.setValue(max);
            this.ready = wasready;
        }
    }
}

function fixup_labels(min_label, max_label, min_handle, max_handle) {
    min_label = $(min_label);
    max_label = $(max_label);
    min_handle = $(min_handle);
    max_handle = $(max_handle);

    var min_hpos = Position.cumulativeOffset(min_handle);
    min_hpos[0] += (min_handle.getWidth() / 2);
    min_label.style.position = 'absolute';
    min_label.style.top  = min_hpos[1] - 14 + 'px';
    min_label.style.left = min_hpos[0] - (min_label.getWidth() / 2) + 'px';

    if (max_label.visible()) {

        var max_hpos = Position.cumulativeOffset(max_handle);
        max_hpos[0] += (max_handle.getWidth() / 2);
        max_label.style.position = 'absolute';
        max_label.style.top  = max_hpos[1] - 14 + 'px';
        max_label.style.left = max_hpos[0] - (max_label.getWidth() / 2) + 'px';

        var min_pos = Position.cumulativeOffset(min_label);
        var max_pos = Position.cumulativeOffset(max_label);
        var min_tr = min_label.getWidth() + min_pos[0];
        var max_tl = max_pos[0];
        var distance = max_tl - min_tr - 4;
        if (min_label.innerHTML && max_label.innerHTML != '' && distance < 0) {
            move = -(distance / 2) | 0;
            min_label.style.left = min_pos[0] - move + 'px';
            max_label.style.left = max_pos[0] + move + 1 + 'px';
        }
    }
}


/*** bundled: /script/slider.js */
var SingleSlider = Class.create();
SingleSlider.prototype = {
    initialize: function(args) {
        this.choices = $A(args['choices']);

        this.track   = args['track'];
        this.handle  = args['handle'];

        this.value   = args['value'];
        this.choice  = this.choices[this.value];
        
        this.on_change   = args['on_change'];
        this.on_complete = args['on_complete'];

        this.slider = new Control.Slider(this.handle, this.track, {
            range:  $R(0, this.choices.length-1),
            values: $R(0, this.choices.length-1),

            onChange:function(v) {
                this.value = v;
                this.choice = this.choices[v];
                if (this.on_change) { this.on_change(this.choice) }
                if (this.ready && this.on_complete) {
                    this.on_complete(this.choice);
                }
            }.bind(this),

            onSlide:function(v) {
                if (this.on_change) { this.on_change(this.choices[v]) }
            }.bind(this)
        });

        this.ready = 0;
        this.slider.setValue(this.value);
        this.slider.setValue(this.value);  // hack -- call it twice to fix label placement
        this.ready = 1;
    }
};



/*** bundled: /script/attachments.js */
// 'Unlimited' file uploads widget function <mreece@vinq.com>
//
// Usage: 
//  <div id="attachments" style="display:none;"></div>
//  <a  onclick="javascript:addAttachment('attachments');">
//      Add attachment</a>
// 
// Clicking the link (that is, calling addAttachment(container_id)) will 
//   append an additional file input to the container div, along with a
//   'remove' link for removing the file input.
// The <input type="file" will have name="attach.n" where n is >= 1
// The 'container' div will be set to 'display:block' when an attachment
//   is added, and 'display:none' if all attachments are removed.

var attach_id    = 1;  // counter for name="attach.n"
var attach_count = 0;  // count of un-removed file inputs
function addAttachment(container_id) {
    var container = document.getElementById(container_id);

    // set up the <input type="file" name="attach.n">
    var input = document.createElement('input');
    input.type = 'file';
    input.name = 'attach.' + attach_id++;

    // set up the <a onclick=removeAttachment()>remove</a>
    var remove = document.createElement('a');
    remove.appendChild(document.createTextNode('remove'));
    remove.onclick = function() {
        container.removeChild(this.parentNode);
        if ( --attach_count < 1 ) {
            container.style.display = 'none';
        }
        return false;
    };

    // set up new div to hold the input and remove link
    var div = document.createElement('div');
    div.appendChild(input);
    div.appendChild(remove);

    // and inject it into the container
    container.appendChild(div);
    if ( ++attach_count > 0 ) {
        container.style.display = 'block';
    }

    return false;
}

/*** bundled: /script/maps.jsm */
// $Id: maps.jsm 15015 2008-12-09 01:16:56Z efoster $
// map linking

var mapsLinked = false; // global that stores whether maps are linked or not

function toggleMapLink() {
    if(!mapsLinked) { linkMaps(); } 
    else { unlinkMaps(); }
}

function linkMaps() {
    mapsLinked = true; 
    $('map_link').src = 'http://www-nychanis-com.2.s.kplex.org/014/static/images/map_linked.gif';
    map1.dpmap.borderActiveColor();
    map2.dpmap.borderActiveColor();
    map2.dpmap.centerAndZoom(map1.dpmap.getCenterLatLng(), map1.dpmap.getZoomLevel()); 
    map1.dpmap.kamap.link(map2.dpmap.kamap);
}

function unlinkMaps() {
    mapsLinked = false;
    $('map_link').src = 'http://www-nychanis-com.4.s.kplex.org/014/static/images/map_unlinked.gif';  
    map1.dpmap.borderNormalColor();
    map2.dpmap.borderNormalColor(); 
    map1.dpmap.kamap.unlink(); 
}

function mapLinkOver() { // mouseover link button
    if(!mapsLinked) { $('map_link').src = 'http://www-nychanis-com.3.s.kplex.org/014/static/images/map_unlinked_ov.gif'; }
    else { $('map_link').src = 'http://www-nychanis-com.1.s.kplex.org/014/static/images/map_linked_ov.gif'; }
    map1.dpmap.borderHighlightColor();
    map2.dpmap.borderHighlightColor();
}

function mapLinkOut() { // mouseout link button
    if(!mapsLinked) { $('map_link').src = 'http://www-nychanis-com.4.s.kplex.org/014/static/images/map_unlinked.gif'; }
    else { $('map_link').src = 'http://www-nychanis-com.2.s.kplex.org/014/static/images/map_linked.gif'; }
   if(!mapsLinked) {
        map1.dpmap.borderNormalColor();
        map2.dpmap.borderNormalColor();
    } else {
        map1.dpmap.borderActiveColor();
        map2.dpmap.borderActiveColor();
   }
}

// map display toggling

function showMap1(number) {

 
    $('map2_container').setStyle({width: '50%'});
    $('map1_container').show();
    $('map_link_container').show();
     _showMap(map1,map2);

}

function showMap2() {
    
    $('map1_container').setStyle({width: '50%'});
    $('map2_container').show();
    $('map_link_container').show();

   _showMap(map2,map1);
    if (updatePageTitle) updatePageTitle();
 
}


function _showMap(show,map) {
    map.dpmap.duplicate.hide();
    map.dpmap.close.show();
    show.dpmap.duplicate.hide();
    show.dpmap.close.show();

    contractTools();
	
    map.dpmap.kamap.resize();
    show.dpmap.kamap.resize();

    if (map.dpmap.place) {
	show.dpmap.place =  map.dpmap.place;
    }

    show.dpmap.centerAndZoom(map.dpmap.getCenterLatLng(), map.dpmap.getZoomLevel()); 
    if (map.dpmap.currentIndicator) {

        show.dpmap.setIndicator( new DPIndicator(map.dpmap.currentIndicator.id,
				function (ind) { 
				  ind.setActiveThematicBoundary(map.dpmap.currentIndicator.getActiveThematicBoundary());
    				  if (updatePageTitle) updatePageTitle();
				}
				));
    }
}

function hideMap1() {
    if(mapsLinked) { unlinkMaps(); }
    
    map2.dpmap.close.hide();
    map2.dpmap.duplicate.show();
    
    $('map2_container').setStyle({width: '100%'});
    $('map1_container').hide();
    $('map_link_container').hide();


    expandTools();

    map1.dpmap.kamap.resize();
    map2.dpmap.kamap.resize();
    if (updatePageTitle) updatePageTitle();
}


function hideMap2() {
    if(mapsLinked) { unlinkMaps(); }
    
    map1.dpmap.close.hide();
    map1.dpmap.duplicate.show();

    $('map1_container').setStyle({width: '100%'});
    $('map2_container').hide();
    $('map_link_container').hide();


    expandTools();

    map1.dpmap.kamap.resize();
    map2.dpmap.kamap.resize();
    if (updatePageTitle) updatePageTitle();
}

function expandTools() {
    var width = '200px';

    if ($('save_as_1')) {
      $('save_as_1').show();
      $('whatmap1').setStyle({width: width});
      $('wheremap1').setStyle({width: width});
    }

    if ($('save_as_2')) {
      $('save_as_2').show();
      $('whatmap2').setStyle({width: width});
      $('wheremap2').setStyle({width: width});
    }

    $$('span.show_text').each( function(span) { span.show(); });
}

function contractTools() {
    var width = '140px';

    if ($('save_as_1')) {
      $('save_as_1').hide();
      $('whatmap1').setStyle({width: width});
      $('wheremap1').setStyle({width: width});
    }

    if ($('save_as_2')) {
      $('save_as_2').hide();
      $('whatmap2').setStyle({width: width});
      $('wheremap2').setStyle({width: width});
    }

    $$('span.show_text').each( function(span) { span.hide(); });
}

function getMapUrl (map,query_only) {
    var query = $H();
       query['zl'] = map.dpmap.getZoomLevel();
        var coords = map.dpmap.getCenterLatLng();
        query['centerX'] = coords.lat;
        query['centerY'] = coords.lng;
        
     var ind = map.dpmap.getIndicator();
       if(typeof(ind) != 'undefined') { 
            query['cid'] = ind.id; 
            query['tc'] = ind.getActiveColor();
            query['cats'] = ind.getActiveBreaks();
	    query['thematic'] = ind.getActiveThematicBoundary();
        }

        if (map.dpmap.place ) { 
            query['pl'] = map.dpmap.place.id;
        }
	link ='';
    if (query_only) {
       return query.toQueryString();
    }

    return link + query.toQueryString();
}



function pageURI( print, query_add ) {
    var query = $H();
    if($('map1_container').visible()) {
        query['mp1z'] = map1.dpmap.getZoomLevel();
        var coords = map1.dpmap.getCenterLatLng();
        query['mp1lat'] = coords.lat;
        query['mp1lng'] = coords.lng;
        if(typeof(map1.dpmap.currentIndicator) != 'undefined') { 
            query['mp1cid'] = map1.dpmap.currentIndicator.id; 
            query['mp1theme'] = map1.dpmap.currentIndicator.getActiveColor();
            query['mp1breaks'] = map1.dpmap.currentIndicator.getActiveBreaks();
	    query['mp1thematic'] = map1.dpmap.currentIndicator.getActiveThematicBoundary();
        }

        if (map1.dpmap.place ) { 
            query['mp1pl'] = map1.dpmap.place.id;
        }else if (typeof(whereSelectValues) != 'undefined' &&
            typeof(whereSelectValues['map1']) != 'undefined') {
            query['mp1pl'] = whereSelectValues['map1']['key'];
        }
    }

    if($('map2_container').visible()) {
        var map = !$('map1_container').visible() ? 'mp1' : 'mp2';
        query[map + 'z'] = map2.dpmap.getZoomLevel();
        var coords = map2.dpmap.getCenterLatLng();
        query[map + 'lat'] = coords.lat;
        query[map + 'lng'] = coords.lng;
        if(typeof(map2.dpmap.currentIndicator) != 'undefined') { 
            query[map + 'cid'] = map2.dpmap.currentIndicator.id; 
            query[map + 'theme'] = map2.dpmap.currentIndicator.getActiveColor();
            query[map + 'breaks'] = map2.dpmap.currentIndicator.getActiveBreaks();
	    query[map + 'thematic'] = map2.dpmap.currentIndicator.getActiveThematicBoundary();
        }
        if (map2.dpmap.place ) { 
            query['mp2pl'] = map2.dpmap.place.id;
        }else if (typeof(whereSelectValues) != 'undefined' &&
            typeof(whereSelectValues['map2']) != 'undefined') {
            query['mp2pl'] = whereSelectValues['map2']['key'];
        }
    }

    for(key in query_add) {
	query[key] = query_add[key];
    }

    var link = '';
    if( print ) { 
        query['print'] = 1;
        link = 'http://www.nychanis.com/map/print?';
    }else {
        link = 'http://www.nychanis.com/map?';
    }

    return  link + query.toQueryString();
}

