<!--

/**
 * ---------------------- Subversion Information ------------------------------
 * ****************************************************************************
 * $Date: 2008-11-19 11:14:12 -0800 (Wed, 19 Nov 2008) $
 * $Rev: 349 $
 * $Author: steven $
 *
 * SVN URL of this file
 * $HeadURL: http://hal/svn/cms/trunk/idx/inc/js/search_form.js $
 * ****************************************************************************
 *
 * @copyright Real Estate Webmasters 2008
 */

    function validateCities(formObj)
    {
        var cities = formObj['search_city[]'];
        var len = cities.length;

        var valid = false;

        for (i = 0; i < len; i++)
        {
            if (cities[i].checked)
            {
                valid = true;
                break;
            }
        }

        if (!valid) alert('Please select a city.');

        return valid;
    }

    function validateCity(formObj)
    {
        var city = formObj['search_city'];
        var valid = false;

	  	if (city.value != "")
        {
	        valid = true;
        }

        if (!valid) alert('Please select a city.');

        return valid;
    }

    function validateMLS(formObj)
    {
        var mls = formObj['search_mls'];
        var len = mls.value.length;

        if (len < 1)
        {
            alert('Please enter a MLS number.');
            return false;
        }

        return true;
    }

    function validateZip(formObj)
    {
        var zip = formObj['search_zip'];
        var len = zip.value.length;

        if (len < 1)
        {
            alert('Please enter a Zip Code.');
            return false;
        }

        return true;
    }

    function save_search_toggle(input) {
        var obj = document.getElementById('search_title');
        if (input.checked) {
            obj.value = "Search Title";
            $('#search_title').show();
        } else {
            obj.value = "";
            $('#search_title').hide();
        }
    }

    function search_box(toggle) {
        var obj = document.getElementById('search_title');
        if (toggle) {
        	if(obj.value == "Search Title") {
        		obj.value = "";
        	}
        } else {
            if(obj.value == "") {
        		obj.value = "Search Title";
        	}
        }
    }

    function updateCity(click) {

    	var vars = "";
    	var val = "";

    	var formblock;
        var forminputs;

        if(click == "map") {
            formblock= document.getElementById('map_form');
            $('#map-city-list').html('Loading City List');
        } else {
            formblock= document.getElementById('searchForm');
            if(click == "subdivision") {
                $('#sub-select-list').html('Loading City List');
            } else if(click == "school") {
                $('#schl-select-list').html('Loading City List');
            } else {
        	    $('#city-list').html('Loading City List');
            }
        }
    	forminputs = formblock.getElementsByTagName('input');

    	if(document.getElementById('search_county').value != "") {
    		vars = "&search_county="+document.getElementById('search_county').value;
    	}
    	for (i = 0; i < forminputs.length; i++) {
    		// regex here to check name attribute
    		var regex = new RegExp("hide_city", "i");
    		if (regex.test(forminputs[i].getAttribute('name'))) {
    			if(click == "subdivision" || click == "school") {
    			    vars+="&search_city="+forminputs[i].value;
    			} else {
    		        vars+="&search_city[]="+forminputs[i].value;
    			}
    		}
    		var regex2 = new RegExp("search_city", "i");
    		if (regex2.test(forminputs[i].getAttribute('name'))) {
    			if(forminputs[i].checked == true) {
    				vars+="&search_city[]="+forminputs[i].value;
    			}
    		}
    	}

	    vars+="&search_by="+click;

    	vars = vars.replace(/ /g,"+");

    //    alert('/idx/dynamic/subdivisions.php?idx=' + val + vars);

        if(click == "subdivision") {
            $('#sub-select-list').load('/idx/dynamic/cities.php?idx=' + val + vars);
            if($('#hide_city').length != 0) {
                setTimeout("updateSub()",1000);
            }
        } else if(click == "school") {
            $('#schl-select-list').load('/idx/dynamic/cities.php?idx=' + val + vars);
            if($('#hide_city').length != 0) {
                setTimeout("updateSchool()",1000);
            }
        }  else if(click == "map") {
            $('#map-city-list').load('/idx/dynamic/map_cities.php?idx=' + val + vars);
        } else {
    	   $('#city-list').load('/idx/dynamic/cities.php?idx=' + val + vars);
        }

    }

    function subTypes() {

        var res = $('#RES');

        if(res.attr('checked') == true) {
            res.parent().parent().parent().parent().find('.subtpyes').slideDown().find('.subtypeselect').removeAttr('disabled');
        } else {
            res.parent().parent().parent().parent().find('.subtpyes').slideUp().find('.subtypeselect').attr('disabled', true);
        }

    }

//-->
