﻿// JScript File
function map_Load(){
    if (GBrowserIsCompatible()){
        document.getElementById('divMap').style.display = 'block'
        document.getElementById('divDirection').style.display = 'none'
        set_mapSettings()
        set_mapControls()
    }
    else{
        document.getElementById('divMap').style.display = 'none'
        document.getElementById('divDirection').style.display = 'block'
    }
}                    
function set_mapSettings(){
    if (GBrowserIsCompatible()){
        _map = new GMap2(document.getElementById('map'));
        _geoCoder = new GClientGeocoder();
        _gPointAB = new GLatLng(39.726779, -84.057469);
        _directions = new GDirections(_map, document.getElementById("my_text_div"));
        document.getElementById("my_text_div").style.display = 'none';
        setCenter(_gPointAB);
        createMarker(_gPointAB);
    }
}
function set_Directions(){
    var _mStreet = document.getElementById('uxStreet').value;
    var _mZip = document.getElementById('uxZip').value;
    var _mCity = document.getElementById('uxCity').value;
    var _mState = document.getElementById('uxState').value;
    
    if (_mStreet != ''){
        if (_mZip != ''){
            document.getElementById("my_text_div").style.display = 'block';
            _directions.load('from: ' + _mStreet + ', ' + _mZip + ' to: 1265 North Fairfield Road, Beavercreek, OH');
        }
        else{
            if(_mCity!= '' && _mState!= ''){
            document.getElementById("my_text_div").style.display = 'block';
                _directions.load('from: ' + _mStreet + ', ' + _mCity + ', ' + _mState + ' to: 1265 North Fairfield Road, Beavercreek, OH');
            }
            else{
                alert('Please enter your current city and state, or zip code.');
                return;
            }
        }
    }
    else{
        alert('Please enter your current street address.');
        return;
    }
}
function set_mapControls(){
    _map.getPane(G_MAP_FLOAT_PANE).appendChild(_toolTip);
    _toolTip.style.visibility='hidden';
    
    _map.addControl(new GSmallMapControl());
}
function setCenter(_mPoint){
    _map.setCenter(_mPoint, 11);
}
function createMarker(_mPoint) {
        var Marker = new GMarker(_mPoint);
        GEvent.addListener(Marker, 'click', function(){ 
                                                marker_Click(Marker);
                                            });
        GEvent.addListener(Marker, 'mouseover', function(){ 
                                                marker_MouseOver(Marker);
                                            });
        GEvent.addListener(Marker, 'mouseout', function(){ 
                                                marker_MouseOff(Marker);
                                            });
                                               
        _map.addOverlay(Marker);
       Marker.openInfoWindowHtml('1265 North Fairfield Road<br>Beavercreek, Ohio');
}                   
function marker_Click(marker)
{
    marker.openInfoWindowHtml('1265 North Fairfield Road<br>Beavercreek, Ohio');
}
function marker_MouseOver(marker)
{
    _toolTip.innerHTML = ('');
	var point = _map.getCurrentMapType().getProjection().fromLatLngToPixel(_map.fromDivPixelToLatLng(new GPoint(0,0),true),_map.getZoom());
	var offset = _map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),_map.getZoom());
	var anchor = marker.getIcon().iconAnchor;
	var width = marker.getIcon().iconSize.width;
	var height = _toolTip.clientHeight;
	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x + width, offset.y - point.y -anchor.y -height)); 
	pos.apply(_toolTip);
	_toolTip.style.visibility = 'visible';
}
function marker_MouseOff(marker)
{
	_toolTip.style.visibility='hidden';
}
function printContainer(s){
    if(s!=null){
        if(s.Parent!=null){
            alert('2');
            window.print(s.parent);
        }
    }
}