﻿
function contactTimes(informationItemId, type, name) {
    var DialogUrl;
    DialogUrl = 'preferred-contact-time.aspx?Time=AM&t=' + type + '&n=' + name.replace(',', ' ') + '&id=' + informationItemId;
    window.radopen(DialogUrl, 'ContactTimes');
    return false;

}
function ShowSendMessageDialog(fastServiceId, informationItemId, ismissing, isemployer) {

    var DialogUrl;
    var extraQueryString = "";
    
    //ZV - if it is a missing person we need special method to get email address
    if (ismissing == 'True') {
        extraQueryString += "&ismissing=1";
    }
    
    //ZV - If this is an employer we need special method to get information
    if (isemployer == 'True') {
        extraQueryString += "&isemployer=1";
    }
    DialogUrl = 'fastmessage' + fastServiceId + '.aspx?id=' + detailedListingId.substring(1) + extraQueryString;
    DialogUrl = 'fastmessage' + fastServiceId + '.aspx?id=' + detailedListingId.substring(1) + '&subid=' + informationItemId + extraQueryString;
    window.radopen(DialogUrl, 'FastMessage' + fastServiceId);
    return false;
}
var geocoder = new GClientGeocoder();

$(document).ready(function() {
    if ($("#personalmap").length > 0) {
        var map = new GMap2($("#personalmap")[0]);
        map.setUIToDefault();
        showAddress(personalAddress, map);
    }
    $("[id$='_linkShowMap']").click(function() {
        showBusinessMap();
        return false;
    });
});
function showBusinessMap() {
    if (loadBusinessMap()) {
        tb_show('',
                '#TB_inline?height=300&width=420&inlineId=businessmap&modal=false', false);

    }
    else {
        $("#businessmap").empty();
        $("#businessmap").append("<p>Google Map could not be loaded due to invalid address</p>");
        tb_show('',
                '#TB_inline?height=100&width=350&inlineId=businessmap&modal=false', false);
        //hack to show caption of thickbox
//        $("#TB_ajaxContent div:first-child").css({ 'top': '1000px' });
    }
}

function loadBusinessMap()
{
    if ($("#businessmap").length > 0) {
        var map = new GMap2($("#businessmap")[0], { size: new GSize(420, 300) });
        map.setUIToDefault();
        showAddress(businessAddress, map);
        return true;  
    }
    return false;
}
function showAddress(address, map) {
    geocoder.getLatLng(
    address,
    function(point) {
        if (!point) {
            map.setCenter(new GLatLng(0, 0), 0);
            return;
        } else {
            map.setCenter(point, 15);
            var marker = new GMarker(point);
            map.addOverlay(marker);
            //marker.openInfoWindowHtml(address);
            return;
        }
    }
  );
}
