/**
 * Given a location on the map (in pixel coordinates relative to the top left of the map)
 * return a location relative to the top-left of the browser window
 * @param {OpenLayers.Evt.xy) Map location
 * @param {OpenLayers.Map} the map
 * @return {OpenLayers.Evt.xy} location relative to the browser window
 */
function getDocumentPosition(px, map) {
    var mapDiv = document.getElementById('map');
    return new OpenLayers.Pixel(px.x + mapDiv.offsets[0], px.y + mapDiv.offsets[1]);
}

/**
 * generic AJAX failure callback
 */
function ajaxFailure() {
    var loadingDiv = Ext.get('small-loading-indicator');
    loadingDiv.setVisible(false);
    alert("Error sending AJAX Request. Please try again later.");
}

/**
  Function: enablePrint 
     Checks whether or not layers are one or off and sets the print button
     to be enabled or disabled as a result
*/
function enablePrint(){
    var vizLayers = tree.getChecked('id');
    if (vizLayers.length > 0){
        // enable the print button
        Ext.getCmp('printButton').enable(); 
    } else {
        // disable the print button
        Ext.getCmp('printButton').disable(); 
    } 
}  

/**
 * Set of functions to convert hex colors to rgb values
 */
function HexToR(h) {return parseInt((cutHex(h)).substring(0,2),16)}
function HexToG(h) {return parseInt((cutHex(h)).substring(2,4),16)}
function HexToB(h) {return parseInt((cutHex(h)).substring(4,6),16)}
function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h}



                            
