var refine_display_text=null;
var object_name_array=null;
var bkp_refine_result_url=null;
var bkp_refine_result_result=null;
var refine_chk_onchange_func=null;
var temp_resultsArr=new Array();
var temp_refine_resultsArr=new Array();
var icons_disp_Arr={"icons-crop":"Cultivated Land","icons-fencing":"Fencing","icons-health":"Fitness","icons-above10floors":"Property above 10 floors","icons-parking":"Parking","icons-security":"Security","icons-verify":"Verified Contact","icons-swiming":"Swimming pool","icons-sports":"Play area","icons-cafeteria":"Cafeteria","icons-newproperty":"New Property","icons-undercon.gif":"Property Under Construction","icons-upcoming":"Upcoming Listing"};
/* Search Results - Paging & Refine*/
(function($) {
	$.fn.showResults = function(data,Options){
		if(!$.isArray(data)){
			ip.print("its not an array");
			data = new Array();
			//throw "showResults expects an array";
		}
		var settings = {
			limit: 20,
			pages: 10,
			totalPages:0,
			total:0,
			start: 0,
			resultTarget: '',
			pagesTarget: '',
			emptyMsg: 'No Results',
			callback: null,
			highlight_results : null,
			offset : 1,
			recperpage : 20,
			template : "",
			signupAlert_template : "",
			header_template : "",
			header_results : "",
			header_pagination : "",
			header_interestedprojects : "",
			header_enquiries: ""
		};
		var paginator = {
			pages: 0,
			page: 0,
			next: 0,
			prev: 0,
			prevPage: 0,
			nextPage: 0,
			startPage: 0,
			endPage: 0,
			listStart: 0,
			listEnd: 0
		};
		if(Options) $.extend(settings, Options);
		if(data) settings.totalPages = Math.ceil(data.length/settings.limit);
		settings.total=data.length;
		return this.each(function() {
			/* save this to self because this changes when scope changes */
			var self = this;
			if(settings.resultTarget == '') {
				if(!$(self).find(".results").length) {
					$(self).append('<div class="results"></div>');
				}
				var $results = $(self).find('.results');
			} else {
				var $results = $(settings.resultTarget);
			}
			/*if(settings.pagesTarget == '') {
				if(!$(self).find(".pagination").length) {
					$(self).prepend('<div class="pagination"></div>');
				}
				var $pagination = $(self).find('.pagination');
			} else {
				var $pagination = $(self).find(settings.pagesTarget);
			}*/
			settings.template = $(self).find(".template").html();
			settings.signupAlert_template= $(self).find(".signupAlertTemplate").html();
			settings.header_results= $("#div_header_results").html();
			settings.header_pagination= $("#div_header_pagination").html();
			settings.header_interestedprojects= $("#div_header_interestedprojects").html();
			settings.header_enquiries= $("#div_header_enquiries").html();
			$results.empty();

			self.displayResults = function(){
				var offset = settings.start+settings.limit;
				if(offset > settings.total){
					offset = settings.total;
				}
				var tempStr,tempArr,listID,listingid;

				/* Header display String */
				settings.header_results=settings.header_results.replace(/%total_results%/g,settings.headerArr["total_results"]);
				settings.header_results=settings.header_results.replace(/%searched_for%/g,settings.headerArr["searched_for"]);
				$results.append(settings.header_results);
				/* End Header display String */

				if(settings.headerArr["total_results"]>0){
					/* Header Pagination*/
					var res_nav=settings.headerArr.res_nav;
					var rec_page_options=settings.headerArr.rec_page_options;
					tempStr="";
					if(rec_page_options!=""){
						var tempArr = rec_page_options.split("|");
						for (var i=0; i<tempArr.length; i++) {
							var countStr=tempArr[i].split("~")[0];
							var countClass=tempArr[i].split("~")[1];
							tempStr+='&nbsp;<a href="javascript:void(0);" onclick="loadSearchResultsJSON(\''+res_nav+'&recperpage='+countStr+'\')" class="'+((countClass==1) ? "active" : "") +'">'+countStr+'</a>';
						}
					}
					settings.header_pagination= settings.header_pagination.replace(/%rec_page_options%/g, ((tempStr=="") ? "" : "View "+tempStr+" Results per page") );
					tempStr="";
					var sort_by=settings.headerArr.sort_by;
					tempArr = sort_by.split("|");
					temp=res_nav+"&recperpage="+settings.recperpage+"&"+tempArr[0].split("~")[0] + "=" + tempArr[0].split("~")[1];
					tempStr+='<a href="javascript:void(0)" onclick="loadSearchResultsJSON(\''+temp+'\')" class="'+ ((tempArr[0].split("~")[1]=="desc") ? "arrUp" : "arrDown") +'" style="padding:2px 10px 2px 2px;">Price</a>';
					temp=res_nav+"&recperpage="+settings.recperpage+"&"+tempArr[1].split("~")[0] + "=" + tempArr[1].split("~")[1];
					tempStr+='&nbsp;<a href="javascript:void(0)" onclick="loadSearchResultsJSON(\''+temp+'\')" class="'+ ((tempArr[1].split("~")[1]=="desc") ? "arrUp" : "arrDown") +'" style="padding:2px 10px 2px 2px;">Date</a>';
					settings.header_pagination= settings.header_pagination.replace(/%sort_by%/g,tempStr);
					tempStr="";
					var pagination = settings.headerArr.pagination;
					tempArr=pagination.split("|");
					var focusPage=parseInt(settings.offset);
					for (var i=0; i<tempArr.length; i++){
						var str =$.trim((tempArr[i].indexOf("~")!=-1) ? tempArr[i].split("~")[0] : tempArr[i]);
						var pagingTo=(tempArr[i].indexOf("~")!=-1) ? tempArr[i].split("~")[1] : "";
						tempStr+= (pagingTo=="") ? str : ( (String(focusPage)==pagingTo) ? "&nbsp;<span>"+pagingTo+"</span>" : '&nbsp;<a href="javascript:void(0);" onclick="loadSearchResultsJSON(\''+res_nav+"&recperpage="+settings.recperpage+'&offset='+pagingTo+'\');return false;" id="'+str.toLowerCase()+'">'+str+'</a>');
					}
					settings.header_pagination= settings.header_pagination.replace(/%pagination%/g,tempStr);
					$results.append(settings.header_pagination);
					/* End Header Pagination*/
				}

				/* Header Interested Projects*/
				tempStr="";
				var temp = settings.headerArr.projects_interested;
				if(temp!=""){
					try{
						tempArr = temp.split("|");
						var temp_template = '<td style="width:33%; padding:0px 5px; vertical-align:top;"><img src="'+ip.img_path+'trans.gif" width="5" height="8" alt="" class="gArrLeft" style="padding:0px;"/><a target="_blank" href="index.php?option=upcoming&amp;page=projectview&amp;id=%LISTID%">%TITLE%, <br /><img src="'+ip.img_path+'trans.gif" width="8" height="1" alt="" />%LOCALITY%</a></td>';
						for (var i=0; i<tempArr.length; i++) {
							temp=temp_template;
							temp=temp.replace(/%LISTID%/g,tempArr[i].split("~")[0]);
							temp=temp.replace(/%TITLE%/g,tempArr[i].split("~")[1]);
							temp=temp.replace(/%LOCALITY%/g,tempArr[i].split("~")[2]);
							tempStr+=temp;
						}
						tempStr = '<table cellspacing="0" cellpadding="0" border="0" style="width:100%;" align="center"><tr>'+tempStr+'</tr></table>';
						settings.header_interestedprojects= settings.header_interestedprojects.replace(/%projects_interested%/g,tempStr);
						$results.append(settings.header_interestedprojects);
					}catch(e){tempStr="";traceErr(e);}
				}
				/* End Header Interested Projects*/

				if(settings.headerArr["total_results"]>0){
					/* Header Enquries*/
					settings.header_enquiries= settings.header_enquiries.replace(/%total_results%/g,settings.header_enquiries);
					$results.append(settings.header_enquiries);
					/* End Header Enquries*/
				}

				if(settings.highlight_results.length>0) self.appendResults(settings,settings.highlight_results,settings.highlight_results.length,$results,"sponsored");

				/* Main Results */
				if(settings.headerArr["total_results"]>0){
					self.appendResults(settings,settings.result,offset,$results);
					$results.append(settings.header_enquiries);
				}

				if(settings.headerArr.projects_interested!="") $results.append(settings.header_interestedprojects);

				if(settings.headerArr["total_results"]>0){
					$results.append(settings.header_pagination);
					$results.append(settings.header_results);
				}else{
					var signup_template=settings.signupAlert_template;
					signup_template=signup_template.replace(/%CNT%/g,1);
					$results.append(signup_template);

					/* if user logged in - ask them to POST Req Listing - Note: 'loggedin' Param is must*/
					if(String(settings.headerArr["res_nav"]).indexOf("loggedin")!=-1){
						var signupAlertTemp_LoggedIn= $(self).find(".signupAlertTemplate_LoggedIn").html();
						$results.append(signupAlertTemp_LoggedIn);
					}
					/* End Post Req*/


				}

				if(typeof settings.callback == "function"){
					settings.callback();
				}
			}
			self.appendResults = function(settings,resultArr,offset,$results,resultType){
				for(var i = settings.start; i < offset; i++) {
					var template = settings.template;
					var signup_template = ((i+1)%settings.signupDispPos==0) ? settings.signupAlert_template : "";
					signup_template=signup_template.replace(/%CNT%/g, (i+1)/settings.signupDispPos);
					if(resultType=="sponsored"){
						template = template.replace(/%colour_code%/g,"hSR");
						template = template.replace(/%cBox%/g,"highlight");
					}
					template = template.replace(/%cBox%/g,"cBox");
					for(var k in resultArr[i]){
						tempStr=tempArr=onclickVal=image_url="";
						tempStr=resultArr[i][k];
						switch(k){
							case "trans":
								tempStr=(String(tempStr).toLowerCase()=="sell") ? "Sale" : ip.ucfirst(tempStr);
								break;
							case "logo":
								template = template.replace(/%logoClass%/g,"imgBorder");
								break;
							case "disp_id":
								listingid = tempStr;
								listID=tempStr.substr(2);
								break;
							case "icon_list":
								tempArr = String(tempStr).split("|");
								tempStr="";
								for (var j=0; j<tempArr.length; j++){
									try{var ico_title=icons_disp_Arr[tempArr[j]];}catch(e){var ico_title=ip.toTitleCase(String(tempArr[j]).substr(6));}
									if(tempArr[j].toLowerCase()=="icons-map") onclickVal=' onclick="ip.OpenPopUp(\'index.php?option=listing&amp;page=viewmap&amp;listingid='+listID+'&amp;notemplate=yes\',100,100,570,530);"';
									tempStr+='<img src="'+ip.img_path+'trans.gif" class="'+tempArr[j]+'" alt="'+ico_title+'" title="'+ico_title+'" hspace="1" '+onclickVal+'/>';
								}
								break;
							case "phone":
								tempStr = 'Contact:&nbsp;<img src="'+ip.img_path+'icons/c2call.gif" alt="" align="absmiddle" hspace="2"> : '+tempStr+'&nbsp;';
								break;
							case "mobile":
								tempStr='<img src="'+ip.img_path+'icons/c2sms.gif" alt="" align="absmiddle" hspace="2"> : '+tempStr+'&nbsp';
								break;
							case "vcard":
								tempStr = (tempStr.toLowerCase()=="y") ? '<a href="javascript:void(0);" onmouseover="showVcard(\''+resultArr[i]["username"]+'\');" onmouseout="hideVcard(\''+resultArr[i]["username"]+'\');"><img src="'+ip.img_path+'icons/vcard.gif" alt=""></a>' : "";
								break;
							case "similarprop":
								tempArr = tempStr.split("|");
								tempStr=tempArr.toString();
								tempStr=tempStr.replace(/,/g,"','");
								tempStr='<a href="javascript:void(0);" onclick="similarproperties(\''+tempStr+'\');">View Similar Properties</a><br />';
								break;
							case "builder_name"://'Builder : '+
								tempStr=tempStr+'<br />';
								break;
							case "selling_price":
								tempStr='Price: '+tempStr;
								break;
							case "rent_price":
								tempStr='Price: '+tempStr;
								break;
							case "bedrooms":
								tempStr+='&nbsp;|';
								break;
							case "area":
								tempStr='Built up Area : '+tempStr+'<br />';
								break;
							case "plotarea":
								tempStr='Plot Area : '+tempStr+'<br />';
								break;
							case "noofunits":
								if(resultArr[i]["selling_price"]!="") tempStr="<br />";
								tempStr+='<img src="'+ip.img_path+'trans.gif" class="icons-above10floors" style="vertical-align: middle;" alt="" title="Mulitple Floors" /><a><strong>10 property units available</strong></a>&nbsp;&nbsp;';
								break;
							/*case "mid_image":
								tempStr = '<a href="http://www.indiaproperty.com/property/IP'+listID+'" target="_blank">'+
													'<img src="'+ip.img_path+''+tempStr+'" alt="" class="imgBorder" style="border: 1px solid rgb(204, 204, 204); padding: 1px;" id="photo_'+listID+'" width="75" height="75" />'+
												'</a><img src="'+ip.img_path+'icons/zoom.gif" alt="" style="cursor: pointer; width: 10px; height: 10px;" onclick="javascript:getZoom(\''+listID+'\',this);">';*/
							case "mid_image":
								tempStr = '<a href="'+resultArr[i]["url"]+'" target="_blank">'+
													'<img src="'+ip.img_path+''+tempStr+'" alt="" class="imgBorder" style="border: 1px solid rgb(204, 204, 204); padding: 1px;" id="photo_'+listID+'" width="75" height="75" />'+
												'</a><img src="'+ip.img_path+'icons/zoom.gif" alt="" style="cursor: pointer; width: 10px; height: 10px;" onclick="javascript:getZoom(\''+listID+'\',this);">';
								break;
							case "contact":
								try{
									tempArr = tempStr.split("|");
									var temp="";
									if(String((tempArr[0]).substr(1)).toUpperCase()=="Y"){
										temp='<li class="inactive"><a href="javascript:void(0);" onclick="javascript:showMailForm(\''+listingid +'\'); navigateTabs(1,\''+listingid +'\',\'basic\');">Click to Email</a></li>';
										template=template.replace(/%EMAIL%/g,temp);
									}

									if(String((tempArr[1]).substr(1)).toUpperCase()=="Y"){
										temp='<li class="inactive"><a href="javascript:void(0);" onclick="javascript:showSMSForm(\''+listingid +'\'); navigateTabs(3,\''+listingid +'\',\'basic\');">Click to SMS</a></li>';
										template=template.replace(/%SMS%/g,temp);
									}

									if(String((tempArr[2]).substr(1)).toUpperCase()=="Y"){
										temp='<li class="inactive"><a href="javascript:void(0);" onclick="javascript:showC2CForm(\''+listingid +'\',null,\'basic\'); navigateTabs(2,\''+listingid +'\',\'basic\');">Click to Call</a></li>';
										template=template.replace(/%C2C%/g,temp);
									}
									tempStr = '<a href="javascript:void(0);" class="button" style="font-size:14px;" onclick="contactForm(\''+listingid +'\');"><strong style="color:#fff;">Contact</strong></a>';
								}catch(e){}
								break;
						}
						var regex = new RegExp("%"+ k +"%", "g");
						template = template.replace(regex, tempStr);
					}
					/*replace all key with null if there is no value - i.e ( objects will not come if there is no value, in that case we replace with default value)*/
					for (var val in nullArr){
						nullArrValue=nullArr[val];
						switch(val){
							case "selling_price":
								if(String(resultArr[i]["trans"]).toLowerCase()=="rent") nullArrValue="";
								break;
							case "rent_price":
								if(String(resultArr[i]["trans"]).toLowerCase()=="rent") nullArrValue=nullArr["selling_price"];
								break;
						}
						var regex = new RegExp("%"+ val +"%", "g");
						template = template.replace(regex,nullArrValue);
					}
					template = template.replace(/%signup_alert%/g,signup_template);
					$results.append(template);
				}
			}
			self.displayResults();
		});
	}
})(jQuery);
/* End Search Results - Paging & Refine*/

/*Refine Results*/
(function($) {
	$.fn.refineResults = function(data,Options){
		if(!$.isArray(data.refine_results)){
			ip.print("its not an array");
			throw "showResults expects an array";
		}
		var settings = {
			total : 0,
			resultTarget: '',
			emptyMsg: 'No Results',
			callback: null,
			result : null,
			res_nav : null,
			template : "",
			cell_template : "",
			chkBox_template:"",
			cellStyleArr : ['background:none; width:21%;','width:19%;','width:13%;','width:20%;','width:21%; padding-right:0px;']
		};
		var defa_check=new Array();
		var tmp_ref_locality="";
		if($ip('ref_locality') && $ip('ref_locality').value!="")
		{
			tmp_ref_locality=$ip('ref_locality').value;
		}
		if($ip('ref_age') && $ip('ref_age').value!="")
		{
			tmp_ref_locality+="|"+$ip('ref_age').value;
		}
		if($ip('ref_bedrooms') && $ip('ref_bedrooms').value!="")
		{
			tmp_ref_locality+="|"+$ip('ref_bedrooms').value;
		}	
		if($ip('ref_area') && $ip('ref_area').value!="")
		{
			tmp_ref_locality+="|"+$ip('ref_area').value;
		}
		if($ip('ref_price') && $ip('ref_price').value!="")
		{
			tmp_ref_locality+="|"+$ip('ref_price').value;
		}

		if(tmp_ref_locality!="")
		{
			defa_check=tmp_ref_locality.split("|");
		}

		if(Options) $.extend(settings, Options);
		settings.total=settings.result.length;
		return this.each(function() {
			var self = this;
			if(settings.total == 0) {
				$(this).append(settings.emptyMsg);
				return;
			}
			var $results = $(settings.resultTarget);
			settings.template = $(self).find(".template").html();
			settings.cell_template = $(self).find("#div_refine_cells").html();
			settings.chkBox_template= $(self).find("#div_refine_chkBox").html();
			var tempStr="";
			var prefixCnt=String("refine_").length;
			self.displayResults = function() {
				$results.empty();
				var resultArr = settings.result;
				for (var i=0; i<resultArr.length; i++){
					var cnt=0;
					for(var k in resultArr[i]){
						var strRefineName=String(k.substr(prefixCnt));
						var temp = settings.cell_template;
						var tempChk="",tempArr;
						temp=temp.replace(/%refine_name%/g,k);
						temp=temp.replace(/%refine_title%/g, eval("refine_display_text." + k) );
						var tempArr = resultArr[i][k].split("|");
						/*[0] -> id, [1]->string, [2]->checked status */
						for (var j=0; j<tempArr.length; j++){
							var chk_temp = settings.chkBox_template;
							chk_temp=chk_temp.replace(/%prefix%/g, eval("object_name_array." + k));
							chk_temp=chk_temp.replace(/%func%/g, eval("refine_chk_onchange_func." + k));
							chk_temp=chk_temp.replace(/%val%/g,tempArr[j].split("~")[0]);
							chk_temp=chk_temp.replace(/%value%/g,tempArr[j].split("~")[1]);
							//alert(tempArr[j].split("~")[0]);alert($.inArray(tempArr[j].split("~")[0],ref_locality));
							if(tempArr[j].split("~")[2]=="1" || (defa_check.length>0 && $.inArray(tempArr[j].split("~")[0],defa_check)!=-1)){
								chk_temp=chk_temp.replace(/%checked_status%/g,'checked="checked"');
							}else{
								chk_temp=chk_temp.replace(/%checked_status%/g,'');
							}
							tempChk+=chk_temp;
						}
						temp=temp.replace(/%check_boxes%/g,tempChk);
						temp=temp.replace(/%url%/g,settings.res_nav + "&constraint="+strRefineName+"&page=refinefilterall");
						temp='<td style="'+settings.cellStyleArr[cnt]+'">'+temp+'</td>';
						tempStr+=temp;
						cnt++;
					}
				}
				tempStr='<form name="reallyadummyform" action="" method="post"><table style="width: 100%;" class="refineFilter" border="0" cellpadding="0" cellspacing="0"><tr>'+tempStr+'</tr></table></form>';
				settings.template=settings.template.replace(/%refine_url%/g,settings.res_nav + "&page=ajaxresultsjsn");
				settings.template=settings.template.replace(/%refine_results%/g,tempStr);
				$results.append(settings.template);

				if(typeof settings.callback == "function") {
					settings.callback();
				}
			}
			self.displayResults();
		});
	}
})(jQuery);
/* End Refine Results*/

/* Call Search Results func() */
function loadSearchResultsJSON(params){
	$("#searchResultsPanel").html(ip.loading("Loading Search Results ... Please wait..."));
	/*for (var i=0; i<temp_resultsArr.length; i++) {
		for (var k in temp_resultsArr[i]){
			if(k=="params"){
				ip.print("coming params = " + params);
				ip.print("temp_resultsArr[i][k] = " + temp_resultsArr[i][k] );
			}
		}
	}
	var bkpArr = {"params": params,"resultArr": null};*/
	params+= "&refer="+new Date().getTime();
	var url = ip.host() + "/index.php";
	$.ajax({
		url : url,
		type : 'POST',
		data : params,
		dataType : 'json',
		success : function(data){
			/*bkpArr.resultArr = data;
			temp_resultsArr.push(bkpArr);*/
			$("#divSearchResultsContainer").showResults(data.quick_results, {
				callback : function(){showSigUpAlert(1,1);},
				resultTarget: '#searchResultsPanel',
				pagesTarget: '.pagination',
				result : (data.quick_results==null)?[]:data.quick_results,
				signupDispPos : 5,
				limit : (data.recperpage) ? data.recperpage : 20,
				headerArr : {
					res_nav : data.res_nav,
					total_results : (data.total_results==null) ? 0 : data.total_results,
					searched_for : data.searched_for,
					rec_page_options: (data.rec_page_options) ? data.rec_page_options : "",
					sort_by:data.sort_by,
					pagination:data.pagination,
					projects_interested:(data.projects_interested==null) ? "" : data.projects_interested
				},
				highlight_results : (data.highlight_results==null) ? [] : data.highlight_results,
				offset:data.offset,
				recperpage : data.recperpage
			});
		},
		error : function(xhr,msg,e){
			ip.print(msg);
			$("#searchResultsPanel").html(ip.err.timeOut);
		}
	});
};
/* Call Refine Results func() */
function loadRefineResults(params){
	params+="&refer="+new Date().getTime();
	var url = ip.host() + "/index.php";
	if(glbRefineParams==null) glbRefineParams=params;
	$ip("div_refine_filters").innerHTML = '<div style="padding:10px;">'+ip.loading("Loading Refine Results... Please wait...") + '</div>';
	$.ajax({
		url : url,
		type : 'POST',
		data : params,
		dataType : 'json',
		success : function(data){
			refine_display_text  = data.display_text;
			object_name_array = data.object_name_array;
			refine_chk_onchange_func = data.refine_chk_onchange_func;
			$("#divRefineContainer").refineResults(data,{
				resultTarget: '#div_refine_filters',
				result : data.refine_results,
				res_nav : data.res_nav
			});
		},
		error : function(xhr,msg,e){
			ip.print(msg);
			$("#div_refine_filters").html(ip.err.timeOut);
		}
	});
}
/*A Null Array Values , for Search Results , it applies these  values when the output array doent contain any value */
var nullArr={
	similarprop:"",
	mobile:"",
	logo:"trans.gif",
	builder_name:"",
	colour_code:"SR",
	contact:"EY|SY|CN",
	noofunits:"",
	area:"",
	plotarea:"",
	phone:"Contact:&nbsp;",
	bedrooms:"",
	icon_list:"",
	vcard:"",
	logoClass : "",
	selling_price:"Price: Contact for price details",
	rent_price:"",
	mid_image : '<img src="'+ip.img_path+'trans.gif" alt="" style="padding: 1px;" width="75" height="75" />',
	SMS:'<li class="inactive" style="display:none;"><a href="javascript:void(0);" onclick="javascript:showSMSForm(\'\',null,\'basic\'); navigateTabs(3,\'\',\'\');">Click to SMS</a></li>',
	C2C:'<li class="inactive" style="display:none;"><a href="javascript:void(0);" onclick="javascript:showC2CForm(\'\',null,\'basic\'); navigateTabs(2,\'\',\'\');">Click to Call</a></li>'
};
function showRefineViewAll(params){
	/*
		def_chk_locality
		def_chk_age
		def_chk_bedroom
		def_chk_price
		def_chk_area
	*/
	var ipCookie = new ip_cookie();
	if(!pageLoaded || lb==null) return ip.throwErr(null,"Please wait while page loads.",2);
	if($ip('ref_locality') && $ip('ref_locality').value!="") params+="&def_chk_locality="+$ip('ref_locality').value;
	if($ip('ref_age') && $ip('ref_age').value!="") params+="&def_chk_age="+$ip('ref_age').value;
	if($ip('ref_bedrooms') && $ip('ref_bedrooms').value!="") params+="&def_chk_bedroom="+$ip('ref_bedrooms').value;
	if($ip('ref_area') && $ip('ref_area').value!="") params+="&def_chk_area="+$ip('ref_area').value;
	if($ip('ref_price') && $ip('ref_price').value!="") params+="&def_chk_price="+$ip('ref_price').value;
	/*Find Constraint Value*/
	var constraintStartFrom = params.indexOf("constraint=");
	var lastInd = (params.substr(constraintStartFrom+11)).indexOf("&");
	var constraint = (lastInd!=-1) ? params.substr(constraintStartFrom+11,lastInd) : params.substr(constraintStartFrom+11);
	ipCookie.setCookie("constraint",constraint,"","","","/");
	/* End find Constraint*/
	var Obj = $ip("div_refine_filters_all");
	/*var conditionObjs = [d.quicksearch.property || $ip("property") || null,d.quicksearch.city || $ip("city") || null];*/
	/*var have2Hide = [$ip("results_rhs_iframe"),$ip("results_rhs_city")];*/
	with(Obj.style){
		display ="";
		position = "absolute";
		display = "block";
		left = (ip.mouseX-270) + "px";
		top= (ip.mouseY - 20) + "px";
		zIndex = "100001";
		/*width = "300px";*/
	}
	/*Obj.onclick = function(){lb.exit();this.style.display="none";this.innerHTML ="";}*/
	Obj.innerHTML = ip.loadingLB("Loading Refine Filters... Please wait...",280);
	lb.init();
	/*if($.inArray(params,bkp_refine_result_url)){
		//bkp_refine_result_url
	}else{
		bkp_refine_result_url.push(params);
	}*/
	/*for (var i=0; i<temp_refine_resultsArr.length; i++) {
		for (var k in temp_refine_resultsArr[i]){
			if(k=="params"){
				ip.print("coming params = " + params);
				ip.print("temp_refine_resultsArr[i][k] = " + temp_refine_resultsArr[i][k] );
			}
		}
	}*/
	var bkpArr = {"params": params,"resultArr": null};
	params+="&refer="+new Date().getTime();
	var url = ip.host() + "/index.php";
	$.ajax({
		url : url,
		type : 'POST',
		data : params,
		dataType : 'json',
		success : function(data){
			/*bkpArr.resultArr = data;
			temp_refine_resultsArr.push(bkpArr);*/
			var refine_title = "refine_"+constraint;
			var result = eval("data.refine_results."+refine_title);
			var $results = $("#div_refine_filters_all");
			//bkp_refine_result_result.push(result);
			if(!$.isArray(result)){
				ip.print("its not an array");
				closeLocalityDiv();
				/*var res = ((data.toLowerCase()).indexOf("error")!="-1" || "") ? '<span style="color:rgb(255,100,100); padding:6px 10px;">Sorry! There was a problem.</span>' : data;
				if(res==""){
					Obj.onclick= function(){lb.exit();this.style.display="none";this.innerHTML ="";};
					res = ip.lbAlert("Unable to access this service currently or Request has been terminated by user.","400",null,Obj.getAttribute('onclick'));
				}*/
			}else{
				var template = $("#div_more_refine_block").html();
				var chkBoxTemplate=$("#div_chkbox_template").html();
				var localityTemplate=$("#div_more_locality_template").html();
				var chkTemplate= $("#div_refine_chkBox").html();

				for (var i=0; i<result.length; i++){
					var temp=template;
					var tempChkBoxTemp = chkBoxTemplate;
					var tempArr= result[i].split("|");
					var tempChk='<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>';
					for (var j=0; j<tempArr.length; j++){
						var chk_temp = chkTemplate;
						chk_temp=chk_temp.replace(/%prefix%/g, eval("object_name_array." + refine_title));
						chk_temp=chk_temp.replace(/%val%/g,tempArr[j].split("~")[0]);
						chk_temp=chk_temp.replace(/%value%/g,tempArr[j].split("~")[1]);
						if(tempArr[j].split("~")[2]=="1"){
							chk_temp=chk_temp.replace(/%checked_status%/g,'checked="checked"');
						}else{
							chk_temp=chk_temp.replace(/%checked_status%/g,'');
						}
						chk_temp=chk_temp.replace(/%func%/g, eval("refine_chk_onchange_func." + refine_title));
						if(j%2==0) tempChk+='</tr><tr>';
						tempChk+='<td>'+chk_temp+'</td>';
					}
					tempChk+='</tr></table>';

					if(constraint.toLowerCase()=="locality"){
						/* Note: Locality Template should not maintain in results page, cause the Scroll DOWN effect wont work if we moved this template to seperate...*/
						var prefixStr = '<table cellspacing="0" border="0" cellpadding="0" style="width:100%;" id="localityScrollList">'+
													'<tr><td style="padding:0px;"><div id="Div_LocalityMore" style="line-height:16px;"><div id="wn"><div id="lyr1" class="content">';
						var suffixStr = '</div></div></div></td>'+
											'<td id="scrollLinks" width="12">'+
												'<div id="scrollbar">'+
													'<div id="up"><a href="javascript:void(0);" onclick="return false" onmouseover="dw_scrollObj.initScroll(\'wn\',\'up\')" onmouseout="dw_scrollObj.stopScroll(\'wn\')" onmousedown="dw_scrollObj.doubleSpeed(\'wn\')" onmouseup="dw_scrollObj.resetSpeed(\'wn\')"><img src="'+ip.img_path+'icons/scroll_up.gif" alt="" /></a></div>'+
													'<div id="track">'+
														'<div id="dragBar"></div>'+
													'</div>'+
													'<div id="down"><a href="javascript:;" onclick="return false" onmouseover="dw_scrollObj.initScroll(\'wn\',\'down\')" onmouseout="dw_scrollObj.stopScroll(\'wn\')" onmousedown="dw_scrollObj.doubleSpeed(\'wn\')" onmouseup="dw_scrollObj.resetSpeed(\'wn\')"><img src="'+ip.img_path+'icons/scroll_down.gif" alt="" /></a></div>'+
												'</div></td></tr></table>';
						temp=temp.replace(/%refine_chkbox_template%/g,prefixStr+tempChkBoxTemp+suffixStr);
					}else{
						temp=temp.replace(/%refine_chkbox_template%/g,tempChkBoxTemp);
					}
					temp=temp.replace(/%check_boxes%/g,tempChk);
					temp=temp.replace(/%frm_name%/g,"frm_refine_"+refine_title);
					temp=temp.replace(/%refine_name%/g,refine_title);

					temp=temp.replace(/%refine_title%/g,eval("refine_display_text." + refine_title));
				}
				$results.html(temp);
				if(constraint.toLowerCase()=="locality"){
					initScrollLayer();
					$results.click(function(){});
				}
			}
		},
		error : function(xhr,msg,e){
			ip.print(msg);
			$("#div_refine_filters").html(ip.err.timeOut);
		}
	});
}
function onChangeRefineBoxes(val,obj){}