// This will remove the helper input text
function handleInput(inputID,helpText) {
	
	if($(inputID).value == helpText) {
		$(inputID).value="";
		$(inputID).focus();
	} 
}
// This will restore the helper input text if the field is left blank
function restoreInput(inputID,helpText) {
	if($(inputID).value == '') {
		$(inputID).value=helpText;
	}
}


// If the xxxxx_to values are set to their max or left as they are to start with, set them to "" which will 
// leave out a max value in the search query
function rs_formChecker() {
	
	if($('rent_row2')) {
		// Price To: Rent (Max:1,000)
		if($('price_to_refine_id')) {
			//rent for the year 52*1000
			if($('price_to_refine_id').value == "52000") {
				$('price_to_refine_id').value = "";	
			}
		}
	}
	
	if($('buy_row2')) {
		// Price To (Max:10,000,000)
		if($('price_to_refine_id')) {
			if($('price_to_refine_id').value == "10000000") {
				$('price_to_refine_id').value = "";	
			}
		}
	}
	
	// Bedrooms To (Max:10)
	if($('no_of_bedrooms_refine_to')) {
		if($('no_of_bedrooms_refine_to').value == "10") {
			$('no_of_bedrooms_refine_to').value = "";	
		}
	}
	
	// Bathrooms To (Max:10)
	if($('no_of_bathrooms_refine_to')) {
		if($('no_of_bathrooms_refine_to').value == "10") {
			$('no_of_bathrooms_refine_to').value = "";	
		}
	}
	
	// Land To (Max:50)
	if($('land_to_id')) {
		if($('land_to_id').value == "50") {
			$('land_to_id').value = "";	
		}
	}
	
	return true;	
}

function formChecker() {
	
    // *** robertv - 27/06/2011 - job 15560 ***
    //If the property ID is filled out, then the other fields are no longer mandatory
    if($('id_num')){
        var id_value = $('id_num').value;
        if(id_value.length > 0 && id_value != 'Enter Property ID' && id_value != 'Property Web Id'){
            return true;
        }
    }
    // *** end robertv - 27/06/2011 - job 15560 ***
	
	//IE selects the first element with a name or id of state, so we need to do a workaround for pages with the refine search form
	$$('select').filterByAttribute('id', '=', 'state').each( function(a, i) {
		state_elt=a;
	});
	if(state_elt) {
		if(state_elt.value=="") {
			alert("Please choose a state to search");
			state_elt.focus();
			return false;
		}
	}
	
	//get the selected realist type using the workaround
	var type_chosen='';
	$$('select').filterByAttribute('id', '=', 'realist_type').each( function(a, i) {
		type_chosen=a.getValue();
	});
	
	//get the location element
	var location_elt=false;
	$$('input').filterByAttribute('id', '=', 'location').each( function(a, i) {
		location_elt=a;
	});
		if(location_elt) 
		{
			if(type_chosen == "R" || type_chosen == "L") {
				
				if(location_elt.value=="Location or postcode" || location_elt.value=="Location, postcode or property web Id") {
					alert("Please enter a location (suburb or postcode) to search.\n\nUse commas to seperate multiple location.");
					location_elt.value="";
					location_elt.focus();
					return false;
				} 
				
			} else { 
				if(location_elt.value == "Location or postcode" || location_elt.value=="Location, postcode or property web Id") {
					location_elt.value="";
				}
			}
		
		}
	
	if($('property_name_id')) {
		if($('property_name_id').value=="Property/Station Name") {
			$('property_name_id').value="";
		}
	}
	
	// If the xxxxx_to values are set to their max or left as they are to start with, set them to "" which will 
	// leave out a max value in the search query

	// If Buy is selected
	if($('sale_type_S').checked==true) { 
		
		// Buy: Price To (Max:10,000,000)
		if($('price_to_new_search_id')) {
			if($('price_to_new_search_id').value == "10000000") {
				$('price_to_new_search_id').value = "";	
			}
		}
		
		// Buy: Price From - If 0, set to "" so it includes auction properties.
		if($('price_from_new_search_id')) {
			if($('price_from_new_search_id').value == "0") {
				$('price_from_new_search_id').value = "";	
			}
		}
		
	} else {
		
		// Rent: Price To (Max:1,000)
		if($('price_to_new_search_id')) {
			//rent for the year 52*1000
			if($('price_to_new_search_id').value == "52000") {
				$('price_to_new_search_id').value = "";	
			}
		}
		
		// Rent: Price From - If 0, set to "" so it includes auction properties
		if($('price_from_new_search_id')) {
			//rent for the year 52*1000
			if($('price_from_new_search_id').value == "0") {
				$('price_from_new_search_id').value = "";	
			}
		}
		
	}
	
	// Bedrooms To (Max:10)
	if($('bedrooms_to')) {
		if($('bedrooms_to').value == "10") {
			$('bedrooms_to').value = "";	
		}
	}
	
	// Bathrooms To (Max:10)
	if($('bathrooms_to')) {
		if($('bathrooms_to').value == "10") {
			$('bathrooms_to').value = "";	
		}
	}
	
	// Land To (Max:50)
	if($('land_to_new_search_id')) {
		if($('land_to_new_search_id').value == "50") {
			$('land_to_new_search_id').value = "";	
		}
	}
	
	
	// Building To (Max:300)
	if($('bldg_area_range_to_search_id')) {
		if($('bldg_area_range_to_search_id').value == "300") {
			$('bldg_area_range_to_search_id').value = "";	
		}
	}
	
	return true;	

}
function getListingMapIcons(){
	var ret=new Array();
	
	//create a default icon
	var listing_icon = new GIcon(G_DEFAULT_ICON);
	listing_icon.shadow = "/listing/images/map_shadow.png";
	listing_icon.image = "/listing/images/map_marker.png";
	listing_icon.printImage = "/listing/images/map_print_marker.gif";
	listing_icon.mozPrintImage = "/listing/images/map_marker.png";
	listing_icon.transparent = "/listing/images/map_transparent.png";
	//we do not want to print the shadow as it must be a gif, which will cover map detail
	listing_icon.printShadow = null;
	listing_icon.iconSize = new GSize(14, 26);
	listing_icon.shadowSize = new GSize(25, 26);
	listing_icon.iconAnchor = new GPoint(6, 26);
	//large icons
	//listing_icon.imageMap = [0,6, 2,4, 3,3, 7,0, 15,0, 17,1, 20,5, 21,7, 21,13, 20,16, 16,20, 14,21, 10,21, 10,33, 8,33, 8,21, 6,21, 1,14, 0,8];
	//small icons
	listing_icon.imageMap = [0,3, 3,0, 9,0, 14,3, 14,9, 9,13, 8,13, 8,25, 6,25, 6,13, 4,13, 0,9];
	listing_icon.infoWindowAnchor = new GPoint(9, 2);
	
	//now use it as a base to create the others
	
	//array references should be ret['<realist_type>']
	//residential
	ret['R']=new GIcon(listing_icon);
	ret['R'].image = "/listing/images/map_marker_teal.png";
	ret['R'].printImage = "/listing/images/map_print_teal.gif";
	ret['R'].mozPrintImage = "/listing/images/map_marker_teal.png";
	
	//holiday rental
	ret['H']=ret['R'];
	
	//rural
	ret['RP']=new GIcon(listing_icon);
	ret['RP'].image = "/listing/images/map_marker_red.png";
	ret['RP'].printImage = "/listing/images/map_print_red.gif";
	ret['RP'].mozPrintImage = "/listing/images/map_marker_red.png";
	
	//rural residential
	ret['RU']=ret['RP'];
	
	//lifestyle
	ret['L']=new GIcon(listing_icon);
	ret['L'].image = "/listing/images/map_marker_green.png";
	ret['L'].printImage = "/listing/images/map_print_green.gif";
	ret['L'].mozPrintImage = "/listing/images/map_marker_green.png";
	
	//land
	ret['V']=new GIcon(listing_icon);
	ret['V'].image = "/listing/images/map_marker_orange.png";
	ret['V'].printImage = "/listing/images/map_print_orange.gif";
	ret['V'].mozPrintImage = "/listing/images/map_marker_orange.png";
	
	//commercial
	ret['C']=new GIcon(listing_icon);
	ret['C'].image = "/listing/images/map_marker_blue.png";
	ret['C'].printImage = "/listing/images/map_print_blue.gif";
	ret['C'].mozPrintImage = "/listing/images/map_marker_blue.png";
	
	//business
	ret['B']=ret['C'];
	
	return ret;
}

function getRegionsFromState(form_id,region_id) {

	frm = document.getElementById(form_id);
	var url = '/ajax_get_suburbs.php?'+$(form_id).toQueryString();
	var regions=$(region_id);
	regions.options.length=0;
	regions.options[0] = new Option('--- Loading ---','');
	
	/*** robertv - 27/03/2009 - job 10118 - added method get ***/
	new Ajax(url, {evalResponse: true,
					method: 'get'}
			).request();
	/*** end robertv - 27/03/2009 - job 10118 ***/
}

// populateHiddenRegion is used on the home page to pass the selected region to a hidden field to be sent with the form submission
function populateHiddenRegion() {
	if($('region_name')) {
		var selectedRegion = $('listing_search').region.options[$('listing_search').region.selectedIndex].text;
		$('region_name').value=selectedRegion;
	}
}

// Use this function to share the current page on facebook
function fbs_click() {
	u=location.href;t=document.title; 
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

// Home Page Region Search Form Checker
function home_region_formChecker() {
	
	if ($('listing_search').state.getValue() == "") {
		alert("Please select a State");
		return false;
	} else {
		
		if ( 
			 $('listing_search').state.getValue() == "ACT" && $('listing_search').region.getValue() == "" || 
			 $('listing_search').state.getValue() == "NSW" && $('listing_search').region.getValue() == "" || 
			 $('listing_search').state.getValue() == "QLD" && $('listing_search').region.getValue() == "" || 
			 $('listing_search').state.getValue() == "SA"  && $('listing_search').region.getValue() == "" || 
			 $('listing_search').state.getValue() == "VIC" && $('listing_search').region.getValue() == "" ||
			 $('listing_search').state.getValue() == "WA"  && $('listing_search').region.getValue() == "" 
			) 
		{
			alert("Please select a Region");
			// don't submit the form
			return false;
		} else {
			// submit the form
			return true;
		}
		
	}
}

