﻿function setEnterEvent() {
	jQuery("#qfsearchbox").keypress(function(e) {
		if (e.which == 13) {
			searchHomes();
		}
		else return false;
	});
}

function showQFOptions() {
	jQuery('#qfoptionscont table').slideDown('slow', function() { jQuery('.qfoptions').hide(); });
}

function hideQFOptions() {
	jQuery('#qfoptionscont table').slideUp('slow', function() { jQuery('.qfoptions').show(); });
}

function searchHomes() {
	if (validateSearchBox()) {
		hideQFOptions();
		internalSearch()
		return false;
	}
	else {
		return false;
	}
}

function qfExternalSearch() {
	if (validateSearchBox()) {
		externalSearch();
		return false;
	}
	else
		return false;
}

function externalSearch() {
    var search = document.getElementById(searchTextBox);
    var no = document.getElementById(qfNewOnly);
    var pmin = document.getElementById(qfPriceMin);
    var pmax = document.getElementById(qfPriceMax);
    var smin = document.getElementById(qfSqftMin);
    var smax = document.getElementById(qfSqftMax);
    var beds = document.getElementById(qfBedrooms);
    var bath = document.getElementById(qfBaths);
    var ptype = document.getElementById(qfPropType);
    var age = document.getElementById(qfAge);
    var sub = document.getElementById(qfSubdivision);
    var sd = document.getElementById(qfSchoolDistrict);
    var gs = document.getElementById(qfGarages);
    var sp = document.getElementById(qfSwimPool);
    var s = QFParser + "/receiver.aspx?";
    s += "s=" + search.value + "&no=" + no.value + "&pmin=" + pmin.value + "&pmax="+pmax.value;
    s += "&smin=" + smin.value + "&smax=" + smax.value + "&br=" + beds.value + "&bt=" + bath.value;
    s += "&pt=" + ptype.value + "&a=" + age.value + "&sub=" + sub.value + "&sd=" + sd.value + "&gs=" + gs.value;
    s += "&sp=" + sp.value;

    if (qfhb)
        window.open(s, "_self");
    else
        window.open(s);
}

function validateSearchBox() {
	var srch = document.getElementById(searchTextBox);

	if (srch.value.replace(/^\s+|\s+$/g, '') == "" || srch.value == "enter mls #, Texas city or zip") {
		document.getElementById(searchTextBox).blur();
		if (document.alert)
			document.alert("enter mls #, city, state or zip<br />(eg 'Dallas, TX' or '75093')", true, searchFocus);
		else
			alert("enter mls #, city, state or zip\n(eg 'Dallas, TX' or '75093')", true, searchFocus);
		return false;
	}
	else
		return true;
}

function searchFocus() {
	document.getElementById(searchTextBox).focus();
}

function setWatermark() {
    var txtB = jQuery("#" + searchTextBox);
    var txt = txtB.val();
    if (txt == "enter mls #, Texas city or zip" || txt == "") {
        txtB.css("color", "#aaaaaa");
        if (txt == "")
            txtB.val("enter mls #, Texas city or zip");
    }

    return true;
}

function clearWatermark() {
    var txtB = jQuery("#" + searchTextBox);
    var txt = txtB.val();
    if (txt == "enter mls #, Texas city or zip") {
        txtB.val("");
        txtB.css("color", "#000000");
    }

    return true;
}

jQuery(document).ready(function() {
    setWatermark();
});