﻿/*
	Homefinder Search:
	
	This function coupled with an input:text field labeled "searchField" will provide the user the ability to view homes starting with specific letters
	
	Simply start typing your inquiry into the search field and the list will update.
*/
function toFirstUpper(id){
	var elem = document.getElementById(id);
		str = elem.value;
		str = str.substr(0,1).toUpperCase() + str.substr(1);
		elem.value = str;
		}
		//*Converts first letter to uppercase


$(document).ready(function(){
	$("#searchField").live('keyup', function(){

		$.ajax({
			type: 'GET',
			url: 'xml/models.xml',
			datatype: 'xml', 
			success: function(xml){
				$('#parentMenu').empty();
				$('#childMenu').empty();
				
				var result = $("#searchField").val();
					result = result.substr(0,1).toUpperCase() + result.substr(1);
				
				//Contains specified value
//				$(xml).find("model[name*='"+result+"']").each(function(){

				//Starts with Specified Value
				$(xml).find("model[name^='"+result+"']").each(function(){
					model = $(this).attr("name");
				
					$("#childMenu").append("<option class='childMenu' id='" +model+ "' value='" +model+ "'>" +model+ " </option>");
				});
				
			}
	
		});
	

	});
	
	
	$("#searchModel > p").click(function(){
		$("#searchField").val("");	
		});
	
});
