var SEARCH_CORE = $H();
//SYSTEM SESSION VARS
SEARCH_CORE.CONTROLLER_CALL_URL    	   		    = "/?page=api_speed_rental&content=main&params=";
SEARCH_CORE.HTML_Elements     					= $H();
SEARCH_CORE.DATA               					= $H();
SEARCH_CORE.MEM_STATE    	    				= $H();
SEARCH_CORE.TMP                					= $H();
SEARCH_CORE.STYLE    	   						= $H();
SEARCH_CORE.STYLE.Selects      					= $H();
SEARCH_CORE.CONST                               = $H();
SEARCH_CORE.RELOAD                              = $H();
SEARCH_CORE.RELOAD.DATA 					    = $A();
//CONSTANTS
//STYLES
SEARCH_CORE.STYLE.Selects.Headings_BG_Color    	= "#C00";
SEARCH_CORE.STYLE.Selects.Headings_Font_Color  	= "#ffffff";

//FILTER
SEARCH_CORE.MEM_STATE.search_Suburb_filter          = $H();
SEARCH_CORE.MEM_STATE.search_Suburb_filter.TimerID  = 0;
SEARCH_CORE.MEM_STATE.search_Suburb_filter.Value    = "";

SEARCH_CORE.CONST.Price_Ranges 					    = $H();
SEARCH_CORE.CONST.Price_Ranges.Sale 				= $H();

SEARCH_CORE.CONST.Price_Ranges.Sale[0]    			= 2000000;
SEARCH_CORE.CONST.Price_Ranges.Sale[1]    			= 4000000;
SEARCH_CORE.CONST.Price_Ranges.Sale[2]    			= 6000000;
SEARCH_CORE.CONST.Price_Ranges.Sale[3]    			= 8000000;
//SEARCH_CORE.CONST.Price_Ranges.Sale[0]    			= 250000;
//SEARCH_CORE.CONST.Price_Ranges.Sale[1]    			= 500000;
//SEARCH_CORE.CONST.Price_Ranges.Sale[2]    			= 750000;
//SEARCH_CORE.CONST.Price_Ranges.Sale[3]    			= 1000000;
//SEARCH_CORE.CONST.Price_Ranges.Sale[4]    			= 1500000;
//SEARCH_CORE.CONST.Price_Ranges.Sale[5]    			= 2000000;
//SEARCH_CORE.CONST.Price_Ranges.Sale[6]    			= 3000000;
//SEARCH_CORE.CONST.Price_Ranges.Sale[7]    			= 4000000;
//SEARCH_CORE.CONST.Price_Ranges.Sale[8]    			= 5000000;
//SEARCH_CORE.CONST.Price_Ranges.Sale[9]    			= 6000000;
//SEARCH_CORE.CONST.Price_Ranges.Sale[10]  			= 7000000;
//SEARCH_CORE.CONST.Price_Ranges.Sale[11]   			= 9000000;
//SEARCH_CORE.CONST.Price_Ranges.Sale[12]   			= 10000000;


SEARCH_CORE.CONST.Price_Ranges.Rental 	   			= $H();

SEARCH_CORE.CONST.Price_Ranges.Rental[0]  			= 1000;
SEARCH_CORE.CONST.Price_Ranges.Rental[1]  			= 2000;
SEARCH_CORE.CONST.Price_Ranges.Rental[2]  			= 3000;
SEARCH_CORE.CONST.Price_Ranges.Rental[3]  			= 4000;
SEARCH_CORE.CONST.Price_Ranges.Rental[4]  			= 5000;
SEARCH_CORE.CONST.Price_Ranges.Rental[5]  			= 6000;
SEARCH_CORE.CONST.Price_Ranges.Rental[6]  			= 7000;
SEARCH_CORE.CONST.Price_Ranges.Rental[7]  			= 8000;
SEARCH_CORE.CONST.Price_Ranges.Rental[8]  			= 9000;
SEARCH_CORE.CONST.Price_Ranges.Rental[9]  			= 10000;

SEARCH_CORE.RELOAD.STATE            		        = false;


function RepopulateCurrentRegion ()
{
	var oOption = $("search_Province_select").options[$("search_Province_select").selectedIndex];
	
	_search_Province_Handler(oOption.text, oOption.value);
	
}

function property_search_init(OfficeIDs,ProvinceID,ProvinceName,UserIDs,GET)
{
	try
	{
		_init_Search_HTML_Elements();
		_init_Search_Observers();
		
		_get_Property_Types();
		_get_Property_PaymentTypes();
		
		if(ProvinceID > 0)
		{
			if(OfficeIDs)
			{
				SEARCH_CORE.DATA.OfficesIDs =  unserialize(OfficeIDs).join(",");
			}
			if(UserIDs)
			{
				SEARCH_CORE.DATA.UserIDs =  unserialize(UserIDs).join(",");
			}
			
			
			
			if(RESULTS_CORE_In_Data)
			{
			 		
				//_console("reloading");
				SEARCH_CORE.RELOAD.STATE            		= true;
				SEARCH_CORE.RELOAD.TMP  					= unserialize(RESULTS_CORE_In_Data);
						 
				SEARCH_CORE.RELOAD.DATA['Province'] 		= SEARCH_CORE.RELOAD.TMP['Province'].split(',');
	
				SEARCH_CORE.RELOAD.DATA['Regions']  		= SEARCH_CORE.RELOAD.TMP['Regions'].split(',');
				SEARCH_CORE.RELOAD.DATA['Suburbs']  		= SEARCH_CORE.RELOAD.TMP['Suburbs'].split(',');
				SEARCH_CORE.RELOAD.DATA['Types']    		= SEARCH_CORE.RELOAD.TMP['Types'].split(',');
				SEARCH_CORE.RELOAD.DATA['Suburbs']  		= SEARCH_CORE.RELOAD.TMP['Suburbs'].split(',');
				SEARCH_CORE.RELOAD.DATA['SuburbFilter']  	= SEARCH_CORE.RELOAD.TMP['SuburbFilter'].replace("_"," ");
				SEARCH_CORE.RELOAD.DATA['Payment']  	    = SEARCH_CORE.RELOAD.TMP['Payment'];
				if(SEARCH_CORE.RELOAD.TMP['Rental_MIN'])
				{
					SEARCH_CORE.RELOAD.DATA['Rental_MIN']  	    = SEARCH_CORE.RELOAD.TMP['Rental_MIN'];
				}
				if(SEARCH_CORE.RELOAD.TMP['Rental_MAX'])
				{
					SEARCH_CORE.RELOAD.DATA['Rental_MAX']  	    = SEARCH_CORE.RELOAD.TMP['Rental_MAX'];
				}
				if(SEARCH_CORE.RELOAD.TMP['Sale_MIN'])
				{
					SEARCH_CORE.RELOAD.DATA['Sale_MIN']  	    = SEARCH_CORE.RELOAD.TMP['Sale_MIN'];
				}
				if(SEARCH_CORE.RELOAD.TMP['Sale_MAX'])
				{
					SEARCH_CORE.RELOAD.DATA['Sale_MAX']  	    = SEARCH_CORE.RELOAD.TMP['Sale_MAX'];
				}
				SEARCH_CORE.RELOAD.TMP 						= $H();
				_repopulate_Search();
			
						
			}
			else
			{
	
				//_console("console new search");
				setTimeout(RepopulateCurrentRegion, 100);
			}
		}
		else
		{
			SEARCH_CORE.HTML_Elements.search_Location_select.options[0] = new Option("-- Select a province --", '0');
		}
	}
	catch(e)
	{
		_error_message("file : "+e.fileName+" <br >on line :"+e.lineNumber+"<br>"+e.message);
	}
}
function _repopulate_Search()
{
	SEARCH_CORE.HTML_Elements.search_Province_select.disabled   = true;
	
	_search_ProvinceMap_Handler(SEARCH_CORE.RELOAD.DATA['Province'][0]);
}
function _init_Search_HTML_Elements()
{
	try
	{
		SEARCH_CORE.HTML_Elements.search_Province_select_div	 		= $('search_Province_select_div');
		SEARCH_CORE.HTML_Elements.search_Province_select	 		    = $('search_Province_select');
		//SEARCH_CORE.HTML_Elements.search_Province_select.selectedIndex  = 3;
		
		SEARCH_CORE.HTML_Elements.search_Suburb_filter   	  			= $('search_Region_Suburb_filter');
		SEARCH_CORE.HTML_Elements.search_Suburb_filter.value 			= "Suburb Filter";
		
		SEARCH_CORE.HTML_Elements.search_Region_Suburb_select_div 	  	= $('search_Region_Suburb_select_div');
		SEARCH_CORE.HTML_Elements.search_Location_select 	  			= $('search_Region_Suburb_select');
		$('search_Region_Suburb_select').style.maxWidth = $('search_Region_Suburb_select').offsetWidth + 'px';
		
		SEARCH_CORE.HTML_Elements.search_Property_Type_select_div       = $('search_Property_Type_select_div');
		SEARCH_CORE.HTML_Elements.search_Type_select     	  			= $('search_Property_Type_select');
		SEARCH_CORE.HTML_Elements.search_Type_select.hideFocus 			= true;
				
		SEARCH_CORE.HTML_Elements.search_PaymentType_select			    = $('search_PaymentType_select');;
		SEARCH_CORE.HTML_Elements.search_PaymentType_select_div		    = $('search_PaymentType_select_div');;
		
		SEARCH_CORE.HTML_Elements.search_Sale_price_options_div         = $('search_Sale_price_options_div');
		SEARCH_CORE.HTML_Elements.search_Sale_Count_lable          	    = $('search_Sale_Count');
		SEARCH_CORE.HTML_Elements.search_Sale_Min_Price_select        	= $('search_Sale_Min_Price_select');
		SEARCH_CORE.HTML_Elements.search_Sale_Max_Price_select          = $('search_Sale_Max_Price_select');
		
		SEARCH_CORE.HTML_Elements.search_Rental_price_options_div       = $('search_Rental_price_options_div');
		SEARCH_CORE.HTML_Elements.search_Rental_Count_label          	= $('search_Rental_Count');
		SEARCH_CORE.HTML_Elements.search_Rental_Min_Price_select        = $('search_Rental_Min_Price_select');
		SEARCH_CORE.HTML_Elements.search_Rental_Max_Price_select        = $('search_Rental_Max_Price_select');
	
		SEARCH_CORE.HTML_Elements.search_Submit_button          		= $('search_Submit_button');
	}
	catch(e)
	{
		_error_message("file : "+e.fileName+" <br >on line :"+e.lineNumber+"<br>"+e.message);
	}
}

function _init_Search_Observers()
{
	try
	{
		Event.observe(SEARCH_CORE.HTML_Elements.search_Province_select, 	   'change',  _search_Province_Handler, false);
		Event.observe(SEARCH_CORE.HTML_Elements.search_Location_select, 	   'change',  _populate_Type_List, false);
		Event.observe(SEARCH_CORE.HTML_Elements.search_Type_select, 	 	   'change',  _search_Payment_Handler,     false);
		Event.observe(SEARCH_CORE.HTML_Elements.search_Submit_button, 	  	   'click',   _search_Submit_Handler,   false);
		Event.observe(SEARCH_CORE.HTML_Elements.search_Suburb_filter,   	   'focus',   _search_Filter_Handler,   false);
		Event.observe(SEARCH_CORE.HTML_Elements.search_Suburb_filter,   	   'keyup',   _search_Filter_Handler,   false);
		Event.observe(SEARCH_CORE.HTML_Elements.search_Sale_Min_Price_select,  'change',  _search_Sale_Price_Handler,   false);
		Event.observe(SEARCH_CORE.HTML_Elements.search_Sale_Max_Price_select,  'change',  _search_Sale_Price_Handler,   false);
		Event.observe(SEARCH_CORE.HTML_Elements.search_PaymentType_select,     'change',  _search_PaymentType_Handler,   false);
	}
	catch(e)
	{
		_error_message("file : "+e.fileName+" <br >on line :"+e.lineNumber+"<br>"+e.message);
	}
}
function _search_ProvinceMap_Handler(provinceID,provinceName)
{
	try
	{
		if(provinceID)
		{
			SEARCH_CORE.HTML_Elements.search_Province_select.selectedIndex 				     = "-1";
			for(i =0;i<=(SEARCH_CORE.HTML_Elements.search_Province_select.options.length-1);i++)
			{
				switch(true)
				{
					case(SEARCH_CORE.HTML_Elements.search_Province_select.options[i].value == provinceID):
						
						switch(true)
						{
							case(SEARCH_CORE.HTML_Elements.search_Province_select.selectedIndex !=SEARCH_CORE.HTML_Elements.search_Province_select.options[i].index):
								SEARCH_CORE.HTML_Elements.search_Province_select.selectedIndex  = SEARCH_CORE.HTML_Elements.search_Province_select.options[i].index;
								_search_Province_Handler();
							break;
						}
					return;
				}
			}
			SEARCH_CORE.HTML_Elements.search_Province_select.options[SEARCH_CORE.HTML_Elements.search_Province_select.options.length]          = new Option(provinceName,provinceID);
			SEARCH_CORE.HTML_Elements.search_Province_select.options[SEARCH_CORE.HTML_Elements.search_Province_select.options.length-1].selected = true;
			_search_Province_Handler();
			//setTimeout("_search_Province_Handler();",50);
		}
	}
	catch(e)
	{
		_error_message("file : "+e.fileName+" <br >on line :"+e.lineNumber+"<br>"+e.message);
	}
}

function _search_Filter_Handler()
{
	try
	{
		if(!SEARCH_CORE.MEM_STATE.search_Suburb_filter.Activated)
		{
			SEARCH_CORE.MEM_STATE.search_Suburb_filter.Activated 	= true;
			SEARCH_CORE.HTML_Elements.search_Suburb_filter.value 	= "";
			return;
		}
		if(SEARCH_CORE.MEM_STATE.search_Suburb_filter.TimerID!=0){clearTimeout(SEARCH_CORE.MEM_STATE.search_Suburb_filter.TimerID);}
		switch(true)
		{
			case(trim(SEARCH_CORE.HTML_Elements.search_Suburb_filter.value)!="" && trim(SEARCH_CORE.HTML_Elements.search_Suburb_filter.value).toUpperCase()!=SEARCH_CORE.MEM_STATE.search_Suburb_filter.Value):
				SEARCH_CORE.MEM_STATE.search_Suburb_filter.TimerID = setTimeout('_search_Filter()', 750);
			break;
			case(SEARCH_CORE.MEM_STATE.search_Suburb_filter.Activated && trim(SEARCH_CORE.HTML_Elements.search_Suburb_filter.value) == "" && SEARCH_CORE.MEM_STATE.search_Suburb_filter.Value !=""):
				SEARCH_CORE.MEM_STATE.search_Suburb_filter.Value 	= "";	
				_populate_Region_Suburb_List();
			break;
		}
	}
	catch(e)
	{
		_error_message("file : "+e.fileName+" <br >on line :"+e.lineNumber+"<br>"+e.message);
	}
}
function _search_Filter()
{
	try
	{
		clearTimeout(SEARCH_CORE.MEM_STATE.search_Suburb_filter.TimerID);
		SEARCH_CORE.MEM_STATE.search_Suburb_filter.Value = trim(SEARCH_CORE.HTML_Elements.search_Suburb_filter.value).toUpperCase();
		_populate_Region_Suburb_List();
	}
	catch(e)
	{
		_error_message("file : "+e.fileName+" <br >on line :"+e.lineNumber+"<br>"+e.message);
	}
}

function _search_Province_Handler()
{
	try
	{
		
		SEARCH_CORE.DATA.ProvinceID = get_Selected_Options(SEARCH_CORE.HTML_Elements.search_Province_select,true);
		if(SEARCH_CORE.DATA.ProvinceID > 0)
		{
			SEARCH_CORE.HTML_Elements.search_Province_select.disabled		  = true;
			SEARCH_CORE.HTML_Elements.search_Suburb_filter.disabled           = true;
			SEARCH_CORE.HTML_Elements.search_Suburb_filter.value 			  = "Suburb/region name";
                        SEARCH_CORE.HTML_Elements.search_Suburb_filter.style.color = "#777";
                        
			SEARCH_CORE.MEM_STATE.search_Suburb_filter.Value 				  = "";
                        
			SEARCH_CORE.HTML_Elements.search_Location_select.disabled         = true; 
			SEARCH_CORE.HTML_Elements.search_PaymentType_select.disabled      = true;
			SEARCH_CORE.MEM_STATE.search_Suburb_filter.Activated              = false;
			SEARCH_CORE.HTML_Elements.search_Type_select.disabled             = true; 
			SEARCH_CORE.HTML_Elements.search_Sale_Min_Price_select.disabled   = true;
			SEARCH_CORE.HTML_Elements.search_Sale_Max_Price_select.disabled   = true;
			SEARCH_CORE.HTML_Elements.search_Rental_Min_Price_select.disabled = true;
			SEARCH_CORE.HTML_Elements.search_Rental_Max_Price_select.disabled = true;
			SEARCH_CORE.HTML_Elements.search_Location_select.style.textAlign = "left";
                        
		
			_search_loading_layer(SEARCH_CORE.HTML_Elements.search_Region_Suburb_select_div,SEARCH_CORE.HTML_Elements.search_Location_select,true);
			_search_loading_layer(SEARCH_CORE.HTML_Elements.search_Property_Type_select_div,SEARCH_CORE.HTML_Elements.search_Type_select,true);		
			
			_get_Province_Properties(SEARCH_CORE.DATA.ProvinceID);
		}

	}
	catch(e)
	{
		_error_message("file : "+e.fileName+" <br >on line :"+e.lineNumber+"<br>"+e.message);
	}
}
function _search_Type_Handler(e)
{
	switch(e.currentTarget.options[e.currentTarget.selectedIndex].value)
	{
	
	}
}
function _search_PaymentType_Handler()
{
	$H(get_Selected_Options(SEARCH_CORE.HTML_Elements.search_PaymentType_select)).each(function(payment)
	{
		switch(payment.value)
		{
			case("1"):
				SEARCH_CORE.HTML_Elements.search_Sale_Min_Price_select.disabled   = true;
				SEARCH_CORE.HTML_Elements.search_Sale_Max_Price_select.disabled   = true;
				SEARCH_CORE.HTML_Elements.search_Rental_Min_Price_select.disabled = false;
				SEARCH_CORE.HTML_Elements.search_Rental_Max_Price_select.disabled = false;
			break;
			case("2"):
				SEARCH_CORE.HTML_Elements.search_Sale_Min_Price_select.disabled   = false;
				SEARCH_CORE.HTML_Elements.search_Sale_Max_Price_select.disabled   = false;
				SEARCH_CORE.HTML_Elements.search_Rental_Min_Price_select.disabled = true;
				SEARCH_CORE.HTML_Elements.search_Rental_Max_Price_select.disabled = true;
			break;
			case("3"):
				SEARCH_CORE.HTML_Elements.search_Sale_Min_Price_select.disabled   = true;
				SEARCH_CORE.HTML_Elements.search_Sale_Max_Price_select.disabled   = true;
				SEARCH_CORE.HTML_Elements.search_Rental_Min_Price_select.disabled = true;
				SEARCH_CORE.HTML_Elements.search_Rental_Max_Price_select.disabled = true;
			break;
		}
	});
}
function _search_Sale_Price_Handler()
{
	
}
function _get_Province_Properties(province_array)
{
	//FETCH ALL PROPERTIES FROM PROPERTY SERACH TABLE WITH SELECTED PROVINCE IDS
	try
	{
		var data = $A();
		data['property_search_options'] = $A();
		data['property_search_options']['officeIDs']       = SEARCH_CORE.DATA.OfficesIDs;
		data['property_search_options']['userIDs']         = SEARCH_CORE.DATA.UserIDs;
		data['property_search_options']['provinceIDs']     = province_array.join(",");
	
		CtrlCall(SEARCH_CORE.CONTROLLER_CALL_URL+"feed:property_search_options;filter:property_search_options;","data="+serialize(data),"_load_Province_Properties");
	}
	catch(e)
	{
		_error_message("file : "+e.fileName+" <br >on line :"+e.lineNumber+"<br>"+e.message);
	}
}
function _get_Property_Types()
{
	//FETCH ALL PROPERTY TYPES
	//CtrlCall(SEARCH_CORE.CONTROLLER_CALL_URL+"feed=function:_get_Property_Types;lang:js",'data=null',"_load_Search_Types");
	CtrlCall(SEARCH_CORE.CONTROLLER_CALL_URL+"feed:types;","","_load_Search_Types");
}
function _get_Property_PaymentTypes()
{
	//FETCH ALL PROPERTY PAYMENT TYPES
	CtrlCall(SEARCH_CORE.CONTROLLER_CALL_URL+"feed:payment_types;","data=null","_load_Payment_Types");
}
function _search_loading_layer(containerDiv,Element,show)
{
		eval("if(!SEARCH_CORE.HTML_Elements."+containerDiv.id+"_loader){SEARCH_CORE.HTML_Elements."+containerDiv.id+"_loader = document.createElement('div');}");
		eval("containerDiv.appendChild(SEARCH_CORE.HTML_Elements."+containerDiv.id+"_loader);");
		switch(show)
		{
			case true:
				Element.style.display = "none";
				eval("SEARCH_CORE.HTML_Elements."+containerDiv.id+"_loader.style.backgroundColor                                     = '#f1f1f1';");
				eval("SEARCH_CORE.HTML_Elements."+containerDiv.id+"_loader.style.top      		                                     = Element.style.top;");
				eval("SEARCH_CORE.HTML_Elements."+containerDiv.id+"_loader.style.left      		                                     = Element.style.left;");
				eval("SEARCH_CORE.HTML_Elements."+containerDiv.id+"_loader.style.width      		                                 = Element.style.width;");
				eval("SEARCH_CORE.HTML_Elements."+containerDiv.id+"_loader.style.height      		                                 = Element.style.height;");
				eval("SEARCH_CORE.HTML_Elements."+containerDiv.id+"_loader.style.zIndex   		 									 = '999';");
				eval("SEARCH_CORE.HTML_Elements."+containerDiv.id+"_loader.innerHTML             								     = \"<table cellpadding='0' cellspacing=0' style='width:\"+SEARCH_CORE.HTML_Elements."+containerDiv.id+"_loader.style.width+\";height:\"+SEARCH_CORE.HTML_Elements."+containerDiv.id+"_loader.style.height+\";'><tr><td style='width:\"+SEARCH_CORE.HTML_Elements."+containerDiv.id+"_loader.style.width+\";height:\"+SEARCH_CORE.HTML_Elements."+containerDiv.id+"_loader.style.height+\"; vertical-align: middle' align='center' valign='middle'><img src ='"+MUFFIN_SHARED_URL+"/images/property_search/remaxloading.gif' align='middle'></td></tr></table>\";");
				eval("SEARCH_CORE.HTML_Elements."+containerDiv.id+"_loader.style.display = 'block';");
			break;
			default:
				Element.style.display = "block";
				
				eval("SEARCH_CORE.HTML_Elements."+containerDiv.id+"_loader.style.display = 'none';");			
			break;
		}
		
}
function _load_Payment_Types(response)
{
	try
	{
		SEARCH_CORE.DATA.PaymentTypes 		  																= $H();
		SEARCH_CORE.TMP._type_reponseSet     																= $M(response);
		SEARCH_CORE.TMP._type_inc 																		    = 0;
		switch(true)
		{
			case(SEARCH_CORE.TMP._type_reponseSet!=null):
				$H(SEARCH_CORE.TMP._type_reponseSet.PaymentTypes.PaymentType).each(function(type)
				{
					SEARCH_CORE.DATA.PaymentTypes[type.value.PaymentID] 	             						= $H();
					SEARCH_CORE.DATA.PaymentTypes[type.value.PaymentID].Name          							= type.value.MethodDescription;
					SEARCH_CORE.DATA.PaymentTypes[type.value.PaymentID].PropertyCount 							= 0;
					SEARCH_CORE.HTML_Elements.search_PaymentType_select.options[SEARCH_CORE.TMP._type_inc]  = new Option(type.value.MethodDescription,type.value.PaymentID);
					SEARCH_CORE.TMP._type_inc++;
				});
			break;
			default:
				_error_message("No Payment Types found");
			break;
		}
		SEARCH_CORE.TMP = $H();
	}
	catch(e)
	{
		_error_message("file : "+e.fileName+" <br >on line :"+e.lineNumber+"<br>"+e.message);
	}
}
function _load_Search_Types(response)
{
	try
	{
		SEARCH_CORE.DATA.Types 		  																	    = $H();
		SEARCH_CORE.TMP._type_reponseSet 																	= $M(response);
		SEARCH_CORE.TMP.optioncount      																	= 0;
		switch(true)
		{
			case(SEARCH_CORE.TMP._type_reponseSet!=null):
				//SEARCH_CORE.TMP._type_reponseSet.Types.Types[0].Type.each(function(type)
				$H(SEARCH_CORE.TMP._type_reponseSet.Types.Type).each(function(type)
				{
					SEARCH_CORE.DATA.Types[type.value.PropTypeID] 	           									= $H();
					SEARCH_CORE.DATA.Types[type.value.PropTypeID].Name          								    = type.value.TypeName;
					SEARCH_CORE.DATA.Types[type.value.PropTypeID].PropertyCount 							        = 0;
				});
			break;
			default:
				_error_message("No Property Types found");
			break;
		}
		SEARCH_CORE.TMP 																					= $H();
		_populate_default_PropertyTypes_list();
	}
	catch(e)
	{
		_error_message("file : "+e.fileName+" <br >on line :"+e.lineNumber+"<br>"+e.message);
	}
}
function _populate_default_PropertyTypes_list()
{
	try
	{
		SEARCH_CORE.TMP.optioncount      																	    = 0;
		//ASSIGN OPTIONS
		SEARCH_CORE.DATA.Types.each(function(type)
		{
			SEARCH_CORE.HTML_Elements.search_Type_select.options[SEARCH_CORE.TMP.optioncount]                   = new Option(type.value.Name,type.key);
			SEARCH_CORE.HTML_Elements.search_Type_select.options[SEARCH_CORE.TMP.optioncount].disabled          = "true";
			SEARCH_CORE.HTML_Elements.search_Type_select.options[SEARCH_CORE.TMP.optioncount].style.color       = "#c1c1c1";
			SEARCH_CORE.TMP.optioncount++;
		});
		SEARCH_CORE.TMP 																						= $H();
	}
	catch(e)
	{
		_error_message("file : "+e.fileName+" <br >on line :"+e.lineNumber+"<br>"+e.message);
	}
	
}
function _load_Province_Properties(response)
{
	if (response.responseText[0]=='|') alert(response.responseText);
	
	try
	{
		SEARCH_CORE.TMP                        = $H();
		SEARCH_CORE.TMP.options_reponseSet = $M(response);
		switch(true)
		{
			case(SEARCH_CORE.TMP.options_reponseSet!=null && SEARCH_CORE.TMP.options_reponseSet.Regions !=null && SEARCH_CORE.TMP.options_reponseSet.Suburbs!=null):
				SEARCH_CORE.DATA.Locations 		        	 = $H();
				SEARCH_CORE.DATA.Locations.Regions     		 = $H();
				SEARCH_CORE.DATA.Locations.Suburbs     		 = $H();
				
				SEARCH_CORE.DATA.Locations.Regions           = SEARCH_CORE.TMP.options_reponseSet.Regions.Region;
				SEARCH_CORE.DATA.Locations.Suburbs           = SEARCH_CORE.TMP.options_reponseSet.Suburbs.Suburb;
				
				_populate_Region_Suburb_List();
			break;
			default:
				SEARCH_CORE.HTML_Elements.search_Location_select.options.length = 0;
				SEARCH_CORE.HTML_Elements.search_Location_select.options[0]     = new Option('No Properties In Province','false');
				_populate_default_PropertyTypes_list();
				_search_loading_layer(SEARCH_CORE.HTML_Elements.search_Property_Type_select_div,SEARCH_CORE.HTML_Elements.search_Type_select,false);	
				_search_loading_layer(SEARCH_CORE.HTML_Elements.search_Region_Suburb_select_div,SEARCH_CORE.HTML_Elements.search_Location_select,false);
				SEARCH_CORE.HTML_Elements.search_Province_select.disabled		  												= false;
			break;
		}
	}
	catch(e)
	{
		_error_message("file : "+e.fileName+" <br >on line :"+e.lineNumber+"<br>"+e.message);
	}
}
function _populate_Region_Suburb_List()
{
	try
	{
		SEARCH_CORE.TMP 																							  = $H();
		SEARCH_CORE.MEM_STATE.location_options                                                                        = $H();
		SEARCH_CORE.MEM_STATE.location_options.Regions 														          = $H();

		SEARCH_CORE.HTML_Elements.search_Location_select.options.length 										      = 0;
		
		SEARCH_CORE.TMP.optioncount 																			      = 0;
		SEARCH_CORE.TMP.propertyCount                                                                                 = 0;

		$H(SEARCH_CORE.DATA.Locations.Suburbs).each(function(suburb)
		{
			if (SEARCH_CORE.MEM_STATE.search_Suburb_filter.Value!="")
			{
			//	SEARCH_CORE.TMP.region_heading = "Filtered";
				if (in_string(SEARCH_CORE.MEM_STATE.search_Suburb_filter.Value,SEARCH_CORE.DATA.Locations.Suburbs[suburb.key].Name.toUpperCase()) || in_string(SEARCH_CORE.MEM_STATE.search_Suburb_filter.Value,SEARCH_CORE.DATA.Locations.Regions[SEARCH_CORE.DATA.Locations.Suburbs[suburb.key].Region].Name.toUpperCase()))
				{
					if(!SEARCH_CORE.MEM_STATE.location_options.Regions[suburb.value.Region])
					{
						SEARCH_CORE.MEM_STATE.location_options.Regions[suburb.value.Region] 		  		   = $H();
						SEARCH_CORE.MEM_STATE.location_options.Regions[suburb.value.Region].Suburbs		       = $H();
					}
					SEARCH_CORE.MEM_STATE.location_options.Regions[suburb.value.Region].Suburbs[suburb.key]   = $H();
					SEARCH_CORE.TMP.propertyCount 															   += SEARCH_CORE.DATA.Locations.Suburbs[suburb.key].PropertyCount;
				}
			}
			else
			{
			//	SEARCH_CORE.TMP.region_heading = "All";
				
				if(!SEARCH_CORE.MEM_STATE.location_options.Regions[suburb.value.Region])
				{
					SEARCH_CORE.MEM_STATE.location_options.Regions[suburb.value.Region] 		  				   = $H();
					SEARCH_CORE.MEM_STATE.location_options.Regions[suburb.value.Region].Suburbs  			       = $H();
				}
				SEARCH_CORE.MEM_STATE.location_options.Regions[suburb.value.Region].Suburbs[suburb.key]    = $H();
				SEARCH_CORE.TMP.propertyCount 															          += SEARCH_CORE.DATA.Locations.Suburbs[suburb.key].PropertyCount;
			}
		});

		if ($A(SEARCH_CORE.MEM_STATE.location_options.Regions).length >0)
		{
			$H(SEARCH_CORE.DATA.Locations.Regions).each(function(region)
			{
				if (SEARCH_CORE.MEM_STATE.location_options.Regions[region.key])
				{
					SEARCH_CORE.HTML_Elements.search_Location_select.options[SEARCH_CORE.TMP.optioncount] 					     = new Option(SEARCH_CORE.DATA.Locations.Regions[region.key].Name,region.key); // +" - "+SEARCH_CORE.TMP.region_heading
					SEARCH_CORE.HTML_Elements.search_Location_select.options[SEARCH_CORE.TMP.optioncount].style.backgroundColor  = SEARCH_CORE.STYLE.Selects.Headings_BG_Color;
					SEARCH_CORE.HTML_Elements.search_Location_select.options[SEARCH_CORE.TMP.optioncount].style.color 		     = SEARCH_CORE.STYLE.Selects.Headings_Font_Color;
					SEARCH_CORE.TMP.optioncount++;
					
					SEARCH_CORE.MEM_STATE.location_options.Regions[region.key].Suburbs.each(function(suburbid)
					{
						SEARCH_CORE.HTML_Elements.search_Location_select.options[SEARCH_CORE.TMP.optioncount] 				     = new Option(SEARCH_CORE.DATA.Locations.Suburbs[suburbid.key].Name+" [ "+SEARCH_CORE.DATA.Locations.Suburbs[suburbid.key].PropertyCount+" ]",SEARCH_CORE.DATA.Locations.Suburbs[suburbid.key].SuburbID);

						if (SEARCH_CORE.RELOAD.STATE && in_array(","+suburbid.key,SEARCH_CORE.RELOAD.DATA['Suburbs']))
						{
							SEARCH_CORE.HTML_Elements.search_Location_select.options[SEARCH_CORE.TMP.optioncount].selected = "true";
						}
						SEARCH_CORE.TMP.optioncount++;
					});	
				}
			});

			SEARCH_CORE.TMP 																							   	= $H();
			SEARCH_CORE.HTML_Elements.search_Suburb_filter.disabled 													   	= false;
			SEARCH_CORE.HTML_Elements.search_Location_select.disabled       											   	= false;
			SEARCH_CORE.HTML_Elements.search_Province_select.disabled		  												= false;
			_search_loading_layer(SEARCH_CORE.HTML_Elements.search_Region_Suburb_select_div,SEARCH_CORE.HTML_Elements.search_Location_select,false);
			_populate_Type_List();
		}
		else
		{
			SEARCH_CORE.HTML_Elements.search_Location_select.disabled 														   = true;
			SEARCH_CORE.HTML_Elements.search_Location_select.options[SEARCH_CORE.TMP.optioncount] 
		}
	}
	catch(e)
	{
		_error_message("file : "+e.fileName+" <br >on line :"+e.lineNumber+"<br>"+e.message);
	}
}

function _populate_Type_List()
{
	try
	{
		_search_loading_layer(SEARCH_CORE.HTML_Elements.search_Property_Type_select_div,SEARCH_CORE.HTML_Elements.search_Type_select,true);
		
		SEARCH_CORE.TMP.Selected_Locations 		  														=  get_Selected_Options(SEARCH_CORE.HTML_Elements.search_Location_select);
		
		SEARCH_CORE.MEM_STATE.available_Types              															= $H();
		SEARCH_CORE.MEM_STATE.available_Types.regions_loaded                                                         = $A();
		SEARCH_CORE.MEM_STATE.available_Types.region_loaded_inc 													    = 0;

		SEARCH_CORE.TMP.post_regions																			= $H();
		SEARCH_CORE.TMP.post_regions.list																		= $A();
		SEARCH_CORE.TMP.post_regions.inc                                                                        = 0;
		
		SEARCH_CORE.MEM_STATE.PostSuburbs  = "-1";
		SEARCH_CORE.MEM_STATE.PostRegions  = "-1";
		switch(true)
		{
			case($A(SEARCH_CORE.TMP.Selected_Locations).length>0):
				switch(in_array("-1",SEARCH_CORE.TMP.Selected_Locations))
				{
					case true:
						SEARCH_CORE.MEM_STATE.location_options.Regions.each(function(region)
						{
							SEARCH_CORE.MEM_STATE.PostRegions    +=","+region.key.substring(7,region.key.length);
							region.value.Suburbs.each(function(suburb)
							{
								SEARCH_CORE.MEM_STATE.PostSuburbs += ","+SEARCH_CORE.DATA.Locations.Suburbs[suburb.key].SuburbID;
								SEARCH_CORE.TMP.PostSuburbs_inc++;
								$H(SEARCH_CORE.DATA.Locations.Suburbs[suburb.key].Types).each(function(type)
								{
									if(!SEARCH_CORE.MEM_STATE.available_Types[type.key])
									{
										SEARCH_CORE.MEM_STATE.available_Types[type.key]                        					  = $H();
										SEARCH_CORE.MEM_STATE.available_Types[type.key].PropertyCount           					  = 0;
										SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment                                     = $H();
									}
									SEARCH_CORE.MEM_STATE.available_Types[type.key].PropertyCount          	  					+= type.value.PropertyCount;
									$H(type.value.Payment).each(function(payment)
									{
										if(!SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key])
										{
											SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key]                                  = $H();
											SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].PropertyCount           	      = 0;
											SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Max           				      = 0;
										    SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Min           				      = null;
										}
										SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Max                                  = Math.max(parseInt(payment.value.Max),SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Max); 
										SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Min                                  = (parseInt(payment.value.Min)<SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Min || SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Min==null)?parseInt(payment.value.Min):SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Min; 
										SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].PropertyCount           	             += payment.value.PropertyCount;
									});
								});
							});
						});
					break;
					default:
						SEARCH_CORE.TMP.regionTypesloaded = $A();
						SEARCH_CORE.TMP.Selected_Locations.each(function(location)
						{
							if(in_string("region_",location))
							{
								SEARCH_CORE.TMP.location_key = "Regions";
							}
							else
							{
								SEARCH_CORE.TMP.location_key = "Suburbs";
								//_console(location);
								location = "sb_"+location;
							}
							//_console(location);
							$H(SEARCH_CORE.DATA.Locations[SEARCH_CORE.TMP.location_key][location].Types).each(function(type)
							{
								
								switch(SEARCH_CORE.TMP.location_key)
								{
									case "Regions":
										
										SEARCH_CORE.MEM_STATE.available_Types.regions_loaded[SEARCH_CORE.MEM_STATE.available_Types.region_loaded_inc] = location;
										SEARCH_CORE.MEM_STATE.PostRegions    															 += ","+location.substring(7,location.length);
										SEARCH_CORE.MEM_STATE.location_options.Regions[location].Suburbs.each(function(suburb)
										{
											if(SEARCH_CORE.DATA.Locations.Suburbs[suburb.key].Types[type.key])
											{
												$H(SEARCH_CORE.DATA.Locations.Suburbs[suburb.key].Types[type.key].Payment).each(function(payment)
												{
														switch(!SEARCH_CORE.MEM_STATE.available_Types[type.key])
														{
															case true:
																SEARCH_CORE.MEM_STATE.available_Types[type.key]				               		= $H();
																SEARCH_CORE.MEM_STATE.available_Types[type.key].PropertyCount                   = 0;
																SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment               	        = $H();
															break;
														}
														if(!SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key])
														{
															SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key]                                  = $H();
															SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].PropertyCount           	      = 0;
															SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Max           				      = 0;
														    SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Min           				      = null;
														}
														SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Max                                  = Math.max(parseInt(payment.value.Max),SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Max); 
														SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Min                                  = (parseInt(payment.value.Min)<SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Min || SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Min==null)?parseInt(payment.value.Min):SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Min; 
														SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].PropertyCount                       += payment.value.PropertyCount;
													
												});
												SEARCH_CORE.MEM_STATE.available_Types[type.key].PropertyCount 	   += SEARCH_CORE.DATA.Locations.Suburbs[suburb.key].Types[type.key].PropertyCount; 
											}
											SEARCH_CORE.MEM_STATE.PostSuburbs 	   += ","+SEARCH_CORE.DATA.Locations.Suburbs[suburb.key].SuburbID;
										});
										
										SEARCH_CORE.MEM_STATE.available_Types.region_loaded_inc++;
									break;
									default:
										switch(!in_array(SEARCH_CORE.DATA.Locations.Suburbs[location].Region,SEARCH_CORE.MEM_STATE.available_Types.regions_loaded))
										{
											case true:
												switch(!SEARCH_CORE.MEM_STATE.available_Types[type.key])
												{
													case true:
														SEARCH_CORE.MEM_STATE.available_Types[type.key]				               		= $H();
														SEARCH_CORE.MEM_STATE.available_Types[type.key].PropertyCount                   = 0;
														SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment               	        = $H();
													break;
												}
												if(!in_array(SEARCH_CORE.DATA.Locations.Suburbs[location].Region,SEARCH_CORE.TMP.post_regions.list))
												{
													SEARCH_CORE.TMP.post_regions.list[SEARCH_CORE.TMP.post_regions.inc] = SEARCH_CORE.DATA.Locations.Suburbs[location].Region;
													SEARCH_CORE.MEM_STATE.PostRegions                                  += ","+SEARCH_CORE.DATA.Locations.Suburbs[location].Region.substring(7,SEARCH_CORE.DATA.Locations.Suburbs[location].Region.length);
													SEARCH_CORE.TMP.post_regions.inc++;
												}
												$H(type.value.Payment).each(function(payment)
												{
													if(!SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key])
													{
														SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key]                                  = $H();
														SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].PropertyCount           	      = 0;
													
														SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Max           				      = 0;
													    SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Min           				      = payment.value.Min;
													}
													SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Max                                  = Math.max(parseInt(payment.value.Max),SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Max); 
													SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Min                                  = (parseInt(payment.value.Min)<SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Min || SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Min==null)?parseInt(payment.value.Min):SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].Min; 
													SEARCH_CORE.MEM_STATE.available_Types[type.key].Payment[payment.key].PropertyCount           	             += payment.value.PropertyCount;
												});
												//_console(SEARCH_CORE.DATA.Locations.Suburbs[location].SuburbID);
												SEARCH_CORE.MEM_STATE.PostSuburbs 	                                += ","+SEARCH_CORE.DATA.Locations.Suburbs[location].SuburbID;
												SEARCH_CORE.MEM_STATE.available_Types[type.key].PropertyCount  	    += type.value.PropertyCount;
											break;
										}
									break;
								}
							});
						});
					break;
				}
			break;
		}
		SEARCH_CORE.TMP.type_avail       = $H();
		SEARCH_CORE.TMP.type_grayd       = $H();
		SEARCH_CORE.TMP.type_avail_count = 0;
		SEARCH_CORE.TMP.type_grayd_count = 0;

		SEARCH_CORE.HTML_Elements.search_Type_select.options.length = 0;
		SEARCH_CORE.DATA.Types.each(function(type)
		{
			switch(!SEARCH_CORE.MEM_STATE.available_Types[type.key])
			{	
				case false:
					SEARCH_CORE.HTML_Elements.search_Type_select.options[SEARCH_CORE.TMP.type_avail_count] 			 = new Option(type.value.Name +" [ "+SEARCH_CORE.MEM_STATE.available_Types[type.key].PropertyCount+" ]",type.key);
					switch(SEARCH_CORE.RELOAD.STATE)
					{
						case(true):
							switch(in_array(","+type.key,SEARCH_CORE.RELOAD.DATA['Types']))
							{
								case true:
									SEARCH_CORE.HTML_Elements.search_Type_select.options[SEARCH_CORE.TMP.type_avail_count].selected 	 = true;
								break;
							}
						break;
						default:
							SEARCH_CORE.HTML_Elements.search_Type_select.options[SEARCH_CORE.TMP.type_avail_count].selected 	         = true;
						break;
					}
					SEARCH_CORE.TMP.type_avail_count++;
				break;
				default:
					SEARCH_CORE.TMP.type_grayd[SEARCH_CORE.TMP.type_grayd_count] 										 = new Option(type.value.Name +" [ 0 ]",type.key);
					SEARCH_CORE.TMP.type_grayd[SEARCH_CORE.TMP.type_grayd_count].style.color                             = "#d1d1d1";
					SEARCH_CORE.TMP.type_grayd[SEARCH_CORE.TMP.type_grayd_count].disabled 							     = true;
					SEARCH_CORE.TMP.type_grayd_count++; 
			}
		});
		SEARCH_CORE.TMP.type_grayd.each(function(option)
		{
			SEARCH_CORE.HTML_Elements.search_Type_select.options[SEARCH_CORE.TMP.type_avail_count] 					 = option.value;
			SEARCH_CORE.TMP.type_avail_count++
		});
		SEARCH_CORE.HTML_Elements.search_Type_select.disabled                                                        = false;
		_search_Payment_Handler();
		_search_loading_layer(SEARCH_CORE.HTML_Elements.search_Property_Type_select_div,SEARCH_CORE.HTML_Elements.search_Type_select,false);
	}
	catch(e)
	{
		_error_message("file : "+e.fileName+" <br >on line :"+e.lineNumber+"<br>"+e.message);
	}
}
function _search_Payment_Handler()
{
	try
	{
		
		for(i = 0;i<SEARCH_CORE.HTML_Elements.search_Type_select.options.length;i++)
		{
			switch(SEARCH_CORE.HTML_Elements.search_Type_select.options[i].disabled)
			{
				case true:
					SEARCH_CORE.HTML_Elements.search_Type_select.options[i].selected = false;
				break;
			}
		}
		SEARCH_CORE.TMP.available_Payment              														    = $H();
		SEARCH_CORE.HTML_Elements.search_PaymentType_select.options.length = 0;
		SEARCH_CORE.HTML_Elements.search_PaymentType_select.disabled       = true;
		var selectedTypes = get_Selected_Options(SEARCH_CORE.HTML_Elements.search_Type_select);
		if(selectedTypes.length >0)
		{
			$H(selectedTypes).each(function(type)
			{
				
				SEARCH_CORE.MEM_STATE.available_Types[type.value].Payment.each(function(payment)
				{
					if(!SEARCH_CORE.TMP.available_Payment[payment.key])
					{
						SEARCH_CORE.TMP.available_Payment[payment.key]               = $H();
						SEARCH_CORE.TMP.available_Payment[payment.key].PropertyCount = 0;
						SEARCH_CORE.TMP.available_Payment[payment.key].Max           = payment.value.Max;
						SEARCH_CORE.TMP.available_Payment[payment.key].Min 			 = payment.value.Min;
						SEARCH_CORE.TMP.available_Payment[payment.key].PropertyCount = 0;
					}
					SEARCH_CORE.TMP.available_Payment[payment.key].PropertyCount += payment.value.PropertyCount;
				});			
			});
		}
		var inc = 0;
		SEARCH_CORE.TMP.available_Payment.each(function(payment)
		{
			SEARCH_CORE.HTML_Elements.search_PaymentType_select.options[inc] =  new Option(SEARCH_CORE.DATA.PaymentTypes[payment.key].Name +" [ "+payment.value.PropertyCount+" ]",payment.key);	
			switch(SEARCH_CORE.RELOAD.STATE)
			{
				case(true):
					switch(payment.key == SEARCH_CORE.RELOAD.DATA['Payment'])
					{
						case true:
							SEARCH_CORE.HTML_Elements.search_PaymentType_select.options[inc].selected           =true;
						break;
					}
				break;
			}
			inc++;
		});
		SEARCH_CORE.HTML_Elements.search_PaymentType_select.disabled         = false;
		
		SEARCH_CORE.HTML_Elements.search_Rental_Min_Price_select.disabled 				    					= true;
		SEARCH_CORE.HTML_Elements.search_Rental_Max_Price_select.disabled 										= true;

		SEARCH_CORE.HTML_Elements.search_Sale_Min_Price_select.disabled 				    					= true;
		SEARCH_CORE.HTML_Elements.search_Sale_Max_Price_select.disabled 										= true;  
		
		
		SEARCH_CORE.TMP.SaleRange 																				= $H();
		SEARCH_CORE.TMP.SaleRange.from_inc 																	    = 0;
		SEARCH_CORE.TMP.SaleRange.to_inc   																	    = 0;
		
		SEARCH_CORE.HTML_Elements.search_Sale_Min_Price_select.options.length 									= 0;
		SEARCH_CORE.HTML_Elements.search_Sale_Max_Price_select.options.length 									= 0;
		SEARCH_CORE.HTML_Elements.search_Sale_Min_Price_select.options[SEARCH_CORE.TMP.SaleRange.from_inc]  			= new Option("From Any",0);
		SEARCH_CORE.HTML_Elements.search_Sale_Max_Price_select.options[SEARCH_CORE.TMP.SaleRange.to_inc]    			= new Option("To Any",0);
		
		SEARCH_CORE.TMP.SaleRange.from_inc++;
		SEARCH_CORE.TMP.SaleRange.to_inc++;
		
		SEARCH_CORE.TMP.RentRange 																				    = $H();
		SEARCH_CORE.TMP.RentRange.from_inc 																	        = 0;
		SEARCH_CORE.TMP.RentRange.to_inc   																	        = 0;
		
		SEARCH_CORE.HTML_Elements.search_Rental_Min_Price_select.options.length 								    = 0;
		SEARCH_CORE.HTML_Elements.search_Rental_Max_Price_select.options.length 								    = 0;
		SEARCH_CORE.HTML_Elements.search_Rental_Min_Price_select.options[SEARCH_CORE.TMP.RentRange.from_inc]  		= new Option("From Any",0);
		SEARCH_CORE.HTML_Elements.search_Rental_Max_Price_select.options[SEARCH_CORE.TMP.RentRange.to_inc]    		= new Option("To Any",0);
		
		SEARCH_CORE.TMP.RentRange.from_inc++;
		SEARCH_CORE.TMP.RentRange.to_inc++;
		
		SEARCH_CORE.TMP.available_Payment.each(function(payment)
		{
			switch(payment.key)
			{
				case "1":
					SEARCH_CORE.CONST.Price_Ranges.Rental.each(function(range)
					{
						
						switch(true)
						{
							case (payment.value.Max>=range.value):
								SEARCH_CORE.HTML_Elements.search_Rental_Min_Price_select.options[SEARCH_CORE.TMP.RentRange.from_inc] = new Option(addCommas(range.value.toFixed(2)),range.value);
								if(SEARCH_CORE.RELOAD.DATA['Rental_MIN'])
								{
									switch(SEARCH_CORE.RELOAD.STATE)
									{
										case(true):
											switch(range.value == SEARCH_CORE.RELOAD.DATA['Rental_MIN'])
											{
												case true:
													SEARCH_CORE.HTML_Elements.search_Rental_Min_Price_select.options[SEARCH_CORE.TMP.RentRange.from_inc].selected           =true;
												break;
											}
										break;
									}
								}
								SEARCH_CORE.TMP.RentRange.from_inc++;										
							break;
						}
						switch(true)
						{
							case (payment.value.Min<=range.value):
								SEARCH_CORE.HTML_Elements.search_Rental_Max_Price_select.options[SEARCH_CORE.TMP.RentRange.to_inc] = new Option(addCommas(range.value.toFixed(2)),range.value);
								if(SEARCH_CORE.RELOAD.DATA['Rental_MAX'])
								{
									switch(SEARCH_CORE.RELOAD.STATE)
									{
										case(true):
											switch(range.value == SEARCH_CORE.RELOAD.DATA['Rental_MAX'])
											{
												case true:
													SEARCH_CORE.HTML_Elements.search_Rental_Max_Price_select.options[SEARCH_CORE.TMP.RentRange.to_inc].selected           =true;
												break;
											}
										break;
									}
								}
								SEARCH_CORE.TMP.RentRange.to_inc++;										
							break;
						}
					});
				break;
				case "2":
					SEARCH_CORE.CONST.Price_Ranges.Sale.each(function(range)
					{
						switch(true)
						{
							case (payment.value.Max>=range.value):
								SEARCH_CORE.HTML_Elements.search_Sale_Min_Price_select.options[SEARCH_CORE.TMP.SaleRange.from_inc] = new Option(addCommas(range.value.toFixed(2)),range.value);
								if(SEARCH_CORE.RELOAD.DATA['Sale_MIN'])
								{
									switch(SEARCH_CORE.RELOAD.STATE)
									{
										case(true):
											switch(range.value == SEARCH_CORE.RELOAD.DATA['Sale_MIN'])
											{
												case true:
													SEARCH_CORE.HTML_Elements.search_Sale_Min_Price_select.options[SEARCH_CORE.TMP.SaleRange.from_inc].selected           =true;
												break;
											}
										break;
									}
								}
								SEARCH_CORE.TMP.SaleRange.from_inc++;										
							break;
						}
						switch(true)
						{
							case (payment.value.Min<=range.value):
								SEARCH_CORE.HTML_Elements.search_Sale_Max_Price_select.options[SEARCH_CORE.TMP.SaleRange.to_inc] = new Option(addCommas(range.value.toFixed(2)),range.value);
								if(SEARCH_CORE.RELOAD.DATA['Sale_MAX'])
								{
									switch(SEARCH_CORE.RELOAD.STATE)
									{
										case(true):
											switch(range.value == SEARCH_CORE.RELOAD.DATA['Sale_MAX'])
											{
												case true:
													SEARCH_CORE.HTML_Elements.search_Sale_Max_Price_select.options[SEARCH_CORE.TMP.SaleRange.to_inc].selected           =true;
												break;
											}
										break;
									}
								}
								SEARCH_CORE.TMP.SaleRange.to_inc++;										
							break;
						}
					});
				break;
			}
		});
		switch(SEARCH_CORE.RELOAD.STATE)
		{
			case(true):
				SEARCH_CORE.HTML_Elements.search_Province_select.disabled   = false;
				SEARCH_CORE.RELOAD.STATE 							        = false;
			break;
		}
		_search_PaymentType_Handler();
	}
	catch(e)
	{
		_error_message("file : "+e.fileName+" <br >on line :"+e.lineNumber+"<br>"+e.message);
	}
}
function _search_Submit_Handler()
{
	SEARCH_CORE.TMP.Post = $A();
	switch(true)
	{
		case(get_Selected_Options(SEARCH_CORE.HTML_Elements.search_Province_select).length==0 || SEARCH_CORE.HTML_Elements.search_Province_select.options[SEARCH_CORE.HTML_Elements.search_Province_select.selectedIndex].value=='-1'):
			_Ciriteria_error("Please Select a Property Province",SEARCH_CORE.HTML_Elements.search_Province_select_div.id);	
		return;
		default:
			
			SEARCH_CORE.TMP.Post['Province'] 					= SEARCH_CORE.HTML_Elements.search_Province_select.options[SEARCH_CORE.HTML_Elements.search_Province_select.selectedIndex].value;
	}
	SEARCH_CORE.TMP.Post['SuburbFilter'] = SEARCH_CORE.MEM_STATE.search_Suburb_filter.Value.replace(" ","_");
	switch(true)
	{
		case(get_Selected_Options(SEARCH_CORE.HTML_Elements.search_Location_select).length==0):
			_Ciriteria_error("Please Select a Property Location",SEARCH_CORE.HTML_Elements.search_Region_Suburb_select_div.id);	
		return;
		default:
			SEARCH_CORE.TMP.Post['Suburbs'] 					= SEARCH_CORE.MEM_STATE.PostSuburbs;
			SEARCH_CORE.TMP.Post['Regions']                     = SEARCH_CORE.MEM_STATE.PostRegions;
	}
	switch(true)
	{
		//case(get_Selected_Options(SEARCH_CORE.HTML_Elements.search_Type_select).length==0):
		//	_Ciriteria_error("Please Select a Property Type (Step 2)");
		//return;
		default:
			SEARCH_CORE.TMP.Post['Types'] = "-1";
			SEARCH_CORE.TMP.selectedTypes	= $H(get_Selected_Options(SEARCH_CORE.HTML_Elements.search_Type_select));
			SEARCH_CORE.TMP.selectedTypes.each(function(type)
			{
                            //SEARCH_CORE.TMP.Post['Types'] += ","+type.value;
			});
                        //Hack to prevent property type box being needed
                        SEARCH_CORE.TMP.Post['Types'] = "-1,1,2,3,4,5,6,7,8";
	}
	switch(true)
	{
		case(get_Selected_Options(SEARCH_CORE.HTML_Elements.search_PaymentType_select).length==0):
			_Ciriteria_error("Please Select a Payment Type",SEARCH_CORE.HTML_Elements.search_PaymentType_select_div.id);
		return;
		default:
			SEARCH_CORE.TMP.Post['Payment']   = SEARCH_CORE.HTML_Elements.search_PaymentType_select.options[SEARCH_CORE.HTML_Elements.search_PaymentType_select.selectedIndex].value;
	}
	switch(SEARCH_CORE.TMP.Post['Payment'])
	{
		case '1':
			SEARCH_CORE.TMP.Post['Rental_MIN']	 			= SEARCH_CORE.HTML_Elements.search_Rental_Min_Price_select.options[SEARCH_CORE.HTML_Elements.search_Rental_Min_Price_select.selectedIndex].value;
			SEARCH_CORE.TMP.Post['Rental_MAX'] 	            = SEARCH_CORE.HTML_Elements.search_Rental_Max_Price_select.options[SEARCH_CORE.HTML_Elements.search_Rental_Max_Price_select.selectedIndex].value;
		break;
		case '2':
			SEARCH_CORE.TMP.Post['Sale_MIN'] 				= SEARCH_CORE.HTML_Elements.search_Sale_Min_Price_select.options[SEARCH_CORE.HTML_Elements.search_Sale_Min_Price_select.selectedIndex].value;
			SEARCH_CORE.TMP.Post['Sale_MAX'] 				= SEARCH_CORE.HTML_Elements.search_Sale_Max_Price_select.options[SEARCH_CORE.HTML_Elements.search_Sale_Max_Price_select.selectedIndex].value;
		break;
	}
//	CtrlCall(SEARCH_CORE.CONTROLLER_CALL_URL+"&param=function:_search_stats_criteria_update;lang:js;","data="+serialize(SEARCH_CORE.TMP.Post),"_search_Submit");
	CtrlCall("/?page=property_search_response&content=main","data="+serialize(SEARCH_CORE.TMP.Post),"_search_Submit");
	
}
function _search_Submit(response)
{
	window.location = "/Property-One-Liners/Search/"+response.responseText+"/";
//	setTimeout("window.location = '?page=property_one_liners&data="+serialize(SEARCH_CORE.TMP.Post)+"';",10);
}
var muffin_box;
function _Ciriteria_error(msg,id)
{
	muffin_box = new MaJiG_BOX("<table class='section_grey' style='width:300px;font-size:7pt;'><tr><td align='center'><strong>Search Criteria Missing</strong></td></tr><tr><td align='center'>"+msg+"</td></tr><tr><td align='center'><input style='font-size: 8pt' type='button' value='Ok' onclick='muffin_box._close();Effect.Shake(\""+id+"\");'></td></tr></table>");
}


