    var str_current_suburb = "";        	
    var str_current_link_str_id = "";
    var int_returntodefault_timeout = -1;
	var updateMap = true;
		
    function e(id){
        return document.getElementById(id);
    }
	
    function onLinkClick(id, str_id, str_asp_link_id){			
        str_current_link_str_id = str_id;
	    showSuburb(str_id);
		updateMap = false;
		UpdateRegionOption(id);
		updateMap = true;
    }

    function onTextLinkClick(id, str_id,str_asp_link_id)
    {
        hideSuburb(str_current_suburb);	
        str_current_suburb = str_id;
        onLinkClick(id,str_id, str_asp_link_id);
    }
    
    function onSuburbOver(str_suburb_id){	
        clearTimeout(int_returntodefault_timeout);	
        hideSuburb(str_current_suburb);				
        str_current_suburb = str_suburb_id;		
        showSuburb(str_current_suburb);	
    }
   
    function onSuburbOut(){		
        if (str_current_suburb == str_current_link_str_id){
	        return;
        }		
        hideSuburb(str_current_suburb);		
        str_current_suburb = "";	
        int_returntodefault_timeout = setTimeout("returnToDefault()", 50);
    }
	
    function returnToDefault(){
        if (str_current_link_str_id.length > 0 ){
	        onSuburbOver(str_current_link_str_id);
        }	
    }	
	
    function showSuburb(str_id){			
        if (e("img-off-" + str_current_suburb)){
	        e("img-off-" + str_current_suburb).className="hide";
        }
        if (e("img-on-" + str_current_suburb)){
	        e("img-on-" + str_current_suburb).className="show";
        }
        if (e("text-" + str_current_suburb)){
	        e("text-" + str_current_suburb).className="show";
        }		
    }	

    function hideSuburb(str_id){	
        if (e("img-off-" + str_id)){
	        e("img-off-" + str_id).className="show";
        }
        if (e("img-on-" + str_id)){
	        e("img-on-" + str_id).className="hide";
        }		
        if (e("text-" + str_id)){
	        e("text-" + str_id).className="show";
        }	
    }
	
	function UpdateRegionOption(id)
	{		
		//Update the map
		if(updateMap)
		{
			var str_id;
			switch(id)
			{
				case '1': str_id = "auckland"; break;	
				case '2': str_id = "bay-of-plenty"; break;
				case '3': str_id = "canterbury"; break;
				case '4': str_id = "coromandel"; break;
				case '5': str_id = "gisborne"; break;
				case '6': str_id = "hawkes-bay"; break;
				case '7': str_id = "manawatu-and-wanganui"; break;
				case '18': str_id = "manawatu-and-wanganui"; break;
				case '8': str_id = "marlborough"; break;
				case '9': str_id = "nelson-and-tasman"; break;
				case '10': str_id = "northland"; break;				
				case '12': str_id = "otago"; break;
				case '13': str_id = "southland"; break;			
				case '15': str_id = "taranaki"; break;
				case '16': str_id = "waikato"; break;
				case '17': str_id = "wellington"; break;				
				case '20': str_id = "west-coast"; break;				
			}
			hideSuburb(str_current_suburb);	
			str_current_suburb = str_id;
			str_current_link_str_id = str_id;
			showSuburb(str_id);
		}
		
		$('select#region').children().each(function()
		{
			var optId = $(this).val();
			if($(this).attr('selected') && optId != id)
			{
				$(this).attr('selected', false);
			}
			else if(optId == id)
			{
				$(this).attr('selected', true);
			}
		});
		
		//Update the city list
		var ajaxUrl = "/Async/GetAllCityAndSuburbByRegionId.asp?rid=" + escape(id);
		$.ajax({url: ajaxUrl, cache: false, success: function(data){	
			var dataArr = data.split("[#$%]");
			$('div#citySelectWrapper').html(dataArr[0]);
			$('div#suburbSelectWrapper').html(dataArr[1]);
		}});
	}
	
	function UpdateSuburbMultiple(id)
	{
		var ajaxUrl = "/Async/GetAllSuburbByCityId.asp?cid=" + escape(id);
		  $.ajax({url: ajaxUrl, cache: false, success: function(data){				  
			  $('div#suburbSelectWrapper').html(data);
		  }});
	}
	
	function ResetHomepageSearchForm()
    {
		document.forms['homepageSearchForm'].reset();
	    UpdateRegionOption(0);		
    }
