function trebBuildURL(form) 
{
	var t_country = document.forms['trebform'].search_country_select.value;
	var t_usCity = document.forms['trebform'].UScitySearch.value;
	var t_usState = document.forms['trebform'].stateSearch.value;
	var t_canCity = document.forms['trebform'].CANcitySearch.value;
	var t_canProv = document.forms['trebform'].provSearch.value;
	var t_city = document.forms['trebform'].citySearch.value;
	if (document.forms['trebform'].search_pricemin) {
		var t_minprice = document.forms['trebform'].search_pricemin.value;
		var t_maxprice = document.forms['trebform'].search_pricemax.value;
		var t_bedrooms = document.forms['trebform'].search_bedrooms.value;
		var t_bathrooms = document.forms['trebform'].search_bathrooms.value;
	}
	else {
		var t_minprice = 0;
		var t_maxprice = 999999999;
		var t_bedrooms = 0;
		var t_bathrooms = 0;
	}	
	var t_trackingCode = document.forms['trebform'].trackingCode.value;
	var t_url = 'http://www.realestatebook.com/homes/';
	
	if(t_country == 'USA') {
		if (t_usCity == '' || t_usCity == null || t_usCity == 'City') {
			t_usCity = '';
		}
		else {
			var intIndexOfMatch = t_usCity.indexOf( ' ' );
			while (intIndexOfMatch != -1){
				// Replace out the current instance.
				t_usCity = t_usCity.replace( ' ', '-' )
				// Get the index of any next matching substring.
				intIndexOfMatch = t_usCity.indexOf( ' ' );
			}
			t_usCity += '-';
		}
		t_url += t_usCity + t_usState + '-' + t_country;
	}
	else if (t_country == 'CAN') {
		if (t_canCity == '' || t_canCity == null || t_canCity == 'City') {
			t_canCity = '';
		}
		else {
			var intIndexOfMatch = t_canCity.indexOf( ' ' );
			while (intIndexOfMatch != -1){
				// Replace out the current instance.
				t_canCity = t_canCity.replace( ' ', '-' )
				// Get the index of any next matching substring.
				intIndexOfMatch = t_canCity.indexOf( ' ' );
			}
			t_canCity += '-';
		}
		t_url += t_canCity + t_canProv + '-' + t_country;
	}
	else {
		if (t_city == '' || t_city == null || t_city == 'City') {
			t_city = '';
		}
		else {
			var intIndexOfMatch = t_city.indexOf( ' ' );
			while (intIndexOfMatch != -1){
				// Replace out the current instance.
				t_city = t_city.replace( ' ', '-' )
				// Get the index of any next matching substring.
				intIndexOfMatch = t_city.indexOf( ' ' );
			}
			t_city += '-';
		}
		if (t_country == 'BHS') { t_url += t_city+'-BS-'+t_country; }
		else if (t_country == 'CYM') { t_url += t_city+'KY-'+t_country; }
		else if (t_country == 'BHS') { t_url += t_city+'BS-'+t_country; }
		else if (t_country == 'DOM') { t_url += t_city+'DO-'+t_country; }
		else if (t_country == 'MEX') { t_url += t_city+'MX-'+t_country; }
		else if (t_country == 'PAN') { t_url += t_city+'PA-'+t_country; }
		else if (t_country == 'PRI') { t_url += t_city+'PR-'+t_country; }
		else if (t_country == 'TCA') { t_url += t_city+'TC-'+t_country; }
		else if (t_country == 'VIR') { t_url += t_city+'VI-'+t_country; }
	}
	if (t_bedrooms!=0 || t_bathrooms !=0) {
		t_url += '/'+t_bedrooms+'-beds/'+t_bathrooms+'-baths';
	}
	if (t_minprice>0 || t_maxprice<999999999) {
		t_url += '/'+t_minprice+'-'+t_maxprice+'-price';
	}
	t_url += t_trackingCode;
	setTimeout(function() { //timeout function is IE bug workaround
		window.location.href = t_url;
	}, 0);	
}

function trebShow(id){
	if (id == 'trebusa') {
		var showid;
		var hideid1;
		var hideid2;
		showid = 'trebusa';
		hideid1 = 'trebcan';
		hideid2 = 'trebother';
	}
	else if (id == 'trebcan') {
		showid = 'trebcan';
		hideid1 = 'trebusa';
		hideid2 = 'trebother';
	}
	else {
		showid = 'trebother';
		hideid1 = 'trebusa';
		hideid2 = 'trebcan';
	}
	if (document.getElementById){
		var obj = document.getElementById(showid);
		obj.style.display = 'block';
		var obj2 = document.getElementById(hideid1);
		obj2.style.display = 'none';
		var obj3 = document.getElementById(hideid2);
		obj3.style.display = 'none';
	}
}
function trebAutoFill(index) {
	var CountryOps = new Array();
	CountryOps.push('trebusa');
	CountryOps.push('trebcan');
	CountryOps.push('none');
	CountryOps.push('none');
	CountryOps.push('none');
	CountryOps.push('none');
	CountryOps.push('none');
	CountryOps.push('none');
	CountryOps.push('none');
	CountryOps.push('none');
	if (CountryOps[index] != null)
	{
		trebShow(CountryOps[index]);
	}
}