/*
CSS Browser Selector v0.3.5 (Feb 05, 2010)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }
function goToByScroll(id) {
    $('html,body').animate({ scrollTop: $("#" + id).offset().top }, 'slow');
}
function isValidEmail(email) {
    var regex = /([\w\d\-_]+)(\.[\w\d\-_]+)*@([\w\d\-_]+\.)([\w\d\-_]+\.)*([\w]{2,3})/;
    if (regex.test(email))
        return true;
    else
        return false;
}
function isInt(input) {
    return !isNaN(parseInt(input));
}
function positionGlobalWait() {
    var sH = $(window).height();
    var sW = $(window).width();

    $('div.global-wait').css('left', (sW / 2) - ($('div.global-wait').width() / 2) + 'px');
    $('div.global-wait').css('top', (sH / 2) - ($('div.global-wait').height() / 2) + 'px');
}
function positionLightbox() {
    if ($('div.pop-shell').length > 0) {
        $('div.pop-shell').css('left', (sW / 2) - ($('div.pop-shell').width() / 2) + 'px');
    }
}
$(window).resize(function() {
    positionGlobalWait();
});
$(document).ready(function() {
    $('.columnLeft2 p img.img-right, .columnLeft2 p img.img-left').unwrap();
    positionGlobalWait();
    $('.tooltip').tipsy({ gravity: 's' });

    // send form spans on click checks blank span and displays label
    $('.footerTop fieldset label span, .lv2 fieldset label span, .inPageEmail fieldset label span, .searchBarFly fieldset label span, .formEnquire fieldset label span, .formEnquire fieldset label.textA span, .formToFriend fieldset label span, .formToFriend fieldset label.textA span, .pop-inner-std fieldset label.tFieldShort span, .pop-inner-std fieldset label.tFieldWide span, .pop-inner-std fieldset label.tAreaWide span, .pop-inner-std fieldset label.tAreaShort span, .bg-formToFriend label span, .bg-formToFriend label.textA span,').click(function() {
        if ($(this).parent().parent().find('label input').attr('value') == "") {
            $(this).parent().find('span').fadeIn('fast');
        }
        $(this).fadeOut('fast', function() {
            $(this).parent().find('input,textarea').focus();
        });
    });
    $('.footerTop fieldset label input, .lv2 fieldset label input, .inPageEmail fieldset label input, .searchBarFly fieldset label input, .formEnquire fieldset label input, .formEnquire fieldset label.textA textarea, .formToFriend fieldset label input, .formToFriend fieldset label.textA textarea, .pop-inner-std fieldset label input, .pop-inner-std fieldset label textarea, .bg-formToFriend label input, .bg-formToFriend label.textA textarea').focusin(function() {
        $(this).parent().find('span').fadeOut('fast');
    });
    $('.footerTop fieldset label input, .lv2 fieldset label input, .inPageEmail fieldset label input, .searchBarFly fieldset label input, .formEnquire fieldset label input, .formEnquire fieldset label.textA textarea, .formToFriend fieldset label input, .formToFriend fieldset label.textA textarea, .pop-inner-std fieldset label input, .pop-inner-std fieldset label textarea, .bg-formToFriend label input, .bg-formToFriend label.textA textarea').focusout(function() {
        if ($(this).attr('value') == "") {
            $(this).parent().find('span').fadeIn('fast');
        }
    });

    // email alert
    $('#emailAlert').mouseover(function() {
        $(this).parent().css('background', '#FFF');
        $('.notifyMsg').fadeIn();
    });
    $('#emailAlert').mouseout(function() {
        $(this).parent().css('background', 'none');
        if ($(this).text() != 'Cancel') {
            $('.notifyMsg').fadeOut();
        }
    });
    // open and close map on the index page
    $('#aSearchSubscription').toggle(function() {
        $(this).html('<span class="notifyMsg">Receive Property Spotter Emails - notify me when properties are listed that meet the current search criteria</span><span class="linkEmailAlert rounded8">Cancel</span>');
        // $(this).html('<span class="linkEmailAlert rounded8">Cancel</span>');
        $('#divSearchSubscribe').slideDown();
    }, function() {
        $(this).html('<span class="notifyMsg">Receive Property Spotter Emails - notify me when properties are listed that meet the current search criteria</span><span class="linkEmailAlert rounded8">Email Alerts</span>');
        // $(this).html('<span class="linkEmailAlert rounded8">Email Alerts</span>');
        $('#divSearchSubscribe').slideUp();
    });
    $('#divSearchSubscribe a.buttonAlertMe').click(function() {
        $('div#divSearchSubscribe .errormsg').html('');
        $('div#divSearchSubscribe .errormsg').hide();
        if ($('div#divSearchSubscribe #tbSUName').val().trim() == '' ||
            $('div#divSearchSubscribe #tbSUName').val() == 'Name') {
            $('div#divSearchSubscribe .errormsg').append('Please enter your name<br />');
        }
        if ($('div#divSearchSubscribe #tbSUEmail').val().trim() == '' ||
            $('div#divSearchSubscribe #tbSUEmail').val() == 'Email') {
            $('div#divSearchSubscribe .errormsg').append('Please enter your email<br />');
        }
        else if (!isValidEmail($('div#divSearchSubscribe #tbSUEmail').val())) {
            $('div#divSearchSubscribe .errormsg').append('Please enter a valid email<br />');
        }
        if ($('div#divSearchSubscribe .errormsg').html() != '') {
            //error
            $('div#divSearchSubscribe .errormsg').show();
        }
        else {
            //send
            $('div#divSearchSubscribe .waitmsg').show();
            $.post("/handlers/SearchHandler.ashx", { op: 'subscribe', name: $('#divSearchSubscribe input#tbSUName').val(), email: $('#divSearchSubscribe input#tbSUEmail').val() }, function(data) {
                $('div#divSearchSubscribe .waitmsg').hide();
                if (data.indexOf('Error:') != -1) {
                    $('div#divSearchSubscribe .errormsg').show();
                    $('div#divSearchSubscribe .errormsg').html(data.substring(6, data.length));
                }
                else if (data.indexOf('Success:') != -1) {
                    $('div#divSearchSubscribe .successmsg').show();
                    $('div#divSearchSubscribe .successmsg').html(data.substring(8, data.length));
                }
            });
        }
        return false;
    });

    // index
    $('.checkCustom').click(function() {
        $(this).toggleClass('active');
        return false;
    });

    var switchMe = "all";
    // openLogin
    $('#openLogin').click(function() {
        switchMe = "login";
        resetSlide();
        return false;
    });
    function openLogin() {
        $('.barShell').slideDown();
        $('#openLogin').addClass('active');
        $('#loginBar').fadeIn();
    }
    // openSearch
    $('#openSearch').click(function() {
        switchMe = "search";
        resetSlide();
        return false;
    });
    function openSearch() {
        $('.barShell').slideDown();
        $('#openSearch').addClass('active');
        $('#searchBar').fadeIn();
    }

    function resetSlide() {
        if (switchMe == "all") {
            $('.barShell').hide();
            $('#searchBar').hide();
            $('#loginBar').hide();
        }
        if (switchMe == "login") {
            $('#searchBar').fadeOut(function() {
                openLogin();
            });
        }

        if (switchMe == "search") {
            $('#loginBar').fadeOut(function() {
                openSearch();
            });
        }
        $('#openLogin').removeClass('active');
        $('#openSearch').removeClass('active');
    }



    // faqs
    $('.linkQuestion').click(function() {
        if (!$(this).parent().parent().hasClass('questionActive')) {
            resetFAQ();
            $(this).parent().parent().removeClass('question').addClass('questionActive');
            $(this).parent().parent().find('.faqBottom').show();
            $(this).parent().parent().find('div.answer').slideDown('fast', function() {
                $('.bgContentBottom').css('bottom', '0'); // hideous fix for IE 6 & 7																					
            });
            $(this).parent().parent().find('.close').fadeIn();
        } else {
            resetFAQ();
        }
        return false;
    });

    $('.close').click(function() {
        resetFAQ();
        return false;
    });
    function resetFAQ() {
        $('div.questionActive').removeClass('questionActive').addClass('question');
        $('.answer').slideUp();
        $('.faqBottom').hide();
        $('.close').fadeOut();
    }


    // popup Enquire form
    $('#openEnquireForm').click(function() {
        $('#formEnquire').fadeIn();
        return false;
    });
    $('#cancelEnquireForm').click(function() {
        $('#formEnquire').fadeOut();
        return false;
    });

    // popup send to a friend form
    $('#openToFriendForm').click(function() {
        $('#formToFriend').fadeIn();
        return false;
    });
    $('#cancelToFriendForm').click(function() {
        $('#formToFriend').fadeOut();
        return false;
    });


    //lightbox
    $('#openDetail').click(function() {
        _buildLightbox();
        return false;
    });
    $('#lightboxOverlay').click(function() {
        _destroyLightbox();
        return false;
    });
    $('#lightboxClose').click(function() {
        $('.flashGallery').html('');
        _destroyLightbox();
        return false;
    });

    // close top
    resetSlide();

    //-----------------------------------------------------
    //-------------------- search menu --------------------
    //-----------------------------------------------------
    $('div.dropPanelOuter a.button').click(function() {
        if (!$(this).hasClass('active')) {
            //activate
            $(this).addClass('active');
            if ($(this).next('div.dropPanel').length > 0)
                $(this).next('div.dropPanel').css('display', 'inline-block');
            else
                $(this).next().find('div.dropPanel').css('display', 'inline-block');
        }
        else {
            //deactivate
            $(this).removeClass('active');
            if ($(this).next('div.dropPanel').length > 0)
                $(this).next('div.dropPanel').css('display', 'none');
            else
                $(this).next().find('div.dropPanel').css('display', 'none');
        }
    });
    var isClosing = false;
    $('div.dropPanelOuter a.button').mouseout(function() {
        isClosing = true;
        setTimeout(function() { closeDDLPopups(); }, 100);
    });

    $('div.dropPanel').bind('mouseover', searchBarDropPanelMouseOver);
    $('div.dropPanel').bind('mouseout', searchBarDropPanelMouseOut);
    function searchBarDropPanelMouseOver() {
        isClosing = false;
    }
    function searchBarDropPanelMouseOut() {
        isClosing = true;
        setTimeout(function() { closeDDLPopups(); }, 100);
    }
    function closeDDLPopups() {
        if (isClosing) {
            $('div.dropPanelOuter a.button').removeClass('active');
            $('div.dropPanelOuter div.dropPanel').css('display', 'none');
        }
    }
    $('div.dropPanelMulti a').bind('click', searchBarMultiPanelLinkClick);
    function searchBarMultiPanelLinkClick() {
        if (!$(this).hasClass('active')) {
            $(this).addClass('active');
        }
        else {
            $(this).removeClass('active');
        }

        if (getGrandChildIndex($(this).parents('div.dropPanelMulti').eq(0), $(this)) == 0) {
            $(this).parents('.panel').eq(0).find('a').removeClass('active');
            $(this).addClass('active');
        }
        else {
            if ($(this).parents('div.dropPanelMulti').eq(0).find('div.suburbColumn').length > 0) {
                $(this).parents('div.dropPanelMulti').eq(0).find('div.suburbColumn').eq(0).find('a').eq(0).removeClass('active');
                if ($(this).parents('div.dropPanelMulti').eq(0).find('div.suburbColumn').find('a.active').length == 0)
                    $(this).parents('div.dropPanelMulti').eq(0).find('div.suburbColumn').eq(0).find('a').eq(0).addClass('active');
            }
            else {
                $(this).parents('div.dropPanelMulti').eq(0).find('a').eq(0).removeClass('active');
                if ($(this).parent().find('a.active').length == 0)
                    $(this).parent().find('a').eq(0).addClass('active');
            }
        }
        var el = $(this).parents('div.dropPanelOuter').eq(0).find('a.button span');
        el.html('');
        var str = ''
        $(this).parent().parent().find('a.active').each(function() {
            str += $(this).find('span').html() + ', ';
        });
        if (str.length > 2)
            str = str.substring(0, str.length - 2);
        if (str.length > 15)
            str = str.substring(0, 15) + "..";
        el.html(str);
    }
    function getGrandChildIndex(elParent, elChild) {
        var index = 0;
        elParent.find('a').each(function() {
            if ($(this).attr('class') == elChild.attr('class')) {
                return false;
            }
            index++;
        });
        return index;
    }
    $('div.dropPanelSingle a').click(function() {
        if (!$(this).hasClass('active')) {
            $(this).addClass('active');
        }
        else {
            $(this).removeClass('active');
        }

        $(this).parent().find('a').removeClass('active');
        $(this).addClass('active');
        var el = $(this).parents('div.dropPanelOuter').eq(0).find('a.button span');
        el.html($(this).find('span').html());
    });
    $('div.dropPanelTwin a').click(function() {
        if (!$(this).hasClass('active')) {
            $(this).addClass('active');
        }
        else {
            $(this).removeClass('active');
        }

        $(this).parent().find('a').removeClass('active');
        $(this).addClass('active');

        var el = $(this).parents('div.dropPanelOuter').eq(0).find('a.button span');
        var start = '';
        if ($(this).parents('span.panel').eq(0).find('div.priceColumn').eq(0).find('a.active span').length > 0)
            start = $(this).parents('span.panel').eq(0).find('div.priceColumn').eq(0).find('a.active span').html();
        var end = '';
        if ($(this).parents('span.panel').eq(0).find('div.priceColumn').eq(1).find('a.active span').length > 0)
            end = $(this).parents('span.panel').eq(0).find('div.priceColumn').eq(1).find('a.active span').html();
        el.html(start + '-' + end);
    });
    $('div#divDDLRegions div.dropPanel a').click(function() {
        searchBarOnSelect($(this), $('input#hdnSearchRegion'));
        var str = '';
        var val;
        $(this).parent().parent().find('a.active').each(function() {
            if ($(this).attr('class').trim() != 'active')
                val = $(this).attr('class').replace(' active', '') + '|';
            else
                val = $(this).parents('div.dropPanelOuter').eq(0).find('a.button span').html() + '|';
            if (str.indexOf(val) < 0)
                str += val;
        });
        $('input#hdnSearchRegion').val(str);
        $('div.global-wait').show();
        $.post("/handlers/SearchHandler.ashx", { op: 'listsuburbs', regions: str }, function(data) {
            $('div.global-wait').hide();

            if (data.indexOf('Error:') != -1) {
                //$('div.keepUpToDate>span.error').fadeIn(500);
                //$('div.keepUpToDate>span.error').html('Unfortunately an error has occured saving your details, please try again or contact us');
            }
            else if (data.indexOf('Success:') != -1) {
                $('div#divSuburbPlaceholder').html(data.replace('Success:', ''));
                $('div.dropPanel').bind('mouseover', searchBarDropPanelMouseOver);
                $('div.dropPanel').bind('mouseout', searchBarDropPanelMouseOut);
                $('div#divSuburbPlaceholder div.dropPanelMulti a').bind('click', searchBarMultiPanelLinkClick)
                $('div#divDDLSuburbs div.dropPanel a').click(function() {
                    searchBarOnSelect($(this), $('input#hdnSearchSuburb'));
                });
            }
        });
    });
    function searchBarOnSelect(objLink, objHF) {
        var str = '';
        var val;
        objLink.parent().parent().find('a.active').each(function() {
            if (objLink.attr('class').trim() != 'active')
                val = $(this).attr('class').replace(' active', '') + '|';
            else
                val = $(this).parents('div.dropPanelOuter').eq(0).find('a.button span').html() + '|';
            if (str.indexOf(val) < 0)
                str += val;
        });
        objHF.val(str);

        //update map
        var action = '';
        if ($('#aCategoryRent').hasClass('active'))
            action = 'r';
        else
            action = 's';
        var furnished = '';
        if ($('#aSearchFurnished').hasClass('active'))
            furnished = 'true';
        else
            furnished = 'false';
        var executive = '';
        if ($('#aSearchExecutive').hasClass('active'))
            executive = 'true';
        else
            executive = 'false';
        var worldCup = '';
        if ($('#aWorldCup').hasClass('active'))
            worldCup = 'true';
        else
            worldCup = 'false';
        var servicedApartments = '';
        if ($('#aServicedApartments').hasClass('active'))
            servicedApartments = 'true';
        else
            servicedApartments = 'false';

        $('div.global-wait').show();
        $.post("/handlers/SearchHandler.ashx", { op: 'searchformap', action: action, region: $('#hdnSearchRegion').val(), suburb: $('#hdnSearchSuburb').val(), propertytype: $('#hdnSearchPropertyType').val(), price: $('#hdnSearchPrice').val(), bdrm: $('#hdnSearchBdrm').val(), bath: $('#hdnSearchBath').val(), keyword: $('#tbSearchKeywords').val(), furnished: furnished, executive: executive, worldCup: worldCup, servicedApartments: servicedApartments }, function(data) {
            $('div.global-wait').hide();

            if (data.indexOf('Error:') != -1) {
                //$('div.keepUpToDate>span.error').fadeIn(500);
                //$('div.keepUpToDate>span.error').html('Unfortunately an error has occured saving your details, please try again or contact us');
            }
            else if (data.indexOf('Success:') != -1) {
                $('#googleSearchMapCoords').html(data.substring(8, data.length));
                if ($('#divGoogleMap').is(':visible')) {
                    initMap();
                }
            }
        });
    }
    $('div#divDDLSuburbs div.dropPanel a').click(function() {
        searchBarOnSelect($(this), $('input#hdnSearchSuburb'));
    });
    $('div#divDDLTypes div.dropPanel a').click(function() {
        searchBarOnSelect($(this), $('input#hdnSearchPropertyType'));
    });
    $('div#divDDLTypes div.dropPanel a').click(function() {
        searchBarOnSelect($(this), $('input#hdnSearchPropertyType'));
    });
    $('div#divDDLPrices div.dropPanel a').click(function() {
        searchBarOnSelect($(this), $('input#hdnSearchPrice'));
    });
    $('div#divDDLBedrooms div.dropPanel a').click(function() {
        searchBarOnSelect($(this), $('input#hdnSearchBdrm'));
    });
    $('div#divDDLBathrooms div.dropPanel a').click(function() {
        searchBarOnSelect($(this), $('input#hdnSearchBath'));
    });
    // main category buttons
    $('#aCategoryRent').click(function() {
        $(this).addClass('active');
        $('#aCategorySale').removeClass('active');

        $('#spanPanelRent').show();
        $('#spanPanelSale').hide();
        searchBarResetPrice();
    });
    $('#aCategorySale').click(function() {
        $(this).addClass('active');
        $('#aCategoryRent').removeClass('active');

        $('#spanPanelRent').hide();
        $('#spanPanelSale').show();
        searchBarResetPrice();
    });
    function searchBarResetPrice() {
        $('#divDDLPrices a.button span').html('Price');
        $('#spanPanelSale a, #spanPanelRent a').removeClass('active');
        $('#hdnSearchPrice').val('');
    }
    //search
    $('#tbSearchKeywords').keyup(function(event) {
        if (event.keyCode == '13') {
            $('#aSearchProperties').trigger('click');
        }
    });
    $('#aSearchProperties').click(function() {
        var action = '';
        if ($('#aCategoryRent').hasClass('active'))
            action = 'r';
        else
            action = 's';
        var furnished = '';
        if ($('#aSearchFurnished').hasClass('active'))
            furnished = 'true';
        else
            furnished = 'false';
        var executive = '';
        if ($('#aSearchExecutive').hasClass('active'))
            executive = 'true';
        else
            executive = 'false';
        var worldCup = '';
        if ($('#aWorldCup').hasClass('active'))
            worldCup = 'true';
        else
            worldCup = 'false';
        var servicedApartments = '';
        if ($('#aServicedApartments').hasClass('active'))
            servicedApartments = 'true';
        else
            servicedApartments = 'false';

        var cookieval = 'action:' + action;
        cookieval += ',region:' + $('#hdnSearchRegion').val();
        cookieval += ',suburb:' + $('#hdnSearchSuburb').val();
        cookieval += ',propertytype:' + $('#hdnSearchPropertyType').val();
        cookieval += ',price:' + $('#hdnSearchPrice').val();
        cookieval += ',bdrm:' + $('#hdnSearchBdrm').val();
        cookieval += ',bath:' + $('#hdnSearchBath').val();
        cookieval += ',keyword:' + $('#tbSearchKeywords').val();
        cookieval += ',furnished:' + furnished;
        cookieval += ',executive:' + executive;
        cookieval += ',worldCup:' + worldCup;
        cookieval += ',servicedApartments:' + servicedApartments;

        var options = { path: '/', expires: 10 };
        $.cookie('searchparams', cookieval, options);

        window.location = '/properties.aspx';
    });

    //ask crockers
    $('#aFooterAskCrockers').click(function() {
        askCrockersPre();
        return false;
    });
    function askCrockersPre() {
        $('div.global-wait').show();
        $.post("/handlers/Forms/AskCrockersHandler.ashx", { op: 'getform' }, function(data) {
            $('div.global-wait').hide();
            $('.pop-shell-std').remove();
            $('#lightboxOverlay').after(data);
            _buildLightboxWithParams($('.pop-shell-std'));

            $('#fsAskCrockers label span').click(function() {
                if ($(this).parent().parent().find('label input[type=text]').attr('value') == "") {
                    $(this).parent().find('span').fadeIn('fast');
                }
                if ($(this).parent().find('input[type=text],textarea').length > 0)
                    $(this).fadeOut('fast', function() {
                        $(this).parent().find('input,textarea').focus();
                    });
            });
            $('#fsAskCrockers label input[type=text], #fsAskCrockers label textarea').focusin(function() {
                $(this).parent().find('span').fadeOut('fast');
            });
            $('#fsAskCrockers label input[type=text], #fsAskCrockers label textarea').focusout(function() {
                if ($(this).attr('value') == "") {
                    $(this).parent().find('span').fadeIn('fast');
                }
            });
            $('div.pop-shell-std a.bPop-close').click(function() {
                _destroyLightbox();
            });
            $('#fsAskCrockers a.buttonAsk').click(function() {
                askCrockers();
            });
        });
    }
    function askCrockers() {
        $('#fsAskCrockers .errormsg').html('');
        $('#fsAskCrockers .errormsg').hide();
        var errorMsg = '';
        if ($('#fsAskCrockers #tbQuestion').val().trim() == '') {
            errorMsg += 'Please enter your question<br />';
        }
        if ($('#fsAskCrockers #tbName').val().trim() == '') {
            errorMsg += 'Please enter your name<br />';
        }
        if ($('#fsAskCrockers #tbEmail').val().trim() == '') {
            errorMsg += 'Please enter your email address<br />';
        }
        else if (!isValidEmail($('#fsAskCrockers #tbEmail').val())) {
            errorMsg += 'Please enter a valid email address<br />';
        }
        if ($('#fsAskCrockers #tbMobile').val().trim() == '') {
            errorMsg += 'Please enter your mobile phone number<br />';
        }
        if (errorMsg != '') {
            $('#fsAskCrockers .errormsg').html(errorMsg);
            $('#fsAskCrockers .errormsg').show();
        }
        else {
            $('div.global-wait').show();
            $.post("/handlers/Forms/AskCrockersHandler.ashx", { op: 'submit', cbSell: $('#fsAskCrockers #cbSelling').is(':checked'), cbBodyCorp: $('#fsAskCrockers #cbBodyCorp').is(':checked'), cbPropMan: $('#fsAskCrockers #cbPropMan').is(':checked'), cbBuying: $('#fsAskCrockers #cbBuying').is(':checked'), cbRenting: $('#fsAskCrockers #cbRenting').is(':checked'), tbQuestion: $('#fsAskCrockers #tbQuestion').val(), tbName: $('#fsAskCrockers #tbName').val(), tbEmail: $('#fsAskCrockers #tbEmail').val(), tbMobile: $('#fsAskCrockers #tbMobile').val() }, function(data) {
                $('div.global-wait').hide();
                if (data.indexOf('Error:') == 0) {
                    $('#fsAskCrockers .errormsg').html(data.substring(6, data.length));
                    $('#fsAskCrockers .errormsg').show();
                }
                else {
                    $('#fsAskCrockers').html('<p style="height:172px;">' + data.replace('Success:', '') + '</p>');
                }
            });
        }
    }
    $('a.actionAdv').click(function() {
        if ($(this).attr('href') == '#adv_RequestProposal') {
            requestProposalPre();
        }
        else if ($(this).attr('href') == '#adv_RequestInfoPack') {
            requestInfoPackPre();
        }
        else if ($(this).attr('href') == '#adv_RequestAppraisal') {
            requestAppraisalPre();
        }
        else if ($(this).attr('href') == '#adv_AskCrockers') {
            askCrockersPre();
        }
        return false;
    });
    function requestProposalPre() {
        $('div.global-wait').show();
        $.post("/handlers/Forms/RequestProposalHandler.ashx", { op: 'getform' }, function(data) {
            $('div.global-wait').hide();
            $('.pop-shell-std').remove();
            $('#lightboxOverlay').after(data);
            _buildLightboxWithParams($('.pop-shell-std'));

            $('#fsRequestProposal label span').click(function() {
                if ($(this).parent().parent().find('label input[type=text]').attr('value') == "") {
                    $(this).parent().find('span').fadeIn('fast');
                }
                if ($(this).parent().find('input[type=text],textarea').length > 0)
                    $(this).fadeOut('fast', function() {
                        $(this).parent().find('input,textarea').focus();
                    });
            });
            $('#fsRequestProposal label input[type=text], #fsRequestProposal label textarea').focusin(function() {
                $(this).parent().find('span').fadeOut('fast');
            });
            $('#fsRequestProposal label input[type=text], #fsRequestProposal label textarea').focusout(function() {
                if ($(this).attr('value') == "") {
                    $(this).parent().find('span').fadeIn('fast');
                }
            });
            $('div.pop-shell-std a.bPop-close').click(function() {
                _destroyLightbox();
            });
            $('#fsRequestProposal a.button-request').click(function() {
                requestProposal();
            });
        });
    }
    function requestProposal() {
        $('#fsRequestProposal .errormsg').html('');
        $('#fsRequestProposal .errormsg').hide();
        var errorMsg = '';
        if ($('#fsRequestProposal #tbName').val().trim() == '') {
            errorMsg += 'Please enter your name<br />';
        }
        if ($('#fsRequestProposal #tbEmail').val().trim() == '') {
            errorMsg += 'Please enter your email address<br />';
        }
        else if (!isValidEmail($('#fsRequestProposal #tbEmail').val())) {
            errorMsg += 'Please enter a valid email address<br />';
        }
        if ($('#fsRequestProposal #tbPhone').val().trim() == '') {
            errorMsg += 'Please enter your phone number<br />';
        }
        if ($('#fsRequestProposal #tbAddress').val().trim() == '') {
            errorMsg += 'Please enter your address<br />';
        }
        if ($('#fsRequestProposal #tbSuburb').val().trim() == '') {
            errorMsg += 'Please enter your suburb<br />';
        }
        if ($('#fsRequestProposal #tbCity').val().trim() == '') {
            errorMsg += 'Please enter your city<br />';
        }
        if (errorMsg != '') {
            $('#fsRequestProposal .errormsg').html(errorMsg);
            $('#fsRequestProposal .errormsg').show();
        }
        else {
            $('div.global-wait').show();
            $.post("/handlers/Forms/RequestProposalHandler.ashx", { op: 'submit', tbName: $('#fsRequestProposal #tbName').val(), tbEmail: $('#fsRequestProposal #tbEmail').val(), tbPhone: $('#fsRequestProposal #tbPhone').val(), tbAddress: $('#fsRequestProposal #tbAddress').val(), tbSuburb: $('#fsRequestProposal #tbSuburb').val(), tbCity: $('#fsRequestProposal #tbCity').val(), tbComments: $('#fsRequestProposal #tbComments').val() }, function(data) {
                $('div.global-wait').hide();
                if (data.indexOf('Error:') == 0) {
                    $('#fsRequestProposal .errormsg').html(data.substring(6, data.length));
                    $('#fsRequestProposal .errormsg').show();
                }
                else {
                    $('#fsRequestProposal').html('<p style="height:172px;">' + data.replace('Success:', '') + '</p>');
                }
            });
        }
    }
    function requestInfoPackPre() {
        $('div.global-wait').show();
        $.post("/handlers/Forms/RequestInfoPackHandler.ashx", { op: 'getform' }, function(data) {
            $('div.global-wait').hide();
            $('.pop-shell-std').remove();
            $('#lightboxOverlay').after(data);
            _buildLightboxWithParams($('.pop-shell-std'));

            $('#fsRequestInfoPack label span').click(function() {
                if ($(this).parent().parent().find('label input[type=text]').attr('value') == "") {
                    $(this).parent().find('span').fadeIn('fast');
                }
                if ($(this).parent().find('input[type=text],textarea').length > 0)
                    $(this).fadeOut('fast', function() {
                        $(this).parent().find('input,textarea').focus();
                    });
            });
            $('#fsRequestInfoPack label input[type=text], #fsRequestInfoPack label textarea').focusin(function() {
                $(this).parent().find('span').fadeOut('fast');
            });
            $('#fsRequestInfoPack label input[type=text], #fsRequestInfoPack label textarea').focusout(function() {
                if ($(this).attr('value') == "") {
                    $(this).parent().find('span').fadeIn('fast');
                }
            });
            $('div.pop-shell-std a.bPop-close').click(function() {
                _destroyLightbox();
            });
            $('#fsRequestInfoPack a.button-request').click(function() {
                requestInfoPack();
            });
        });
    }
    function requestInfoPack() {
        $('#fsRequestInfoPack .errormsg').html('');
        $('#fsRequestInfoPack .errormsg').hide();
        var errorMsg = '';
        if ($('#fsRequestInfoPack #tbName').val().trim() == '') {
            errorMsg += 'Please enter your name<br />';
        }
        if ($('#fsRequestInfoPack #tbEmail').val().trim() == '') {
            errorMsg += 'Please enter your email address<br />';
        }
        else if (!isValidEmail($('#fsRequestInfoPack #tbEmail').val())) {
            errorMsg += 'Please enter a valid email address<br />';
        }
        if ($('#fsRequestInfoPack #tbPhone').val().trim() == '') {
            errorMsg += 'Please enter your phone number<br />';
        }
        if ($('#fsRequestInfoPack #tbAddress').val().trim() == '') {
            errorMsg += 'Please enter your address<br />';
        }
        if ($('#fsRequestInfoPack #tbSuburb').val().trim() == '') {
            errorMsg += 'Please enter your suburb<br />';
        }
        if ($('#fsRequestInfoPack #tbCity').val().trim() == '') {
            errorMsg += 'Please enter your city<br />';
        }
        if (errorMsg != '') {
            $('#fsRequestInfoPack .errormsg').html(errorMsg);
            $('#fsRequestInfoPack .errormsg').show();
        }
        else {
            $('div.global-wait').show();
            $.post("/handlers/Forms/RequestInfoPackHandler.ashx", { op: 'submit', tbName: $('#fsRequestInfoPack #tbName').val(), tbEmail: $('#fsRequestInfoPack #tbEmail').val(), tbPhone: $('#fsRequestInfoPack #tbPhone').val(), tbAddress: $('#fsRequestInfoPack #tbAddress').val(), tbSuburb: $('#fsRequestInfoPack #tbSuburb').val(), tbCity: $('#fsRequestInfoPack #tbCity').val(), tbComments: $('#fsRequestInfoPack #tbComments').val() }, function(data) {
                $('div.global-wait').hide();
                if (data.indexOf('Error:') == 0) {
                    $('#fsRequestInfoPack .errormsg').html(data.substring(6, data.length));
                    $('#fsRequestInfoPack .errormsg').show();
                }
                else {
                    $('#fsRequestInfoPack').html('<p style="height:172px;">' + data.replace('Success:', '') + '</p>');
                }
            });
        }
    }
    function requestAppraisalPre() {
        $('div.global-wait').show();
        $.post("/handlers/Forms/RequestAppraisalHandler.ashx", { op: 'getform' }, function(data) {
            $('div.global-wait').hide();
            $('.pop-shell-std').remove();
            $('#lightboxOverlay').after(data);
            _buildLightboxWithParams($('.pop-shell-std'));

            $('#fsRequestAppraisal label span').click(function() {
                if ($(this).parent().parent().find('label input[type=text]').attr('value') == "") {
                    $(this).parent().find('span').fadeIn('fast');
                }
                if ($(this).parent().find('input[type=text],textarea').length > 0)
                    $(this).fadeOut('fast', function() {
                        $(this).parent().find('input,textarea').focus();
                    });
            });
            $('#fsRequestAppraisal label input[type=text], #fsRequestAppraisal label textarea').focusin(function() {
                $(this).parent().find('span').fadeOut('fast');
            });
            $('#fsRequestAppraisal label input[type=text], #fsRequestAppraisal label textarea').focusout(function() {
                if ($(this).attr('value') == "") {
                    $(this).parent().find('span').fadeIn('fast');
                }
            });
            $('div.pop-shell-std a.bPop-close').click(function() {
                _destroyLightbox();
            });
            $('#fsRequestAppraisal a.button-request').click(function() {
                requestAppraisal();
            });
        });
    }
    function requestAppraisal() {
        $('#fsRequestAppraisal .errormsg').html('');
        $('#fsRequestAppraisal .errormsg').hide();
        var errorMsg = '';
        if ($('#fsRequestAppraisal #tbEmail').val().trim() == '') {
            errorMsg += 'Please enter your email address<br />';
        }
        else if (!isValidEmail($('#fsRequestAppraisal #tbEmail').val())) {
            errorMsg += 'Please enter a valid email address<br />';
        }
        if (errorMsg != '') {
            $('#fsRequestAppraisal .errormsg').html(errorMsg);
            $('#fsRequestAppraisal .errormsg').show();
        }
        else {
            $('div.global-wait').show();
            $.post("/handlers/Forms/RequestAppraisalHandler.ashx", { op: 'submit', tbAddress: $('#fsRequestAppraisal #tbAddress').val(), tbSuburb: $('#fsRequestAppraisal #tbSuburb').val(), tbCity: $('#fsRequestAppraisal #tbCity').val(), ddlPropertyType: $('#fsRequestAppraisal #ddlPropertyType').val(), ddlNumBedrooms: $('#fsRequestAppraisal #ddlNumBedrooms').val(), ddlNumBathrooms: $('#fsRequestAppraisal #ddlNumBathrooms').val(), ddlNumParking: $('#fsRequestAppraisal #ddlNumParking').val(), tbComments: $('#fsRequestAppraisal #tbComments').val(), tbName: $('#fsRequestAppraisal #tbName').val(), tbEmail: $('#fsRequestAppraisal #tbEmail').val(), tbPhone: $('#fsRequestAppraisal #tbPhone').val() }, function(data) {
                $('div.global-wait').hide();
                if (data.indexOf('Error:') == 0) {
                    $('#fsRequestAppraisal .errormsg').html(data.substring(6, data.length));
                    $('#fsRequestAppraisal .errormsg').show();
                }
                else {
                    $('#fsRequestAppraisal').html('<p style="height:172px;">' + data.replace('Success:', '') + '</p>');
                }
            });
        }
    }
});	
$(window).resize(function(){
	var winW = $('body').width();
	$('.footerShell').css('display','none');
	$('.footerShell').css('display','block');
});
function _buildLightbox() {
    var sH = $(window).height();
    var sW = $(window).width();
    $("#lightboxOverlay").css('height', sH + 'px').css('display', 'block');
    //$('#lightboxOverlay').bgiframe(); // js to fix select boxes in IE 6
    $('.pop-shell').css('left', (sW / 2) - ($('.pop-shell').width() / 2) + 'px');
    //$('.pop-shell').css('top', (sH / 2) - ($('.pop-shell').height() / 2) + 'px');

    $('html,body').animate({ scrollTop: 0 }, 'slow');
    
    $('.pop-shell').fadeIn();
};
function _buildLightboxWithParams(obj) {
    var sH = $(window).height();
    var sW = $(window).width();
    $("#lightboxOverlay").css('height', sH + 'px').css('display', 'block');
    //$('#lightboxOverlay').bgiframe(); // js to fix select boxes in IE 6
    obj.css('left', (sW / 2) - (obj.width() / 2) + 'px');
    obj.css('top', '20px');
    //$('.pop-shell').css('top', (sH / 2) - ($('.pop-shell').height() / 2) + 'px');

    $('html,body').animate({ scrollTop: 0 }, 'slow');

    obj.fadeIn();
}
function _destroyLightbox() {
    $('#lightboxOverlay').fadeOut();
    $('.pop-shell').fadeOut();
    $('.pop-shell-std').fadeOut();
};
jQuery.extend(jQuery, {
    imagesToLoad: 0,
    loadedImages: [],
    preloadImages: function() {
        var settings = {
            urls: [],
            begin: function() { },
            each: function() { },
            complete: function() { },
            scope: window
        };
        jQuery.extend(settings, arguments[0]);
        var images = [];

        jQuery.imagesToLoad = settings.urls.length;

        settings.begin.call(settings.scope, settings.urls);
        for (var i = 0; i < settings.urls.length; i++) {
            images[i] = new Image();
            images[i].onload = function() {
                settings.each.call(settings.scope, this);
                jQuery.loadedImages.push(this);
                if (jQuery.loadedImages.length >= jQuery.imagesToLoad) {
                    settings.complete.call(settings.scope, jQuery.loadedImages);
                }
            }
            images[i].src = settings.urls[i];
        }
    }
});

