function serviceAreaSelected(info)
{
    if (info.serviceAreaId != -1)
    {
        serviceAreaSelectedGlobal(info);
        
        var locationParameter = getLocationParameter(info);
        var result = $.ajax({
            url: '/Handlers/SelectorActions.ashx?serviceAreaId=' + info.serviceAreaId + '&' + locationParameter + '&contextId=' + info.contextId + '&serviceTypeId=' + info.serviceTypeId + '&action=' + ACTION_GET_REDIRECT_OPTION,
            async: false,
            dataType: "application/json",
            error: function (XMLHttpRequest, textStatus, errorThrown) { handleError(info.msgControlId, errorThrown); }
            }).responseText;       
        
        try { result = eval('(' + result + ')');} catch(err) { result = '';}   
        if (result != null && result != '')
        {                  
            if (info.useSkin)
            {
                redirectUsingSkin(info);
            }
            else if (info.contextId == 1)//Residential
            {
                if (result.HomeRedirectOption == 1) //CompareRates
                {
                    redirectToCompareOffers(info);                
                }
                else //GetQuote
                {
                    redirectToBusinessService(info);
                }
            }
            else if (info.contextId == 2)//Comercial
            {
                if (result.BusinessRedirectOption == 1) //CompareRates
                {
                    redirectToCompareOffers(info);
                }
                else //GetQuote
                {
                    redirectToBusinessService(info);
                }
            }
        }
    }
}

function redirectUsingSkin(info)
{
    var customDataParameter = getCustomDataParameter(info);
    var locationParameter = getLocationParameter(info);
    if (info.skinTarget == "_parent")
    {
        window.open(info.skinHost + info.skinBusinessSubmitPageUrl + "?sa=" + info.serviceAreaId + "&" + locationParameter + "&ContextId=" + info.contextId + '&serviceTypeId=' + info.serviceTypeId + "&skin=" + info.skin + customDataParameter, info.skinTarget);
    }
    else    
    {
        window.location = info.secureSiteUrl + "/" + info.skinBusinessSubmitPageUrl + "?sa=" + info.serviceAreaId + "&" + locationParameter + "&ContextId=" + info.contextId + '&serviceTypeId=' + info.serviceTypeId + "&skin=" + info.skin + customDataParameter;
    }
}

function redirectToCompareOffers(info)
{
    var customDataParameter = getCustomDataParameter(info);
    var locationParameter = getLocationParameter(info);
    if(top==self)
        window.location = '/compareoffers.aspx?sa=' + info.serviceAreaId + '&' + locationParameter + '&ContextId=' + info.contextId + '&subpageid=' + info.voidSubLinkId4BizPages + '&serviceTypeId=' + info.serviceTypeId + customDataParameter;
    else
        window.open('/compareoffers.aspx?sa=' + info.serviceAreaId + '&' + locationParameter + '&ContextId=' + info.contextId + '&subpageid=' + info.voidSubLinkId4BizPages + '&serviceTypeId=' + info.serviceTypeId + customDataParameter, '_parent');
}

function redirectToBusinessService(info)
{
    var customDataParameter = getCustomDataParameter(info);
    var locationParameter = getLocationParameter(info);
    window.location = info.secureSiteUrl +  '/business_service.aspx?sa=' + info.serviceAreaId + '&' + locationParameter + '&ContextId=' + info.contextId + '&serviceTypeId=' + info.serviceTypeId + customDataParameter;
}

function getCustomDataParameter(info)
{
    var customDataParameter = '';
    if (info.customData != '' && info.customData != null){
        customDataParameter = '&cd=' + info.customData;
    }        
    return customDataParameter;
}