var autoSearchFields = new Array('type', 'region', 'keyword', 'facilities', 'typeOfCare', 'minRentalPrice', 'maxRentalPrice', 'minBuyPrice', 'maxBuyPrice');

function hideEmptyThumbnails() {
    $('div[rel=empty]').hide();
    $('div[rel^=empty{tag_image]').hide();
}
function hideEmptyLinks() {
    $('a[href^={tag_]').hide();
    $('a[href=""]').hide();
}
function formatFacilityTitle() {
    var thumb;
    var titleObj = $('#item-title');
    var title = titleObj.text();
    var titleParts = title.split('-');
    if (titleParts.length >= 2) {
        var part1 = titleParts[0];
        var part2 = titleParts[1];
        titleObj.html('<h4 class="decorate" class="js">' + part1 + '</h4><h1 class="js">' + part2 + '</h1>');
    }
}
function formatUnitTitle() {
    var titleObj = $('#item-title');
    var title = titleObj.text();
    var titleParts = title.split('-');
    if (titleParts.length >= 4) {
        var part1 = titleParts[0];
        var part2 = titleParts[1];
        var part3 = titleParts[2];
        var part4 = titleParts[3];
        titleObj.html('<h4 class="decorate" class="js">' + part1 + '</h4><h1 class="js">' + part3 + ' - ' + part4 + '</h1>');
    }
}
function formatFacilities() {
    var facilities = $('#facilities');
    var list = facilities.text().split(',');
    var content = '<ul>';
    for (i = 0; i < list.length; i++) {
        content += '<li>' + list[i] + '</li>';
    }
    content += '</ul>';
    facilities.html(content);
}
function changeImage() { /* Replace "small" with "main" for CMS pages. */
    var thumbSrc = $(this).attr('href');
    if ($('#main-image').attr('src') != thumbSrc) {
        $('#main-image').fadeOut('slow', function () { /* Preload the image before making the switch */
            var img = new Image;
            img.src = thumbSrc;
            img.onload = function () {
                $('#main-image').attr('src', thumbSrc).fadeIn('slow');
            }
        });
    }
}
function escapeAllWebAppLinks() {
    // Changes all spaces to an underscore
    $('a[href*=/_webapp_]').each(function () {
        $(this).attr('href', escapeWebAppItemLink($(this).attr('href')));
    });
}
function escapeAllLinks() {
    $('a').each(function () {
        $(this).attr('href', escape($(this).attr('href')));
    });
}
function rewriteCustomContentRetrieveLinks() {
    var webAppId;
    $('a[href*=CustomContentRetrieve.aspx]').each(function () {
        if ($(this).attr('class').indexOf('noparse') < 0) {
            webAppId = $(this).attr('href').replace('CustomContentRetrieve.aspx?ID=', '_webapp_');
            $(this).attr('href', webAppId + '/' + escapeWebAppItemLink($(this).text()));
        }
    });
}
function escapeWebAppItemLink(href) {
    return escape(href).replace(/%20/g, '_');
}
function formatItemPrice() {
    var type;
    var fortype;
    var urltype;
    var prefix;
    var numberRegExp;
    var numberStr;
    
    $('span[class=item-price]').children('span').each(function () {
        type = $(this).attr('type').toLowerCase();
        fortype = $(this).attr('fortype').toLowerCase();
        try {
            prefix = $(this).attr('pfix').toLowerCase();
        } catch (e) {
            prefix = type;
        }
        numberRegExp = /[0-9]+/g;
        numberMatch = numberRegExp.exec($(this).text());
		if (numberMatch != null) {
			numberStr = numberMatch[0];
			$(this).html('&pound;' + formatNumberAsCurrency(numberStr));
	    }
	    else {
	    	$(this).html('&pound;' + 'POA');
	    }
        // if this property is for sale AND rent
        // display the price for the type the user is searching against
        if (type.indexOf(',') > 0) {
            try {
                urltype = getUrlVars()['pt'].toLowerCase();
                if (urltype != null) type = urltype;
            } catch (e) {}
            // remove buy,rent prefix
            try {
            	originalValue = $(this).parent().text();
            	newValue = $(this).parent().text().replace(/(Buy\,Rent\W{2}.{1})/g,'');
            	$(this).parent().text(newValue);
            }
            catch(e) {}
        }
        else if (type == fortype) {
            // display the relevant price for the single property type
            if (prefix == '') prefix = type;
            $(this).parent().html(capitaliseFirstLetter(prefix) + ' ' + $(this).html());
        }
    });
}
function capitaliseFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}
function formatItemPriceForCarousel() {
    var type;
    formatItemPrice();
    $('span[class=item-price]').each(function () {
        type = $(this).attr('type');
        if (type != undefined) {
            if ($(this).attr('type').indexOf(',') > 0) {
                $(this).parent().html($(this).html());
            }
        }
    });
}
function formatNumberAsCurrency(number) {
    var suffix = '';
    if (number == 0) {
        return 'POA';
    }
    else {
        if (number < 10000) suffix = ' PCM';
        number += '';
        x = number.split('.');
        x1 = x[0];
        x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        return x1 + x2 + suffix;
    }
}
function displaySearchInfo() {
    var defaultPropertyType = 'buy/rent';
    var propertyType = getUrlVars()['pt'];
    var region = getUrlVars()['r'];
    var postaltown = getUrlVars()['po'];
    var searchType = getUrlVars()['st'];
    var searchTypeName = 'Property to ';
    var radiusMessage = '';
    // Buy or rent
    if (propertyType == '' || propertyType == '*') {
        propertyType = defaultPropertyType;
    }
    // Properties or facilities?
    if (searchType == 'f') searchTypeName = 'Facilities ';
    else searchTypeName += ' ' + propertyType;
    // Add postal town
    if (postaltown == '' || postaltown == undefined) {
        $('#title').html(searchTypeName + ' ' + formatRegion(region));
    }
    else {
        $('#title').html(searchTypeName + ' near ' + unescape(postaltown.toLowerCase()));
        radiusMessage = ' within a 35km (22 miles) radius';
    }
    // Show result count
    $('#stats').html('<div style="float:left;">Results ' + getItemCountMin() + ' to ' + getItemCountMax() + radiusMessage + ' </div><div style="float:right;"><a href="/" id="new-search-link">start new search</a></div><div style="clear:both;" />');
} /* PAGINATION */
function getItemCountMin() {
    return ((getCurrentPage() * itemGroupSize) - (itemGroupSize - 1));
}
function getItemCountMax() {
    if (results != undefined) return (getItemCountMin() + (results.length - 1));
    return (getItemCountMin() + (itemGroupSize - 1));
}
function getItemGroupSize() {
    return getUrlVars()['Items'];
}
function getCurrentPage() {
    var page = getUrlVars()['Page']
    if (page == undefined) page = 1;
    return page;
}
function getUrlVars(url) {
    var vars = [],
        hash;
    var hashes;
    if (url == undefined) {
        hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    }
    else {
        hashes = url.slice(url.indexOf('?') + 1).split('&');
    }
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
function formatRegion(region) {
    try {
        if (region == '*' || region == '') {
            return 'across the UK';
        }
        else if (region == 'East') {
            return 'in Eastern England';
        }
        else if (region.indexOf('%20') > 0) {
            return 'in the ' + region.replace(/%20/g, ' ');
        }
        else {
            return 'in ' + region;
        }
    }
    catch (e) {
        return 'across the UK';
    }
}
function handleNoSearchResults() {
    if ($('[id^=webappsearchresults]').html() == 'No results found.') {
        $('[id^=webappsearchresults]').hide();
        $('#no-results').show();
        $('#map').hide();
        $('#stats').html('Your search returned 0 out of ' + $('#totalProperties').val() + ' properties in the UK');
    }
}
function autoSearchHandler() {
    $('a[rel=autosearch]').click(function () {
        autoSearch($(this));
        return false;
    });
}
function autoSearch(trigger) {
    var field;
    for (i = 0; i < autoSearchFields.length; i++) {
    	field = autoSearchFields[i];
        if ($(trigger).attr(field) != undefined && $(trigger).attr(field) != '') {
            $('[rel=' + field + ']').val($(trigger).attr(field));
            // try { console.log($('[rel=' + field + ']').val()); } catch(e) {}
        }
    }
    addTrackingVarsToAutoSearchUrl();
    $('#auto-search').submit();
}
function clearAutoSearchFields() {
	var field;
    for (i = 0; i < autoSearchFields.length; i++) {
    	field = autoSearchFields[i];
        $('[rel=' + field + ']').val('');
        // try { console.log('cleared autosearch field: ' + field); } catch(e) {}
    }
}
function addTrackingVarsToSearchUrl() {
    var region = $('[rel=region]').val();
    var type = $('input[rel=type]:checked').val();
    var po = '';
    var pc = $('#Postcode_4065').val();
    if (pc == undefined) pc = $('#Postcode_4399').val();
    var pt = $('#postaltown').val();
    if (pc != undefined && pc != '') {
        po = pt;
    }
    if (region == undefined) {
        region = $('[rel=region]').val();
    }
    if (type == undefined) {
        type = $('[rel=type]').val();
    }
    if (po == undefined) {
        type = $('[rel=po]').val();
    }
    $('#search-form').attr('action', $('#search-form').attr('action') + '&r=' + region + '&pt=' + type + '&po=' + po);
}
function addTrackingVarsToAutoSearchUrl() {
    var region = $('input[rel=region]').val();
    var type = $('input[rel=type]').val();
    $('#auto-search').attr('action', $('#auto-search').attr('action') + '&r=' + region + '&pt=' + type + '&po=');
}
function appendSearchVarsToPaginationUrls() {
    var linkHref;
    $("ul.pagination").children('li').each(function () {
        linkHref = $(this).children('a').attr('href');
        $(this).children('a').attr('href', appendSearchVarsToUrl(linkHref));
        //alert($(this).children('a').attr('href'));
    });
}
function appendSearchVarsToUrl(url) {
    var type = getUrlVars()['pt'];
    var region = getUrlVars()['r'];
    var po = getUrlVars()['po'];
    var st = getUrlVars()['st'];
    if (type != undefined) url += '&pt=' + type;
    if (region != undefined) url += '&r=' + region;
    if (po != undefined) url += '&po=' + po;
    if (st != undefined) url += '&st=' + st;
    return url;
}
function resetSearchValues() {
    $('select[rel=region]').val('*');
    $('#CAT_Custom_73303_input').val('All Regions');
    $('#Postcode_4065').val('');
    $('#Postcode_4399').val('');
    $('#postaltown').val($('#default-text').val());
    $('#postaltown').attr('class', 'postcode-search-input-faded');
    $('#isAdvancedSearchActive').val('0');
}
function displayTypeSpecificInfo(type) {
    if (type == 'Buy') {
        $('#tenure').show();
    }
}
function toggleSearchType() {
    $('#postcode-search').toggle();
    $('#region-select').toggle();
    $('select[rel=region]').val('*');
    $('#CAT_Custom_73303_input').val('All Regions');
    $('#Postcode_4065').val('');
    $('#Postcode_4399').val('');
    $('#postaltown').val($('#default-text').val());
    $('#postaltown').attr('class', 'postcode-search-input-faded');
    if ($('#toggle-search').text() == 'Search by region?') {
        $('#toggle-search').text('Search by town/city?');
        $('#postcode-search-active').val('false');
    }
    else {
        $('#toggle-search').text('Search by region?');
        $('#postcode-search-active').val('true');
    }
}
function toggleAdvancedSearch() {
    var diff = '+=190';
    var active = false;
    $('a[rel=advanced-search]').attr('disabled');
    if ($('#isAdvancedSearchActive').val() == '0') {
        $('#search').css('background-image', 'url(../images/layout/uk-map-advanced.gif)');
        $('#advanced-search').fadeTo(0, 1);
        $('a[rel=advanced-search]').text('Basic Search?');
        $('#isAdvancedSearchActive').val('1');
        $('#buy-rent').show();
        active = true;
    }
    else {
        diff = '-=190';
        $('#isAdvancedSearchActive').val('0');
        $('#buy-rent').hide();
        active = false;
    }
    $('#search').animate({
        height: diff
    }, 400, function () {
        if (!active) {
            $('#advanced-search').fadeTo(1, 0);
            $('#search').css('background-image', 'url(../images/layout/uk-map-bottom.gif)');
            $('a[rel=advanced-search]').text('Advanced Search?');
        }
        $('a[rel=advanced-search]').removeAttr('disabled');
    });
}
function clearOperatorFilter() {
    $('#operator').val('');
}
function bindRelatedFields() {
    $('[bindTo]').each(function (target) {
        var targetField = $(this);
        //alert('target: ' + targetField.attr('name'));
        var sourceField = $('#' + targetField.attr('bindTo'));
        //alert('source: ' + sourceField.attr('name'));
        $('#search-form').submit(function (target) {
            targetField.val(sourceField.val());
        });
    });
}
function advancedSearchHandler() {
    var minPrice;
    var maxPrice;
    var type = $('input[name=CAT_Custom_73955]').val();
    // switch between rent/buy
    $('input[name=CAT_Custom_73955]').click(function () {
        $('select[rel*=price]').hide();
        $('select[rel*=price]').val('');
        $('select[rel*=price]').attr('disabled', 'disabled');
        minPrice = $('select[rel=' + $(this).val() + '-price-min]');
        maxPrice = $('select[rel=' + $(this).val() + '-price-max]');
        minPrice.removeAttr('disabled');
        maxPrice.removeAttr('disabled');
        minPrice.show();
        maxPrice.show();
    });
    // if the price or beds max/min are selected, show units instead of facilities
    $('select[rel^=' + type + '-price]').change(function () {
        var r = parseInt($('select[rel^=rooms]').val());
        var minp = parseInt($('select[rel^=' + type + '-price-min]').val());
        var maxp = parseInt($('select[rel^=' + type + '-price-max]').val());
        $('#isUnitSearch').val((minp > 0 || maxp > 0 || r > 0) ? 1 : 0);
        // try { console.log('isUnitSearch = ' + $('#isUnitSearch').val()); } catch (e) {}
    });
    // if a care type is chosen, show units instead of facilities
    $('input[name=CAT_Custom_72290]').click(function () {
        $('#isUnitSearch').val(1);
        try { console.log('isUnitSearch = ' + $('#isUnitSearch').val()); } catch (e) {}
    });
    $('select[rel^=rooms]').change(function () {
        var r = parseInt($(this).val());
        var minp = parseInt($('select[rel^=' + type + '-price-min]').val());
        var maxp = parseInt($('select[rel^=' + type + '-price-max]').val());
        $('#isUnitSearch').val((minp > 0 || maxp > 0 || r > 0) ? 1 : 0);
        // try { console.log('isUnitSearch = ' + $('#isUnitSearch').val()); } catch (e) {}
    });
}
function truncateTeaserText() {
    var text = '';
    var dots = '...';
    $('div .item-teaser').each(function () {
        text = $(this).text().replace('<br>/g', ' ');
        if (text.length > 150) {
            if (text.indexOf('.') == text.length) dots = '';
            $(this).text(text.substring(0, 150) + '...');
        }
    });
}
function Marker(lat, lon, index, title, description, width, address) {
    this.lat = lat;
    this.lon = lon;
    this.index = index;
    this.title = title;
    this.description = description;
    this.width = width;
    this.address = address;
    this.toString = function () {
        return 'Marker: ' + this.point;
    };
}
function enquiryFormHandler() {
    var isValid = false;
    var action;
    $('.enquiry-field').each(function () {
        $(this).focus(function () {
            if ($(this).val() == $(this).attr('watermark')) {
                $(this).val('');
                $(this).attr('class', $(this).attr('class') + ' active');
            }
        });
        $(this).blur(function () {
            if ($(this).val() == '') {
                $(this).val($(this).attr('watermark'));
                $(this).attr('class', $(this).attr('class').replace(' active', ''));
            }
        });
    });
    $('#enquiry-send').click(function () {
        var emailList = '';
        var firstName = $('#FirstName');
        var lastName = $('#LastName');
        var email = $('#EmailAddress');
        var homePhone = $('#HomePhone');
        var message = $('#CAT_Custom_73933');
        var isValid = $('#isValid');
        var customerEmail = $('#customerEmail');
        var additionalEmail = $('#additionalEmail');
        var messageContent = message.val();
        var propertyName = $('#PropertyName');
        var propertyAddress = $('#PropertyAddress');
        if (firstName.val() == firstName.attr('watermark')) firstName.val('');
        if (lastName.val() == lastName.attr('watermark')) lastName.val('');
        if (email.val() == email.attr('watermark')) email.val('');
        if (homePhone.val() == homePhone.attr('watermark')) homePhone.val('');
        if (message.val() == message.attr('watermark')) message.val('');
        checkWholeForm16922(document.forms['enquiry-form']);
        if (isValid.val() == 'true') {
            // concatenate emails
            emailList = customerEmail.val();
            if (additionalEmail.val() != '') emailList = emailList + ',' + additionalEmail.val();
            //if (getUrlVars['debug'] != '') alert(emailList);
            // set action to reciept only
            action = 'http://homeswithcare.com/Default.aspx?A=Form&PageID=/enquiry-thanks.htm&Email=' + emailList + '&Subject=' + escape('Enquiry from Homes With Care');
            messageContent = '<strong>Property Name</strong>: ' + propertyName.val() + '<br /><strong>Property Address</strong>: ' + propertyAddress.val() + '<br /><strong>Property URL</strong>: ' + window.location.href + '<br /><br /><strong>Message</strong>: ' + message.val();
            $('#CAT_Custom_73933').val(messageContent);
            $('#enquiry-form').attr('target', 'capture');
            $('#enquiry-form').submit();
            $('#enquiry-form').attr('action', action);
            $('#CAT_Custom_73933').attr('name', 'Message');
            $('#enquiry-form').attr('target', 'receipt');
            $('#enquiry-form').submit();
            $('#enquiry-form').hide();
            $('#enquiry-form-thanks').show();
        }
        return false;
    });
}
function checkWholeForm16922(theForm) {
    var why = "";
    if (theForm.FirstName) why += isEmpty(theForm.FirstName.value, "First Name");
    if (theForm.LastName) why += isEmpty(theForm.LastName.value, "Last Name");
    if (theForm.EmailAddress) why += checkEmail(theForm.EmailAddress.value);
    if (theForm.CaptchaV2) why += captchaIsInvalid(theForm, "Enter Word Verification in box below", "Please enter the correct Word Verification as seen in the image");
    if (theForm.CAT_Custom_73933) why += isEmpty(theForm.CAT_Custom_73933.value, "Message");
    if (why != "") {
        alert(why);
    }
    else {
        $('#isValid').val('true');
    }
}
function actionButtonHandler() {
    $('img.action-button').mouseenter(function () {
        $(this).attr('src', $(this).attr('src').replace('-off', '-on'));
    });
    $('img.action-button').mouseleave(function () {
        $(this).attr('src', $(this).attr('src').replace('-on', '-off'));
    });
}
function formatFacilityInfoLink() {
    $('#facility-info-link').children('a').text('View more information about this facility');
    $('#facility-info-link').children('a').attr('class', 'bulleted-link');
}
function formatFacilitySearchLink() {
    var facilityName;
    var facilitySearchLink;
    var searchLinkContainer = $('[rel=facility-search-link]');
    facilitySearchLinks = searchLinkContainer.children('a');
    facilityName = searchLinkContainer.first().text();
    if (facilitySearchLinks.attr('href') != '') {
        searchLinkContainer.html('<a class="bulleted-link" href="/advanced-search"></a>');
        facilitySearchLinks = searchLinkContainer.children('a');
    }
    facilitySearchLinks.text('View all properties at this facility');
    facilitySearchLinks.attr('class', 'bulleted-link');
    facilitySearchLinks.attr('keyword', facilityName);
    facilitySearchLinks.attr('rel', 'autosearch');
    autoSearchHandler();
}
function displayUnitRegions() {
    if (getUrlVars()['r'] == '*') {
        $('span .region-text').show();
    }
}
function insertParam(key, value, url) {
    key = escape(key);
    value = escape(value);
    var kvp = url.substr().split('&');
    var i = kvp.length;
    var x;
    while (i--) {
        x = kvp[i].split('=');
        if (x[0] == key) {
            x[1] = value;
            kvp[i] = x.join('=');
            break;
        }
    }
    if (i < 0) {
        kvp[kvp.length] = [key, value].join('=');
    }
    //this will reload the page, it's likely better to store this until finished
    return url = kvp.join('&');
}
function toggleExactSearch() {
    var actionString;
    var useExactSearch = true;
    $('input[name=CAT_Custom_72607]').each(function () {
        if ($(this).is(':checked')) {
            useExactSearch = false;
        }
    });
    actionString = insertParam('Exact', useExactSearch, $("#search-form").attr("ACTION"));
    $("#search-form").attr("ACTION", actionString);
}
function getGACode(operatorName) {
    var ga = new Array();
    if (operatorName == '') {
        return null;
    }
    ga["Abbey Care Village"] = "UA-20021162-1";
    ga["Adlington"] = "UA-20021262-1";
    ga["Affinity Care Homes"] = "UA-22226150-1";
    ga["Anchor"] = "UA-16789002-1";
    ga["Aspen Retirement Living"] = "UA-29333533-1";
    ga["Aspire Housing"] = "UA-29329890-1";
    ga["Audley Retirement"] = "UA-16783999-1";
    ga["Autumn Assisted Living"] = "UA-20021165-1";
    ga["Avery Healthcare"] = "UA-29331776-1";
    ga["Barchester Healthcare"] = "UA-16717534-1";
    ga["Barton Park"] = "UA-20020392-1";
    ga["Beaumont Village"] = "UA-20020976-1";
    ga["Belong"] = "UA-16799286-1";
    ga["BEN - Motor & Allied Trades"] = "UA-16803100-1";
    ga["Bield Housing Association Ltd"] = "UA-16799777-1";
    ga["Bramshott Place Village"] = "UA-16798197-1";
    ga["Brendon Care"] = "UA-16798199-1";
    ga["Broad Oak Manor"] = "UA-16799296-1";
    ga["Care South"] = "UA-29332567-1";
    ga["Care Village Group Ltd"] = "UA-16799786-1";
    ga["Cheviot Homes"] = "UA-16803505-1";
    ga["Czajka Care Group"] = "UA-29333838-1";
    ga["Danny House"] = "UA-20021176-1";
    ga["ExtraCare Charitable Trust"] = "UA-20020397-1";
    ga["Golden Living"] = "UA-20020988-1";
    ga["Goldsborough - BUPA"] = "UA-16799385-1";
    ga["Grove Place"] = "UA-20021264-1";
    ga["Hadrian Healthcare"] = "UA-20022701-1";
    ga["Hanover"] = "UA-20021265-1";
    ga["Hawthorns"] = "UA-16799997-1";
    ga["Highland Park Village"] = "UA-16804903-1";
    ga["Inchmarlo"] = "UA-16804904-1";
    ga["Joseph Rowntree Housing Trust"] = "UA-16799798-1";
    ga["KeyHomes East"] = "UA-29331357-1";
    ga["Linkfield Court"] = "UA-16804412-1";
    ga["LifeCare Residences"] = "UA-20263389-1";
    ga["Manor House Senior Living"] = "UA-16804907-1";
    ga["Maria Mallaband Care Group"] = "UA-16804332-1";
    ga["MHA"] = "UA-16804336-1";
    ga["Middleton Hall"] = "UA-16804933-1";
    ga["Middleton Woods"] = "UA-16805225-1";
    ga["Midland Heart"] = "UA-25464186-1";
    ga["Mitford Care"] = "UA-16804938-1";
    ga["Motcombe Grange"] = "UA-16804348-1";
    ga["Oakbridge"] = "UA-16804443-1";
    ga["Oakbridge Retirement Villages"] = "UA-16802595-1";
    ga["Pegasus Retirement"] = "UA-29334335-1";
    ga["Prestigious Retirement Villages"] = "UA-25512916-1";
    ga["Prime Life"] = "UA-16807113-1";
    ga["PSP Healthcare Ltd"] = "UA-16805833-1";
    ga["Ramsay Healthcare"] = "UA-19971820-1";
    ga["Rayners"] = "UA-16807412-1";
    ga["Renaissance Lifecare"] = "UA-16805646-1";
    ga["Retirement Security Ltd"] = "UA-20020678-1";
    ga["Retirement Villages"] = "UA-16806718-1";
    ga["Richmond Care Villages"] = "UA-16805836-1";
    ga["Royal Bay Group"] = "UA-16805547-1";
    ga["Saxon Weald"] = "UA-22226516-1";
    ga["Sentinel Healthcare"] = "UA-16807414-1";
    ga["Shaw Healthcare"] = "UA-29333642-1";
    ga["Shelbourne"] = "UA-20022512-1";
    ga["Sheringham House"] = "UA-20021095-1";
    ga["Signature"] = "UA-16805839-1";
    ga["Southdowns"] = "UA-20020788-1";
    ga["Somerset Care"] = "UA-25512914-1";
    ga["Standon House Ltd"] = "UA-29332378-1";
    ga["St Georges"] = "UA-16805650-1";
    ga["St Monica Trust"] = "UA-16806138-1";
    ga["Sunrise Senior Living"] = "UA-16805553-1";
    ga["The Amesbury Abbey Group"] = "UA-19972010-1";
    ga["The Priory"] = "UA-16806142-1";
    ga["The Whiteley Homes Trust"] = "UA-16808843-1";
    ga["Viridian Housing"] = "UA-29333536-1";
    ga["Westward Care"] = "UA-20022514-1";
    return ga[operatorName];
}
function getOperatorFromWebAppName(name) {
    var operator = '';
    if (name != '') {
        operator = jQuery.trim(name.split('-')[0]);
    }
    return operator;
}
function showPhoneNumber() {
	try {
		$('#hotline-button').fadeOut('fast');
		$('#hotline-window').fadeIn('fast');
		registerContactNumberRequestHWC();
		registerContactNumberRequestCustomer();
	}
	catch(e) {
		alert('Sorry, there was a problem displaying the phone number. Please email us at enquiries@homeswithcare.com.');
		try { console.log(e); } catch(ex) {}
	}
}

var autolinkCountArray = new Array();
$(function () {
    try {
    	clearAutoSearchFields();
	    if (window.location.href.indexOf('/_blog/') == -1 &&
	    		window.location.href.indexOf('/Default.aspx') == -1 &&
	    		window.location.href.indexOf('/customer-zone/') == -1 &&
	    		window.location.href.indexOf('/Links') == -1 &&
	    		window.location.href.indexOf('/glossary') == -1) {
		    $('body').autolink('assisted living', '/questions', autolinkCountArray);
		    $('body').autolink('integrated close care', '/questions', autolinkCountArray);
		    $('body').autolink('close care', '/questions', autolinkCountArray);
		    $('body').autolink('independent living', '/questions', autolinkCountArray);
		    $('body').autolink('extra care', '/questions', autolinkCountArray);
		    $('body').autolink('hotel services', '/questions, autolinkCountArray');
		    $('body').autolink('care home', '/questions', autolinkCountArray);
		    $('body').autolink('care packages', '/questions', autolinkCountArray);
		}
		$('#browse-link').qtip({
		   content: {
		      text: $('#browse-submenu').html()
		   },
		   position: {
		      my: 'top center',
		      at: 'bottom center'
		   },
		   hide: {
		      fixed: true,
		      delay: 500
		   },
		   style: {
		      classes: 'ui-tooltip-dark ui-tooltip-shadow ui-tooltip-rounded',
		      tip: {
		         width: 16,
		         height: 10
		      }
		   }
		})
	}
	catch(e) {}
});
