var is_map = false;
function initialize_map() {   
    if (GBrowserIsCompatible() && is_map == false) {        
        var map = new GMap2(getElement("map_canvas"));        
        map.setCenter(new GLatLng(41.937387,-87.665126), 13);       
        map.setUIToDefault(); 
        map.openInfoWindow(map.getCenter(), getElement("map_info")); 
        is_map = true; 
        if (document.body.scrollHeight) {   
            window.scrollBy(0, 2000); 
        } else if (screen.height) { // IE5   
            window.scrollBy(0, screen.height); 
        }   
    }   
}

function get_directions() {  
    var start = getElement("start_address");
    if (start.value != "") {
        var map = new GMap2(getElement("map_canvas"));  
        var directionsPanel = getElement("map_directions"); 
        
        var link_button = getElement("print_directions_button");
        var vis = link_button.style;  // if the style.display value is blank we try to figure it out here  
	    if(vis.display==''&&link_button.offsetWidth!=undefined&&link_button.offsetHeight!=undefined)    
	    vis.display = (link_button.offsetWidth!=0&&link_button.offsetHeight!=0)?'block':'none'; 
	    vis.display = 'block';
	    
        directionsPanel.innerHTML = ""; 
        map.setCenter(new GLatLng(41.937387,-87.665126), 13);  
        var directions = new GDirections(map, directionsPanel); 
        directions.clear(); 
        directions.load("from: " + start.value + " to: 3047 N Lincoln Ave, Chicago IL 60657");
        if (document.body.scrollHeight) {   
            window.scrollBy(0, 2000); 
        } else if (screen.height) { // IE5   
            window.scrollBy(0, screen.height); 
        }

    }
}   

function print_directions() {
    
    var content = getElement("map_directions").innerHTML;
    var pwin = window.open('','_blank','width=500,height=400,resizeable=yes,scrollbars=yes');

    pwin.document.open();
    pwin.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
                        + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
                        + "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">"
                        + "<head><style type=\"text/css\">.reg_fs{border: none;}<\/style>"
                        + "<title>Print Directions<\/title><\/head>"
                        + "<body><div id=\"directions\">"
                        + "<form action=\"javascript:self.print();\">"
                        + "<fieldset class=\"reg_fs\"><input type=\"submit\" value=\"Print\"><\/input>"
                        + "&nbsp;<input type=\"button\" value=\"Close\" onclick=\"window.close();\"><\/input><\/fieldset>"
                        + "<\/form>" + content + "<\/div><\/body><\/html>");
    pwin.document.title = "Print Directions";
    if (navigator.userAgent.indexOf("Opera") == -1 && navigator.userAgent.indexOf("Safari") == -1) {
        pwin.location.reload(true);
    }
    pwin.focus();
} 
