$(document).ready(function () {
    $('#searchButton').click(function() {
        if ($('#searchFields').is(":hidden"))
            $('#searchFields').show("slow");
        else
            $('#searchFields').hide("slow");
    });

    // cbMain
});

function printPage() {
    window.print();
}

function setupPageTools(tools) {
    var toolsHTML = tools.html();
    var firstH1 = $('.cbMain h1:first');
    if (firstH1)
    {
        firstH1.css('display', 'inline');
        firstH1.after('<div class="clear">&nbsp;</div>');
        firstH1.after(toolsHTML);
    }
}

jQuery.fn.outerHTML = function() {
    return $('<div>').append(this.eq(0).clone()).html();
};

function searchCityAgents() {
    var cityField = document.getElementById('cityname');
    if (cityField) {
        var city = cityField.value;
        if (city.indexOf(',') > 0)
            city = city.substr(0, city.indexOf(','));
        window.location.href = '/trip-planning/find-an-agent.aspx?city=' + city;
    }
    return false;
}

//usage javascript:showDialog('4908','Testing');
function showDialog(ID, Title, Width, Height) {
    if ($(".popUpDialog").length > 0) {
        $(".popUpDialog").dialog("open");
        if ($.browser.msie && $.browser.version < 8) { $('.ui-dialog-titlebar-close').css('margin-top', '1px'); }
    } else {
        $('body').append('<div class="popUpDialog"></div>');
        Width = (Width != null && Width != '') ? Width : 640;
        Height = (Height != null && Height != '') ? Height : 480;
        $(".popUpDialog").dialog({ autoOpen: true, height: Height, width: Width, modal: true, draggable: false, resizable: false, position: 'center', title: '<h4>' + Title + '</h4>', zIndex: 100000 });
    }

    $.ajax({
        url: '/popupdialog.ashx?id=' + ID,
        async: false,
        success: function (data) {
            $(".popUpDialog").html(data);
        }
    });
}

/*********** Generic Helper Function *************/
function showObj(obj) {
    objWin = window.open('', 'objectWindow', '');
    if (!objWin.document.body)
        objWin.document.write('<html><head></head><body></body></html>');

    objWin.document.body.style.font = '11px Ariel, Helvetica, Sans-serif';
    var strHTML = '<h2>' + obj + '</h2>';
    strHTML += '<table cellspacing="0" border="1">';
    var objRegExp = new RegExp('<', 'g');
    var objRegExpLB = new RegExp('\\n', 'g');
    for (o in obj) {
        strHTML += '<tr>';
        strHTML += '<td valign="top">' + o + ': </td>';
        strHTML += '<td valign="top" style="color: #660000;">';
        try {
            strObjTxt = new String(obj[o]);
            strHTML += '<pre>' + strObjTxt.replace(objRegExp, '&lt;') + '</pre>';
        } catch (er) {
            strHTML += '--ERROR [' + er + ']--';
        }
        strHTML += '</td>';
        strHTML += '</tr>';
    }
    strHTML += '</table>';
    strHTML += '<br />';
    objWin.document.body.innerHTML += strHTML;
}
