var SEARCH_CORE = $H();
//SYSTEM SESSION VARS
SEARCH_CORE.CONTROLLER_CALL_URL    	   		    = "/?page=api_speed&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    	= "#003466";
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]    			= 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;

var SetpaymentID       = 0;
var SetpropTypeID      = 0;

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,PaymentID)
{
    try
    {
        if(PaymentID)
        {
            SetpaymentID = PaymentID;
        }
        if(GET){
            SetpropTypeID = GET;
        }

        _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("Please select region...", '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 			  = "Type in suburb or region";
            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()
{
    var selected_options = get_Selected_Options( SEARCH_CORE.HTML_Elements.search_PaymentType_select );

    //alert(selected_options);

    $H(selected_options).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(",");
        data['property_search_options']['paymentIDs']	   = SetpaymentID;
        data['property_search_options']['typeIDs']         = SetpropTypeID;

        //        alert(SEARCH_CORE.CONTROLLER_CALL_URL);

        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.SuburbGroupings = $H();
                SEARCH_CORE.DATA.Locations.Suburbs = $H();
				
                SEARCH_CORE.DATA.Locations.Regions = SEARCH_CORE.TMP.options_reponseSet.Regions.Region;
                SEARCH_CORE.DATA.Locations.SuburbGroupings = SEARCH_CORE.TMP.options_reponseSet.SuburbGroupings.SuburbGrouping;
                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.MEM_STATE.location_options.SuburbGroupings 														  = $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()) ||
                    in_string(SEARCH_CORE.MEM_STATE.search_Suburb_filter.Value,SEARCH_CORE.DATA.Locations.SuburbGroupings[SEARCH_CORE.DATA.Locations.Suburbs[suburb.key].SuburbGrouping].Name.toUpperCase())
                    )
                    {
                    if(!SEARCH_CORE.MEM_STATE.location_options.SuburbGroupings[suburb.value.SuburbGrouping])
                    {
                        SEARCH_CORE.MEM_STATE.location_options.SuburbGroupings[suburb.value.SuburbGrouping] = $H();
                        SEARCH_CORE.MEM_STATE.location_options.SuburbGroupings[suburb.value.SuburbGrouping].Suburbs = $H();
                    }
                    SEARCH_CORE.MEM_STATE.location_options.SuburbGroupings[suburb.value.SuburbGrouping].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();
                }
                if(!SEARCH_CORE.MEM_STATE.location_options.SuburbGroupings[suburb.value.SuburbGrouping])
                {
                    SEARCH_CORE.MEM_STATE.location_options.SuburbGroupings[suburb.value.SuburbGrouping] = $H();
                    SEARCH_CORE.MEM_STATE.location_options.SuburbGroupings[suburb.value.SuburbGrouping].Suburbs = $H();
                }

                SEARCH_CORE.MEM_STATE.location_options.SuburbGroupings[suburb.value.SuburbGrouping].Suburbs[suburb.key] = $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.SuburbGroupings).length >0)
        {
            $H(SEARCH_CORE.DATA.Locations.SuburbGroupings).each(function(suburb_grouping)
            {
                if (SEARCH_CORE.MEM_STATE.location_options.SuburbGroupings[suburb_grouping.key])
                {
                    var varOptionCount = 0;
                    var varSuburbIDs = 0;
                    SEARCH_CORE.HTML_Elements.search_Location_select.options[SEARCH_CORE.TMP.optioncount] 					     	= new Option(SEARCH_CORE.DATA.Locations.SuburbGroupings[suburb_grouping.key].Name, '0'); // +" - "+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;
                    
                    varOptionCount = SEARCH_CORE.TMP.optioncount;
                    SEARCH_CORE.TMP.optioncount++;
					
                    SEARCH_CORE.MEM_STATE.location_options.SuburbGroupings[suburb_grouping.key].Suburbs.each(function(suburbid)
                    {
                        //the commented part contains the count for suburb listings
                        // 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);
                        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].SuburbID);
                        varSuburbIDs += 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.HTML_Elements.search_Location_select.options[varOptionCount] 					     = new Option(SEARCH_CORE.DATA.Locations.SuburbGroupings[suburb_grouping.key].Name, varSuburbIDs + '0'); // +" - "+SEARCH_CORE.TMP.region_heading
                    SEARCH_CORE.HTML_Elements.search_Location_select.options[varOptionCount].style.backgroundColor  = SEARCH_CORE.STYLE.Selects.Headings_BG_Color;
                    SEARCH_CORE.HTML_Elements.search_Location_select.options[varOptionCount].style.color 		     = SEARCH_CORE.STYLE.Selects.Headings_Font_Color;
                }
            });

            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.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.TMP.post_suburb_groupings = $H();
        SEARCH_CORE.TMP.post_suburb_groupings.list = $A();
        SEARCH_CORE.TMP.post_suburb_groupings.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";
                                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 "SuburbGroupings":

                                        SEARCH_CORE.MEM_STATE.available_Types.suburb_groupings_loaded[SEARCH_CORE.MEM_STATE.available_Types.suburb_groupings_loaded_inc] = location;
                                        SEARCH_CORE.MEM_STATE.PostSuburb_groupings    															 += ","+location.substring(7,location.length);
                                        SEARCH_CORE.MEM_STATE.location_options.SuburbGroupings[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.suburb_grouping_loaded_inc++;
                                        break;

                                    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++;
                    break;
            }
        });
        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;
		
        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.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 (Step 1)",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 (Step 1)",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;
            });
    }
    switch(true)
    {
        case(get_Selected_Options(SEARCH_CORE.HTML_Elements.search_PaymentType_select).length==0):
            _Ciriteria_error("Please Select a Payment Type (Step 2)",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>");
}


function getSelectedSuburbs(ele){
	
    var foo = "";   
    var counter = 0;
    //    jQuery("#search_Region_Suburb_select").each(function(i, selected){
    //          // Get the options for the select here... can I use select.each...?
    //          if(jQuery(selected).val() == 0){
    //
    //          }
    //          $('option', this).each(function() {
    //            alert(this.value);
    //          });
    //       }
    //    );
    jQuery("#search_Region_Suburb_select").each(function(i, selected){
        foo = jQuery(selected).val();
    });
    var suburbIDs = "";
    if(foo.length >= 1){
        for(var i = 0 ; i< foo.length; i++){
            if(foo[i].substring(0 , 3) != "reg"){
                suburbIDs = suburbIDs + foo[i];
                if(i+1 != foo.length){
                    suburbIDs +=  ",";
                }
            }
        }
        jQuery("#adv_search_region_suburb_ids").val(suburbIDs);
    }
}

function setAdvancedPaymentType(){
    if(jQuery("#adv_search_payment_type_rental").is(':checked'))
    {
        jQuery("#adv_search_price_from").replaceWith(rentFrom);
        jQuery("#adv_search_price_to").replaceWith(rentTo);
        jQuery("#adv_payment").val("1");
        property_search_init('',jQuery('#search_Province_select').val(),jQuery('#js_province_full').val(),null,jQuery('#adv_types').val(),"1");
    }
    //if sale checked
    if(jQuery("#adv_search_payment_type_sale").is(':checked'))
    {
        jQuery("#adv_search_price_from").replaceWith(saleFrom);
        jQuery("#adv_search_price_to").replaceWith(saleTo);

        jQuery("#adv_payment").val("2");
        property_search_init('',jQuery('#search_Province_select').val(),jQuery('#js_province_full').val(),null,jQuery('#adv_types').val(),"2");
    }
    //if neither checked
    if(!jQuery("#adv_search_payment_type_sale").is(':checked') && !jQuery("#adv_search_payment_type_rental").is(':checked')){
        jQuery("#adv_search_price_from").replaceWith(saleFrom);
        jQuery("#adv_search_price_to").replaceWith(saleTo);
        jQuery("#adv_payment").val("-1");
        property_search_init('',jQuery("#search_Province_select").val(),jQuery("#js_province_full").val(),null,jQuery("#adv_types").val(),"-1");
    }else if(jQuery("#adv_search_payment_type_sale").is(':checked') && jQuery("#adv_search_payment_type_rental").is(':checked')){
        property_search_init('',jQuery('#search_Province_select').val(),jQuery('#js_province_full').val(),null,jQuery('#adv_types').val(),"-1");
        //jQuery("#adv_payment").val("1,2");
        jQuery("#adv_payment").val("-1");
    }
}

function setSimplePaymentType(){
    //if rent checked
    if(jQuery("#adv_search_sale_type_rental").is(':checked') )
    {
        if(jQuery("#adv_search_price_to").val() !== undefined){
            jQuery("#search_price").replaceWith(rentSimpleFrom);
            jQuery("#Payment").val(jQuery("#adv_search_sale_type_rental").val());
        }else{
            
        }
    }
    //if sale checked
    if(jQuery("#adv_search_sale_type_sale").is(':checked'))
    {
        if(jQuery("#adv_search_price_to").val() !== undefined){
            jQuery("#search_price").replaceWith(saleSimpleFrom);
            jQuery("#Payment").val(jQuery("#adv_search_sale_type_sale").val());
        }
    }
    //if neither checked
    if(!jQuery("#adv_search_sale_type_sale").is(':checked') && !jQuery("#adv_search_sale_type_rental").is(':checked')){
        if(jQuery("#adv_search_price_to").val() !== undefined){
            jQuery("#search_price").replaceWith(saleSimpleFrom);
            jQuery("#Payment").val("-1");
        }
    }else{
        if(jQuery("#adv_search_sale_type_sale").is(':checked') && jQuery("#adv_search_sale_type_rental").is(':checked')){
            jQuery("#Payment").val(jQuery("#adv_search_sale_type_sale").val() +","+jQuery("#adv_search_sale_type_rental").val());
        }
    }
}


function setSimplePropType(){
    if(jQuery("#adv_search_prop_type_comm").is(':checked'))
    {
        jQuery("#Types").val(jQuery("#adv_search_prop_type_comm").val());
    }
    //if sale checked
    if(jQuery("#adv_search_prop_type_indust").is(':checked'))
    {
        jQuery("#Types").val(jQuery("#adv_search_prop_type_indust").val());
    }
    //if neither checked
    if(!jQuery("#adv_search_prop_type_comm").is(':checked') && !jQuery("#adv_search_prop_type_indust").is(':checked')){
        jQuery("#Types").val("-1");
    }else if(jQuery("#adv_search_prop_type_comm").is(':checked') && jQuery("#adv_search_prop_type_indust").is(':checked')){
        jQuery("#Types").val(jQuery("#adv_search_prop_type_indust").val()+","+jQuery("#adv_search_prop_type_comm").val());
    }
}

function setAdvancedPropType(){
    if(jQuery("#adv_search_prop_type_com").is(':checked'))
    {
        jQuery("#adv_types").val(jQuery("#adv_search_prop_type_com").val());
        jQuery("#adv_search_building_type").replaceWith(commHTMLOptions);
        property_search_init('',jQuery('#search_Province_select').val(),jQuery('#js_province_full').val(),null,jQuery('#adv_types').val(),jQuery("#adv_payment").val());
    }
    //if sale checked
    if(jQuery("#adv_search_prop_type_indus").is(':checked'))
    {
        jQuery("#adv_types").val(jQuery("#adv_search_prop_type_indus").val());
        jQuery("#adv_search_building_type").replaceWith(industHTMLOptions);
        property_search_init('',jQuery('#search_Province_select').val(),jQuery('#js_province_full').val(),null,jQuery('#adv_types').val(),jQuery("#adv_payment").val());
    }
    //if neither checked
    if(!jQuery("#adv_search_prop_type_com").is(':checked') && !jQuery("#adv_search_prop_type_indus").is(':checked')){
        jQuery("#adv_types").val("-1");
        jQuery("#adv_search_building_type").replaceWith(commHTMLOptions);
        property_search_init('',jQuery('#search_Province_select').val(),jQuery('#js_province_full').val(),null,jQuery('#adv_types').val(),jQuery("#adv_payment").val());
    }else if(jQuery("#adv_search_prop_type_com").is(':checked') && jQuery("#adv_search_prop_type_indus").is(':checked')){
        jQuery("#adv_types").val(jQuery("#adv_search_prop_type_indus").val()+","+jQuery("#adv_search_prop_type_com").val());
        jQuery("#adv_search_building_type").replaceWith(commHTMLOptions);
        property_search_init('',jQuery('#search_Province_select').val(),jQuery('#js_province_full').val(),null,jQuery('#adv_types').val(),jQuery("#adv_payment").val());
    }
}


function redirWebRef(eleName){
    //if(eleName.value == 'N/A'){
    window.location = "http://"+document.domain+"/"+jQuery("#"+eleName).val()+"/";
//}else{
//alert('please type a valid web reference number');
//}
}

function redirAgentSearch(eleName){
    //if(eleName.value == 'N/A'){
    var agent_name = jQuery("#"+eleName).val();
    agent_name = agent_name.replace(/\s+/g,'+');
    window.location = "http://"+document.domain+"/Agents/Find/"+agent_name+"/";
//}else{
//alert('please type a valid agent name number');
//}
}

function redirOfficeSearch(eleName){
    //if(eleName.value == 'N/A'){
    var officeDetails = jQuery("#"+eleName).val();
    var officeDetailsArr = officeDetails.split(" - ");

    var officeName = officeDetailsArr[0].replace(/\s+/g,'+');
    var suburb = officeDetailsArr[1].replace(/\s+/g,'+');
    var city = officeDetailsArr[2].replace(/\s+/g,'+');
    var state = officeDetailsArr[3].replace(/\s+/g,'+');

    if(officeDetails == "Enter Area or Office Name"){
        window.location = "http://"+document.domain+"/Office-Search/";
    }else{
        window.location = "http://"+document.domain+"/Office-Search/"+state+"/"+city+"/"+suburb+"/"+officeName+"/";
    }
}

function setProvinceSelection(selIndex , subIds){
    jQuery('#search_Province_select').val(selIndex);
    jQuery('search_Province').val(selIndex);
    _search_Province_Handler();
    jQuery('#adv_search_region_suburb_ids').val(subIds);
    setSelectedSuburbs(subIds);
}

function setProvinceSelectionOnly(selIndex){
    jQuery('#search_Province_select').val(selIndex);
    jQuery('search_Province').val(selIndex);
    _search_Province_Handler();
}

function setSelectedSuburbs(subIds){
    if(!isNaN(subIds)){
        jQuery('#search_Region_Suburb_select').val(subIds);
    }else{
        var suburbs = subIds.split("-");
        for(var i = 0 ; i < suburbs.length ; i++){
            jQuery('#search_Region_Suburb_select').val(suburbs[i]);
        }
    }
}

function clearText(field) {
    if (field.defaultValue == field.value) {
        field.value = '';
    } else if (field.value.strip() == '') {
        field.value = field.defaultValue;
    }
}

function toggleAdvanced(url,type)
{
    var el = document.getElementById("advanced-search");
    if ( el.style.display != 'none' ) {
//        Effect.Fade(el.id, { duration: 0.4, queue: 'front' });
//        Effect.Appear(document.getElementById("quick-search"), { duration: 0.4, queue: 'end' });
        document.getElementById("advanced-search").style.display = "none";
        document.getElementById("quick-search").style.display = "block";
        document.getElementById("advanced-search-link").innerHTML = "Advanced search &raquo;";
    } else {
//        Effect.Fade(document.getElementById("quick-search"), { duration: 0.4, queue: 'front' });
//        Effect.Appear(el.id, { duration: 0.4, queue: 'end' });
        document.getElementById("advanced-search").style.display = "block";
        document.getElementById("quick-search").style.display = "none";
        document.getElementById("advanced-search-link").innerHTML = "Simple search &raquo;";

        /*Only log to DB on open*/
        type = type.replace(" ","+");
        new Ajax.Request(url+'php/advanced_search_tracker.php?type='+type,
        {
            onSuccess : function(response)
            {
                //alert('#win');
            },
            onFailure : function(response)
            {
                //alert('Error loading advanced search');
            }
        });
    }
}

function suburb_search_validation(){
    var ele = jQuery('#suburbinput');
    var ele2 = jQuery('#search_suburb_city');
    var pass = false;
//    jQuery('#search_suggestion').removeClass();
//    jQuery('#search_suggestion').addClass("search_labels_small_white center");
    if(ele.val() != undefined && ele.val() ){
        // redirect to property_search_suburb view via post
        var params = {"suburb_region_suburb_grouping": ele.val()}
        var method = "post";
        post_to_url("http://"+document.domain+"/property_search_suburb/" , params , method);
        pass = false;
    }else{
        if(ele2.val() != undefined && ele2.val()){
            document.remax_search_form.submit();
        }else{
//            jQuery('#search_suggestion').removeClass();
//            jQuery('#search_suggestion').addClass("search_labels_small_white_large center");
            alert('Type an area name and make a selection from the drop down menu.');
            pass = false;
        }
    }
    return pass;
}

function property_search_suburb_submit(ele){
    // redirect to property_search_suburb view via post
    var params = {  "search_suburb_city": ''+jQuery('#'+ele).val() ,
                    "search_type" : 'quick_search' ,
                    'Types' : '1' ,
                    'Payment' : '-1' ,
                    'adv_search_price_from' : '0' ,
                    'adv_search_price_to' : '0'
                }
    var method = "POST";
    post_to_url("http://"+document.domain+"/index.php?page=property_search_response" , params , method);
}


function post_to_url(path, params, method) {
    method = method || "post"; // Set method to post by default, if not specified.

    // The rest of this code assumes you are not using a library.
    // It can be made less wordy if you use one.
    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);

    for(var key in params) {
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", key);
        hiddenField.setAttribute("value", params[key]);

        form.appendChild(hiddenField);
    }

    document.body.appendChild(form);    // Not entirely sure if this is necessary
    form.submit();
}



