// Quick Search
function openWin(url)
{
	winPopup.height = 675;
	winPopup.width = 545;
	winPopup.top = screen.availHeight - (screen.availHeight/2) -(winPopup.height/2);
	winPopup.left = screen.availWidth - (screen.availWidth/2) -(winPopup.width/2);
	winPopup.url = url;
	winPopup.open();
}

function clearForEntry(obj)
{
	if(obj.value == "City" || obj.value == "Zip" || obj.value == "MLS#")
		obj.value = "";
}


function testForValidEntry(obj)
{
	var confirmText = "You can only search by one of these fields (City, Zip Code or MLS) at a time.\n\nWould you like to clear out the other fields and keep the value that you just entered?";
	
	switch(obj.id)
	{
		case "txtCity":
			if(obj.value == "")
				obj.value = "City";
			else
			{
				if(obj.value != "City" && (document.getElementById('txtZipCode').value != "Zip" || document.getElementById('txtMLSID').value != "MLS#"))
				{
					if(confirm(confirmText))
					{
						document.getElementById('txtZipCode').value = "Zip";
						document.getElementById('txtMLSID').value = "MLS#";
					}
					else
						document.getElementById('txtCity').value = "City";
				}
			}
			break;
		case "txtZipCode":
			if(obj.value == "")
				obj.value = "Zip";
			else
			{
				if(obj.value != "Zip" && (document.getElementById('txtCity').value != "City" || document.getElementById('txtMLSID').value != "MLS#"))
				{
					if(confirm(confirmText))
					{
						document.getElementById('txtCity').value = "City";
						document.getElementById('txtMLSID').value = "MLS#";
						validateZipCode(obj.value);
					}
					else
						document.getElementById('txtZipCode').value = "Zip";
				}
				else
				{
					validateZipCode(obj.value);
				}
			}
			break;
		case "txtMLSID":
			if(obj.value == "")
				obj.value = "MLS#";
			else
			{
				if(obj.value != "MLS#" && (document.getElementById('txtCity').value != "City" || document.getElementById('txtZipCode').value != "Zip"))
				{
					if(confirm(confirmText))
					{
						document.getElementById('txtCity').value = "City";
						document.getElementById('txtZipCode').value = "Zip";
					}
					else
						document.getElementById('txtMLSID').value = "MLS#";
				}
			}
			break;
	}
}

function validateZipCode(number)
{
	if(number != "Zip" && (isNaN(number) || (number.toString().length != 5)))
	{
		alert("Please enter a valid zip code.");
		document.getElementById('txtZipCode').value = "Zip";
	}
}

function submitQuickSearch()
{
	var bolError = false;
	var errorMessage = "";
	
	if(document.getElementById('txtCity').value == "City" && document.getElementById('txtZipCode').value == "Zip" && document.getElementById('txtMLSID').value == "MLS#")
	{
		errorMessage += "Please enter a City, Zip Code or MLS number.\n";
		bolError = true;
	}
	
	if(document.getElementById("cboMinPrice").value != "" && document.getElementById("cboMaxPrice").value != "")
	{
		if(parseInt(document.getElementById("cboMinPrice").value) > parseInt(document.getElementById("cboMaxPrice").value))
		{
			errorMessage += "Your minimum price cannot be higher that your maximum price.\n";
			bolError = true;
		}
	}
	
	if(document.getElementById("cboMinBeds").value != "" && document.getElementById("cboMaxBeds").value != "")
	{
		if(parseInt(document.getElementById("cboMinBeds").value) > parseInt(document.getElementById("cboMaxBeds").value))
		{
			errorMessage += "Your minimum number of bedrooms cannot be higher that your maximum number of bedrooms.\n";
			bolError = true;
		}
	}
	
	if(document.getElementById("cboMinBaths").value != "" && document.getElementById("cboMaxBaths").value != "")
	{
		if(parseInt(document.getElementById("cboMinBaths").value) > parseInt(document.getElementById("cboMaxBaths").value))
		{
			errorMessage += "Your minimum number of bathrooms cannot be higher that your maximum number of bathrooms.\n";
			bolError = true;
		}
	}
	
	if(bolError)
		alert(errorMessage);
	else
	{
		var l = "";
		
		if(document.getElementById('txtMLSID').value == "MLS#")
			l = "/Search/Default.aspx?ID=" + "&type=R&submit=T" + (encodeURIComponent(document.getElementById('txtCity').value) != "City" ? "&City=" + encodeURIComponent(document.getElementById('txtCity').value) : "") + (document.getElementById('txtZipCode').value != "Zip" ? "&zip=" + encodeURIComponent(document.getElementById('txtZipCode').value) : "") + "&class=" + encodeURIComponent(document.getElementById("cboPropertyType").value) + "&NPR=" + encodeURIComponent(document.getElementById("cboMinPrice").value) + "&XPR=" + encodeURIComponent(document.getElementById("cboMaxPrice").value) + "&NBD=" + encodeURIComponent(document.getElementById("cboMinBeds").value) + "&XBD=" + encodeURIComponent(document.getElementById("cboMaxBeds").value) + "&NBA=" + encodeURIComponent(document.getElementById("cboMinBaths").value) + "&XBA=" + encodeURIComponent(document.getElementById("cboMaxBaths").value);		
		else
			l = "/Search/Default.aspx?ID=" + "&type=I&submit=T&LID=" + encodeURIComponent(document.getElementById('txtMLSID').value) + "&class=" + encodeURIComponent(document.getElementById("cboPropertyType").value) + "&NPR=" + encodeURIComponent(document.getElementById("cboMinPrice").value) + "&XPR=" + encodeURIComponent(document.getElementById("cboMaxPrice").value) + "&NBD=" + encodeURIComponent(document.getElementById("cboMinBeds").value) + "&XBD=" + encodeURIComponent(document.getElementById("cboMaxBeds").value) + "&NBA=" + encodeURIComponent(document.getElementById("cboMinBaths").value) + "&XBA=" + encodeURIComponent(document.getElementById("cboMaxBaths").value);
		// HAAAACK -- safari seems to have a bug and won't allow the location property to be set for an individual frame, mja
		if(SE_UserAgent('safari'))
			top.location.href = l;
		else
			location = l;
	}
}