(function() {
var widgetID = 43209;
var agentHeaderID = null;
if (!widgetID) {
alert('Invalid widget ID given.');
return false;
}
function widgetMainOut() {
var src = (!isNaN(widgetID)) ? 'quicksearchjs.php?widgetid=43209' : 'quicksearchjs.php';
var widgetElement = idx('script[src$="'+src+'"]');
// check for a dynamic widget
if (!widgetElement.size()) {
var widgetSrc = idx('#idxwidgetsrc-43209');
if (widgetSrc.size()) {
widgetElement = widgetSrc;
}
}
var maincID = 'IDX-quicksearch-43209';
var formID = 'IDX-quicksearchForm-43209';
idx('body').on('submit','#'+formID,function(e) {
var disabled = [];
// disable empty form values
idx('input[type="text"]',this).each(function (key,val) {
if (idx(this).val() === '') {
idx(this).prop('disabled',true);
disabled.push(idx(this).attr('id'));
}
else
idx(this).val(idx(this).val().replace(/[^0-9]/g, ''));
});
idx('select',this).each(function (key,val) {
if (idx('option:selected',this).val() === '') {
idx(this).prop('disabled',true);
disabled.push(idx(this).attr('id'));
}
});
setTimeout(function() {
idx.each(disabled,function(i,v) {
idx('#'+v).attr('disabled',false);
});
},250);
return true;
});
// open in a new window/tab
var formTarget = '_self';
var mainc = idx('
').attr({'id':maincID,
'class':'IDX-quicksearchWrapper'
}).append(
idx('').attr({
'id':formID,
'class':'IDX-quicksearchForm',
'action':'//properties.winnirentals.com/idx/results/listings',
'method':'get',
'target':formTarget
})
);
widgetElement.after(mainc);
idx('#'+maincID).before('#IDX-quicksearch-43209 {width:250px;}\#IDX-quicksearch-43209 { border-radius: 10px; -webkit-border-radius: 10px; border: 1px solid #ccc; box-shadow: 1px 1px 5px #777; -webkit-box-shadow: 1px 1px 5px #777; } #IDX-quicksearch-43209 label { margin: 0 5px;} #IDX-qsIdxIDWrap-43209 { margin-top: 10px; } #IDX-quicksearch-43209 select { width: 100% } .IDX-qsTextInput { width: 120px } .IDX-qsFieldWrap { padding: 5px 10px; text-align: right; } #IDX-qsMinPriceLabel-43209 { float: left; } #IDX-qsMaxPriceLabel-43209 { float: left; } #IDX-qsMinBedLabel-43209 { float:left; } #IDX-qsMinSqFtLabel-43209 { float: left; } #IDX-qsMinBathLabel-43209 { float: left; } #IDX-qsCityListLabel-43209 { float: left; } #IDX-qsIdxIDLabel-43209 { display: none; } #IDX-qsPtLabel-43209 { display: none; } #IDX-qsCityListLabel-43209 { display: none; }');
idx('#'+formID).append(
idx('
'id':'IDX-qsIdxIDWrap-43209',
'class':'IDX-qsFieldWrap'
}).append(
idx('').attr({
'id':'IDX-qsIdxIDLabel-43209',
'class':'IDX-qsLabel',
'for':'IDX-qsIdxID-43209'
}).text('Select An MLS')
).append(
idx('').attr({
'id':'IDX-qsIdxID-43209',
'class':'IDX-qsInput IDX-qsSelectInput',
'name':'idxID'
}).append(idx('').val('').text('Multiple / All')).append(idx('').val('b027').html('New England Real Estate Network (NEREN)').prop('selected',true))
)
);
idx('#'+formID).append(
idx('
'id':'IDX-qsMinPriceWrap-43209',
'class':'IDX-qsFieldWrap'
}).append(
idx('').attr({
'id':'IDX-qsMinPriceLabel-43209',
'class':'IDX-qsLabel',
'for':'IDX-qsMinPrice-43209'
}).text('Min Price')
).append(
idx('').attr({
'id':'IDX-qsMinPrice-43209',
'class':'IDX-qsInput IDX-qsTextInput',
'name':'lp',
'type':'text'
}).val('100000')
)
);
idx('#'+formID).append(
idx('
'id':'IDX-qsMaxPriceWrap-43209',
'class':'IDX-qsFieldWrap'
}).append(
idx('').attr({
'id':'IDX-qsMaxPriceLabel-43209',
'class':'IDX-qsLabel',
'for':'IDX-qsMaxPrice-43209'
}).text('Max Price')
).append(
idx('').attr({
'id':'IDX-qsMaxPrice-43209',
'class':'IDX-qsInput IDX-qsTextInput',
'name':'hp',
'type':'text'
}).val('500000')
)
);
idx('#'+formID).append(
idx('').attr({
'id':'IDX-qsCCZHidden-43209',
'class':'IDX-qsInput IDX-qsHiddenInput',
'name':'ccz',
'type':'hidden'
}).val('city')
);
idx('#'+formID).append(
idx('
'id':'IDX-qsCityListWrap-43209',
'class':'IDX-qsFieldWrap'
}).append(
idx('').attr({
'id':'IDX-qsCityListLabel-43209',
'class':'IDX-qsLabel',
'for':'IDX-qsCityList-43209'
}).text('City')
).append(
idx('').attr({
'id':'IDX-qsCityList-43209',
'class':'IDX-qsInput IDX-qsSelectInput',
'name':'city[]'
})
)
);
idx('#IDX-qsCityList-43209').append(
idx('').attr('class','IDX-qsOption').val('').text('Choose a City')
);
idx('#IDX-qsCityList-43209').append(
idx('').attr('class','IDX-qsOption').val('931').prop('selected',false).text('Alton')
);
idx('#IDX-qsCityList-43209').append(
idx('').attr('class','IDX-qsOption').val('7932').prop('selected',false).text('Center Harbor')
);
idx('#IDX-qsCityList-43209').append(
idx('').attr('class','IDX-qsOption').val('17901').prop('selected',false).text('Gilford')
);
idx('#IDX-qsCityList-43209').append(
idx('').attr('class','IDX-qsOption').val('24887').prop('selected',false).text('Laconia')
);
idx('#IDX-qsCityList-43209').append(
idx('').attr('class','IDX-qsOption').val('29749').prop('selected',false).text('Meredith')
);
idx('#IDX-qsCityList-43209').append(
idx('').attr('class','IDX-qsOption').val('31372').prop('selected',false).text('Moultonborough')
);
idx('#IDX-qsCityList-43209').append(
idx('').attr('class','IDX-qsOption').val('47067').prop('selected',false).text('Tuftonboro')
);
idx('#IDX-qsCityList-43209').append(
idx('').attr('class','IDX-qsOption').val('52423').prop('selected',false).text('Wolfeboro')
);
idx('#IDX-quicksearchForm-43209').submit(function(evt) {
if (idx('#IDX-qsCityList-43209').val() === '')
{
evt.preventDefault();
var params = idx.param(idx('#IDX-quicksearchForm-43209 input[type!=submit]'));
params += '&' + idx.param(idx('#IDX-quicksearchForm-43209 select').has('option:selected[value!=""]'));
params = params.replace(/&$/,'');
var cityParams = idx.param(idx('#IDX-qsCityList-43209 > option[value!=""]')).replace(/undefined/g, 'city[]');
var url = idx('#IDX-quicksearchForm-43209').attr('action') + "?" + params + '&' + cityParams;
window.open(url, '_self');
}
});
idx('#'+formID).append(
idx('').attr({
'id':'IDX-qsQuickSearch-43209',
'class':'IDX-qsInput IDX-qsHiddenInput',
'name':'widgetReferer',
'type':'hidden'
}).val('true')
);
idx('#'+formID).append(
idx('
'id':'IDX-qsSubmitWrap-43209',
'class':'IDX-qsFieldWrap'
}).append(
idx('').attr({
'id':'IDX-qsSubmit-43209',
'class':'IDX-qsInput IDX-qsButtonInput',
'type':'submit'
}).val('Search')
)
);
/**
* handle the prop types
*/
// cach the elements that we are going to be using
var mlsElement = idx('#IDX-qsIdxID-'+widgetID);
var propTypeElement = idx('#IDX-qsPt-'+widgetID);
var qsPropTypes = {"1":"Residential","2":"Land","3":"Commercial Sale","4":"Commercial Lease","5":"Multi-Family","6":"Boat Facility","7":"Rental"};
var qsAllPropertyTypes = null;
var defaultIdxID = 'b027';
var defautltPt = '';
var currentMls = mlsElement.val();
var initialLoad = true;
if (qsPropTypes)
{
addQsPtOptions(qsPropTypes);
}
if (qsAllPropertyTypes)
{
mlsElement.change(qsPropTypeToggle);
// set the proptypes by default
qsPropTypeToggle();
}
function qsPropTypeToggle() {
if (qsAllPropertyTypes)
{
currentMls = mlsElement.val();
if (currentMls) {
addQsPtOptions(qsAllPropertyTypes[currentMls]);
} else {
addQsPtOptions(qsPropTypes);
}
}
}
function addQsPtOptions(propTypes)
{
var options = ['All'];
idx.each(propTypes, function(ptID,propertyType) {
var selected = '';
if (propertyTypeShouldBeSelected(ptID))
selected = ' selected="selected"';
options.push(''+propertyType+'');
});
propTypeElement.html(options.join("\n"));
initialLoad = false;
}
function propertyTypeShouldBeSelected(ptID)
{
// first load and pt match, yes select it!
if (initialLoad && defautltPt == ptID) {
return true;
}
// default idxID and prop type match current, yes!
if (currentMls == defaultIdxID && defautltPt == ptID) {
return true;
}
return false;
}
if (agentHeaderID) {
idx(function() {
var widetSrc = widgetElement.attr('src');
if (widetSrc.match(/.+quicksearchjs\.php/)) {
var quicksearchForm = idx('#IDX-quicksearchForm-43209');
quicksearchForm.append(idx('').attr({
type: 'hidden',
name: 'agentHeaderID',
value: agentHeaderID
}));
} else if (widetSrc.match(/.+leadloginwidget\.php/)) {
var leadLoginForm = idx('#IDX-widgetLeadLoginForm');
leadLoginForm.append(idx('').attr({
type: 'hidden',
name: 'agentHeaderID',
value: agentHeaderID
}));
} else if (widetSrc.match(/.+mapwidgetjs\.php/)) {
idx('#IDX-map-' + widgetID).on('click', 'a[href^="http"]', function (e) {
e.preventDefault();
var href = idx(e.target).attr('href');
if (href.match(/.+\?.+/)) {
href = href + '&agentHeaderID=' + agentHeaderID;
} else {
href = href + '?agentHeaderID=' + agentHeaderID;
}
window.location.href = href;
});
} else {
// carousel, showcase, and slideshow
var detailsLinks = idx('div[id*='+widgetID+']').find('a[href*=widgetReferer]');
detailsLinks.each(function(index, element) {
var originalLink = idx(element).attr('href');
idx(element).attr('href', originalLink + '&agentHeaderID=' + agentHeaderID );
});
}
});
}
}
// build a script tag with our version of jquery provided if it doesn't already exist
if (typeof idx == 'undefined') {
/**
* fake idx object to let other widgets know the first widget has inserted jqidx.js
* wait to jqwidx.js loaded, idx will be the jquery object.
*/
window.idx = {};
var jqsrc = '//d1qfrurkpai25r.cloudfront.net/graphical/javascript/jqwidx.js?auid=YXgQkhdRnkcpqdrHLvvS7AAAABo';
var idxjs = document.createElement('script');
idxjs.setAttribute('type','text/javascript');
idxjs.setAttribute('id','idx_jquery_include_tag');
idxjs.setAttribute('src',jqsrc);
// lets let IE in or he'll just sit outside and drink and cry
if (idxjs.readyState) {
idxjs.onreadystatechange = function () {
if (this.readyState == 'complete' || this.readyState == 'loaded') {
widgetMainOut();
}
};
}
// For gooder browsers
else {
idxjs.onload = widgetMainOut;
}
// for loading speed our best bet is to insert our jquery before the first script tag on their site since, at minimum,
// this widget is being loaded in a script tag, we know there's at least 1 in the document and we know for sure this
// will load before any version of jquery on their site so that we can sequester our version behind noConflict
var s1 = document.getElementsByTagName('script')[0];
s1.parentNode.insertBefore(idxjs, s1);
}
// if the idx jquert is loaded then we need to wait until the idx val is defined
else {
// wait to the first widget's idx jquery object loaded
var callWidgetOut = function () {
if (window.idx && window.idx.fn) {
widgetMainOut();
} else {
setTimeout(function() {
callWidgetOut();
}, 500);
}
};
callWidgetOut();
}
})();