(function($){
$.pricerent = function(t,p){
p = $.extend({
defaultvalue:{},
type : 'slider', //slider or select
lang : 'chi',
priceType : 'sell',
trans :false,
hiddenInclude : {},
initFunction : function(){},
district : false,
price1 : false,
price2 : false,
area1 : 0,
area2 : false,
bedroom1 : 0,
bedroom2 : false,
usageObj :{},
distObj :{},
btn :{
'chi':{
'all':'全選',
'clear':'取消',
'submit':'確定'
},
'eng':{
'all':'All',
'clear':'Clear',
'submit':'Confirm'
}
},
sizeTxt : {
min : 0,
max : 6200,
step : 200,
txt1 : "呎或以上",
txt2 : "呎",
min : 0
},
rentTxt :{
max : 81000,
step : 1000,
txt1 : "元或以上",
txt2 : "元",
min : 0
},
priceTxt :{
max : 2100,
step : 100,
txt1 : "萬或以上",
txt2 : "萬",
min : 0
},
//select Option
priceUnit : {
// 0:'unit',
// 1:'total'
},
selectSetAny: false,
priceRange :{
// 'sell':{
// 'unit':{
// 0: {
// 0:'8',
// 1:'10',
// 2:'12',
// 3:'14',
// 4:'15',
// 5:'16',
// 6:'19+'
// },
// 1: {
// 0:'8',
// 1:'10',
// 2:'12',
// 3:'14',
// 4:'15',
// 5:'16',
// 6:'19+'
// }
// },
// 'total':{
// 0: {
// 0:'8?U',
// 1:'10?U',
// 2:'12?U',
// 3:'14?U',
// 4:'15?U',
// 5:'16?U',
// 6:'19?U+'
// },
// 1: {
// 0:'8?U',
// 1:'10?U',
// 2:'12?U',
// 3:'14?U',
// 4:'15?U',
// 5:'16?U',
// 6:'19?U+'
// }
// }
// },
// 'rent':{
// 'unit':{
// 0: {
// 0:'8',
// 1:'10',
// 2:'12',
// 3:'14',
// 4:'15',
// 5:'16',
// 6:'19+'
// },
// 1: {
// 0:'8',
// 1:'10',
// 2:'12',
// 3:'14',
// 4:'15',
// 5:'16',
// 6:'19+'
// }
// },
// 'total':{
// 0: {
// 0:'8?d',
// 1:'10?d',
// 2:'12?d',
// 3:'14?d',
// 4:'15?d',
// 5:'16?d',
// 6:'19?d+'
// },
// 1: {
// 0:'8?d',
// 1:'10?d',
// 2:'12?d',
// 3:'14?d',
// 4:'15?d',
// 5:'16?d',
// 6:'19?d+'
// }
// }
// }
},
sizeRange :{
// 0:{
// 0:'500',
// 7:'3500+',
// },
// 1:{
// 0:'500',
// 7:'3500+',
// }
}
}, p);
/*DOM ids/classes*/
/*event*/
v= {
conWord : function(){
switch(p.lang){
case 'chi':
return ' 至 ';
break;
default:
return ' to ';
}
},
priceText : function (type){
var pType = new Object;
if (type==="rent"){
return p.rentTxt;
}else if(type==="sell"){
return p.priceTxt;
}
},
sizeText : function(){
$.extend({},p.sizeTxt);
// var size = new Object;
// size.min = 0
// size.max = 6200;
// size.step = 200;
// size.txt1 = "?`漏?H?W";
// size.txt2 = "?`";
// size.min = 0;
return $.extend({},p.sizeTxt);
}
}
var e = {
initAllEvent : function(){
if (p.priceType==1)p.priceType='sell';
else if (p.priceType==2)p.priceType='rent';
else if (!p.priceType)p.priceType='sell';
switch(p.type){
case 'select':
if (p.selectSetAny){
if (p.selectSetAny.chi=='underfined'||p.selectSetAny.chi=='underfined'||p.selectSetAny.chi==null||p.selectSetAny===true){
p.selectSetAny={};
p.selectSetAny['chi']='所有';
}
if (p.selectSetAny.eng=='underfined'||p.selectSetAny.eng=='underfined'||p.selectSetAny.eng==null||p.selectSetAny===true){
p.selectSetAny['eng']='Any';
}
}
s.initprice();
f.priceTypeChange();
s.priceUnitChange();
s.initDistrict();
s.initSize();
break;
case 'slider':
if (p.selectSetAny){
if (p.selectSetAny.chi=='underfined'||p.selectSetAny.chi=='underfined'||p.selectSetAny.chi==null||p.selectSetAny===true){
p.selectSetAny={};
p.selectSetAny['chi']='所有';
}
if (p.selectSetAny.eng=='underfined'||p.selectSetAny.eng=='underfined'||p.selectSetAny.eng==null||p.selectSetAny===true){
p.selectSetAny['eng']='Any';
}
}
this.setDefault();
this.setHiddenInclude();
this.initSizeBar();
this.initRoomBar();
this.initPriceBar(p.priceType);
this.initBathBar();
this.initdate();
f.loadDist();
f.loadUsage();
f.focusUsage();
f.focusDist();
f.priceTypeChange();
f.autocompleteProp();
f.autocompleteBuildingBox();
f.autocompleteStreetBox();
this.setInitprice();
this.setInitSize();
this.setInitBedroom();
this.setInitDistrict();
e.initResetButton();
p.initFunction();
break;
}
},
setDefault :function(){
$.each(p.defaultvalue,function(i,e){
switch(i){
case 'price_type':
switch(e){
case '1':
p.priceType='sell';
break;
case '2':
p.priceType='rent';
break;
}
$.each($("[name="+i+"]"),function(idx,elm){
if ($(elm).val()==e){
$(elm).prop('checked',true);
}
else $(elm).prop('checked',false);
})
break;
default:
$.each($("[name="+i+"]"),function(idx,elm){
if ($(elm).val()==e){
$(elm).prop('checked',true);
}
else $(elm).prop('checked',false);
})
break;
}
})
},
setdefaultvalue :function(){
$.each($("[name="+i+"]"),function(idx,elm){
if ($(elm).val()==e){
$(elm).prop('checked',true);
}
else $(elm).prop('checked',false);
})
},
initSizeBar :function(){
var size=v.sizeText();
$(t).find("#size-range").slider({
range: true,
min: size.min,
max: size.max,
step:size.step,
values: [size.min,size.max],
slide: function(event, ui) {
var max = $(t).find( "#size-range" ).slider( "option", "max" );
var step= $(t).find( "#size-range" ).slider( "option", "step" );
$(t).find("#area1-hid").val(ui.values[0]);
$(t).find("#area1").changeValOrHtml(ui.values[0]);
$(t).find("#area2-hid").val(ui.values[1]);
$(t).find("#area2").changeValOrHtml(ui.values[1]);
if (ui.values[1] == max){
$(t).find("#area2").next('label').html(size.txt1);
$(t).find("#area2").changeValOrHtml(max-step);
$(t).find("#area2-hid").val(max-step+"+");
}else
$(t).find("#area2").next('label').html(size.txt2);
if (ui.values[0] == max){
$(t).find("#area1").changeValOrHtml(max-step);
}
}
});
//initial
$(t).find("#area1").changeValOrHtml($(t).find("#size-range").slider("values", 0))
.next('label').html(size.txt2+v.conWord());
$(t).find("#area2").changeValOrHtml(parseInt($(t).find("#size-range").slider("values", 1))-$(t).find( "#size-range" ).slider( "option", "step" ))
.next('label').html(size.txt1);
$(t).find("#area2-hid").val(parseInt($(t).find("#size-range").slider("values", 1))-$(t).find( "#size-range" ).slider( "option", "step" )+"+");
$(t).find("#area1-hid").val(parseInt($(t).find("#size-range").slider("values", 0)));
},
initBathBar : function () {
$(t).find("#bathRms-range").slider({
range: true,
min: 1,
max: 7,
step:1,
values: [0,7],
slide: function(event, ui) {
var max = $(t).find( "#bathRms-range" ).slider( "option", "max" );
var step= $(t).find( "#bathRms-range" ).slider( "option", "step" );
$(t).find("#bathRms1-hid").val(ui.values[0]);
$(t).find("#bathRms1").changeValOrHtml(ui.values[0]);
$(t).find("#bathRms2-hid").val(ui.values[1]);
$(t).find("#bathRms2").changeValOrHtml(ui.values[1]);
if (ui.values[1] == max){
$(t).find("#bathRms2").next('label').html("Rms+");
$(t).find("#bathRms2").changeValOrHtml(max-step);
$(t).find("#bathRms2-hid").val(max-step+"+");
}else
$(t).find("#bathRms2").next('label').html("Rms");
if (ui.values[0] == max){
$(t).find("#bathRms1").changeValOrHtml(max-step);
}
}
});
//initial
$(t).find("#bathRms1").changeValOrHtml($(t).find("#bathRms-range").slider("values", 0))
.next('label').html("Rms to ");
$(t).find("#bathRms2").changeValOrHtml(parseInt($(t).find("#bathRms-range").slider("values", 1))-$(t).find( "#bathRms-range" ).slider( "option", "step" ))
.next('label').html("Rms+");
$(t).find("#bathRms2-hid").val(parseInt($(t).find("#bathRms-range").slider("values", 1))-$(t).find( "#bathRms-range" ).slider( "option", "step" )+"+");
$(t).find("#bathRms1-hid").val(parseInt($(t).find("#bathRms-range").slider("values", 0)));
},
initRoomBar : function(){
$(t).find("#bedRms-range").slider({
range: true,
min: 1,
max:7,
step:1,
values: [0,7],
slide: function(event, ui) {
var max = $(t).find( "#bedRms-range" ).slider( "option", "max" );
var step= $(t).find( "#bedRms-range" ).slider( "option", "step" );
$(t).find("#bedRms1-hid").val(ui.values[0]);
$(t).find("#bedRms1").changeValOrHtml(ui.values[0]);
$(t).find("#bedRms2-hid").val(ui.values[1]);
$(t).find("#bedRms2").changeValOrHtml(ui.values[1]);
if (ui.values[1] == max){
$(t).find("#bedRms2").next('label').html("Rms+");
$(t).find("#bedRms2").changeValOrHtml(max-step);
$(t).find("#bedRms2-hid").val(max-step+"+");
}else
$(t).find("#bedRms2").next('label').html("Rms");
if (ui.values[0] == max){
$(t).find("#bedRms1").changeValOrHtml(max-step);
}
}
});
//initial
$(t).find("#bedRms1").changeValOrHtml($(t).find("#bedRms-range").slider("values", 0))
.next('label').html(" Rms to ");
$(t).find("#bedRms2").changeValOrHtml(parseInt($(t).find("#bedRms-range").slider("values", 1))-$(t).find( "#bedRms-range" ).slider( "option", "step" ))
.next('label').html("Rms+");
$(t).find("#bedRms1-hid").val($(t).find("#bedRms-range").slider("values", 0));
$(t).find("#bedRms2-hid").val($(t).find("#bedRms-range").slider("values", 1)-$(t).find( "#bedRms-range" ).slider( "option", "step" )+"+");
},
initPriceBar : function(type){
var pType = v.priceText(type);
$(t).find("#price-range1").slider({
range: true,
min : pType.min,
max : pType.max,
step : pType.step,
values : [pType.min ,pType.max],
slide: function(event, ui) {
var max = $(t).find( "#price-range1" ).slider( "option", "max" );
var step = $(t).find( "#price-range1" ).slider( "option", "step" );
$(t).find("#price1").changeValOrHtml(ui.values[0]);
$(t).find("#price1-hid").val(f.changePriceUnit(parseFloat(ui.values[0]),pType.txt2,type));
$(t).find("#price3-hid").val(parseFloat(ui.values[0]));
$(t).find("#price2").changeValOrHtml(ui.values[1]);
$(t).find("#price2-hid").val(f.changePriceUnit(parseFloat(ui.values[1]),pType.txt2,type));
$(t).find("#price4-hid").val(parseFloat(ui.values[1]));
//$(t).find("#price2").val(ui.values[1]);
if (ui.values[1] >= max){
$(t).find("#price2").next('label').text(pType.txt1);
$(t).find("#price2").changeValOrHtml(max-pType.step);
$(t).find("#price2-hid").val(f.changePriceUnit(parseFloat(max-pType.step),pType.txt2,type)+'+');
$(t).find("#price4-hid").val(parseFloat(max)+'+');
}else
$(t).find("#price2").next('label').text(pType.txt2);
if (ui.values[0] == max){
$(t).find("#price1").changeValOrHtml(max-pType.step);
$(t).find("#price1-hid").val(f.changePriceUnit(parseFloat(ui.values[0]-pType.step),pType.txt2,type));
$(t).find("#price3-hid").val(parseFloat(ui.values[0]-pType.step));
}
}
});
//initial
$(t).find("#price1").changeValOrHtml($(t).find("#price-range1").slider("values", 0))
.next('label').text(pType.txt2+v.conWord());
$(t).find("#price1-hid").val(f.changePriceUnit(parseFloat($(t).find("#price-range1").slider("values", 0)),pType.txt2,type ));
$(t).find("#price3-hid").val(parseFloat($(t).find("#price-range1").slider("values", 0)));
//console.log(parseInt($(t).find("#price-range1").slider("values", 1))-pType.step);
$(t).find("#price2").changeValOrHtml(parseInt($(t).find("#price-range1").slider("values", 1))-pType.step)
.next('label').text(pType.txt1);
$(t).find("#price2-hid").val(f.changePriceUnit(parseFloat($(t).find("#price-range1").slider("values", 1)),pType.txt2,type )+"+");
$(t).find("#price4-hid").val(parseFloat($(t).find("#price-range1").slider("values", 1)-pType.step+"+"));
$(t).find("#priceWrap1").show();
$(t).find("#priceWrap2").hide();
},
initdate : function(){
$(t).find("#date1, #date2").datepicker({
dateFormat : 'yy/mm/dd',
showAnim : 'blind'
})
$(t).find("#date1").datepicker( "setDate" , '-1m');
$(t).find("#date2").datepicker( "setDate" , 'today');
},
initResetButton : function(){
$(t).find("[type=reset]").click(function(){
//sconsole.log($(t).find("form"));
if ($(t).find("input[name]").length)
{ $.each($(t).find("input[name]"),function(i,elm){
//console.log(elm);
var field_type = elm.type.toLowerCase();
switch(field_type) {
case "text":
case "password":
case "textarea":
// case "hidden":
elm.value = "";
break;
case "radio":
case "checkbox":
if (elm.checked) {
elm.checked = false;
}
break;
case "select-one":
case "select-multi":
elm.selectedIndex = -1;
break;
default:
break;
}
})
}
else {
// t.reset()
};
e.initSizeBar();
e.initRoomBar();
e.initPriceBar(p.priceType);
e.initBathBar();
e.initdate();
p.initFunction();
return false;
})
},
setInitprice: function(){
if (p.price1||p.price2)
{
var pType=v.priceText(p.priceType);
var sign = (p.price2.lastIndexOf("+"))? "+":"";
var stepAdj= (sign)?pType.step:0;
var max = $(t).find( "#price-range1" ).slider( "option", "max" );
var step = $(t).find( "#price-range1" ).slider( "option", "step" );
var price2=(p.price2)? p.price2.replace(/\+/g, ""): (max-step);
if (price2==(max-step))
{var text1=pType.txt1;}
else {var text1=pType.txt2;}
var price1=(p.price1)? p.price1.replace(/\+/g, ""):0;
$(t).find("#price-range1").slider( "option", "values", [price1,price2+stepAdj] );
$(t).find("#price1").changeValOrHtml(price1);
$(t).find("#price1-hid").val(f.changePriceUnit(parseFloat(p.price1),pType.txt2,p.priceType));
$(t).find("#price3-hid").val(parseFloat(p.price1));
$(t).find("#price2-hid").val(f.changePriceUnit(parseFloat(p.price2),pType.txt2,p.priceType)+sign);
$(t).find("#price4-hid").val(parseFloat(p.price2)+sign);
//$(t).find("#price1-hid").val(p.price1).html(p.price1);
$(t).find("#price2").changeValOrHtml(price2)
.next('label').text(text1);
//$(t).find("#price2-hid").val(p.price2);
}
},
setInitSize : function(){
if (p.area1||p.area2)
{
var pType=v.sizeText();
var sign = (p.price2.lastIndexOf("+"))? "+":"";
var stepAdj= (sign)?pType.step:0;
var max = $(t).find( "#size-range" ).slider( "option", "max" );
var step = $(t).find( "#size-range" ).slider( "option", "step" );
var area2=(p.area2)? p.area2.replace(/\+/g, ""): (max-step);
if (area2==(max-step))
{var text1=pType.txt1;}
else {var text1=pType.txt2;}
var area1=(p.area1)? p.area1.replace(/\+/g, ""):0;
$(t).find("#size-range").slider( "option", "values", [area1,area2+stepAdj] );
$(t).find("#area1").changeValOrHtml(area1);
$(t).find("#area1-hid").val(p.area1);
$(t).find("#area2").changeValOrHtml(area2)
.next('label').text(text1);
$(t).find("#area2-hid").val(p.area2);
}
},
setInitBedroom : function(){
if (p.bedroom1||p.bedroom2)
{
var pType=v.sizeText();
var sign = (p.price2.lastIndexOf("+"))? "+":"";
var stepAdj= (sign)?pType.step:0;
var max = $(t).find( "#bedRms-range" ).slider( "option", "max" );
var step = $(t).find( "#bedRms-range" ).slider( "option", "step" );
var bedroom2=(p.bedroom2)? p.bedroom2.replace(/\+/g, ""): (max-step);
if (bedroom2==(max-step))
{var text1=pType.txt1;}
else {var text1=pType.txt2;}
var bedroom1=(p.bedroom1)? p.bedroom1.replace(/\+/g, ""):0;
$(t).find("#bedRms-range").slider( "option", "values", [bedroom1,bedroom2+stepAdj] );
$(t).find("#bedroom1").changeValOrHtml(bedroom1);
$(t).find("#bedroom1-hid").val(p.bedroom1);
$(t).find("#bedroom2").changeValOrHtml(bedroom2)
.next('label').text(text1);
$(t).find("#bedroom2-hid").val(p.bedroom2);
}
},
setInitDistrict : function(){
if (p.defaultvalue.district||p.district)
{
if (p.defaultvalue.district)p.district=p.defaultvalue.district;
var distAry=[];
distAry = p.district.split(",");
$.each(distAry,function(i,e){
if ($('#distDialog').length){
$.each($('#distDialog').find('label'),function(li,le){
if ($(le).text()==e){
$(le).find('input[type=checkbox]').prop('checked',true);
}
});
}
});
var distPara=$(t).find("[name=district]");
distPara=distPara[0];
switch(distPara.type.toLowerCase()){
case 'select-one':
$(distPara).html('');
var option='';
$(distPara).append(option);
break;
case 'password':
case 'text':
$(distPara).val(p.district);
break;
}
}
},
setHiddenInclude : function(){
if (p.hiddenInclude){
$.each(p.hiddenInclude,function(i,e){
var hiddenInput='';
$(t).append(hiddenInput);
})
}
}
}
var f={
loadDist: function(){
var optDistDOMPre = '
';
var outDistDOM = "";
if (p.trans)
var url="./ajax/getTransaction.php?type=loadDist";
else
var url="./ajax/getProperty.php?type=distlist";
$.ajax({
url : url,
//url : "./data/loaddistlist.json",
data : p.hiddenInclude,
cache : true,
dataType : "json",
type : "get",
success : function(data){
if (data){
var district=$('[name=district]')[0];
switch( district.type){
case 'select-one':
switch(p.lang){
case "chi":
var tmpl='';
break;
case "eng":
var tmpl='';
break;
}
$.template( "tmplObj", tmpl );
/******Apply template******/
if ($("#distDialog").length){
$.each(data,function(i,v){
$('#search_dis_result').tmpl(v).appendTo($("#zone_"+v.ZONE).parent());
});
}else
{
if (p.selectSetAny){
var anySelectOpt='';
$(t).find('[name=district]').append(anySelectOpt);
}
$.tmpl( "tmplObj", data )
.appendTo( "[name=district]" );
}
break;
case 'hidden':
case 'text':
$.each(data,function(i,v){
$('#search_dis_result').tmpl(v).appendTo($("#zone_"+v.ZONE).parent());
});
break;
}
}
}
})
},
loadUsage : function(){
var selectWrap = $(t).find("#usageDialog");
var optDOMPre = '