// Quick Search

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(CountyList,State)
{
	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?ST=" + State +"&County=" + CountyList + "&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;
	}
}

function submitShortQuickSearch(CountyList)
{
	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(bolError)
		alert(errorMessage);
	else
	{
		var l = "";
		
		if(document.getElementById('txtMLSID').value == "MLS#")
			l = "/Search/Default.aspx?ST=PA&County=" + CountyList + "&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) : "");		
		else
			l = "/Search/Default.aspx?ID=" + "&type=I&submit=T&LID=" + encodeURIComponent(document.getElementById('txtMLSID').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;
	}
}

function submitFullQuickSearch(CountyList)
{
    var pool = "";
    var fireplace = "";
    var photo = "";
    var tour = "";
    var clo = "";
    var sold = "";
    var bankowned = "";
    
	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("cboSqFtMin").value != "" && document.getElementById("cboSqFtMax").value != "")
	{
		if(parseInt(document.getElementById("cboSqFtMin").value) > parseInt(document.getElementById("cboSqFtMax").value))
		{
			errorMessage += "Your minimum square feet cannot be higher that your maximum square Feet.\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(document.getElementById("chkPool").checked == true)
	{
        pool = "T";
    }
    
	if(document.getElementById("chkFireplace").checked == true)
	{
        fireplace = "T";
    }    

	if(document.getElementById("chkPic").checked == true)
	{
        photo = "T";
    }

	if(document.getElementById("chkTour").checked == true)
	{
        tour = "T";
    }        
	
	if(document.getElementById("chkREO").checked == true)
	{
        bankowned = "Y";
    }        
		
	if(document.getElementById("chkCLO").checked == true)
	{
        clo = "Y";
    }	
	
	//if(document.getElementById("chkSold").checked == true)
	//{
    //    sold = "Y";
    //}		
	//+ "&DBS=" + encodeURIComponent(document.getElementById("cboDBS").value) 
	
	if(bolError)
		alert(errorMessage);
	else
	{
		var l = "";
		
		if(document.getElementById('txtMLSID').value == "MLS#")
			l = "/Search/Default.aspx?ST=PA&County=" + CountyList + "&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) + "&GAR=" + encodeURIComponent(document.getElementById("cboGarage").value) + "&STORY=" + encodeURIComponent(document.getElementById("cboStories").value) + "&NSQ=" + encodeURIComponent(document.getElementById("cboSqFtMin").value) + "&XSQ=" + encodeURIComponent(document.getElementById("cboSqFtMax").value) + "&AGE=" + encodeURIComponent(document.getElementById("cboAge").value) + "&STREET=" + encodeURIComponent(document.getElementById("txtStreetName").value) + "&PIC=" + photo + "&POOL=" + pool + "&TOUR=" + tour + "&CLO=" + clo + "&FP=" + fireplace + "&BANKOWNED=" + bankowned + "&CSS=" + sold + "&DBL=" + encodeURIComponent(document.getElementById("cboDBL").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) + "&GAR=" + encodeURIComponent(document.getElementById("cboGarage").value) + "&STORY=" + encodeURIComponent(document.getElementById("cboStories").value) + "&NSQ=" + encodeURIComponent(document.getElementById("cboSqFtMin").value) + "&XSQ=" + encodeURIComponent(document.getElementById("cboSqFtMax").value) + "&AGE=" + encodeURIComponent(document.getElementById("cboAge").value) + "&STREET=" + encodeURIComponent(document.getElementById("txtStreetName").value) + "&PIC=" + photo + "&POOL=" + pool + "&TOUR=" + tour + "&CLO=" + clo + "&FP=" + fireplace + "&CSS=" + sold + "&BANKOWNED=" + bankowned + "&DBL=" + encodeURIComponent(document.getElementById("cboDBL").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;
	}
}

