
var http_request = false;

function makeRequest(type, url)
{
	http_request = false;
	if (window.XMLHttpRequest) 
	{												// Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) 
		{
			http_request.overrideMimeType('text/xml');
		}
	} 
	else if (window.ActiveXObject) 
	{ 
		try 
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) 
			{
			}
		}
	}
	if (!http_request) 
	{
		alert('Sorry, there is an error.');
		return false;
	}

	if(type == 'city_location'){
		http_request.onreadystatechange = alertContents;
	} else if(type == 'listing_residential'){
		http_request.onreadystatechange = listingResidential;
	} else if(type == 'listing_office'){
		http_request.onreadystatechange = listingOffice;
	} else if(type == 'listing_retail'){
		http_request.onreadystatechange = listingRetail;
	} else if(type == 'listing_ceremonial'){
		http_request.onreadystatechange = listingCeremonial;
	} else if(type == 'listing_storage'){
		http_request.onreadystatechange = listingStorage;
	} else if(type == 'listing_services'){
		http_request.onreadystatechange = listingServices;
	} else if(type == 'listing_roommates'){
		http_request.onreadystatechange = listingRoommates;
	} else if(type == 'listing_shortstay'){
		http_request.onreadystatechange = listingShortstay;
	} else if(type == 'listing_commodities'){
		http_request.onreadystatechange = listingCommodities;
	} else if(type == 'listing_vehicle'){
		http_request.onreadystatechange = listingVehicle;
	} else if(type == 'listing_microsite'){
		http_request.onreadystatechange = listingMicrosite;
	} else if(type == 'search_broker'){
		http_request.onreadystatechange = searchBroker;
	} else if(type == 'search_listing'){
		http_request.onreadystatechange = searchListings;
	} else if(type == 'hm_search_listing'){
		http_request.onreadystatechange = hmSearchListings;
	}

	http_request.open('GET', url, true);
	http_request.send(null);
}

function hmSearchListings()
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200)
		{
			var subobj = document.forms['frmSearch'].location;
			var result = http_request.responseText;
			if(result != ""){
			var actualsubstr = result.split(",");
				subobj.options.length = 1;
				subobj.disabled = false;
				subobj.options[0].value = 'All';
				subobj.options[0].text = 'All Location';
				for(var i=0;i<actualsubstr.length;i++) 
				{
					subobj.options.length ++;
					var again_split = trim(actualsubstr[i]).split("|");
					subobj.options[i+1].value = trim(again_split[0]);
					subobj.options[i+1].text = trim(again_split[1]);
					//if (document.forms['frmSearch'].tmp_location.value == subobj.options[i+1].value)
					//{
					//	subobj.options[i+1].selected = true;
					//}
				}

			} else {
				subobj.options.length = 1;
				subobj.options[0].value = 'All';
				subobj.options[0].text = 'All Location';
				//subobj.options[1].value = '-1';
				//subobj.options[1].text = 'Other';
				//subobj.disabled = true;
			}
		} 
		else 
		{
			alert('Sorry, there was a problem with the request.');
		}
	}
}

function searchListings()
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200)
		{
			var subobj = document.forms['frmSearchCategory'].location;
			var result = http_request.responseText;
			if(result != ""){
			var actualsubstr = result.split(",");
				subobj.options.length = 1;
				subobj.disabled = false;
				subobj.options[0].value = 'All';
				subobj.options[0].text = 'All Location';
				for(var i=0;i<actualsubstr.length;i++) 
				{
					subobj.options.length ++;
					var again_split = trim(actualsubstr[i]).split("|");
					subobj.options[i+1].value = trim(again_split[0]);
					subobj.options[i+1].text = trim(again_split[1]);
					if (document.forms['frmSearchCategory'].tmp_location.value == subobj.options[i+1].value)
					{
						subobj.options[i+1].selected = true;
					}
				}

			} else {
				subobj.options.length = 1;
				subobj.options[0].value = 'All';
				subobj.options[0].text = 'All Location';
				//subobj.options[1].value = '-1';
				//subobj.options[1].text = 'Other';
				//subobj.disabled = true;
			}
		} 
		else 
		{
			alert('Sorry, there was a problem with the request.');
		}
	}
}

function searchBroker()
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var subobj = document.forms['frmSearchBroker'].location;
			var result = http_request.responseText;
			if(result != ""){
			var actualsubstr = result.split(",");
				subobj.options.length = 1;
				subobj.disabled = false;
				subobj.options[0].value = 'All';
				subobj.options[0].text = 'All Location';
				for(var i=0;i<actualsubstr.length;i++) 
				{
					subobj.options.length ++;
					var again_split = trim(actualsubstr[i]).split("|");
					subobj.options[i+1].value = trim(again_split[0]);
					subobj.options[i+1].text = trim(again_split[1]);
				}

			} else {
				subobj.options.length = 1;
				subobj.options[0].value = 'All';
				subobj.options[0].text = 'All Location';
				//subobj.options[1].value = '-1';
				//subobj.options[1].text = 'Other';
				//subobj.disabled = true;
			}
		} 
		else 
		{
			alert('Sorry, there was a problem with the request.');
		}
	}
}

function alertContents()
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var subobj = document.forms['frmregister'].location;
			var result = http_request.responseText;
			if(result != ""){
			var actualsubstr = result.split(",");
				subobj.options.length = 0;
				subobj.disabled = false;
				if(result=='-1|Other'){
					subobj.options.length = 1;
					subobj.options[0].value = '-1';
					subobj.options[0].text = 'Other';
					document.forms['frmregister'].location_other.disabled = false;
				}else{
					for(var i=0;i<actualsubstr.length;i++) 
					{
						subobj.options.length ++;
						var again_split = trim(actualsubstr[i]).split("|");
						subobj.options[i].value = trim(again_split[0]);
						subobj.options[i].text = trim(again_split[1]);
						if(document.forms['frmregister'].lid.value){
							if (document.forms['frmregister'].lid.value == subobj.options[i].value)
							{
								subobj.options[i].selected = true;
							}
						}	
					}
				}
			} else {
				subobj.options.length = 0;
				subobj.disabled = true;
			}
		} 
		else 
		{
			alert('Sorry, there was a problem with the request.');
		}
	}
}

function listingResidential()
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var subobj = document.forms['frmResidentialListing'].location;
			var result = http_request.responseText;
			if(result != ""){
			var actualsubstr = result.split(",");
				subobj.options.length = 0;
				subobj.disabled = false;
				if(result=='-1|Other'){
					subobj.options.length = 1;
					subobj.options[0].value = '-1';
					subobj.options[0].text = 'Other';
					document.forms['frmResidentialListing'].location_other.disabled = false;
				}else{
					for(var i=0;i<actualsubstr.length;i++) 
					{
						subobj.options.length ++;
						var again_split = trim(actualsubstr[i]).split("|");
						subobj.options[i].value = trim(again_split[0]);
						subobj.options[i].text = trim(again_split[1]);
						if(document.forms['frmResidentialListing'].lid.value){
							if (document.forms['frmResidentialListing'].lid.value == subobj.options[i].value)
							{
								subobj.options[i].selected = true;
							}
						}
					}
				}
			} else {
				subobj.options.length = 0;
				subobj.disabled = true;
				//subobj.options.length = 1;
				//subobj.options[0].value = '-1';
				//subobj.options[0].text = 'Other';
				//document.forms['frmResidentialListing'].location_other.disabled = false;
			}
		} 
		else 
		{
			alert('Sorry, there was a problem with the request.');
		}
	}
}

function listingMicrosite()
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var subobj = document.forms['frmMicrositeListing'].location;
			var result = http_request.responseText;
			if(result != ""){
			var actualsubstr = result.split(",");
				subobj.options.length = 0;
				subobj.disabled = false;
				if(result=='-1|Other'){
					subobj.options.length = 1;
					subobj.options[0].value = '-1';
					subobj.options[0].text = 'Other';
					document.forms['frmMicrositeListing'].location_other.disabled = false;
				}else{
					for(var i=0;i<actualsubstr.length;i++) 
					{
						subobj.options.length ++;
						var again_split = trim(actualsubstr[i]).split("|");
						subobj.options[i].value = trim(again_split[0]);
						subobj.options[i].text = trim(again_split[1]);
						if(document.forms['frmMicrositeListing'].lid.value){
							if (document.forms['frmMicrositeListing'].lid.value == subobj.options[i].value)
							{
								subobj.options[i].selected = true;
							}
						}
					}
				}
			} else {
				subobj.options.length = 0;
				subobj.disabled = true;
				//subobj.options.length = 1;
				//subobj.options[0].value = '-1';
				//subobj.options[0].text = 'Other';
				//document.forms['frmMicrositeListing'].location_other.disabled = false;
			}
		} 
		else 
		{
			alert('Sorry, there was a problem with the request.');
		}
	}
}

function listingVehicle()
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var subobj = document.forms['frmVehicleListing'].location;
			var result = http_request.responseText;
			if(result != ""){
			var actualsubstr = result.split(",");
				subobj.options.length = 0;
				subobj.disabled = false;
				if(result=='-1|Other'){
					subobj.options.length = 1;
					subobj.options[0].value = '-1';
					subobj.options[0].text = 'Other';
					document.forms['frmVehicleListing'].location_other.disabled = false;
				}else{
					for(var i=0;i<actualsubstr.length;i++)
					{
						subobj.options.length ++;
						var again_split = trim(actualsubstr[i]).split("|");
						subobj.options[i].value = trim(again_split[0]);
						subobj.options[i].text = trim(again_split[1]);
						if(document.forms['frmVehicleListing'].lid.value){
							if (document.forms['frmVehicleListing'].lid.value == subobj.options[i].value)
							{
								subobj.options[i].selected = true;
							}
						}
					}
				}
			} else {
				subobj.options.length = 0;
				subobj.disabled = true;
			}
		} 
		else 
		{
			alert('Sorry, there was a problem with the request.');
		}
	}
}

function listingRoommates()
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var subobj = document.forms['frmRoommatesListing'].location;
			var result = http_request.responseText;
			if(result != ""){
			var actualsubstr = result.split(",");
				subobj.options.length = 0;
				subobj.disabled = false;
				if(result=='-1|Other'){
					subobj.options.length = 1;
					subobj.options[0].value = '-1';
					subobj.options[0].text = 'Other';
					document.forms['frmRoommatesListing'].location_other.disabled = false;
				}else{
					for(var i=0;i<actualsubstr.length;i++) 
					{
						subobj.options.length ++;
						var again_split = trim(actualsubstr[i]).split("|");
						subobj.options[i].value = trim(again_split[0]);
						subobj.options[i].text = trim(again_split[1]);
						if(document.forms['frmRoommatesListing'].lid.value){
							if (document.forms['frmRoommatesListing'].lid.value == subobj.options[i].value)
							{
								subobj.options[i].selected = true;
							}
						}
					}
				}
			} else {
				subobj.options.length = 0;
				subobj.disabled = true;
			}
		} 
		else 
		{
			alert('Sorry, there was a problem with the request.');
		}
	}
}

function listingOffice()
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var subobj = document.forms['frmOfficeListing'].location;
			var result = http_request.responseText;
			if(result != ""){
			var actualsubstr = result.split(",");
				subobj.options.length = 0;
				subobj.disabled = false;
				if(result=='-1|Other'){
					subobj.options.length = 1;
					subobj.options[0].value = '-1';
					subobj.options[0].text = 'Other';
					document.forms['frmOfficeListing'].location_other.disabled = false;
				}else{
					for(var i=0;i<actualsubstr.length;i++) 
					{
						subobj.options.length ++;
						var again_split = trim(actualsubstr[i]).split("|");
						subobj.options[i].value = trim(again_split[0]);
						subobj.options[i].text = trim(again_split[1]);
						if(document.forms['frmOfficeListing'].lid.value){
							if (document.forms['frmOfficeListing'].lid.value == subobj.options[i].value)
							{
								subobj.options[i].selected = true;
							}
						}
					}
				}
			} else {
				subobj.options.length = 0;
				subobj.disabled = true;
			}
		} 
		else 
		{
			alert('Sorry, there was a problem with the request.');
		}
	}
}

function listingRetail()
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var subobj = document.forms['frmRetailListing'].location;
			var result = http_request.responseText;
			if(result != ""){
			var actualsubstr = result.split(",");
				subobj.options.length = 0;
				subobj.disabled = false;
				if(result=='-1|Other'){
					subobj.options.length = 1;
					subobj.options[0].value = '-1';
					subobj.options[0].text = 'Other';
					document.forms['frmRetailListing'].location_other.disabled = false;
				}else{
					for(var i=0;i<actualsubstr.length;i++) 
					{
						subobj.options.length ++;
						var again_split = trim(actualsubstr[i]).split("|");
						subobj.options[i].value = trim(again_split[0]);
						subobj.options[i].text = trim(again_split[1]);
						if(document.forms['frmRetailListing'].lid.value){
							if (document.forms['frmRetailListing'].lid.value == subobj.options[i].value)
							{
								subobj.options[i].selected = true;
							}
						}
					}
				}
			} else {
				subobj.options.length = 0;
				subobj.disabled = true;
			}
		} 
		else 
		{
			alert('Sorry, there was a problem with the request.');
		}
	}
}

function listingShortstay()
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var subobj = document.forms['frmShortstayListing'].location;
			var result = http_request.responseText;
			if(result != ""){
			var actualsubstr = result.split(",");
				subobj.options.length = 0;
				subobj.disabled = false;
				if(result=='-1|Other'){
					subobj.options.length = 1;
					subobj.options[0].value = '-1';
					subobj.options[0].text = 'Other';
					document.forms['frmShortstayListing'].location_other.disabled = false;
				}else{
					for(var i=0;i<actualsubstr.length;i++) 
					{
						subobj.options.length ++;
						var again_split = trim(actualsubstr[i]).split("|");
						subobj.options[i].value = trim(again_split[0]);
						subobj.options[i].text = trim(again_split[1]);
						if(document.forms['frmShortstayListing'].lid.value){
							if (document.forms['frmShortstayListing'].lid.value == subobj.options[i].value)
							{
								subobj.options[i].selected = true;
							}
						}
					}
				}
			} else {
				subobj.options.length = 0;
				subobj.disabled = true;
			}
		} 
		else 
		{
			alert('Sorry, there was a problem with the request.');
		}
	}
}

function listingCommodities()
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var subobj = document.forms['frmCommoditiesListing'].location;
			var result = http_request.responseText;
			if(result != ""){
			var actualsubstr = result.split(",");
				subobj.options.length = 0;
				subobj.disabled = false;
				if(result=='-1|Other'){
					subobj.options.length = 1;
					subobj.options[0].value = '-1';
					subobj.options[0].text = 'Other';
					document.forms['frmCommoditiesListing'].location_other.disabled = false;
				}else{
					for(var i=0;i<actualsubstr.length;i++) 
					{
						subobj.options.length ++;
						var again_split = trim(actualsubstr[i]).split("|");
						subobj.options[i].value = trim(again_split[0]);
						subobj.options[i].text = trim(again_split[1]);
						if(document.forms['frmCommoditiesListing'].lid.value){
							if (document.forms['frmCommoditiesListing'].lid.value == subobj.options[i].value)
							{
								subobj.options[i].selected = true;
							}
						}
					}
				}
			} else {
				subobj.options.length = 0;
				subobj.disabled = true;
			}
		} 
		else 
		{
			alert('Sorry, there was a problem with the request.');
		}
	}
}

function listingCeremonial()
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var subobj = document.forms['frmCeremonialListing'].location;
			var result = http_request.responseText;
			if(result != ""){
			var actualsubstr = result.split(",");
				subobj.options.length = 0;
				subobj.disabled = false;
				if(result=='-1|Other'){
					subobj.options.length = 1;
					subobj.options[0].value = '-1';
					subobj.options[0].text = 'Other';
					document.forms['frmCeremonialListing'].location_other.disabled = false;
				}else{
					for(var i=0;i<actualsubstr.length;i++) 
					{
						subobj.options.length ++;
						var again_split = trim(actualsubstr[i]).split("|");
						subobj.options[i].value = trim(again_split[0]);
						subobj.options[i].text = trim(again_split[1]);
						if(document.forms['frmCeremonialListing'].lid.value){
							if (document.forms['frmCeremonialListing'].lid.value == subobj.options[i].value)
							{
								subobj.options[i].selected = true;
							}
						}
					}
				}
			} else {
				subobj.options.length = 0;
				subobj.disabled = true;
			}
		} 
		else 
		{
			alert('Sorry, there was a problem with the request.');
		}
	}
}

function listingStorage()
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var subobj = document.forms['frmStorageListing'].location;
			var result = http_request.responseText;
			if(result != ""){
			var actualsubstr = result.split(",");
				subobj.options.length = 0;
				subobj.disabled = false;
				if(result=='-1|Other'){
					subobj.options.length = 1;
					subobj.options[0].value = '-1';
					subobj.options[0].text = 'Other';
					document.forms['frmStorageListing'].location_other.disabled = false;
				}else{
					for(var i=0;i<actualsubstr.length;i++) 
					{
						subobj.options.length ++;
						var again_split = trim(actualsubstr[i]).split("|");
						subobj.options[i].value = trim(again_split[0]);
						subobj.options[i].text = trim(again_split[1]);
						if(document.forms['frmStorageListing'].lid.value){
							if (document.forms['frmStorageListing'].lid.value == subobj.options[i].value)
							{
								subobj.options[i].selected = true;
							}
						}
					}
				}
			} else {
				subobj.options.length = 0;
				subobj.disabled = true;
			}
		} 
		else 
		{
			alert('Sorry, there was a problem with the request.');
		}
	}
}

function listingServices()
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var subobj = document.forms['frmServicesListing'].location;
			var result = http_request.responseText;
			if(result != ""){
			var actualsubstr = result.split(",");
				subobj.options.length = 0;
				subobj.disabled = false;
				if(result=='-1|Other'){
					subobj.options.length = 1;
					subobj.options[0].value = '-1';
					subobj.options[0].text = 'Other';
					document.forms['frmServicesListing'].location_other.disabled = false;
				}else{
					for(var i=0;i<actualsubstr.length;i++) 
					{
						subobj.options.length ++;
						var again_split = trim(actualsubstr[i]).split("|");
						subobj.options[i].value = trim(again_split[0]);
						subobj.options[i].text = trim(again_split[1]);
						if(document.forms['frmServicesListing'].lid.value){
							if (document.forms['frmServicesListing'].lid.value == subobj.options[i].value)
							{
								subobj.options[i].selected = true;
							}
						}
					}
				}
			} else {
				subobj.options.length = 0;
				subobj.disabled = true;
			}
		} 
		else 
		{
			alert('Sorry, there was a problem with the request.');
		}
	}
}

function trim(str)
{
	s = str.replace(/^(\s)*/, '');
	s = s.replace(/(\s)*$/, '');
	return s;
}
