$(document).ready(function(){ var searchTypeInitialized; var prevCheckBox; //console.log('Cookie Support: ' + getCookieSupport()); if (getCookieSupport() || !getCookieSupport() === null){ $("#searchButtons").css('visibility','visible'); } //console.log("Grabbed Cookie support") $("#residentialSearchBox").bind( "click", function() { if (!$(this).prop("checked")){ //console.log('dechecking resi sale'); checkResiButton(); } else { checkResiButton(); } }); $("#commercialSearchBoxForLease").bind( "click", function() { if (!$(this).prop("checked")){ //console.log('dechecking lease'); checkResiButton(); } else { checkLeaseButton(); } }); $("#commercialSearchBoxForSale").bind( "click", function() { if (!$(this).prop("checked")){ //console.log('dechecking sale'); checkResiButton(); } else { checkSaleButton(); } }); //console.log('Starting quickNav checks'); if (typeof quickNav !== 'undefined') { if (quickNav.lt === "c") { if (quickNav.lst === "s"){ checkSaleButton(); //console.log("Quick Nav Sale"); } if (quickNav.lst === "l"){ checkLeaseButton(); //console.log("Quick Nav Lease"); } } if (quickNav.lt === "r") { if (quickNav.lst === "na"){ checkResiButton(); //console.log("Quick Nav Resi"); } } } else { //console.log('quickNav undefined'); if ($.cookie()) { if ($.cookie('cs') === 'sale') { checkSaleButton(); //console.log('cookie commercial for sale'); return; } if ($.cookie('cs') === 'lease') { checkLeaseButton(); //console.log('cookie commercial for lease'); return; } if ($.cookie('cs') === 'resi') { checkResiButton(); //console.log('residential'); return; } if (typeof listingType !== 'undefined' && typeof isLeaseSearch !== 'undefined') { console.log('listingtype: ' + listingType + " isLeaseSearch: " + isLeaseSearch); if (listingType === 'commercial') { if (isLeaseSearch) { checkLeaseButton(); return; } else { checkSaleButton(); return; } } else { checkResiButton(); return; } } } } function updateSearchText(mode){ if (mode === 'residential'){ //console.log('Updating Search Text Resi'); $(".sampleSearchText").text("eg. Vancouver 2 bedroom Condos under 500K"); //console.log('Prev Check Box: ' + prevCheckBox); if ($("#searchValue").prop("value") === defaultSearchTextCommercial || prevCheckBox === 'commercial-lease' || prevCheckBox === 'commercial-sale'){ $("#searchValue").prop("value",defaultSearchTextResidential); $("#searchValue").prop("title",defaultSearchTextResidential); } if ($("#searchValue").prop("value").toLowerCase().indexOf('For Lease'.toLowerCase()) !== -1){ str = $("#searchValue").prop("value"); str = str.replace(/For Lease/i, ''); $("#searchValue").prop("value",str); $("#searchValue").prop("title",str); quickNav.s = str; } if ($("#searchValue").prop("value").toLowerCase().indexOf('For Sale'.toLowerCase()) !== -1){ str = $("#searchValue").prop("value"); str = str.replace(/For Sale/i, ''); $("#searchValue").prop("value",str); $("#searchValue").prop("title",str); quickNav.s = str; } } else if (mode === 'commercial-sale') { //console.log('Updating Search Text Comm'); $(".sampleSearchText").text("eg. Vancouver Offices For Sale under 5 million"); //console.log('Prev Check Box: ' + prevCheckBox); if ($("#searchValue").prop("value") === defaultSearchTextResidential || prevCheckBox === 'resi'){ $("#searchValue").prop("value",defaultSearchTextCommercial); $("#searchValue").prop("title",defaultSearchTextCommercial); } if ($("#searchValue").prop("value").toLowerCase().indexOf('For Lease'.toLowerCase()) !== -1){ str = $("#searchValue").prop("value"); if ($("#searchValue").prop("value").toLowerCase().indexOf('For Sale'.toLowerCase()) === -1) str = str.replace(/For Lease/i, 'for sale'); $("#searchValue").prop("value",str); $("#searchValue").prop("title",str); quickNav.s = str; } } else if (mode === 'commercial-lease') { //console.log('Updating Search Text Comm'); $(".sampleSearchText").text("eg. Vancouver Offices For Lease under 5 million" ); //console.log('Prev Check Box: ' + prevCheckBox); if ($("#searchValue").prop("value") === defaultSearchTextResidential || prevCheckBox === 'resi'){ $("#searchValue").prop("value",defaultSearchTextCommercial); $("#searchValue").prop("title",defaultSearchTextCommercial); } if ($("#searchValue").prop("value").toLowerCase().indexOf('For Sale'.toLowerCase()) !== -1){ str = $("#searchValue").prop("value"); if ($("#searchValue").prop("value").toLowerCase().indexOf('For Lease'.toLowerCase()) === -1) str = str.replace(/For Sale/i, 'for lease'); $("#searchValue").prop("value",str); $("#searchValue").prop("title",str); quickNav.s = str; } } $("#searchValue").css("color","rgb(128, 128, 128)"); } function checkResiButton(){ //console.log('Check Resi Button'); $("#residentialSearchBox").prop("checked", true); $("#commercialSearchBoxForSale").prop("checked", false); $("#commercialSearchBoxForLease").prop("checked", false); $("#searchForm").prop("action","/search"); $("#residentialRegions").show(); $("#commercialRegionsForSale").hide(); $("#commercialRegionsForLease").hide(); $.cookie('cs', 'resi', { path: '/'}); //console.log("removing cs cookie"); updateSearchText('residential'); toggleNextPrevButtons(); prevCheckBox = 'resi'; } function checkSaleButton(){ //console.log('Check Sale Button'); $("#commercialSearchBoxForSale").prop("checked", true); $("#commercialSearchBoxForLease").prop("checked", false); $("#residentialSearchBox").prop("checked", false); $("#searchForm").prop("action","/commercial/search"); //console.log('showing commercial regions'); $("#residentialRegions").hide(); $("#commercialRegionsForLease").hide(); $("#commercialRegionsForSale").show(); $.cookie('cs', 'sale', { path: '/'}); updateSearchText('commercial-sale'); toggleNextPrevButtons(); prevCheckBox = 'commercial-sale'; } function checkLeaseButton(){ //console.log('Check Lease Button'); $("#commercialSearchBoxForLease").prop("checked", true); $("#commercialSearchBoxForSale").prop("checked", false); $("#residentialSearchBox").prop("checked", false); $("#searchForm").prop("action","/commercial/search"); //console.log('showing commercial regions'); $("#residentialRegions").hide(); $("#commercialRegionsForSale").hide(); $("#commercialRegionsForLease").show(); $.cookie('cs', 'lease', { path: '/'}); updateSearchText('commercial-lease'); toggleNextPrevButtons() prevCheckBox = 'commercial-lease'; } function toggleNextPrevButtons(){ if (!searchTypeInitialized){ searchTypeInitialized = true; } else { if ($("#nextListingButton").length !== 0){ $("#nextListingButton").attr('onclick', ''); $('#nextListingButton').addClass('disabled'); } if ($("#previousListingButton").length !== 0){ $("#previousListingButton").attr('onclick', ''); $('#previousListingButton').addClass('disabled'); } $("#listingNumberText").text("Please Search Again"); } } });